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 int long long
#pragma GCC diagnostic ignored "-Wunused-result"
#define len(v) (int)(v.size())
using namespace std;
typedef pair<int, int> pii;
const int maxVerrous = 1000*1000;
int nbVerrous, tailleOperation;
int reqUnlock[maxVerrous];
int cur[maxVerrous];
struct Machin
{
int req, ind;
bool operator< (Machin oth) const
{
int c1 = reqUnlock[ind] - cur[ind];
int c2 = reqUnlock[oth.ind] - cur[oth.ind];
if (c1 != c2) return c1 < c2;
else return ind < oth.ind;
}
};
vector<Machin> tab;
set<Machin> wcur;
signed main()
{
scanf("%lld%lld", &nbVerrous, &tailleOperation);
tab.resize(nbVerrous);
for (int indVerrou = 0; indVerrou < nbVerrous; ++indVerrou) {
scanf("%lld", &reqUnlock[indVerrou]);
tab[indVerrou] = {reqUnlock[indVerrou], indVerrou};
}
sort(tab.begin(), tab.end());
vector<vector<int>> operations;
operations.reserve(100*1000);
vector<int> curOp(tailleOperation + 1);
int indOp = 0;
while ((! tab.empty()) || (! wcur.empty())) {
++indOp;
if (indOp * tailleOperation > 3*1000*1000 || len(tab) + len(wcur) < tailleOperation) {
printf("-1\n");
return 0;
}
while (len(wcur) < tailleOperation) {
wcur.insert(tab.back());
tab.pop_back();
}
auto it = wcur.begin();
int rem = reqUnlock[it->ind] - cur[it->ind];
curOp[0] = rem;
for (int ind = 1; ind <= tailleOperation; ++ind) {
curOp[ind] = it->ind + 1;
cur[it->ind] += rem;
++it;
}
operations.push_back(curOp);
while ((! wcur.empty()) && (reqUnlock[wcur.begin()->ind] == cur[wcur.begin()->ind])) {
wcur.erase(wcur.begin());
}
}
printf("%lld\n", (int)(operations.size()));
for (auto op : operations) {
for (int choisi : op) {
printf("%lld ", choisi);
}
printf("\n");
}
return 0;
}
# | 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... |