codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

331A1.md (2424B)


      1 Source: https://codeforces.com/problemset/problem/331/A1
      2 
      3 A1. Oh Sweet Beaverette
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 — Oh my sweet Beaverette, would you fancy a walk along a wonderful woodland belt with me?
     22 
     23 — Of course, my Smart Beaver! Let us enjoy the splendid view together. How about Friday night?
     24 
     25 At this point the Smart Beaver got rushing. Everything should be perfect by Friday, so he needed to prepare the belt to the upcoming walk. He needed to cut down several trees.
     26 
     27 Let's consider the woodland belt as a sequence of trees. Each tree *i* is described by the esthetic appeal *a**i* — some trees are very esthetically pleasing, others are 'so-so', and some trees are positively ugly!
     28 
     29 The Smart Beaver calculated that he needed the following effects to win the Beaverette's heart:
     30 
     31 * The first objective is to please the Beaverette: the sum of esthetic appeal of the remaining trees must be maximum possible;
     32 * the second objective is to surprise the Beaverette: the esthetic appeal of the first and the last trees in the resulting belt must be the same;
     33 * and of course, the walk should be successful: there must be at least two trees in the woodland belt left.
     34 
     35 Now help the Smart Beaver! Which trees does he need to cut down to win the Beaverette's heart?
     36 
     37 Input
     38 
     39 The first line contains a single integer *n* — the initial number of trees in the woodland belt, 2 ≤ *n*. The second line contains space-separated integers *a**i* — the esthetic appeals of each tree. All esthetic appeals do not exceed 109 in their absolute value.
     40 
     41 * to get 30 points, you need to solve the problem with constraints: *n* ≤ 100 (subproblem A1);
     42 * to get 100 points, you need to solve the problem with constraints: *n* ≤ 3·105 (subproblems A1+A2).
     43 
     44 Output
     45 
     46 In the first line print two integers — the total esthetic appeal of the woodland belt after the Smart Beaver's intervention and the number of the cut down trees *k*.
     47 
     48 In the next line print *k* integers — the numbers of the trees the Beaver needs to cut down. Assume that the trees are numbered from 1 to *n* from left to right.
     49 
     50 If there are multiple solutions, print any of them. It is guaranteed that at least two trees have equal esthetic appeal.
     51 
     52 Examples
     53 
     54 Input
     55 
     56 ```
     57 5  
     58 1 2 3 1 2
     59 ```
     60 
     61 Output
     62 
     63 ```
     64 8 1  
     65 1
     66 ```
     67 
     68 Input
     69 
     70 ```
     71 5  
     72 1 -2 3 1 -2
     73 ```
     74 
     75 Output
     76 
     77 ```
     78 5 2  
     79 2 5
     80 ```