算法
开4个数组,从最后一层地毯依次向下扫一遍就行了
C++ 代码
#include <iostream>
using namespace std;
const int N = 1e4 + 10;
int n, a[N], b[N], g[N], k[N], x, y;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i] >> b[i] >> g[i] >> k[i];
}
cin >> x >> y;
for (int i = n; i >= 1; i--) {
if (a[i] <= x && b[i] <= y && a[i] + g[i] >= x && b[i] + k[i] >= y) {
cout << i << endl;
return 0;
}
}
cout << -1 << endl;
return 0;
}