Skip to content

Instantly share code, notes, and snippets.

@asi1024
Created August 28, 2015 19:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asi1024/5308780ac37a5d7b96c9 to your computer and use it in GitHub Desktop.
Save asi1024/5308780ac37a5d7b96c9 to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
ll INF = 1e16;
int N, R[256], S[256];
ll memo[160][50000];
bool flag[160][50000];
ll dp(int n, int s) {
if (n == N) return s <= 0 ? -INF : INF;
if (flag[n][s+25000]) return memo[n][s+25000];
ll a = -dp(n+1, -s+S[n]+1) - R[n] + 1;
ll b = dp(n+1, s+S[n]) + R[n] + 1;
flag[n][s+25000] = true;
return memo[n][s+25000] = min(a, max(1LL, b));
}
int main() {
int A, B;
cin >> N >> A >> B;
ll sum = 0;
REP(i,N) {
cin >> R[i] >> S[i];
sum += S[i];
}
for (int i = 0;; ++i) {
if (dp(0, sum - 2 * i) <= A - B) {
cout << sum - i << " " << i << endl;
return 0;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment