shopee Fireworks Festival

Shopee will be hosting a fireworks festival along one of Singapore’s main streets. The main street spans across N number of roads and the distance between each adjacent road is 1.

The person-in-charge is expected to set off the fireworks for m times, with the i th time ( 1≤i≤m ) being set off at the timing ti along the road ai punctually. If you catch the i th firework at road x

1≤x≤n ), then you will be able to receive bi-|ai-x| amount of free Shopee coins. Note that the amount of Shopee coins may be a negative value.

You are able to move d amount of distance within each unit of time without leaving the main street. Alternatively, you may also pick a random spot along the main street at the beginning of the festival (where time = 1) to maximise your chances of gaining Shopee coins.

Note that the person-in-charge may concurrently set off two or more fireworks at one time. 

Your aim is to strategise the best way to receive the highest amount of Shopee coins. 

Input
The first row should feature three integers: nmd ( 1≤n≤150000;1≤m≤300;1≤d≤n ). For variable m, each row of input should include integers ai, bi, ti ( 1≤ai≤n;1≤bi≤109;1≤ti≤109 ). The i th row should feature the respective variables for the i th set off.

Note: It is ensured that the inputs fulfil the criteria of ti ≤ ti+1 ( 1≤i <m ).

Output: 

To print an integer of the highest possible amount of Shopee coins. 

SAMPLE INPUT

10 2 1
1 500 5
9 500 5

SAMPLE OUTPUT

992

思路:dp+单调队列优化

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 150010;
const long long INF = 10000000000000000LL;
 
long long dp[2][MAXN];
 
struct Node {
	int a, b, t;
	void input() {
		scanf("%d%d%d", &a, &b, &t);
	}
};
Node node[310];
int q[MAXN];
 
int main() {
	int n, m, d;
	while (scanf("%d%d%d", &n, &m, &d) == 3) {
		for (int i = 0; i < m; i++) {
			node[i].input();
		}
		int now = 0;
		memset(dp[now], 0, sizeof(dp[now]));
		for (int i = 0; i < m; i++) {
			now ^= 1;
			int dd = 0;
			if (i > 0) {
				if ((long long)d * (node[i].t - node[i-1].t) > n) {
					dd = n;
				} else {
					dd = d * (node[i].t - node[i-1].t);
				}	
			}
 
			int st = 0, ed = 0;
			int nn = 1;
			for (int j = 1; j <= n; j++) {
				while (nn <= n && nn <= j+dd) {
					while (st < ed && dp[now^1][nn] >= dp[now^1][q[ed-1]]) ed--;
					q[ed++] = nn++;
				}
				while (q[st] < j-dd)st++;
				dp[now][j] = dp[now^1][q[st]] + node[i].b - abs(node[i].a - j);
			}
		}
		long long ans = dp[now][1];
		for (int i = 1; i <= n; i++)
			ans = max(ans, dp[now][i]);
		cout<<ans<<endl;
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值