Submission #367616

# Submission time Handle Problem Language Result Execution time Memory
367616 2021-02-17T18:55:48 Z nicolaalexandra Gift (IZhO18_nicegift) C++14
100 / 100
1442 ms 101328 KB
#include <bits/stdc++.h>
#define DIM 1000010
using namespace std;

//set <pair<long long,int> > s;
priority_queue <pair<long long,int> > h;
vector <pair<long long,int> > w;
vector <long long> sol[DIM];
long long v[DIM];
int n,k,i,el;

int main (){

    //ifstream cin ("date.in");
    //ofstream cout ("date.out");

    cin>>n>>k;
    long long sum = 0;
    for (i=1;i<=n;i++){
        cin>>v[i];
        h.push(make_pair(v[i],i));
        sum += v[i];
    }

    if (sum % k){
        cout<<-1;
        return 0;
    }

    long long cnt = sum / k;

    while (!h.empty()){
        if (h.size() < k){
            cout<<-1;
            return 0;
        }

        int pas = 0; long long val = 0, val2 = 0;
        w.clear();

        for (int i=1;i<=k;i++){
            val = h.top().first;
            int poz = h.top().second;
            h.pop();
            w.push_back(make_pair(val,poz));
        }


        if (!h.empty())
            val2 = h.top().first;
        val = min (val,cnt - val2);

        sol[++el].push_back (val);
        cnt -= val;

        for (auto it : w){
            long long x = it.first; int poz = it.second;
            sol[el].push_back(poz);

            if (x > val)
                h.push(make_pair(x-val,poz));
        }
    }

    cout<<el<<"\n";
    for (i=1;i<=el;i++){
        for (auto it : sol[i])
            cout<<it<<" ";
        cout<<"\n";
    }


    return 0;
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:33:22: warning: comparison of integer expressions of different signedness: 'std::priority_queue<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   33 |         if (h.size() < k){
      |             ~~~~~~~~~^~~
nicegift.cpp:38:13: warning: unused variable 'pas' [-Wunused-variable]
   38 |         int pas = 0; long long val = 0, val2 = 0;
      |             ^~~
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23788 KB n=4
2 Correct 16 ms 23788 KB n=3
3 Correct 16 ms 23788 KB n=3
4 Correct 16 ms 23788 KB n=4
5 Correct 18 ms 23788 KB n=4
6 Correct 16 ms 23788 KB n=2
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23788 KB n=4
2 Correct 16 ms 23788 KB n=3
3 Correct 16 ms 23788 KB n=3
4 Correct 16 ms 23788 KB n=4
5 Correct 18 ms 23788 KB n=4
6 Correct 16 ms 23788 KB n=2
7 Correct 16 ms 23788 KB n=5
8 Correct 17 ms 23788 KB n=8
9 Correct 16 ms 23788 KB n=14
10 Correct 19 ms 23788 KB n=11
11 Correct 49 ms 26976 KB n=50000
12 Correct 46 ms 26720 KB n=50000
13 Correct 18 ms 23788 KB n=10
14 Correct 17 ms 23916 KB n=685
15 Correct 17 ms 23788 KB n=623
16 Correct 17 ms 23916 KB n=973
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23788 KB n=4
2 Correct 16 ms 23788 KB n=3
3 Correct 16 ms 23788 KB n=3
4 Correct 16 ms 23788 KB n=4
5 Correct 18 ms 23788 KB n=4
6 Correct 16 ms 23788 KB n=2
7 Correct 16 ms 23788 KB n=5
8 Correct 17 ms 23788 KB n=8
9 Correct 16 ms 23788 KB n=14
10 Correct 19 ms 23788 KB n=11
11 Correct 49 ms 26976 KB n=50000
12 Correct 46 ms 26720 KB n=50000
13 Correct 18 ms 23788 KB n=10
14 Correct 17 ms 23916 KB n=685
15 Correct 17 ms 23788 KB n=623
16 Correct 17 ms 23916 KB n=973
17 Correct 17 ms 23916 KB n=989
18 Correct 17 ms 23788 KB n=563
19 Correct 17 ms 23916 KB n=592
20 Correct 17 ms 23916 KB n=938
21 Correct 18 ms 23916 KB n=747
22 Correct 17 ms 23936 KB n=991
# Verdict Execution time Memory Grader output
1 Correct 1039 ms 85300 KB n=1000000
2 Correct 654 ms 58036 KB n=666666
3 Correct 384 ms 43464 KB n=400000
4 Correct 270 ms 36424 KB n=285714
5 Correct 37 ms 24808 KB n=20000
6 Correct 177 ms 31956 KB n=181818
7 Correct 25 ms 24428 KB n=10000
8 Correct 23 ms 24300 KB n=6666
9 Correct 21 ms 24044 KB n=4000
10 Correct 22 ms 24172 KB n=2857
11 Correct 18 ms 23916 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23788 KB n=4
2 Correct 16 ms 23788 KB n=3
3 Correct 16 ms 23788 KB n=3
4 Correct 16 ms 23788 KB n=4
5 Correct 18 ms 23788 KB n=4
6 Correct 16 ms 23788 KB n=2
7 Correct 16 ms 23788 KB n=5
8 Correct 17 ms 23788 KB n=8
9 Correct 16 ms 23788 KB n=14
10 Correct 19 ms 23788 KB n=11
11 Correct 49 ms 26976 KB n=50000
12 Correct 46 ms 26720 KB n=50000
13 Correct 18 ms 23788 KB n=10
14 Correct 17 ms 23916 KB n=685
15 Correct 17 ms 23788 KB n=623
16 Correct 17 ms 23916 KB n=973
17 Correct 17 ms 23916 KB n=989
18 Correct 17 ms 23788 KB n=563
19 Correct 17 ms 23916 KB n=592
20 Correct 17 ms 23916 KB n=938
21 Correct 18 ms 23916 KB n=747
22 Correct 17 ms 23936 KB n=991
23 Correct 1039 ms 85300 KB n=1000000
24 Correct 654 ms 58036 KB n=666666
25 Correct 384 ms 43464 KB n=400000
26 Correct 270 ms 36424 KB n=285714
27 Correct 37 ms 24808 KB n=20000
28 Correct 177 ms 31956 KB n=181818
29 Correct 25 ms 24428 KB n=10000
30 Correct 23 ms 24300 KB n=6666
31 Correct 21 ms 24044 KB n=4000
32 Correct 22 ms 24172 KB n=2857
33 Correct 18 ms 23916 KB n=2000
34 Correct 39 ms 25572 KB n=23514
35 Correct 39 ms 25572 KB n=23514
36 Correct 17 ms 23916 KB n=940
37 Correct 16 ms 23788 KB n=2
38 Correct 81 ms 28508 KB n=100000
39 Correct 80 ms 28636 KB n=100000
40 Correct 16 ms 23788 KB n=10
41 Correct 17 ms 23788 KB n=100
42 Correct 20 ms 24044 KB n=1000
43 Correct 1020 ms 97992 KB n=1000000
44 Correct 1442 ms 101328 KB n=1000000
45 Correct 966 ms 77656 KB n=666666
46 Correct 611 ms 56264 KB n=400000
47 Correct 29 ms 24684 KB n=2336
48 Correct 892 ms 71700 KB n=285714
49 Correct 802 ms 70252 KB n=181818
50 Correct 63 ms 26592 KB n=40000
51 Correct 40 ms 25316 KB n=20000
52 Correct 29 ms 24660 KB n=10000
53 Correct 91 ms 29676 KB n=6666
54 Correct 22 ms 24172 KB n=4000
55 Correct 302 ms 44272 KB n=2857
56 Correct 22 ms 24044 KB n=2000