Another fun Greedy problem to work on: we simply go from first to second last person, as long someone is odd, we distribute bread to her and her next.
#include <vector>
#include <iostream> using namespace std; int main()
{
int N;
cin >> N;
vector<int> B(N);
for(int B_i = ;B_i < N;B_i++){
cin >> B[B_i];
} int cnt = ;
for(int i = ; i < N - ; i ++)
{
if(B[i] % )
{
B[i] ++;
B[i+]++;
cnt += ;
}
} if(B.back() % )
cout << "NO" << endl;
else
cout << cnt << endl; return ;
}