Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- int main(){
- ll n,l;
- cin>>n>>l;
- ll a[n+1];
- for (ll i=1; i<=n; i++){
- cin>>a[i];
- }
- ll i=1;
- ll sum=0;
- for (ll j=1; j<=n; j++){
- sum+=a[j];
- while (sum>l){
- sum-=a[i++];
- }
- if (sum==l){
- for (ll k=i; k<=j; k++){
- cout<<a[k]<<" ";
- }
- return 0;
- }
- }
- cout<<-1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement