Buying Order (Easy) write ans in python This is the easy version of the problem…
- User
Buying Order (Easy) write ans in python
This is the easy version of the problem available for 100 points in all divisions. Note that here you need to find the maximum number of items possible.
There's a shop with NN distinct items numbered 11, 22, .... NN. There's also a boolean array BB of length NN.
You want to buy all NN items once each, in some order. Say this order is P1,P2,...,PNP1,P2,...,PN. When buying item PiPi,
codeIf BPi=1BPi=1 and there exists some j<ij<i such that Pj>PiPj>Pi, you get two copies of item PiPi, otherwise you get one copy. Informally, you get two copies if you have bought an item with a larger index before, otherwise you get one copy. If BPi=0BPi=0, it's the opposite - if there exists some j<ij<i such that Pj<PiPj<Pi, you get two copies, otherwise one. Informally, you get two copies if you have bought an item with a smaller index before, otherwise you get one copy.Find the maximum total number of items that you can have in the end. Input Format
codeThe first line of input will contain a single integer TT, denoting the number of test cases. Each test case consists of multiple lines of input. The first line of each test case contains NN - the number of items The second line contains NN boolean variables - B1,B2,...,BNB1,B2,...,BN.Output Format
For each test case, output on a new the maximum possible number of items.
- Assistant