Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include <iomanip>
- #include <algorithm>
- #include <math.h>
- #include <stack>
- #include <queue>
- #include <deque>
- #include <vector>
- #include <set>
- #include <string>
- #include <map>
- using namespace std;
- typedef long long ll;
- pair <ll, pair <ll, ll>> A[200];
- set <pair <ll, ll>> S[4];
- ll ans[200];
- int main() {
- #ifdef _DEBUG
- freopen("input.txt", "r", stdin);
- #else
- freopen("carrefour.in", "r", stdin);
- freopen("carrefour.out", "w", stdout);
- #endif
- ll n;
- cin >> n;
- ll a, b;
- cin >> a >> b;
- a %= 4; b %= 4;
- for (ll i = 0; i < n; i++) {
- cin >> A[i].second.second >> A[i].first;
- A[i].second.second %= 4;
- A[i].second.first = i;
- }
- A[n].second.first = n;
- A[n].first = 100000;
- A[n].second.second = 0;
- n++;
- ll t = 0;
- sort(A, A + n);
- if ((a + b) % 2 == 0) {
- ll a1 = (a + 3) % 4;
- ll b1 = (b + 3) % 4;
- for (ll i = 0; i < n; i++) {
- ll j = i;
- t++;
- while (A[j].first == t) {
- S[A[j].second.second].insert(make_pair(t, A[j].second.first));
- j++;
- if (j == n) {
- break;
- }
- }
- j--;
- i = j;
- if (S[a].size() > 0 || S[b].size() > 0) {
- if (S[a].size() > 0) {
- ans[(*S[a].begin()).second] = t;
- S[a].erase(S[a].begin());
- }
- if (S[b].size() > 0) {
- ans[(*S[b].begin()).second] = t;
- S[b].erase(S[b].begin());
- }
- continue;
- }
- else {
- if (S[a1].size() > 0) {
- ans[(*S[a1].begin()).second] = t;
- S[a1].erase(S[a1].begin());
- }
- if (S[b1].size() > 0) {
- ans[(*S[b1].begin()).second] = t;
- S[b1].erase(S[b1].begin());
- }
- }
- }
- for (ll i = 0; i < n - 1; i++) {
- cout << ans[i] << '\n';
- }
- return 0;
- }
- ll a1, b1;
- if (b == (a + 1) % 4) {
- swap(a, b);
- }
- b1 = (a + 1) % 4;
- a1 = (a + 2) % 4;
- for (ll i = 0; i < n; i++) {
- ll j = i;
- t++;
- while (A[j].first == t) {
- S[A[j].second.second].insert(make_pair(t, A[j].second.first));
- j++;
- if (j == n) {
- break;
- }
- }
- j--;
- i = j;
- if (S[a].size() > 0 || S[b].size() > 0) {
- if (S[b].size() > 0) {
- ans[(*S[b].begin()).second] = t;
- S[b].erase(S[b].begin());
- continue;
- }
- if (S[a].size() > 0) {
- ans[(*S[a].begin()).second] = t;
- S[a].erase(S[a].begin());
- }
- continue;
- }
- else {
- if (S[b1].size() > 0) {
- ans[(*S[b1].begin()).second] = t;
- S[b1].erase(S[b1].begin());
- continue;
- }
- if (S[a1].size() > 0) {
- ans[(*S[a1].begin()).second] = t;
- S[a1].erase(S[a1].begin());
- }
- }
- }
- for (ll i = 0; i < n - 1; i++) {
- cout << ans[i] << '\n';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment