Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<fstream>
- #include<vector>
- #include<stdint.h>
- #include<map>
- #include<string>
- #include<iomanip>
- #include<algorithm>
- #define all(container) container.begin(), container.end()
- #define fors(counter, start, finish) for (ll counter = start; counter < finish; ++counter)
- #define forb(counter, start, finish) for (int counter = start; counter >= finish; --counter)
- #define vec(type) std::vector<type>
- #define dvec(type) std::vector<std::vector<type>>
- #define ll int64_t
- //#define fin std::cin
- struct versh {
- int idx = 0;
- int weight = 0;
- };
- int main() {
- std::ifstream fin("input.txt");
- std::ofstream fout("output.txt");
- int m;
- fin >> m;
- fors(i, 0, m) {
- int n, sum = 0; fin >> n;
- vec(versh) v(n);
- fors(i, 0, n) {
- fin >> v[i].weight;
- v[i].idx = i;
- sum += v[i].weight;
- }
- fout << sum / 2 << std::endl;
- std::sort(all(v),
- [](auto& lhs, auto& rhs) {return lhs.weight > rhs.weight; });
- fors(j, 0, n) {
- int k = 0;
- while (v[j].weight != 0 && k < n) {
- if (v[k].weight != 0 && k != j) {
- v[j].weight--;
- v[k].weight--;
- fout << v[j].idx + 1 << " " << v[k].idx + 1 << std::endl;
- }
- k++;
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment