Submission #335173

#TimeUsernameProblemLanguageResultExecution timeMemory
335173amunduzbaevGift (IZhO18_nicegift)C++14
0 / 100
556 ms238264 KiB
#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]; void solve(){ ll n, k, mx, sum; 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<<-1; return; } 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 = 0; 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; } /* 4 2 2 3 3 2 */ int main(){ int t = 1; //cin>>t; while(t--) solve(); return 0; }

Compilation message (stderr)

nicegift.cpp: In function 'void solve()':
nicegift.cpp:28:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   28 |  scanf("%lld %lld", &n, &k);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~
nicegift.cpp:30:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   30 |   scanf("%lld", &a[i]);
      |   ~~~~~^~~~~~~~~~~~~~~
nicegift.cpp:34:8: warning: 'mx' may be used uninitialized in this function [-Wmaybe-uninitialized]
   34 |  if(mx * k > sum || sum % k){
      |     ~~~^~~
nicegift.cpp:27:15: warning: 'sum' may be used uninitialized in this function [-Wmaybe-uninitialized]
   27 |  ll n, k, mx, sum;
      |               ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...