File tree 1 file changed +70
-0
lines changed
1 file changed +70
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < bits/stdc++.h>
2
+ #include < iostream>
3
+ #include < sstream>
4
+ using namespace std ;
5
+
6
+ #define mod 1000000007
7
+ #define one (x ) __builtin_popcountll(x)
8
+ #define pp pair<ll,ll>
9
+ #define all (x ) (x).begin(), (x).end()
10
+ #define removeDuplicates (a ) a.resize(unique(all(a))-a.begin())
11
+ typedef long long int ll;
12
+
13
+
14
+
15
+
16
+ void subMain (){
17
+ ll n,a,b;cin>>n>>a>>b;
18
+ ll ar[n],presum[n];
19
+ for (int i=0 ;i<n;++i)
20
+ {
21
+ cin>>ar[i];
22
+ }
23
+ presum[0 ]=ar[0 ];
24
+ for (int i=1 ;i<n;++i)
25
+ {
26
+ presum[i]=presum[i-1 ]+ar[i];
27
+ }
28
+ multiset<ll>s;
29
+ s.insert (0 );
30
+ ll ans=-9e18 ;
31
+ ans=max (ans,presum[a-1 ]);
32
+ int flag=0 ;
33
+ for (int i=a;i<n;++i)
34
+ {
35
+ if (i-b>=0 )
36
+ {
37
+ if (!flag)
38
+ {
39
+ auto it=s.find (0 );
40
+ s.erase (it);
41
+ flag=1 ;
42
+ }
43
+ }
44
+ if (i-a>=0 )
45
+ {
46
+ s.insert (presum[i-a]);
47
+ }
48
+ ans=max (ans,presum[i]-*s.begin ());
49
+ if (i-b>=0 )
50
+ {
51
+ auto it=s.find (presum[i-b]);
52
+ s.erase (it);
53
+ }
54
+ }
55
+ cout<<ans<<endl;
56
+ }
57
+
58
+ int32_t main (){
59
+
60
+ ios_base::sync_with_stdio (false );
61
+ cin.tie (0 ); cout.tie (0 );
62
+
63
+
64
+ /* ll t;
65
+ cin >> t;
66
+ while(t--){
67
+ subMain();
68
+ }*/
69
+ subMain ();
70
+ }
You can’t perform that action at this time.
0 commit comments