You are viewing a single comment's thread. Return to all comments →
C++ solution :
#include<iostream> #include<vector> using namespace std; int main() { int n, index=0, sum=0, x; cin >> n; vector<int> v; while(n--) { cin >> x; if (x%2) v.push_back(index); index++; } if (v.size()%2){ cout << "NO"; return 0;} for (int i=1;i<v.size();i+=2) sum+=v[i]-v[i-1]; cout << sum*2; }
Seems like cookies are disabled on this browser, please enable them to open this website
Fair Rations
You are viewing a single comment's thread. Return to all comments →
C++ solution :