Cod sursa(job #2747319)

Utilizator EmiHHodoroaba Emanuel EmiH Data 29 aprilie 2021 00:18:25
Problema Loto Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <fstream>
#define NMAX 10005
using namespace std;

int n,m,k;
int ms[NMAX], cost[NMAX];
bool b[NMAX];

long long sol;

int main(){

    ifstream in("loto.in");
    ofstream out("loto.out");
    in>>n>>m>>k;
    for (int i=1; i<=m;i++)
    {
        in>>ms[i]>>cost[i];
    }

    while (n>0)
    {
        int Min=9999999;
        int poz=0;
        for (int i=1;i<=m;i++)
        {
            if (b[i]==false && ms[i]>=n)
            {
                if (cost[i]<Min)
                {
                    Min=cost[i];
                    poz=i;
                }
            }
        }
        n=n-k;
        sol=sol+Min;
        b[poz]=1;
    }
    out<<sol<<'\n';
}