Submission #44349

# Submission time Handle Problem Language Result Execution time Memory
44349 2018-03-31T14:19:28 Z ruhanhabib39 Candies (JOI18_candies) C++17
100 / 100
902 ms 28124 KB
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 2e5;
const long long INF = 1e16;

typedef set<pair<long long,long long>,greater<pair<long long,long long>>> inc_set;

long long N;
inc_set pos, val;
long long res[MAXN + 10];

int main() {
   scanf("%lld", &N);
   for(long long i = 0; i < N; i++) {
      long long a; scanf("%lld", &a);
      pos.emplace(i, a);
      val.emplace(a, i);
   }
   pos.emplace(-1LL, -INF); pos.emplace(N, -INF);
   val.emplace(-INF, -1LL); val.emplace(-INF, N);
   long long ss = 0;
   for(int i = 0; i < (N+1)/2; i++) {
      auto valIt = val.begin();

      ss += valIt->first;
      res[i] = ss;

      auto posIt = pos.find({valIt->second, valIt->first});
      auto x = *prev(posIt);
      auto y = *posIt;
      auto z = *next(posIt);

      for(auto it : {x,y,z}) {
         pos.erase(it);
         val.erase({it.second, it.first});
      }

      pos.insert({y.first, x.second + z.second - y.second});
      val.insert({x.second + z.second - y.second, y.first});
   }

   for(int i = 0; i < (N + 1)/2; i++) {
      printf("%lld\n", res[i]);
   }

}

Compilation message

candies.cpp: In function 'int main()':
candies.cpp:14:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%lld", &N);
    ~~~~~^~~~~~~~~~~~
candies.cpp:16:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       long long a; scanf("%lld", &a);
                    ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 504 KB Output is correct
2 Correct 5 ms 612 KB Output is correct
3 Correct 5 ms 808 KB Output is correct
4 Correct 4 ms 808 KB Output is correct
5 Correct 5 ms 808 KB Output is correct
6 Correct 5 ms 808 KB Output is correct
7 Correct 4 ms 972 KB Output is correct
8 Correct 4 ms 972 KB Output is correct
9 Correct 6 ms 972 KB Output is correct
10 Correct 4 ms 972 KB Output is correct
11 Correct 5 ms 972 KB Output is correct
12 Correct 5 ms 972 KB Output is correct
13 Correct 4 ms 972 KB Output is correct
14 Correct 5 ms 1036 KB Output is correct
15 Correct 4 ms 1036 KB Output is correct
16 Correct 5 ms 1036 KB Output is correct
17 Correct 5 ms 1036 KB Output is correct
18 Correct 5 ms 1068 KB Output is correct
19 Correct 4 ms 1068 KB Output is correct
20 Correct 4 ms 1068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 504 KB Output is correct
2 Correct 5 ms 612 KB Output is correct
3 Correct 5 ms 808 KB Output is correct
4 Correct 4 ms 808 KB Output is correct
5 Correct 5 ms 808 KB Output is correct
6 Correct 5 ms 808 KB Output is correct
7 Correct 4 ms 972 KB Output is correct
8 Correct 4 ms 972 KB Output is correct
9 Correct 6 ms 972 KB Output is correct
10 Correct 4 ms 972 KB Output is correct
11 Correct 5 ms 972 KB Output is correct
12 Correct 5 ms 972 KB Output is correct
13 Correct 4 ms 972 KB Output is correct
14 Correct 5 ms 1036 KB Output is correct
15 Correct 4 ms 1036 KB Output is correct
16 Correct 5 ms 1036 KB Output is correct
17 Correct 5 ms 1036 KB Output is correct
18 Correct 5 ms 1068 KB Output is correct
19 Correct 4 ms 1068 KB Output is correct
20 Correct 4 ms 1068 KB Output is correct
21 Correct 877 ms 27984 KB Output is correct
22 Correct 895 ms 28096 KB Output is correct
23 Correct 902 ms 28096 KB Output is correct
24 Correct 401 ms 28096 KB Output is correct
25 Correct 387 ms 28096 KB Output is correct
26 Correct 383 ms 28096 KB Output is correct
27 Correct 413 ms 28096 KB Output is correct
28 Correct 432 ms 28096 KB Output is correct
29 Correct 469 ms 28096 KB Output is correct
30 Correct 451 ms 28096 KB Output is correct
31 Correct 447 ms 28096 KB Output is correct
32 Correct 454 ms 28096 KB Output is correct
33 Correct 599 ms 28096 KB Output is correct
34 Correct 596 ms 28096 KB Output is correct
35 Correct 598 ms 28096 KB Output is correct
36 Correct 857 ms 28124 KB Output is correct
37 Correct 826 ms 28124 KB Output is correct
38 Correct 841 ms 28124 KB Output is correct
39 Correct 387 ms 28124 KB Output is correct
40 Correct 384 ms 28124 KB Output is correct
41 Correct 396 ms 28124 KB Output is correct
42 Correct 419 ms 28124 KB Output is correct
43 Correct 412 ms 28124 KB Output is correct
44 Correct 420 ms 28124 KB Output is correct
45 Correct 481 ms 28124 KB Output is correct
46 Correct 433 ms 28124 KB Output is correct
47 Correct 432 ms 28124 KB Output is correct
48 Correct 587 ms 28124 KB Output is correct
49 Correct 597 ms 28124 KB Output is correct
50 Correct 594 ms 28124 KB Output is correct