답안 #203277

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
203277 2020-02-20T05:01:57 Z dolphingarlic Potatoes and fertilizers (LMIO19_bulves) C++14
0 / 100
6 ms 480 KB
#include <bits/stdc++.h>
using namespace std;

long long c[500001], ans = 0;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		long long a, b;
		cin >> a >> b;
		c[i] = c[i - 1] + a - b;
	}
	priority_queue<long long> pq;
	for (int i = 1; i <= n; i++) {
		if (c[i] > c[n]) {
			ans += c[i] - c[n];
			c[i] = c[n];
		} else if (c[i] < 0) ans -= c[i];
		pq.push(c[i]);
		if (pq.top() > c[i]) {
			ans += pq.top() - c[i];
			pq.pop();
			pq.push(c[i]);
		}
	}
	cout << ans;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 380 KB Output is correct
3 Incorrect 6 ms 480 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 380 KB Output is correct
3 Incorrect 6 ms 480 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 380 KB Output is correct
3 Correct 5 ms 388 KB Output is correct
4 Incorrect 5 ms 376 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 380 KB Output is correct
3 Incorrect 6 ms 480 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 380 KB Output is correct
3 Incorrect 6 ms 480 KB Output isn't correct