답안 #950983

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
950983 2024-03-21T03:28:07 Z daoquanglinh2007 Potatoes and fertilizers (LMIO19_bulves) C++17
100 / 100
153 ms 22220 KB
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
 
const int NM = 5e5;
 
int n, a[NM+5], b[NM+5], c[NM+5], d[NM+5], cur = 0;
priority_queue <int> pq;
 
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> a[i] >> b[i];
        c[i] = c[i-1]+a[i];
        d[i] = d[i-1]+b[i];
    }
    pq.push(0);
    for (int i = 1; i < n; i++){
        if (c[i]-d[i] >= pq.top()){
            pq.push(c[i]-d[i]);
            continue;
        }
        cur += pq.top()-(c[i]-d[i]);
        pq.pop();
        if (c[i]-d[i] > 0){
            pq.push(c[i]-d[i]);
            pq.push(c[i]-d[i]);
        }
        else{
            pq.push(0);
            pq.push(0);
        }
    }
    int lst = pq.top(), slope = 0;
    while (lst > c[n]-d[n]){
        cur += slope*(lst-max(c[n]-d[n], pq.top()));
        lst = pq.top();
        pq.pop();
        slope++;
    }
    cout << cur;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 12 ms 9768 KB Output is correct
5 Correct 24 ms 14300 KB Output is correct
6 Correct 82 ms 15504 KB Output is correct
7 Correct 87 ms 22220 KB Output is correct
8 Correct 120 ms 21452 KB Output is correct
9 Correct 90 ms 22152 KB Output is correct
10 Correct 74 ms 22112 KB Output is correct
11 Correct 79 ms 20676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 12 ms 9768 KB Output is correct
5 Correct 24 ms 14300 KB Output is correct
6 Correct 82 ms 15504 KB Output is correct
7 Correct 87 ms 22220 KB Output is correct
8 Correct 120 ms 21452 KB Output is correct
9 Correct 90 ms 22152 KB Output is correct
10 Correct 74 ms 22112 KB Output is correct
11 Correct 79 ms 20676 KB Output is correct
12 Correct 36 ms 14488 KB Output is correct
13 Correct 92 ms 18132 KB Output is correct
14 Correct 90 ms 20788 KB Output is correct
15 Correct 120 ms 20936 KB Output is correct
16 Correct 153 ms 20860 KB Output is correct
17 Correct 60 ms 22060 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 1 ms 4696 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 1 ms 4696 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 2 ms 4440 KB Output is correct
14 Correct 2 ms 4444 KB Output is correct
15 Correct 2 ms 4444 KB Output is correct
16 Correct 2 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 1 ms 4696 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 12 ms 9768 KB Output is correct
12 Correct 24 ms 14300 KB Output is correct
13 Correct 82 ms 15504 KB Output is correct
14 Correct 87 ms 22220 KB Output is correct
15 Correct 120 ms 21452 KB Output is correct
16 Correct 90 ms 22152 KB Output is correct
17 Correct 74 ms 22112 KB Output is correct
18 Correct 79 ms 20676 KB Output is correct
19 Correct 36 ms 14488 KB Output is correct
20 Correct 92 ms 18132 KB Output is correct
21 Correct 90 ms 20788 KB Output is correct
22 Correct 120 ms 20936 KB Output is correct
23 Correct 153 ms 20860 KB Output is correct
24 Correct 60 ms 22060 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 2 ms 4440 KB Output is correct
27 Correct 2 ms 4444 KB Output is correct
28 Correct 2 ms 4444 KB Output is correct
29 Correct 2 ms 4444 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 31 ms 14292 KB Output is correct
34 Correct 65 ms 17868 KB Output is correct
35 Correct 110 ms 21644 KB Output is correct
36 Correct 105 ms 22140 KB Output is correct
37 Correct 94 ms 20348 KB Output is correct
38 Correct 102 ms 21148 KB Output is correct
39 Correct 61 ms 20680 KB Output is correct
40 Correct 78 ms 20504 KB Output is correct
41 Correct 61 ms 20348 KB Output is correct
42 Correct 61 ms 21044 KB Output is correct
43 Correct 63 ms 20172 KB Output is correct
44 Correct 64 ms 21192 KB Output is correct
45 Correct 132 ms 20212 KB Output is correct
46 Correct 53 ms 21192 KB Output is correct
47 Correct 71 ms 19152 KB Output is correct