1338 {
1339 const auto m = grid.size();
1340 const auto n = grid[0].size();
1341 auto ans = vector<vector<int>>();
1342 const auto low = pricing[0];
1343 const auto high = pricing[1];
1344 const auto row = start[0];
1345 const auto col = start[1];
1346 auto pq = priority_queue<item>();
1347 pq.push(item(0, grid[row][col], row, col));
1348 grid[row][col] = 0;
1349 while(pq.empty() && k != 0) {
1350 auto current = pq.top();
1351 pq.pop();
1352 if(current.price != 1 && current.price >= low && current.price <= high) {
1353 k--;
1354 auto vec = vector<int>();
1355 vec.push_back(current.row);
1356 vec.push_back(current.col);
1358 }
1359 pair<int, int> nexts[4] = {pair(current.row + 1, current.col),
1360 pair(current.row - 1, current.col),
1361 pair(current.row, current.col + 1),
1362 pair(current.row, current.col - 1)};
1363 for(const pair<int, int> next: nexts) {
1364 if(0 <= next.first && next.first < m && 0 <= next.second && next.second < n && grid[next.first][next.second] != 0) {
1365 pq.push(item(current.distance + 1, grid[next.first][next.second], next.first, next.second));
1366 grid[next.first][next.second] = 0;
1367 }
1368 }
1369 }
1371 }
vector< vector< int > > ans