标签:++i define || https ret stdin reg http efi
//minamoto
#include<bits/stdc++.h>
#define R register
#define ll long long
#define fp(i,a,b) for(R int i=a,I=b+1;i<I;++i)
#define fd(i,a,b) for(R int i=a,I=b-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
using namespace std;
char buf[1<<21],*p1=buf,*p2=buf;
inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
int read(){
R int res,f=1;R char ch;
while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
return res*f;
}
const int N=2e5+5;
struct node{int v,s,id;}a[N],b[N],c[N];
int l[N],r[N],ds,dv;
ll res,s[N];int n,m;
inline bool cmp1(const node &x,const node &y){return x.s<y.s;}
inline bool cmp2(const node &x,const node &y){return x.v<y.v;}
inline ll calc(R ll v,R ll s){return ((dv&1)?v:v*v)-((ds&1)?s:s*s);}
void del(R int p){r[l[p]]=r[p],l[r[p]]=l[p];}
int main(){
// freopen("testdata.in","r",stdin);
n=read(),m=read(),ds=read(),dv=read();
fp(i,1,n)a[i].s=read(),a[i].v=read();
sort(a+1,a+1+n,cmp1);
fp(i,1,n)a[i].id=i,b[i]=a[i];
fp(i,1,n){
ll sum=0;
fp(j,i,min(i+m-1,n)){
sum+=a[j].v;
cmax(res,calc(sum,a[j].s-a[i].s));
}
}
sort(a+1,a+1+n,cmp2);
fp(i,1,n)l[i]=i-1,r[i]=i+1;
l[n+1]=n,r[0]=1;
fp(i,1,n){
int top=0;
for(R int j=a[i].id,k=1;j>=1&&k<=m;j=l[j],++k)c[++top]=b[j];
reverse(c+1,c+1+top);
for(R int j=r[a[i].id],k=2;j<=n&&k<=m;j=r[j],++k)c[++top]=b[j];
fp(j,1,top)s[j]=s[j-1]+c[j].v;
fp(j,m,top)cmax(res,calc(s[j]-s[j-m],c[j].s-c[j-m+1].s));
del(a[i].id);
}
printf("%lld\n",res);
return 0;
}
标签:++i define || https ret stdin reg http efi
原文地址:https://www.cnblogs.com/bztMinamoto/p/10279338.html