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;
long long m,n,k,x,y;
int main(){
cin>>n>>m;
long long grille[n+5][m+5];
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
cin>>grille[i][j];
}
}
long long res=0;
cin>>k;
while(k--){
cin>>x>>y;
res=res+grille[x][y];
long long maxiCur=-1;
if(x-1>=0&&y+1<m&&y-1>=0){
maxiCur=max(maxiCur,grille[x-1][y]+grille[x][y+1]+grille[x][y-1]);
}
if(x-1>=0&&y-1>=0&&x+1<n){
maxiCur=max(maxiCur,grille[x-1][y]+grille[x+1][y]+grille[x][y-1]);
}
if(x-1>=0&&x+1<n&&y+1<m){
maxiCur=max(maxiCur,grille[x-1][y]+grille[x+1][y]+grille[x][y+1]);
}
if(y+1<m&&y-1>=0&&x+1<n){
maxiCur=max(maxiCur,grille[x][y+1]+grille[x][y-1]+grille[x+1][y]);
}
if(maxiCur==-1){
cout<<"No"<<endl;
return 0;
}
res=res+maxiCur;
}
cout<<res<<endl;
}
# | 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... |