Submission #794825

#TimeUsernameProblemLanguageResultExecution timeMemory
794825MODDIPalembang Bridges (APIO15_bridge)C++17
22 / 100
36 ms5908 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair typedef long long ll; typedef pair<long long, long long> pll; typedef pair<int,int> pii; typedef vector<int> vi; typedef vector<long long> vl; int k, n; ll ans = 0; vl ord; int main(){ ios_base::sync_with_stdio(false); cin>>k>>n; for(int i = 0; i < n; i++){ char side1, side2; ll p1, p2; cin>>side1>>p1>>side2>>p2; if(side1 == side2){ ans += abs(p1 - p2); } else { ord.pb(p1); ord.pb(p2); } } sort(ord.begin(), ord.end()); int sz = (int)ord.size(); if(ord.size() > 0){ ll pref[sz]; pref[0] = ord[0]; for(int i = 1; i < sz; i++) pref[i] = pref[i-1] + ord[i]; ll best = 1e18; for(int i = 0; i < sz; i++){ ll here = ans; if(i+1 < sz) { here += pref[sz-1]; here -= pref[i]; here -= (sz - 1 - i) * ord[i]; } if(i){ here -= pref[i-1]; here += i * ord[i]; } here += (int)ord.size()/2; best = min(best, here); } cout<<best<<endl; return 0; } cout<<ans<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...