CF2194B Offshores

思路

很简单的题,没想明白为什么有人切了 CD 没切。
问了一下 @WBJ0429 为什么做那么慢,得知他以为可以进行多次转移,把某个银行中剩余的钱作为“补给”,在最后 $10$ 分钟才发现。
实则这是错的。

我们知道若要使得某银行中的存款数达到最大,则需要把其他银行中所有能转移的钱全都转移到该银行。
首先假设我们要将所有银行中的钱全都转移出来到一个虚拟银行(初始资金数为 $0$),计算出总和。
然后我们枚举最后要转移到哪个银行,从总和中减掉这个银行的贡献,再加上它的初始钱数即可,把这些值取 $\max$ 即可得到最终答案。

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include<bits/stdc++.h>
#define fir first
#define sec second
#define int long long
#define pii pair<int,int>
#define fep(i,s,e) for(int i=s;i<e;i++)
#define pef(i,s,e) for(int i=s;i>e;i--)
#define rep(i,s,e) for(int i=s;i<=e;i++)
#define per(i,s,e) for(int i=s;i>=e;i--)
namespace FastIO{
template<typename T>inline void read(T &x){
x=0;int f=1;char c=getchar();
for(;!isdigit(c);c=getchar())if(c=='-')f=-1;
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);x*=f;
}
template<typename T,typename...Args>
inline void read(T &x,Args&...args){
read(x);
read(args...);
}
template<typename T>void print(T x){
if(x<0)x=-x,putchar('-');
if(x>9)print(x/10);
putchar((x%10)^48);
}
}
using namespace std;
using namespace FastIO;
const int N=2e5+47;
int T,n,x,y,a[N],b[N];
signed main(){
read(T);
while(T--){
read(n,x,y);
int ans=0,sum=0;
rep(i,1,n){
read(a[i]);
b[i]=a[i]/x*y;
sum+=b[i];
}
rep(i,1,n){
ans=max(ans,sum-b[i]+a[i]);
}
print(ans);puts("");
}
}