/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 332.0 KiB
#2 Accepted 2ms 332.0 KiB
#3 Accepted 2ms 540.0 KiB
#4 Accepted 2ms 488.0 KiB
#5 Accepted 2ms 560.0 KiB
#6 Accepted 6ms 660.0 KiB
#7 Accepted 49ms 1.934 MiB
#8 Accepted 46ms 1.566 MiB
#9 Accepted 48ms 1.816 MiB
#10 Accepted 43ms 2.273 MiB
#11 Accepted 52ms 2.184 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-10-03 13:04:40
Judged By
Score
100
Total Time
52ms
Peak Memory
2.273 MiB