#include <iostream>
#include <vector>
using namespace std;
int main() {int m, n, cx, cy;
cin >> m >> n;
vector<int>a;
a.reserve(m*n);
for (int i = 0;i < m;++i) {
for(int j = 0;j < n;++j) {
int v;
cin >> v;
a.push_back(v);
}
int x;
int value = 0;
cin >> x;
for (int k = 0;k < x;++k) {
cin >> cx >> cy;
if((a[cy-1 + (cx-1)*cy]) != -100) {
value += a[cy-1 + (cx-1)*cy];
a[cy-1 + (cx-1)*cy] = -100;
}cout << value;
Объяснение:
int main() {
int n, m;
cin >> n >> m;
int a[100][100];
// чтение
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> a[i][j];
int max = a[0][0], max_i = 0, max_j = 0;
if (a[i][j] > max) {
max = a[i][j];
max_i = i;
max_j = j;
cout << max_i << " " << max_j;
return 0;
#include <iostream>
#include <vector>
using namespace std;
int main() {int m, n, cx, cy;
cin >> m >> n;
vector<int>a;
a.reserve(m*n);
for (int i = 0;i < m;++i) {
for(int j = 0;j < n;++j) {
int v;
cin >> v;
a.push_back(v);
}
}
int x;
int value = 0;
cin >> x;
for (int k = 0;k < x;++k) {
cin >> cx >> cy;
if((a[cy-1 + (cx-1)*cy]) != -100) {
value += a[cy-1 + (cx-1)*cy];
a[cy-1 + (cx-1)*cy] = -100;
}
}cout << value;
}
Объяснение:
#include <iostream>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int a[100][100];
// чтение
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> a[i][j];
}
}
int max = a[0][0], max_i = 0, max_j = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (a[i][j] > max) {
max = a[i][j];
max_i = i;
max_j = j;
}
}
}
cout << max_i << " " << max_j;
return 0;
}
Объяснение: