Source Code
#include <bits/stdc++.h>
using namespace std;

int main(){
  long long n,k;
  cin>>n;
  vector<long long> v;
  cin>>k;
  v.push_back(k);
  int g = 1;
  for(int i = 0; i < n-1 ; i++){
    cin>>k;
    if(k<0){
      v[v.size()-1] += k;
      g = 1;
    }
    else if(k == 0){
      if(i == n-2 || g == 1)
        continue;
      else
        v.push_back(0);
    }
    else{
      v.push_back(k);
    }
    
  }for(int i = 0; i < v.size() ; i++)
      cout<<v[i]<<" ";

}
Copy
b Duukh
GNU G++17
1 ms
588 KB
Wrong Answer