Submission #172905

# Submission time Handle Problem Language Result Execution time Memory
172905 2020-01-02T17:55:35 Z muhammad_hokimiyon Gift (IZhO18_nicegift) C++14
7 / 100
2000 ms 174836 KB
#include <bits/stdc++.h>

#pragma GCC optimize("Ofast")

#define fi first
#define se second
#define ll long long

using namespace std;

const int N = 3e6 + 7;
const int M = 23;
const int mod = 998244353;

ll n,k;
ll a[N];
set < pair < ll , ll > > s;

void solve1()
{
    cin >> n >> k;
    ll sum = 0;
    for( int i = 1; i <= n; i++ ){
        cin >> a[i];
        s.insert({a[i] , i});
        sum += a[i];
    }
    if( (--s.end())->fi * k > sum || sum % k != 0 ){
        cout << -1;
        return;
    }
    int ans = 0;
    vector < ll > res;
    vector < vector < ll > > cnt(N);
    while( !s.empty() ){
        int sz = 1;
        vector < pair < ll , ll > > y;
        while( sz <= k ){
            auto x = *--s.end();
            s.erase(--s.end());
            y.push_back(x);
            sz++;
        }
        if( s.empty() ){
            res.push_back(y[0].fi);
            ans++;
            for( auto x : y ){
                cnt[ans].push_back(x.se);
            }
            break;
        }
        ll l = 1 , r = y[0].fi;
        while( l < r ){
            ll m = (l + r) / 2;
            if( sum - (m + 1) * k >= max((--s.end())->fi , y[0].fi - (m + 1)) * k )l = m + 1;
            else r = m;
        }
        l = min(l , (--s.end())->se);
        sum -= l * k;
        res.push_back(l);
        ans++;
        for( auto x : y ){
            cnt[ans].push_back(x.se);
            if( x.fi - l > 0 ){
                x.fi -= l;
                s.insert(x);
            }
        }
    }
    cout << ans << "\n";
    for( int i = 1; i <= ans; i++ ){
        cout << res[i - 1] << " ";
        for( auto x : cnt[i] ){
            cout << x << " ";
        }
        cout << "\n";
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    //freopen( "input.txt" , "r" , stdin );
    //freopen( "output.txt" , "w" , stdout );

    int cghf = 1;//cin >> cghf;
    while( cghf-- ){
        solve1();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 68 ms 70776 KB n=4
2 Correct 68 ms 70780 KB n=3
3 Correct 2 ms 376 KB n=3
4 Correct 69 ms 70776 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 68 ms 70776 KB n=4
2 Correct 68 ms 70780 KB n=3
3 Correct 2 ms 376 KB n=3
4 Correct 69 ms 70776 KB n=4
5 Correct 2 ms 376 KB n=4
6 Correct 2 ms 376 KB n=2
7 Runtime error 153 ms 143272 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 68 ms 70776 KB n=4
2 Correct 68 ms 70780 KB n=3
3 Correct 2 ms 376 KB n=3
4 Correct 69 ms 70776 KB n=4
5 Correct 2 ms 376 KB n=4
6 Correct 2 ms 376 KB n=2
7 Runtime error 153 ms 143272 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2097 ms 174836 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 68 ms 70776 KB n=4
2 Correct 68 ms 70780 KB n=3
3 Correct 2 ms 376 KB n=3
4 Correct 69 ms 70776 KB n=4
5 Correct 2 ms 376 KB n=4
6 Correct 2 ms 376 KB n=2
7 Runtime error 153 ms 143272 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Halted 0 ms 0 KB -