闫式dp分析法
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int N = 1010;
int f[N][N] , w[N] , v[N];
int n , m , k;
int main() {
cin >> n >> m >> k;
for (int i = 1 ; i <= k ; i ++ ) {
int V1 , V2;
cin >> V1 >> V2;
for (int j = n ; j >= V1 ; j -- )
for (int z = m - 1 ; z >= V2 ; z -- ) f[j][z] = max(f[j][z] , f[j - V1][z - V2] + 1);
}
cout << f[n][m - 1] << ' ';
int k = m;
while (k > 0 && f[n][k - 1] == f[n][m - 1]) k --;
cout << m - k;
}