이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb emplace_back
#define pii pair<int,int>
#define ff first
#define ss second
#define All(x) x.begin(), x.end()
using namespace std;
#define debug(args...) kout("[ " + string(#args) + " ]", args)
void kout() { cerr << endl; }
template <class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ',kout(b...); }
template <class T> void pary(T L, T R) { while (L != R) cerr << *L << " \n"[++L==R]; }
struct Node {
int X;
vector <int> I;
Node(int x) {
X = x;
}
};
const int MAXN = 1000000;
int N, K;
vector <pii> arr;
vector <Node> ops;
bool flag = true;
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> N >> K;
arr.resize(N);
for (int i = 0; i < N; i++) {
auto &[v, id] = arr[i];
cin >> v;
id = i + 1;
}
while (flag) {
sort(All(arr), [](const pii x, const pii y){
return x.ff > y.ff;
});
if (!arr[0].ff) {
break;
} else if (!arr[K-1].ff) {
flag = false;
break;
}
int sum = 0, mmax = (K < N ? arr[K].ff : 0);
for (int i = 0; i < N; i++)
sum += arr[i].ff;
int p = min(arr[K-1].ff, (sum - (mmax * K)) / K);
if (p <= 0) {
flag = false;
}
ops.pb(Node(p));
for (int i = 0; i < K; i++) {
arr[i].ff -= p;
ops[ops.size()-1].I.pb(arr[i].ss);
}
}
if (flag) {
cout << ops.size() << '\n';
for (Node now : ops) {
cout << now.X;
for (int i : now.I) cout << ' ' << i;
cout << '\n';
}
} else {
cout << -1 << '\n';
}
}
컴파일 시 표준 에러 (stderr) 메시지
nicegift.cpp: In function 'int main()':
nicegift.cpp:32:9: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
32 | auto &[v, id] = arr[i];
| ^
# | 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... |