Submission #523466

# Submission time Handle Problem Language Result Execution time Memory
523466 2022-02-07T17:14:57 Z RaresFelix Gift (IZhO18_nicegift) C++17
30 / 100
453 ms 68892 KB
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <vector>
#include <iostream>
#include <queue>

#define MN 1007171

using namespace std;
using ll = long long;

ll n, k, A[MN];
priority_queue<pair<ll, int> > S;
vector<pair<int, vector<int>>> O;
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> k;
    ll sum = 0;
    for(ll i = 1; i <= n; ++i)
        cin >> A[i], S.push({A[i], i}), sum += A[i];
    if(S.top().first > sum / k || sum % k) {
        cout << "-1\n";
        return 0;
    }
    ll vmin, suma_ramasa, delta;
    vector<int> PU;
    while(!S.empty()) {
        suma_ramasa = sum;
        for(ll i = 1; i <= k; ++i)
            PU.push_back(S.top().second), suma_ramasa -= S.top().first, S.pop();
        if(!S.empty())
            delta = min(A[PU.back()], sum / k - S.top().first);
        else delta = A[PU.back()];
        O.push_back(make_pair(delta, PU));
        for(auto it : PU){
            A[it] -= delta;
            sum -= delta;
            if(A[it])
                S.push({A[it], it});
        }
        PU.clear();
    }
    cout << O.size() << "\n";
    for(auto [c, v] : O) {
        cout << c << " ";
        for(auto it : v)
            cout << it << " ";
        cout << "\n";
    }
    return 0;
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:26:8: warning: unused variable 'vmin' [-Wunused-variable]
   26 |     ll vmin, suma_ramasa, delta;
      |        ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB n=4
2 Correct 0 ms 204 KB n=3
3 Correct 0 ms 204 KB n=3
4 Correct 0 ms 204 KB n=4
5 Correct 0 ms 204 KB n=4
6 Correct 0 ms 204 KB n=2
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB n=4
2 Correct 0 ms 204 KB n=3
3 Correct 0 ms 204 KB n=3
4 Correct 0 ms 204 KB n=4
5 Correct 0 ms 204 KB n=4
6 Correct 0 ms 204 KB n=2
7 Correct 0 ms 204 KB n=5
8 Correct 0 ms 204 KB n=8
9 Correct 0 ms 204 KB n=14
10 Correct 0 ms 204 KB n=11
11 Correct 20 ms 3912 KB n=50000
12 Correct 19 ms 3656 KB n=50000
13 Correct 0 ms 204 KB n=10
14 Correct 1 ms 332 KB n=685
15 Correct 1 ms 332 KB n=623
16 Correct 1 ms 332 KB n=973
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB n=4
2 Correct 0 ms 204 KB n=3
3 Correct 0 ms 204 KB n=3
4 Correct 0 ms 204 KB n=4
5 Correct 0 ms 204 KB n=4
6 Correct 0 ms 204 KB n=2
7 Correct 0 ms 204 KB n=5
8 Correct 0 ms 204 KB n=8
9 Correct 0 ms 204 KB n=14
10 Correct 0 ms 204 KB n=11
11 Correct 20 ms 3912 KB n=50000
12 Correct 19 ms 3656 KB n=50000
13 Correct 0 ms 204 KB n=10
14 Correct 1 ms 332 KB n=685
15 Correct 1 ms 332 KB n=623
16 Correct 1 ms 332 KB n=973
17 Correct 1 ms 332 KB n=989
18 Correct 1 ms 332 KB n=563
19 Correct 1 ms 332 KB n=592
20 Correct 1 ms 332 KB n=938
21 Correct 1 ms 332 KB n=747
22 Correct 1 ms 332 KB n=991
# Verdict Execution time Memory Grader output
1 Incorrect 453 ms 68892 KB Added number should be positive
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB n=4
2 Correct 0 ms 204 KB n=3
3 Correct 0 ms 204 KB n=3
4 Correct 0 ms 204 KB n=4
5 Correct 0 ms 204 KB n=4
6 Correct 0 ms 204 KB n=2
7 Correct 0 ms 204 KB n=5
8 Correct 0 ms 204 KB n=8
9 Correct 0 ms 204 KB n=14
10 Correct 0 ms 204 KB n=11
11 Correct 20 ms 3912 KB n=50000
12 Correct 19 ms 3656 KB n=50000
13 Correct 0 ms 204 KB n=10
14 Correct 1 ms 332 KB n=685
15 Correct 1 ms 332 KB n=623
16 Correct 1 ms 332 KB n=973
17 Correct 1 ms 332 KB n=989
18 Correct 1 ms 332 KB n=563
19 Correct 1 ms 332 KB n=592
20 Correct 1 ms 332 KB n=938
21 Correct 1 ms 332 KB n=747
22 Correct 1 ms 332 KB n=991
23 Incorrect 453 ms 68892 KB Added number should be positive
24 Halted 0 ms 0 KB -