Submission #787620

# Submission time Handle Problem Language Result Execution time Memory
787620 2023-07-19T10:28:18 Z willychan Gift (IZhO18_nicegift) C++14
30 / 100
28 ms 4172 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include<bits/extc++.h>
//__gnu_pbds




int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int n,k;cin>>n>>k;
	ll sum=0;
	vector<int> arr(n);
	int maxn = 0;
	for(int i=0;i<n;i++){
		cin>>arr[i];
		sum+=arr[i];
		maxn = max(maxn,arr[i]);
	}
	if(sum%k){
		cout<<-1<<"\n";
		return 0;
	}
	if(maxn>sum/k){
		cout<<-1<<"\n";
		return 0;
	}
	priority_queue<pair<int,int> > pq;
	for(int i=0;i<n;i++){
		pq.push({arr[i],i});
	}
	vector<vector<int>> ans;
	while(pq.size()>=k){
		vector<int> v(k);
		ll tomi = LONG_LONG_MAX;
		for(int i=0;i<k;i++){
			v[i] = pq.top().second;
			tomi = pq.top().first;
			pq.pop();
		}
		if(pq.size()) tomi = min(tomi,(sum/k)-pq.top().first);
		sum-=k*tomi;
		vector<int> tempans;
		tempans.push_back(tomi);
		for(auto i : v){
			tempans.push_back(i+1);	
			arr[i]-=tomi;
			if(arr[i]) pq.push({arr[i],i});
		}
		ans.push_back(tempans);
	}
	cout<<ans.size()<<"\n";
	for(auto ar : ans){
		for(auto v : ar){
			cout<<v<<" ";
		}
		cout<<"\n";
	}
	return 0;
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:34:17: 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]
   34 |  while(pq.size()>=k){
      |        ~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB n=4
2 Correct 1 ms 320 KB n=3
3 Correct 0 ms 316 KB n=3
4 Correct 1 ms 324 KB n=4
5 Correct 0 ms 212 KB n=4
6 Correct 0 ms 212 KB n=2
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB n=4
2 Correct 1 ms 320 KB n=3
3 Correct 0 ms 316 KB n=3
4 Correct 1 ms 324 KB n=4
5 Correct 0 ms 212 KB n=4
6 Correct 0 ms 212 KB n=2
7 Correct 0 ms 212 KB n=5
8 Correct 1 ms 212 KB n=8
9 Correct 1 ms 212 KB n=14
10 Correct 1 ms 316 KB n=11
11 Correct 28 ms 3012 KB n=50000
12 Correct 16 ms 2676 KB n=50000
13 Correct 0 ms 320 KB n=10
14 Correct 1 ms 340 KB n=685
15 Correct 1 ms 320 KB n=623
16 Correct 1 ms 320 KB n=973
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB n=4
2 Correct 1 ms 320 KB n=3
3 Correct 0 ms 316 KB n=3
4 Correct 1 ms 324 KB n=4
5 Correct 0 ms 212 KB n=4
6 Correct 0 ms 212 KB n=2
7 Correct 0 ms 212 KB n=5
8 Correct 1 ms 212 KB n=8
9 Correct 1 ms 212 KB n=14
10 Correct 1 ms 316 KB n=11
11 Correct 28 ms 3012 KB n=50000
12 Correct 16 ms 2676 KB n=50000
13 Correct 0 ms 320 KB n=10
14 Correct 1 ms 340 KB n=685
15 Correct 1 ms 320 KB n=623
16 Correct 1 ms 320 KB n=973
17 Correct 1 ms 340 KB n=989
18 Correct 1 ms 340 KB n=563
19 Correct 1 ms 340 KB n=592
20 Correct 1 ms 340 KB n=938
21 Correct 1 ms 324 KB n=747
22 Correct 1 ms 340 KB n=991
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 4172 KB Jury has the answer but participant has not
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB n=4
2 Correct 1 ms 320 KB n=3
3 Correct 0 ms 316 KB n=3
4 Correct 1 ms 324 KB n=4
5 Correct 0 ms 212 KB n=4
6 Correct 0 ms 212 KB n=2
7 Correct 0 ms 212 KB n=5
8 Correct 1 ms 212 KB n=8
9 Correct 1 ms 212 KB n=14
10 Correct 1 ms 316 KB n=11
11 Correct 28 ms 3012 KB n=50000
12 Correct 16 ms 2676 KB n=50000
13 Correct 0 ms 320 KB n=10
14 Correct 1 ms 340 KB n=685
15 Correct 1 ms 320 KB n=623
16 Correct 1 ms 320 KB n=973
17 Correct 1 ms 340 KB n=989
18 Correct 1 ms 340 KB n=563
19 Correct 1 ms 340 KB n=592
20 Correct 1 ms 340 KB n=938
21 Correct 1 ms 324 KB n=747
22 Correct 1 ms 340 KB n=991
23 Incorrect 8 ms 4172 KB Jury has the answer but participant has not
24 Halted 0 ms 0 KB -