/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 492.0 KiB
#2 Accepted 2ms 540.0 KiB
#3 Accepted 2ms 512.0 KiB
#4 Accepted 2ms 492.0 KiB
#5 Accepted 2ms 584.0 KiB
#6 Accepted 4ms 540.0 KiB
#7 Accepted 28ms 2.02 MiB
#8 Accepted 28ms 1.52 MiB
#9 Accepted 28ms 1.77 MiB
#10 Accepted 27ms 2.328 MiB
#11 Accepted 26ms 1.984 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-09-05 17:19:38
Judged By
Score
100
Total Time
28ms
Peak Memory
2.328 MiB