Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main() {
- int n, m;
- scanf("%d%d", &n, &m);
- int mat[n][m];
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < m; j++) {
- scanf("%d", &mat[i][j]);
- }
- }
- int k;
- scanf("%d", &k);
- int sum = 0, brojac = 0;
- for(int t = 0; t < k; t++) {
- int x;
- scanf("%d", &x);
- if(x <= n * m) {
- int red = x / m;
- if(x % m == 0) {
- sum += mat[red - 1][m - 1];
- brojac++;
- }
- else {
- sum += mat[red][(x % m) - 1];
- brojac++;
- }
- }
- }
- printf("%d\n", sum / brojac);
- return 0;
- }
- /*
- 5 4
- 1 2 5 0
- 7 2 3 1
- 12 4 5 4
- 6 1 0 1
- 2 3 4 5
- 4
- 10
- 12
- 22
- 6
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement