Codeforces 964B

探讨了一种消息阅读策略,通过分析消息的成本变化与额外收益的关系来最大化收益。根据成本变化的正负,确定最佳阅读时间。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

B. Messages

time limit per test:

1 second

memory limit per test:

256 megabytes

input:

standard input

output:

standard output

There are n incoming messages for Vasya. The i-th message is going to be received after ti minutes. Each message has a cost, which equals to A initially. After being received, the cost of a message decreases by B each minute (it can become negative). Vasya can read any message after receiving it at any moment of time. After reading the message, Vasya's bank account receives the current cost of this message. Initially, Vasya's bank account is at 0.

Also, each minute Vasya's bank account receives C·k, where k is the amount of received but unread messages.

Vasya's messages are very important to him, and because of that he wants to have all messages read after T minutes.

Determine the maximum amount of money Vasya's bank account can hold after T minutes.

Input

The first line contains five integers nABC and T (1 ≤ n, A, B, C, T ≤ 1000).

The second string contains n integers ti (1 ≤ ti ≤ T).

Output

Output one integer  — the answer to the problem.

Examples

input

Copy

4 5 5 3 5
1 5 5 4

output

Copy

20

input

Copy

5 3 1 1 3
2 2 2 1 1

output

Copy

15

input

Copy

5 5 3 4 5
1 2 3 4 5

output

Copy

35

Note

In the first sample the messages must be read immediately after receiving, Vasya receives A points for each message, n·A = 20 in total.

In the second sample the messages can be read at any integer moment.

In the third sample messages must be read at the moment T. This way Vasya has 1, 2, 3, 4 and 0 unread messages at the corresponding minutes, he gets 40 points for them. When reading messages, he receives (5 - 4·3) + (5 - 3·3) + (5 - 2·3) + (5 - 1·3) + 5 =  - 5 points. This is 35 in total.

 

题意

有n个信息,第i个信息会在ti分收到。每个信息有初始价值A,收到后不读价值会每分钟减少B,读了你会收到对应的价值。此外你每分钟都会收到C*k的价值,其中k是你收到但没读的信的个数。每分钟你可以读无限封信,所有信必须在T时刻之前读完,问你最后你能获得的最大价值是多少?

思路

第一眼看到感觉挺复杂,以为是个DP,但是仔细一想其实很简单。

对于每一封信,如果收到了不读的话,每分钟会少B,多C,那就只要看B和C的大小了。

如果B>C,当然是一收到就读,不然会每分钟减少(B-C)

如果B<C,当然是在T时刻再读,这样每分钟都会增加(C-B)

如果B=C,收到之后任何时刻读都可以。

因此结论就是

B<=C时,ans = A * n

B>C时,ans = [ A + (C - B) * (T - ti) ] 的求和

AC代码

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
#define INF 0x3f3f3f3f
typedef long long ll;

int s[1010];

int main()
{
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    int n, a, b, c, t, ans = 0;
    scanf("%d%d%d%d%d", &n, &a, &b, &c, &t);
    for(int i = 0; i < n; i++)
    	scanf("%d", &s[i]);
    if(b >= c)
    	ans = n * a;
    else
    {
    	sort(s, s + n);
    	int x = c - b;
    	for(int i = 0; i < n; i++)
    	{
    		ans = ans + a + x * (t - s[i]);
    	}
    }
    printf("%d\n", ans);
    return 0;    
}

 

资源下载链接为: https://pan.quark.cn/s/22ca96b7bd39 在当今的软件开发领域,自动化构建与发布是提升开发效率和项目质量的关键环节。Jenkins Pipeline作为一种强大的自动化工具,能够有效助力Java项目的快速构建、测试及部署。本文将详细介绍如何利用Jenkins Pipeline实现Java项目的自动化构建与发布。 Jenkins Pipeline简介 Jenkins Pipeline是运行在Jenkins上的一套工作流框架,它将原本分散在单个或多个节点上独立运行的任务串联起来,实现复杂流程的编排与可视化。它是Jenkins 2.X的核心特性之一,推动了Jenkins从持续集成(CI)向持续交付(CD)及DevOps的转变。 创建Pipeline项目 要使用Jenkins Pipeline自动化构建发布Java项目,首先需要创建Pipeline项目。具体步骤如下: 登录Jenkins,点击“新建项”,选择“Pipeline”。 输入项目名称和描述,点击“确定”。 在Pipeline脚本中定义项目字典、发版脚本和预发布脚本。 编写Pipeline脚本 Pipeline脚本是Jenkins Pipeline的核心,用于定义自动化构建和发布的流程。以下是一个简单的Pipeline脚本示例: 在上述脚本中,定义了四个阶段:Checkout、Build、Push package和Deploy/Rollback。每个阶段都可以根据实际需求进行配置和调整。 通过Jenkins Pipeline自动化构建发布Java项目,可以显著提升开发效率和项目质量。借助Pipeline,我们能够轻松实现自动化构建、测试和部署,从而提高项目的整体质量和可靠性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值