#include<bits/stdc++.h>
#include "closing.h"
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
int max_score(int N,int X,int Y,ll K,vector<int>U,vector<int>V,vector<int>W){
if(X>Y) swap(X,Y);
vector<pair<int,int>>adj[N];
for(int i=0;i<N-1;i++){
adj[U[i]].pb({V[i],W[i]});
adj[V[i]].pb({U[i],W[i]});
}
ll D[N];
D[0]=0;
for(int i=1;i<N;i++){
for(auto [j,w]:adj[i]){
if(j==i-1){
D[i]=D[i-1]+w;
}
}
}
function <ll(int,int)> calc=[&](int i,int j){
if(i>j) swap(i,j);
return D[j]-D[i];
};
// check all interval that is reacheble from both
vector<ll>v;
int ans=0;
for(int l=0;l<N;l++){
for(int r=l;r<N;r++){
if(r<X||l>Y) continue;//not possible
ll total=0;
int cnt=0;
for(int i=l;i<=r;i++){
total+=max(calc(i,X),calc(i,Y));
cnt+=2;
}
for(int i=X;i<l;i++){
total+=calc(i,X);
cnt++;
}
for(int i=Y;i>=r;i--){
total+=calc(i,Y);
cnt++;
}
if(total>K){
continue;
}
for(int i=0;i<min(X,l)-1;i++){
v.pb(calc(X,i));
}
for(int i=max(r,Y)+1;i<N;i++){
v.pb(calc(Y,i));
}
sort(all(v));
for(int i=0;i<v.size();i++){
if(total+v[i]<=K){
total+=v[i];
cnt++;
}
}
ans=max(ans,cnt);
v.clear();
}
}
for(int i=0;i<N;i++){
v.pb(min(calc(i,X),calc(i,Y)));
}
sort(all(v));
int cnt=0;
ll total=0;
for(int i=0;i<N;i++){
if(total+v[i]<=K){
total+=v[i];
cnt++;
}
}
ans=max(ans,cnt);
return ans;
}
Compilation message
closing.cpp: In function 'int max_score(int, int, int, long long int, std::vector<int>, std::vector<int>, std::vector<int>)':
closing.cpp:63:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
63 | for(int i=0;i<v.size();i++){
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1067 ms |
20936 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '3', found: '4' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '3', found: '4' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '3', found: '4' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '3', found: '4' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '3', found: '4' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '3', found: '4' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '3', found: '4' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '3', found: '4' |
3 |
Halted |
0 ms |
0 KB |
- |