# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
378647 | wiwiho | Gift (IZhO18_nicegift) | C++14 | 588 ms | 62560 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>
#define mp make_pair
#define F first
#define S second
#define eb emplace_back
#define printv(a, b) { \
for(auto pv : a) b << pv << " "; \
b << "\n"; \
}
using namespace std;
typedef long long ll;
using pll = pair<ll, ll>;
using pii = pair<int, int>;
const ll MAX = 1LL << 60;
ostream& operator<<(ostream& o, pll p){
return o << '(' << p.F << ',' << p.S << ')';
}
ll iceil(ll a, ll b){
return (a + b - 1) / b;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, k;
cin >> n >> k;
priority_queue<pll> pq;
for(int i = 1; i <= n; i++){
ll a;
cin >> a;
pq.push(mp(a, i));
}
vector<pair<ll, vector<int>>> ans;
while(pq.size() >= k){
vector<pll> t;
for(int i = 0; i < k; i++){
t.eb(pq.top());
pq.pop();
}
ll tmp = t.back().F;
ans.eb(mp(tmp, vector<int>()));
for(pll i : t){
ans.back().S.eb(i.S);
i.F -= tmp;
if(i.F) pq.push(i);
}
}
if(!pq.empty()){
cout << "-1\n";
return 0;
}
cout << ans.size() << "\n";
for(auto& i : ans){
cout << i.F << " ";
printv(i.S, cout);
}
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... |