aboutsummaryrefslogtreecommitdiff
path: root/17/day4/stock_trading.cpp
diff options
context:
space:
mode:
Diffstat (limited to '17/day4/stock_trading.cpp')
-rw-r--r--17/day4/stock_trading.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/17/day4/stock_trading.cpp b/17/day4/stock_trading.cpp
new file mode 100644
index 0000000..c2aa679
--- /dev/null
+++ b/17/day4/stock_trading.cpp
@@ -0,0 +1,21 @@
+#include <bits/stdc++.h>
+using namespace std;
+using ll = long long;
+
+int main() {
+ ios_base::sync_with_stdio(0), cin.tie(0);
+
+ int N, L;
+ cin >> N >> L;
+
+ multiset<ll> S;
+ ll ans = 0;
+ for (int i = 0, b, s; i < N; ++i) {
+ cin >> b >> s;
+ ans = max(ans - (i >= L ? *begin(S) : 0) + s, ans);
+ S.insert({ b, s });
+ if (i >= L) S.erase(begin(S)), S.erase(prev(end(S)));
+ }
+ for (auto it = S.begin(); L; ++it, --L) ans -= *it;
+ cout << ans << endl;
+} \ No newline at end of file