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;
#define sz(s) (int)s.size()
#define ff first
#define ss second
int main(){
ios::sync_with_stdio(false); cin.tie(nullptr);
int n, k;
cin >> n >> k;
vector <int> a(n);
multiset <pair<int,int>> s;
for(int i = 0; i < n; i++){
cin >> a[i];
s.insert({a[i],i});
}
vector <pair<int,int>> v;
while(sz(s) > 1){
pair <int,int> x = *(--s.end());
s.erase(--s.end());
pair <int,int> y = *(--s.end());
s.erase(--s.end());
x.ff--;
y.ff--;
if(x.ff != 0) s.insert(x);
if(y.ff != 0) s.insert(y);
v.push_back({x.ss,y.ss});
}
if(sz(s) == 1){
cout << -1;
return 0;
}
cout << sz(v) << "\n";
for(auto i : v){
cout << 1 << ' ' << i.ff << ' ' << i.ss << '\n';
}
}
# | 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... |