new file: 40.cpp

This commit is contained in:
2026-08-18 10:05:59 +08:00
parent b420b2bb5d
commit 17db00d583
+27
View File
@@ -0,0 +1,27 @@
// 125
#include <bits/stdc++.h>
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;
}