Submission #332252

#TimeUsernameProblemLanguageResultExecution timeMemory
332252vitkishloh228Gift (IZhO18_nicegift)C++14
30 / 100
2093 ms16300 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...