Cod sursa(job #1973162)

Utilizator 00MikeComputer00Mihnea Andreescu 00MikeComputer00 Data 24 aprilie 2017 18:01:05
Problema Heavy metal Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <fstream>
#include <algorithm>

using namespace std;
ifstream cin("heavymetal.in");
ofstream cout("heavymetal.out");
struct w
{
    int x,y;
};
bool z(w a,w b)
{
    return a.x<b.x;
}
w v[100005];
bool ok;
int main()
{
    int n,i,j,s=0;
    cin>>n;
    for(i=1;i<=n;i++)
        cin>>v[i].x>>v[i].y;
    sort(v+1,v+n+1,z);
    i=1;
    while(1<2)
    {
        s=s+v[i].y-v[i].x;
        j=v[i].y;
        while(v[i].x<j)
            {
            i++;
            if(i==n+1)
            {
                ok=1;
                break;
            }
            }
        if(ok==1)
            break;
    }
    cout<<s;
    cin.close();
    cout.close();
    return 0;
}