提交时间:2025-04-23 20:52:35

运行 ID: 37621

#include <cstdio> #include <iostream> #include <algorithm> using namespace std; int n, a[200010], b[200010]; int main() { // freopen("bamboo.in", "r", stdin); // freopen("bamboo.out", "w", stdout); cin >> n; int ans = 0; for (int i = 1; i <= n; i++) { cin >> a[i] >> b[i]; if (b[i] < a[i] - b[i]) b[i] = a[i] - b[i]; ans = max(ans, a[i]); } int mx_p = 0, mxx_p = 0; for (int i = 1; i <= n; i++) if (b[i] > b[mx_p]) mx_p = i; for (int i = 1; i <= n; i++) if (b[i] > b[mxx_p]) if (i != mx_p) mxx_p = i; cout << max(ans, b[mx_p] + b[mxx_p]) << endl; fclose(stdin); fclose(stdout); return 0; }