Submission #335176

# Submission time Handle Problem Language Result Execution time Memory
335176 2020-12-11T11:43:33 Z amunduzbaev Gift (IZhO18_nicegift) C++14
19 / 100
524 ms 108836 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 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 ll inf = 1e18+7;
const int N = 1e6+5;

vector<pair<ll, ll>>v[N];
vector<ll>ans[N]; 
ll a[N];

/*
4 2
2 3 3 2
*/

int main(){
	
	ll n, k, mx = 0, sum = 0;
	scanf("%lld %lld", &n, &k);
	for(int i=0; i<n; i++){
		scanf("%lld", &a[i]);
		mx = max(a[i], mx);
		sum += a[i];
	}
	if(mx * k > sum || sum % k){
		cout<<mx<<" "<<sum<<" "<<-1;
		return 0;
	}		
	
	ll c = 0, cnt = 0;
	ll size = sum/k;
	
	for(int i=0; i<n; i++){
		if(c + a[i] >= size){
			ll x = c + a[i] - size;
			v[cnt++].pb({a[i] - x, i + 1});
			c = x;
			v[cnt].pb({c, i + 1});
        }
		else{
			c += a[i];
			v[cnt].pb({a[i], i+1});
		}
	}
	bool f = 1;
	cnt = 0;
	while(f){
		f = 1;
		ll mn = inf;
		for(int i = 0; i < k; i++)  mn = min(mn, v[i].back().ff);
		ans[cnt].pb(mn);
		for(int i = 0; i < k; i++){
			pll x = v[i].back();
			v[i].pop_back();
			x.ff -= mn;
			ans[cnt].pb(x.ss);
			if(x.ff > 0) v[i].pb(x);
		}
		f &= (!v[0].empty());
		cnt++;
	}
	printf("%lld\n", cnt);
	for(int i = 0; i < cnt; i++){
		for(int j = 0; j < sz(ans[i]); j++){
			printf("%lld ", ans[i][j]);
		}printf("\n");
	}
	return 0;
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:34:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   34 |  scanf("%lld %lld", &n, &k);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~
nicegift.cpp:36:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   36 |   scanf("%lld", &a[i]);
      |   ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 32 ms 47340 KB n=4
2 Correct 33 ms 47340 KB n=3
3 Incorrect 33 ms 47340 KB Integer -1 violates the range [1, 3]
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 32 ms 47340 KB n=4
2 Correct 33 ms 47340 KB n=3
3 Incorrect 33 ms 47340 KB Integer -1 violates the range [1, 3]
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 32 ms 47340 KB n=4
2 Correct 33 ms 47340 KB n=3
3 Incorrect 33 ms 47340 KB Integer -1 violates the range [1, 3]
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 524 ms 108836 KB n=1000000
2 Correct 325 ms 90564 KB n=666666
3 Correct 196 ms 72524 KB n=400000
4 Correct 479 ms 97608 KB n=285714
5 Correct 39 ms 48492 KB n=20000
6 Correct 425 ms 95168 KB n=181818
7 Correct 36 ms 47852 KB n=10000
8 Correct 76 ms 53740 KB n=6666
9 Correct 34 ms 47596 KB n=4000
10 Correct 289 ms 79724 KB n=2857
11 Correct 33 ms 47468 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 32 ms 47340 KB n=4
2 Correct 33 ms 47340 KB n=3
3 Incorrect 33 ms 47340 KB Integer -1 violates the range [1, 3]
4 Halted 0 ms 0 KB -