Submission #378842

#TimeUsernameProblemLanguageResultExecution timeMemory
378842wiwihoGift (IZhO18_nicegift)C++14
7 / 100
429 ms61880 KiB
#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); ll n, k; cin >> n >> k; vector<pll> a(n); for(int i = 0; i < n; i++){ cin >> a[i].F; a[i].S = i + 1; } sort(a.begin(), a.end(), greater<>()); vector<pair<ll, vector<int>>> ans; int lst = 0; for(int i = 1; i < n; i++){ while(a[lst].F == 0) lst++; if(i == lst) continue; ll t = min(a[i].F, a[lst].F); a[lst].F -= t; a[i].F -= t; ans.eb(mp(t, vector<int>())); ans.back().S.eb(a[lst].S); ans.back().S.eb(a[i].S); } for(int i = 0; i < n; i++){ if(a[i].F != 0){ cout << "-1\n"; return 0; } } cout << ans.size() << "\n"; for(auto& i : ans){ cout << i.F << " "; printv(i.S, cout); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...