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
#define mid (start+end)/2
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);
//give me five point
int32_t main(){
faster
int n,m;cin>>n>>m;
int dizi[n+1][m+1];
for(int i=0;i<n;i++)dizi[i][0]=0;
for(int j=0;j<m;j++)dizi[0][j]=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>dizi[i][j];
}
}
int k;cin>>k;
int ans=0;
for(int i=0;i<k;i++){
int a,b;cin>>a>>b;
int maxi=0;
int ort=dizi[a][b];
//int ust=dizi[a+1][b],alt=dizi[a-1][b],sag=dizi[a][b+1],sol=dizi[a][b-1];
int ust=0,alt=0,sag=0,sol=0;
if(a+1>0)ust=dizi[a+1][b];
if(a-1<=n)alt=dizi[a-1][b];
if(b+1<=m)sag=dizi[a][b+1];
if(b-1>0)sol=dizi[a][b-1];
int cev1=max(alt,ust)+sag+sol+ort;
int cev2=max(sag,sol)+alt+ust+ort;
maxi=max(cev1,cev2);
ans+=maxi;
}
cout<<ans<<'\n';
return 0;
}
# | 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... |