-
-
Save Hacv16/efd3f00e84b4b595bbb67e84285395b0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
const int MAXN = 3e5 + 10; | |
int n, x[MAXN], h[MAXN], f[MAXN]; | |
int main() | |
{ | |
ios_base::sync_with_stdio(false); | |
cin.tie(NULL); | |
cin >> n; | |
for(int i = 1; i <= n; i++) cin >> x[i]; | |
for(int i = 1; i <= n; i++) cin >> h[i]; | |
stack<int> ativos; | |
for(int i = n; i >= 1; i--) | |
{ | |
int curF = 0; | |
while(!ativos.empty() && x[i] + h[i] >= x[ ativos.top() ]) | |
{ | |
curF += f[ ativos.top() ]; | |
ativos.pop(); | |
} | |
f[i] = curF + 1; | |
ativos.push(i); | |
} | |
for(int i = 1; i <= n; i++) | |
cout << f[i] << ' '; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment