Submission #379359

#TimeUsernameProblemLanguageResultExecution timeMemory
379359rk42745417Gift (IZhO18_nicegift)C++17
100 / 100
813 ms124572 KiB
/* -------------- | / | | / | | / | * |/ | | ------ * | | | | / \ | | |\ | | | |\ | \ | | | \ | | | | \ | \ | | | \ | | \ / \ | V | | \ \__/| ----- \ | */ #include <bits/stdc++.h> using namespace std; #define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL); using ll = int64_t; using ull = uint64_t; using ld = long double; using uint = uint32_t; const double EPS = 1e-8; const int INF = 0x3F3F3F3F; const ll LINF = 4611686018427387903; const int MOD = 1e9+7; /*--------------------------------------------------------------------------------------*/ signed main() { EmiliaMyWife int n, k; cin >> n >> k; vector<ll> arr(n); ll sum = 0, mx = 0; for(int i = 0; i < n; i++) { cin >> arr[i]; sum += arr[i]; mx = max(mx, arr[i]); } if(sum % k || mx > sum / k) return cout << "-1\n", 0; ll len = sum / k; ll s = 0; vector<ll> v, owo(n); for(int i = 0; i < n; i++) { s += arr[i]; v.push_back(s % len ? s % len : len); owo[i] = s; } vector<pair<ll, vector<int>>> ans; sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); ll prv = 0; for(ll x : v) { vector<int> tmp(k); for(int i = 0; i < k; i++) { tmp[i] = lower_bound(owo.begin(), owo.end(), x + len * i) - owo.begin(); } ans.push_back({x - prv, tmp}); prv = x; } cout << ans.size() << '\n'; for(const auto &[x, y] : ans) { cout << x; for(auto w : y) cout << ' ' << w + 1; cout << '\n'; } }
#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...