fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int distanceCovered(vector<vector<int>> busStops)
  5. {
  6. int answer;
  7. answer=0;
  8. long long arr[1000005]={0};
  9. int z = busStops.size();
  10. for (int i = 0; i < z; i++)
  11. {
  12. arr[busStops[i][0]]++;
  13. arr[busStops[i][1]]--;
  14. }
  15. long long curr = 0;
  16. for (int i = 0; i < 1000005; i++)
  17. {
  18. curr+=arr[i];
  19. if (curr>0)
  20. {
  21. answer++;
  22. }
  23. }
  24. return answer;
  25. }
  26.  
  27. int main()
  28. {
  29. ios::sync_with_stdio(0);
  30. cin.tie(0);
  31.  
  32. int rows,cols; cin>>rows>>cols;
  33. vector<vector<int>> store(rows);
  34.  
  35. for (int i = 0; i < rows; i++)
  36. {
  37. for (int j = 0; j < cols; j++)
  38. {
  39. int x; cin>>x;
  40. store[i].push_back(x);
  41. }
  42. }
  43.  
  44. cout<<distanceCovered(store)<<'\n';
  45. }
Success #stdin #stdout 0.01s 11368KB
stdin
3 2
2 4
3 5
6 7
stdout
4