Submission #343323

# Submission time Handle Problem Language Result Execution time Memory
343323 2021-01-03T16:37:28 Z Sprdalo Gift (IZhO18_nicegift) C++17
7 / 100
2000 ms 8300 KB
/*
	Zharaskhan
	stupid ver. 1
*/
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int MAXN = 1e6;
pair <int, int> a[MAXN];
vector< vector< int > > ans;

int main() {
	int n, k;
	scanf("%d%d", &n, &k);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i].first);
		a[i].second = i + 1;
	}
	bool good = true;
	vector <int> res;
	res.resize(k + 1);
	while (true) {
		sort(a , a + n, greater <pair <int, int> > ());
		for (int i = 0; i < k; i++) {
			if (a[i].first == 0) {
				good = false;
				break;
			}
		}


		if (!good) {
			break;
		}
		int dff = 1;
		res[0] = dff;
		for (int i = 0; i < k; i++) {
			a[i].first -= dff;
			res[i + 1] = a[i].second;
		}
		ans.push_back(res);

	}
	for (int i = 0; i < n; i++) {
		if (a[i].first > 0) {
			printf("-1\n");
			return 0;
		}
	}
 	printf("%d\n", (int)ans.size());
	for (int i = 0; i < ans.size(); i++) {
		for (int j = 0; j <= k; j++) {
			printf("%d ", ans[i][j]);
		}
		printf("\n");
	}


	return 0;
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:52:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |  for (int i = 0; i < ans.size(); i++) {
      |                  ~~^~~~~~~~~~~~
nicegift.cpp:15:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   15 |  scanf("%d%d", &n, &k);
      |  ~~~~~^~~~~~~~~~~~~~~~
nicegift.cpp:17:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   17 |   scanf("%d", &a[i].first);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Correct 2 ms 1132 KB n=8
9 Correct 8 ms 1192 KB n=14
10 Correct 7 ms 1004 KB n=11
11 Execution timed out 2074 ms 1264 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Correct 2 ms 1132 KB n=8
9 Correct 8 ms 1192 KB n=14
10 Correct 7 ms 1004 KB n=11
11 Execution timed out 2074 ms 1264 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2084 ms 8300 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Correct 2 ms 1132 KB n=8
9 Correct 8 ms 1192 KB n=14
10 Correct 7 ms 1004 KB n=11
11 Execution timed out 2074 ms 1264 KB Time limit exceeded
12 Halted 0 ms 0 KB -