Submission #68125775


Source Code Expand

#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
const int maxn = 10000+5;
int a[maxn],b[maxn],p[maxn];
int sum[maxn];
int dp[maxn][1005];
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin>>n;
    for (int i=1;i<=n;i++)
    {
        cin>>p[i]>>a[i]>>b[i];
        sum[i]=sum[i-1]+b[i];
    }
    for (int j=0;j<=1001;j++)
        dp[n+1][j]=j;
    for (int i=n;i>0;i--)
    {
        for (int j=0;j<=1001;j++)
        {
            if (p[i]>=j)
                dp[i][j]=dp[i+1][min(1001,j+a[i])];
            else
                dp[i][j]=dp[i+1][max(0,j-b[i])];
        }
    }
    int q;
    cin>>q;
    while (q--)
    {
        int x,d=1;
        cin>>x;
        if (x>500)
        {
            d=lower_bound(sum+1,sum+n+1,x-500)-sum;
            if (d>n)
            {
                x-=sum[n];
                cout<<x<<'\n';
                continue;
            }
            x-=sum[d];
            d++;
        }
        if (d==n+1)
            cout<<x<<'\n';
        else
            cout<<dp[d][x]<<'\n';
    }
}

Submission Info

Submission Time
Task D - Takahashi's Expectation
User Alliy666
Language C++ 23 (gcc 12.2)
Score 425
Code Size 1221 Byte
Status AC
Exec Time 81 ms
Memory 44932 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 425 / 425
Status
AC × 3
AC × 30
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.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, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3564 KiB
00_sample_01.txt AC 1 ms 3560 KiB
00_sample_02.txt AC 1 ms 3716 KiB
01_random_03.txt AC 79 ms 44892 KiB
01_random_04.txt AC 80 ms 44924 KiB
01_random_05.txt AC 80 ms 44924 KiB
01_random_06.txt AC 80 ms 44924 KiB
01_random_07.txt AC 80 ms 44820 KiB
01_random_08.txt AC 80 ms 44836 KiB
01_random_09.txt AC 80 ms 44836 KiB
01_random_10.txt AC 80 ms 44824 KiB
01_random_11.txt AC 80 ms 44840 KiB
01_random_12.txt AC 79 ms 44864 KiB
01_random_13.txt AC 79 ms 44852 KiB
01_random_14.txt AC 79 ms 44896 KiB
01_random_15.txt AC 80 ms 44804 KiB
01_random_16.txt AC 28 ms 18372 KiB
01_random_17.txt AC 24 ms 4204 KiB
01_random_18.txt AC 70 ms 35472 KiB
01_random_19.txt AC 18 ms 14996 KiB
01_random_20.txt AC 28 ms 26956 KiB
01_random_21.txt AC 64 ms 22068 KiB
01_random_22.txt AC 55 ms 6436 KiB
01_random_23.txt AC 33 ms 6204 KiB
01_random_24.txt AC 78 ms 44912 KiB
01_random_25.txt AC 79 ms 44884 KiB
01_random_26.txt AC 79 ms 44932 KiB
01_random_27.txt AC 81 ms 44812 KiB
01_random_28.txt AC 80 ms 44928 KiB
01_random_29.txt AC 80 ms 44808 KiB