1
+ #include < bits/stdc++.h>
2
+
3
+ using namespace std ;
4
+ typedef long long ll;
5
+
6
+ void solve () {
7
+ int n;
8
+ cin >> n;
9
+
10
+ vector<int > t1 (n), t2 (n);
11
+ for (int i = 0 ; i < n; ++i) {
12
+ cin >> t1[i];
13
+ }
14
+ for (int i = 0 ; i < n; ++i) {
15
+ cin >> t2[i];
16
+ }
17
+
18
+ vector<pair<int , int > > gifts (n);
19
+ for (int i = 0 ; i < n; ++i) {
20
+ gifts[i] = {t1[i], t2[i]};
21
+ }
22
+
23
+ vector<pair<int , int > > groupA, groupB;
24
+ for (const auto &gift: gifts) {
25
+ if (gift.first <= gift.second ) {
26
+ groupA.push_back (gift);
27
+ } else {
28
+ groupB.push_back (gift);
29
+ }
30
+ }
31
+
32
+ sort (groupA.begin (), groupA.end (),
33
+ [](const pair<int , int > &a, const pair<int , int > &b) {
34
+ return a.first < b.first ;
35
+ });
36
+ sort (groupB.begin (), groupB.end (),
37
+ [](const pair<int , int > &a, const pair<int , int > &b) {
38
+ return a.second > b.second ;
39
+ });
40
+
41
+ // 合并组A和组B
42
+ vector<pair<int , int > > sorted_gifts;
43
+ sorted_gifts.insert (sorted_gifts.end (), groupA.begin (), groupA.end ());
44
+ sorted_gifts.insert (sorted_gifts.end (), groupB.begin (), groupB.end ());
45
+
46
+ // 计算总时间
47
+ int sum_t1 = 0 ;
48
+ for (const auto &gift: sorted_gifts) {
49
+ sum_t1 += gift.first ;
50
+ }
51
+
52
+ int santa_end = 0 ;
53
+ int current_pack_time = 0 ;
54
+ for (const auto &gift: sorted_gifts) {
55
+ current_pack_time += gift.first ;
56
+ int start = max (current_pack_time, santa_end);
57
+ santa_end = start + gift.second ;
58
+ }
59
+
60
+ int total_time = max (sum_t1, santa_end);
61
+ cout << total_time << endl;
62
+ }
63
+
64
+ signed main () {
65
+ ios::sync_with_stdio (false );
66
+ cin.tie (nullptr );
67
+
68
+ int t = 1 ;
69
+ // cin >> t;
70
+ while (t--) solve ();
71
+ return 0 ;
72
+ }
73
+
74
+ /*
75
+ 破译密码【算法赛】
76
+ */
0 commit comments