[Codeforces] [629B] Far Relative’s Problem

Problem Description

Loading...

Problem Analysis

I’ve always felt this kind of problem doesn’t really count as Greedy
yet I keep seeing plenty of people filing it under Greedy
there should be an interval-greedy way to write it too
but I never came up with one, nor found one
the complexity here depends on the interval size
the greedy strategy depends on the size of n
so presumably there’s some room to choose

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
struct node {
    char sex;
    int l,r;
} a[5200];
int man[5200],woman[5200];
int main() {
    int n;
    while(scanf("%d",&n)!=EOF) {
        getchar();
        memset(man,0,sizeof(man));
        memset(woman,0,sizeof(woman));
        for(int i=0; i<n; i++) {
            scanf("%c %d %d",&a[i].sex,&a[i].l,&a[i].r);
            getchar();
            if(a[i].sex=='M') {
                for(int j=a[i].l; j<=a[i].r; j++)
                    man[j]++;
            } else {
                for(int j=a[i].l; j<=a[i].r; j++)
                    woman[j]++;
            }
        }
        int res=0;
        for(int i=1; i<367; i++) {
            res=max(res,min(man[i],woman[i]));
        }
        printf("%d\n",res*2);
    }
    return 0;
}

Loading...