답안 #200104

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
200104 2020-02-05T11:06:35 Z SamAnd Potatoes and fertilizers (LMIO19_bulves) C++17
100 / 100
257 ms 15332 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 500005;

int n;
long long a[N];

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
    {
        scanf("%lld", &a[i]);
        int x;
        scanf("%d", &x);
        a[i] -= x;
        a[i] += a[i - 1];
    }
    long long ans = 0;
    for (int i = 1; i <= n; ++i)
    {
        if (a[i] < 0)
        {
            ans += (-a[i]);
            a[i] = 0;
        }
        if (a[i] > a[n])
        {
            ans += (a[i] - a[n]);
            a[i] = a[n];
        }
    }
    priority_queue<long long> q;
    q.push(a[1]);
    for (int i = 2; i <= n; ++i)
    {
        q.push(a[i]);
        if (a[i] < q.top())
        {
            ans += (q.top() - a[i]);
            q.pop();
            q.push(a[i]);
        }
    }
    printf("%lld\n", ans);
    return 0;
}

Compilation message

bulves.cpp: In function 'int main()':
bulves.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
bulves.cpp:13:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld", &a[i]);
         ~~~~~^~~~~~~~~~~~~~~
bulves.cpp:15:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &x);
         ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 6 ms 376 KB Output is correct
4 Correct 20 ms 1652 KB Output is correct
5 Correct 34 ms 2928 KB Output is correct
6 Correct 97 ms 7960 KB Output is correct
7 Correct 187 ms 14180 KB Output is correct
8 Correct 144 ms 13284 KB Output is correct
9 Correct 154 ms 12772 KB Output is correct
10 Correct 141 ms 10476 KB Output is correct
11 Correct 136 ms 10468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 6 ms 376 KB Output is correct
4 Correct 20 ms 1652 KB Output is correct
5 Correct 34 ms 2928 KB Output is correct
6 Correct 97 ms 7960 KB Output is correct
7 Correct 187 ms 14180 KB Output is correct
8 Correct 144 ms 13284 KB Output is correct
9 Correct 154 ms 12772 KB Output is correct
10 Correct 141 ms 10476 KB Output is correct
11 Correct 136 ms 10468 KB Output is correct
12 Correct 51 ms 4208 KB Output is correct
13 Correct 122 ms 10980 KB Output is correct
14 Correct 195 ms 15204 KB Output is correct
15 Correct 143 ms 13412 KB Output is correct
16 Correct 172 ms 12772 KB Output is correct
17 Correct 143 ms 10468 KB Output is correct
18 Correct 6 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 6 ms 376 KB Output is correct
7 Correct 6 ms 376 KB Output is correct
8 Correct 6 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 6 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 6 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 6 ms 376 KB Output is correct
8 Correct 6 ms 376 KB Output is correct
9 Correct 6 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 6 ms 376 KB Output is correct
12 Correct 7 ms 376 KB Output is correct
13 Correct 6 ms 376 KB Output is correct
14 Correct 6 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 6 ms 376 KB Output is correct
17 Correct 6 ms 376 KB Output is correct
18 Correct 6 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 6 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 6 ms 376 KB Output is correct
8 Correct 6 ms 376 KB Output is correct
9 Correct 6 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 20 ms 1652 KB Output is correct
12 Correct 34 ms 2928 KB Output is correct
13 Correct 97 ms 7960 KB Output is correct
14 Correct 187 ms 14180 KB Output is correct
15 Correct 144 ms 13284 KB Output is correct
16 Correct 154 ms 12772 KB Output is correct
17 Correct 141 ms 10476 KB Output is correct
18 Correct 136 ms 10468 KB Output is correct
19 Correct 51 ms 4208 KB Output is correct
20 Correct 122 ms 10980 KB Output is correct
21 Correct 195 ms 15204 KB Output is correct
22 Correct 143 ms 13412 KB Output is correct
23 Correct 172 ms 12772 KB Output is correct
24 Correct 143 ms 10468 KB Output is correct
25 Correct 6 ms 376 KB Output is correct
26 Correct 7 ms 376 KB Output is correct
27 Correct 6 ms 376 KB Output is correct
28 Correct 6 ms 376 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 6 ms 376 KB Output is correct
31 Correct 6 ms 376 KB Output is correct
32 Correct 64 ms 4208 KB Output is correct
33 Correct 153 ms 10980 KB Output is correct
34 Correct 254 ms 15204 KB Output is correct
35 Correct 229 ms 12900 KB Output is correct
36 Correct 154 ms 13412 KB Output is correct
37 Correct 257 ms 15204 KB Output is correct
38 Correct 161 ms 11592 KB Output is correct
39 Correct 154 ms 10980 KB Output is correct
40 Correct 162 ms 10468 KB Output is correct
41 Correct 164 ms 10596 KB Output is correct
42 Correct 175 ms 10480 KB Output is correct
43 Correct 167 ms 10596 KB Output is correct
44 Correct 205 ms 15332 KB Output is correct
45 Correct 142 ms 10724 KB Output is correct
46 Correct 156 ms 10460 KB Output is correct
47 Correct 6 ms 376 KB Output is correct