Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <sstream>
- #include <vector>
- int torches[1024];
- int area[1024];
- int light[1024];
- int N;
- int K;
- int main()
- {
- std::cin >> N;
- std::cin >> K;
- std::string str;
- for (int i = 0; i < K; i++)
- {
- std::cin >> torches[i];
- std::cin >> light[i];
- }
- for (int i = 0; i < N; i++)
- area[i] = 0;
- for (int i = 0; i < K; i++)
- {
- int istart = torches[i] - light[i];
- int iend = torches[i] + light[i];
- if (istart > 0 && iend < N)
- {
- for (int j = istart; j <= iend; j++)
- {
- area[j] = 1;
- }
- }
- else if (istart <= 0)
- {
- for (int j = 0; j <= iend; j++)
- {
- area[j] = 1;
- }
- }
- else if (iend >= N)
- {
- for (int j = istart; j <= N - 1; j++)
- {
- area[j] = 1;
- }
- }
- else if (iend >= N && istart <= 0)
- {
- for (int j = 0; j <= N - 1; j++)
- {
- area[j] = 1;
- }
- }
- }
- int count = 0;
- for (int i = 0; i < N; i++)
- if (area[i] == 0)
- count++;
- std::cout << count;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement