-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflorarie.cpp
84 lines (63 loc) · 1.37 KB
/
florarie.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <limits.h>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <string>
#include <algorithm>
#include <bitset>
//#include <unordered_map>
using namespace std;
typedef pair<int, int> ii;
#define traverse(c, it) \
for (vector<int>::iterator it = c.begin(); it != c.end(); it++)
int N, M, K;
int cost[1020][1020];
int row, col;
int closestCost;
int r, c;
void findClosest(int budget) {
row = 0; col = 0;
closestCost = INT_MIN;
r = 0; c = 0;
while(row < N && col < M) {
if(cost[row][col] == budget) {
r = row;
c = col;
break;
}
if(cost[row][col] <= budget) {
if(cost[row][col] > closestCost) {
closestCost = cost[row][col];
r = row;
c = col;
}
}
if(cost[row][col] < budget) {
col++;
} else {
row++;
}
}
}
int main() {
cin >> N >> M;
memset(cost, -1, sizeof(cost));
for(int i = 0; i < N; i++) {
for(int j = 0; j < M; j++) {
cin >> cost[i][j];
}
}
cin >> K;
int budget;
for(int i = 0; i < K; i++) {
cin >> budget;
findClosest(budget);
cout << r << " " << c << endl;
}
return 0;
}