Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <ext/pb_ds/tree_policy.hpp>
- #include <ext/pb_ds/assoc_container.hpp>
- #pragma GCC target("fpmath=387") //Turns on excess precision
- using namespace std;
- using namespace __gnu_pbds;
- #define EPS 1e-9
- #define PI acos(-1)
- #define ll long long
- #define Mod 1'000'000'007
- #define INF 2'000'000'000
- #define sz(x) int(x.size())
- #define all(s) s.begin(), s.end()
- #define rall(s) s.rbegin(), s.rend()
- #define Num_of_Digits(n) ((int)log10(n)+1)
- #define to_decimal(bin) stoll(bin, nullptr, 2)
- #define fixed(n) cout << fixed << setprecision(n)
- //#define ceil(n, m) (((n) / (m)) + ((n) % (m) ? 1 : 0))
- #define cout(st) for(auto& i : st) cout << i << " "; cout << "\n"
- #define cout_map(mp) for(auto& [f, s] : mp) cout << f << " : " << s << "\n"
- #define matrix(grid, n, m) vector < vector <int> > grid(n, vector <int> (m));
- #define cout_2d(grid) for(auto& v : grid){for(auto& x : v) cout << x << " "; cout << "\n";}
- #define cin_2d(grid, n, m) for(int i=0; i<n; i++) for(int j=0; j<m && cin >> grid[i][j]; j++);
- #define ordered_set tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update>
- #define multi_ordered_set tree<int, null_type, less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
- template < typename T = int > using Pair = pair < T, T >; //Pair<int> p;
- template < typename T = int > istream& operator >> (istream &in, vector < T > &v) {
- for (auto &x: v) in >> x;
- return in;
- }
- template < typename T = int > ostream& operator << (ostream &out, const vector < T > &v) {
- for (const T &x: v) out << x << ' ';
- return out;
- }
- void Anwar_Rizk(){
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
- #endif
- }
- // 8 1 4
- //-10 15 -11 -5 8 -5 2 2
- void max_sum_subarray(vector<ll> arr, int L, int R){
- int n = arr.size();
- vector < ll > pre(n, arr[0]);
- for (int i = 1; i < n; i++) pre[i] = pre[i - 1] + arr[i];
- cout << pre << "\n";
- multiset < ll > s1;
- s1.insert(0);
- ll ans = pre[L - 1];
- int flag = 0;
- for (int i = L; i < n; i++) {
- if (i - R >= 0) {
- if (flag == 0) {
- auto it = s1.find(0);
- s1.erase(it);
- flag = 1;
- }
- }
- cout << "i = " << i << "\n";
- cout << "ans = " << ans << "\n";
- cout << "s1 = ";cout(s1); cout << "----------------\n";
- if (i - L >= 0) s1.insert(pre[i - L]);
- cout(s1); cout << "----------------\n";
- ans = max(ans, pre[i] - *s1.begin());
- if (i - R >= 0) {
- auto it = s1.find(pre[i - R]);
- s1.erase(it);
- }
- cout << "ans = " << ans << "\n";
- cout << "s1 = ";cout(s1); cout << "\n";
- }
- cout << ans << endl;
- }
- void solve(){
- ll n, a, b;
- cin >> n >> a >> b;
- vector < ll > v(n);
- cin >> v;
- max_sum_subarray(v, a, b);
- }
- int main()
- { Anwar_Rizk();
- int t = 1;
- //cin >> t;
- while(t--){
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement