답안 #767660

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
767660 2023-06-27T02:36:02 Z Trunkty Gift (IZhO18_nicegift) C++14
49 / 100
2000 ms 133756 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll

int n,k,tot;
int arr[1000005];
set<pair<int,int>> s;
vector<vector<int>> ans;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> k;
    for(int i=1;i<=n;i++){
        cin >> arr[i];
        s.insert({arr[i],i});
        tot += arr[i];
    }
    if(tot%k!=0 or tot/k<(*prev(s.end())).first){
        cout << -1 << "\n";
        return 0;
    }
    int lef=tot/k;
    s.insert({0,0});
    while((*prev(s.end())).first>0){
        vector<pair<int,int>> v;
        for(int i=1;i<=k;i++){
            v.push_back(*prev(s.end()));
            s.erase(v.back());
        }
        int torem = min(v.back().first,lef-(*prev(s.end())).first);
        lef -= torem;
        vector<int> ps={torem};
        for(pair<int,int> i:v){
            ps.push_back(i.second);
            s.insert({i.first-torem,i.second});
        }
        ans.push_back(ps);
    }
    cout << ans.size() << "\n";
    for(vector<int> i:ans){
        for(int j:i){
            cout << j << " ";
        }
        cout << "\n";
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB n=4
2 Correct 0 ms 212 KB n=3
3 Correct 1 ms 212 KB n=3
4 Correct 1 ms 328 KB n=4
5 Correct 0 ms 336 KB n=4
6 Correct 1 ms 212 KB n=2
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB n=4
2 Correct 0 ms 212 KB n=3
3 Correct 1 ms 212 KB n=3
4 Correct 1 ms 328 KB n=4
5 Correct 0 ms 336 KB n=4
6 Correct 1 ms 212 KB n=2
7 Correct 0 ms 332 KB n=5
8 Correct 0 ms 212 KB n=8
9 Correct 1 ms 212 KB n=14
10 Correct 1 ms 212 KB n=11
11 Correct 32 ms 6040 KB n=50000
12 Correct 28 ms 5676 KB n=50000
13 Correct 0 ms 212 KB n=10
14 Correct 1 ms 340 KB n=685
15 Correct 1 ms 340 KB n=623
16 Correct 1 ms 324 KB n=973
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB n=4
2 Correct 0 ms 212 KB n=3
3 Correct 1 ms 212 KB n=3
4 Correct 1 ms 328 KB n=4
5 Correct 0 ms 336 KB n=4
6 Correct 1 ms 212 KB n=2
7 Correct 0 ms 332 KB n=5
8 Correct 0 ms 212 KB n=8
9 Correct 1 ms 212 KB n=14
10 Correct 1 ms 212 KB n=11
11 Correct 32 ms 6040 KB n=50000
12 Correct 28 ms 5676 KB n=50000
13 Correct 0 ms 212 KB n=10
14 Correct 1 ms 340 KB n=685
15 Correct 1 ms 340 KB n=623
16 Correct 1 ms 324 KB n=973
17 Correct 1 ms 340 KB n=989
18 Correct 1 ms 340 KB n=563
19 Correct 1 ms 340 KB n=592
20 Correct 1 ms 340 KB n=938
21 Correct 1 ms 340 KB n=747
22 Correct 1 ms 340 KB n=991
# 결과 실행 시간 메모리 Grader output
1 Correct 826 ms 112736 KB n=1000000
2 Correct 502 ms 70916 KB n=666666
3 Correct 277 ms 39392 KB n=400000
4 Correct 184 ms 27080 KB n=285714
5 Correct 9 ms 2260 KB n=20000
6 Correct 107 ms 19152 KB n=181818
7 Correct 5 ms 1344 KB n=10000
8 Correct 4 ms 980 KB n=6666
9 Correct 2 ms 724 KB n=4000
10 Correct 6 ms 728 KB n=2857
11 Correct 1 ms 468 KB n=2000
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB n=4
2 Correct 0 ms 212 KB n=3
3 Correct 1 ms 212 KB n=3
4 Correct 1 ms 328 KB n=4
5 Correct 0 ms 336 KB n=4
6 Correct 1 ms 212 KB n=2
7 Correct 0 ms 332 KB n=5
8 Correct 0 ms 212 KB n=8
9 Correct 1 ms 212 KB n=14
10 Correct 1 ms 212 KB n=11
11 Correct 32 ms 6040 KB n=50000
12 Correct 28 ms 5676 KB n=50000
13 Correct 0 ms 212 KB n=10
14 Correct 1 ms 340 KB n=685
15 Correct 1 ms 340 KB n=623
16 Correct 1 ms 324 KB n=973
17 Correct 1 ms 340 KB n=989
18 Correct 1 ms 340 KB n=563
19 Correct 1 ms 340 KB n=592
20 Correct 1 ms 340 KB n=938
21 Correct 1 ms 340 KB n=747
22 Correct 1 ms 340 KB n=991
23 Correct 826 ms 112736 KB n=1000000
24 Correct 502 ms 70916 KB n=666666
25 Correct 277 ms 39392 KB n=400000
26 Correct 184 ms 27080 KB n=285714
27 Correct 9 ms 2260 KB n=20000
28 Correct 107 ms 19152 KB n=181818
29 Correct 5 ms 1344 KB n=10000
30 Correct 4 ms 980 KB n=6666
31 Correct 2 ms 724 KB n=4000
32 Correct 6 ms 728 KB n=2857
33 Correct 1 ms 468 KB n=2000
34 Correct 22 ms 3372 KB n=23514
35 Correct 22 ms 3344 KB n=23514
36 Correct 1 ms 340 KB n=940
37 Correct 0 ms 212 KB n=2
38 Correct 64 ms 10184 KB n=100000
39 Correct 62 ms 10152 KB n=100000
40 Correct 0 ms 324 KB n=10
41 Correct 1 ms 340 KB n=100
42 Correct 4 ms 468 KB n=1000
43 Correct 1041 ms 133756 KB n=1000000
44 Execution timed out 2085 ms 111012 KB Time limit exceeded
45 Halted 0 ms 0 KB -