結果
問題 | No.2667 Constrained Permutation |
ユーザー |
![]() |
提出日時 | 2024-03-08 21:54:56 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 781 bytes |
コンパイル時間 | 2,434 ms |
コンパイル使用メモリ | 77,492 KB |
実行使用メモリ | 48,100 KB |
最終ジャッジ日時 | 2024-09-29 19:34:09 |
合計ジャッジ時間 | 21,049 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 42 WA * 4 |
ソースコード
import java.io.BufferedReader;import java.io.InputStreamReader;import java.util.Arrays;public class Main {public static void main(String[] args) throws Exception {BufferedReader br = new BufferedReader(new InputStreamReader(System.in));int n = Integer.parseInt(br.readLine());int[] l = new int[n];int[] r = new int[n];for (int i = 0; i < n; i++) {String[] sa = br.readLine().split(" ");l[i] = Integer.parseInt(sa[0]);r[i] = Integer.parseInt(sa[1]);}br.close();Arrays.sort(l);Arrays.sort(r);int maxL = 0;int minR = 1000000007;for (int i = 0; i < n; i++) {int i1 = i + 1;maxL = Math.max(maxL, l[i] - i1);minR = Math.min(minR, r[i] - i1);}int ans = Math.max(minR - maxL + 1, 0);System.out.println(ans);}}