# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1112679 | 2024-11-14T14:43:45 Z | vjudge1 | Gift (IZhO18_nicegift) | C++17 | 1912 ms | 112756 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; vi vv(k,0); while (!ms.empty()) { if (ms.size() == k) { if(ms.begin()->ff != ms.rbegin()->ff) { cout << -1 << endl; return; } } auto itt = ms.begin(); int ctr = 0; for (;ctr != k;++itt) { vv[ctr] = (itt->ss); ctr++; } 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
# | 결과 | 실행 시간 | 메모리 | 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 | 356 KB | n=4 |
6 | Correct | 1 ms | 336 KB | n=2 |
# | 결과 | 실행 시간 | 메모리 | 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 | 356 KB | n=4 |
6 | Correct | 1 ms | 336 KB | n=2 |
7 | Correct | 1 ms | 336 KB | n=5 |
8 | Correct | 1 ms | 336 KB | n=8 |
9 | Correct | 1 ms | 336 KB | n=14 |
10 | Correct | 1 ms | 336 KB | n=11 |
11 | Correct | 22 ms | 5316 KB | n=50000 |
12 | Correct | 18 ms | 5192 KB | n=50000 |
13 | Correct | 1 ms | 336 KB | n=10 |
14 | Correct | 1 ms | 336 KB | n=685 |
15 | Correct | 1 ms | 336 KB | n=623 |
16 | Correct | 1 ms | 336 KB | n=973 |
# | 결과 | 실행 시간 | 메모리 | 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 | 356 KB | n=4 |
6 | Correct | 1 ms | 336 KB | n=2 |
7 | Correct | 1 ms | 336 KB | n=5 |
8 | Correct | 1 ms | 336 KB | n=8 |
9 | Correct | 1 ms | 336 KB | n=14 |
10 | Correct | 1 ms | 336 KB | n=11 |
11 | Correct | 22 ms | 5316 KB | n=50000 |
12 | Correct | 18 ms | 5192 KB | n=50000 |
13 | Correct | 1 ms | 336 KB | n=10 |
14 | Correct | 1 ms | 336 KB | n=685 |
15 | Correct | 1 ms | 336 KB | n=623 |
16 | Correct | 1 ms | 336 KB | n=973 |
17 | Correct | 1 ms | 336 KB | n=989 |
18 | Correct | 1 ms | 336 KB | n=563 |
19 | Correct | 1 ms | 336 KB | n=592 |
20 | Correct | 1 ms | 336 KB | n=938 |
21 | Correct | 1 ms | 336 KB | n=747 |
22 | Correct | 1 ms | 336 KB | n=991 |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 580 ms | 100952 KB | n=1000000 |
2 | Correct | 349 ms | 55408 KB | n=666666 |
3 | Correct | 211 ms | 32460 KB | n=400000 |
4 | Correct | 140 ms | 24504 KB | n=285714 |
5 | Correct | 8 ms | 1872 KB | n=20000 |
6 | Correct | 87 ms | 14460 KB | n=181818 |
7 | Correct | 7 ms | 1104 KB | n=10000 |
8 | Correct | 3 ms | 848 KB | n=6666 |
9 | Correct | 2 ms | 764 KB | n=4000 |
10 | Correct | 4 ms | 592 KB | n=2857 |
11 | Correct | 2 ms | 592 KB | n=2000 |
# | 결과 | 실행 시간 | 메모리 | 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 | 356 KB | n=4 |
6 | Correct | 1 ms | 336 KB | n=2 |
7 | Correct | 1 ms | 336 KB | n=5 |
8 | Correct | 1 ms | 336 KB | n=8 |
9 | Correct | 1 ms | 336 KB | n=14 |
10 | Correct | 1 ms | 336 KB | n=11 |
11 | Correct | 22 ms | 5316 KB | n=50000 |
12 | Correct | 18 ms | 5192 KB | n=50000 |
13 | Correct | 1 ms | 336 KB | n=10 |
14 | Correct | 1 ms | 336 KB | n=685 |
15 | Correct | 1 ms | 336 KB | n=623 |
16 | Correct | 1 ms | 336 KB | n=973 |
17 | Correct | 1 ms | 336 KB | n=989 |
18 | Correct | 1 ms | 336 KB | n=563 |
19 | Correct | 1 ms | 336 KB | n=592 |
20 | Correct | 1 ms | 336 KB | n=938 |
21 | Correct | 1 ms | 336 KB | n=747 |
22 | Correct | 1 ms | 336 KB | n=991 |
23 | Correct | 580 ms | 100952 KB | n=1000000 |
24 | Correct | 349 ms | 55408 KB | n=666666 |
25 | Correct | 211 ms | 32460 KB | n=400000 |
26 | Correct | 140 ms | 24504 KB | n=285714 |
27 | Correct | 8 ms | 1872 KB | n=20000 |
28 | Correct | 87 ms | 14460 KB | n=181818 |
29 | Correct | 7 ms | 1104 KB | n=10000 |
30 | Correct | 3 ms | 848 KB | n=6666 |
31 | Correct | 2 ms | 764 KB | n=4000 |
32 | Correct | 4 ms | 592 KB | n=2857 |
33 | Correct | 2 ms | 592 KB | n=2000 |
34 | Correct | 20 ms | 3276 KB | n=23514 |
35 | Correct | 18 ms | 3288 KB | n=23514 |
36 | Correct | 2 ms | 592 KB | n=940 |
37 | Correct | 1 ms | 336 KB | n=2 |
38 | Correct | 47 ms | 8892 KB | n=100000 |
39 | Correct | 60 ms | 8760 KB | n=100000 |
40 | Correct | 1 ms | 336 KB | n=10 |
41 | Correct | 1 ms | 336 KB | n=100 |
42 | Correct | 4 ms | 592 KB | n=1000 |
43 | Correct | 755 ms | 109608 KB | n=1000000 |
44 | Correct | 1912 ms | 112756 KB | n=1000000 |
45 | Correct | 966 ms | 79628 KB | n=666666 |
46 | Correct | 601 ms | 44132 KB | n=400000 |
47 | Correct | 11 ms | 1104 KB | n=2336 |
48 | Correct | 654 ms | 48260 KB | n=285714 |
49 | Correct | 469 ms | 42140 KB | n=181818 |
50 | Correct | 37 ms | 4792 KB | n=40000 |
51 | Correct | 17 ms | 2640 KB | n=20000 |
52 | Correct | 10 ms | 1616 KB | n=10000 |
53 | Correct | 60 ms | 4632 KB | n=6666 |
54 | Correct | 6 ms | 848 KB | n=4000 |
55 | Correct | 224 ms | 16480 KB | n=2857 |
56 | Correct | 4 ms | 592 KB | n=2000 |