-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathA_Download_More_RAM.cpp
More file actions
55 lines (53 loc) · 1.04 KB
/
A_Download_More_RAM.cpp
File metadata and controls
55 lines (53 loc) · 1.04 KB
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
45
46
47
48
49
50
51
52
53
54
55
#include<bits/stdc++.h>
#include<vector>
#include <algorithm>
#define ll long long
#define lld long double
#define lli long long int
#define sza(x) ((int)x.size())
#define all(a) (a).begin(),(a).end()
#define vll vector<long long int>
#define pb push_back
#define mp make_pair
#define se second
#define fi first
using namespace std;
bool compare(ll a , ll b)
{
if(a>b) return true;
return false;
}
void solve() {
ll n,k;
vector<pair<ll ,ll>> ram;
cin>>n>>k;
ll a[n] , b[n];
for(ll i=0; i<n;i++){
cin>>a[i];
}
for(ll i=0; i<n;i++){
cin>>b[i];
}
for(ll i=0; i<n;i++){
ram.pb(mp(a[i] , b[i]));
}
sort(all(ram));
for(ll i=0; i<n; i++){
if(ram[i].first <= k){
k+= ram[i].second;
}
else{
break;
}
}
cout<<k<<endl;
}
int main() {
ios_base::sync_with_stdio(false);
int t=1;
cin>>t;
for( int k=1;k<=t;k++){
solve();
}
return 0;
}