#include using namespace std; #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define RREP(i, n) for (int i = ((int)(n)-1); i >= 0; i--) #define REPITR(itr, ARRAY) for (auto itr = (ARRAY).begin(); itr != (ARRAY).end(); ++itr) #define RREPITR(itr, ARRAY) for (auto itr = (ARRAY).rbegin(); itr != (ARRAY).rend(); ++itr) #define ALL(n) (n).begin(), (n).end() using ll = long long; using ull = unsigned long long; // #define int long long template struct edge { int to; T cost; edge() {} edge(int to, T cost): to(to), cost(cost) {} }; ll N; // 3000 fixed ll T; // 400 fixed vector, pair>> working_pathes; ll money = 1e6; ll constexpr cost_base = 1e7; ll collaborater = 1; ll constexpr grid_size = 14; pair dir[4] = {pair(0, 1), pair(0, -1), pair(1, 0), pair(-1, 0)}; set, pair>> is_constructed; signed main() { cin >> N >> T; working_pathes.resize(N); REP(i, N) { cin >> working_pathes[i].first.first >> working_pathes[i].first.second >> working_pathes[i].second.first >> working_pathes[i].second.second; working_pathes[i].first.first--; working_pathes[i].first.second--; working_pathes[i].second.first--; working_pathes[i].second.second--; } clock_t start_time = clock(); map, pair>, int> seen_count; int rem = 0; REP(day, T) { if (clock() - start_time > 1.8 * CLOCKS_PER_SEC) { cout << 3 << endl; continue; } cin >> money >> collaborater; if (collaborater < 100) { cout << 2 << endl; continue; } else if (money < cost_base / sqrt(collaborater)) { cout << 3 << endl; continue; } else { rem--; if (rem < 0) { rem = 4; seen_count.clear(); REP(n, N) { pair start = working_pathes[n].first; pair end = working_pathes[n].second; vector> seen(grid_size, vector(grid_size)); deque> que; que.push_back(start); seen[start.first][start.second] = true; while (!que.empty()) { pair c = que.front(); que.pop_front(); if (c == end) { break; } for (auto d: dir) { auto n = c; n.first += d.first; n.second += d.second; if (n.first < 0 || grid_size <= n.first || n.second < 0 || grid_size <= n.second) { continue; } auto path = pair, pair>(c, n); // seen_count[path] += 1; if (seen[n.first][n.second]) { continue; } bool exsits = is_constructed.find(path) != is_constructed.end(); if (!exsits) { seen_count[path] += 1; } seen[n.first][n.second] = true; if (exsits) { que.push_front(n); } else { que.push_back(n); } } } } } auto ma = max_element(ALL(seen_count), [](const auto& x, const auto& y) { return x.second < y.second; }); // // 60*0.3 = 48 // if (-cost_base / sqrt(collaborater) + (*ma).second * 30 * (T - day) < 5000) { // cout << 3 << endl; // } else { cout << 1 << " " << (*ma).first.first.first + 1 << " " << (*ma).first.first.second + 1 << " " << (*ma).first.second.first + 1 << " " << (*ma).first.second.second + 1 << endl; is_constructed.insert((*ma).first); (*ma).second = -1; // } } } return 0; }