Update Code

This commit is contained in:
Hmtsai 2024-01-25 18:07:29 +08:00
parent 812e0560da
commit 711f39698c
2 changed files with 58 additions and 16 deletions

View File

@ -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;
}

View File

@ -1,22 +1,22 @@
#include <iostream> #include <iostream>
int f(int p, int k, int b) { int f(int p, int k, int b) {
if (p == 0) { if (p == 0) {
return 1; return 1;
} }
int tmp = f(p / 2, k, b) % k; int tmp = f(p / 2, k, b) % k;
tmp = (tmp * tmp) % k; tmp = (tmp * tmp) % k;
if (p % 2 == 1) { if (p % 2 == 1) {
tmp = (tmp * b) % k; tmp = (tmp * b) % k;
} }
return tmp; return tmp;
} }
int main() { int main() {
int b, p, k; int b, p, k;
std::cin >> b >> p >> k; std::cin >> b >> p >> k;
int tmpb = b; int tmpb = b;
b %= k; b %= k;
std::cout << f(p, k, b) << std::endl; std::cout << f(p, k, b) << std::endl;
return 0; return 0;
} }