QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#162306 | #2556. Yet Another Interval Graph Problem | black_ice | WA | 1ms | 3744kb | C++14 | 2.2kb | 2023-09-03 09:31:23 | 2023-09-03 09:31:24 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
const int N = 2510,M = 5e6 + 10,INF = 1e9;
int T,n,m;
struct Node
{
int l,r,w;
bool operator<(const Node & W) const
{
return r < W.r;
}
};
int f[N];
priority_queue<int,vector<int>,greater<int>> heap;
vector<Node> nodes;
vector<int> tmp;
void solve()
{
cin >> n >> m;
int tot = 0;
for(int i = 1;i <= n;i++)
{
int l,r,w;
cin >> l >> r >> w;
nodes.push_back({l,r,w});
tmp.push_back(l);
tmp.push_back(r);
tot += w;
}
sort(tmp.begin(),tmp.end());
tmp.erase(unique(tmp.begin(),tmp.end()),tmp.end());
for(int i = 0;i < n;i++)
{
auto &cur = nodes[i];
int posl = lower_bound(tmp.begin(), tmp.end(), cur.l) - tmp.begin() + 1;
int posr = lower_bound(tmp.begin(), tmp.end(), cur.r) - tmp.begin() + 1;
cur.l = posl,cur.r = posr;
}
sort(nodes.begin(),nodes.end());
nodes.push_back({-INF,INF,0});
for(int i = 0;i <= n;i++)
{
int sum = 0,tmpl = 0;
if(i) tmpl = nodes[i - 1].l;
while(heap.size()) heap.pop();
for(int j = i - 1;j >= 0;j--)
{
if(nodes[j].r >= tmpl)
{
if(heap.size() < m)
{
heap.push(nodes[j].w);
sum += nodes[j].w;
}
else if(nodes[j].w > heap.top())
{
sum -= heap.top();
heap.pop();
sum += nodes[j].w;
heap.push(nodes[j].w);
}
tmpl = min(tmpl,nodes[j].l);
f[i + 1] = max(f[i + 1],f[j] + sum);
}
else{
f[i + 1] = max(f[i + 1],f[j + 1] + sum + nodes[j].w);
break;
}
}
}
// for(int i = 1;i <= n + 1;i++)
// {
// cout << f[i] << ' ';
// }
// cout << endl;
cout << tot - f[n + 1] << endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
T = 1;
while(T--)
{
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3744kb
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: 1ms
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'