Advertisement
HashZayed

Fair Rations

Sep 19th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.90 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Numerics;
  6. class Solution {
  7.  
  8.     static void Main(String[] args) {
  9.         int N = Convert.ToInt32(Console.ReadLine());
  10.         string[] B_temp = Console.ReadLine().Split(' ');
  11.         int[] B = Array.ConvertAll(B_temp,Int32.Parse);
  12.         int oddCount=0,start=-1,end=0,result = 0;
  13.         //List<Vector2> pairs = new List<Vector2>();
  14.         for(int i=0;i<N;i++){
  15.             if(B[i]%2!=0) {
  16.                 oddCount++;
  17.                 if(start==-1) start = i;
  18.                 else{
  19.                     end = i;
  20.                     result += (end-start)*2;
  21.                     start=-1;
  22.                     end=-1;
  23.                 }
  24.             }
  25.         }
  26.         if(oddCount%2==0){
  27.             Console.WriteLine(result);
  28.         }else{
  29.             Console.WriteLine("NO");
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement