Cod sursa(job #3167938)

Utilizator CastielGurita Adrian Castiel Data 11 noiembrie 2023 12:06:48
Problema Lupul Urias si Rau Scor 44
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.43 kb
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("lupu.in");
ofstream fout("lupu.out");
int n,x,l,d[100005],a[100005],v[100005],s;
int main()
{
    fin>>n>>x>>l;
    for(int i=1;i<=n;i++)
    {
        fin>>d[i]>>a[i];
        d[i]=(x-d[i])/l;
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            if(a[i]<a[j])
            {
                swap(a[i],a[j]);
                swap(d[i],d[j]);
            }
            else if(a[i]==a[j])
            {
                if(d[i]>d[j])
                {
                    swap(a[i],a[j]);
                    swap(d[i],d[j]);
                }
            }
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(v[d[i]]==0){v[d[i]]=a[i];}
        else{
            for(int j=d[i]-1;j>=0;j--)
            {
                if(v[j]==0){v[j]=a[i];break;}
            }
        }
    }
    for(int i=0;i<=x/l+1;i++)
    {
        s=s+v[i];
    }
    fout<<s;
    fin.close();
    fout.close();
    return 0;
}