ABC D 求调
  • 板块学术版
  • 楼主Mobius127
  • 当前回复11
  • 已保存回复11
  • 发布时间2022/8/6 21:43
  • 上次更新2023/10/27 16:41:43
查看原帖
ABC D 求调
341102
Mobius127楼主2022/8/6 21:43

不知道脑子里进了什么东西,AC 31 WA 8.

因为这个没去想 FGEx,十分沙币

#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <cctype>
#define int long long
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const int mo=1e9+7;
inline int read(){
	char ch=getchar();int x=0, f=1;
	while(!isdigit(ch)){if(ch=='-') f=-1; ch=getchar();}
	while(isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
	return x*f;
}
inline void write(int x){
    if(x<0) putchar('-'), x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}
inline int ksm(int a, int b){
	int ret=1;
	for(; b; b>>=1, a=1ll*a*a%mo)
		if(b&1) ret=1ll*ret*a%mo;
	return ret;
}
const int N=2e5+5;
int n, m, L, R, pre[N], suf[N], a[N], ans;
int qL[N], qR[N], ltop, rtop;
bool cmp(int x, int y){return x>y;}
signed main(){
	n=read(), L=read(), R=read();
	for(int i=1; i<=n; ++i) 
		a[i]=read(), pre[i]=pre[i-1]+a[i];
	for(int j=n; j>=1; --j) 
		suf[j]=suf[j+1]+a[j];
	
	ans=pre[n];
	
	for(int i=1; i<=n; i++){
		if(pre[i]>i*L) qL[++ltop]=i;
		ans=min(ans, i*L+suf[i+1]);
	}
	qL[++ltop]=0;
	qR[++rtop]=n+1;
	for(int i=n; i>=1; --i){
		if(suf[i]>(n-i+1)*R) qR[++rtop]=i;
		ans=min(ans, (n-i+1)*R+pre[i-1]);
	}
	
	int rr=rtop;
	sort(qR+1, qR+rr+1);rr=1;
	for(int i=1; i<ltop; ++i){
		int ml=qL[i];
		while(qR[rr]<=ml) ++rr;//printf("--%d\n", rr);
		int mr=qR[rr];
		ans=min(ans, L*ml+pre[mr-1]-pre[ml]+R*(n-mr+1));
	}
	int ll=ltop;
	sort(qL+1, qL+ll+1, cmp);ll=1;
	for(int i=rtop-1; i>=1; --i){
		int mr=qR[i];
		while(qL[ll]>=mr) --ll;
		int ml=qL[ll];
		ans=min(ans, L*ml+pre[mr-1]-pre[ml]+R*(n-mr+1));
	}
	printf("%lld", ans);
	return 0;
}


2022/8/6 21:43
加载中...