# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
973138 | 2024-05-01T14:14:01 Z | hihihah | Potatoes and fertilizers (LMIO19_bulves) | C++14 | 148 ms | 17864 KB |
#include<bits/stdc++.h> using namespace std; #define ll long long #define all(x) x.begin(), x.end() #define pii pair<int, int> int n; int a[500009]; int b[500009]; int64_t pre[500009]; void hihihah() { cin >> n; for(int i = 1; i <= n; i ++) cin >> a[i] >> b[i]; for(int i = 1; i <= n; i ++) { pre[i] = pre[i - 1] + a[i] - b[i]; } priority_queue<int64_t> p; int64_t ans = 0; p.push(0); for(int i = 1; i <= n; i ++) { if(pre[i] < 0) { ans += -pre[i]; pre[i] = 0; } if(p.top() > pre[i]) ans += p.top() - pre[i]; p.push(pre[i]); p.push(pre[i]); p.pop(); } while(p.top() > pre[n]) { ans += p.top(); p.pop(); } cout << ans; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define orz "mo" if(fopen(orz".inp", "r")) { freopen(orz".inp", "r", stdin); // freopen(orz".out", "w", stdout); } int t = 1; // cin >> t; while(t --) { hihihah(); } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 4444 KB | Output is correct |
2 | Correct | 1 ms | 4444 KB | Output is correct |
3 | Correct | 2 ms | 4444 KB | Output is correct |
4 | Correct | 12 ms | 7644 KB | Output is correct |
5 | Correct | 23 ms | 8412 KB | Output is correct |
6 | Correct | 80 ms | 11400 KB | Output is correct |
7 | Correct | 90 ms | 17864 KB | Output is correct |
8 | Correct | 148 ms | 15288 KB | Output is correct |
9 | Correct | 96 ms | 15820 KB | Output is correct |
10 | Correct | 83 ms | 15052 KB | Output is correct |
11 | Correct | 100 ms | 14540 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 | 2 ms | 4444 KB | Output is correct |
4 | Correct | 12 ms | 7644 KB | Output is correct |
5 | Correct | 23 ms | 8412 KB | Output is correct |
6 | Correct | 80 ms | 11400 KB | Output is correct |
7 | Correct | 90 ms | 17864 KB | Output is correct |
8 | Correct | 148 ms | 15288 KB | Output is correct |
9 | Correct | 96 ms | 15820 KB | Output is correct |
10 | Correct | 83 ms | 15052 KB | Output is correct |
11 | Correct | 100 ms | 14540 KB | Output is correct |
12 | Incorrect | 36 ms | 8924 KB | Output isn't correct |
13 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 4444 KB | Output is correct |
2 | Correct | 1 ms | 4444 KB | Output is correct |
3 | Correct | 1 ms | 4440 KB | Output is correct |
4 | Incorrect | 1 ms | 4448 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 4444 KB | Output is correct |
2 | Correct | 1 ms | 4444 KB | Output is correct |
3 | Correct | 2 ms | 4444 KB | Output is correct |
4 | Correct | 1 ms | 4440 KB | Output is correct |
5 | Incorrect | 1 ms | 4448 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 4444 KB | Output is correct |
2 | Correct | 1 ms | 4444 KB | Output is correct |
3 | Correct | 2 ms | 4444 KB | Output is correct |
4 | Correct | 1 ms | 4440 KB | Output is correct |
5 | Incorrect | 1 ms | 4448 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |