fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int cur1[200001];
  5. int cur2[200001];
  6.  
  7. int main(){
  8. int n,q;
  9. cin >> n >> q;
  10. for(int i = 1; i <= q; i++){
  11. int x,y;
  12. cin >> x >> y;
  13. cur1[x] += 1;
  14. cur1[y+1] -= 1;
  15. cur2[y+1] -= y - x + 1;
  16. }
  17. int dem = 0;
  18. int tong = 0;
  19. int kq = 0;
  20. for(int i = 1; i <= n+1; i++){
  21. dem += cur1[i];
  22. tong = tong + dem + cur2[i];
  23. kq = max(kq,tong);
  24. }
  25. cout << kq;
  26. }
  27.  
Success #stdin #stdout 0s 5304KB
stdin
Standard input is empty
stdout
Standard output is empty