Submission #1867871
Source Code Expand
import java.io.*; import java.util.*; class P implements Comparable<P>{ long a,b; P(long x,long y){a=x;b=y;} @Override public int compareTo(P o){ return Long.compare(a,o.a); } } class Main { static final long I=1L<<48; public static void main(String[] args) { MyScanner sc = new MyScanner(); out = new PrintWriter(new BufferedOutputStream(System.out)); int n=sc.nextInt(); P[]lr=new P[n]; for(int i=0;i<n;++i){ long l=sc.nextInt(); long r=sc.nextInt(); lr[i]=new P(l+r,l); } Arrays.sort(lr); int nn=n/2*2; long sl=n%2==1?lr[0].b:0; long sr=n%2==1?lr[0].a-lr[0].b:0; long[][]dp=new long[nn+1][nn/2+1]; Arrays.fill(dp[0],I); dp[0][0]=0; for(int i=0;i<nn;++i){ int u=i; int nxt=i+1; long l=lr[i+n%2].b; long r=lr[i+n%2].a-l; Arrays.fill(dp[nxt],I); for(int j=0;j<=Math.min(i+1,nn/2);++j){ int lft=j,rgt=i+1-j; if(lft>nn/2||rgt>nn/2)continue; if(rgt>0) dp[nxt][j]=Math.min(dp[nxt][j],dp[u][j]+(nn/2-rgt+1)*l+(nn/2-rgt)*r); if(lft>0) dp[nxt][j]=Math.min(dp[nxt][j],dp[u][j-1]+(nn/2-lft)*l+(nn/2-lft+1)*r); } } if(n%2==1)throw new Error(); //System.err.println(Arrays.deepToString(dp)); out.println(dp[nn][nn/2]+(sl+sr)*(nn/2)); out.close(); } // http://codeforces.com/blog/entry/7018 //-----------PrintWriter for faster output--------------------------------- public static PrintWriter out; //-----------MyScanner class for faster input---------- public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine(){ String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Submission Info
Submission Time | |
---|---|
Task | F - Intervals |
User | kirika_comp |
Language | Java8 (OpenJDK 1.8.0) |
Score | 0 |
Code Size | 2878 Byte |
Status | RE |
Exec Time | 324 ms |
Memory | 168752 KB |
Judge Result
Set Name | Sample | All | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 1000 | ||||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | example0.txt, example1.txt |
All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, 040.txt, 041.txt, 042.txt, example0.txt, example1.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
000.txt | WA | 305 ms | 163624 KB |
001.txt | WA | 179 ms | 49876 KB |
002.txt | WA | 306 ms | 164128 KB |
003.txt | RE | 309 ms | 128388 KB |
004.txt | WA | 307 ms | 162396 KB |
005.txt | RE | 217 ms | 77040 KB |
006.txt | WA | 307 ms | 164716 KB |
007.txt | WA | 233 ms | 81236 KB |
008.txt | WA | 317 ms | 168752 KB |
009.txt | WA | 172 ms | 28780 KB |
010.txt | WA | 306 ms | 163344 KB |
011.txt | WA | 224 ms | 80492 KB |
012.txt | WA | 310 ms | 164148 KB |
013.txt | WA | 166 ms | 30700 KB |
014.txt | WA | 315 ms | 166736 KB |
015.txt | RE | 180 ms | 54996 KB |
016.txt | WA | 315 ms | 162988 KB |
017.txt | WA | 271 ms | 129488 KB |
018.txt | WA | 316 ms | 163668 KB |
019.txt | RE | 228 ms | 82772 KB |
020.txt | RE | 68 ms | 19412 KB |
021.txt | RE | 81 ms | 17236 KB |
022.txt | WA | 307 ms | 161948 KB |
023.txt | WA | 291 ms | 162000 KB |
024.txt | WA | 314 ms | 161076 KB |
025.txt | WA | 294 ms | 165636 KB |
026.txt | WA | 324 ms | 164912 KB |
027.txt | WA | 299 ms | 164524 KB |
028.txt | WA | 300 ms | 166696 KB |
029.txt | WA | 295 ms | 164948 KB |
030.txt | WA | 314 ms | 165324 KB |
031.txt | WA | 297 ms | 166340 KB |
032.txt | WA | 306 ms | 164620 KB |
033.txt | WA | 301 ms | 163428 KB |
034.txt | WA | 309 ms | 164648 KB |
035.txt | WA | 294 ms | 164456 KB |
036.txt | WA | 306 ms | 166224 KB |
037.txt | WA | 299 ms | 164792 KB |
038.txt | WA | 310 ms | 165200 KB |
039.txt | WA | 304 ms | 163876 KB |
040.txt | WA | 315 ms | 161676 KB |
041.txt | WA | 305 ms | 166468 KB |
042.txt | WA | 311 ms | 164736 KB |
example0.txt | AC | 71 ms | 19412 KB |
example1.txt | AC | 71 ms | 19284 KB |