본문 바로가기
Develop/백준 (Cpp)

[백준] 15593번 : Lifeguards (Bronze) (C++)

by Tarra 2024. 1. 4.

15593번 : Lifeguards (Bronze) 


문제)

Farmer John has opened a swimming pool for his cows, figuring it will help them relax and produce more milk.

To ensure safety, he hires  cows as lifeguards, each of which has a shift that covers some contiguous interval of time during the day.

 

For simplicity, the pool is open from time  until time  on a daily basis, so each shift can be described by two integers, giving the time at which a cow starts and ends her shift. For example, a lifeguard starting at time  and ending at time  covers three units of time (note that the endpoints are "points" in time).

 

Unfortunately, Farmer John hired 1 more lifeguard than he has the funds to support. Given that he must fire exactly one lifeguard, what is the maximum amount of time that can still be covered by the shifts of the remaining lifeguards? An interval of time is covered if at least one lifeguard is present.

 

 

 

입력 :

The first line of input contains  (1≤N≤100). Each of the next lines describes a lifeguard in terms of two integers in the range 0…1000, giving the starting and ending point of a lifeguard's shift. All such endpoints are distinct. Shifts of different lifeguards might overlap.

 

 

 

출력 :

Please write a single number, giving the maximum amount of time that can still be covered if Farmer John fires 1 lifeguard.

 

 

 

 

 

 

풀이)

 

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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// 15593. Lifeguards (Bronze)
#include <iostream>
#include <vector>
 
using namespace std;
 
int main()
{
    int n;
    cin >> n;
 
    vector<pair<intint>> vec;
 
    int a, b;
    for (int i = 0; i < n; i++)
    {
        cin >> a >> b;
        vec.push_back(make_pair(a, b));
    }
 
 
    int answer = 0;
    for (int i = 0; i < n; i++)
    {
        int cnt = 0;
        vector<bool> visited(1001false);
        
        for (int j = 0; j < n; j++)
        {
            if (j == i) continue;
 
            for (int k = vec[j].first; k < vec[j].second; k++)
            {
                if (visited[k] == false)
                {
                    visited[k] = true;
                    cnt++;
                }
            }
        }
 
        answer = max(answer, cnt);
    }
 
    cout << answer;
 
    return 0;
}
 
cs

출처 : https://www.acmicpc.net/problem/15593 

 

15593번: Lifeguards (Bronze)

The first line of input contains $N$ ($1 \leq N \leq 100$). Each of the next $N$ lines describes a lifeguard in terms of two integers in the range $0 \ldots 1000$, giving the starting and ending point of a lifeguard's shift. All such endpoints are distinct

www.acmicpc.net