-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1106.cpp
More file actions
33 lines (28 loc) · 781 Bytes
/
1106.cpp
File metadata and controls
33 lines (28 loc) · 781 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int dp[1000 * 100 +1]; // 비용 i일때 최대 고객
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int C, N;
cin >> C >> N;
vector<pair<int, int>> v(N+1);
for(int i = 1; i <= N; i++){
cin >> v[i].first >> v[i].second;
}
for(int i = 1; i <= 100000; i++){
for(int j = 1; j <= N; j++){
if(i % v[j].first == 0){
dp[i] = max(dp[i], v[j].second * (i / v[j].first));
}
if(i - v[j].first >= 0){
dp[i] = max(dp[i], dp[i-v[j].first] + v[j].second);
}
}
if(C <= dp[i]){
cout << i;
return 0;
}
}
}