SHARE
TWEET

codeforce - Parity Alternated Deletions

jakaria_hossain Mar 31st, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.     int n,i;
  6.     cin>>n;
  7.     int ara[n+1],even[n],odd[n],sum=0,e=0,o=0;
  8.     memset(even,0,sizeof(even));
  9.     memset(odd,0,sizeof(odd));
  10.     for(i=0;i<n;i++)
  11.     {
  12.         cin>>ara[i];
  13.         if(ara[i]%2)odd[o++]=ara[i];
  14.         else even[e++]=ara[i];
  15.     }
  16.     sort(even,even+e);
  17.     sort(odd,odd+o);
  18.     if(e==o)
  19.     {
  20.         printf("0\n");
  21.         return 0;
  22.     }
  23.     if(e<o)
  24.     {
  25.         for(i=0;i<o-e-1;i++)sum+=odd[i];
  26.         printf("%d\n",sum);
  27.         return 0;
  28.     }
  29.     else
  30.     {
  31.         for(i=0;i<e-o-1;i++)sum+=even[i];
  32.         printf("%d\n",sum);
  33.         return 0;
  34.     }
  35. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top