-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10982.cpp
More file actions
44 lines (35 loc) · 875 Bytes
/
10982.cpp
File metadata and controls
44 lines (35 loc) · 875 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
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
#define MAXN 100050
int T, INF=1234567891;
int opt[MAXN];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin >> T;
for(int i=0 ; i<T ; i++){
int N;
cin >> N;
fill(opt, opt+100050, INF);
opt[0]=0;
while(N--){
int time_a, time_b;
cin >> time_a >> time_b;
for(int j=100000 ; j>=0 ; j--){
if(j < time_a){
opt[j] = opt[j] + time_b;
} else {
opt[j] = min(opt[j-time_a], opt[j]+time_b);
}
}
}
int ans=INF;
for(int k=0 ; k<=100000 ; k++){
ans = min(ans, max(k,opt[k]));
}
cout << ans << '\n';
}
}