#include "closing.h"
#include <bits/stdc++.h>
using namespace std;
long long pos[200003];
long long cost1[200003];
long long cost2[200003];
long long pfx1[200003];
long long pfx2[200003];
long long maxroll[200003]; //maxroll[i]=a <==> de "tra no" 1 khoang toi da =a, can rollback it nhat i vi tri tu loai 1 xuong loai 0
long long minupd[200003]; //minupt[i]=k <==> voi 1 budget<=i; upgrade duoc toi da k vi tri tu loai 1 len loai 2
struct cus{
bool operator()(const long long &x, const long long &y){
return x>y;
}
};
int max_score(int N, int X, int Y, long long K, std::vector<int> U, std::vector<int> V, std::vector<int> W)
{
int n=N;
int x=X;
int y=Y;
long long k=K;
for(int i=0;i<n-1;i++){
cin>>U[i]>>V[i]>>W[i];
pos[i+1]=pos[i]+W[i];
}
for(int i=0;i<n;i++){
cost1[i]=min(abs(pos[i]-pos[x]),abs(pos[i]-pos[y]));
cost2[i]=max(abs(pos[i]-pos[x]),abs(pos[i]-pos[y]))-cost1[i];
pfx1[i+1]=pfx1[i]+cost1[i];
}
priority_queue <long long> pq;
long long mcost=k;
//case 1: chi nang cap cac dinh len toi da 1
for(int i=0;i<n;i++){
pq.push(-cost1[i]);
}
long long ans=0;
while(mcost>0&&!pq.empty()){
mcost+=pq.top();
ans++;
pq.pop();
}
if(mcost<0){
ans--;
}
long long tans=0;
tans=max(tans,ans);
while(!pq.empty()){
pq.pop();
}
///case 2: ton tai dinh duoc nang cap len 2 => tat ca cac diem trong doan (l,r) deu da duoc nang cap len loai 1. sau do tham nhu tren
mcost=k-(pfx1[y+1]-pfx1[x]);
if(mcost>0){
ans=y-x+1;
for(int i=0;i<n;i++){
pq.push(-cost2[i]);
}
for(int i=0;i<n;i++){
if(i<x||i>y){
pq.push(-cost1[i]);
}
}
while(!pq.empty()&&mcost>0){
ans++;
mcost+=pq.top();
pq.pop();
}
if(mcost<0){
ans--;
}
tans=max(tans,ans);
}
return tans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
64 ms |
13512 KB |
1st lines differ - on the 1st token, expected: '451', found: '371' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2392 KB |
1st lines differ - on the 1st token, expected: '30', found: '35' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2392 KB |
1st lines differ - on the 1st token, expected: '30', found: '35' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2392 KB |
1st lines differ - on the 1st token, expected: '30', found: '35' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |