Submission #89447

# Submission time Handle Problem Language Result Execution time Memory
89447 2018-12-14T17:11:25 Z antimirage Gift (IZhO18_nicegift) C++17
30 / 100
225 ms 65660 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 1e6 + 7;
const int INF = 1e9 + 7;

int a[N], p[N];
int n, k, s;

vector < pair < int, int > > dq[N];
vector < int > ans[N];

main(){
	cin >> n >> k;
	int mx = -1;
	for (int i = 0; i < n; i++){
        scanf("%d", &a[i]);
        s += a[i];
        mx = max(mx, a[i]);
	}
	int h = s / k, cs = 0, c = 0;
	if (mx > h || s % k != 0){
        cout << -1;
        return 0;
	}
	for (int i = 0; i < n; i++){
        if(a[i] == 0) continue;
        if (cs + a[i] >= h){
            a[i] -= (h - cs);
            dq[c].push_back(make_pair(h - cs, i));
            cs = 0; i--; c++;
            continue;
        }
        cs += a[i];
        dq[c].push_back(make_pair(a[i], i));
	}
	int g = 0;
	while (s != 0){
        int mn = -1;
        for (int i = 0; i < k; i++){
            if (mn == -1){
                mn = dq[i][p[i]].first;
                continue;
            }
            mn = min(mn, dq[i][p[i]].first);
        }
        ans[g].push_back(mn);
        for (int i = 0; i < k; i++){
            dq[i][p[i]].first -= mn;
            ans[g].push_back(dq[i][p[i]].second + 1);
            if(dq[i][p[i]].first == 0)
                p[i]++;
        }
        g++;
        s -= (mn * k);
	}
	cout << g << endl;
	int it = 0;
	while (it != g){
        for (int i = 0; i < (int)ans[it].size(); i++){
            cout << ans[it][i] << " ";
        }
        cout << endl;
        it++;
	}
}
/**
4 2
2 3 3 2
**/

Compilation message

nicegift.cpp:13:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
nicegift.cpp: In function 'int main()':
nicegift.cpp:17:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a[i]);
         ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 48 ms 47224 KB n=4
2 Correct 48 ms 47352 KB n=3
3 Correct 49 ms 47592 KB n=3
4 Correct 50 ms 47676 KB n=4
5 Correct 49 ms 47676 KB n=4
6 Correct 47 ms 47676 KB n=2
# Verdict Execution time Memory Grader output
1 Correct 48 ms 47224 KB n=4
2 Correct 48 ms 47352 KB n=3
3 Correct 49 ms 47592 KB n=3
4 Correct 50 ms 47676 KB n=4
5 Correct 49 ms 47676 KB n=4
6 Correct 47 ms 47676 KB n=2
7 Correct 49 ms 47676 KB n=5
8 Correct 50 ms 47676 KB n=8
9 Correct 48 ms 47680 KB n=14
10 Correct 48 ms 47680 KB n=11
11 Correct 142 ms 50496 KB n=50000
12 Correct 139 ms 50496 KB n=50000
13 Correct 48 ms 50496 KB n=10
14 Correct 50 ms 50496 KB n=685
15 Correct 48 ms 50496 KB n=623
16 Correct 51 ms 50496 KB n=973
# Verdict Execution time Memory Grader output
1 Correct 48 ms 47224 KB n=4
2 Correct 48 ms 47352 KB n=3
3 Correct 49 ms 47592 KB n=3
4 Correct 50 ms 47676 KB n=4
5 Correct 49 ms 47676 KB n=4
6 Correct 47 ms 47676 KB n=2
7 Correct 49 ms 47676 KB n=5
8 Correct 50 ms 47676 KB n=8
9 Correct 48 ms 47680 KB n=14
10 Correct 48 ms 47680 KB n=11
11 Correct 142 ms 50496 KB n=50000
12 Correct 139 ms 50496 KB n=50000
13 Correct 48 ms 50496 KB n=10
14 Correct 50 ms 50496 KB n=685
15 Correct 48 ms 50496 KB n=623
16 Correct 51 ms 50496 KB n=973
17 Correct 50 ms 50496 KB n=989
18 Correct 48 ms 50496 KB n=563
19 Correct 54 ms 50496 KB n=592
20 Correct 54 ms 50496 KB n=938
21 Correct 51 ms 50496 KB n=747
22 Correct 51 ms 50496 KB n=991
# Verdict Execution time Memory Grader output
1 Incorrect 225 ms 65660 KB Jury has the answer but participant has not
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 48 ms 47224 KB n=4
2 Correct 48 ms 47352 KB n=3
3 Correct 49 ms 47592 KB n=3
4 Correct 50 ms 47676 KB n=4
5 Correct 49 ms 47676 KB n=4
6 Correct 47 ms 47676 KB n=2
7 Correct 49 ms 47676 KB n=5
8 Correct 50 ms 47676 KB n=8
9 Correct 48 ms 47680 KB n=14
10 Correct 48 ms 47680 KB n=11
11 Correct 142 ms 50496 KB n=50000
12 Correct 139 ms 50496 KB n=50000
13 Correct 48 ms 50496 KB n=10
14 Correct 50 ms 50496 KB n=685
15 Correct 48 ms 50496 KB n=623
16 Correct 51 ms 50496 KB n=973
17 Correct 50 ms 50496 KB n=989
18 Correct 48 ms 50496 KB n=563
19 Correct 54 ms 50496 KB n=592
20 Correct 54 ms 50496 KB n=938
21 Correct 51 ms 50496 KB n=747
22 Correct 51 ms 50496 KB n=991
23 Incorrect 225 ms 65660 KB Jury has the answer but participant has not
24 Halted 0 ms 0 KB -