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>
using namespace std;
#define int long long
int32_t main()
{
ios_base::sync_with_stdio(false); cin.tie(0);
int n, m; cin>>n>>m;
int val[n][m];
for(int i=0; i<n; i++)
{
for(int l=0; l<m; l++)
cin>>val[i][l];
}
int k; cin>>k;
vector<array<int, 2>> ind(k);
n--; m--;
int sum=0, f=0;
for(int i=0; i<k; i++)
{
int h=0;
int x, y; cin>>x>>y;
if(y>=1&&m-y>=1)
{
if(x>=1) h=max(h, val[x][y]+val[x-1][y]+val[x][y-1]+val[x][y+1]);
if(n-x>=1) h=max(h,val[x][y]+val[x+1][y]+val[x][y-1]+val[x][y+1]);
}
if(x>=1&&n-x>=1)
{
if(y>=1) h=max(h, val[x][y]+val[x+1][y]+val[x-1][y]+val[x][y-1]);
if(m-y>=1) h=max(h, val[x][y]+val[x+1][y]+val[x-1][y]+val[x][y+1]);
}
if(h==0) f=1;
sum+=h;
}
if(f) cout<<"NO\n";
else cout<<sum<<"\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |