Source Code
// CODED BY ABDALAH ABUSALAH
// ~/SolverToBe/Developers/KnightK0der
/*
#---================================================================---#
#                                                                      #
# .d888888   dP                .d88888b           dP          dP       #
# d8     88  88                88.                88          88       #
# 88aaaaa88  88d888b. dP    dP `Y88888b. .d8888b. 88 .d8888b. 88d888b. #
# 88     88  88'  `88 88    88       `8b 88'  `88 88 88'  `88 88'  `88 #
# 88     88  88.  .88 88.  .88 d8'   .8P 88.  .88 88 88.  .88 88    88 #
# 88     88  88Y8888' `88888P'  Y88888P  `88888P8 dP `88888P8 dP    dP #
#                                                                      #
# .....................................................................#
# .......={====== ./ Contact With Me @ FB.COM/MRABUSALAH ======}=......#
# ....................*/#include <bits/stdc++.h>/*.....................#
#---================================================================---#
*/

using namespace std;
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define f(i, x, n) for (int i = x; i < (int)(n); ++i)
#define all(a) a.begin(),a.end()
#define endl '\n'
#define scantc scanf("%d",&tc);
#define l(s) s.length();
#define S second
#define F first
#define pb push_back
#define NumOfDigits(n) ((int)log10(n)+1)
typedef vector<int> vi;
typedef vector<pair<int, int>> vip;
const int N = 100000 + 10;
const double PI = 3.14159;

int gcd(int a, int b) {
    return !b ? a : gcd(b, a % b);
}

int lcm(int a, int b) {
    return (a / gcd(a, b)) * b;
}

int randomNum() {
    return rand() % 100 + 1;
}

double distanceBetweenTwoPoints(double x, double y, double a, double b) {
    return sqrt(pow(x - a, 2) + pow(y - b, 2));
}

bool isPrime(ll n) {
    if (n == 2) {
        return true;
    }
    if ((n < 2) || !(n % 2)) {
        return false;
    }
    for (int i = 3; i * i <= n; i += 2) {
        if (!(n % i))
            return false;
    }
    return true;
}

bool twoPointers(vector<int> v, int key) {
    int left = 0, right = v.size() - 1;
    while (left < right) {
        if (v[left] + v[right] == key)
            return 1;
        else if (v[left] + v[right] > key)
            right--;
        else
            left++;
    }
    return 0;
}

void calcTime() {
    clock_t t;
    t = clock();
    //myCode();
    t = clock() - t;
    double time_taken = ((double) t) / CLOCKS_PER_SEC; // calculate the elapsed time
    printf("The program took %f seconds to execute", time_taken);

}

int dr[4] = {0, 1, 0, -1};
int dc[4] = {1, 0, -1, 0};
// x |= (1<<i) to make a bit = 1
// x &= ~(1<<i) to clear a bit = 0
// x & (1<<j) to check if bit j is 1 in x


/*
[#]=============================================================[#]
         ___    ____              ____          ___ _
        |_ _|  / ___|__ _ _ __   |  _ \  ___   |_ _| |_
         | |  | |   / _` | '_ \  | | | |/ _ \   | || __|
         | |  | |__| (_| | | | | | |_| | (_) |  | || |_
        |___|  \____\__,_|_| |_| |____/ \___/  |___|\__|
                     it's just about time

[#]=============================================================[#]
*/

inline void start() {
    // return (sudo apt-get ACCEPTED)
}

inline int SD() {
    int x;
    scanf("%d", &x);
    return x;
}

int const SIZE = 1e6 + 10;
int arr[SIZE];

inline void solve() {
    ll n ;
    cin>>n;
    vector<ll> v;
    while(n--){
    	ll x;
    	cin>>x;
    	v.pb(x);
    }
    for(int i = 0 ;i < v.size() -1;i++){
    	if((i < v.size() - 1) && v[i] <= v[i + 1]){
    		v[i] += v[i+1];
    		v.erase(v.begin() + i+1);
    		if(i > 0 && v[i] > v[i-1]){
    			i--;
	    	}
	    	i--;
    	}
    	
    }
    
    for(int i = 0 ;i < v.size();i++) cout<<v[i] << " ";
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.in", "r", stdin);
#endif
    //========================//
    /*||*/                /*||*/
    /*||*/    start();    /*||*/
    /*||*/    solve();    /*||*/
    /*||*/                /*||*/
    //========================//
    return 0;
}
Copy
b KnightK0der
GNU G++17
0 ms
488 KB
Wrong Answer