/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 504.0 KiB
#2 Wrong Answer 2ms 332.0 KiB
#3 Wrong Answer 3ms 568.0 KiB
#4 Wrong Answer 3ms 492.0 KiB
#5 Wrong Answer 4ms 580.0 KiB
#6 Wrong Answer 19ms 656.0 KiB
#7 Wrong Answer 162ms 1.496 MiB
#8 Wrong Answer 178ms 1.332 MiB
#9 Wrong Answer 176ms 1.426 MiB
#10 Wrong Answer 164ms 860.0 KiB
#11 Wrong Answer 157ms 1.422 MiB

Code

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

// Function to check if we can achieve a target value for all elements with at most `k` operations
bool canAchieveTarget(int n, int k, int target) {
    // Total operations needed to set all elements to at least `target`
    int requiredOps = target * n;
    return requiredOps <= k;
}

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

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

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

        if (canAchieveTarget(n, k, mid)) {
            bestTarget = mid; // This target is achievable, try for a larger one
            left = mid + 1;
        } else {
            right = mid - 1;
        }
    }

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

    // Print the result
    cout << X * Y << endl;
}

signed 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 17:04:52
Judged At
2024-10-03 13:05:23
Judged By
Score
1
Total Time
178ms
Peak Memory
1.496 MiB