# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
920047 | Aiperiii | Palembang Bridges (APIO15_bridge) | C++14 | 96 ms | 9152 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define int long long
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
signed main(){
ios_base::sync_with_stdio();
cin.tie(0);cout.tie(0);
int k,n;
cin>>k>>n;
vector <char> t1(n),t2(n);
vector <int> x(n),y(n);
for(int i=0;i<n;i++){
cin>>t1[i]>>x[i]>>t2[i]>>y[i];
}
int ans=0,sum=0;
vector <int> v,pr;
for(int j=0;j<n;j++){
if(t1[j]==t2[j])ans+=abs(x[j]-y[j]);
else{
ans++;
v.pb(x[j]);v.pb(y[j]);
}
}
sort(all(v));
for(int i=0;i<v.size();i++){
sum+=v[i];
pr.pb(sum);
}
int mn=1e18;
for(int i=0;i<n;i++){
int res=ans;
auto it=upper_bound(all(v),x[i]);
if(it!=v.end()){
int pos=it-v.begin();
int cnt=v.size()-pos;
pos--;
int d=pr.back();
if(pos>=0)d-=pr[pos];
res+=d-cnt*x[i];
}
if(it!=v.begin()){
it--;
int pos=it-v.begin();
int d=pr[pos];pos++;
res+=pos*x[i]-d;
}
mn=min(mn,res);
}
cout<<mn<<"\n";
}
/*
1 5
B 0 A 4
B 1 B 3
A 5 B 7
B 2 A 6
B 1 A 7
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |