fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. int M, N;
  5. long long P[1005][1005];
  6.  
  7. scanf("%d %d", &M, &N);
  8.  
  9. for (int i = 1; i <= M; i++) {
  10. for (int j = 1; j <= N; j++) {
  11. scanf("%lld", &P[i][j]);
  12. }
  13. }
  14.  
  15. for (int i = 0; i <= M; i++) {
  16. P[i][0] = 0;
  17. }
  18.  
  19. for (int j = 0; j <= N; j++) {
  20. P[0][j] = 0;
  21. }
  22.  
  23. int B, K;
  24.  
  25. while (scanf("%d", &B) == 1 && B != -9) {
  26. scanf("%d", &K);
  27.  
  28. long long hasil = P[B][K]
  29. - P[B-1][K]
  30. - P[B][K-1]
  31. + P[B-1][K-1];
  32.  
  33. printf("%lld ", hasil);
  34. }
  35.  
  36. printf("\n");
  37.  
  38. return 0;
  39. }
Success #stdin #stdout 0s 5320KB
stdin
3 3
10 30 60
15 45 95
17 51 107
1 1
2 1
1 3
3 3
-9
stdout
10 5 30 6