Submission #169404

# Submission time Handle Problem Language Result Execution time Memory
169404 2019-12-20T08:43:25 Z RafaelSus Gift (IZhO18_nicegift) C++14
100 / 100
1232 ms 96656 KB
#include <bits/stdc++.h>
 
using namespace std;
const int N = 1e6 + 5;
typedef long long ll;
const ll inf=1e18+18ll;
#define pb push_back
 
ll n,k;
ll a[N];
/*
void build(int v,int tl,int tr){
  if(tl==tr)t[v]=a[tl],return;
  int tm=(tl+tr)/2;
  build(v+v,tl,tm);
  build(v+v+1,tm+1,tr);
  t[v]=min(t[v+v],t[v+v+1]);
}

void pushdown(int v){
  if(lazy[v]==0)return;
  t[v+v]-=lazy[v];
  t[v+v+1]-=lazy[v];
  lazy[v+v]+=lazy[v];
  lazy[v+v+1]+=lazy[v];
  lazy[v]=0;
}

void update(int v,int tl,int tr,int l,int r,ll d){
  if(l>r)return;
  if(tl>=l&&tr<=r){
    lazy[v]+=d;
    t[v]-=d;
    return;
  }
  pushdown(v);
  int tm=(tl+tr)/2;
  if(l<=tm)update(v+v,tl,tm,l,r,d);
  if(r>tm)update(v+v+1,tm+1,tr,l,r,d);
  t[v]=min(t[v+v],t[v+v+1]);
}

ll query(int v,int tl,int tr,int l,int r){
  if(tl>=l&&tr<=r)return t[v];
  ll res=inf;
  int tm=(tl+tr)/2;
  pushdown(v);
  if(l<=tm)res=min(res,query(v+v,tl,tm,l,r));
  if(r>tm)res=min(res,query(v+v+1,tm+1,tr,l,r));
  return res;
}*/

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  ll S=0ll;
  cin>>n>>k;
  priority_queue<pair<ll,int>> q;
  for(int i=0;i<n;i++){
    cin>>a[i];
    q.push({a[i],i});
    S+=a[i];
  }
  if(S%k||q.top().first>S/k){cout<<"-1\n";return 0;}
  S/=k;
  vector<vector<ll>> answ;
  ll cnt=0ll;
  while(q.top().first){
    pair<ll,int>tmp[k];
    //if(q.size()<k){cout<<"-1\n";return 0;}
    for(int i=0;i<k;i++){
      tmp[i]=q.top();
      q.pop();
    }
    vector<ll> an;
    ll mx=q.size()?q.top().first:0ll;
    ll x=min(tmp[k-1].first,S-mx);
    an.push_back(x);S-=x;
    for(int i=0;i<k;i++){
      tmp[i].first-=x;q.push(tmp[i]);
      an.push_back(tmp[i].second+1);
    }
    cnt+=(ll)an.size();
    //if(cnt>=3*1e6){cout<<"-1";return 0;}
    answ.push_back(an);
  }
  cout<<answ.size()<<'\n';
  for(int i=0;i<answ.size();i++){
    for(int j=0;j<answ[i].size();j++){
      cout<<answ[i][j]<<' ';
    }
    cout<<'\n';
  }
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:88:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<answ.size();i++){
               ~^~~~~~~~~~~~
nicegift.cpp:89:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int j=0;j<answ[i].size();j++){
                 ~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB n=4
2 Correct 2 ms 376 KB n=3
3 Correct 2 ms 376 KB n=3
4 Correct 2 ms 376 KB n=4
5 Correct 2 ms 376 KB n=4
6 Correct 2 ms 376 KB n=2
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB n=4
2 Correct 2 ms 376 KB n=3
3 Correct 2 ms 376 KB n=3
4 Correct 2 ms 376 KB n=4
5 Correct 2 ms 376 KB n=4
6 Correct 2 ms 376 KB n=2
7 Correct 2 ms 376 KB n=5
8 Correct 2 ms 376 KB n=8
9 Correct 2 ms 376 KB n=14
10 Correct 2 ms 376 KB n=11
11 Correct 31 ms 3564 KB n=50000
12 Correct 28 ms 3596 KB n=50000
13 Correct 2 ms 380 KB n=10
14 Correct 2 ms 376 KB n=685
15 Correct 2 ms 376 KB n=623
16 Correct 3 ms 376 KB n=973
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB n=4
2 Correct 2 ms 376 KB n=3
3 Correct 2 ms 376 KB n=3
4 Correct 2 ms 376 KB n=4
5 Correct 2 ms 376 KB n=4
6 Correct 2 ms 376 KB n=2
7 Correct 2 ms 376 KB n=5
8 Correct 2 ms 376 KB n=8
9 Correct 2 ms 376 KB n=14
10 Correct 2 ms 376 KB n=11
11 Correct 31 ms 3564 KB n=50000
12 Correct 28 ms 3596 KB n=50000
13 Correct 2 ms 380 KB n=10
14 Correct 2 ms 376 KB n=685
15 Correct 2 ms 376 KB n=623
16 Correct 3 ms 376 KB n=973
17 Correct 2 ms 376 KB n=989
18 Correct 2 ms 376 KB n=563
19 Correct 2 ms 376 KB n=592
20 Correct 2 ms 440 KB n=938
21 Correct 2 ms 504 KB n=747
22 Correct 3 ms 376 KB n=991
# Verdict Execution time Memory Grader output
1 Correct 704 ms 65752 KB n=1000000
2 Correct 440 ms 48832 KB n=666666
3 Correct 246 ms 26772 KB n=400000
4 Correct 171 ms 17828 KB n=285714
5 Correct 12 ms 1368 KB n=20000
6 Correct 103 ms 11104 KB n=181818
7 Correct 6 ms 1016 KB n=10000
8 Correct 7 ms 888 KB n=6666
9 Correct 5 ms 632 KB n=4000
10 Correct 7 ms 760 KB n=2857
11 Correct 3 ms 504 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB n=4
2 Correct 2 ms 376 KB n=3
3 Correct 2 ms 376 KB n=3
4 Correct 2 ms 376 KB n=4
5 Correct 2 ms 376 KB n=4
6 Correct 2 ms 376 KB n=2
7 Correct 2 ms 376 KB n=5
8 Correct 2 ms 376 KB n=8
9 Correct 2 ms 376 KB n=14
10 Correct 2 ms 376 KB n=11
11 Correct 31 ms 3564 KB n=50000
12 Correct 28 ms 3596 KB n=50000
13 Correct 2 ms 380 KB n=10
14 Correct 2 ms 376 KB n=685
15 Correct 2 ms 376 KB n=623
16 Correct 3 ms 376 KB n=973
17 Correct 2 ms 376 KB n=989
18 Correct 2 ms 376 KB n=563
19 Correct 2 ms 376 KB n=592
20 Correct 2 ms 440 KB n=938
21 Correct 2 ms 504 KB n=747
22 Correct 3 ms 376 KB n=991
23 Correct 704 ms 65752 KB n=1000000
24 Correct 440 ms 48832 KB n=666666
25 Correct 246 ms 26772 KB n=400000
26 Correct 171 ms 17828 KB n=285714
27 Correct 12 ms 1368 KB n=20000
28 Correct 103 ms 11104 KB n=181818
29 Correct 6 ms 1016 KB n=10000
30 Correct 7 ms 888 KB n=6666
31 Correct 5 ms 632 KB n=4000
32 Correct 7 ms 760 KB n=2857
33 Correct 3 ms 504 KB n=2000
34 Correct 22 ms 2348 KB n=23514
35 Correct 22 ms 2308 KB n=23514
36 Correct 3 ms 504 KB n=940
37 Correct 2 ms 376 KB n=2
38 Correct 55 ms 5780 KB n=100000
39 Correct 58 ms 5736 KB n=100000
40 Correct 1 ms 376 KB n=10
41 Correct 2 ms 380 KB n=100
42 Correct 5 ms 504 KB n=1000
43 Correct 826 ms 86940 KB n=1000000
44 Correct 1232 ms 96656 KB n=1000000
45 Correct 799 ms 63688 KB n=666666
46 Correct 436 ms 36208 KB n=400000
47 Correct 13 ms 1144 KB n=2336
48 Correct 716 ms 55012 KB n=285714
49 Correct 597 ms 45324 KB n=181818
50 Correct 36 ms 3056 KB n=40000
51 Correct 19 ms 1780 KB n=20000
52 Correct 12 ms 1144 KB n=10000
53 Correct 57 ms 4472 KB n=6666
54 Correct 8 ms 760 KB n=4000
55 Correct 241 ms 16364 KB n=2857
56 Correct 5 ms 632 KB n=2000