Pagini recente » Cod sursa (job #2490468) | Cod sursa (job #1881164) | Istoria paginii runda/simulare_oji_2023_clasa_9_14_martie/clasament | Cod sursa (job #1699136) | Cod sursa (job #2399503)
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("energii.in");
ofstream g("energii.out");
const int mr=10002;
int G,W,d[mr+6];
void dinamica (int x,int y)
{
for(int i=mr-1;i>=1; i--){
if(d[i]!=0&&x+i<=mr-1){
if((d[x+i]>d[i]+y||d[x+i]==0))d[x+i]=d[i]+y;
}
}
if(d[x]>y||d[x]==0)d[x]=y;
}
void citire(){
f>>G >>W ;
for(int i= 1; i<= G; i++)
{
int x,y;
f>> x>> y;
dinamica(x,y);
}
}
int main()
{ citire();
int i= W;
while( d[ i ] == 0&& i<mr+5){
i++;
}
if(i>mr)g<<"-1";
else{
int mi= d[i];
for(int j= i+1; j<= mr; j++)
{
if(mi> d[j]&& d[j]!=0){mi=d[j];}
}
g<<mi;
}
return 0;
}