Some Uninitialized value is gicing unexpected output ..Need help in identifying the issue The Problem statement goes here Best Vacation is The submissione goes here 81970910
include<bits/stdc++.h>
using namespace std;
define ll long long
define pb push_back
define io ios_base::sync_with_stdio(false);cin.tie(NULL);
define pie acos(-1)
define loop(i,a,n) for(ll i=a;i<n;i++)
define vi vector
define vl vector
define all(a) a.begin(),a.end()
void solve() { #define int long long int n ,x; cin>>n>>x; vi a(2*n); loop(i,0,n) { cin>>a[i]; a[n+i] = a[i]; } vi pre(2*n); pre[0] = a[0]; vl sum(2*n); for(int i = 1 ; i<2*n ; i++) { pre[i] = a[i]+pre[i-1]; } sum[0]=a[0]*(a[0]+1)/2; for(int i = 1; i< 2*n ;i++) { sum[i] = sum[i-1] + a[i]*(a[i]+1)/2; } ll ans = 0 ; for(int i = 0 ; i < 2*n ; i++) { int y = pre[i] — x; auto it = upper_bound(all(pre),y); if(it!=pre.end()) { int j = it — pre.begin(); int diff = pre[i]-pre[j-1] — x; ll here = sum[i]-sum[j-1]; here-=(diff*(diff+1)/2); //cout<<here<<" "<<ans<<endl; //seee(j,here,diff) ans = max(ans,here); } }
cout<<ans<<endl;
}
undef int
int main() { // your code goes here io; solve(); return 0; }