結果
| 問題 |
No.2667 Constrained Permutation
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-03-08 21:29:03 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 620 bytes |
| コンパイル時間 | 895 ms |
| コンパイル使用メモリ | 78,820 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-09-29 18:58:26 |
| 合計ジャッジ時間 | 4,498 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 42 WA * 4 |
ソースコード
#include<iostream>
#include<vector>
#include<algorithm>
#include<cassert>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;cin>>N;
vector<pair<int,int> >LR(N);
for(int i=0;i<N;i++)cin>>LR[i].first>>LR[i].second;
sort(LR.begin(),LR.end());
int lk=-2e9;
for(int i=0;i<N;i++)
{
int l=LR[i].first;
//l<=k+i+1 <=> l-i-1<=k
lk=max(lk,l-i-1);
}
sort(LR.begin(),LR.end(),[](pair<int,int>l,pair<int,int>r){return l.second<r.second;});
int rk=2e9;
for(int i=0;i<N;i++)
{
int r=LR[i].second;
//k+i+1<=r <=> k<=r-i-1
rk=min(rk,r-i-1);
}
cout<<max(0,rk-lk+1)<<endl;
}