Pagini recente » Cod sursa (job #2354619) | Cod sursa (job #2267868) | Cod sursa (job #708216) | Cod sursa (job #73855) | Cod sursa (job #2213870)
#include <bits/stdc++.h>
using namespace std;
ifstream in("harta.in");
ofstream out("harta.out");
const int NMAX = 100;
int a[NMAX+2], b[NMAX+2], gata[NMAX+2][NMAX+2];
int N;
int main()
{
in >> N;
for( int i = 1; i <= N; ++i ) in >> a[i] >> b[i];
out << accumulate(a+1, a+N+1, 0) << '\n';
while( *max_element(a+1, a+N+1) > 0 ) {
int x = max_element(a+1, a+N+1) - a;
int y = max_element(b+1, b+N+1) - b;
while( gata[x][y] || x == y )
y = max_element(b+y+1, b+N+1) - b;
--a[x];
--b[y];
gata[x][y] = gata[y][x] = 1;
out << x << ' ' << y << '\n';
}
return 0;
}