Advertisement
Dmaxiya

破译密码 参考代码

Apr 6th, 2025 (edited)
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long LL;
  5. const int maxn = 1000 + 100;
  6. struct Node {
  7.     int a, b;
  8. };
  9.  
  10. bool operator<(const Node &a, const Node &b) {
  11.     return max(a.a + a.b, a.a + b.a) + b.b < max(b.a + b.b, b.a + a.a) + a.b;
  12. }
  13.  
  14. int n, ta, ans;
  15. Node node[maxn];
  16.  
  17. int main() {
  18. #ifdef ExRoc
  19.     freopen("test.txt", "r", stdin);
  20. #endif // ExRoc
  21.     ios::sync_with_stdio(false);
  22.  
  23.     cin >> n;
  24.     for (int i = 0; i < n; ++i) {
  25.         cin >> node[i].a;
  26.     }
  27.     for (int i = 0; i < n; ++i) {
  28.         cin >> node[i].b;
  29.     }
  30.     sort(node, node + n);
  31.     for (int i = 0; i < n; ++i) {
  32.         ta += node[i].a;
  33.         ans = max(ans, ta) + node[i].b;
  34.     }
  35.     cout << ans << endl;
  36.  
  37.     return 0;
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement