#include <bits/stdc++.h>
using namespace std;
const int INF = -1e9;
int maximumTotalWeight(int k, int n, int m, vector<pair<int,int>>& clusters) {
// Initialize two DP arrays for current and previous DP state
vector<vector<int>> dpCurrent(n+1, vector<int>(m+1, INF));
vector<vector<int>> dpPrevious(n+1, vector<int>(m+1, INF));
dpPrevious[0][0] = 0; // Base case: no clusters, no elements chosen
// Iterate through all clusters
for(int i = 1; i <= k; i++) {
int weightOfFirstGroup = clusters[i-1].first;
int weightOfSecondGroup = clusters[i-1].second;
for(int x = 0; x <= n; x++) {
for(int y = 0; y <= m; y++) {
// Case 1: Do not choose this cluster
dpCurrent[x][y] = dpPrevious[x][y];
// Case 2: Choose this cluster for group 1
if(x > 0) {
dpCurrent[x][y] = max(dpCurrent[x][y], dpPrevious[x-1][y] + weightOfFirstGroup);
}
// Case 3: Choose this cluster for group 2
if(y > 0) {
dpCurrent[x][y] = max(dpCurrent[x][y], dpPrevious[x][y-1] + weightOfSecondGroup);
}
}
}
// Swap the current and previous states for the next iteration
swap(dpCurrent, dpPrevious);
}
return dpPrevious[n][m];
}
int main() {
int k, n, m; cin >> k >> n >> m;
vector<pair<int,int>> clusters(k);
for(auto& x : clusters) cin >> x.first >> x.second;
cout << maximumTotalWeight(k, n, m, clusters);
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgpjb25zdCBpbnQgSU5GID0gLTFlOTsKaW50IG1heGltdW1Ub3RhbFdlaWdodChpbnQgaywgaW50IG4sIGludCBtLCB2ZWN0b3I8cGFpcjxpbnQsaW50Pj4mIGNsdXN0ZXJzKSB7CiAgICAvLyBJbml0aWFsaXplIHR3byBEUCBhcnJheXMgZm9yIGN1cnJlbnQgYW5kIHByZXZpb3VzIERQIHN0YXRlCiAgICB2ZWN0b3I8dmVjdG9yPGludD4+IGRwQ3VycmVudChuKzEsIHZlY3RvcjxpbnQ+KG0rMSwgSU5GKSk7CiAgICB2ZWN0b3I8dmVjdG9yPGludD4+IGRwUHJldmlvdXMobisxLCB2ZWN0b3I8aW50PihtKzEsIElORikpOwoKICAgIGRwUHJldmlvdXNbMF1bMF0gPSAwOyAvLyBCYXNlIGNhc2U6IG5vIGNsdXN0ZXJzLCBubyBlbGVtZW50cyBjaG9zZW4KICAgIAogICAgLy8gSXRlcmF0ZSB0aHJvdWdoIGFsbCBjbHVzdGVycwogICAgZm9yKGludCBpID0gMTsgaSA8PSBrOyBpKyspIHsKICAgICAgICBpbnQgd2VpZ2h0T2ZGaXJzdEdyb3VwID0gY2x1c3RlcnNbaS0xXS5maXJzdDsKICAgICAgICBpbnQgd2VpZ2h0T2ZTZWNvbmRHcm91cCA9IGNsdXN0ZXJzW2ktMV0uc2Vjb25kOwoKICAgICAgICBmb3IoaW50IHggPSAwOyB4IDw9IG47IHgrKykgewogICAgICAgICAgICBmb3IoaW50IHkgPSAwOyB5IDw9IG07IHkrKykgewogICAgICAgICAgICAgICAgLy8gQ2FzZSAxOiBEbyBub3QgY2hvb3NlIHRoaXMgY2x1c3RlcgogICAgICAgICAgICAgICAgZHBDdXJyZW50W3hdW3ldID0gZHBQcmV2aW91c1t4XVt5XTsKCiAgICAgICAgICAgICAgICAvLyBDYXNlIDI6IENob29zZSB0aGlzIGNsdXN0ZXIgZm9yIGdyb3VwIDEKICAgICAgICAgICAgICAgIGlmKHggPiAwKSB7CiAgICAgICAgICAgICAgICAgICAgZHBDdXJyZW50W3hdW3ldID0gbWF4KGRwQ3VycmVudFt4XVt5XSwgZHBQcmV2aW91c1t4LTFdW3ldICsgd2VpZ2h0T2ZGaXJzdEdyb3VwKTsKICAgICAgICAgICAgICAgIH0KCiAgICAgICAgICAgICAgICAvLyBDYXNlIDM6IENob29zZSB0aGlzIGNsdXN0ZXIgZm9yIGdyb3VwIDIKICAgICAgICAgICAgICAgIGlmKHkgPiAwKSB7CiAgICAgICAgICAgICAgICAgICAgZHBDdXJyZW50W3hdW3ldID0gbWF4KGRwQ3VycmVudFt4XV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