/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 320.0 KiB
#2 Accepted 1ms 532.0 KiB
#3 Accepted 1ms 320.0 KiB
#4 Accepted 2ms 328.0 KiB
#5 Accepted 2ms 356.0 KiB
#6 Accepted 4ms 576.0 KiB
#7 Accepted 30ms 1.758 MiB
#8 Accepted 30ms 1.668 MiB
#9 Accepted 30ms 1.734 MiB
#10 Accepted 28ms 2.125 MiB
#11 Accepted 30ms 2.02 MiB

Code

#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll fun(int n, ll k)
{
    ll max_v = k / n;
    ll optimal_v = k / (2 * n);
    ll ans = 0;

    for (ll v : {optimal_v, optimal_v - 1, optimal_v + 1})
    {
        if (v < 0)
            continue;
        ll Y = v;
        ll X = k - n * v;
        if (X >= 0)
        {
            ans = max(ans, X * Y);
        }
    }

    return ans;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T;
    cin >> T;

    while (T--)
    {
        int n;
        ll k;
        cin >> n >> k;

        cout << fun(n, k) << '\n';
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1092 Bitwise AND
Contest
Brain Booster #5
Language
C++20 (G++ 13.2.0)
Submit At
2024-09-05 17:19:38
Judged At
2024-11-11 02:58:23
Judged By
Score
100
Total Time
30ms
Peak Memory
2.125 MiB