Codeforces 731B Coupons and Discounts(贪心)

时间:2023-03-09 14:44:50
Codeforces 731B Coupons and Discounts(贪心)

题目链接 Coupons and Discounts

逐步贪心即可。

若当前位为奇数则当前位的下一位减一,否则不动。

 #include <bits/stdc++.h>

 using namespace std;

 #define rep(i,a,b)              for(int i(a); i <= (b); ++i)

 int a[];
int n; int main(){ memset(a, , sizeof a);
scanf("%d", &n);
rep(i, , n) scanf("%d", a + i);
bool flag = true;
rep(i, , n + ){
if (a[i] < ){
flag = false;
break;
} if (i == n + ) break;
if (a[i] & ){
--a[i + ];
}
} puts(flag ? "YES" : "NO");
return ; }