Submission #787636

# Submission time Handle Problem Language Result Execution time Memory
787636 2023-07-19T10:33:56 Z willychan Gift (IZhO18_nicegift) C++14
30 / 100
360 ms 66748 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]);
	}
	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);
	}
	if(sum){
		cout<<-1<<"\n";
		return 0;
	}
	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:26: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]
   26 |  while(pq.size()>=k){
      |        ~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB n=4
2 Correct 0 ms 212 KB n=3
3 Correct 0 ms 212 KB n=3
4 Correct 0 ms 212 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 0 ms 212 KB n=4
2 Correct 0 ms 212 KB n=3
3 Correct 0 ms 212 KB n=3
4 Correct 0 ms 212 KB n=4
5 Correct 0 ms 212 KB n=4
6 Correct 0 ms 212 KB n=2
7 Correct 1 ms 212 KB n=5
8 Correct 0 ms 224 KB n=8
9 Correct 0 ms 212 KB n=14
10 Correct 0 ms 212 KB n=11
11 Correct 18 ms 2904 KB n=50000
12 Correct 15 ms 2640 KB n=50000
13 Correct 0 ms 212 KB n=10
14 Correct 1 ms 340 KB n=685
15 Correct 1 ms 340 KB n=623
16 Correct 1 ms 340 KB n=973
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB n=4
2 Correct 0 ms 212 KB n=3
3 Correct 0 ms 212 KB n=3
4 Correct 0 ms 212 KB n=4
5 Correct 0 ms 212 KB n=4
6 Correct 0 ms 212 KB n=2
7 Correct 1 ms 212 KB n=5
8 Correct 0 ms 224 KB n=8
9 Correct 0 ms 212 KB n=14
10 Correct 0 ms 212 KB n=11
11 Correct 18 ms 2904 KB n=50000
12 Correct 15 ms 2640 KB n=50000
13 Correct 0 ms 212 KB n=10
14 Correct 1 ms 340 KB n=685
15 Correct 1 ms 340 KB n=623
16 Correct 1 ms 340 KB n=973
17 Correct 1 ms 340 KB n=989
18 Correct 1 ms 212 KB n=563
19 Correct 1 ms 340 KB n=592
20 Correct 1 ms 340 KB n=938
21 Correct 1 ms 340 KB n=747
22 Correct 1 ms 340 KB n=991
# Verdict Execution time Memory Grader output
1 Incorrect 360 ms 66748 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 212 KB n=4
2 Correct 0 ms 212 KB n=3
3 Correct 0 ms 212 KB n=3
4 Correct 0 ms 212 KB n=4
5 Correct 0 ms 212 KB n=4
6 Correct 0 ms 212 KB n=2
7 Correct 1 ms 212 KB n=5
8 Correct 0 ms 224 KB n=8
9 Correct 0 ms 212 KB n=14
10 Correct 0 ms 212 KB n=11
11 Correct 18 ms 2904 KB n=50000
12 Correct 15 ms 2640 KB n=50000
13 Correct 0 ms 212 KB n=10
14 Correct 1 ms 340 KB n=685
15 Correct 1 ms 340 KB n=623
16 Correct 1 ms 340 KB n=973
17 Correct 1 ms 340 KB n=989
18 Correct 1 ms 212 KB n=563
19 Correct 1 ms 340 KB n=592
20 Correct 1 ms 340 KB n=938
21 Correct 1 ms 340 KB n=747
22 Correct 1 ms 340 KB n=991
23 Incorrect 360 ms 66748 KB Jury has the answer but participant has not
24 Halted 0 ms 0 KB -