Created
July 13, 2022 21:35
-
-
Save modos/1a098c2c4be16c75fe1d48b3aaa4e0bd to your computer and use it in GitHub Desktop.
زیربازه
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<bits/stdc++.h> | |
using namespace std; | |
#define ll long long | |
int INF = 2e9; | |
const int N = 3e5 + 35; | |
ll W; | |
ll psum[N]; | |
int main() | |
{ | |
ios::sync_with_stdio(0); | |
cin.tie(0); | |
int n; | |
cin >> n >> W; | |
for (int i = 1;i <= n;i++) | |
{ | |
ll w; | |
cin >> w; | |
psum[i] = psum[i - 1] + w; | |
} | |
ll ans = 0; | |
set<ll>st; | |
for (int i = 0;i <= n;i++) | |
{ | |
auto it = st.lower_bound(psum[i] - W); | |
if (it != st.end()) | |
ans = max(ans, psum[i] - *it); | |
st.insert(psum[i]); | |
} | |
cout << ans; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment