# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
92169 | davitmarg | Gift (IZhO18_nicegift) | C++17 | 2047 ms | 89756 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.
/*
DEATH-MATCH
Davit-Marg
*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iterator>
#include <ctype.h>
#include <stdlib.h>
#include <cassert>
#include <fstream>
#define mod 998244353ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
using namespace std;
LL gcd(LL a, LL b) {
while (b) {
a %= b;
swap(a, b);
}
return a;
}
LL n,k,a[1000006],d,v,s;
bool hav=1;
priority_queue<pair<LL, int>> q;
vector<int> ans;
int main()
{
cin >> n >> k;
for (LL i = 0; i < n; i++)
{
scanf("%lld", a + i);
s += a[i];
q.push(MP(a[i],i));
if (i && a[i] != a[i - 1])
hav = 0;
}
if (hav && 0)
{
d = k / gcd(n, k);
if (a[0] % d != 0)
{
cout << -1 << endl;
return 0;
}
cout << d * n / k;
for (LL i = 0; i < d*n; i++)
{
v %= k;
if (v == 0)
cout << endl << a[0] / d << " ";
cout << (i%n) + 1 << " ";
v++;
}
cout << endl;
}
else
{
int step = 0;
vector<pair<LL, int>> st;
while (!q.empty())
{
while (step == 0 && !st.empty())
{
q.push(st[st.size()-1]);
st.pop_back();
}
pair<LL, int> p=q.top();
q.pop();
ans.PB(p.second);
p.first--;
if (p.first > 0)
st.PB(p);
step++;
step %= k;
}
if (!q.empty() || !st.empty())
{
cout << -1 << endl;
return 0;
}
else
{
cout << ans.size() / k;
for (int i = 0; i < ans.size(); i++)
{
if (i%k == 0)
cout<< endl << 1 << " ";
cout << ans[i]+1 << " ";
}
cout << endl;
}
}
return 0;
}
/*
4 2
1 1 4 4
4 3
6 6 6 6
14 7
10 10 10 10 10 10 10 10 10 10 10 10 10 10
*/
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... |