This is Problem
- Supermarket
Problem Statement: You're in a supermarket and want to buy N items but you have only S dollars.
Input Format: first two numbers N (the number of items) and S (The amount of dollars you have) followed by N integers indicate the price of each item N is a positive integers less than or equal to 1,000,000 0 < S < 1,000,000,001 All prices are less than 1,000,001
Output Format: Print "Yes" if the total price of items less than or equal to S and print "No" otherwise.
Sample Input: 6 100 8 31 4 12 19 2
Sample Output: Yes
Notes: 8 + 31 + 4 + 12 + 19 + 2 = 76
76 < 100
Then "Yes" you can buy them
This is My Code:
#include <iostream>
using namespace std;
int main()
{
int N,S;
cin >> N >> S;
int sum=0;
int numslist[N];
for (int i=0; i<N; i++)
{
cin>>numslist[i];
sum=sum+numslist[i];
}
if(sum<=S)
cout << "No" << endl;
else if(sum>S)
cout << "Yes" << endl;
return 0;
}
I submit This Code and The Online Judge and it say Wrong answer Website
Please any one Help me and say What's the wrong?