- 2023tyoi0292 的博客
三点三线 II
- 2024-5-3 22:53:57 @
三点三线 II
谢谢大样例,思路:一看就知道是贪心,不过要用结构体,先排个序,按照从小到大排
十年OI一场空,不开long long见祖宗
AC code
#include <iostream>
#include <cstdio>
#include <algorithm>
#define ll long long
using namespace std;
struct node {
ll w, y, id;
}a[100005];
bool cmp(node x, node y) {
return x.w - x.y < y.w - y.y;
}
int main() {
freopen("linedotII.in", "r", stdin);
freopen("linedotII.out", "w", stdout);
int n;
cin >> n;
for(int i = 1; i <= n; i++) {
cin >> a[i].w >> a[i].y;
a[i].id = i;
}
sort(a + 1, a + n + 1, cmp);
ll sum = 0, maxn = -1e18;
for(int i = 1; i <= n; i++) {
maxn = max(maxn, sum - a[i].y);
sum += a[i].w;
}
cout << maxn << endl;
for(int i = 1; i <= n; i++) {
cout << a[i].id << ' ';
}
return 0;
}