Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. // LUNCHBOX
  2.  
  3. #include <iostream>
  4. #include <cstring>
  5. using namespace std;
  6. #include <fstream>
  7. #include <cstdio>
  8. #include <cmath>
  9. #include <ctime>
  10. #include <vector>
  11. #include <stack>
  12. #include <queue>
  13. #include <functional>
  14. #include <deque>
  15. #include <numeric>
  16. #include <set>
  17. #include <climits>
  18. #include <utility>
  19. #include <map>
  20. #include <algorithm>
  21. #define INF 987654321
  22. #define MOD 1000000007
  23. typedef long long ll;
  24. typedef unsigned long long ull;
  25. inline int max( int x, int y ){ return x > y ? x : y ; }
  26. inline int min( int x, int y ){ return x < y ? x : y ; }
  27. inline ll max( ll x, ll y ){ return x > y ? x : y ; }
  28. inline ll min( ll x, ll y ){ return x < y ? x : y ; }
  29. inline ull max( ull x, ull y ){ return x > y ? x : y ; }
  30. inline ull min( ull x, ull y ){ return x < y ? x : y ; }
  31.  
  32.  
  33. int main(){
  34.  
  35. int TC, N, eat;
  36. int ans = 0;
  37.  
  38. scanf("%d", &TC);
  39. while( TC-- ){
  40.  
  41. scanf("%d", &N);
  42. vector<int> Micro(N);
  43. vector<int> Eat(N);
  44. ans = 0;
  45.  
  46. for( int i=0; i<N; ++i ){
  47. scanf("%d", &Micro[i]);
  48. }
  49. for( int i=0; i<N; ++i ){
  50. scanf("%d", &Eat[i]);
  51. }
  52.  
  53. vector<pair<int, int> >order;
  54. for( int i=0; i<N; ++i ){
  55. order.push_back(make_pair( -Eat[i], i ));
  56. }
  57. sort(order.begin(), order.end());
  58.  
  59. eat = 0;
  60. ans = 0;
  61. for( int i=0; i<N; ++i ){
  62. eat += Micro[order[i].second];
  63. ans = max( ans, eat+Eat[order[i].second] );
  64. }
  65. printf("%d\n", ans);
  66. }
  67. return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement