Submission #5447833


Source Code Expand

Copy
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
int main()
{
	int N, x;
	cin >> N >> x;
	vector<int> a(N);

	for(int i=0; i<N; i++){
		cin >> a.at(i);
	}
	sort(a.begin(), a.end());

	int cnt=0;
	for(int i=0; i<N; i++){
		if(x>=a.at(i)){
			cnt++;
			x-=a.at(i);
		}else{
			break;
		}
	}
	if(x>0){
		if(cnt){
			cnt--;
		}
	}
	cout << cnt << endl;
	return 0;
}

Submission Info

Submission Time
Task A - Candy Distribution Again
User proton
Language C++14 (GCC 5.4.1)
Score 0
Code Size 473 Byte
Status
Exec Time 1 ms
Memory 256 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt
All 0 / 200 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt
Case Name Status Exec Time Memory
0_00.txt 1 ms 256 KB
0_01.txt 1 ms 256 KB
0_02.txt 1 ms 256 KB
0_03.txt 1 ms 256 KB
1_00.txt 1 ms 256 KB
1_01.txt 1 ms 256 KB
1_02.txt 1 ms 256 KB
1_03.txt 1 ms 256 KB
1_04.txt 1 ms 256 KB
1_05.txt 1 ms 256 KB
1_06.txt 1 ms 256 KB
1_07.txt 1 ms 256 KB