Update Code
This commit is contained in:
parent
812e0560da
commit
711f39698c
|
@ -0,0 +1,42 @@
|
|||
#include <iostream>
|
||||
#define MAXN 1000000
|
||||
|
||||
bool check(int n, int nn, int *C, int *M, int A) {
|
||||
int count = 0, i, j;
|
||||
i = nn;
|
||||
j = 1;
|
||||
while (i <= n) {
|
||||
if (M[i] < C[j]) {
|
||||
count += C[j] - M[i];
|
||||
}
|
||||
i++;
|
||||
j++;
|
||||
}
|
||||
return count <= A;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int n, M[MAXN], C[MAXN], mid, ans, B, A;
|
||||
std::cin >> n >> B >> A; // N:Students B:Bike Nums A:School Money M:Student
|
||||
// Money C:Student Bike Money
|
||||
for (int i = 1; i <= n; i++) {
|
||||
std::cin >> M[i];
|
||||
}
|
||||
for (int i = 1; i <= n; i++) {
|
||||
std::cin >> C[i];
|
||||
}
|
||||
// sort()
|
||||
// sort()
|
||||
int l = 0, r = n;
|
||||
while (l <= r) {
|
||||
mid = (l + r) / 2;
|
||||
if (check(n, mid, C, M, A)) {
|
||||
ans = mid;
|
||||
l = mid + 1;
|
||||
} else {
|
||||
r = mid - 1;
|
||||
}
|
||||
}
|
||||
std::cout << ans << std::endl;
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue