629B - Far Relative’s Problem - CodeForces Solution


brute force *1100

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
using namespace std;
 
const int DAYS = 371;
int party[2][DAYS];
// 0 -> female
// 1 -> male
 
 
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	cin >> n;
	
	vector<pair<int,int>> male;
	vector<pair<int,int>> female;
	
	for(int i = 0; i < n; i++){
		char s;
		int a, b;
		cin >> s >> a >> b;
		if(s == 'F') female.push_back({a, b});
		else male.push_back({a, b});
	}
	
	int m = male.size();
	int f = female.size();
	
	if(m == 0 or f == 0){
		cout << 0 << '\n';
		return 0;
	}
	
	for(int i = 1; i <= 366; i++){
		for(int j = 0; j < m; j++){
			if(male[j].first <= i and i <= male[j].second){
				party[1][i]++;
			}
		}
		
		for(int k = 0; k < f; k++){
			if(female[k].first <= i and i <= female[k].second){
				party[0][i]++;
			}
		}
	}
	
	int ans = 0;
	
	for(int i = 1; i <= 366; i++){
		ans = max(ans, min(party[0][i], party[1][i])); 
	}
	
	cout << ans*2 << '\n';
	return 0;
}


Comments

Submit
0 Comments
More Questions

908A - New Year and Counting Cards
146A - Lucky Ticket
1594C - Make Them Equal
1676A - Lucky
1700B - Palindromic Numbers
702C - Cellular Network
1672C - Unequal Array
1706C - Qpwoeirut And The City
1697A - Parkway Walk
1505B - DMCA
478B - Random Teams
1705C - Mark and His Unfinished Essay
1401C - Mere Array
1613B - Absent Remainder
1536B - Prinzessin der Verurteilung
1699B - Almost Ternary Matrix
1545A - AquaMoon and Strange Sort
538B - Quasi Binary
424A - Squats
1703A - YES or YES
494A - Treasure
48B - Land Lot
835A - Key races
1622C - Set or Decrease
1682A - Palindromic Indices
903C - Boxes Packing
887A - Div 64
755B - PolandBall and Game
808B - Average Sleep Time
1515E - Phoenix and Computers