답안 #331336

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
331336 2020-11-28T03:30:34 Z Nson Potatoes and fertilizers (LMIO19_bulves) C++14
0 / 100
17 ms 748 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

	multiset<ll> s;

	ll m = 0, b = 0;

	s.insert(0);

	auto smooth = [&]() {
		while(!s.empty() and m > 0 and *prev(s.end()) > 0) {
			m--;
			b += *prev(s.end());
			s.erase(prev(s.end()));
		}
	};

	ll d = 0;
	for(int i = 0; i < n; i++) {
		int aa, bb;
		scanf("%d %d", &aa, &bb);
		aa -= bb;
		d += aa;

		smooth();
		if(d >= 0) {
			s.insert(d);
			s.insert(d);
			b -= d;
			m += 1;
		}
		else {
			m += 1;
			b -= d;
		}
		while(!s.empty() and *s.begin() < 0) s.erase(s.begin());
	}

	smooth();

	printf("%lld\n", d * m + b);

}

Compilation message

bulves.cpp: In function 'int main()':
bulves.cpp:8:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    8 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
bulves.cpp:27:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   27 |   scanf("%d %d", &aa, &bb);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 2 ms 620 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Incorrect 17 ms 748 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 2 ms 620 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Incorrect 17 ms 748 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 2 ms 620 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Incorrect 1 ms 364 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 2 ms 620 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Incorrect 1 ms 364 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 2 ms 620 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Incorrect 1 ms 364 KB Output isn't correct
6 Halted 0 ms 0 KB -