求助T3
  • 板块学术版
  • 楼主tybbs不是SCATZ
  • 当前回复2
  • 已保存回复2
  • 发布时间2022/9/4 17:51
  • 上次更新2023/10/27 12:33:52
查看原帖
求助T3
527303
tybbs不是SCATZ楼主2022/9/4 17:51
#include<bits/stdc++.h>
#define int long long
using namespace std;
int a[100005];
signed main(){
	freopen("test.txt","r",stdin);
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int n,x,p,q;
	int mt;
	cin>>n>>x>>p>>q;
	mt=x*p,x*=q;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		a[i]*=q;
	}
	int pre=1,pt=0,tt=0,ans=0;
	while(pre<=n){
		int t=ceil((((a[pre]-pt+ans*mt)*1.0)/(x-mt))-1.0);
		if(t<0) t=0;
		if(t){
			pt+=x*t;
			tt=0;
			ans+=t;
			continue;
		}
		while(tt<x && pre<=n){
			tt+=a[pre];
			if(tt>=x) break;
			pre++;			
		}
		if(pre==n && tt<x) continue;
		tt-=a[pre];	
		pt+=(x-tt);
		tt=0;
		ans++;
	}	
	cout<<ans;
}

样例全过,然而挂零

2022/9/4 17:51
加载中...