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