Submission #332252

# Submission time Handle Problem Language Result Execution time Memory
332252 2020-12-01T19:21:18 Z vitkishloh228 Gift (IZhO18_nicegift) C++14
30 / 100
2000 ms 16300 KB
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<stack>
#include<queue>
using namespace std;
int main() {
	int n, k, t, cnt = 0, sum = 0, mx = -1;
    cin >> n >> k;
	priority_queue<pair<int, int> > pq, pq1;
	for (int i = 0; i < n; i++) { 
		scanf("%d", &t); 
		mx = max(mx, t);
		sum += t;
		pq.push(make_pair(t, i + 1));
		pq1.push(make_pair(t, i + 1)); 
	}
	while (pq.size() >= k)
	{
		stack<pair<int, int> > st;
		for (int i = 0; i < k; i++) {
			st.push(pq.top());
			pq.pop();
		}
		for (int i = 0; i < k; i++) { 
			st.top().first--;
			if (st.top().first != 0) pq.push(st.top());
			st.pop();
		}
		cnt++;
	}
	if ((sum - mx) < (k - 1) * mx) { 
		printf("-1"); 
		return 0;
	}
	printf("%d\n", cnt);
	while (pq1.size() >= k)
	{
		printf("1 ");
		stack<pair<int, int> > st;
		for (int i = 0; i < k; i++) { st.push(pq1.top()); pq1.pop(); }
		for (int i = 0; i < k; i++) { st.top().first--; if (st.top().first != 0) pq1.push(st.top()); printf("%d ", st.top().second); st.pop(); }
		printf("\n");
	}
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:19:19: warning: comparison of integer expressions of different signedness: 'std::priority_queue<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   19 |  while (pq.size() >= k)
      |         ~~~~~~~~~~^~~~
nicegift.cpp:38:20: warning: comparison of integer expressions of different signedness: 'std::priority_queue<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   38 |  while (pq1.size() >= k)
      |         ~~~~~~~~~~~^~~~
nicegift.cpp:13:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   13 |   scanf("%d", &t);
      |   ~~~~~^~~~~~~~~~
# 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 364 KB n=8
9 Correct 9 ms 492 KB n=14
10 Correct 5 ms 364 KB n=11
11 Correct 52 ms 2144 KB n=50000
12 Correct 50 ms 2144 KB n=50000
13 Correct 30 ms 748 KB n=10
14 Correct 32 ms 748 KB n=685
15 Correct 35 ms 876 KB n=623
16 Correct 20 ms 620 KB n=973
# 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 364 KB n=8
9 Correct 9 ms 492 KB n=14
10 Correct 5 ms 364 KB n=11
11 Correct 52 ms 2144 KB n=50000
12 Correct 50 ms 2144 KB n=50000
13 Correct 30 ms 748 KB n=10
14 Correct 32 ms 748 KB n=685
15 Correct 35 ms 876 KB n=623
16 Correct 20 ms 620 KB n=973
17 Correct 33 ms 876 KB n=989
18 Correct 16 ms 620 KB n=563
19 Correct 27 ms 748 KB n=592
20 Correct 27 ms 748 KB n=938
21 Correct 21 ms 620 KB n=747
22 Correct 23 ms 620 KB n=991
# Verdict Execution time Memory Grader output
1 Execution timed out 2093 ms 16300 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 364 KB n=8
9 Correct 9 ms 492 KB n=14
10 Correct 5 ms 364 KB n=11
11 Correct 52 ms 2144 KB n=50000
12 Correct 50 ms 2144 KB n=50000
13 Correct 30 ms 748 KB n=10
14 Correct 32 ms 748 KB n=685
15 Correct 35 ms 876 KB n=623
16 Correct 20 ms 620 KB n=973
17 Correct 33 ms 876 KB n=989
18 Correct 16 ms 620 KB n=563
19 Correct 27 ms 748 KB n=592
20 Correct 27 ms 748 KB n=938
21 Correct 21 ms 620 KB n=747
22 Correct 23 ms 620 KB n=991
23 Execution timed out 2093 ms 16300 KB Time limit exceeded
24 Halted 0 ms 0 KB -