救命!还能怎么优化?
查看原帖
救命!还能怎么优化?
821841
CH_wuji楼主2024/8/3 18:50
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
#define STA stack<int>
#define VEC vector<int>
#define QUE deque<int>
#define LIST list<int>
#define MP map<int,int>
#define ST set<int>
#define S string
#define C char
#define F float
#define D double
#define I int
#define CON continue
#define BR break
#define fi first
#define se second
#define LLL __int128
using namespace std;
const int N = 1e5 + 9;
struct node {
	int f, st, ti;
} a[N];
I main() {
//	ios::sync_with_stdio(false);
//	cin.tie(0);
//	cout.tie(0);
	int n, ans = 0, ct = 0;
	scanf("%d",&n);
	for (int i = 1; i <= n; ++i)
		scanf("%d%d%d",&a[i].f,&a[i].st,&a[i].ti);
	for (int i = 1; i <= n; ++i) {
		if (a[i].f == 1) {
			if (!ct) {
				ans += a[i].st;
				continue;
			}
			bool fl = false;
			for (int j = 1; j < i; ++j) {
				if (a[j].f == 0 && a[i].ti - a[j].ti <= 45 && a[i].st <= a[j].st) {
					a[j].f = 1;
					fl = true;
					break;
				}
			}
			if (!fl)ans += a[i].st; 
			
		} else {
			ans += a[i].st;
			ct++;
		}
	//	cout << ans << endl;
	}
	printf("%d",ans);
	return 0;
}

2024/8/3 18:50
加载中...