Advertisement
Josif_tepe

Untitled

Feb 14th, 2021
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.91 KB | None | 0 0
  1. #include <stdio.h>
  2. #define MAX 500
  3. int main()
  4. {
  5.    int a[MAX][MAX],n,m,niza[3], nova[MAX][MAX], k=0;
  6.    scanf("%d%d",&n,&m);
  7.    for (int i=0; i<n; i++){
  8.        for(int j=0; j<m;j++)
  9.        {
  10.            scanf("%d",&a[i][j]);
  11.        }
  12.    }
  13.     scanf("%d", &k);
  14.    for(int i=0;i<k;i++){
  15.        scanf("%d", &niza[i]);
  16.    }
  17.     int zbir = 0 ;
  18.     for(int i = 0; i < k; i++) {
  19.         if(niza[i] > n * m) {
  20.             continue;
  21.         }
  22.         for(int x = 0; x < n; x++) {
  23.             for(int y = 0; y < m; y++) {
  24.                 niza[i] -= 1;
  25.                 if(niza[i] == 0) {
  26.                     zbir += a[x][y];
  27.                     break;
  28.                 }
  29.                
  30.             }
  31.             if(niza[i] == 0) {
  32.                 break;
  33.             }
  34.         }
  35.     }
  36.     printf("%d\n", zbir);
  37.    
  38.     return 0;
  39. }
  40. /*
  41.  5 4
  42.  1 2 5 0
  43.  7 2 3 1
  44.  12 4 5 4
  45.  6 1 0 1
  46.  2 3 4 5
  47.  1 7 6
  48.  */
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement