답안 #377078

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
377078 2021-03-13T00:58:38 Z wzy Potatoes and fertilizers (LMIO19_bulves) C++11
100 / 100
294 ms 15224 KB
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef pair<ll,ll> pll;
typedef vector<string> vs;
typedef vector<pll> vpl;
typedef vector<int> vi;
std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());
const int N = 500005;
int a[N] , b[N] , n;

int32_t main(){
	scanf("%d" , &n);
	priority_queue<ll> pq;
	long long ans = 0 , cur = 0;
	for(int i = 1; i <= n; i ++){
		scanf("%d%d" , &a[i] , &b[i]);
		cur += a[i] - b[i];
		if(i < n){
			ans += abs(cur);
			pq.push(max(0ll,cur)) , pq.push(max(0ll,cur));
			pq.pop();
		}
	}
	while(sz(pq)){
		ans -= min(pq.top() , cur);
		pq.pop();
	}
	printf("%lld\n" , ans);
}

Compilation message

bulves.cpp: In function 'int32_t main()':
bulves.cpp:24:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   24 |  scanf("%d" , &n);
      |  ~~~~~^~~~~~~~~~~
bulves.cpp:28:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   28 |   scanf("%d%d" , &a[i] , &b[i]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 2 ms 492 KB Output is correct
4 Correct 19 ms 1636 KB Output is correct
5 Correct 42 ms 2800 KB Output is correct
6 Correct 129 ms 7900 KB Output is correct
7 Correct 191 ms 15060 KB Output is correct
8 Correct 223 ms 13312 KB Output is correct
9 Correct 195 ms 12500 KB Output is correct
10 Correct 180 ms 10276 KB Output is correct
11 Correct 172 ms 10216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 2 ms 492 KB Output is correct
4 Correct 19 ms 1636 KB Output is correct
5 Correct 42 ms 2800 KB Output is correct
6 Correct 129 ms 7900 KB Output is correct
7 Correct 191 ms 15060 KB Output is correct
8 Correct 223 ms 13312 KB Output is correct
9 Correct 195 ms 12500 KB Output is correct
10 Correct 180 ms 10276 KB Output is correct
11 Correct 172 ms 10216 KB Output is correct
12 Correct 58 ms 4064 KB Output is correct
13 Correct 157 ms 10568 KB Output is correct
14 Correct 190 ms 15160 KB Output is correct
15 Correct 219 ms 13276 KB Output is correct
16 Correct 256 ms 12500 KB Output is correct
17 Correct 173 ms 10196 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 2 ms 492 KB Output is correct
8 Correct 2 ms 492 KB Output is correct
9 Correct 2 ms 492 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 2 ms 492 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 2 ms 492 KB Output is correct
8 Correct 2 ms 492 KB Output is correct
9 Correct 2 ms 492 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 2 ms 492 KB Output is correct
14 Correct 2 ms 492 KB Output is correct
15 Correct 2 ms 492 KB Output is correct
16 Correct 2 ms 492 KB Output is correct
17 Correct 2 ms 492 KB Output is correct
18 Correct 2 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 2 ms 492 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 2 ms 492 KB Output is correct
8 Correct 2 ms 492 KB Output is correct
9 Correct 2 ms 492 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 19 ms 1636 KB Output is correct
12 Correct 42 ms 2800 KB Output is correct
13 Correct 129 ms 7900 KB Output is correct
14 Correct 191 ms 15060 KB Output is correct
15 Correct 223 ms 13312 KB Output is correct
16 Correct 195 ms 12500 KB Output is correct
17 Correct 180 ms 10276 KB Output is correct
18 Correct 172 ms 10216 KB Output is correct
19 Correct 58 ms 4064 KB Output is correct
20 Correct 157 ms 10568 KB Output is correct
21 Correct 190 ms 15160 KB Output is correct
22 Correct 219 ms 13276 KB Output is correct
23 Correct 256 ms 12500 KB Output is correct
24 Correct 173 ms 10196 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 2 ms 492 KB Output is correct
27 Correct 2 ms 492 KB Output is correct
28 Correct 2 ms 492 KB Output is correct
29 Correct 2 ms 492 KB Output is correct
30 Correct 2 ms 492 KB Output is correct
31 Correct 2 ms 492 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 59 ms 4168 KB Output is correct
34 Correct 152 ms 10332 KB Output is correct
35 Correct 294 ms 15208 KB Output is correct
36 Correct 254 ms 12628 KB Output is correct
37 Correct 219 ms 13160 KB Output is correct
38 Correct 272 ms 15224 KB Output is correct
39 Correct 179 ms 11220 KB Output is correct
40 Correct 190 ms 10452 KB Output is correct
41 Correct 174 ms 10196 KB Output is correct
42 Correct 172 ms 10196 KB Output is correct
43 Correct 168 ms 10460 KB Output is correct
44 Correct 219 ms 10344 KB Output is correct
45 Correct 245 ms 15060 KB Output is correct
46 Correct 196 ms 10580 KB Output is correct
47 Correct 173 ms 9312 KB Output is correct