0
I’m trying to solve a problem of the site Urionlinejudge (problem link) and I’m getting a mistake like Time limit exceeded, and I’m having trouble identifying the problem. I can imagine that it is in the first scanf(), where it may be necessary to read the input without using the ENTER key. Below is the code.
#include <stdio.h>
int main (){
int X, Y, P, Q;
int i, j, k, l;
char carac;
while(1){
scanf("%d %d %d", &X, &Y, &P);
if(X==0 && Y==0 && P==0){
return 0;
}
int campo[X][Y];
for(i=0;i<X;i++){
for(j=0;j<Y;j++){
campo[i][j]=0;
}
}
scanf("%d", &Q);
int N=0, Z, W, qtd;
for(i=0;i<Q;i++){
qtd=0;
scanf(" %c", &carac);
if(carac=='A'){
scanf("%d %d %d", &N, &X, &Y);
campo[X][Y]+=N;
}
else{
scanf("%d %d %d %d", &X, &Y, &Z, &W);
for(j=X;j<=Z;j++){
if(Y>W){
l=Y;
Y=W;
W=l;
}
for(k=Y;k<=W;k++){
qtd+=campo[j][k];
}
}
printf("%d\n", qtd*P);
}
}
}
}