Cod sursa(job #3236725)

Utilizator not_anduAndu Scheusan not_andu Data 30 iunie 2024 17:28:48
Problema Taramul Nicaieri Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1 kb
#include <bits/stdc++.h>

using namespace std;

#define INFILE "harta.in"
#define OUTFILE "harta.out"

int n;
vector<int> adj;
vector<pair<int, int> > grade;

bool compare(int node1, int node2){
    return (grade[node1] > grade[node2]);
}

void solve(){

    cin >> n;
    adj.resize(n);
    grade.resize(n);

    int cnt = 0;
    for(int i = 0; i < n; ++i){
        cin >> grade[i].first >> grade[i].second;
        adj[i] = i;
        cnt += grade[i].first;
    }

    cout << cnt << '\n';
    for(int i = 0; i < n; ++i){
        sort(adj.begin(), adj.end(), compare);
        for(int j = 0; j < n; ++j){
            if(i != adj[j] && grade[adj[j]].first > 0 && grade[i].second > 0){
                --grade[adj[j]].first;
                --grade[i].second;
                cout << adj[j] + 1 << " " << i + 1 << '\n';
            }
        }
    }

}

int main(){
    ios_base::sync_with_stdio(false);
    freopen(INFILE, "r", stdin);
    freopen(OUTFILE, "w", stdout);
    cin.tie(0), cout.tie(0);
    solve();
    return 0;
}