Wa on 13 求调
  • 板块CF3B Lorry
  • 楼主Light_Pursuer
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/5/12 18:27
  • 上次更新2024/5/12 20:52:52
查看原帖
Wa on 13 求调
636197
Light_Pursuer楼主2024/5/12 18:27
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5 + 5;
inline int read() {
    int x = 0, f = 1;
	char c = getchar();
    while (!isdigit (c)) {
		if (c == '-') {
			f = -1;
		}
		c = getchar();
	}
    while (isdigit (c)) {
		x = x * 10 + c - '0';
		c = getchar();
	}
    return x * f;
}
struct node{
	int x, id;
}a1[N], a2[N];
bool cmp (node x, node y) {
	return x.x > y.x;
} 
int n, v, ans, sum = -1, cnt1, cnt2, pre1[N], pre2[N];
void solve () {
	int t, p;
	cin >> n >> v;
	for (int i = 1; i <= n; i++) {
		cin >> t >> p;
		if (t == 1) {
			a1[++cnt1] = {p, i};
		} else {
			a2[++cnt2] = {p, i};
		}
	}
	sort (a1 + 1, a1 + cnt1 + 1, cmp);
	sort (a2 + 1, a2 + cnt2 + 1, cmp);
	for (int i = 1; i <= cnt1; i++) {
		pre1[i] = pre1[i - 1] + a1[i].x;
	}
	for (int i = 1; i <= cnt2; i++) {
		pre2[i] = pre2[i - 1] + a2[i].x;
	}
	for (int i = 	0; i * 2 <= n && i <= cnt2; i++) {
		if (v - 2 * i > cnt1) continue;
		int now = pre2[i] + pre1[v - 2 * i];
		if (sum < now) {
			sum = now;
			ans = i;
		}		
	}
	cout << sum << endl;
	for (int i = 1; i <= ans; i++) {
		cout << a2[i].id << ' ';
	}
	for (int i = 1; i <= v - 2 * ans; i++) {
		cout << a1[i].id << ' ';
	}
}
signed main() {
	solve();
	return 0;
}

思路没问题,cf提示:wrong answer Truck size limit exceeded

2024/5/12 18:27
加载中...