|
|
back to boardtime limit Posted by Anuar 1 Dec 2011 15:15 why time limit? n*(n+1)/2 operations: import java.util.*; public class RailwayTickets { public static long l1,l2,l3,c1,c2,c3,n; public static int s,t; public static long f(long k) { if (k>0 && k<=l1) return c1; else if (k>l1 && k<=l2) return c2; else if (k>l2 && k<=l3) return c3; return Long.MAX_VALUE; } public static void main(String args[]) { Scanner in = new Scanner(System.in); l1=in.nextLong();l2=in.nextLong();l3=in.nextLong();c1=in.nextLong();c2=in.nextLong();c3=in.nextLong();n=in.nextLong();s=in.nextInt();t=in.nextInt(); long[] d = new long[10001], c = new long[10001]; if (s>t) {int yed=s;s=t;t=yed;}; for (int i=2;i<=n;i++) c[i]=in.nextLong(); for (int i=1;i<=n;i++) d[i]=Long.MAX_VALUE; d[s]=0; for (int i=s+1;i<=t;i++) for (int j=s;j<i;j++) if (d[i]>d[j]+f(c[i]-c[j])) d[i]=d[j]+f(c[i]-c[j]); System.out.println(d[t]); } } Edited by author 01.12.2011 15:34 Re: time limit Posted by nobik 16 Jun 2012 20:38 Try to use c++ to solve this problem or think about better algorithm))) And you read not very fast)) Try to use stream tokenizer)) Edited by author 16.06.2012 22:14 |
|
|