Advertisement
edward4324

helpa svet

Oct 25th, 2021 (edited)
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.35 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <sstream>
  4. #include <vector>
  5.  
  6. int torches[1024];
  7. int area[1024];
  8. int light[1024];
  9.  
  10. int N;
  11. int K;
  12.  
  13. int main()
  14. {
  15.  
  16.     std::cin >> N;
  17.     std::cin >> K;
  18.  
  19.     std::string str;
  20.  
  21.     for (int i = 0; i < K; i++)
  22.     {
  23.  
  24.         std::cin >> torches[i];
  25.         std::cin >> light[i];
  26.  
  27.     }
  28.  
  29.     for (int i = 0; i < N; i++)
  30.         area[i] = 0;
  31.  
  32.     for (int i = 0; i < K; i++)
  33.     {
  34.  
  35.         int istart = torches[i] - light[i];
  36.         int iend = torches[i] + light[i];
  37.  
  38.         if (istart > 0 && iend < N)
  39.         {
  40.  
  41.             for (int j = istart; j <= iend; j++)
  42.             {
  43.                 area[j] = 1;
  44.             }
  45.  
  46.         }
  47.         else if (istart <= 0)
  48.         {
  49.             for (int j = 0; j <= iend; j++)
  50.             {
  51.                 area[j] = 1;
  52.             }
  53.         }
  54.         else if (iend >= N)
  55.         {
  56.  
  57.             for (int j = istart; j <= N - 1; j++)
  58.             {
  59.                 area[j] = 1;
  60.             }
  61.  
  62.         }
  63.         else if (iend >= N && istart <= 0)
  64.         {
  65.  
  66.             for (int j = 0; j <= N - 1; j++)
  67.             {
  68.                 area[j] = 1;
  69.             }
  70.  
  71.         }
  72.  
  73.     }
  74.  
  75.     int count = 0;
  76.  
  77.     for (int i = 0; i < N; i++)
  78.         if (area[i] == 0)
  79.             count++;
  80.  
  81.     std::cout << count;
  82.  
  83.     return 0;
  84.  
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement