Submission #961252

# Submission time Handle Problem Language Result Execution time Memory
961252 2024-04-11T18:48:56 Z pragmatist Gift (IZhO18_nicegift) C++17
0 / 100
2000 ms 476 KB
#include<bits/stdc++.h>

using namespace std;

const int N = (int)1e6+7;

int n, k, a[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
	cin >> n >> k;
	long long tot = 0;
	int mx = 0;
	for(int i = 1; i <= n; ++i) {
		cin >> a[i];
		tot += a[i];
		mx = max(mx, a[i]);
	}    
	if(tot%k) {
		cout << "-1\n";
		return 0;
	}
	if(mx>tot/2) {
		cout << "-1\n";
		return 0;
	}
	cout << tot/k << "\n";
	set<pair<int, int> > s;
	for(int i = 1; i <= n; ++i) {
		s.insert({a[i], i});
	}
	for(int i = 1; i <= tot/k; ++i) {
		vector<int> cur;
		for(int j = 0; j < k; ++j) {
			auto it = s.begin();
			cur.push_back(it->second);
			s.erase(it);
		}
		cout << "1 ";
		for(auto id : cur) {
			assert(a[id]>0);
			cout << id << ' ';
		}
		cout << "\n";
		for(auto id : cur) {
			a[id]--;
			if(a[id]>0) {
				s.insert({a[id], id});
			}
		}
	}
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB n=4
2 Execution timed out 2020 ms 344 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB n=4
2 Execution timed out 2020 ms 344 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB n=4
2 Execution timed out 2020 ms 344 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 476 KB Jury has the answer but participant has not
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB n=4
2 Execution timed out 2020 ms 344 KB Time limit exceeded
3 Halted 0 ms 0 KB -