Advertisement
ec1117

Untitled

Feb 20th, 2022
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #include "bits/stdc++.h"
  2.  
  3. using namespace std;
  4.  
  5.  
  6. int x[1005],y[1005];
  7.  
  8. bool done[1005];
  9.  
  10. int main(){
  11. int n;cin>>n;
  12. for(int i=0;i<n;i++){
  13. cin>>x[i]>>y[i];
  14. }
  15.  
  16. //biggest R we can have
  17. int bigR=1e9;
  18. for(int i=0;i<n;i++){
  19. for(int j=0;j<n;j++){
  20. if(y[i]+y[j]==1){//1 infected, 1 not
  21. bigR=min(bigR,abs(x[i]-x[j])-1);
  22. }
  23. }
  24. }
  25.  
  26. vector<pair<int,int>> v;
  27. for(int i=0;i<n;i++){
  28. v.push_back({x[i],y[i]});
  29. }
  30. sort(v.begin(),v.end());
  31.  
  32. int cnt=0;
  33. for(int i=0;i<n;i++){
  34. if(v[i].second==1){
  35. if(i==0){
  36. cnt++;
  37. } else {
  38. if(v[i-1].second==0){
  39. cnt++;
  40. } else {
  41. if(v[i-1].second==1 && v[i].first-v[i-1].first>bigR){
  42. cnt++;
  43. }
  44. }
  45. }
  46. }
  47. }
  48. cout<<cnt<<endl;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement