题解
考虑如果选择b肯定是在所有的a使用完毕后再使用
数据量1000枚举a的使用量i 计算每个数值选择a比选择b高出的收益然后降序排序并选择前i个答案取max即可
AC代码
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int MAXN = 1e3 + 10;
struct node
{
ll a, b;
}a[MAXN];
int main()
{
#ifdef LOCAL
//freopen("C:/input.txt", "r", stdin);
#endif
int n;
cin >> n;
for (int i = 1; i <= n; i++)
scanf("%lld%lld", &a[i].a, &a[i].b);
ll ans = 0;
for (int i = 1; i <= n; i++) //枚举a数量
{
/*
for (int j = 1; j <= n; j++)
a[j].s = a[j].a - i * a[j].b; //作为a的收益
sort(a + 1, a + n + 1, greater<node>());
*/
sort(a + 1, a + n + 1, [i](const node &a, const node &b){ return a.a - a.b * i > b.a - b.b * i; }); //lambda
ll res = 0;
for (int j = 1; j <= n; j++) //前i个选为a否则为b
if (j <= i)
res += a[j].a;
else
res += i * a[j].b;
ans = max(ans, res);
}
cout << ans << endl;
return 0;
}