Cod sursa(job #866339)

Utilizator andrei97andrei andrei97 Data 27 ianuarie 2013 20:24:18
Problema Lupul Urias si Rau Scor 8
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.26 kb
//#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;
            }
        }
    }
}