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<iostream>
using namespace std;
int r,s,a,b;
long long **sum_pr,odp;
long long *dokad;
void inicjuj()
{
if(a>b)
swap(a,b);
odp=a+b;
sum_pr=new long long *[s+1];
for(int i=0;i<=s;++i)
sum_pr[i]=new long long [r+1];
dokad=new long long[r+1];
}
long long sum_prost(int xpd,int ypd,int xlg,int ylg)
{
return sum_pr[xpd][ypd]-sum_pr[xlg-1][ypd]-sum_pr[xpd][ylg-1]+sum_pr[xlg-1][ylg-1];
}
int main()
{
scanf("%d%d%d%d",&r,&s,&a,&b);
inicjuj();
for(int i=1;i<=r;++i)
{
for(int j=1;j<=i;++j)
dokad[j]=1;
for(int j=1;j<=s;++j)
{
scanf("%lld",&sum_pr[j][i]);
sum_pr[j][i]+=sum_pr[j-1][i]+sum_pr[j][i-1]-sum_pr[j-1][i-1];
for(int k=i;k>0;--k)
{
while(dokad[k]<j)
{
if(sum_prost(j,i,dokad[k],k)<=a)
break;
++dokad[k];
}
odp=min(odp,abs(a-sum_prost(j,i,dokad[k],k))+abs(b-sum_prost(j,i,dokad[k],k)));
if(dokad[k]>1)
odp=min(odp,abs(a-sum_prost(j,i,dokad[k]-1,k))+abs(b-sum_prost(j,i,dokad[k]-1,k)));
}
}
}
printf("%lld",odp);
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:22:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
22 | scanf("%d%d%d%d",&r,&s,&a,&b);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:30:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
30 | scanf("%lld",&sum_pr[j][i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |