Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  5. int const maxn = 5e6 + 7;
  6. long long const mod = 1000000007;
  7. int n, m, cnt[maxn];
  8. priority_queue<int> q;
  9. vector<int> noize, cost;
  10.  
  11. void input() {
  12. cin >> n >> m;
  13. int temp;
  14. for (int i = 0; i < n; i++) {
  15. cin >> temp;
  16. noize.push_back(temp);
  17. }
  18. for (int i = 0; i < n; i++) {
  19. cin >> temp;
  20. cost.push_back(temp);
  21. }
  22. }
  23.  
  24. void solve() {
  25. long long ans = mod * mod;
  26. for (int i = 0; i <= n - m; i++) {
  27. int currmin = mod;
  28. long long currans = 0;
  29. for (int j = i; j < i + m; j++) {
  30. currmin = min(currmin, noize[j]);
  31. }
  32. for (int j = i; j < i + m; j++) {
  33. currans += cost[j] * (noize[j] - currmin);
  34. }
  35. ans = min(ans, currans);
  36. }
  37. cout << ans;
  38. }
  39.  
  40. int32_t main() {
  41. IOS
  42. input();
  43. solve();
  44. return 0;
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement