TOJ 3982.Vacation

来源:互联网 发布:海隆软件 编辑:程序博客网 时间:2024/05/01 21:20

题目链接: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

35 32 2 25 35 6 16 51 1 1 1 1

Sample Output

215



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
原创粉丝点击