947B - Producing Snow - CodeForces Solution


binary search data structures implementation *1600

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>

using namespace std;

#define int long long

signed main() {
    int n;
    cin >> n;
    vector<int> v(n), t(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> t[i];
    }
    multiset<int> snow;
    int sumtemp = 0;
    for (int i = 0; i < n; ++i) {
        snow.insert(v[i] + sumtemp);
        int lastsnow = 0;
        while (!snow.empty() && (*snow.begin()) - sumtemp <= t[i]) {
            lastsnow += (*snow.begin()) - sumtemp;
            snow.erase(snow.begin());
        }
        cout << lastsnow + t[i] * snow.size() << ' ';
        sumtemp += t[i];
    }
    return 0;
}/*1688079711.7097514*/


Comments

Submit
0 Comments
More Questions

50A - Domino piling
479A - Expression
1480A - Yet Another String Game
1216C - White Sheet
1648A - Weird Sum
427A - Police Recruits
535A - Tavas and Nafas
581A - Vasya the Hipster
1537B - Bad Boy
1406B - Maximum Product
507B - Amr and Pins
379A - New Year Candles
1154A - Restoring Three Numbers
750A - New Year and Hurry
705A - Hulk
492B - Vanya and Lanterns
1374C - Move Brackets
1476A - K-divisible Sum
1333A - Little Artem
432D - Prefixes and Suffixes
486A - Calculating Function
1373B - 01 Game
1187A - Stickers and Toys
313B - Ilya and Queries
579A - Raising Bacteria
723A - The New Year Meeting Friends
302A - Eugeny and Array
1638B - Odd Swap Sort
1370C - Number Game
1206B - Make Product Equal One