Submission #794822

#TimeUsernameProblemLanguageResultExecution timeMemory
794822MODDIPalembang Bridges (APIO15_bridge)C++14
0 / 100
1 ms340 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; int main(){ cin>>k>>n; vl ord; 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(); ll pref[(int)ord.size()]; pref[0] = ord[0]; for(int i = 1; i < (int)ord.size(); 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; }
#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...