Submission #529451

# Submission time Handle Problem Language Result Execution time Memory
529451 2022-02-23T03:10:17 Z penguinhacker Akcija (COCI21_akcija) C++14
90 / 110
5000 ms 21044 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ar array

const int mxN=2000;
int n, k;
ar<int, 2> a[mxN];
vector<vector<ll>> dp;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> k;
	for (int i=0; i<n; ++i)
		cin >> a[i][1] >> a[i][0];
	sort(a, a+n);
	dp.push_back({a[0][1]});
	for (int i=1; i<n; ++i) {
		// extend max elements
		int old_sz=dp.size();
		if (dp.size()<a[i][0]) {
			vector<ll> t=dp.back();
			for (ll& x : t)
				x+=a[i][1];
			dp.push_back(t);
		}
		for (int j=old_sz-1; j; --j) { // update dp[j] with possible better elements from dp[j-1]
			vector<ll> t;
			t.reserve(k);
			for (int x=0, y=0; t.size()<k&&(x<dp[j-1].size()||y<dp[j].size());) {
				if (y==dp[j].size()||(x<dp[j-1].size()&&dp[j-1][x]+a[i][1]<=dp[j][y]))
					t.push_back(dp[j-1][x++]+a[i][1]);
				else
					t.push_back(dp[j][y++]);
			}
			swap(dp[j], t);
		}
		// update only 1
		if (dp[0].size()==k&&a[i][1]<dp[0].back())
			dp[0].pop_back();
		dp[0].insert(lower_bound(dp[0].begin(), dp[0].end(), a[i][1]), a[i][1]);
	}
	for (int i=dp.size()-1, j=0; ~i&&k; --k) {
		cout << i+1 << " " << dp[i][j++] << "\n";
		if (j==dp[i].size())
			--i, j=0;
	}
	if (k)
		cout << "0 0";
	return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:23:16: warning: comparison of integer expressions of different signedness: 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} and 'std::array<int, 2>::value_type' {aka 'int'} [-Wsign-compare]
   23 |   if (dp.size()<a[i][0]) {
Main.cpp:32:31: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   32 |    for (int x=0, y=0; t.size()<k&&(x<dp[j-1].size()||y<dp[j].size());) {
      |                       ~~~~~~~~^~
Main.cpp:32:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |    for (int x=0, y=0; t.size()<k&&(x<dp[j-1].size()||y<dp[j].size());) {
      |                                    ~^~~~~~~~~~~~~~~
Main.cpp:32:55: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |    for (int x=0, y=0; t.size()<k&&(x<dp[j-1].size()||y<dp[j].size());) {
      |                                                      ~^~~~~~~~~~~~~
Main.cpp:33:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     if (y==dp[j].size()||(x<dp[j-1].size()&&dp[j-1][x]+a[i][1]<=dp[j][y]))
      |         ~^~~~~~~~~~~~~~
Main.cpp:33:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     if (y==dp[j].size()||(x<dp[j-1].size()&&dp[j-1][x]+a[i][1]<=dp[j][y]))
      |                           ~^~~~~~~~~~~~~~~
Main.cpp:41:19: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   41 |   if (dp[0].size()==k&&a[i][1]<dp[0].back())
      |       ~~~~~~~~~~~~^~~
Main.cpp:47:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |   if (j==dp[i].size())
      |       ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 36 ms 452 KB Output is correct
2 Correct 39 ms 420 KB Output is correct
3 Correct 32 ms 452 KB Output is correct
4 Correct 32 ms 452 KB Output is correct
5 Correct 39 ms 472 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 16 ms 328 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 316 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 452 KB Output is correct
2 Correct 39 ms 420 KB Output is correct
3 Correct 32 ms 452 KB Output is correct
4 Correct 32 ms 452 KB Output is correct
5 Correct 39 ms 472 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 16 ms 328 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 316 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 40 ms 460 KB Output is correct
15 Correct 43 ms 460 KB Output is correct
16 Correct 34 ms 456 KB Output is correct
17 Correct 34 ms 404 KB Output is correct
18 Correct 39 ms 464 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 2 ms 332 KB Output is correct
23 Correct 13 ms 588 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 0 ms 204 KB Output is correct
26 Correct 1 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 464 KB Output is correct
2 Correct 49 ms 456 KB Output is correct
3 Correct 40 ms 460 KB Output is correct
4 Correct 43 ms 340 KB Output is correct
5 Correct 47 ms 448 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 12 ms 460 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 316 KB Output is correct
13 Correct 0 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 588 KB Output is correct
2 Correct 2 ms 588 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 2 ms 576 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 312 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 312 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 2 ms 356 KB Output is correct
6 Correct 0 ms 316 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 312 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 452 KB Output is correct
2 Correct 39 ms 420 KB Output is correct
3 Correct 32 ms 452 KB Output is correct
4 Correct 32 ms 452 KB Output is correct
5 Correct 39 ms 472 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 16 ms 328 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 316 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 40 ms 460 KB Output is correct
15 Correct 43 ms 460 KB Output is correct
16 Correct 34 ms 456 KB Output is correct
17 Correct 34 ms 404 KB Output is correct
18 Correct 39 ms 464 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 2 ms 332 KB Output is correct
23 Correct 13 ms 588 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 0 ms 204 KB Output is correct
26 Correct 1 ms 316 KB Output is correct
27 Correct 45 ms 464 KB Output is correct
28 Correct 49 ms 456 KB Output is correct
29 Correct 40 ms 460 KB Output is correct
30 Correct 43 ms 340 KB Output is correct
31 Correct 47 ms 448 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 2 ms 332 KB Output is correct
36 Correct 12 ms 460 KB Output is correct
37 Correct 1 ms 204 KB Output is correct
38 Correct 0 ms 316 KB Output is correct
39 Correct 0 ms 316 KB Output is correct
40 Correct 2 ms 588 KB Output is correct
41 Correct 2 ms 588 KB Output is correct
42 Correct 1 ms 460 KB Output is correct
43 Correct 1 ms 460 KB Output is correct
44 Correct 2 ms 576 KB Output is correct
45 Correct 0 ms 204 KB Output is correct
46 Correct 1 ms 332 KB Output is correct
47 Correct 1 ms 332 KB Output is correct
48 Correct 1 ms 332 KB Output is correct
49 Correct 1 ms 312 KB Output is correct
50 Correct 0 ms 204 KB Output is correct
51 Correct 1 ms 332 KB Output is correct
52 Correct 1 ms 460 KB Output is correct
53 Correct 2 ms 312 KB Output is correct
54 Correct 2 ms 332 KB Output is correct
55 Correct 2 ms 332 KB Output is correct
56 Correct 2 ms 332 KB Output is correct
57 Correct 2 ms 356 KB Output is correct
58 Correct 0 ms 316 KB Output is correct
59 Correct 1 ms 204 KB Output is correct
60 Correct 1 ms 204 KB Output is correct
61 Correct 1 ms 204 KB Output is correct
62 Correct 1 ms 332 KB Output is correct
63 Correct 1 ms 312 KB Output is correct
64 Correct 1 ms 204 KB Output is correct
65 Correct 1 ms 332 KB Output is correct
66 Execution timed out 5074 ms 21044 KB Time limit exceeded
67 Halted 0 ms 0 KB -