結果

問題 No.2543 Many Meetings
ユーザー HIKKY1317
提出日時 2023-11-24 22:50:36
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 941 bytes
コンパイル時間 2,115 ms
コンパイル使用メモリ 174,144 KB
実行使用メモリ 9,692 KB
最終ジャッジ日時 2024-09-26 09:43:22
合計ジャッジ時間 8,867 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 2
other AC * 14 WA * 21 RE * 5
権限があれば一括ダウンロードができます

ソースコード

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