# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
642561 | moday_morning | T-Covering (eJOI19_covering) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define int long long
using namespace std;
int ar[1000006][1000006];
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> ar[i][j];
}
}
int q;
cin >> q;
while (q--) {
int i, j;
cin >> i >> j;
vector <int> a;
a.push_back(ar[i+1][j]);
a.push_back(ar[i-1][j]);
a.push_back(ar[i][j+1]);
a.push_back(ar[i][j-1]);
int sum = 0, mn = INT_MAX, ind = 0;
for (int i = 0; i < 4; i++) {
mn = min(mn, a[i]);
if (a[i] == mn) {
ind = i;
}
}
for (int i = 0; i < 4; i++) {
if (ind != i) {
sum += a[i];
}
}
cout << sum << "\n";
}
}