Submission #649458

#TimeUsernameProblemLanguageResultExecution timeMemory
649458ymmBaloni (COCI15_baloni)C++17
100 / 100
750 ms92432 KiB
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;

const int N = 1'000'010;
set<int> balloons[N];
int n;

void shoot(int h)
{
	int lst = -1;
	while (h >= 0) {
		auto it = balloons[h].upper_bound(lst);
		if (it == balloons[h].end())
			break;
		lst = *it;
		balloons[h].erase(it);
		--h;
	}
}

int main()
{
	cin.tie(0) -> sync_with_stdio(false);
	cin >> n;
	Loop (i,0,n) {
		int h;
		cin >> h;
		balloons[h].insert(i);
	}
	int ans = 0;
	LoopR (i,0,N) {
		while (balloons[i].size()) {
			shoot(i);
			++ans;
		}
	}
	cout << ans << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...