Cod sursa(job #546952)

Utilizator roots4Irimia Alexandru Gabriel roots4 Data 5 martie 2011 17:59:39
Problema Energii Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.55 kb
#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;
}