Cod sursa(job #442953)

Utilizator stefan.teleustefan teleu stefan.teleu Data 15 aprilie 2010 19:11:27
Problema Gutui Scor 0
Compilator cpp Status done
Runda teme_upb Marime 0.71 kb
#include<fstream>
#include<cstdlib>
#include<vector>
#include<algorithm>

using namespace std;

struct Gutui{
	unsigned long h;
	unsigned long w;
	bool operator() (Gutui a, Gutui b) {  if (a.h == b.h) return (a.w<b.w);return (a.h<b.h); }
}gutui;



int main(){
	unsigned long n,h,u,u1=0,hmax=0,umax=0;
	
	ifstream fin ("gutui.in");
	ofstream fout ("gutui.out");
	fin>>n>>h>>u;
	vector<Gutui> g(n);	
	for (int i=0; i<n; i++)
		fin>>g[i].h>>g[i].w;
	sort(g.begin(),g.end(),gutui);
	
	for (int i=n-1; i>=0; i--)
		{
		while (g[i].h+u1 < h)
			{	
					
			hmax=g[i].h;
			u1+=10;
			umax+=g[i].w;
			}
		}

		fout<<umax<<endl;
	for (int i=0; i<n; i++)
		fout<<g[i].h<<" "<<g[i].w<<endl;
	fin.close();
	fout.close();
	return 0;
}