Submission #782684

#TimeUsernameProblemLanguageResultExecution timeMemory
782684math_rabbit_1028즐거운 채소 기르기 (JOI14_growing)C++14
30 / 100
1071 ms908 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; int n, arr[303030]; ll lt[303030], rt[303030]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 1; i <= n; i++) cin >> arr[i]; vector<int> v; for (int i = 1; i <= n; i++) { lt[i] = lt[i - 1] + (v.end() - upper_bound(v.begin(), v.end(), arr[i])); v.push_back(arr[i]); sort(v.begin(), v.end()); } v.clear(); for (int i = n; i >= 1; i--) { rt[i] = rt[i + 1] + (v.end() - upper_bound(v.begin(), v.end(), arr[i])); v.push_back(arr[i]); sort(v.begin(), v.end()); } ll ans = 1e18; for (int i = 0; i <= n; i++) ans = min(ans, lt[i] + rt[i + 1]); cout << ans << "\n"; 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...