# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1112675 | 2024-11-14T14:32:26 Z | vjudge1 | Gift (IZhO18_nicegift) | C++17 | 632 ms | 101168 KB |
//Dost SEFEROĞLU #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2") #include <bits/stdc++.h> using namespace std; #define int long long #define pii pair<int,int> #define ff first #define ss second #define sp << " " << #define vi vector<int> #define all(xx) xx.begin(),xx.end() #define ps(xxx) cout << (xxx) << endl; const int N = 5e2+1,inf = 1e16,MOD = 1e9+7; void solve() { int n,k; cin >> n >> k; int s = 0; set<pii,greater<pii>> ms; vi a(n+1); for (int i=1;i<=n;i++) { cin >> a[i]; s+=a[i]; ms.insert({a[i],i}); } if (s%k != 0 || ms.rbegin()->ff > s/k) { cout << -1 << endl; return; } vector<pair<int,vi>> ops; int sm = s/k; while (!ms.empty()) { vi vv; auto itt = ms.begin(); int ctr = 0; for (;ctr != k;++itt) { vv.push_back(itt->ss); ctr++; } if (ms.size() == k) assert(ms.begin()->ff == ms.rbegin()->ff); int knxt = next(ms.begin(),k-1)->ff; int subt = min(knxt,sm-((ms.size() > k) ? (next(ms.begin(),k)->ff) : 0ll)); sm-=subt; for (auto it : vv) { ms.erase({a[it],it}); if (a[it]-subt > 0) ms.insert({a[it]-subt,it}); //else assert(a[it] == subt); a[it]-=subt; } ops.push_back({subt,vv}); } cout << ops.size() << '\n'; for (auto it : ops) { cout << it.ff << " "; for (auto itt : it.ss) cout << itt << " "; cout << '\n'; } } signed main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #ifdef Dodi freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); #endif int t = 1; //cin >> t; while (t --> 0) solve(); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | n=4 |
2 | Correct | 1 ms | 336 KB | n=3 |
3 | Correct | 1 ms | 336 KB | n=3 |
4 | Correct | 1 ms | 336 KB | n=4 |
5 | Correct | 1 ms | 336 KB | n=4 |
6 | Correct | 1 ms | 336 KB | n=2 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | n=4 |
2 | Correct | 1 ms | 336 KB | n=3 |
3 | Correct | 1 ms | 336 KB | n=3 |
4 | Correct | 1 ms | 336 KB | n=4 |
5 | Correct | 1 ms | 336 KB | n=4 |
6 | Correct | 1 ms | 336 KB | n=2 |
7 | Correct | 1 ms | 336 KB | n=5 |
8 | Runtime error | 1 ms | 592 KB | Execution killed with signal 6 |
9 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | n=4 |
2 | Correct | 1 ms | 336 KB | n=3 |
3 | Correct | 1 ms | 336 KB | n=3 |
4 | Correct | 1 ms | 336 KB | n=4 |
5 | Correct | 1 ms | 336 KB | n=4 |
6 | Correct | 1 ms | 336 KB | n=2 |
7 | Correct | 1 ms | 336 KB | n=5 |
8 | Runtime error | 1 ms | 592 KB | Execution killed with signal 6 |
9 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 632 ms | 101168 KB | n=1000000 |
2 | Correct | 380 ms | 55244 KB | n=666666 |
3 | Correct | 207 ms | 32340 KB | n=400000 |
4 | Correct | 132 ms | 24516 KB | n=285714 |
5 | Correct | 9 ms | 1884 KB | n=20000 |
6 | Correct | 80 ms | 14660 KB | n=181818 |
7 | Correct | 4 ms | 1116 KB | n=10000 |
8 | Correct | 3 ms | 852 KB | n=6666 |
9 | Correct | 2 ms | 592 KB | n=4000 |
10 | Correct | 4 ms | 592 KB | n=2857 |
11 | Correct | 1 ms | 592 KB | n=2000 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | n=4 |
2 | Correct | 1 ms | 336 KB | n=3 |
3 | Correct | 1 ms | 336 KB | n=3 |
4 | Correct | 1 ms | 336 KB | n=4 |
5 | Correct | 1 ms | 336 KB | n=4 |
6 | Correct | 1 ms | 336 KB | n=2 |
7 | Correct | 1 ms | 336 KB | n=5 |
8 | Runtime error | 1 ms | 592 KB | Execution killed with signal 6 |
9 | Halted | 0 ms | 0 KB | - |