From 17db00d5831bf59a605c63f6815c8784ca5420b9 Mon Sep 17 00:00:00 2001 From: hanyixuanten Date: Tue, 18 Aug 2026 10:05:59 +0800 Subject: [PATCH] new file: 40.cpp --- 40.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 40.cpp diff --git a/40.cpp b/40.cpp new file mode 100644 index 0000000..6b0336b --- /dev/null +++ b/40.cpp @@ -0,0 +1,27 @@ +// 125 +#include +using namespace std; +struct node +{ + int w, s; + const bool operator<(const node &x) const + { + return w + s < x.w + x.s; + } +} a[50005]; +int main() +{ + int n; + scanf("%d", &n); + for (int i = 1; i <= n; ++i) + scanf("%d%d", &a[i].w, &a[i].s); + sort(a + 1, a + 1 + n); + int tot = 0, ans = -2147483648; + for (int i = 1; i <= n; ++i) + { + ans = max(ans, tot - a[i].s); + tot += a[i].w; + } + printf("%d\n", ans); + return 0; +} \ No newline at end of file