voidsolve(vector<int>& fruits, vector<int>& heights, int k){ int left = 0, maxLength = 0; while (left < fruits.size()) { int curFruit = 0; int curHeight = heights[left]; int right = left; while (right < fruits.size() && (curHeight % heights[right] == 0)) { curFruit += fruits[right]; curHeight = heights[right++]; while (curFruit > k && left < right) { curFruit -= fruits[left++]; } maxLength = max(maxLength, right - left); } left = right; } out << maxLength << endl; }
intmain(){ int tc; in >> tc; for (int t = 1; t <= tc; t++) { int n, k; in >> n >> k; vector<int> fruits, heights; for (int i = 0; i < n; i++) { int fruit; in >> fruit; fruits.push_back(fruit); } for (int i = 0; i < n; i++) { int height; in >> height; heights.push_back(height); } solve(fruits, heights, k); } return0; }