Skip to content

Commit

Permalink
Add 09027.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiyabye committed Jun 5, 2024
1 parent 88b63b0 commit 5f58e20
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions 09xxx/09027.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

void solve(void) {
int n; cin >> n;
vector<long long> a(n), b(n);
for (int i=0; i<n; i++) cin >> a[i];
for (int i=0; i<n; i++) cin >> b[i];
for (int i=1; i<n; i++) b[i] += b[i-1];

vector<long long> dp(n); dp[0] = 0;
for (int i=1; i<n; i++) dp[0] += (a[i] - a[0]) * (b[i] - b[i-1]);
for (int i=1; i<n; i++) dp[i] = dp[i-1] + (a[i] - a[i-1]) * (2 * b[i-1] - b[n-1]);
cout << a[distance(dp.begin(), min_element(dp.begin(), dp.end()))] << "\n";
}

int main(void) {
ios::sync_with_stdio(false);
cin.tie(nullptr);

int t; cin >> t;
while (t--) solve();
return 0;
}

0 comments on commit 5f58e20

Please sign in to comment.