Click Here to go back to the homepage.

A Prize No One Can Win Solution:


#include <bits/stdc++.h>

using namespace std;

int main(){
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	int prizes, price;
	cin >> prizes >> price;
	if(prizes < 2){
		cout << 1;
		return 0;
	} 
	vector<int> prices;
	for(int i = 0; i < prizes; i++){
		int temp;
		cin >> temp;
		prices.push_back(temp);
	}
	sort(prices.begin(), prices.end());
	int i = 1;
	int total = 1;
	while(i < prices.size()){
		if(prices[i] + prices[i - 1] <= price){
			total++;
		} else {
			break;
		}
		i++;
	}
	cout << total;
	
	return 0;
}