Submission #172900

# Submission time Handle Problem Language Result Execution time Memory
172900 2020-01-02T17:50:27 Z muhammad_hokimiyon Gift (IZhO18_nicegift) C++14
7 / 100
2000 ms 155844 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 , int > > 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 < int > > cnt(N);
    while( !s.empty() ){
        int sz = 1;
        vector < pair < ll , int > > 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;
        }
        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 67 ms 70824 KB n=4
2 Correct 67 ms 70856 KB n=3
3 Correct 2 ms 376 KB n=3
4 Correct 66 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 67 ms 70824 KB n=4
2 Correct 67 ms 70856 KB n=3
3 Correct 2 ms 376 KB n=3
4 Correct 66 ms 70776 KB n=4
5 Correct 2 ms 376 KB n=4
6 Correct 2 ms 376 KB n=2
7 Runtime error 156 ms 143224 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 67 ms 70824 KB n=4
2 Correct 67 ms 70856 KB n=3
3 Correct 2 ms 376 KB n=3
4 Correct 66 ms 70776 KB n=4
5 Correct 2 ms 376 KB n=4
6 Correct 2 ms 376 KB n=2
7 Runtime error 156 ms 143224 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 1110 ms 155844 KB n=1000000
2 Correct 707 ms 127448 KB n=666666
3 Correct 426 ms 104568 KB n=400000
4 Execution timed out 2061 ms 154208 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 67 ms 70824 KB n=4
2 Correct 67 ms 70856 KB n=3
3 Correct 2 ms 376 KB n=3
4 Correct 66 ms 70776 KB n=4
5 Correct 2 ms 376 KB n=4
6 Correct 2 ms 376 KB n=2
7 Runtime error 156 ms 143224 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Halted 0 ms 0 KB -