Cod sursa(job #1347715)

Utilizator JokerOsHreceniuc Cristian JokerOs Data 19 februarie 2015 09:41:40
Problema Jocul Flip Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.88 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("seg.in");
ofstream g("seg.out");
struct segment
{
    int capat;
    int lungime;
    int s;
    int a;
    int maxx;
};
segment x[100];
bool c[100];
int main()
{
    int n,k,i,l=1,b,j,s=0,maxx,a,m,nr,y[100];
    f>>n;
    s=0;
    maxx=1;
    for(i=1; i<=n; i++)
    {
        f>>x[i].capat;
        f>>x[i].lungime;
        a=x[i].lungime+x[i].capat;
        for(j=x[i].capat; j<=x[i].lungime+x[i].capat; j++)
        {
            if(a>maxx)
                maxx=a;
            if(c[j]==1)
                j++;
            else if(c[j]==0)
            {
                c[j]=1;
                s++;
            }
        }
    }
    for(i=1; i<=maxx; i++)
    {
        if(c[i]==0)
            s--;
        else if(c[i]==1)
            i++;

    }
    g<<s;
    return 0;
}