답안 #219208

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
219208 2020-04-04T14:34:25 Z quocnguyen1012 Potatoes and fertilizers (LMIO19_bulves) C++14
100 / 100
187 ms 15340 KB
#include <bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;

const int maxn = 5e5 + 5;

ll sum[maxn];
int N;

signed main(void)
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #ifdef LOCAL
    freopen("A.INP", "r", stdin);
    freopen("A.OUT", "w", stdout);
  #endif // LOCAL
  cin >> N;
  for(int i = 1; i <= N; ++i){
    int a, b; cin >> a >> b;
    sum[i] = sum[i - 1] + a - b;
  }
  priority_queue<ll> pq;
  ll res = 0;
  for(int i = 1; i <= N; ++i){
    if(sum[i] < 0){
      res -= sum[i];
      sum[i] = 0;
    }
    if(sum[i] > sum[N]){
      res += sum[i] - sum[N];
      sum[i] = sum[N];
    }
    pq.push(sum[i]);
    if(sum[i] < pq.top()){
      res += pq.top() - sum[i];
      pq.pop();
      pq.push(sum[i]);
    }
  }
  cout << res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 14 ms 1792 KB Output is correct
5 Correct 23 ms 2940 KB Output is correct
6 Correct 67 ms 7920 KB Output is correct
7 Correct 130 ms 15216 KB Output is correct
8 Correct 103 ms 13420 KB Output is correct
9 Correct 107 ms 12780 KB Output is correct
10 Correct 82 ms 10476 KB Output is correct
11 Correct 76 ms 10476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 14 ms 1792 KB Output is correct
5 Correct 23 ms 2940 KB Output is correct
6 Correct 67 ms 7920 KB Output is correct
7 Correct 130 ms 15216 KB Output is correct
8 Correct 103 ms 13420 KB Output is correct
9 Correct 107 ms 12780 KB Output is correct
10 Correct 82 ms 10476 KB Output is correct
11 Correct 76 ms 10476 KB Output is correct
12 Correct 34 ms 4212 KB Output is correct
13 Correct 91 ms 11372 KB Output is correct
14 Correct 127 ms 15212 KB Output is correct
15 Correct 101 ms 13420 KB Output is correct
16 Correct 112 ms 12652 KB Output is correct
17 Correct 90 ms 10480 KB Output is correct
18 Correct 6 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 6 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 6 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 6 ms 512 KB Output is correct
13 Correct 6 ms 512 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 6 ms 512 KB Output is correct
18 Correct 6 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 6 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 14 ms 1792 KB Output is correct
12 Correct 23 ms 2940 KB Output is correct
13 Correct 67 ms 7920 KB Output is correct
14 Correct 130 ms 15216 KB Output is correct
15 Correct 103 ms 13420 KB Output is correct
16 Correct 107 ms 12780 KB Output is correct
17 Correct 82 ms 10476 KB Output is correct
18 Correct 76 ms 10476 KB Output is correct
19 Correct 34 ms 4212 KB Output is correct
20 Correct 91 ms 11372 KB Output is correct
21 Correct 127 ms 15212 KB Output is correct
22 Correct 101 ms 13420 KB Output is correct
23 Correct 112 ms 12652 KB Output is correct
24 Correct 90 ms 10480 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 6 ms 512 KB Output is correct
27 Correct 6 ms 512 KB Output is correct
28 Correct 6 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 6 ms 512 KB Output is correct
32 Correct 48 ms 4212 KB Output is correct
33 Correct 116 ms 10960 KB Output is correct
34 Correct 186 ms 15284 KB Output is correct
35 Correct 172 ms 12780 KB Output is correct
36 Correct 112 ms 13548 KB Output is correct
37 Correct 187 ms 15288 KB Output is correct
38 Correct 103 ms 11376 KB Output is correct
39 Correct 110 ms 10988 KB Output is correct
40 Correct 108 ms 10476 KB Output is correct
41 Correct 103 ms 10476 KB Output is correct
42 Correct 109 ms 10476 KB Output is correct
43 Correct 111 ms 10476 KB Output is correct
44 Correct 139 ms 15340 KB Output is correct
45 Correct 91 ms 10860 KB Output is correct
46 Correct 110 ms 10348 KB Output is correct
47 Correct 6 ms 384 KB Output is correct