题目链接:
http://codeforces.com/contest/1154/problem/F
思路:
dp,因为只买k个铲子,所以只需要对最便宜的k个铲子进行dp即可。
递推式为:
选择优惠方案:dp[i]=min(dp[i],dp[i-p[j].x]+sum[i]-sum[i-p[j].x+p[j].y]) ; 1<=j<=m,1<=i<=k
不选优惠方案: dp[i]=min(dp[i],dp[i-1]+a[i]);
代码如下:
//include <bits/stdc++.h>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <time.h>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <functional>
#define sdddd(x,y,z,k) scanf("%d%d%d%d", &x, &y, &z, &k)
#define sddd(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define sdd(x,y) scanf("%d%d", &x, &y)
#define sd(x) scanf("%d", &x)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
//#define mp make_pair
#define pb push_back
#define ms(x, y) memset(x, y, sizeof x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
const int maxn = 2*1e5+5;;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
template <class T>
inline bool scan_d(T &ret) {
char c; int sgn;
if (c = getchar(), c == EOF) return 0;
while (c != '-' && (c<'0' || c>'9')) c = getchar();
sgn = (c == '-') ? -1 : 1;
ret = (c == '-') ? 0 : (c - '0');
while (c = getchar(), c >= '0'&&c <= '9') ret = ret * 10 + (c - '0');
ret *= sgn;
return 1;
}
struct node
{
int x,y;
};
node p[maxn];
int n,m,k;
ll dp[2005];
int a[maxn];
ll sum[maxn];
int compare (int a,int b)
{
return a<b;
}
int main()
{
memset (sum,0,sizeof(sum));
scanf("%d%d%d",&n,&m,&k);
for (int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
sort(a+1,a+n+1);
for (int i=1;i<=n;i++)
{
sum[i]=sum[i-1]+a[i];
}
for (int i=1;i<=m;i++)
{
scanf("%d%d",&p[i].x,&p[i].y);
}
for (int i=1;i<=k;i++)
{
dp[i]=LINF;
}
dp[0]=0;
for (int i=1;i<=k;i++)
{
for (int j=1;j<=m;j++)
{
if(p[j].x>i) continue;
dp[i]=min(dp[i],dp[i-p[j].x]+sum[i]-sum[i-p[j].x+p[j].y]);
}
dp[i]=min(dp[i],dp[i-1]+a[i]);
}
printf("%lld\n",dp[k]);
return 0;
}