Submission #153959

# Submission time Handle Problem Language Result Execution time Memory
153959 2019-09-17T15:02:30 Z andrew Gift (IZhO18_nicegift) C++17
18 / 100
2000 ms 170640 KB
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#define fi first
#define se second
#define p_b push_back
#define pll pair<ll,ll>
#define pii pair<int,int>
#define m_p make_pair
#define all(x) x.begin(),x.end()
#define sset ordered_set
#define sqr(x) (x)*(x)
#define pw(x) (1ll << x)

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
const ll MAXN = 1123456;
const ll N = 2e5;
mt19937_64 rnd(chrono::system_clock::now().time_since_epoch().count());

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template <typename T> void vout(T s){cout << s << endl;exit(0);}

int main(){
    ios_base :: sync_with_stdio(0);
    cin.tie(0);

    ll n, k;
    cin >> n >> k;

    vector <ll> a(n);

    set <pll> st;

    ll sc = 0, mx = 0;

    for(int i = 0; i < n; i++){
        cin >> a[i];
        st.insert({a[i], i});
        sc += a[i];
        mx = max(mx, a[i]);
    }

    if(sc % k)vout(-1);

    pll fufel = *--st.end();
    st.erase(--st.end());
    sc -= mx;

    if(sc < mx)vout(-1);

    vector < pair<ll, vector <ll> > > ans;

    while(sc > mx){
        vector <pll> V;
        for(int i = 0; i < k; i++){
            if(st.empty())vout(-1);
            pll xe = *--st.end();
            V.p_b(xe);
            st.erase(--st.end());
        }
        sc -= k;
        vector <ll> c;
        for(auto i : V)c.p_b(i.se);
        ans.p_b({1, c});
        for(auto i : V){
            if(i.fi > 1)st.insert({i.fi - 1, i.se});
        }
        c.clear();
        V.clear();
    }

    while(!st.empty()){
        vector <pll> V;
        for(int i = 1; i < k; i++){
            if(st.empty())vout(-1);
            pll xe = *--st.end();
            V.p_b(xe);
            st.erase(--st.end());
        }
        sc -= k;
        vector <ll> c;
        for(auto i : V)c.p_b(i.se);
        c.p_b(fufel.se);
        ans.p_b({1, c});
        for(auto i : V){
            if(i.fi > 1)st.insert({i.fi - 1, i.se});
        }
        c.clear();
        V.clear();
    }

    cout << ans.size() << "\n";
    for(auto i : ans){
        cout << i.fi;
        for(auto j : i.se)cout << " " << j + 1;
        cout << "\n";
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB n=4
2 Correct 2 ms 376 KB n=3
3 Correct 3 ms 380 KB n=3
4 Correct 2 ms 376 KB n=4
5 Correct 2 ms 376 KB n=4
6 Correct 2 ms 376 KB n=2
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB n=4
2 Correct 2 ms 376 KB n=3
3 Correct 3 ms 380 KB n=3
4 Correct 2 ms 376 KB n=4
5 Correct 2 ms 376 KB n=4
6 Correct 2 ms 376 KB n=2
7 Correct 2 ms 376 KB n=5
8 Correct 2 ms 376 KB n=8
9 Correct 12 ms 1268 KB n=14
10 Correct 8 ms 1116 KB n=11
11 Correct 52 ms 6376 KB n=50000
12 Correct 58 ms 6924 KB n=50000
13 Correct 35 ms 3816 KB n=10
14 Correct 39 ms 3476 KB n=685
15 Correct 41 ms 3684 KB n=623
16 Correct 26 ms 2284 KB n=973
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB n=4
2 Correct 2 ms 376 KB n=3
3 Correct 3 ms 380 KB n=3
4 Correct 2 ms 376 KB n=4
5 Correct 2 ms 376 KB n=4
6 Correct 2 ms 376 KB n=2
7 Correct 2 ms 376 KB n=5
8 Correct 2 ms 376 KB n=8
9 Correct 12 ms 1268 KB n=14
10 Correct 8 ms 1116 KB n=11
11 Correct 52 ms 6376 KB n=50000
12 Correct 58 ms 6924 KB n=50000
13 Correct 35 ms 3816 KB n=10
14 Correct 39 ms 3476 KB n=685
15 Correct 41 ms 3684 KB n=623
16 Correct 26 ms 2284 KB n=973
17 Incorrect 27 ms 2432 KB Jury has the answer but participant has not
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2109 ms 170640 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB n=4
2 Correct 2 ms 376 KB n=3
3 Correct 3 ms 380 KB n=3
4 Correct 2 ms 376 KB n=4
5 Correct 2 ms 376 KB n=4
6 Correct 2 ms 376 KB n=2
7 Correct 2 ms 376 KB n=5
8 Correct 2 ms 376 KB n=8
9 Correct 12 ms 1268 KB n=14
10 Correct 8 ms 1116 KB n=11
11 Correct 52 ms 6376 KB n=50000
12 Correct 58 ms 6924 KB n=50000
13 Correct 35 ms 3816 KB n=10
14 Correct 39 ms 3476 KB n=685
15 Correct 41 ms 3684 KB n=623
16 Correct 26 ms 2284 KB n=973
17 Incorrect 27 ms 2432 KB Jury has the answer but participant has not
18 Halted 0 ms 0 KB -