https://atcoder.jp/contests/abc209/tasks/abc209_b
题目描述
Takahashi's shop sells N products. The usual price of the ii-th product is yen (Japanese currency).
It has a bargain sale today, with a discount of 1 yen off the usual prices for the 2-nd, 4-th, and the subsequent even-indexed products. The 1-st, 3-rd, and the subsequent odd-indexed products are sold for their usual prices.
You have X yen. Can you buy all the NN products with this money?
数据范围
- 1≤N≤100
- 1≤X≤10000
- 1≤≤100
- All values in input are integers.
输入
Input is given from Standard Input in the following format:
N X ……
输出
If you can buy all the N products, print Yes
; otherwise, print No
.
思路分析
水题,判断奇偶数,再拿相加值比大小
#include <iostream>
using namespace std;
int main () {
int n,x,s=0;
cin>>n>>x;
int a[n+1];
for (int i=1;i<=n;i++){
cin>>a[i];
}
for (int i=1;i<=n;i++){
if (i%2==0){
a[i]--;
}
s+=a[i];
}
if (s<=x){
cout<<"Yes";
}
else
cout<<"No";
return 0;
}