关于刚刚【MX-X3-T2】「RiOI-4」消えた夏の夢
查看原帖
关于刚刚【MX-X3-T2】「RiOI-4」消えた夏の夢
725816
Perfect_Youth楼主2024/9/8 18:08

对于这个代码:

#include <bits/stdc++.h>
#define int long long

using namespace std;

const int N = 1e5 + 7;

int n, m, p, op, mx;

vector<int> a;

signed main() {
	scanf ("%lld%lld", &n, &p);
	m = n;
	for (int i = 1; i <= n; i++) {
        int b;
		scanf ("%lld", &b);
        a.insert(upper_bound(a.begin(), a.end(), b), b);
    }
    while (m--) {
        p += a[n - 1];
        mx = max(mx, p);
        op = -a[n - 1];
        a.pop_back();
        a.insert(upper_bound(a.begin(), a.end(), op), op);
    }
	printf ("%lld", mx);
	return 0;
}

O(n2)O(n^2) 跑的飞快。

2024/9/8 18:08
加载中...