# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
881301 | dimashhh | Gift (IZhO18_nicegift) | C++17 | 569 ms | 192672 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 <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 1;
#define int long long
int n,k;
ll a[N];
set<pair<ll,ll>> st;
vector<pair<vector<int>,int>> res(N * 3);
void test(){
cin >> n >> k;
for(int i = 1;i <= n;i++){
cin >> a[i];
st.insert({a[i],i});
}
int it = 1;
while(!st.empty()){
if((int)(it - 1) * k > 3e6||st.size() < k){
cout << -1 << '\n';
return;
}
vector<int> f;
int oo;
for(int i = 1;i <= k;i++){
auto [x,y] = *st.rbegin();
st.erase({x,y});
oo = x;
f.push_back(y);
}
res[it] = {f,oo};
it++;
for(auto j:f){
a[j] -= oo;
if(a[j]){
st.insert({a[j],j});
}
}
}
cout << it - 1 << '\n';
for(int f = 1;f < it;f++){
cout << res[f].second << ' ';
for(auto j:res[f].first)
cout << j << ' ';
cout << '\n';
}
}
main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int T = 1;
// cin >> T;
while(T--)
test();
}
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... |