Advertisement
ec1117

Untitled

Feb 20th, 2022
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. #include <string>
  4. #include <algorithm>
  5. #include <map>
  6.  
  7. int n, f=-1, mnCows;
  8. int x, s, maxR; //maxR is the smallest distance between a infected and non infected
  9. int cows[1000005];
  10.  
  11.  
  12. int main()
  13. {
  14. cin >> n; maxR = 1e9; mnCows = 0;
  15. for (int i = 0; i < n; i++)
  16. {
  17. cin >> x >> s;
  18. cows[x] = s+1;
  19. }
  20. for (int i = 0; i < 1000005; i++)
  21. {
  22. if (f!=-1 && cows[i] != cows[f]) {
  23. if(cows[i]!=0 && cows[f]!=0){
  24. if (i - f - 1 < maxR) {
  25. maxR = i - f - 1;
  26. }
  27. }
  28. }
  29. if (cows[i] == 1 || cows[i] == 2) {
  30. f = i;
  31. }
  32. }
  33. f = -1;
  34. for (int i = 0; i < 1000005; i++)
  35. {
  36. if(f==-1 && cows[i]==2){
  37. mnCows++;
  38. }
  39. if (f!=-1 && cows[f] == 1 && cows[i] == 2) {
  40. mnCows++;
  41. }
  42. if (f!=-1 && cows[i] == 2 && cows[f] == 2) {
  43. if (i - f > maxR) {
  44. mnCows++;
  45. }
  46. }
  47. if (cows[i] == 1 || cows[i] == 2) {
  48. f = i;
  49. }
  50. }
  51. cout << mnCows << endl;
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement