Cod sursa(job #640307)

Utilizator thesvcoolmanLucian Bicsi thesvcoolman Data 25 noiembrie 2011 10:49:56
Problema Energii Scor 5
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.6 kb
using namespace std;
#include<fstream>
ifstream fin("energii.in");
ofstream fout("energii.out");

int main()
{
	int l,g,w,v1[1001],v2[1001],k,aux;
	int s=0,e=0;
	
	fin>>g>>w;
	for(k=0;k<g;k++)
		fin>>v1[k]>>v2[k];
	
	int ordonat=0;
	while(!ordonat)
	{
		ordonat=1;
		for(k=0;k<g-1;k++)
			if(v1[k]<v1[k+1])
			{
				aux=v1[k];
				v1[k]=v1[k+1];
				v1[k+1]=aux;
				aux=v2[k];
				v2[k]=v2[k+1];
				v2[k+1]=aux;
				ordonat=0;
			}
	}
	
	k=0;
	while(s<w&&k<g)
	{
		s=s+v1[k];
		e=e+v2[k];
		k++;
	}
	
	if(s<w)
	{
		fout<<"-1";
		return 0;
	}
	fout<<e;
	return 0;
}