度度熊与邪恶大魔王

来源:互联网 发布:赤瞳 喜欢 知乎 编辑:程序博客网 时间:2024/06/10 04:45

传送门

#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>#include <map>#include <algorithm>using namespace std;#define pi acos(-1)#define endl '\n'#define srand() srand(time(0));#define me(x,y) memset(x,y,sizeof(x));#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)#define close() ios::sync_with_stdio(0); cin.tie(0);#define FOR(x,n,i) for(int i=x;i<=n;i++)#define FOr(x,n,i) for(int i=x;i<n;i++)#define W while#define sgn(x) ((x) < 0 ? -1 : (x) > 0)#define bug printf("***********\n");typedef long long LL;const int INF=0x3f3f3f3f;const LL LINF=1e18+7;const int dx[]= {-1,0,1,0,1,-1,-1,1};const int dy[]= {0,1,0,-1,-1,1,-1,1};const int maxn=2005;const int maxx=1e5+100;const double EPS=1e-7;const int mod=998244353;template<class T>inline T min(T a,T b,T c){return min(min(a,b),c);}template<class T>inline T max(T a,T b,T c){return max(max(a,b),c);}template<class T>inline T min(T a,T b,T c,T d){return min(min(a,b),min(c,d));}template<class T>inline T max(T a,T b,T c,T d){return max(max(a,b),max(c,d));}inline LL Scan(){LL Res=0,ch,Flag=0;if((ch=getchar())=='-')Flag=1;else if(ch>='0' && ch<='9')Res=ch-'0';while((ch=getchar())>='0'&&ch<='9')Res=Res*10+ch-'0';return Flag ? -Res : Res;}LL dp[maxn][14];//dp[i][j]为花费 i为血 j为防 LL a[maxx],b[maxx],k[maxn],p[maxn];int main(){//freopen( "in.txt" , "r" , stdin );int n,m;while(~scanf("%d%d",&n,&m)){for(int i=1;i<=n;i++){a[i]=Scan();b[i]=Scan();}for(int i=1;i<=m;i++){k[i]=Scan();p[i]=Scan();}for(int i=0;i<maxn;i++)for(int j=0;j<=10;j++)dp[i][j]=LINF;for(int i=0;i<=10;i++)//防御 {dp[0][i]=0;for(int j=1;j<=m;j++){LL t=p[j]-i;//破防的伤害if(t<=0) continue;for(int p=t;p<=2003;p++){dp[p][i]=min(dp[p-t][i]+k[j],dp[p][i]);}}for(int j=2002;j>=0;j--)//单调性 {dp[j][i]=min(dp[j][i],dp[j+1][i]);}}LL ans=0;for(int i=1;i<=n;i++)ans+=dp[a[i]][b[i]];if(ans>=LINF)puts("-1");else cout<<ans<<endl;}}


原创粉丝点击