結果
| 問題 |
No.1767 BLUE to RED
|
| コンテスト | |
| ユーザー |
merlin
|
| 提出日時 | 2021-11-26 23:01:53 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 491 ms / 2,000 ms |
| コード長 | 1,286 bytes |
| コンパイル時間 | 2,133 ms |
| コンパイル使用メモリ | 78,276 KB |
| 実行使用メモリ | 69,636 KB |
| 最終ジャッジ日時 | 2024-06-29 18:26:24 |
| 合計ジャッジ時間 | 10,797 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
ソースコード
import java.io.*;
import java.util.*;
class Main
{
public static void main(String args[])throws Exception
{
BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb=new StringBuilder();
String s[]=bu.readLine().split(" ");
int n=Integer.parseInt(s[0]),m=Integer.parseInt(s[1]);
int i,a[]=new int[n],b[]=new int[m];
s=bu.readLine().split(" ");
for(i=0;i<n;i++) a[i]=Integer.parseInt(s[i]);
s=bu.readLine().split(" ");
for(i=0;i<m;i++) b[i]=Integer.parseInt(s[i]);
int ans,l=0;
while(l<m && b[l]<a[0]) l++;
ans=Math.max(a[0]-b[0],0);
ans+=Math.max(b[m-1]-a[n-1],0);
for(i=1;i<n;i++)
{
ArrayList<Integer> te=new ArrayList<>();
while(l<m && b[l]<=a[i]) te.add(b[l++]);
ans+=minimum(te,a[i-1],a[i]);
}
System.out.println(ans);
}
static int minimum(ArrayList<Integer> te,int l,int r)
{
//System.out.println(te+" "+l+" "+r);
if(te.size()==0) return 0;
int n=te.size(),ans,i;
ans=r-te.get(0);
for(i=0;i+1<n;i++) ans=Math.min(ans,te.get(i)-l+r-te.get(i+1));
ans=Math.min(ans,te.get(n-1)-l);
return ans;
}
}
merlin