Pagini recente » Cod sursa (job #2190440) | Cod sursa (job #385705) | Cod sursa (job #3252561) | Cod sursa (job #2752791) | Cod sursa (job #866339)
Cod sursa(job #866339)
//#include <fstream>
//#include <iostream>
//using namespace std;
#include <cstdio>
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;
FILE *in = fopen("lupu.in", "r");
fscanf(in, "%i%i%i", &n, &x, &l);
for(int i = 0; i < n; i++) //in >> t[i].d >> t[i].l;
fscanf(in, "%i%i", &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();
freopen("lupu.out", "w", in);
fprintf(in, "%i", total);
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;
}
}
}
}