본문 바로가기

코드포스

[코드포스 Practice5] C. Mind the Gap

These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts 11 minute.

He was asked to insert one takeoff in the schedule. The takeoff takes 11 minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least ss minutes from both sides.

Find the earliest time when Arkady can insert the takeoff.

 

Input

The first line of input contains two integers nn and ss (1n1001≤n≤100, 1s601≤s≤60) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff.

Each of next nn lines contains two integers hh and mm (0h230≤h≤23, 0m590≤m≤59) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is 00 00). These times are given in increasing order.

Output

Print two integers hh and mm — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff.


으아악

s분이라는 걸 8분으로 봐서 계속 잘못 생각했다ㅋㅋㅋ 예시 대입해서 푸는데 자꾸 될 것 같은데 예시 답은 다른 시간대여서 뭐지 싶었음. 푸는 건 쉬웠다. 첫 시간 이전에 되는지 확인하고 사이 시간대 되는지 확인.. 다 안 되면 마지막 시간에 넣기.. 

 

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <functional>
 
using namespace std;
using i64 = long long;
 
//printf("%d", );
//scanf("%d", &);
//printf("\n");
 
int main() {
    int n, s;
    scanf("%d %d", &n, &s);
    
    int sum;
    for(int i = 0; i < n; i++){
        int h, m;
        scanf("%d %d", &h, &m);
        
        if(i == 0){
            if(s+1 <= 60*h + m){
                printf("0 0");
                return 0;
            }
            sum = 60*h + m;
        }
        int after = 60*h + m;
        if(after - sum >= s*2 + 2){
            printf("%d %d", (sum+s+1)/60, (sum+s+1)%60);
            return 0;
        }
        
        sum = after;
    }
    printf("%d %d", (sum+s+1)/60, (sum+s+1)%60);
    
    return 0;
}

 

여담이지만 take off가 비행기가 이륙한다는 뜻이었다. 착륙은 알지만 이륙은 몰랐서

 


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int n, s;
    scanf("%d %d", &n, &s);
    
    vector<int> arr;
    arr.push_back(-s -1);
    
    for(int i = 0; i < n; i++){
        int h, m;
        scanf("%d %d", &h, &m);
        arr.push_back(h * 60 + m);
    }
    
    arr.push_back(987654321);
    
    for(int i = 1; i < arr.size(); i++){
        int p = arr[i-1];
        int nxt = arr[i];
        
        if(p+1+s < nxt-s){
            int t = max(p+1+s, 0);
            printf("%d %d\n", t/60, t%60);
            return 0;
        }
    }
    
    return 0;
}

 

오.. 보면 맨 처음이랑 맨 끝을 따로 체크해야 하는데 이걸 따로 예외로 안 두고 임의의 값을 넣어서 쭉 비교를 할 수 있다. 

깔끔해! 다음에 써먹어야지