제출 #121297

#제출 시각아이디문제언어결과실행 시간메모리
121297PlurmRoller Coaster Railroad (IOI16_railroad)C++11
0 / 100
90 ms7540 KiB
#include "railroad.h" #include <bits/stdc++.h> using namespace std; bool cmpf(pair<int,int> x,pair<int,int> y){ return x.second < y.second; } int prefmin[200005]; int sufmin[200005]; long long plan_roller_coaster(vector<int> s, vector<int> t) { int n = (int) s.size(); vector<pair<int,int> > com; for(int i = 0; i < n; i++){ com.push_back(make_pair(s[i],t[i])); } sort(com.begin(), com.end(), cmpf); long long ans = 0ll; for(int i = 0; i < n; i++){ ans += t[i]; ans -= s[i]; } prefmin[0] = s[0]; for(int i = 1; i < n; i++){ prefmin[i] = min(prefmin[i-1], s[i]); } sufmin[n-1] = s[n-1]; for(int i = n-2; i >= 0; i--){ sufmin[i] = min(sufmin[i+1], s[i]); } ans = min(ans, ans - t[0] + sufmin[1]); for(int i = 1; i < n; i++){ ans = min(ans, ans - t[i] + min(prefmin[i-1], sufmin[i+1])); } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...