救救孩子吧
查看原帖
救救孩子吧
164883
Zigh_Wang楼主2022/9/4 21:26

贪心(或者说递推

T掉了两个点

在这里插入图片描述

#include<bits/stdc++.h>
#define ll long long
using namespace std;

const int MAXN = 1e5 + 5;

int inpt()
{
	int x = 0, f = 1;
	char ch;
	for(ch = getchar(); (ch < '0' || ch > '9') && ch != '-'; ch = getchar());
	if(ch == '-'){
		f = -1;
		ch = getchar();
	}
	do{
		x = (x << 3) + (x << 1) + ch - '0';
		ch = getchar();
	}while(ch >= '0' && ch <= '9');
	return x * f;
}

int n, x, p, q;
int t[MAXN];
ll ans = 0;

int main()
{
//	freopen("task5.in", "r", stdin);
	
	n = inpt(), x = inpt(), p = inpt(), q = inpt();
	for(int i = 1; i <= n; i++) {
		t[i] = inpt();
	}
	
	ll sum = 0;
	for(int i = 1; i <= n; i++) {
		ll cando = 1ll * ans * x * (q - p) / q - sum;
		if(t[i] > cando) {
			ans += (t[i] - cando) / (1ll * x * (q - p) / q + 1);
		}
		cando = 1ll * ans * x * (q - p) / q - sum;
		while(t[i] > cando) {
			ans++;
			cando = 1ll * ans * x * (q - p) / q - sum;
		}
		int tmp = t[i];
		while(tmp + t[i + 1] <= cando && tmp + t[i + 1] < x && i <= n) {
			tmp += t[++i];
		}
		sum += tmp;
		ans++;
	}
	ans--;
	
	printf("%lld", ans);

 	return 0;
}

2022/9/4 21:26
加载中...