답안 #919089

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
919089 2024-01-31T08:31:05 Z imarn Potatoes and fertilizers (LMIO19_bulves) C++14
100 / 100
173 ms 17264 KB
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define vvi vector<vi>
#define vp vector<pii>
using namespace std;
priority_queue<ll>q;
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;cin>>n;
    ll dp[n+1]={0};
    for(int i=1,a,b;i<=n;i++){
        cin>>a>>b;dp[i]=a-b+dp[i-1];
    }ll res=0;
    for(int i=1;i<n;i++){
        if(dp[i]<0)res-=dp[i],dp[i]=0;
        res+=dp[i];
        q.push(dp[i]);
        q.push(dp[i]);
        q.pop();
    }
    while(!q.empty()){
        res-=min(dp[n],q.top());q.pop();
    }cout<<res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 11 ms 1756 KB Output is correct
5 Correct 24 ms 2876 KB Output is correct
6 Correct 79 ms 7748 KB Output is correct
7 Correct 105 ms 17096 KB Output is correct
8 Correct 143 ms 13516 KB Output is correct
9 Correct 115 ms 13032 KB Output is correct
10 Correct 93 ms 11044 KB Output is correct
11 Correct 96 ms 11720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 11 ms 1756 KB Output is correct
5 Correct 24 ms 2876 KB Output is correct
6 Correct 79 ms 7748 KB Output is correct
7 Correct 105 ms 17096 KB Output is correct
8 Correct 143 ms 13516 KB Output is correct
9 Correct 115 ms 13032 KB Output is correct
10 Correct 93 ms 11044 KB Output is correct
11 Correct 96 ms 11720 KB Output is correct
12 Correct 36 ms 4048 KB Output is correct
13 Correct 92 ms 11528 KB Output is correct
14 Correct 112 ms 17264 KB Output is correct
15 Correct 142 ms 15080 KB Output is correct
16 Correct 148 ms 13256 KB Output is correct
17 Correct 86 ms 11720 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 2 ms 344 KB Output is correct
15 Correct 1 ms 488 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 11 ms 1756 KB Output is correct
12 Correct 24 ms 2876 KB Output is correct
13 Correct 79 ms 7748 KB Output is correct
14 Correct 105 ms 17096 KB Output is correct
15 Correct 143 ms 13516 KB Output is correct
16 Correct 115 ms 13032 KB Output is correct
17 Correct 93 ms 11044 KB Output is correct
18 Correct 96 ms 11720 KB Output is correct
19 Correct 36 ms 4048 KB Output is correct
20 Correct 92 ms 11528 KB Output is correct
21 Correct 112 ms 17264 KB Output is correct
22 Correct 142 ms 15080 KB Output is correct
23 Correct 148 ms 13256 KB Output is correct
24 Correct 86 ms 11720 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 2 ms 344 KB Output is correct
28 Correct 1 ms 488 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 1 ms 520 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 40 ms 4048 KB Output is correct
34 Correct 100 ms 12228 KB Output is correct
35 Correct 173 ms 15492 KB Output is correct
36 Correct 164 ms 13552 KB Output is correct
37 Correct 148 ms 14576 KB Output is correct
38 Correct 172 ms 17132 KB Output is correct
39 Correct 113 ms 12260 KB Output is correct
40 Correct 127 ms 11568 KB Output is correct
41 Correct 98 ms 11684 KB Output is correct
42 Correct 99 ms 11896 KB Output is correct
43 Correct 91 ms 11372 KB Output is correct
44 Correct 100 ms 10532 KB Output is correct
45 Correct 164 ms 16824 KB Output is correct
46 Correct 129 ms 12484 KB Output is correct
47 Correct 107 ms 10640 KB Output is correct