Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
- int const maxn = 5e6 + 7;
- long long const mod = 1000000007;
- int n, m, cnt[maxn];
- priority_queue<int> q;
- vector<int> noize, cost;
- void input() {
- cin >> n >> m;
- int temp;
- for (int i = 0; i < n; i++) {
- cin >> temp;
- noize.push_back(temp);
- }
- for (int i = 0; i < n; i++) {
- cin >> temp;
- cost.push_back(temp);
- }
- }
- void solve() {
- long long ans = mod * mod;
- for (int i = 0; i <= n - m; i++) {
- int currmin = mod;
- long long currans = 0;
- for (int j = i; j < i + m; j++) {
- currmin = min(currmin, noize[j]);
- }
- for (int j = i; j < i + m; j++) {
- currans += cost[j] * (noize[j] - currmin);
- }
- ans = min(ans, currans);
- }
- cout << ans;
- }
- int32_t main() {
- IOS
- input();
- solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement