Submission #308752

# Submission time Handle Problem Language Result Execution time Memory
308752 2020-10-01T20:50:24 Z aZvezda Gift (IZhO18_nicegift) C++14
7 / 100
619 ms 65848 KB
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e18 + 7;
template<class T> inline void fix(T &x) {if(labs(x) >= mod) {x %= mod;} if(x < 0) {x += mod;}}
#define out(x) cout << __LINE__ << ": " << (#x) << " = " << (x) << endl

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    vector<vector<ll> > ans;
    ll n, k;
    cin >> n >> k;
    priority_queue<pair<ll, ll> > pq;
    ll avr = 0;
    for(ll i = 0; i < n; i ++) {
        ll a;
        cin >> a;
        avr += a;
        if(a != 0) {
            pq.push({a, i});
        }
    }
    if(avr % k != 0) {
        cout << -1 << endl;
        return 0;
    }
    avr /= k;
    while(pq.size() >= k) {
        vector<pair<ll, ll> > curr;
        ll get = mod;
        for(ll i = 0; i < k; i ++) {
            chkmin(get, pq.top().first);
            curr.push_back(pq.top()); pq.pop();
        }
        if(!pq.empty()) {
            chkmin(get, avr - pq.top().first);
        }
        ans.resize(ans.size() + 1);
        ans.back().push_back(get);
        for(auto &it : curr) {
            ans.back().push_back(it.second + 1);
            it.first -= get;
            if(it.first > 0) {
                pq.push({it});
            }
        }
    }
    if(pq.size() != 0) {
        cout << -1 << endl;
        return 0;
    }
    cout << ans.size() << endl;
    for(auto it : ans) {
        for(auto itt : it) {
            cout << itt << " ";
        }
        cout << endl;
    }
    return 0;
}


Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:35:21: 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 'll' {aka 'long long int'} [-Wsign-compare]
   35 |     while(pq.size() >= k) {
      |           ~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB n=4
2 Correct 0 ms 384 KB n=3
3 Correct 1 ms 384 KB n=3
4 Correct 1 ms 384 KB n=4
5 Correct 1 ms 384 KB n=4
6 Correct 0 ms 384 KB n=2
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB n=4
2 Correct 0 ms 384 KB n=3
3 Correct 1 ms 384 KB n=3
4 Correct 1 ms 384 KB n=4
5 Correct 1 ms 384 KB n=4
6 Correct 0 ms 384 KB n=2
7 Correct 0 ms 384 KB n=5
8 Correct 1 ms 384 KB n=8
9 Incorrect 0 ms 384 KB Jury has the answer but participant has not
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB n=4
2 Correct 0 ms 384 KB n=3
3 Correct 1 ms 384 KB n=3
4 Correct 1 ms 384 KB n=4
5 Correct 1 ms 384 KB n=4
6 Correct 0 ms 384 KB n=2
7 Correct 0 ms 384 KB n=5
8 Correct 1 ms 384 KB n=8
9 Incorrect 0 ms 384 KB Jury has the answer but participant has not
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 619 ms 65848 KB n=1000000
2 Correct 385 ms 34372 KB n=666666
3 Correct 220 ms 19924 KB n=400000
4 Incorrect 113 ms 9428 KB Jury has the answer but participant has not
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB n=4
2 Correct 0 ms 384 KB n=3
3 Correct 1 ms 384 KB n=3
4 Correct 1 ms 384 KB n=4
5 Correct 1 ms 384 KB n=4
6 Correct 0 ms 384 KB n=2
7 Correct 0 ms 384 KB n=5
8 Correct 1 ms 384 KB n=8
9 Incorrect 0 ms 384 KB Jury has the answer but participant has not
10 Halted 0 ms 0 KB -