intmain(){ int n; cin >> n; int* arr = newint[n]; int remain = 0;//当日剩余生煎数 bool failed = false;//不能满足? for (int i = 0; i < n; i++) cin >> arr[i]; for (int i = 0; i < n; i++) { int a = arr[i] - remain;//扣去前一天剩下的券(如果有) 今天还有的生煎数 if (a < 0) {//昨天有剩券 但今天不想吃 failed = true;//不能满足 break; }
if (a % 2 == 0)//今天不需要买 券那个方案,选方案一 remain = 0; if (a % 2 == 1)//需要买张券,选方案二 remain = 1; } if (remain == 0 && failed == false)//最后一天 没剩 且 之前都满足 cout << "YES" << endl; if (remain == 1 || failed == true)//最后一天有剩 或 之前某天不满足 cout << "NO" << endl;