求助,28,29测试点TLE,其他都AC
查看原帖
求助,28,29测试点TLE,其他都AC
579109
LiDingguang楼主2022/9/5 22:23

下面是代码:

#include<bits/stdc++.h>
using namespace std;
int n,j;
double r,sleep1,sleep2,other,x,p,q,a[100005],num;
int main(){
    cin>>n>>x>>p>>q;
    r=p/q;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=1;;i++){
        sleep2=r*x*i-sleep1;//每天睡的时间 
        other=min(x,x-sleep2);
        for(;j<n;j++){
            if(other>=a[j]){
            	if(other==a[j]&&sleep2<=0){
            		sleep2-=other;
            		break;
				}
				other-=a[j];
                num+=a[j];
            }else{
                sleep1+=max(0.0,sleep2);
                sleep1+=other;
                break;
            }
        }
        if(j==n){
            cout<<i;
            return 0;
        }
        num=0;
    }
}
2022/9/5 22:23
加载中...