結果
| 問題 |
No.2543 Many Meetings
|
| コンテスト | |
| ユーザー |
kobaryo222
|
| 提出日時 | 2023-11-15 04:06:20 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 844 bytes |
| コンパイル時間 | 2,982 ms |
| コンパイル使用メモリ | 252,588 KB |
| 実行使用メモリ | 13,760 KB |
| 最終ジャッジ日時 | 2024-09-26 04:33:04 |
| 合計ジャッジ時間 | 6,841 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | TLE * 1 -- * 39 |
ソースコード
// TLE 解法: 区間スケジューリングを愚直に N - K + 1 回する
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
int main(){
int N, K;
cin >> N >> K;
vector<int> L(N), R(N);
vector<P> v(N);
for(int i = 0; i < N; i++){
cin >> L[i] >> R[i];
v[i] = P(R[i], L[i]);
}
sort(v.begin(), v.end());
const int inf = 1'000'000'100; // 1e9 + 100
int ans = inf;
for(int i = 0; i < N - K + 1; i++){
int cur = i, cnt = 1, next = i + 1;
while(cnt != K && next < N){
if(v[next].second >= v[cur].first){
cur = next;
cnt++;
}
next++;
}
if(cnt == K) ans = min(ans, v[cur].first - v[i].second);
}
if(ans != inf) cout << ans << endl;
else cout << -1 << endl;
}
kobaryo222