Skip to content

Instantly share code, notes, and snippets.

@catupper
Created October 1, 2011 12:54
Show Gist options
  • Save catupper/1256026 to your computer and use it in GitHub Desktop.
Save catupper/1256026 to your computer and use it in GitHub Desktop.
GCJJ2011
#include<stdio.h>
int main(){
int T,M,C,W,i,j;
scanf("%d",&T);
for(i=1;i<=T;i++){
scanf("%d%d%d",&M,&C,&W);
int A[100],B[100];
for(int j=0;j<C;j++){
scanf("%d%d",&A[j],&B[j]);
}
int n;
n=W-1;
for(j=C-1;j>=0;j--){
if(n<B[j]){
n=A[j]+n-1;
}
else if(n>=B[j]&&n<=(A[j]+B[j]-2)){
n=n-B[j];
}
}
printf("Case #%d: %d\n",i,n+1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment