답안 #295720

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
295720 2020-09-09T20:39:25 Z RezwanArefin01 Potatoes and fertilizers (LMIO19_bulves) C++17
100 / 100
232 ms 15208 KB
#include <bits/stdc++.h>
using namespace std; 

typedef long long ll;
typedef pair<int, int> ii; 

const int N = 5e5 + 5; 

int n; 
ll p[N]; 

int main() {
  int n; 
  scanf("%d", &n); 

  for(int i = 1; i <= n; ++i) {
    int a, b; 
    scanf("%d %d", &a, &b); 
    p[i] = p[i - 1] + a - b; 
  }

  ll ans = 0; 
  priority_queue<ll> Q; 
  for(int i = 1; i <= n; ++i) {
    if(p[i] < 0) ans -= p[i], p[i] = 0; 
    if(p[i] > p[n]) ans += p[i] - p[n], p[i] = p[n]; 
    Q.push(p[i]); 
    Q.push(p[i]); 
    ans += Q.top() - p[i]; 
    Q.pop(); 
  }
  
  printf("%lld\n", ans); 
    
  return 0;
}

Compilation message

bulves.cpp: In function 'int main()':
bulves.cpp:14:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   14 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
bulves.cpp:18:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   18 |     scanf("%d %d", &a, &b);
      |     ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 21 ms 1660 KB Output is correct
5 Correct 28 ms 2936 KB Output is correct
6 Correct 95 ms 7916 KB Output is correct
7 Correct 192 ms 15208 KB Output is correct
8 Correct 151 ms 13416 KB Output is correct
9 Correct 164 ms 12648 KB Output is correct
10 Correct 135 ms 10472 KB Output is correct
11 Correct 136 ms 10472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 21 ms 1660 KB Output is correct
5 Correct 28 ms 2936 KB Output is correct
6 Correct 95 ms 7916 KB Output is correct
7 Correct 192 ms 15208 KB Output is correct
8 Correct 151 ms 13416 KB Output is correct
9 Correct 164 ms 12648 KB Output is correct
10 Correct 135 ms 10472 KB Output is correct
11 Correct 136 ms 10472 KB Output is correct
12 Correct 59 ms 4080 KB Output is correct
13 Correct 130 ms 10984 KB Output is correct
14 Correct 198 ms 15208 KB Output is correct
15 Correct 148 ms 13288 KB Output is correct
16 Correct 162 ms 12648 KB Output is correct
17 Correct 134 ms 10472 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 21 ms 1660 KB Output is correct
12 Correct 28 ms 2936 KB Output is correct
13 Correct 95 ms 7916 KB Output is correct
14 Correct 192 ms 15208 KB Output is correct
15 Correct 151 ms 13416 KB Output is correct
16 Correct 164 ms 12648 KB Output is correct
17 Correct 135 ms 10472 KB Output is correct
18 Correct 136 ms 10472 KB Output is correct
19 Correct 59 ms 4080 KB Output is correct
20 Correct 130 ms 10984 KB Output is correct
21 Correct 198 ms 15208 KB Output is correct
22 Correct 148 ms 13288 KB Output is correct
23 Correct 162 ms 12648 KB Output is correct
24 Correct 134 ms 10472 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 67 ms 4080 KB Output is correct
33 Correct 172 ms 10980 KB Output is correct
34 Correct 232 ms 15208 KB Output is correct
35 Correct 213 ms 12864 KB Output is correct
36 Correct 168 ms 13416 KB Output is correct
37 Correct 219 ms 15208 KB Output is correct
38 Correct 143 ms 11364 KB Output is correct
39 Correct 174 ms 10984 KB Output is correct
40 Correct 147 ms 10472 KB Output is correct
41 Correct 144 ms 10472 KB Output is correct
42 Correct 149 ms 10472 KB Output is correct
43 Correct 147 ms 10472 KB Output is correct
44 Correct 201 ms 15208 KB Output is correct
45 Correct 166 ms 10776 KB Output is correct
46 Correct 140 ms 10340 KB Output is correct
47 Correct 1 ms 384 KB Output is correct