Pagini recente » Cod sursa (job #2521887) | Cod sursa (job #3282891) | Poliție | Cod sursa (job #3256640) | Cod sursa (job #1761364)
//PROBLEMA LUI SEBICA :)
//BAI SARACILOR
//TOT FARA SURSA DE APROAPE 100?
//twitch.tv/lokitolou
//comentariu
//E posibil ca Ana sa aiba mere
#include<fstream>
#include<algorithm>
using namespace std;
ifstream f("rucsac.in");
ofstream g("rucsac.out");
int n,gmax,s;
struct ob{int p,gr;
float x;}v[5001];
bool test(ob t1, ob t2)
{
return(t1.x>t2.x or (t1.x==t2.x and t1.gr<t2.gr));}
using namespace std;
int main()
{
f>>n>>gmax;
for(int i=1;i<=n;++i)
{f>>v[i].gr>>v[i].p;
v[i].x=v[i].p/(v[i].gr+0.0);}
sort(v+1,v+n+1,test);
for(int i=1;i<=n;++i)
{
if(gmax-v[i].gr>=0)
{
s+=v[i].p;
gmax-=v[i].gr;
}
}
g<<s<<endl;
}