Pagini recente » Cod sursa (job #488868) | Cod sursa (job #609868) | Cod sursa (job #1695805) | Cod sursa (job #1382143) | Cod sursa (job #2044875)
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
ifstream f("heavymetal.in");
ofstream g("heavymetal.out");
const int Nmax=100000;
int G[Nmax+5],v[Nmax+5];
int N;
struct formatie
{
int A,B;
};
bool compare(formatie f1,formatie f2)
{
return f1.A<f2.A;
}
bool compare2(formatie f1,formatie f2)
{
return f1.B>f2.B;
}
int main()
{
f>>N;
formatie G[N];
for(int i=1;i<=N;i++)
{
int x,y;
f>>x>>y;
G[i].A=x;G[i].B=y;
}
sort(G,G+N,compare);
sort(G,G+N,compare2);
int s=G[1].B-G[1].A;
for(int i=1;i<N;i++)
{
if(G[i].A!=G[i+1].A)
{
s+=G[i+1].B-G[i+1].A;
}
}
g<<s;
return 0;
}