[HAOI2013] 花卉节

  贪心,尽量捡便宜的买,反正是糊弄更多的老百姓开心。

 

// q.c

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
typedef unsigned long long ULL;
const int M=100000+10;
struct Flower { 
	ULL cost,lover;
	bool operator < (const Flower &A) const {
		if(cost!=A.cost) return cost<A.cost;
		else return lover>A.lover;
	}
}flower[M];
int n; ULL b,ans;
int main() {
	freopen("haoi13_t2.in","r",stdin);
	freopen("haoi13_t2.out","w",stdout);
	cin>>n>>b;
	for(int i=1;i<=n;i++) cin>>flower[i].cost>>flower[i].lover;
	sort(flower+1,flower+n+1);
	for(int i=1;i<=n;i++) {
		ULL cnt=b/flower[i].cost;
		if(!cnt) break;
		if(cnt>flower[i].lover) cnt=flower[i].lover;
		b-=flower[i].cost*cnt;
		ans+=cnt;
	}
	cout<<ans;
	return 0;
}

 

posted @ 2018-04-15 18:19  qjs12  阅读(76)  评论(0编辑  收藏  举报