Pagini recente » Cod sursa (job #2877540) | Cod sursa (job #2472026) | Cod sursa (job #2271962) | Cod sursa (job #5219) | Cod sursa (job #1322094)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("lupu.in");
ofstream g("lupu.out");
const int NMax = 100002;
struct Oi{
int d,l; //distanta , lana
}Sheep[NMax];
bool SheepComp(Oi A, Oi B)
{
return A.d > B.d ;
}
int main()
{
int n,x,l,i,j,st,dr;
f>>n>>x>>l;
for(i=1;i<=n;i++)
{
f>>Sheep[i].d>>Sheep[i].l;
}
sort(Sheep+1,Sheep+n+1,SheepComp);
dr = Sheep[1].d;
st = Sheep[1].d - l + 1;
// Luam din intervalul [st,dr]
i=1;
long long int tempmax;
long long int result= 0;
while(dr>=0)
{
// g<<st<<" "<<dr<<endl;
tempmax = 0;
while(Sheep[i].d <= dr && st <= Sheep[i].d && i<=n)
{
if( Sheep[i].d <= x && Sheep[i].l > tempmax)
{
tempmax = Sheep[i].l;
}
i++;
}
result = result + tempmax;
dr=dr-l;
st=st-l;
}
g<<result;
}