rt,被 Hack WA100。贪心,O(n)。
/*
Code by swate114514.
*/
#include <bits/stdc++.h>
using namespace std;
using PII = pair<int, int>;
using i32 = int32_t;
using i64 = int64_t;
using ui32 = uint32_t;
using ui64 = uint64_t;
int t;
namespace swate {
const int N = 1e5 + 5;
int b[N], s[N];
int n;
int ans1 = 0, ans2 = 0, mn = INT_MAX;
inline void init() {
}
inline void solve() {
cin >> n;
for (int i = 1; i <= n; ++i)
cin >> b[i];
for (int i = 1; i <= n; ++i)
cin >> s[i], ans2 += s[i], mn = min(mn, max(0, b[i] - s[i]));
for (int i = 2, v, w; i <= n; ++i)
cin >> v >> w, ans1 += w * 2;
cout << ans1 << ' ' << ans2 + mn << '\n';
}
}
// #define Test
i32 main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
#ifdef Test
cin >> t;
#else
t = 1;
#endif
for (int i = 1; i <= t; ++i) {
swate::init();
swate::solve();
}
return 0;
}