Cod sursa(job #2044875)

Utilizator SamySam2099Irsai Samuel SamySam2099 Data 21 octombrie 2017 15:37:16
Problema Heavy metal Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.72 kb
#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;
}