Submission #1134600

#TimeUsernameProblemLanguageResultExecution timeMemory
1134600Halym2007Gift (IZhO18_nicegift)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define sz size() #define ff first #define ss second #define pb push_back #define pii pair <ll, ll> #define dur exit(0) #define dur1 return(0) const int N = 2e6 + 5; ll n, k, a[N], gos[N]; vector <vector <ll>> v; int main () { // freopen ("input.txt", "r", stdin); ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin >> n >> k; ll sum = 0; for (int i = 1; i <= n; ++i) { cin >> a[i]; sum += a[i]; } if (sum % k != 0) { return cout << "-1", 0; } for (ll i = 1; i <= n; ++i) { if (sum / k < a[i]) { return cout << "-1", 0; } } queue <pii> q[k + 1]; int san = 1, val = 0; for (ll i = 1; i <= n; ++i) { if (val + a[i] <= sum / k) { q[san].push ({a[i], i}); gos[san] += a[i]; val += a[i]; if (val == sum / k) { san++; val = 0; } } else { ll gosh = sum / k - val; q[san].push({gosh, i}); gos[san] += gosh; san++; val = a[i] - gosh; q[san].push({val, i}); gos[san] += val; } } for (int i = 1; i < k; ++i) { assert (gosh[i] != gosh[i + 1]); } while (1) { vector <ll> kk; ll oo = 0; ll mn = 2e18; for (ll i = 1; i <= k; ++i) { if (q[i].empty()) { oo++; continue; } mn = min(q[i].front().ff, mn); } if (oo) { // assert (oo == k); break; } kk.pb (mn); for (ll i = 1; i <= k; ++i) { kk.pb (q[i].front().ss); q[i].front().ff -= mn; if (!q[i].front().ff) { q[i].pop(); } } v.pb (kk); } assert ((ll)v.sz <= n); cout << (ll)v.sz << "\n"; for (int i = 0; i < (ll)v.sz; ++i) { for (ll j : v[i]) { cout << j << " "; } cout << "\n"; } }

Compilation message (stderr)

In file included from /usr/include/c++/11/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:33,
                 from nicegift.cpp:1:
nicegift.cpp: In function 'int main()':
nicegift.cpp:55:25: error: 'gosh' was not declared in this scope; did you mean 'gos'?
   55 |                 assert (gosh[i] != gosh[i + 1]);
      |                         ^~~~