Pagini recente » Cod sursa (job #837458) | Cod sursa (job #2766291) | Cod sursa (job #1056825) | Cod sursa (job #1601429) | Cod sursa (job #416906)
Cod sursa(job #416906)
#include<fstream>
#define DIM 10001
using namespace std;
ifstream fin("heavymetal.in");
ofstream fout("heavymetal.out");
int start[DIM], sfarsit[DIM];
int main()
{
int i,j,n,aux,aux2,total,s,x;
fin>>n;
for(i=1;i<=n;++i)
{
fin>>start[i];
fin>>sfarsit[i];
}
for(i=1;i<=n;++i)
for(j=i+1;j<=n;++j)
if((start[i]>start[j])||(start[i]==start[j]&&sfarsit[i]<sfarsit[j]))
{
aux=start[i];
aux2=sfarsit[i];
start[i]=start[j];
sfarsit[i]=sfarsit[j];
start[j]=aux;
sfarsit[j]=aux2;
}
total=0;
x=0;
s=0;
int max=0,k=0;
for(j=1;j<=n;++j)
{
x=0;
s=0;k++;
for(i=k;i<=n;++i)
if(start[i]>=x)
{
total=sfarsit[i]-start[i];
x=sfarsit[i];
s=s+total;
}
if(s>max) max=s;
}
// for(i=1;i<=n;++i)
// fout<<start[i]<<" "<<sfarsit[i]<<"\n";
fout<<max;
return 0;
}