Submission #385452

# Submission time Handle Problem Language Result Execution time Memory
385452 2021-04-04T10:38:10 Z vanic Gift (IZhO18_nicegift) C++14
7 / 100
818 ms 99008 KB
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <set>
#include <stack>
#include <map>
#include <queue>
#include <vector>
#include <cstring>
#include <array>
#include <bitset>

using namespace std;
typedef long long ll;

const int maxn=1e6+5;

ll a[maxn];
set < ll > s;
set < pair < ll, int > > s1;
vector < vector < ll > > q;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n, k;
	cin >> n >> k;
	ll sum=0;
	s.insert(0);
	for(int i=0; i<n; i++){
		cin >> a[i];
		sum+=a[i];
		s.insert(a[i]);
		s1.insert({a[i], i});
	}
	if(sum%k){
		cout << -1 << '\n';
		return 0;
	}
	ll val;
	set < pair < ll, int > >::iterator it;
	vector < ll > v;
	vector < pair < ll, int > > ins;
	set < ll >::iterator it1;
	while(!s1.empty()){
		if((int)s1.size()==k){
			it=s1.begin();
			val=it->first;
			v.push_back(val);
			for(int i=0; i<k; i++){
				v.push_back(it->second+1);
				if(val!=it->first){
					cout << -1 << '\n';
					return 0;
				}
				it++;
			}
			s1.clear();
		}
		else{
			it=--s1.end();
			for(int i=0; i<k; i++){
				it--;
			}
			val=it->first;
			it1=s.lower_bound(val);
			it1--;
			val=*it1;
			it++;
			val=it->first-val;
			v.push_back(val);
			it=--s1.end();
			for(int i=0; i<k; i++){
				v.push_back(it->second+1);
				it--;
			}
			it=--s1.end();
			for(int i=0; i<k; i++){
				ins.push_back({it->first-val, it->second});
				it=s1.erase(it);
				it--;
			}
			for(int i=0; i<k;  i++){
				if(ins[i].first){
					s1.insert(ins[i]);
				}
			}
			ins.clear();
			
		}
		q.push_back(v);
		v.clear();
	}
	cout << q.size() << '\n';
	for(int i=0; i<(int)q.size(); i++){
		for(int j=0; j<(int)q[i].size(); j++){
			cout << q[i][j] << ' ';
		}
		cout << '\n';
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Correct 1 ms 364 KB n=8
9 Incorrect 1 ms 364 KB Jury has the answer but participant has not
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Correct 1 ms 364 KB n=8
9 Incorrect 1 ms 364 KB Jury has the answer but participant has not
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 818 ms 99008 KB n=1000000
2 Correct 508 ms 64372 KB n=666666
3 Correct 286 ms 39900 KB n=400000
4 Runtime error 211 ms 45160 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Correct 1 ms 364 KB n=8
9 Incorrect 1 ms 364 KB Jury has the answer but participant has not
10 Halted 0 ms 0 KB -