Codeforces Round #303 (Div. 2) 545C - Woodcutters Solution



  Problem Link:  https://codeforces.com/problemset/problem/545/C

Solution in C++:

  1. /// La ilaha illellahu muhammadur rasulullah
  2. ///******Bismillahir-Rahmanir-Rahim******///
  3. /// Abul Hasnat Tonmoy
  4. /// Department of CSE,23rd batch
  5. /// Islamic University,Bangladesh
  6. ///**********ALLAH IS ALMIGHTY************///
  7. #include <bits/stdc++.h>
  8. using namespace std;
  9. int main() {
  10. ios_base::sync_with_stdio(0);
  11. cin.tie(0);
  12. int n;
  13. cin >> n;
  14. std::vector<int> x;
  15. std::vector<int> h;
  16. int a, b;
  17. for (int i = 0; i <= n; i++) {
  18. cin >> a >> b;
  19. x.push_back(a);
  20. h.push_back(b);
  21. }
  22. if (n <= 2) {
  23. cout << n << endl;
  24. return 0;
  25. }
  26. int ans = 1;
  27. for (int i = 1; i < n - 1; i++) {
  28. if (x[i] - h[i] > x[i - 1]) {
  29. ans++;
  30. } else if (x[i] + h[i] < x[i + 1]) {
  31. ans++;
  32. x[i] = (x[i] + h[i]);
  33. }
  34. }
  35. cout << ans + 1 << endl;
  36. }

No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h ...

Powered by Blogger.