# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
80730 | inom | Gift (IZhO18_nicegift) | C++14 | 2068 ms | 171152 KiB |
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 <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
#define ll long long
#define mp make_pair
const int MAXN = 1e6;
pair <int, int> a[MAXN];
vector< vector< ll > > ans;
int main() {
int n, k;
scanf("%d%d", &n, &k);
set < pair <ll, int> > S;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i].first);
a[i].second = i + 1;
S.insert(mp(-a[i].first, i + 1));
}
vector <ll> res;
res.resize(3);
while (!S.empty()) {
if (S.size() == 1) {
printf("-1");
return 0;
}
res[0] = 1;
pair <ll, int> P = *S.begin();
S.erase(S.begin());
res[1] = P.second;
pair <ll, int> P2 = *S.begin();
S.erase(S.begin());
res[2] = P2.second;
if (P.first != -1ll) {
S.insert(mp(P.first + 1, P.second));
}
if (P2.first != -1ll) {
S.insert(mp(P2.first + 1, P2.second));
}
ans.push_back(res);
}
if (!S.empty()) {
printf("-1");
return 0;
}
printf("%d\n", (int)ans.size());
for (int i = 0; i < ans.size(); i++) {
for (int j = 0; j <= k; j++) {
printf("%lld ", ans[i][j]);
}
printf("\n");
}
return 0;
}
Compilation message (stderr)
# | 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... |