代码求调,悬关
查看原帖
代码求调,悬关
593791
_Catluo_楼主2024/5/8 11:51

WA #1 #2 #3 #8 #9

#include<bits/stdc++.h>
#define int long long 
using namespace std;
namespace IO{
    char buff[1<<21],*p1=buff,*p2=buff;
    char getch(){
        return p1==p2&&(p2=((p1=buff)+fread(buff,1,1<<21,stdin)),p1==p2)?EOF:*p1++;
    }
    template<typename T>
    void read(T &x){
        char ch=getch();int fl=1;x=0;
        while(ch>'9'||ch<'0'){if(ch=='-')fl=-1;ch=getch();}
        while(ch<='9'&&ch>='0'){x=x*10+ch-48;ch=getch();}
        x*=fl;
    }
    template<typename T,typename ...Args>
    void read(T &x,Args& ...args){
        read(x);read(args...);
    }
    char obuf[1<<21],*p3=obuf;
    void putch(char ch){
        if(p3-obuf<(1<<21))*p3++=ch;
        else fwrite(obuf,p3-obuf,1,stdout),p3=obuf,*p3++=ch;
    }
    char ch[100];
    template<typename T>
    void write(T x){
        if(!x)return putch('0');
        if(x<0)putch('-'),x*=-1;
        int top=0;
        while(x)ch[++top]=x%10+48,x/=10;
        while(top)putch(ch[top]),top--;
    }
    template<typename T,typename ...Args>
    void write(T x,Args ...args){
        write(x),putch(' '),write(args...);
    }
    void flush(){fwrite(obuf,p3-obuf,1,stdout);}
}
using namespace IO;
const int N=2e5+5;
int n,m,c,d,len;
int a[N],sum[N];
int f[45][N],g[45][N];
int q[45][N],l[45],r[45];
stack<int>st;
signed main(){
	memset(f,0x3f,sizeof f);
	read(n,m,c,d);
	len=c*n+m;
	for(int i=1;i<=len;i++)read(a[i]);
	for(int i=1;i<=len;i++)sum[i]=sum[i-1]+a[i];
	f[0][0]=0;
	for(int i=0;i<=n;i++)r[i]=-1;
	for(int i=c;i<=len;i++){
		for(int j=1;j<=n;j++){
			while(l[j-1]<=r[j-1]&&f[j-1][q[j-1][r[j-1]]]>=f[j-1][i-c])r[j-1]--;q[j-1][++r[j-1]]=i-c;
			while(q[j-1][l[j-1]]<i-d-c)l[j-1]++;
			g[j][i]=q[j-1][l[j-1]];
			f[j][i]=f[j-1][g[j][i]]+sum[i]-sum[i-c+1];
		}
	}
	int maxn=len;
	for(int i=0;i<len;i++)
		if(f[n][i]<f[n][maxn])maxn=i;
	write(sum[len]-f[n][maxn]),putch('\n');
	int now=maxn,w=n;
	while(now){
		st.push(now-c+1);
		now=g[w--][now];
	}
	while(!st.empty())write(st.top()),putch(' '),st.pop();
	flush();
	return 0;
}
2024/5/8 11:51
加载中...