Submission #1867759
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(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); } } //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 | 2791 Byte |
Status | WA |
Exec Time | 359 ms |
Memory | 168048 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 | 328 ms | 166736 KB |
001.txt | WA | 176 ms | 50260 KB |
002.txt | WA | 329 ms | 165656 KB |
003.txt | WA | 290 ms | 127956 KB |
004.txt | WA | 328 ms | 165560 KB |
005.txt | WA | 209 ms | 77776 KB |
006.txt | WA | 328 ms | 162944 KB |
007.txt | WA | 231 ms | 84248 KB |
008.txt | WA | 329 ms | 165524 KB |
009.txt | WA | 163 ms | 28396 KB |
010.txt | WA | 334 ms | 166632 KB |
011.txt | WA | 223 ms | 80368 KB |
012.txt | WA | 332 ms | 168048 KB |
013.txt | WA | 167 ms | 29096 KB |
014.txt | WA | 321 ms | 163736 KB |
015.txt | AC | 175 ms | 52180 KB |
016.txt | WA | 334 ms | 166048 KB |
017.txt | WA | 284 ms | 128160 KB |
018.txt | WA | 327 ms | 163776 KB |
019.txt | WA | 227 ms | 81108 KB |
020.txt | AC | 83 ms | 18260 KB |
021.txt | AC | 74 ms | 20820 KB |
022.txt | WA | 317 ms | 164160 KB |
023.txt | WA | 330 ms | 165016 KB |
024.txt | WA | 317 ms | 164992 KB |
025.txt | WA | 318 ms | 163488 KB |
026.txt | WA | 326 ms | 165464 KB |
027.txt | WA | 319 ms | 163660 KB |
028.txt | WA | 327 ms | 165916 KB |
029.txt | WA | 315 ms | 162288 KB |
030.txt | WA | 321 ms | 165088 KB |
031.txt | WA | 310 ms | 163992 KB |
032.txt | WA | 327 ms | 166124 KB |
033.txt | WA | 318 ms | 166700 KB |
034.txt | WA | 321 ms | 165732 KB |
035.txt | WA | 316 ms | 165060 KB |
036.txt | WA | 319 ms | 162224 KB |
037.txt | WA | 331 ms | 165064 KB |
038.txt | WA | 316 ms | 163636 KB |
039.txt | WA | 313 ms | 166052 KB |
040.txt | WA | 323 ms | 161864 KB |
041.txt | WA | 324 ms | 161364 KB |
042.txt | WA | 359 ms | 163104 KB |
example0.txt | AC | 74 ms | 20308 KB |
example1.txt | AC | 73 ms | 19540 KB |