답안 #615514

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
615514 2022-07-31T10:00:25 Z rsjw Potatoes and fertilizers (LMIO19_bulves) C++17
100 / 100
799 ms 85368 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
struct Function {
	multiset<int> s;
	int k, p;
	Function(int a, int b) { k = a, p = b; }
	void reset(int a, int b) { s.clear(), k = a, p = b; }
	void prefix() {
		if (k <= 0)
			return;
		if (s.size() < k)
			assert(0);
		auto it = s.end();
		int c = k;
		while (c--) {
			it--;
			k--, p += *it;
			s.erase(it);
		}
	}
	void merge(Function x) {
		for (auto ele : x.s)
			s.insert(ele);
		k += x.k, p += x.p;
	}
};

int A[500010], B[500010];

void get() {
	int n, i, x;
	cin >> n;
	for (i = 1; i <= n; i++)
		cin >> A[i] >> B[i], A[i] += A[i - 1], B[i] += B[i - 1];
	Function a(0, 0);
	for (i = 1; i <= n * 2; i++)
		a.s.insert(0);
	Function h(0, 0);
	int ext = 0;
	for (i = 1; i < n; i++) {
		x = A[i] - B[i];
		if (x > A[n] - B[n]) {
			ext += (x - A[n] + B[n]);
			x = A[n] - B[n];
		}
		// printf(" %lld ", x);
		h.reset(1, -x);
		h.s.insert(x);
		h.s.insert(x);

		a.merge(h);
		a.prefix();
	}
	cout << ext + a.p;
	return;
}
signed main() {
	ios::sync_with_stdio(false);
	cout.tie(NULL);
	int T;
	T = 1;
	while (T--)
		get();
	return 0;
}

Compilation message

bulves.cpp: In member function 'void Function::prefix()':
bulves.cpp:12:16: warning: comparison of integer expressions of different signedness: 'std::multiset<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   12 |   if (s.size() < k)
      |       ~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 3 ms 724 KB Output is correct
3 Correct 3 ms 732 KB Output is correct
4 Correct 56 ms 8384 KB Output is correct
5 Correct 104 ms 16508 KB Output is correct
6 Correct 321 ms 42868 KB Output is correct
7 Correct 678 ms 85292 KB Output is correct
8 Correct 697 ms 83460 KB Output is correct
9 Correct 799 ms 82800 KB Output is correct
10 Correct 679 ms 80432 KB Output is correct
11 Correct 703 ms 80472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 3 ms 724 KB Output is correct
3 Correct 3 ms 732 KB Output is correct
4 Correct 56 ms 8384 KB Output is correct
5 Correct 104 ms 16508 KB Output is correct
6 Correct 321 ms 42868 KB Output is correct
7 Correct 678 ms 85292 KB Output is correct
8 Correct 697 ms 83460 KB Output is correct
9 Correct 799 ms 82800 KB Output is correct
10 Correct 679 ms 80432 KB Output is correct
11 Correct 703 ms 80472 KB Output is correct
12 Correct 177 ms 21580 KB Output is correct
13 Correct 445 ms 51312 KB Output is correct
14 Correct 788 ms 85272 KB Output is correct
15 Correct 710 ms 83360 KB Output is correct
16 Correct 639 ms 82712 KB Output is correct
17 Correct 570 ms 80492 KB Output is correct
18 Correct 3 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 3 ms 724 KB Output is correct
3 Correct 3 ms 724 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 5 ms 760 KB Output is correct
8 Correct 3 ms 724 KB Output is correct
9 Correct 4 ms 724 KB Output is correct
10 Correct 3 ms 720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 3 ms 724 KB Output is correct
3 Correct 3 ms 732 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 5 ms 760 KB Output is correct
8 Correct 3 ms 724 KB Output is correct
9 Correct 4 ms 724 KB Output is correct
10 Correct 3 ms 720 KB Output is correct
11 Correct 3 ms 724 KB Output is correct
12 Correct 2 ms 596 KB Output is correct
13 Correct 3 ms 852 KB Output is correct
14 Correct 3 ms 852 KB Output is correct
15 Correct 3 ms 748 KB Output is correct
16 Correct 2 ms 768 KB Output is correct
17 Correct 3 ms 724 KB Output is correct
18 Correct 3 ms 856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 3 ms 724 KB Output is correct
3 Correct 3 ms 732 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 5 ms 760 KB Output is correct
8 Correct 3 ms 724 KB Output is correct
9 Correct 4 ms 724 KB Output is correct
10 Correct 3 ms 720 KB Output is correct
11 Correct 56 ms 8384 KB Output is correct
12 Correct 104 ms 16508 KB Output is correct
13 Correct 321 ms 42868 KB Output is correct
14 Correct 678 ms 85292 KB Output is correct
15 Correct 697 ms 83460 KB Output is correct
16 Correct 799 ms 82800 KB Output is correct
17 Correct 679 ms 80432 KB Output is correct
18 Correct 703 ms 80472 KB Output is correct
19 Correct 177 ms 21580 KB Output is correct
20 Correct 445 ms 51312 KB Output is correct
21 Correct 788 ms 85272 KB Output is correct
22 Correct 710 ms 83360 KB Output is correct
23 Correct 639 ms 82712 KB Output is correct
24 Correct 570 ms 80492 KB Output is correct
25 Correct 2 ms 596 KB Output is correct
26 Correct 3 ms 852 KB Output is correct
27 Correct 3 ms 852 KB Output is correct
28 Correct 3 ms 748 KB Output is correct
29 Correct 2 ms 768 KB Output is correct
30 Correct 3 ms 724 KB Output is correct
31 Correct 3 ms 856 KB Output is correct
32 Correct 3 ms 724 KB Output is correct
33 Correct 151 ms 21684 KB Output is correct
34 Correct 447 ms 51292 KB Output is correct
35 Correct 711 ms 85312 KB Output is correct
36 Correct 776 ms 82932 KB Output is correct
37 Correct 659 ms 83432 KB Output is correct
38 Correct 669 ms 85368 KB Output is correct
39 Correct 625 ms 81488 KB Output is correct
40 Correct 515 ms 73992 KB Output is correct
41 Correct 612 ms 80616 KB Output is correct
42 Correct 608 ms 80536 KB Output is correct
43 Correct 605 ms 80472 KB Output is correct
44 Correct 595 ms 80424 KB Output is correct
45 Correct 719 ms 85288 KB Output is correct
46 Correct 608 ms 80856 KB Output is correct
47 Correct 509 ms 63968 KB Output is correct