Cod sursa(job #911630)

Utilizator valentina506Moraru Valentina valentina506 Data 11 martie 2013 20:00:06
Problema Lupul Urias si Rau Scor 16
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.76 kb
#include<fstream>
#include<set>
using namespace std;
int n,m,k,i,j,pas,poz;
struct oaie
{
    unsigned long long dist,l;
};
oaie a[100001];
bool uz[100001],ok;
unsigned long long max1,sol,d;
int main()
{
    ifstream f("lupu.in");
    ofstream g("lupu.out");
    f>>n>>m>>k;
    for(i=1;i<=n;++i)
    {
        f>>a[i].dist>>a[i].l;
        a[i].dist=(m-a[i].dist)/k+1;
    }
    ok=1;
    pas=sol=0;
    while(ok&&pas<n)
    {
        ok=max1=0;
        for(i=1;i<=n;++i)
            if(!uz[i]&&a[i].dist==pas+1&&a[i].l>max1)
            max1=a[i].l,poz=i;
        if(max1>0)
        {
            sol+=max1;
            uz[poz]=1;
            ok=1;
            //g<<poz<<" "<<sol<<"\n";
        }
        ++pas;
    }
    g<<sol;
}