CF964B 题解

· · 题解

思路

我们有 n 封信,如果我们每次收到就读,那收益就是 n \times a 。
我们再来思考拖时间读的情况。
如果不读,每分钟收益减少 b ,但同时也会增加 c \times k 的钱。
那每封信每分钟的价格变化应该是加上 c - b 。
我们总共到 t 要拖的时间是所有 t - t_i 的和。 如果 c > b 那么是可以一直拖到 t 的,就相当于每分钟这封信的价格以 c - b 的速度增长,这样价值最大化至 sum(t - t_i) \times (c - b) + n \times a 。
否则应该收到就读,输出 n \times a 。

AC 代码

#include<bits/stdc++.h>
using namespace std;
int n,a,b,c,t,sum;
int m[1005];
int main(){
    cin >> n >> a >> b >> c >> t;
    for(int i=0;i<n;i++)cin >> m[i],sum+=t-m[i];
    int ans=n*a;
    if(b<c){
        ans+=sum*(c-b);
    }
    cout << ans;
}