Submission #229370

# Submission time Handle Problem Language Result Execution time Memory
229370 2020-05-04T10:36:37 Z DodgeBallMan Candies (JOI18_candies) C++14
100 / 100
399 ms 19576 KB
#include <bits/stdc++.h>
#define pii pair<long, long>
#define x first
#define y second
 
using namespace std;
 
const int N = 2e5 + 10;
  
int n, L[N], R[N];
long long A[N];
set<pii> S;
 
int main() 
{
    scanf("%d",&n);
    for( int i = 1 ; i <= n ; i++ ) {
        scanf("%lld", A + i);
        if( i > 1 ) L[i] = i - 1;
        if( i < n ) R[i] = i + 1;
        S.emplace( A[i], i );
    }
    long long ans = 0;
    for( int i = 1 ; i <= ( n + 1 ) / 2 ; i++ ) {
        int now = S.rbegin()->y;
        printf("%lld\n",ans += A[now]);
        S.erase( pii( A[now], now ) );
        int l = L[now], r = R[now];
        if( l ) S.erase( pii( A[l], l ) );
        if( r ) S.erase( pii( A[r], r ) );
        A[now] = A[l] + A[r] - A[now];
        if( l && r ) {
            L[now] = L[l], R[now] = R[r];
            S.emplace( A[now], now );
        } else now = 0;
        if( L[l] ) R[L[l]] = now;
        if( R[r] ) L[R[r]] = now;
    }
 
    return 0;
}

Compilation message

candies.cpp: In function 'int main()':
candies.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
candies.cpp:18:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld", A + i);
         ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 512 KB Output is correct
2 Correct 6 ms 512 KB Output is correct
3 Correct 6 ms 512 KB Output is correct
4 Correct 6 ms 512 KB Output is correct
5 Correct 6 ms 512 KB Output is correct
6 Correct 6 ms 512 KB Output is correct
7 Correct 6 ms 512 KB Output is correct
8 Correct 6 ms 512 KB Output is correct
9 Correct 6 ms 512 KB Output is correct
10 Correct 6 ms 512 KB Output is correct
11 Correct 6 ms 512 KB Output is correct
12 Correct 6 ms 512 KB Output is correct
13 Correct 7 ms 512 KB Output is correct
14 Correct 6 ms 512 KB Output is correct
15 Correct 6 ms 512 KB Output is correct
16 Correct 6 ms 512 KB Output is correct
17 Correct 6 ms 512 KB Output is correct
18 Correct 6 ms 384 KB Output is correct
19 Correct 6 ms 640 KB Output is correct
20 Correct 6 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 512 KB Output is correct
2 Correct 6 ms 512 KB Output is correct
3 Correct 6 ms 512 KB Output is correct
4 Correct 6 ms 512 KB Output is correct
5 Correct 6 ms 512 KB Output is correct
6 Correct 6 ms 512 KB Output is correct
7 Correct 6 ms 512 KB Output is correct
8 Correct 6 ms 512 KB Output is correct
9 Correct 6 ms 512 KB Output is correct
10 Correct 6 ms 512 KB Output is correct
11 Correct 6 ms 512 KB Output is correct
12 Correct 6 ms 512 KB Output is correct
13 Correct 7 ms 512 KB Output is correct
14 Correct 6 ms 512 KB Output is correct
15 Correct 6 ms 512 KB Output is correct
16 Correct 6 ms 512 KB Output is correct
17 Correct 6 ms 512 KB Output is correct
18 Correct 6 ms 384 KB Output is correct
19 Correct 6 ms 640 KB Output is correct
20 Correct 6 ms 512 KB Output is correct
21 Correct 383 ms 19448 KB Output is correct
22 Correct 373 ms 19424 KB Output is correct
23 Correct 385 ms 19448 KB Output is correct
24 Correct 166 ms 19196 KB Output is correct
25 Correct 166 ms 19320 KB Output is correct
26 Correct 162 ms 19192 KB Output is correct
27 Correct 182 ms 19448 KB Output is correct
28 Correct 171 ms 19448 KB Output is correct
29 Correct 174 ms 19448 KB Output is correct
30 Correct 186 ms 19448 KB Output is correct
31 Correct 191 ms 19448 KB Output is correct
32 Correct 186 ms 19448 KB Output is correct
33 Correct 270 ms 19364 KB Output is correct
34 Correct 268 ms 19192 KB Output is correct
35 Correct 278 ms 19320 KB Output is correct
36 Correct 383 ms 19448 KB Output is correct
37 Correct 399 ms 19576 KB Output is correct
38 Correct 359 ms 19452 KB Output is correct
39 Correct 169 ms 19320 KB Output is correct
40 Correct 165 ms 19192 KB Output is correct
41 Correct 166 ms 19192 KB Output is correct
42 Correct 177 ms 19424 KB Output is correct
43 Correct 177 ms 19388 KB Output is correct
44 Correct 172 ms 19392 KB Output is correct
45 Correct 184 ms 19448 KB Output is correct
46 Correct 185 ms 19448 KB Output is correct
47 Correct 186 ms 19448 KB Output is correct
48 Correct 270 ms 19296 KB Output is correct
49 Correct 257 ms 19324 KB Output is correct
50 Correct 291 ms 19376 KB Output is correct