/* Problem URL: https://codeforces.com/contest/609/problem/D */ #include #include #include using namespace std; using namespace __gnu_pbds; template > using ordered_set = tree; #define V vector #define rmin(a, b) a = min(a, b) #define rmax(a, b) a = max(a, b) #define rep(i, lim) for (int i = 0; i < (lim); i++) #define nrep(i, s, lim) for (int i = s; i < (lim); i++) #define repv(i, v) for (auto &i : (v)) #define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; } #define sortv(v) sort(v.begin(), v.end()) #define all(v) (v).begin(), (v).end() using vi = vector; using vvi = vector; using vvvi = vector; using vvvvi = vector; using ll = long long; using vl = vector; using vvl = vector; using vvvl = vector; using vvvvl = vector; template auto operator<<(ostream &os, const vector &vec)->ostream& { os << vec[0]; for (size_t i = 1; i < vec.size(); i++) { os << ' ' << vec[i]; } os << '\n'; return os; } template auto operator>>(istream &is, vector &vec)->istream& { for (auto &i : vec) { is >> i; } return is; } template auto operator<<(ostream &os, const vector> &vec)->ostream& { for (auto &i : vec) { os << i[0]; for (size_t j = 1; j < i.size(); j++) { os << ' ' << i[j]; } os << '\n'; } return os; } template auto operator>>(istream &is, vector> &vec)->istream& { for (auto &i : vec) { for (auto &j : i) { is >> j; } } return is; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m, k; ll s; cin >> n >> m >> k >> s; vl cost[2] = {vl(n), vl(n)}; cin >> cost[0]; cin >> cost[1]; nrep(i, 1, n) { rmin(cost[0][i], cost[0][i - 1]); rmin(cost[1][i], cost[1][i - 1]); } V> gad[2]; rep(i, m) { int t; ll c; cin >> t >> c; gad[t - 1].emplace_back(c, i); } sortv(gad[0]); sortv(gad[1]); ll sum1 = 0; ll sum2 = 0; int i = 0; int j = 0; for (; i < min((int)gad[0].size(), k); i++) { sum1 += gad[0][i].first; } for (; j < k - i; j++) { sum2 += gad[1][j].first; } int oo = INT32_MAX >> 1; int ansi = -1; int ansj = -1; int ans = oo; while (i >= 0 && j <= gad[1].size()) { int low = 0; int high = n - 1; int act = -1; while (low <= high) { int mid = (low + high) >> 1; ll now = sum1 * cost[0][mid] + sum2 * cost[1][mid]; if (now <= s) { act = mid; high = mid - 1; continue; } low = mid + 1; } if (act == -1) { if (j == gad[1].size()) { break; } i--; sum1 -= gad[0][i].first; sum2 += gad[1][j].first; j++; continue; } if (act < ans) { ans = act; ansi = i; ansj = j; } if (j == gad[1].size()) { break; } i--; sum1 -= gad[0][i].first; sum2 += gad[1][j].first; j++; } if (ans == oo) { cout << "-1\n"; return 0; } int choice1 = 0; int choice2 = 0; nrep(i, 1, ans + 1) { if (cost[0][i] < cost[0][i - 1]) { choice1 = i; } if (cost[1][i] < cost[1][i - 1]) { choice2 = i; } } cout << ans + 1 << '\n'; rep(k, ansi) { cout << gad[0][k].second + 1 << ' ' << choice1 + 1 << '\n'; } rep(k, ansj) { cout << gad[1][k].second + 1 << ' ' << choice2 + 1 << '\n'; } }