#include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef struct info { ll minute; ll stopIdx; ll tourists; ll busX; }INFO; typedef struct busSort { ll idx; ll val; ll maxMinute; ll maxTourists; }BUS_SORT; bool comp(INFO a, INFO b) { return a.busX < b.busX; } bool bsComp(BUS_SORT a, BUS_SORT b) { return a.val < b.val; } bool bsComp1(BUS_SORT a, BUS_SORT b) { return a.maxMinute > b.maxMinute; } bool bsComp2(BUS_SORT a, BUS_SORT b) { return a.maxTourists > b.maxTourists; } unordered_map stopMaxMinute; unordered_map stopMinMinute; unordered_map stopMaxTourists; unordered_map usedIdxs; int main() { ios_base::sync_with_stdio(0); freopen("wonderland.in","r",stdin); freopen("wonderland.out","w",stdout); ll maxBus = 0LL; ll busIdx = 0LL; ll n; bool allX = true; cin >> n; vector > stops; for (int i = 0; i < n; i++) { ll x, y; cin >> x >> y; stops.push_back({x, y}); allX &= (y == 0); } ll m; cin >> m; vector > buses; for (int i = 0; i < m; i++) { ll l, r; cin >> l >> r; buses.push_back({l, r}); if (l > maxBus) { maxBus = l; busIdx = i; } } ll t, f; cin >> t >> f; vector inf; ll maxMin = 0; ll minMin = LLONG_MAX; for (int i = 0; i < f; i++) { ll a, b, c; cin >> a >> b >> c; INFO in; in.minute = a; in.stopIdx = b - 1; in.tourists = c; in.busX = buses[b - 1].first; inf.push_back(in); maxMin = max(maxMin, a * 1LL); minMin = min(minMin, a * 1LL); stopMaxMinute[b - 1] = max(stopMaxMinute[b - 1], a); if (stopMinMinute[b - 1] == 0 || a < stopMinMinute[b - 1]) stopMinMinute[b - 1] = a; stopMaxTourists[b - 1] = max(stopMaxTourists[b - 1], c); usedIdxs[b - 1] = 1; } ll d; cin >> d; if (m == 1) { ll bestScore = LLONG_MAX; vector unused; for (int i = 0; i < n; i++) { if (usedIdxs[i] == 0) unused.push_back(i); } vector ansFirstPart; ll ansTotal; vector ansSecondPart; vector > closest; vector differentIdxs; unordered_map ump; for (int i = 0; i < inf.size() ; i++) { ump[inf[i].stopIdx]++; if (ump[inf[i].stopIdx] == 1) differentIdxs.push_back(inf[i].stopIdx); } ump.clear(); vector tmp; vector closestUnused; for (int i = 0; i < differentIdxs.size(); i++) { vector bsVec; for (int j = 0; j < differentIdxs.size(); j++) { ll ii = differentIdxs[i], jj = differentIdxs[j]; if (ii != jj) { ll val = abs(stops[ii].first - stops[jj].first) + abs(stops[ii].second - stops[jj].second); BUS_SORT bs; bs.val = val; bs.idx = j; bs.maxMinute = stopMaxMinute[j]; bs.maxTourists = stopMaxTourists[j]; bsVec.push_back(bs); } } sort(bsVec.begin(), bsVec.end(), bsComp); for (int j = 0; j < bsVec.size(); j++) tmp.push_back(bsVec[j].idx); closest.push_back(tmp); tmp.clear(); ll maxi = LLONG_MAX; ll save = -1; for (int j = 0; j < unused.size(); j++) { ll ii = differentIdxs[i], jj = unused[j]; if (ii != jj) { ll val = abs(stops[ii].first - stops[jj].first) + abs(stops[ii].second - stops[jj].second); if (val < maxi) { maxi = val; save = j; } } } if (save != -1) closestUnused.push_back(save); } for (int i = 0; i < differentIdxs.size(); i++) { ump.clear(); ll ii = differentIdxs[i]; ll currScore = 0LL; ump[i] = 1; vector chain; chain.push_back(ii); ll prev = i; while (chain.size() < differentIdxs.size()) { for (int j = 0; j < closest[prev].size(); j++) { if (ump[closest[prev][j]] == 0) { ump[closest[prev][j]] = 1; chain.push_back(differentIdxs[closest[prev][j]]); prev = closest[prev][j]; break; } } } //try cyclic routes chain.push_back(ii); ll time = buses[0].second * 1LL; for (int j = 0; j < chain.size() - 1; j++) time += abs(stops[chain[j]].first - stops[chain[j + 1]].first) + abs(stops[chain[j]].second - stops[chain[j + 1]].second); ll distance = time - buses[0].second * 1LL; ll total = (t - max(minMin, maxMin - d)) / time; if (time < bestScore) { ansFirstPart.clear(); ansSecondPart.clear(); bestScore = time; for (int j = 0; j < chain.size(); j++) ansFirstPart.push_back(chain[j] + 1); ansTotal = total; if (d != -1) ansTotal = min(ansTotal, d/distance); ll curr = max(minMin, maxMin - d); for (int i = 0; i < ansTotal; i++) { ansSecondPart.push_back(curr); curr += time * 1LL; } } //try normal routes if(closestUnused.size() > 0) { chain[chain.size() - 1] = unused[closestUnused[prev]]; ll time = buses[0].second * 1LL; for (int j = 0; j < chain.size() - 1; j++) time += abs(stops[chain[j]].first - stops[chain[j + 1]].first) + abs(stops[chain[j]].second - stops[chain[j + 1]].second); ll distance = time - buses[0].second * 1LL; ll total = (t - max(minMin, maxMin - d)) / time; if (time < bestScore) { ansFirstPart.clear(); ansSecondPart.clear(); bestScore = time; for (int j = 0; j < chain.size(); j++) ansFirstPart.push_back(chain[j] + 1); ansTotal = total; if (d != -1) ansTotal = min(ansTotal, d/distance); ll curr = max(minMin, maxMin - d); for (int i = 0; i < ansTotal; i++) { ansSecondPart.push_back(curr); curr += time * 1LL; } } } } cout << ansFirstPart.size() << " "; for (int i = 0; i < ansFirstPart.size(); i++) cout << ansFirstPart[i] << " "; cout << "\n" << ansTotal << " "; for (int i = 0; i < ansSecondPart.size(); i++) cout << ansSecondPart[i] << " "; cout << "\n"; return 0; } ll bestScore = LLONG_MAX; vector unused; for (int i = 0; i < n; i++) { if (usedIdxs[i] == 0) unused.push_back(i); } vector ansFirstPart; ll ansTotal; vector ansSecondPart; vector > closest; vector differentIdxs; unordered_map ump; for (int i = 0; i < inf.size() ; i++) { ump[inf[i].stopIdx]++; if (ump[inf[i].stopIdx] == 1) differentIdxs.push_back(inf[i].stopIdx); } ump.clear(); vector tmp; vector closestUnused; for (int i = 0; i < differentIdxs.size(); i++) { vector bsVec; for (int j = 0; j < differentIdxs.size(); j++) { ll ii = differentIdxs[i], jj = differentIdxs[j]; if (ii != jj) { ll val = abs(stops[ii].first - stops[jj].first) + abs(stops[ii].second - stops[jj].second); BUS_SORT bs; bs.val = val; bs.idx = j; bs.maxMinute = stopMaxMinute[j]; bs.maxTourists = stopMaxTourists[j]; bsVec.push_back(bs); } } sort(bsVec.begin(), bsVec.end(), bsComp); for (int j = 0; j < bsVec.size(); j++) tmp.push_back(bsVec[j].idx); closest.push_back(tmp); tmp.clear(); ll maxi = LLONG_MAX; ll save = -1; for (int j = 0; j < unused.size(); j++) { ll ii = differentIdxs[i], jj = unused[j]; if (ii != jj) { ll val = abs(stops[ii].first - stops[jj].first) + abs(stops[ii].second - stops[jj].second); if (val < maxi) { maxi = val; save = j; } } } if (save != -1) closestUnused.push_back(save); } for (int i = 0; i < differentIdxs.size(); i++) { ump.clear(); ll ii = differentIdxs[i]; ll currScore = 0LL; ump[i] = 1; vector chain; chain.push_back(ii); ll prev = i; while (chain.size() < differentIdxs.size()) { for (int j = 0; j < closest[prev].size(); j++) { if (ump[closest[prev][j]] == 0) { ump[closest[prev][j]] = 1; chain.push_back(differentIdxs[closest[prev][j]]); prev = closest[prev][j]; break; } } } //try cyclic routes chain.push_back(ii); ll time = buses[busIdx].second * 1LL; for (int j = 0; j < chain.size() - 1; j++) time += abs(stops[chain[j]].first - stops[chain[j + 1]].first) + abs(stops[chain[j]].second - stops[chain[j + 1]].second); ll distance = time - buses[busIdx].second * 1LL; ll total = (t - max(minMin, maxMin - d)) / time; if (time < bestScore) { ansFirstPart.clear(); ansSecondPart.clear(); bestScore = time; for (int j = 0; j < chain.size(); j++) ansFirstPart.push_back(chain[j] + 1); ansTotal = total; if (d != -1) ansTotal = min(ansTotal, d/distance); ll curr = max(minMin, maxMin - d); for (int i = 0; i < ansTotal; i++) { ansSecondPart.push_back(curr); curr += time * 1LL; } } //try normal routes if(closestUnused.size() > 0) { chain[chain.size() - 1] = unused[closestUnused[prev]]; ll time = buses[busIdx].second * 1LL; for (int j = 0; j < chain.size() - 1; j++) time += abs(stops[chain[j]].first - stops[chain[j + 1]].first) + abs(stops[chain[j]].second - stops[chain[j + 1]].second); ll distance = time - buses[busIdx].second * 1LL; ll total = (t - max(minMin, maxMin - d)) / time; if (time < bestScore) { ansFirstPart.clear(); ansSecondPart.clear(); bestScore = time; for (int j = 0; j < chain.size(); j++) ansFirstPart.push_back(chain[j] + 1); ansTotal = total; if (d != -1) ansTotal = min(ansTotal, d/distance); ll curr = max(minMin, maxMin - d); for (int i = 0; i < ansTotal; i++) { ansSecondPart.push_back(curr); curr += time * 1LL; } } } } for (int i = 0; i < busIdx; i++) cout<<"0\n0\n"; cout << ansFirstPart.size() << " "; for (int i = 0; i < ansFirstPart.size(); i++) cout << ansFirstPart[i] << " "; cout << "\n" << ansTotal << " "; for (int i = 0; i < ansSecondPart.size(); i++) cout << ansSecondPart[i] << " "; cout << "\n"; for (int i = busIdx + 1; i < m ; i++) cout << "0\n0\n"; return 0; }