This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
int v;
vector <Node> ops;
bool flag = true;
set <pii> now;
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> N >> K;
for (int i = 0; i < N; i++) {
cin >> v;
now.insert(pii(v, i+1));
}
while (now.size()) {
if (now.size() < K) {
flag = false;
break;
}
auto it = prev(now.end());
ops.pb(1);
vector <pii> tmp;
int x = 0;
// debug(now.size());
for (int i = 0; i < K; i++) {
// debug(it->ff, it->ss);
ops[ops.size()-1].I.pb(it->ss);
tmp.pb(*it);
if (i+1 < K) {
it = prev(now.erase(it));
} else {
now.erase(it);
if (!now.size())
x = it->ff;
else
x = it->ff - prev(now.end())->ff + 1;
}
}
ops[ops.size()-1].X = x;
for (pii i : tmp) {
if (i.ff-x)
now.insert(pii(i.ff-x, 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';
}
}
Compilation message (stderr)
nicegift.cpp: In function 'int main()':
nicegift.cpp:36:18: warning: comparison of integer expressions of different signedness: 'std::set<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
36 | if (now.size() < K) {
| ~~~~~~~~~~~^~~
# | 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... |