답안 #836449

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
836449 2023-08-24T11:19:41 Z urieg Potatoes and fertilizers (LMIO19_bulves) C++17
100 / 100
158 ms 15228 KB
#include<bits/stdc++.h>
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define ve vector
typedef long long ll;
using namespace std;



int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;
    ll a,b ;
    priority_queue<ll>q;
    long long ans = 0;
    cin>>n;
    vector<ll>d(n);
    for(int i = 0;i<n;i++){
        cin>>a>>b;
        d[i] = a-b;
        if(i)d[i] += d[i-1];
    }

    if(d[0] < 0){
        ans += -d[0];
        d[0]=0;
    }
    q.push(d[0]);
    for(int i = 1; i<n-1; i++){
        if(d[i]<0){
            ans += -d[i];
            d[i]=0;
        }
        q.push(d[i]);
        if(q.top()>d[i]){
            ans += q.top()-d[i];
            q.push(d[i]);
            q.pop();
        }
    }
    if(n>1){
        while(q.size()>0 && q.top()>d[n-1]){
            ans += q.top()-d[n-1];
            q.pop();
        }
    }
    cout<<ans;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 10 ms 1368 KB Output is correct
5 Correct 22 ms 2260 KB Output is correct
6 Correct 84 ms 4456 KB Output is correct
7 Correct 73 ms 8388 KB Output is correct
8 Correct 118 ms 8432 KB Output is correct
9 Correct 83 ms 12612 KB Output is correct
10 Correct 75 ms 10348 KB Output is correct
11 Correct 85 ms 10412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 10 ms 1368 KB Output is correct
5 Correct 22 ms 2260 KB Output is correct
6 Correct 84 ms 4456 KB Output is correct
7 Correct 73 ms 8388 KB Output is correct
8 Correct 118 ms 8432 KB Output is correct
9 Correct 83 ms 12612 KB Output is correct
10 Correct 75 ms 10348 KB Output is correct
11 Correct 85 ms 10412 KB Output is correct
12 Correct 35 ms 4160 KB Output is correct
13 Correct 89 ms 10836 KB Output is correct
14 Correct 89 ms 15148 KB Output is correct
15 Correct 126 ms 13340 KB Output is correct
16 Correct 158 ms 12612 KB Output is correct
17 Correct 60 ms 10436 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 10 ms 1368 KB Output is correct
12 Correct 22 ms 2260 KB Output is correct
13 Correct 84 ms 4456 KB Output is correct
14 Correct 73 ms 8388 KB Output is correct
15 Correct 118 ms 8432 KB Output is correct
16 Correct 83 ms 12612 KB Output is correct
17 Correct 75 ms 10348 KB Output is correct
18 Correct 85 ms 10412 KB Output is correct
19 Correct 35 ms 4160 KB Output is correct
20 Correct 89 ms 10836 KB Output is correct
21 Correct 89 ms 15148 KB Output is correct
22 Correct 126 ms 13340 KB Output is correct
23 Correct 158 ms 12612 KB Output is correct
24 Correct 60 ms 10436 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 27 ms 4292 KB Output is correct
34 Correct 69 ms 10880 KB Output is correct
35 Correct 118 ms 15228 KB Output is correct
36 Correct 106 ms 12940 KB Output is correct
37 Correct 98 ms 13252 KB Output is correct
38 Correct 104 ms 15216 KB Output is correct
39 Correct 73 ms 11380 KB Output is correct
40 Correct 69 ms 10948 KB Output is correct
41 Correct 65 ms 10436 KB Output is correct
42 Correct 66 ms 10436 KB Output is correct
43 Correct 66 ms 10376 KB Output is correct
44 Correct 69 ms 10436 KB Output is correct
45 Correct 129 ms 15100 KB Output is correct
46 Correct 60 ms 10692 KB Output is correct
47 Correct 68 ms 10180 KB Output is correct