답안 #1098693

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1098693 2024-10-09T17:57:42 Z noyancanturk Potatoes and fertilizers (LMIO19_bulves) C++17
100 / 100
128 ms 27080 KB
#include "bits/stdc++.h"
using namespace std;

#define int int64_t    
#define pb push_back

using pii=pair<int,int>;

const int lim=2e5+100;
const int mod=1e9+7;

signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#ifdef Local  
    freopen(".in","r",stdin);freopen(".out","w",stdout);
#endif
    int n;
    cin>>n;
    int a[n+1],b[n+1];
    for(int i=1;i<=n;i++)cin>>a[i]>>b[i];
    int d[n+1];
    for(int i=1;i<=n;i++)d[i]=a[i]-b[i];
    int p[n+1];
    p[0]=0;
    for(int i=1;i<=n;i++)p[i]=p[i-1]+d[i];
    priority_queue<int>pq;
    int ans=0;
    for(int i=1;i<=n;i++){
        if(p[i]<0){
            if(pq.size()){
                ans+=pq.top();
                pq.pop();
            }
            ans-=p[i];
        }else{
            pq.push(p[i]);
            ans+=pq.top()-p[i];
            pq.push(p[i]);
            pq.pop();
        }
    }
    while(p[n]<pq.top()){
        ans+=pq.top()-p[n];
        pq.pop();
    }
    cout<<ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 1 ms 504 KB Output is correct
4 Correct 9 ms 2660 KB Output is correct
5 Correct 21 ms 4816 KB Output is correct
6 Correct 71 ms 13772 KB Output is correct
7 Correct 70 ms 23108 KB Output is correct
8 Correct 124 ms 25036 KB Output is correct
9 Correct 72 ms 20952 KB Output is correct
10 Correct 75 ms 22068 KB Output is correct
11 Correct 82 ms 22220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 1 ms 504 KB Output is correct
4 Correct 9 ms 2660 KB Output is correct
5 Correct 21 ms 4816 KB Output is correct
6 Correct 71 ms 13772 KB Output is correct
7 Correct 70 ms 23108 KB Output is correct
8 Correct 124 ms 25036 KB Output is correct
9 Correct 72 ms 20952 KB Output is correct
10 Correct 75 ms 22068 KB Output is correct
11 Correct 82 ms 22220 KB Output is correct
12 Correct 32 ms 7132 KB Output is correct
13 Correct 79 ms 15940 KB Output is correct
14 Correct 75 ms 23108 KB Output is correct
15 Correct 120 ms 25004 KB Output is correct
16 Correct 128 ms 24524 KB Output is correct
17 Correct 65 ms 22196 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 1 ms 504 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 1 ms 504 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 9 ms 2660 KB Output is correct
12 Correct 21 ms 4816 KB Output is correct
13 Correct 71 ms 13772 KB Output is correct
14 Correct 70 ms 23108 KB Output is correct
15 Correct 124 ms 25036 KB Output is correct
16 Correct 72 ms 20952 KB Output is correct
17 Correct 75 ms 22068 KB Output is correct
18 Correct 82 ms 22220 KB Output is correct
19 Correct 32 ms 7132 KB Output is correct
20 Correct 79 ms 15940 KB Output is correct
21 Correct 75 ms 23108 KB Output is correct
22 Correct 120 ms 25004 KB Output is correct
23 Correct 128 ms 24524 KB Output is correct
24 Correct 65 ms 22196 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 600 KB Output is correct
33 Correct 28 ms 7124 KB Output is correct
34 Correct 69 ms 18120 KB Output is correct
35 Correct 112 ms 26920 KB Output is correct
36 Correct 106 ms 24524 KB Output is correct
37 Correct 112 ms 24992 KB Output is correct
38 Correct 115 ms 27080 KB Output is correct
39 Correct 76 ms 23244 KB Output is correct
40 Correct 80 ms 21604 KB Output is correct
41 Correct 72 ms 22220 KB Output is correct
42 Correct 73 ms 22196 KB Output is correct
43 Correct 77 ms 22056 KB Output is correct
44 Correct 80 ms 22068 KB Output is correct
45 Correct 124 ms 26824 KB Output is correct
46 Correct 91 ms 22456 KB Output is correct
47 Correct 74 ms 19404 KB Output is correct