Skip to content

Instantly share code, notes, and snippets.

@tjkendev
Last active May 12, 2016 04:10
Show Gist options
  • Save tjkendev/b3038713abded218c190 to your computer and use it in GitHub Desktop.
Save tjkendev/b3038713abded218c190 to your computer and use it in GitHub Desktop.
Code Festival 2015 チーム対抗リレー - submit
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<cmath>
using namespace std;
#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define absd(x) (x<0?-(x):x)
#define pow2(x) ((x)*(x))
#define rep(i,n) for(int i=0; i<n; ++i)
#define repr(i,n) for(int i=n-1; i>=0; --i)
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define replr(i,s,n) for(int i=n; i>=s; --i)
#define repf(i,s,n,j) for(int i=s; i<=n; i+=j)
#define repe(e,obj) for(auto e : obj)
#define SP << " " <<
#define COL << " : " <<
#define COM << ", " <<
#define ARR << " -> " <<
#define PNT(STR) cout << STR << endl
#define POS(X,Y) "(" << X << ", " << Y << ")"
#define DEB(A) " (" << #A << ") " << A
#define DEBREP(i,n,val) for(int i=0; i<n; ++i) cout << val << " "; cout << endl
#define ALL(V) (V).begin(), (V).end()
#define INF 1000000007
#define INFLL 10000000000000000007LL
#define EPS 1e-9
typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
//typedef pair<ll, ll> P;
typedef pair<P, int> PI;
typedef pair<int, P> IP;
typedef pair<P, P> PP;
typedef priority_queue<P, vector<P>, greater<P> > pvqueue;
#define N 10008
#define M 1003
#define L 10009
ll dp[M][L];
int main() {
ll n, m, l;
ll va[N], ea[N];
ll vb[M], eb[M];
cin >> n >> m >> l;
rep(i, n) cin >> va[i] >> ea[i];
rep(i, m) cin >> vb[i] >> eb[i];
rep(i, M) rep(j, L) dp[i][j] = 0;
rep(i, m) {
rep(j, l+1) dp[i+1][j] = dp[i][j];
rep(j, l+1) {
if(j-vb[i]>=0) {
dp[i+1][j] = maxd(dp[i+1][j], dp[i][j-vb[i]]+eb[i]);
}
}
}
ll ans = 0;
rep(i, n) {
if(l-va[i] >= 0) {
ans = maxd(ans, dp[m][l-va[i]] + ea[i]);
}
}
cout << ans << endl;
return 0;
}
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<cmath>
using namespace std;
#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define absd(x) (x<0?-(x):x)
#define pow2(x) ((x)*(x))
#define rep(i,n) for(int i=0; i<n; ++i)
#define repr(i,n) for(int i=n-1; i>=0; --i)
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define replr(i,s,n) for(int i=n; i>=s; --i)
#define repf(i,s,n,j) for(int i=s; i<=n; i+=j)
#define repe(e,obj) for(auto e : obj)
#define SP << " " <<
#define COL << " : " <<
#define COM << ", " <<
#define ARR << " -> " <<
#define PNT(STR) cout << STR << endl
#define POS(X,Y) "(" << X << ", " << Y << ")"
#define DEB(A) " (" << #A << ") " << A
#define DEBREP(i,n,val) for(int i=0; i<n; ++i) cout << val << " "; cout << endl
#define ALL(V) (V).begin(), (V).end()
#define INF 1000000007
#define INFLL 10000000000000000007LL
#define EPS 1e-9
typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
//typedef pair<ll, ll> P;
typedef pair<P, int> PI;
typedef pair<int, P> IP;
typedef pair<P, P> PP;
typedef priority_queue<P, vector<P>, greater<P> > pvqueue;
#define N 10008
#define M 1003
#define L 10009
// ここのM,Lが逆だった
ll dp[M][L];
int main() {
ll n, m, l;
ll va[N], ea[N];
ll vb[M], eb[M];
cin >> n >> m >> l;
rep(i, n) cin >> va[i] >> ea[i];
rep(i, m) cin >> vb[i] >> eb[i];
// ここのi,jが逆だった
rep(i, M) rep(j, L) dp[i][j] = 0;
rep(i, m) {
rep(j, l+1) {
if(j-vb[i]>=0) {
dp[i+1][j] = maxd(dp[i][j], dp[i][j-vb[i]]+eb[i]);
} else {
// この場合分けを忘れてたorz...
dp[i+1][j] = dp[i][j];
}
}
}
ll ans = 0;
rep(i, n) {
if(l-va[i] >= 0) {
ans = maxd(ans, dp[m][l-va[i]] + ea[i]);
}
}
cout << ans << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment