Pagini recente » Profil Andrulian | Cod sursa (job #565530) | Profil Andrei-27 | Cod sursa (job #1105506) | Cod sursa (job #546952)
Cod sursa(job #546952)
#include <fstream.h>
#include <algorithm>
#define val 10010
using namespace std;
struct pereche{
float a;
int b;
int c;
};
int com(pereche a , pereche b){
return a.a>b.a;
}
pereche V[val];
int n , Min , cost , i , p , min2;
float w , d;
int main(){
ifstream f("energii.in");
ofstream g("energii.out");
f>>n>>Min;
for(i=1;i<=n;i++){
f>>w>>d;
V[i].a=w/d;
V[i].b=(int) d;
V[i].c=(int) w;
}
sort(V+1 , V+n+1 , com);
while(min2<Min){
min2+=V[++p].c;
cost+=V[p].b;
}
g<<cost;
f.close();
g.close();
return 0;
}