Submission #38834499


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define all(v) v.begin(),v.end() 
typedef long long ll;
typedef pair<int, int> pii;

int dm=0;

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

    int b[n]; 
    long long ans[m];
    pair<int, int> c[m]; 
    for(int i=0; i<n; i++) cin>>b[i];
    
    for(int i=0; i<m; i++){
        cin>>c[i].first;
        c[i].second = i;
    }
    sort(b, b+n, greater<int>());
    sort(c, c+m);

    function<void(int, int, int, int)> solve = [&](int st, int end, int sst, int send){
        if(sst == send){
            for(int i=st; i<=end; i++){
                ans[c[i].second] = sst * (ll)(b[sst-1]+c[i].first);
            }
        }
        else if(st == end){
            auto [x, idx] = c[st];
            ans[idx] = 0;
            for(int t=sst; t<=send; t++){
                ans[idx] = max(ans[idx], t * (ll)(b[t-1] + x));
            }
        }
        else if(st<=end){
            int mid = (st+end)/2;
            auto [x, idx] = c[mid];
            int k = -1;
            ans[idx] = 0;
            for(int t=sst; t<=send; t++){
                long long curans = t * (ll)(b[t-1] + x);
                if(curans > ans[idx]){
                    k = t;
                    ans[idx] = curans;
                }
            }

            solve(st, mid-1, sst, k);
            solve(mid+1, end, k, send);

        }
    };

    solve(0, m-1, 1, n);

    for(int i=0; i<m; i++) cout << ans[i] << " ";


}

int main()
{
    #ifndef ONLINE_JUDGE
        dm = 1;
        freopen("input.txt", "r", stdin);
    #endif 
    if(!dm){ios::sync_with_stdio(false);cin.tie(0);}
    int t = 1;
    //cin >> t;
    while (t--)solve();
}

Submission Info

Submission Time
Task G - Shopping in AtCoder store
User nk12384
Language C++ (GCC 9.2.1)
Score 600
Code Size 1764 Byte
Status AC
Exec Time 94 ms
Memory 7608 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 4
AC × 37
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 02_handmade_23.txt, 02_handmade_24.txt, 02_handmade_25.txt, 02_handmade_26.txt, 02_handmade_27.txt, 02_handmade_28.txt, 02_handmade_29.txt, 02_handmade_30.txt, 02_handmade_31.txt, 02_handmade_32.txt, 02_handmade_33.txt, 02_handmade_34.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 6 ms 3572 KiB
00_sample_01.txt AC 2 ms 3624 KiB
00_sample_02.txt AC 2 ms 3520 KiB
00_sample_03.txt AC 2 ms 3608 KiB
01_random_03.txt AC 85 ms 7476 KiB
01_random_04.txt AC 89 ms 7532 KiB
01_random_05.txt AC 89 ms 7528 KiB
01_random_06.txt AC 91 ms 7396 KiB
01_random_07.txt AC 90 ms 7492 KiB
01_random_08.txt AC 94 ms 7504 KiB
01_random_09.txt AC 89 ms 7480 KiB
01_random_10.txt AC 89 ms 7452 KiB
01_random_11.txt AC 87 ms 7576 KiB
01_random_12.txt AC 91 ms 7516 KiB
01_random_13.txt AC 89 ms 7532 KiB
01_random_14.txt AC 30 ms 4128 KiB
01_random_15.txt AC 40 ms 5072 KiB
01_random_16.txt AC 57 ms 5860 KiB
01_random_17.txt AC 77 ms 7068 KiB
01_random_18.txt AC 40 ms 5424 KiB
01_random_19.txt AC 35 ms 4356 KiB
01_random_20.txt AC 35 ms 4820 KiB
01_random_21.txt AC 33 ms 4584 KiB
01_random_22.txt AC 68 ms 6896 KiB
01_random_23.txt AC 55 ms 6288 KiB
02_handmade_23.txt AC 25 ms 4432 KiB
02_handmade_24.txt AC 24 ms 4392 KiB
02_handmade_25.txt AC 49 ms 7488 KiB
02_handmade_26.txt AC 67 ms 7540 KiB
02_handmade_27.txt AC 61 ms 7532 KiB
02_handmade_28.txt AC 63 ms 7460 KiB
02_handmade_29.txt AC 70 ms 7608 KiB
02_handmade_30.txt AC 60 ms 6724 KiB
02_handmade_31.txt AC 60 ms 6832 KiB
02_handmade_32.txt AC 59 ms 6688 KiB
02_handmade_33.txt AC 64 ms 6752 KiB
02_handmade_34.txt AC 74 ms 7524 KiB