そのため、特定の金額で購入できる最大のユニークなアイテムを見つけるように求める問題を解決する必要があります。そのため、アイテムの数と所有しているお金を入力します。他の人を失敗させながら、ほんの一握りのケースのソリューションを提供するだけです。ただし、テストケースにアクセスすることはできません。
これが失敗する条件は何ですか?何かアイデアはありますか?
例:
Input: 7 50
1 12 5 111 200 100 10
Output: 4
int main()
{
int n,x,money,count=0,j=0;
cout<<"Enter no of items and money you have";
cin>>n>>money; //size of array(number of items)
vector<int> a(n);
for(int i=0;i<n;i++)
{
cin>>x; //assigning price of each item
a[i]=x;
}
sort(a.begin(),a.end()); // sorting prices in ascending order
while(money-a[j]>0) //buying stuff until you are broke
{
j++;
count++;
}
cout<<count; //returning no of items that can be purchased.
}