답안 #957103

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
957103 2024-04-03T02:10:39 Z Darren0724 Gift (IZhO18_nicegift) C++17
100 / 100
1534 ms 96936 KB
#include <bits/stdc++.h>
using namespace std;
#define LCBorz ios_base::sync_with_stdio(false); cin.tie(0);
#define int long long
#define all(x) x.begin(), x.end()
//#define endl '\n'
const int N=200005;
const int INF=1e18;
const int mod=1e9+7;

int32_t main() {
    LCBorz;
    int n,k;cin>>n>>k;
    vector<int> v(n+1);
    priority_queue<pair<int,int>> pq;
    int total=0;
    for(int i=1;i<=n;i++){
        cin>>v[i];
        pq.push({v[i],i});
        total+=v[i];
    }
    vector<vector<int>> ans;
    while(pq.size()>=k){
        int mn=0;
        vector<int> t;
        for(int i=0;i<k;i++){
            auto [a,b]=pq.top();
            pq.pop();
            mn=a;
            t.push_back(b);
        }
        int mx=(pq.size()?pq.top().first:0);
        int left=total-mx;
        int cost=min(mn,(left-(k-1)*mx)/k);
        for(int j:t){
            v[j]-=cost;
            if(v[j]>0)pq.push({v[j],j});
        }
        total-=cost*k;
        t.push_back(cost);
        reverse(all(t));
        ans.push_back(t);
    }
    if(pq.size()!=0){
        cout<<-1<<endl;
        return 0;
    }
    cout<<ans.size()<<endl;
    for(auto v:ans){
        for(int j:v){
            cout<<j<<' ';
        }
        cout<<endl;
    }

    
    return 0;
}

Compilation message

nicegift.cpp: In function 'int32_t main()':
nicegift.cpp:23:20: warning: comparison of integer expressions of different signedness: 'std::priority_queue<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   23 |     while(pq.size()>=k){
      |           ~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB n=4
2 Correct 0 ms 348 KB n=3
3 Correct 0 ms 348 KB n=3
4 Correct 0 ms 348 KB n=4
5 Correct 0 ms 348 KB n=4
6 Correct 0 ms 348 KB n=2
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB n=4
2 Correct 0 ms 348 KB n=3
3 Correct 0 ms 348 KB n=3
4 Correct 0 ms 348 KB n=4
5 Correct 0 ms 348 KB n=4
6 Correct 0 ms 348 KB n=2
7 Correct 1 ms 348 KB n=5
8 Correct 0 ms 344 KB n=8
9 Correct 0 ms 348 KB n=14
10 Correct 0 ms 348 KB n=11
11 Correct 68 ms 3536 KB n=50000
12 Correct 48 ms 3472 KB n=50000
13 Correct 0 ms 344 KB n=10
14 Correct 1 ms 348 KB n=685
15 Correct 1 ms 348 KB n=623
16 Correct 2 ms 348 KB n=973
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB n=4
2 Correct 0 ms 348 KB n=3
3 Correct 0 ms 348 KB n=3
4 Correct 0 ms 348 KB n=4
5 Correct 0 ms 348 KB n=4
6 Correct 0 ms 348 KB n=2
7 Correct 1 ms 348 KB n=5
8 Correct 0 ms 344 KB n=8
9 Correct 0 ms 348 KB n=14
10 Correct 0 ms 348 KB n=11
11 Correct 68 ms 3536 KB n=50000
12 Correct 48 ms 3472 KB n=50000
13 Correct 0 ms 344 KB n=10
14 Correct 1 ms 348 KB n=685
15 Correct 1 ms 348 KB n=623
16 Correct 2 ms 348 KB n=973
17 Correct 1 ms 348 KB n=989
18 Correct 1 ms 348 KB n=563
19 Correct 1 ms 348 KB n=592
20 Correct 1 ms 348 KB n=938
21 Correct 1 ms 348 KB n=747
22 Correct 1 ms 348 KB n=991
# 결과 실행 시간 메모리 Grader output
1 Correct 923 ms 65752 KB n=1000000
2 Correct 470 ms 42056 KB n=666666
3 Correct 216 ms 22460 KB n=400000
4 Correct 133 ms 14520 KB n=285714
5 Correct 6 ms 1564 KB n=20000
6 Correct 75 ms 11204 KB n=181818
7 Correct 3 ms 984 KB n=10000
8 Correct 3 ms 860 KB n=6666
9 Correct 1 ms 600 KB n=4000
10 Correct 3 ms 604 KB n=2857
11 Correct 1 ms 348 KB n=2000
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB n=4
2 Correct 0 ms 348 KB n=3
3 Correct 0 ms 348 KB n=3
4 Correct 0 ms 348 KB n=4
5 Correct 0 ms 348 KB n=4
6 Correct 0 ms 348 KB n=2
7 Correct 1 ms 348 KB n=5
8 Correct 0 ms 344 KB n=8
9 Correct 0 ms 348 KB n=14
10 Correct 0 ms 348 KB n=11
11 Correct 68 ms 3536 KB n=50000
12 Correct 48 ms 3472 KB n=50000
13 Correct 0 ms 344 KB n=10
14 Correct 1 ms 348 KB n=685
15 Correct 1 ms 348 KB n=623
16 Correct 2 ms 348 KB n=973
17 Correct 1 ms 348 KB n=989
18 Correct 1 ms 348 KB n=563
19 Correct 1 ms 348 KB n=592
20 Correct 1 ms 348 KB n=938
21 Correct 1 ms 348 KB n=747
22 Correct 1 ms 348 KB n=991
23 Correct 923 ms 65752 KB n=1000000
24 Correct 470 ms 42056 KB n=666666
25 Correct 216 ms 22460 KB n=400000
26 Correct 133 ms 14520 KB n=285714
27 Correct 6 ms 1564 KB n=20000
28 Correct 75 ms 11204 KB n=181818
29 Correct 3 ms 984 KB n=10000
30 Correct 3 ms 860 KB n=6666
31 Correct 1 ms 600 KB n=4000
32 Correct 3 ms 604 KB n=2857
33 Correct 1 ms 348 KB n=2000
34 Correct 33 ms 2344 KB n=23514
35 Correct 31 ms 2392 KB n=23514
36 Correct 2 ms 348 KB n=940
37 Correct 0 ms 348 KB n=2
38 Correct 60 ms 5648 KB n=100000
39 Correct 53 ms 5572 KB n=100000
40 Correct 0 ms 344 KB n=10
41 Correct 1 ms 348 KB n=100
42 Correct 2 ms 604 KB n=1000
43 Correct 1315 ms 88600 KB n=1000000
44 Correct 1534 ms 96936 KB n=1000000
45 Correct 868 ms 64824 KB n=666666
46 Correct 403 ms 38580 KB n=400000
47 Correct 8 ms 1116 KB n=2336
48 Correct 821 ms 55652 KB n=285714
49 Correct 616 ms 47608 KB n=181818
50 Correct 22 ms 3032 KB n=40000
51 Correct 11 ms 1752 KB n=20000
52 Correct 7 ms 984 KB n=10000
53 Correct 44 ms 4432 KB n=6666
54 Correct 4 ms 604 KB n=4000
55 Correct 173 ms 16212 KB n=2857
56 Correct 3 ms 604 KB n=2000