답안 #587928

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
587928 2022-07-02T14:18:19 Z jmyszka2007 Potatoes and fertilizers (LMIO19_bulves) C++17
20 / 100
15 ms 1416 KB
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n;
	scanf("%d", &n);
	vector<int>a(n + 1);
	vector<int>b(n + 1);
	for(int i = 1; i <= n; i++) {
		scanf("%d%d", &a[i], &b[i]);
	}
	int ans = 0;
	int d = 0;
	priority_queue<int>q;
	for(int i = 1; i <= n; i++) {
		d += a[i] - b[i];
		ans += abs(d);
		if(d < 0) {
			q.push(0);
			q.push(0);
		}
		else {
			q.push(d);
			q.push(d);
		}
		q.pop();
	}
	while(!q.empty()) {
		int x = q.top();
		q.pop();
		ans -= min(x, d);
	}
	printf("%d\n", ans);
}

Compilation message

bulves.cpp: In function 'int main()':
bulves.cpp:5:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
bulves.cpp:9:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |   scanf("%d%d", &a[i], &b[i]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 376 KB Output is correct
4 Incorrect 15 ms 1416 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 376 KB Output is correct
4 Incorrect 15 ms 1416 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 312 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 376 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 312 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 368 KB Output is correct
14 Incorrect 3 ms 308 KB Output isn't correct
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 376 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Incorrect 15 ms 1416 KB Output isn't correct
12 Halted 0 ms 0 KB -