forked from gopalgoel19/Competitive-Programming-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcandy.cpp
32 lines (31 loc) · 784 Bytes
/
candy.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
#include <vector>
using namespace std;
int main(){
long long int n,x;
cin>>n;
vector<long long> v(n);
for(int i=0;i<n;i++) cin>>v[i];
for(int i=1;i<n;i++){
v[i]+=2*v[i-1];
}
//for(int i=0;i<n;i++) cout<<v[i]<<" ";
//cout<<endl;
cin>>x;
vector<long long int> ans;
for(int i=n-1;i>=0;i--){
if(v[i]<=x) {
x-=v[i];
ans.push_back(v[i]);
}
}
if(x==0){
for(int i=ans.size()-1;i>=0;i--){
//cout<<ans[i]<<" ";
}
cout<<"YES"<<endl;
}
else{
cout<<"NO"<<endl;
}
}