Submission #958259

#TimeUsernameProblemLanguageResultExecution timeMemory
958259MilosMilutinovic만두 (JOI14_ho_t2)C++14
100 / 100
101 ms756 KiB
#include<bits/stdc++.h> #define pb push_back #define fi first #define se second #define mp make_pair using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef long double ld; template <typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;} template <typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;} ll readint(){ ll x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int n,m; int c[10005],a[505],b[505]; int dpa[20005],dpb[20005]; int main(){ n=readint(); m=readint(); for(int i=1;i<=n;i++) c[i]=readint(); for(int i=1;i<=m;i++) a[i]=readint(),b[i]=readint(); for(int i=1;i<=n;i++){ for(int j=n;j>=0;j--) chkmax(dpa[j+1],dpa[j]+c[i]); } for(int i=0;i<=20000;i++) dpb[i]=1e9; dpb[0]=0; for(int i=1;i<=m;i++){ for(int j=20000-a[i];j>=0;j--) chkmin(dpb[j+a[i]],dpb[j]+b[i]); } int ans=0,mx=0; for(int i=0;i<=20000;i++){ chkmax(mx,dpa[i]); chkmax(ans,mx-dpb[i]); } printf("%d\n",ans); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...