列表

详情


NC223807. TheBoomsdayProject

描述

Aloha is a poor guy who likes riding a bike. But he is too poor to afford a bicycle.

Recently, the Boom's bike-sharing service entered his school. It only costs yuan for every single rent of a bicycle. From then on, Aloha could rent a bike and enjoy the speed and passion of riding.

The Boom's company has launched a promotion program named the . In this program, users can buy discount cards with several free rents and a valid period. For example, after purchasing a discount card with free rents and days of valid time, one doesn't need to pay extra fees for the following rents in the next days. Note that, no matter when the card is bought on day , it will always expire at the end of day . Also, any new discount card overrides the previous one even if it is still valid, i.e., the remaining free rents of the previous discount card are voided immediately when the new discount card is purchased.

There are different types of discount cards in the . A card of th type with k_i free rents and a valid period of days costs c_i yuan. One can buy any type of discount card unlimited times.

Given the rental records, Aloha wants to know the minimum money he has to pay, provided that he takes the best strategy.

输入描述

The first line of input contains three integers  , denoting the number of discount card types, the number of rental records, and the price of a single rent.
Then follow lines, specifying the types of discount cards. The th line contains three integers d_i, k_i, c_i , denoting the valid period, the number of free rents, and the price of a discount card of type .
The last lines describe Aloha's rental records. The th of them contains two integers p_i, q_i , representing that Aloha would rent bikes q_i times on Day p_i. It is guaranteed that are distinct.

输出描述

Print one integer in a line, denoting the minimum money Aloha has to pay if he adopts the best strategy.

示例1

输入:

2 1 10
1 3 12
1 2 9
1 10

输出:

42

示例2

输入:

2 4 10
1 3 12
1 2 9
1 3
2 3
3 3
4 1

输出:

45

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++(clang++ 11.0.1) 解法, 执行用时: 635ms, 内存消耗: 2856K, 提交时间: 2022-11-03 09:32:42

#include<bits/stdc++.h>
using namespace std;
int n,m,r,f[300005],a[300005];
int l[505],d[505],k[505],c[505];
signed main()
{
	ios::sync_with_stdio(0);
	cin>>n>>m>>r;
	for(int i=1;i<=n;i++)
		cin>>d[i]>>k[i]>>c[i],l[i]=1;
	int len=0;
	for(int i=1,p,q;i<=m;i++)
	{
		cin>>p>>q;
		while(q--)
			a[++len]=p;
	}
	sort(a+1,a+len+1);
	for(int i=1;i<=len;i++)
	{
		f[i]=f[i-1]+r;
		for(int j=1;j<=n;j++)
		{
			while(i-l[j]+1>k[j]||a[i]-a[l[j]]+1>d[j])
			{
				l[j]++;
				if(l[j]>i)break;
			}
			f[i]=min(f[i],f[l[j]-1]+c[j]);
		}
		//cerr<<f[i]<<endl;
	}
	cout<<f[len]<<endl;
}

上一题