Pagini recente » Cod sursa (job #1303120) | Cod sursa (job #2746246) | Cod sursa (job #1337398) | Cod sursa (job #504630) | Cod sursa (job #866330)
Cod sursa(job #866330)
#include <fstream>
#include <iostream>
using namespace std;
struct oaie{
int d;
int l;
};
void sort(int n);
oaie t[100000];
int main()
{
int n, x, l, total = 0;
ifstream in("lupu.in");
in >> n >> x >> l;
for(int i = 0; i < n; i++) in >> t[i].d >> t[i].l;
sort(n);
//for(int i = 0; i < n; i++) cout << t[i].l << " ";
for(int i = 0; i < n; i++)
{
if(t[i].d <= x)
{
total += t[i].l;
//oile se deplaseaza
for(int j = i + 1; j < n; j++) t[j].d += l;
}
}
//cout << total;
ofstream out("lupu.out");
out << total;
in.close();
out.close();
return 0;
}
void sort(int n)
{
int val;
for(int i = 0; i < n - 1; i++)
{
for(int j = i + 1; j < n; j++)
{
if(t[j].l > t[i].l)
{
val = t[i].l;
t[i].l = t[j].l;
t[j].l = val;
val = t[i].d;
t[i].d = t[j].d;
t[j].d = val;
}
}
}
}