TOJ 3982.Vacation

题目链接:http://acm.tju.edu.cn/toj/showp3982.html



3982.    Vacation
Time Limit: 1.0 Seconds    Memory Limit: 65536K
Total Runs: 416    Accepted Runs: 248



Z is planning to visit the Tourist Kingdom for M days. This kingdom is full of lovely cities. During his stay Z would like to visit as many different cities as possible. He cannot visit more than one city on the same day.

Additionally,different cities may require him to stay for a different number of days.For each i,city i counts as visited if Z spends at least d[i] days in the city.

Help Z find the maximal number of cities he can visit during his vacation.

Input

First a integer T,the number of test cases.For each test case,the first line is M and N,the total days Z has and the number of cities.(M,N≤50)

Then N integers,meaning the int[] d.

Output

The maximal number of cities Z can visit.

Sample Input

3
5 3
2 2 2
5 3
5 6 1
6 5
1 1 1 1 1

Sample Output

2
1
5



Source: TJU Team Selection 2013



 

水题,水的不能再水的题,排序然后贪心。说多了直接上代码好了。。。


#include <stdio.h>
#include <algorithm>
using namespace std;
int main(){
	int n,m,t,city[51],sum;
	scanf("%d",&t);
	while(t--){
		scanf("%d%d",&n,&m);
		sum=0;
		for(int i=0;i<m;i++)
			scanf("%d",&city[i]);
		sort(city,city+m);
		for(int i=0;i<m;i++)
			if(n>=city[i]){
				sum++;
				n-=city[i];
			}
			else 
				break;
		printf("%d\n",sum);
	}
} 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值