248A - Cupboards - CodeForces Solution


implementation *800

Please click on ads to support us..

Python Code:

n=int(input())
u=[]
v=[]
for i in range(n):
    l,m=map(int,input().split())
    u.append(l)
    v.append(m)
cnt=0
cnt1=0
cnt2=0
cnt3=0
sum=0
for i in u:
    if i==0:
        cnt+=1
    else:
        cnt1+=1
sum=min(cnt,cnt1)
for i in v:
    if i==0:
        cnt2+=1
    else:
        cnt3+=1
c=sum+min(cnt2,cnt3)
print(c)

C++ Code:

#include <iostream>
using namespace std;

int main() {
   int n, cntl1 = 0, cntl2 = 0, cntr1 = 0, cntr2 = 0;
   cin >> n;
   int l[n], r[n];
   for (int i = 0; i < n; i++){
        cin >> l[i] >> r[i];
        if (l[i] == 0){
                cntl1++;
        }
        else if (l[i] == 1){
                cntl2++;
        }
        if (r[i] == 0){
                cntr1++;
        }
        else if (r[i] == 1){
                cntr2++;
        }
   }
   cout << min(cntl1, cntl2) + min(cntr1, cntr2);
   
	return 0;
}


Comments

Submit
0 Comments
More Questions

1538A - Stone Game
1454C - Sequence Transformation
165B - Burning Midnight Oil
17A - Noldbach problem
1350A - Orac and Factors
1373A - Donut Shops
26A - Almost Prime
1656E - Equal Tree Sums
1656B - Subtract Operation
1656A - Good Pairs
1367A - Short Substrings
87A - Trains
664A - Complicated GCD
1635D - Infinite Set
1462A - Favorite Sequence
1445B - Elimination
1656C - Make Equal With Mod
567A - Lineland Mail
1553A - Digits Sum
1359B - New Theatre Square
766A - Mahmoud and Longest Uncommon Subsequence
701B - Cells Not Under Attack
702A - Maximum Increase
1656D - K-good
1426A - Floor Number
876A - Trip For Meal
1326B - Maximums
1635C - Differential Sorting
961A - Tetris
1635B - Avoid Local Maximums