Skip to content

Instantly share code, notes, and snippets.

@justcoding121
Created October 24, 2012 04:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justcoding121/3943740 to your computer and use it in GitHub Desktop.
Save justcoding121/3943740 to your computer and use it in GitHub Desktop.
import java.util.*;
import java.io.*;
public class Main {
final static String FNAME = "C-small-attempt0";
public Scanner in;
public PrintWriter out;
void open() throws IOException {
in = new Scanner( new File( FNAME + ".in" ) ) ;
out = new PrintWriter( new File( FNAME + ".out" ) );
}
void close() throws IOException {
out.close();
}
int h;
int w;
char cur;
void run() throws IOException {
int tn = in.nextInt();
for ( int test = 1; test <= tn; test ++ ) {
int r=in.nextInt();
int k=in.nextInt();
int N=in.nextInt();
int[] a=new int[N];
for(int i=0;i
a[i]=in.nextInt();
int sum=0,t=0,cost=0;
for(int j=0;j
{
for(int i=0;i
{
sum=sum+a[i];
if(sum>k)
{
sum=sum-a[i];
t=i-1;
break;
}
}
cost=cost+sum;
sum=0;
int[] b=new int[t+1];
for(int i=0;i<=t;i++)
b[i]=a[i];
for(int l=0;l<(N-t-1);l++)
a[l]=a[l+t+1];
int g=0;
for(int l=(N-t-1);l
{
a[l]=b[g];
g++;
}
}
out.println( "Case #" + test + ": " + cost );
}
}
public static void main( String[] args ) throws IOException {
new Thread() {
public void run() {
try {
Main solution = new Main();
solution.open();
solution.run();
solution.close();
} catch ( Exception e ) {
throw new RuntimeException( e );
}
}
}.start();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment