Cod sursa(job #866330)

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