Advertisement
Nayeemzaman

trek

Dec 28th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.29 KB | None | 0 0
  1. #include<stdio.h>
  2. int main()
  3. {
  4.     long long int x,i,ct=0,sum=0,count=0;
  5.     scanf("%lld",&x);
  6.     int n[x],cpy[x];
  7.     for(i=0; i<x; i++)
  8.     {
  9.         scanf("%lld",&n[i]);
  10.         cpy[i]=n[i];
  11.         sum = sum+n[i];
  12.     }
  13.     i=0;
  14.     if(n[0]%2!=0)
  15.     {
  16.         while(i<x)
  17.         {
  18.             if(n[i]%2!=0)
  19.             {
  20.                 if(n[i]==0)
  21.                    {break;}
  22.                 ct++;
  23.                 n[i]=n[i]-1;
  24.                 i++;
  25.             }
  26.             else if(n[i]%2==0)
  27.             {
  28.                 if(n[i]==0)
  29.                     {break;}
  30.                 ct++;
  31.                 n[i]=n[i]-1;
  32.                 i--;
  33.  
  34.             }
  35.         }
  36.     }
  37.     else if(n[0]%2==0)
  38.     {
  39.         while(i<x)
  40.         {
  41.             if(n[i]%2==0)
  42.             {
  43.                 if(n[i]==0)
  44.                     {break;}
  45.                 ct++;
  46.                 n[i]=n[i]-1;
  47.                 i++;
  48.  
  49.             }
  50.             else if(n[i]%2!=0)
  51.             {
  52.                 if(n[i]==0)
  53.                     {break;}
  54.                 ct++;
  55.                 n[i]=n[i]-1;
  56.                 i--;
  57.  
  58.             }
  59.         }
  60.     }
  61.     for(i=0; i<x; i++)
  62.     {
  63.         if(n[i]!=cpy[i])
  64.             count++;
  65.     }
  66.     printf("%lld %lld\n",count,sum-ct);
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement