답안 #962419

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
962419 2024-04-13T13:36:26 Z pragmatist Gift (IZhO18_nicegift) C++17
7 / 100
2000 ms 374420 KB
#include<bits/stdc++.h>

using namespace std;

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

int n, k;
long long a[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
	cin >> n >> k;
	long long tot = 0;
	for(int i = 1; i <= n; ++i) {
		cin >> a[i];
		tot += a[i];
	}    
	priority_queue<pair<long long, int> > s;
	for(int i = 1; i <= n; ++i) {
		s.push({a[i], i});
	}
	vector<vector<long long> > ans;
	vector<long long> v;
	while((int)s.size()>=k) {
		vector<int> cur;       
		for(int j = 0; j < k; ++j) {
			cur.push_back(s.top().second);
			s.pop();
		}
		int can = a[cur.back()];
		v = {can};
		for(auto id : cur) {
			assert(a[id]>=can);
			v.push_back(id);
		}
		ans.push_back(v);
		for(auto id : cur) {
			a[id] -= can;
			if(a[id]>0) {
				s.push({a[id], id});
			}
		}
	}
	if(!s.empty()) {
		cout << "-1\n";
		return 0;
	}
	cout << (int)ans.size() << "\n";
	for(auto x : ans) {
		for(auto y : x) {
			cout << y << ' ';
		}
		cout << "\n";
	}
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB n=4
2 Correct 0 ms 344 KB n=3
3 Correct 0 ms 348 KB n=3
4 Correct 1 ms 348 KB n=4
5 Correct 0 ms 348 KB n=4
6 Correct 0 ms 348 KB n=2
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB n=4
2 Correct 0 ms 344 KB n=3
3 Correct 0 ms 348 KB n=3
4 Correct 1 ms 348 KB n=4
5 Correct 0 ms 348 KB n=4
6 Correct 0 ms 348 KB n=2
7 Correct 1 ms 348 KB n=5
8 Correct 0 ms 344 KB n=8
9 Incorrect 1 ms 348 KB Jury has the answer but participant has not
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB n=4
2 Correct 0 ms 344 KB n=3
3 Correct 0 ms 348 KB n=3
4 Correct 1 ms 348 KB n=4
5 Correct 0 ms 348 KB n=4
6 Correct 0 ms 348 KB n=2
7 Correct 1 ms 348 KB n=5
8 Correct 0 ms 344 KB n=8
9 Incorrect 1 ms 348 KB Jury has the answer but participant has not
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2044 ms 374420 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB n=4
2 Correct 0 ms 344 KB n=3
3 Correct 0 ms 348 KB n=3
4 Correct 1 ms 348 KB n=4
5 Correct 0 ms 348 KB n=4
6 Correct 0 ms 348 KB n=2
7 Correct 1 ms 348 KB n=5
8 Correct 0 ms 344 KB n=8
9 Incorrect 1 ms 348 KB Jury has the answer but participant has not
10 Halted 0 ms 0 KB -