-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3541.h
51 lines (43 loc) · 762 Bytes
/
3541.h
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
#pragma once
#include <iostream>
#include <climits>
using namespace std;
int N, M;
int u[2000];
int d[2000];
int search(int idx) {
int start = 0;
int end = N;
int mid = (start + end) / 2;
int ret = INT_MAX;
while (start <= end) {
mid = (start + end) / 2;
int result = u[idx] * mid - d[idx] * (N - mid);
if (result < 1)
start = mid+1;
else if (result > 1) {
end = mid - 1;
ret = min(result, ret);
}
else {
break;
ret = min(result, ret);
}
}
return ret;
}
int main_3541() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> N;
cin >> M;
for (int i = 0; i < M; i++) {
cin >> u[i];
cin >> d[i];
}
int ret = INT_MAX;
for(int i=0;i<M;i++)
ret = min(ret, search(i));
cout << ret << endl;
return 0;
}