QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#507322#2556. Yet Another Interval Graph ProblemGenshinImpactsFaultWA 0ms3768kbC++141.3kb2024-08-06 16:09:422024-08-06 16:09:44

Judging History

你现在查看的是最新测评结果

  • [2024-08-06 16:09:44]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3768kb
  • [2024-08-06 16:09:42]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 5010;
int n, m;
struct P {
	int l, r, w;
}; P a[N];
vector<int> p; int lp;
ll f[N];
multiset<int> st;
vector<int> veclb[N];

int main() {
	ios::sync_with_stdio(0); cin.tie(nullptr);
	cin >> n >> m;
	p.reserve(2 * n);
	for(int i = 1; i <= n; i++) {
		cin >> a[i].l >> a[i].r >> a[i].w;
		p.push_back(a[i].l), p.reserve(a[i].r);
	}
	sort(p.begin(), p.end()), p.resize(unique(p.begin(), p.end()) - p.begin());
	lp = p.size();
	for(int i = 1; i <= n; i++) {
		a[i].l = lower_bound(p.begin(), p.end(), a[i].l) - p.begin() + 1;
		a[i].r = lower_bound(p.begin(), p.end(), a[i].r) - p.begin() + 1;
	}
	sort(a + 1, a + n + 1, [](P x, P y) { return x.r < y.r; });
	f[0] = 1;
	int pos = 0;
	for(int i = 1; i <= lp; i++) {
		for(; pos < n && a[pos + 1].r <= i;) {
			++pos;
			veclb[a[pos + 1].l].push_back(a[pos + 1].w);
		}
		ll sum = 0;
		f[i] = f[i - 1];
		st.clear();
		for(int j = i; j; j--) {
			for(auto v : veclb[j]) {
				sum += v;
				st.insert(v);
				for(; st.size() > m;) {
					sum -= *st.begin();
					st.erase(st.begin());
				}
			}
			f[i] = max(f[i], f[j - 1] + sum);
		}
	}
	ll ans = 0;
	for(int i = 1; i <= n; i++) ans += a[i].w;
	cout << ans - f[lp] << "\n";
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3768kb

input:

5 2
1 4 1
3 6 2
5 8 5
7 10 2
9 12 1

output:

3

result:

ok single line: '3'

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3684kb

input:

5 1
2 6 5
4 6 2
8 8 5
1 3 4
6 8 7

output:

10

result:

wrong answer 1st lines differ - expected: '12', found: '10'