結果

問題 No.2543 Many Meetings
ユーザー HIKKY1317HIKKY1317
提出日時 2023-11-24 22:50:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 941 bytes
コンパイル時間 1,787 ms
コンパイル使用メモリ 175,200 KB
実行使用メモリ 10,200 KB
最終ジャッジ日時 2023-11-24 22:50:45
合計ジャッジ時間 7,824 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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];
    }
  }
  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[i];
        Answer++;
      }
      if(Answer==K){
        ans=min(ans,CurrentTime-L[i]);
        break;
      }
    }
  }
  cout << ans << endl;
}
0