Submission #335571

# Submission time Handle Problem Language Result Execution time Memory
335571 2020-12-13T07:48:54 Z amunduzbaev Gift (IZhO18_nicegift) C++14
30 / 100
247 ms 88004 KB
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define int long long
#define ll long long 
#define ld long double 
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(),x.rend()
#define prc(n) fixed << setprecision(n)
#define fastios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pi acos(-1);
const int inf = 1e9+7;
const int N = 5e5+5;
vector<pll> ans[N];
vector<ll> aa[N];
int a[N];

void solve(){
	
	int n, k, sum = 0, mx = 0, f = 1;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>a[i];
		sum += a[i];
		mx  = max(a[i], mx);
	}
	if(sum % k || sum < mx * k){
		cout<<-1<<"\n";
		return;
	}
	int cur = 0, cnt = 0, tmp = sum / k;
	for(int i=0;i<n;i++){
		if(cur + a[i] > tmp){
			ans[cnt].pb({tmp - cur, i+1});
			cnt++;
			ans[cnt].pb({cur + a[i] - tmp, i+1});
			cur = cur + a[i] - tmp;
		}else if(cur + a[i] == tmp){
			ans[cnt].pb({a[i], i+1});
			cnt++;
			cur = 0;
		}else{
			cur += a[i];
			ans[cnt].pb({a[i], i+1});
		}
	}
	cnt = 0;
	while(f){
		f = 0;
		int mn = 9e18;
		for(int i=0;i<k;i++)
			mn = min(ans[i].back().ff, mn);
		
		aa[cnt].pb(mn);
		
		for(int i=0;i<k;i++){
			pll tmp1 = ans[i].back();
			ans[i].pop_back();
			tmp1.ff -= mn;
			aa[cnt].pb(tmp1.ss);
			if(tmp1.ff > 0) ans[i].pb(tmp1);
		}
		f |= !ans[0].empty();
		cnt++;
	}
	cout<<cnt<<"\n";
	for(int i=0; i<cnt; i++){
		for(int j=0; j<sz(aa[i]); j++){
			cout<<aa[i][j]<<" ";
		}cout<<"\n";
	}
	
	return;
}



main(){
	fastios
	int t = 1;
	//cin>>t;
	while(t--) solve();
	return 0;
}

Compilation message

nicegift.cpp:86:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   86 | main(){
      |      ^
# Verdict Execution time Memory Grader output
1 Correct 18 ms 23788 KB n=4
2 Correct 20 ms 23788 KB n=3
3 Correct 19 ms 23788 KB n=3
4 Correct 19 ms 23788 KB n=4
5 Correct 17 ms 23788 KB n=4
6 Correct 16 ms 23788 KB n=2
# Verdict Execution time Memory Grader output
1 Correct 18 ms 23788 KB n=4
2 Correct 20 ms 23788 KB n=3
3 Correct 19 ms 23788 KB n=3
4 Correct 19 ms 23788 KB n=4
5 Correct 17 ms 23788 KB n=4
6 Correct 16 ms 23788 KB n=2
7 Correct 17 ms 23788 KB n=5
8 Correct 18 ms 23788 KB n=8
9 Correct 16 ms 23788 KB n=14
10 Correct 19 ms 23788 KB n=11
11 Correct 41 ms 27624 KB n=50000
12 Correct 40 ms 27516 KB n=50000
13 Correct 17 ms 23788 KB n=10
14 Correct 17 ms 23916 KB n=685
15 Correct 17 ms 23916 KB n=623
16 Correct 17 ms 23916 KB n=973
# Verdict Execution time Memory Grader output
1 Correct 18 ms 23788 KB n=4
2 Correct 20 ms 23788 KB n=3
3 Correct 19 ms 23788 KB n=3
4 Correct 19 ms 23788 KB n=4
5 Correct 17 ms 23788 KB n=4
6 Correct 16 ms 23788 KB n=2
7 Correct 17 ms 23788 KB n=5
8 Correct 18 ms 23788 KB n=8
9 Correct 16 ms 23788 KB n=14
10 Correct 19 ms 23788 KB n=11
11 Correct 41 ms 27624 KB n=50000
12 Correct 40 ms 27516 KB n=50000
13 Correct 17 ms 23788 KB n=10
14 Correct 17 ms 23916 KB n=685
15 Correct 17 ms 23916 KB n=623
16 Correct 17 ms 23916 KB n=973
17 Correct 17 ms 23864 KB n=989
18 Correct 17 ms 23916 KB n=563
19 Correct 19 ms 24044 KB n=592
20 Correct 18 ms 24044 KB n=938
21 Correct 17 ms 24044 KB n=747
22 Correct 18 ms 24044 KB n=991
# Verdict Execution time Memory Grader output
1 Runtime error 247 ms 88004 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 18 ms 23788 KB n=4
2 Correct 20 ms 23788 KB n=3
3 Correct 19 ms 23788 KB n=3
4 Correct 19 ms 23788 KB n=4
5 Correct 17 ms 23788 KB n=4
6 Correct 16 ms 23788 KB n=2
7 Correct 17 ms 23788 KB n=5
8 Correct 18 ms 23788 KB n=8
9 Correct 16 ms 23788 KB n=14
10 Correct 19 ms 23788 KB n=11
11 Correct 41 ms 27624 KB n=50000
12 Correct 40 ms 27516 KB n=50000
13 Correct 17 ms 23788 KB n=10
14 Correct 17 ms 23916 KB n=685
15 Correct 17 ms 23916 KB n=623
16 Correct 17 ms 23916 KB n=973
17 Correct 17 ms 23864 KB n=989
18 Correct 17 ms 23916 KB n=563
19 Correct 19 ms 24044 KB n=592
20 Correct 18 ms 24044 KB n=938
21 Correct 17 ms 24044 KB n=747
22 Correct 18 ms 24044 KB n=991
23 Runtime error 247 ms 88004 KB Execution killed with signal 11 (could be triggered by violating memory limits)
24 Halted 0 ms 0 KB -