Start: Dec, 04, 2016 12:00:00
杭州师范大学第十届程序设计竞赛—正式
End: Dec, 04, 2016 17:00:00
Time elapsed:
Time remaining:

Problem_ID: B
Result: Accepted
Time: 2ms
Memory: 1708kB
In contest: 1075

#include<iostream>
#include<vector>
#include<string>
#include<stdlib.h>
 using namespace std;

 vector<int> shuru()
 {
	 int n,m;
	 cin>>n>>m;
	 int a[2] = {n ,m};
	 vector<int>  arraynt;
	 arraynt.resize(2);
	 arraynt[0] = n;
	 arraynt[1] = m;
	 return arraynt;
 }
 vector<int> sum(int m )
 {
	 vector<int>  arrayInt;
	 arrayInt.resize(m);
	 for(int i = 0;i<m;i++)
	 {
		 int aa = 0;
		 cin>>aa;
		 arrayInt[i] = aa;
		 
	 }
	 return arrayInt;
 }

 vector<int> sort( vector<int> fds,int m)
 {
	 for(int k = m - 1;k>0;k--)
	 {
		 for(int i = 0;i<k;i++)
		 {
			 int ma1 = fds[i];
			 int ma2 = fds[i+1];
			 if(ma1>ma2)
			 {
				fds[i] = ma2;
				fds[i+1] = ma1;
			 }
		 }
	 }
	 
	 return fds;
 }

 

 int main()
 {
	 vector<int>  arraynt;
	 arraynt.resize(2);
	 int T = 0;
	 cin>>T;
	 vector<int>  arrayIntTT;
	 arrayIntTT.resize(T);

	 for(int i = 0;i<T;i++)
	 {
		 int n,m;
		 arraynt = shuru();
		 n = arraynt[0];
		 m = arraynt[1];
		 if(n<0 || n>10000 || m<0 || m>100 )
		 {
			 return 0;
		 }
		 vector<int>  arraynt1;
		arraynt1.resize(m);
		vector<int>  arraynt31;
		arraynt31.resize(m);
		
		arraynt1 =  sum(m);
		arraynt31 = sort(arraynt1,m);
		int temp = 0;
		int count = 0;
		 for(int k = 0;k<m;k++)
		 {
			 temp = temp + arraynt31[k];
			 if(temp<=n)
			 {
				 arrayIntTT[i]++;
			 }
		 }

	 }
	 for(int j = 0;j<T;j++)
	 {
		 cout<< arrayIntTT[j]<<endl;
	 }  
	 return 0;
 }