Submission #133825

# Submission time Handle Problem Language Result Execution time Memory
133825 2019-07-21T13:26:28 Z Kastanda Gift (IZhO18_nicegift) C++11
7 / 100
2000 ms 263248 KB
// ItnoE
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1000006;
int n, k;
ll SM, A[N];
vector < ll > R;
priority_queue < pair < ll , int > > Pq;
int main()
{
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; i ++)
    {
        scanf("%lld", &A[i]);
        Pq.push({A[i], i});
        SM += A[i];
    }
    if (SM % k || Pq.top().first > SM / k)
        return !printf("-1\n");
    while (Pq.top().first)
    {
        vector < int > vec;
        for (int i = 0; i < k; i ++)
            vec.push_back(Pq.top().second), Pq.pop();
        ll Mx = Pq.size() ? Pq.top().first : 0LL;
        ll X = min(A[vec.back()], SM - Mx * k);
        R.push_back(X); SM -= X;
        for (int i = 0; i < k; i ++)
            A[vec[i]] -= X, Pq.push({A[vec[i]], vec[i]}), R.push_back(vec[i]);
    }
    printf("%d\n", (int)R.size() / (k + 1));
    for (int i = 0; i < (int)R.size(); i ++)
    {
        printf("%lld ", R[i]);
        if ((i + 1) % (k + 1) == 0)
            printf("\n");
    }
    return 0;
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &k);
     ~~~~~^~~~~~~~~~~~~~~~
nicegift.cpp:15:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld", &A[i]);
         ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB n=4
2 Correct 2 ms 376 KB n=3
3 Correct 2 ms 256 KB n=3
4 Correct 2 ms 376 KB n=4
5 Correct 2 ms 376 KB n=4
6 Correct 2 ms 256 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 2 ms 256 KB n=3
4 Correct 2 ms 376 KB n=4
5 Correct 2 ms 376 KB n=4
6 Correct 2 ms 256 KB n=2
7 Correct 2 ms 296 KB n=5
8 Correct 2 ms 256 KB n=8
9 Execution timed out 2073 ms 263248 KB Time limit exceeded
10 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 2 ms 256 KB n=3
4 Correct 2 ms 376 KB n=4
5 Correct 2 ms 376 KB n=4
6 Correct 2 ms 256 KB n=2
7 Correct 2 ms 296 KB n=5
8 Correct 2 ms 256 KB n=8
9 Execution timed out 2073 ms 263248 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 669 ms 50436 KB n=1000000
2 Correct 414 ms 39316 KB n=666666
3 Correct 234 ms 21840 KB n=400000
4 Execution timed out 2064 ms 139068 KB Time limit exceeded
5 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 2 ms 256 KB n=3
4 Correct 2 ms 376 KB n=4
5 Correct 2 ms 376 KB n=4
6 Correct 2 ms 256 KB n=2
7 Correct 2 ms 296 KB n=5
8 Correct 2 ms 256 KB n=8
9 Execution timed out 2073 ms 263248 KB Time limit exceeded
10 Halted 0 ms 0 KB -