/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 320.0 KiB
#2 Wrong Answer 2ms 532.0 KiB
#3 Wrong Answer 2ms 324.0 KiB
#4 Wrong Answer 2ms 320.0 KiB
#5 Wrong Answer 3ms 324.0 KiB
#6 Wrong Answer 21ms 588.0 KiB
#7 Wrong Answer 200ms 1.492 MiB
#8 Wrong Answer 194ms 1.25 MiB
#9 Wrong Answer 199ms 1.387 MiB
#10 Wrong Answer 196ms 756.0 KiB
#11 Wrong Answer 197ms 1.254 MiB

Code

 #include <bits/stdc++.h>
using namespace std;

bool canAchieveTarget(long long n, long long k, long long target) {
    // To make all elements at least `target`, each element needs to be incremented to `target`
    // The total operations needed to achieve this
    long long requiredOps = target * n;  // Total operations needed to set all elements to `target`

    return k >= requiredOps;  // Check if we have enough operations
}

void solve() {
    long long n, k;
    cin >> n >> k;

    // Binary search for the maximum value of `target` (Y)
    long long left = 0, right = k / n, bestTarget = 0;

    while (left <= right) {
        long long mid = (left + right) / 2;

        if (canAchieveTarget(n, k, mid)) {
            bestTarget = mid;
            left = mid + 1;  // Try for a larger target
        } else {
            right = mid - 1;  // Try for a smaller target
        }
    }

    // The final result is X * Y, where X = K - (N * bestTarget)
    long long X = k - (n * bestTarget);
    long long Y = bestTarget;

    cout << X * Y << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int t;
    cin >> t;

    while (t--) {
        solve();
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1092 Bitwise AND
Contest
Brain Booster #5
Language
C++17 (G++ 13.2.0)
Submit At
2024-09-05 16:51:40
Judged At
2024-10-03 13:05:53
Judged By
Score
1
Total Time
200ms
Peak Memory
1.492 MiB