Pagini recente » Cod sursa (job #89698) | Cod sursa (job #2137185) | Cod sursa (job #2142466) | Cod sursa (job #1427406) | Cod sursa (job #3191054)
#include <bits/stdc++.h>
using namespace std;
ifstream in("harta.in");
ofstream out("harta.out");
int n, x, y, s, mx, poz;
struct Nod {
int in;
int nod;
int out;
Nod(int a, int b, int c) : in(a), nod(b), out(c) {}
bool operator < (const Nod& other) const
{
if (in > other.in)
return true;
if (in < other.in)
return false;
else
return out > other.out;
}
};
vector<Nod> drum;
int main()
{
in >> n;
drum.push_back({0, 0, 0});
for(int i = 1; i <= n; i++)
{
in >> x >> y;
Nod nod(y, i, x);
drum.push_back(nod);
s += y;
}
out << s << endl;
while(n)
{
sort(drum.begin() + 1, drum.end());
n--;
mx = 0; poz = 0;
for (int i = 1; i < drum.size(); i++)
{
if (drum[i].out > mx)
{
mx = drum[i].out;
poz = i;
}
}
for (int i = 1; i <= mx + 1; i++)
{
if (i != poz && drum[poz].out > 0)
{
drum[i].in--;
drum[poz].out--;
out << drum[poz].nod << " " << drum[i].nod << endl;
}
}
}
return 0;
}