Codeforces Round #303 (Div. 2) 545C - Woodcutters Solution
Problem Link: https://codeforces.com/problemset/problem/545/C
Solution in C++:
- /// La ilaha illellahu muhammadur rasulullah
- ///******Bismillahir-Rahmanir-Rahim******///
- /// Abul Hasnat Tonmoy
- /// Department of CSE,23rd batch
- /// Islamic University,Bangladesh
- ///**********ALLAH IS ALMIGHTY************///
- #include <bits/stdc++.h>
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int n;
- cin >> n;
- std::vector<int> x;
- std::vector<int> h;
- int a, b;
- for (int i = 0; i <= n; i++) {
- cin >> a >> b;
- x.push_back(a);
- h.push_back(b);
- }
- if (n <= 2) {
- cout << n << endl;
- return 0;
- }
- int ans = 1;
- for (int i = 1; i < n - 1; i++) {
- if (x[i] - h[i] > x[i - 1]) {
- ans++;
- } else if (x[i] + h[i] < x[i + 1]) {
- ans++;
- x[i] = (x[i] + h[i]);
- }
- }
- cout << ans + 1 << endl;
- }
No comments