시도 횟수: 3회
해결한 시간: 00:28
<aside> 💡
그리디하게 옮기면서 돈이 가장 많이 손실되는 은행에 모아야한다.
각 은행 당 옮겨지는 돈은 $\lfloor a_i\times x/y \rfloor$이다.
</aside>
#include <bits/stdc++.h>
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
using namespace std;
typedef long long ll;
int n;
ll x, y;
bool compare(ll a, ll b)
{
return a-a/x*y > b-b/x*y;
}
void solve()
{
cin >> n >> x >> y;
vector<ll> a(n);
for(int i = 0; i<n; i++){
cin >> a[i];
}
sort(a.begin(), a.end(), compare);
for(int i = 1; i<n; i++){
a[0] += a[i]/x*y;
}
cout << a[0] <<"\\n";
}
signed main()
{
FASTIO;
int _tc; cin >> _tc;
while (_tc--) solve();
return 0;
}
문제를 잘못 읽어서 여러번 틀렸다.