結果

問題 No.2543 Many Meetings
ユーザー HIKKY1317HIKKY1317
提出日時 2023-11-24 22:53:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 954 bytes
コンパイル時間 2,210 ms
コンパイル使用メモリ 175,204 KB
実行使用メモリ 16,872 KB
最終ジャッジ日時 2023-11-24 22:54:00
合計ジャッジ時間 9,085 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,480 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 182 ms
10,200 KB
testcase_04 AC 185 ms
10,200 KB
testcase_05 AC 208 ms
10,200 KB
testcase_06 AC 182 ms
10,200 KB
testcase_07 AC 183 ms
10,200 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main(){
  int N;
  long long K;
  cin >> N >> K;
  long long L[N+1],R[N+1];
  vector<pair<long long, long long>> tmp;
  for(int i=1;i<=N;i++){
    cin >> L[i] >> R[i];
    tmp.push_back(make_pair(R[i],L[i]));
  }
  sort(tmp.begin(),tmp.end());
  for(int i=1;i<=N;i++){
    R[i]=tmp[i-1].first;
    L[i]=tmp[i-1].second;
  }
  long long ans=1e18;
  long long CurrentTime=0,Answer=0;
  for(int i=1;i<=N;i++){
    if(CurrentTime<=L[i]){
      CurrentTime=R[i];
      Answer++;
    }
    if(Answer==K){
      ans=CurrentTime-L[1];
      break;
    }
  }
  if(Answer<K){
    cout << -1 << endl;
    return 0;
  }
  for(int i=1;i<=N;i++){
    CurrentTime=0,Answer=0;
    for(int j=i;CurrentTime-L[i]<=ans;j++){
      if(CurrentTime<=L[j]){
        CurrentTime=R[j];
        Answer++;
      }
      if(Answer==K){
        ans=min(ans,CurrentTime-L[i]);
        break;
      }
    }
  }
  cout << ans << endl;
}
0