# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
18154 | comet | Schools (IZhO13_school) | C++98 | 85 ms | 41016 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
int N,M,S;
ll d[501][101][101];
ll a[501],b[501];
ll max(ll x,ll y){
return x>y?x:y;
}
ll max(ll x,ll y,ll z){
return max(x,max(y,z));
}
ll f(int p,int x,int y){
if(p==N){
if(x<M||y<S)return -1e18;
return 0;
}
ll& ret=d[p][x][y];
if(~ret)return ret;
if(x==M&&y==S)return ret=f(p+1,x,y);
if(x==M)return ret=max(f(p+1,x,y),f(p+1,x,y+1)+b[y]);
if(y==S)return ret=max(f(p+1,x,y),f(p+1,x+1,y)+a[x]);
return ret=max(f(p+1,x,y),f(p+1,x+1,y)+a[x],f(p+1,x,y+1)+b[y]);
}
int main(){
scanf("%d%d%d",&N,&M,&S);
for(int i=0;i<N;i++){
scanf("%lld%lld\n",&a[i],&b[i]);
}
memset(d,-1,sizeof(d));
printf("%lld\n",f(0,0,0));
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |