F - Shovels Shop
题意:有 件物品每个价值 , 个 ,对于每个 即,买 件物品,可以优惠掉其中 件最便宜的。问买 个物品的最少花费。
题解:
首先,对于每个
,
相同时,肯定
越大越好。
其次,这些优惠肯定是从这
个物品中前
小里优惠。
因此我们考虑
代表购买前
个物品所需要的最少花费。就有
利用填表法的
思想,肯定就是通过前面已经确定好的最优子结构来推出
,即
,其中
代表对于
所对应能减免的数量。
代码
#include<bits/stdc++.h>
#define P pair<int,int>
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
using namespace std;
const int N = 2E5+10, M = 5025;
typedef long long LL;
int a[N],off[N], dp[M], sum[M];
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.in","r",stdin);
#endif
ios::sync_with_stdio(false); cin.tie(0);
int n,k,m,x,y;
cin >> n >> m >> k;
for(int i = 1; i <= n; ++i) {
cin >> a[i];
}
memset(off, -1, sizeof off);
for(int i = 0; i < m; ++i) {
cin >> x >> y;
off[x] = max(off[x], y);
}
sort(a + 1, a + n + 1);
for(int i = 1; i <= k; ++i) sum[i] = sum[i - 1] + a[i];
dp[0] = 0;
for(int i = 1; i <= k; ++i) {
dp[i] = sum[i];
for(int j = 1; j <= i; ++j) {
if(~off[j])
dp[i] = min(dp[i], dp[i - j] + sum[i] - sum[i - j + off[j]]);
}
}
cout << dp[k] << endl;
return 0;
}