답안 #740743

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
740743 2023-05-13T03:35:21 Z Prieved1 Potatoes and fertilizers (LMIO19_bulves) C++17
100 / 100
360 ms 15176 KB
#include<bits/stdc++.h>
using namespace std;
int main () {
  int n;
  cin >> n;
  int a[n], b[n];
  long long res=0;
  long long d=0, dd=0;
  priority_queue<long long> pq;
  for(int i = 0;i<n;i++) {
    cin >> a[i] >> b[i];
    dd+=a[i]-b[i];
  }
  for(int i = 0;i<n;i++) {
    d+=a[i]-b[i];
    long long c=d;
    if(c<0) {
      res-=c;
      c=0;
    }
    if(c>dd) {
      res+=c-dd;
      c=dd;
    }
//    cerr << c << " " << d << endl;
    pq.push(c);
    if(pq.top()!=c) {
      res+=pq.top()-c;
      pq.pop();
      pq.push(c);
    }
  }
  cout << res << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 19 ms 1232 KB Output is correct
5 Correct 41 ms 2196 KB Output is correct
6 Correct 144 ms 4388 KB Output is correct
7 Correct 275 ms 8396 KB Output is correct
8 Correct 235 ms 8396 KB Output is correct
9 Correct 211 ms 8388 KB Output is correct
10 Correct 142 ms 8396 KB Output is correct
11 Correct 148 ms 8392 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 2 ms 340 KB Output is correct
4 Correct 19 ms 1232 KB Output is correct
5 Correct 41 ms 2196 KB Output is correct
6 Correct 144 ms 4388 KB Output is correct
7 Correct 275 ms 8396 KB Output is correct
8 Correct 235 ms 8396 KB Output is correct
9 Correct 211 ms 8388 KB Output is correct
10 Correct 142 ms 8396 KB Output is correct
11 Correct 148 ms 8392 KB Output is correct
12 Correct 72 ms 2408 KB Output is correct
13 Correct 175 ms 10904 KB Output is correct
14 Correct 294 ms 15176 KB Output is correct
15 Correct 241 ms 13240 KB Output is correct
16 Correct 229 ms 12544 KB Output is correct
17 Correct 151 ms 10300 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 0 ms 212 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 2 ms 308 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 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 2 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 2 ms 308 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 2 ms 312 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 3 ms 356 KB Output is correct
15 Correct 2 ms 312 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 336 KB Output is correct
18 Correct 2 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 2 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 2 ms 308 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 19 ms 1232 KB Output is correct
12 Correct 41 ms 2196 KB Output is correct
13 Correct 144 ms 4388 KB Output is correct
14 Correct 275 ms 8396 KB Output is correct
15 Correct 235 ms 8396 KB Output is correct
16 Correct 211 ms 8388 KB Output is correct
17 Correct 142 ms 8396 KB Output is correct
18 Correct 148 ms 8392 KB Output is correct
19 Correct 72 ms 2408 KB Output is correct
20 Correct 175 ms 10904 KB Output is correct
21 Correct 294 ms 15176 KB Output is correct
22 Correct 241 ms 13240 KB Output is correct
23 Correct 229 ms 12544 KB Output is correct
24 Correct 151 ms 10300 KB Output is correct
25 Correct 2 ms 312 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 3 ms 356 KB Output is correct
28 Correct 2 ms 312 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 2 ms 336 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 87 ms 4052 KB Output is correct
34 Correct 201 ms 10836 KB Output is correct
35 Correct 360 ms 15164 KB Output is correct
36 Correct 280 ms 12732 KB Output is correct
37 Correct 305 ms 13208 KB Output is correct
38 Correct 346 ms 15164 KB Output is correct
39 Correct 187 ms 11448 KB Output is correct
40 Correct 198 ms 10828 KB Output is correct
41 Correct 173 ms 10300 KB Output is correct
42 Correct 166 ms 10312 KB Output is correct
43 Correct 169 ms 10312 KB Output is correct
44 Correct 164 ms 10300 KB Output is correct
45 Correct 301 ms 15048 KB Output is correct
46 Correct 174 ms 10684 KB Output is correct
47 Correct 183 ms 10192 KB Output is correct