/*
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, s;
bool hav = 1;
priority_queue<pair<LL, int>> q;
vector<pair<LL, int>> ans;
pair < LL, int > mn = {mod*mod,mod};
int main()
{
cin >> n >> k;
for (int i = 0; i < n; i++)
{
scanf("%lld", a + i);
s += a[i];
mn = min(mn, MP(a[i], i));
if (i && a[i] != a[i - 1])
hav = 0;
}
mn.first--;
for (int i = 0; i < n; i++)
q.push(MP(a[i]-mn.first, i));
if(!hav)
{
int step = 0;
vector<pair<LL, int>> st;
while (!q.empty())
{
for (int i = 0; i < k; i++)
{
if (q.empty())
{
cout << -1 << endl;
return 0;
}
st.PB(q.top());
q.pop();
}
LL d = st.back().first;
if (!q.empty())
d = min(st.back().first - q.top().first+1ll, d);
for (int i = k - 1; i >= 0; i--)
{
ans.PB(MP(d, st[i].second));
if (st[i].first - d > 0)
q.push(MP(st[i].first - d, st[i].second));
st.pop_back();
}
}
if (!q.empty() || !st.empty())
{
cout << -1 << endl;
return 0;
}
}
a[0] = mn.first;
if (a[0])
{
d = k / gcd(n, k);
if (a[0] % d != 0)
{
cout << -1 << endl;
return 0;
}
for (LL i = 0; i < d*n; i++)
ans.PB(MP(a[0] / d,i%n));
}
cout << ans.size() / k;
for (int i = 0; i < ans.size(); i++)
{
if (i%k == 0)
cout << endl << ans[i].first << " ";
cout << ans[i].second + 1 << " ";
}
cout << endl;
return 0;
}
/*
4 2
1 2 3 4
4 3
7 9 11 9
14 7
11 8 10 8 12 8 12 12 10 10 10 9 8 12
*/
Compilation message
nicegift.cpp: In function 'int main()':
nicegift.cpp:59:7: warning: unused variable 'step' [-Wunused-variable]
int step = 0;
^~~~
nicegift.cpp:107:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < ans.size(); i++)
~~^~~~~~~~~~~~
nicegift.cpp:46:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld", a + i);
~~~~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
n=4 |
2 |
Correct |
2 ms |
376 KB |
n=3 |
3 |
Correct |
2 ms |
256 KB |
n=3 |
4 |
Correct |
2 ms |
256 KB |
n=4 |
5 |
Correct |
1 ms |
376 KB |
n=4 |
6 |
Correct |
2 ms |
376 KB |
n=2 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
n=4 |
2 |
Correct |
2 ms |
376 KB |
n=3 |
3 |
Correct |
2 ms |
256 KB |
n=3 |
4 |
Correct |
2 ms |
256 KB |
n=4 |
5 |
Correct |
1 ms |
376 KB |
n=4 |
6 |
Correct |
2 ms |
376 KB |
n=2 |
7 |
Correct |
2 ms |
256 KB |
n=5 |
8 |
Correct |
2 ms |
376 KB |
n=8 |
9 |
Correct |
16 ms |
1012 KB |
n=14 |
10 |
Correct |
9 ms |
760 KB |
n=11 |
11 |
Correct |
64 ms |
3152 KB |
n=50000 |
12 |
Correct |
80 ms |
3812 KB |
n=50000 |
13 |
Correct |
43 ms |
1520 KB |
n=10 |
14 |
Incorrect |
5 ms |
1012 KB |
Jury has the answer but participant has not |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
n=4 |
2 |
Correct |
2 ms |
376 KB |
n=3 |
3 |
Correct |
2 ms |
256 KB |
n=3 |
4 |
Correct |
2 ms |
256 KB |
n=4 |
5 |
Correct |
1 ms |
376 KB |
n=4 |
6 |
Correct |
2 ms |
376 KB |
n=2 |
7 |
Correct |
2 ms |
256 KB |
n=5 |
8 |
Correct |
2 ms |
376 KB |
n=8 |
9 |
Correct |
16 ms |
1012 KB |
n=14 |
10 |
Correct |
9 ms |
760 KB |
n=11 |
11 |
Correct |
64 ms |
3152 KB |
n=50000 |
12 |
Correct |
80 ms |
3812 KB |
n=50000 |
13 |
Correct |
43 ms |
1520 KB |
n=10 |
14 |
Incorrect |
5 ms |
1012 KB |
Jury has the answer but participant has not |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1048 ms |
53428 KB |
Not all heaps are empty in the end |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
n=4 |
2 |
Correct |
2 ms |
376 KB |
n=3 |
3 |
Correct |
2 ms |
256 KB |
n=3 |
4 |
Correct |
2 ms |
256 KB |
n=4 |
5 |
Correct |
1 ms |
376 KB |
n=4 |
6 |
Correct |
2 ms |
376 KB |
n=2 |
7 |
Correct |
2 ms |
256 KB |
n=5 |
8 |
Correct |
2 ms |
376 KB |
n=8 |
9 |
Correct |
16 ms |
1012 KB |
n=14 |
10 |
Correct |
9 ms |
760 KB |
n=11 |
11 |
Correct |
64 ms |
3152 KB |
n=50000 |
12 |
Correct |
80 ms |
3812 KB |
n=50000 |
13 |
Correct |
43 ms |
1520 KB |
n=10 |
14 |
Incorrect |
5 ms |
1012 KB |
Jury has the answer but participant has not |
15 |
Halted |
0 ms |
0 KB |
- |