Codeforces Round #837 (Div. 2) 1771B. Hossam and Friends Solution


 

 Problem Link: https://codeforces.com/problemset/problem/1771/B

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. #define ll long long int
  10. int main() {
  11. ios_base::sync_with_stdio(0);
  12. cin.tie(0);
  13. ll t;
  14. cin >> t;
  15. while (t--) {
  16. ll n, m, x, y, ans = 0;
  17. cin >> n >> m;
  18. std::vector<ll> v(n + 1, -1);
  19. while (m--) {
  20. cin >> x >> y;
  21. if (x > y) swap(x, y);
  22. v[y] = max(v[y], x);
  23. }
  24. ll next = 1;
  25. for (ll i = 1; i <= n; i++) {
  26. next = max(next, v[i] + 1);
  27. ans += (i - next + 1);
  28. }
  29. cout << ans << endl;
  30. }
  31. }

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 &g...

Powered by Blogger.