답안 #486146

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
486146 2021-11-10T15:50:16 Z luka1234 Gift (IZhO18_nicegift) C++14
0 / 100
752 ms 112496 KB
#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
using namespace std;
ll n,m;
ll a[1000001];
ll sum=0;
ll mx=0;
int main(){
	cin>>n>>m;
	vector<int> index(n+1,0);
	vector<vector<pair<ll,ll> > > blocks(n+1);
	vector<vector<ll> > ans(n+1);
	for(int k=1;k<=n;k++){
		cin>>a[k];
		sum+=a[k];
		mx=max(mx,a[k]);
	}
	if(sum%m!=0||mx>sum/m){
		cout<<-1;
		return 0;
	}
	int ind=1;
	for(int k=1;k<=m;k++){
		ll sz=sum/m;
		while(sz>0){
			ll f=a[ind];
			if(sz>=f){
				sz-=f;
				ind++;
				blocks[k].push_back({f,ind});
			}
			else{
				a[ind]-=sz;
				f-=sz;
				blocks[k].push_back({f,ind});
				sz=0;
			}
		}
	}
	ind=0;
	while(index[1]<blocks[1].size()){
		ll mn=1e18;
		for(int k=1;k<=m;k++){
			mn=min(mn,blocks[k][index[k]].ff);
		}
		ans[ind].push_back(mn);
		for(int k=1;k<=m;k++){
			ans[ind].push_back(blocks[k][index[k]].ss);
		}
		for(int k=1;k<=m;k++){
			blocks[k][index[k]].ff-=mn;
			if(blocks[k][index[k]].ff==0){
				index[k]++;
			}
		}
		ind++;
	}
	for(int k=0;k<ind;k++){
		for(int i=0;i<ans[k].size();i++){
			cout<<ans[k][i]<<' ';
		}
		cout<<"\n";
	}
    return 0;
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:43:16: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |  while(index[1]<blocks[1].size()){
nicegift.cpp:61:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |   for(int i=0;i<ans[k].size();i++){
      |               ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB Taken too much stones from the heap
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB Taken too much stones from the heap
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB Taken too much stones from the heap
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 752 ms 112496 KB Expected int32, but "1000000000000" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB Taken too much stones from the heap
2 Halted 0 ms 0 KB -