Submission #367612

# Submission time Handle Problem Language Result Execution time Memory
367612 2021-02-17T18:50:18 Z nicolaalexandra Gift (IZhO18_nicegift) C++14
49 / 100
2000 ms 116292 KB
#include <bits/stdc++.h>
#define DIM 1000010
using namespace std;

set <pair<long long,int> > s;
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];
        s.insert(make_pair(v[i],i));
        sum += v[i];
    }

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

    long long cnt = sum / k;

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

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

        for (set <pair<long long,int> > :: reverse_iterator it = s.rbegin(); it != s.rend(); it++){
            //sol[el].push_back(it->second);
            pas++;
            if (pas == k+1){
                val2 = it->first;
                break;
            }
            w.push_back(make_pair(it->first,it->second));
            val = it->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);
            s.erase(make_pair(x,poz));
            if (x > val)
                s.insert(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:32:22: warning: comparison of integer expressions of different signedness: 'std::set<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   32 |         if (s.size() < k){
      |             ~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23788 KB n=4
2 Correct 17 ms 23788 KB n=3
3 Correct 16 ms 23808 KB n=3
4 Correct 17 ms 23788 KB n=4
5 Correct 17 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 17 ms 23788 KB n=3
3 Correct 16 ms 23808 KB n=3
4 Correct 17 ms 23788 KB n=4
5 Correct 17 ms 23788 KB n=4
6 Correct 16 ms 23788 KB n=2
7 Correct 16 ms 23788 KB n=5
8 Correct 16 ms 23788 KB n=8
9 Correct 17 ms 23916 KB n=14
10 Correct 16 ms 23788 KB n=11
11 Correct 59 ms 28012 KB n=50000
12 Correct 53 ms 27904 KB n=50000
13 Correct 16 ms 23788 KB n=10
14 Correct 17 ms 23916 KB n=685
15 Correct 17 ms 23916 KB n=623
16 Correct 18 ms 23916 KB n=973
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23788 KB n=4
2 Correct 17 ms 23788 KB n=3
3 Correct 16 ms 23808 KB n=3
4 Correct 17 ms 23788 KB n=4
5 Correct 17 ms 23788 KB n=4
6 Correct 16 ms 23788 KB n=2
7 Correct 16 ms 23788 KB n=5
8 Correct 16 ms 23788 KB n=8
9 Correct 17 ms 23916 KB n=14
10 Correct 16 ms 23788 KB n=11
11 Correct 59 ms 28012 KB n=50000
12 Correct 53 ms 27904 KB n=50000
13 Correct 16 ms 23788 KB n=10
14 Correct 17 ms 23916 KB n=685
15 Correct 17 ms 23916 KB n=623
16 Correct 18 ms 23916 KB n=973
17 Correct 17 ms 23916 KB n=989
18 Correct 17 ms 23916 KB n=563
19 Correct 17 ms 23936 KB n=592
20 Correct 17 ms 23916 KB n=938
21 Correct 17 ms 23916 KB n=747
22 Correct 17 ms 23916 KB n=991
# Verdict Execution time Memory Grader output
1 Correct 1353 ms 108876 KB n=1000000
2 Correct 887 ms 88044 KB n=666666
3 Correct 495 ms 61420 KB n=400000
4 Correct 348 ms 50540 KB n=285714
5 Correct 37 ms 25580 KB n=20000
6 Correct 227 ms 40556 KB n=181818
7 Correct 28 ms 24684 KB n=10000
8 Correct 24 ms 24428 KB n=6666
9 Correct 20 ms 24172 KB n=4000
10 Correct 24 ms 24300 KB n=2857
11 Correct 19 ms 24172 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23788 KB n=4
2 Correct 17 ms 23788 KB n=3
3 Correct 16 ms 23808 KB n=3
4 Correct 17 ms 23788 KB n=4
5 Correct 17 ms 23788 KB n=4
6 Correct 16 ms 23788 KB n=2
7 Correct 16 ms 23788 KB n=5
8 Correct 16 ms 23788 KB n=8
9 Correct 17 ms 23916 KB n=14
10 Correct 16 ms 23788 KB n=11
11 Correct 59 ms 28012 KB n=50000
12 Correct 53 ms 27904 KB n=50000
13 Correct 16 ms 23788 KB n=10
14 Correct 17 ms 23916 KB n=685
15 Correct 17 ms 23916 KB n=623
16 Correct 18 ms 23916 KB n=973
17 Correct 17 ms 23916 KB n=989
18 Correct 17 ms 23916 KB n=563
19 Correct 17 ms 23936 KB n=592
20 Correct 17 ms 23916 KB n=938
21 Correct 17 ms 23916 KB n=747
22 Correct 17 ms 23916 KB n=991
23 Correct 1353 ms 108876 KB n=1000000
24 Correct 887 ms 88044 KB n=666666
25 Correct 495 ms 61420 KB n=400000
26 Correct 348 ms 50540 KB n=285714
27 Correct 37 ms 25580 KB n=20000
28 Correct 227 ms 40556 KB n=181818
29 Correct 28 ms 24684 KB n=10000
30 Correct 24 ms 24428 KB n=6666
31 Correct 20 ms 24172 KB n=4000
32 Correct 24 ms 24300 KB n=2857
33 Correct 19 ms 24172 KB n=2000
34 Correct 47 ms 25964 KB n=23514
35 Correct 47 ms 25964 KB n=23514
36 Correct 17 ms 23916 KB n=940
37 Correct 16 ms 23788 KB n=2
38 Correct 113 ms 32032 KB n=100000
39 Correct 114 ms 32108 KB n=100000
40 Correct 16 ms 23788 KB n=10
41 Correct 17 ms 23788 KB n=100
42 Correct 22 ms 24044 KB n=1000
43 Correct 1474 ms 116292 KB n=1000000
44 Execution timed out 2039 ms 107900 KB Time limit exceeded
45 Halted 0 ms 0 KB -