이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
int n, k;
long long a[N];
long long sum;
long long X;
vector < vector <int> > vres;
int lcm(int x, int y) { // n * k <= 2e6
    int g = __gcd(x, y);
    return x * (y / g);
}
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n >> k;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i], sum += a[i];
    }
    bool equal = true;
    for (int i = 2; i <= n; ++i) equal &= (a[i] == a[1]);
    
    assert(sum <= 1e5 || equal);
    if (sum % k != 0) return printf("-1\n"), 0;
    priority_queue < pair<long long, int> > pq;
    for (int i = 1; i <= n; ++i) pq.push(make_pair(a[i], i));
    if (equal) X = sum / lcm(n, k); else X = 1;
    while(!pq.empty()) {
        int taken = 0;
        vector<int> cur;
        while(!pq.empty() && taken < k) {
            int pos = pq.top().second; pq.pop();
            cur.push_back(pos);
            a[pos] -= X;
            ++taken;
        }
        if (taken != k) return printf("-1\n"), 0;
        for (int pos : cur) {
            if (a[pos] > 0) {
                pq.push(make_pair(a[pos], pos));
            }
        }
        vres.push_back(cur);
    }
    printf("%d\n", vres.size());
    for (auto &v : vres) {
        printf("%lld ", X); // X
        for (int &pos : v) printf("%d ", pos); printf("\n");
    }
}
컴파일 시 표준 에러 (stderr) 메시지
nicegift.cpp: In function 'int main()':
nicegift.cpp:53:31: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<std::vector<int> >::size_type {aka long unsigned int}' [-Wformat=]
     printf("%d\n", vres.size());
                               ^| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |