Submission #47815

# Submission time Handle Problem Language Result Execution time Memory
47815 2018-05-07T17:18:43 Z dqhungdl Gift (IZhO18_nicegift) C++17
0 / 100
2000 ms 189728 KB
#include <bits/stdc++.h>
using namespace std;

typedef pair<int64_t,int64_t> ii;
int64_t n,k,top=0,a[1000005],rs[3000005];
vector<int64_t> g[3000005];
set<ii> s;

int main()
{
	ios_base::sync_with_stdio(false);
	//freopen("TEST.INP","r",stdin);
	//freopen("TEST.OUT","w",stdout);
	cin>>n>>k;
	int64_t sum=0,maxn=0;
	for(int64_t i=1;i<=n;i++)
	{
		cin>>a[i];
		sum+=a[i];
		maxn=max(maxn,a[i]);
		s.insert(ii(a[i],i));
	}
	if(sum%k!=0||maxn>sum/k)
	{
		cout<<-1;
		return 0;
	}
	int64_t ave=sum/k;
	while(s.size()>0)
	{
		vector<int64_t> TMP;
		for(int64_t i=1;i<=k;i++)
		{
			int64_t u=(*s.rbegin()).second;
			s.erase(s.find(*s.rbegin()));
			TMP.push_back(u);
		}
		int64_t tmp=0;
		if(s.size()>0)
			tmp=(*s.rbegin()).first;
		int64_t lim=min(TMP.back(),ave-tmp);
		rs[++top]=lim;
		g[top]=TMP;
		for(int64_t i=0;i<TMP.size();i++)
		{
			a[TMP[i]]-=lim;
			if(a[TMP[i]]>0)
				s.insert(ii(a[TMP[i]],TMP[i]));
		}
	}
	cout<<top<<"\n";
	for(int64_t i=1;i<=top;i++)
	{
		cout<<rs[i]<<' ';
		for(int64_t j=0;j<g[i].size();j++)
			cout<<g[i][j]<<' ';
		cout<<"\n";
	}
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:44:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int64_t i=0;i<TMP.size();i++)
                   ~^~~~~~~~~~~
nicegift.cpp:55:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int64_t j=0;j<g[i].size();j++)
                   ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 56 ms 70904 KB Taken too much stones from the heap
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 56 ms 70904 KB Taken too much stones from the heap
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 56 ms 70904 KB Taken too much stones from the heap
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2058 ms 189728 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 56 ms 70904 KB Taken too much stones from the heap
2 Halted 0 ms 0 KB -