Submission #63415775


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10;

int n;ll x;
ll a[N],b[N];

bool check(ll mid)
{
    ll w=a[1]+b[1]-mid;
    ll r=a[1],l=max(0ll,a[1]-w);
    for(int i=2;i<=n;i++)
    {
        w=a[i]+b[i]-mid;
        ll r1=a[i],l1=max(0ll,a[i]-w);
        l=max(0ll,l-x),r=r+x;
        l=max(l,l1), r=min(r,r1);
        if(l>r) return 0;
    }
    return 1;
}

int main()
{
    scanf("%d%lld",&n,&x);
    ll mx=0x3f3f3f3f3f3f3f3f;
    for(int i=1;i<=n;i++) scanf("%lld%lld",&a[i],&b[i]),mx=min(mx,a[i]+b[i]);
    ll l=0,r=mx,mid,ans=0;
    while(l<=r)
    {
        mid=(l+r)>>1;
        if(check(mid)) ans=mid,l=mid+1;
        else r=mid-1;
    }
    ll val=0;
    for(int i=1;i<=n;i++) val+=a[i]+b[i]-ans;
    printf("%lld\n",val);
}

Submission Info

Submission Time
Task F - Smooth Occlusion
User cjh_hhz
Language C++ 20 (gcc 12.2)
Score 500
Code Size 814 Byte
Status AC
Exec Time 49 ms
Memory 6964 KiB

Compile Error

Main.cpp: In function ‘int main()’:
Main.cpp:26:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   26 |     scanf("%d%lld",&n,&x);
      |     ~~~~~^~~~~~~~~~~~~~~~
Main.cpp:28:32: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   28 |     for(int i=1;i<=n;i++) scanf("%lld%lld",&a[i],&b[i]),mx=min(mx,a[i]+b[i]);
      |                           ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 4
AC × 69
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_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, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 01_random_40.txt, 01_random_41.txt, 01_random_42.txt, 01_random_43.txt, 01_random_44.txt, 01_random_45.txt, 01_random_46.txt, 01_random_47.txt, 01_random_48.txt, 01_random_49.txt, 01_random_50.txt, 01_random_51.txt, 01_random_52.txt, 01_random_53.txt, 01_random_54.txt, 01_random_55.txt, 01_random_56.txt, 01_random_57.txt, 01_random_58.txt, 01_random_59.txt, 01_random_60.txt, 01_random_61.txt, 01_random_62.txt, 01_random_63.txt, 01_random_64.txt, 01_random_65.txt, 01_random_66.txt, 01_random_67.txt, 01_random_68.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3604 KiB
00_sample_01.txt AC 1 ms 3784 KiB
00_sample_02.txt AC 1 ms 3848 KiB
00_sample_03.txt AC 1 ms 3736 KiB
01_random_04.txt AC 44 ms 6680 KiB
01_random_05.txt AC 45 ms 6652 KiB
01_random_06.txt AC 44 ms 6720 KiB
01_random_07.txt AC 44 ms 6892 KiB
01_random_08.txt AC 45 ms 6792 KiB
01_random_09.txt AC 47 ms 6836 KiB
01_random_10.txt AC 44 ms 6780 KiB
01_random_11.txt AC 46 ms 6792 KiB
01_random_12.txt AC 45 ms 6808 KiB
01_random_13.txt AC 46 ms 6892 KiB
01_random_14.txt AC 46 ms 6792 KiB
01_random_15.txt AC 47 ms 6812 KiB
01_random_16.txt AC 45 ms 6804 KiB
01_random_17.txt AC 46 ms 6964 KiB
01_random_18.txt AC 45 ms 6824 KiB
01_random_19.txt AC 44 ms 6836 KiB
01_random_20.txt AC 44 ms 6788 KiB
01_random_21.txt AC 46 ms 6952 KiB
01_random_22.txt AC 44 ms 6784 KiB
01_random_23.txt AC 45 ms 6820 KiB
01_random_24.txt AC 45 ms 6892 KiB
01_random_25.txt AC 46 ms 6796 KiB
01_random_26.txt AC 45 ms 6828 KiB
01_random_27.txt AC 46 ms 6812 KiB
01_random_28.txt AC 44 ms 6792 KiB
01_random_29.txt AC 46 ms 6796 KiB
01_random_30.txt AC 43 ms 6772 KiB
01_random_31.txt AC 46 ms 6896 KiB
01_random_32.txt AC 45 ms 6812 KiB
01_random_33.txt AC 49 ms 6724 KiB
01_random_34.txt AC 40 ms 6516 KiB
01_random_35.txt AC 41 ms 6536 KiB
01_random_36.txt AC 14 ms 4528 KiB
01_random_37.txt AC 3 ms 3852 KiB
01_random_38.txt AC 23 ms 5188 KiB
01_random_39.txt AC 37 ms 6232 KiB
01_random_40.txt AC 8 ms 4168 KiB
01_random_41.txt AC 19 ms 4928 KiB
01_random_42.txt AC 26 ms 5452 KiB
01_random_43.txt AC 22 ms 5324 KiB
01_random_44.txt AC 33 ms 6052 KiB
01_random_45.txt AC 17 ms 4760 KiB
01_random_46.txt AC 34 ms 6948 KiB
01_random_47.txt AC 34 ms 6792 KiB
01_random_48.txt AC 35 ms 6820 KiB
01_random_49.txt AC 26 ms 6812 KiB
01_random_50.txt AC 34 ms 6896 KiB
01_random_51.txt AC 45 ms 6652 KiB
01_random_52.txt AC 45 ms 6832 KiB
01_random_53.txt AC 46 ms 6660 KiB
01_random_54.txt AC 43 ms 6804 KiB
01_random_55.txt AC 44 ms 6708 KiB
01_random_56.txt AC 45 ms 6948 KiB
01_random_57.txt AC 45 ms 6812 KiB
01_random_58.txt AC 41 ms 6836 KiB
01_random_59.txt AC 44 ms 6900 KiB
01_random_60.txt AC 45 ms 6952 KiB
01_random_61.txt AC 39 ms 6800 KiB
01_random_62.txt AC 45 ms 6792 KiB
01_random_63.txt AC 49 ms 6776 KiB
01_random_64.txt AC 49 ms 6784 KiB
01_random_65.txt AC 48 ms 6796 KiB
01_random_66.txt AC 47 ms 6832 KiB
01_random_67.txt AC 1 ms 3740 KiB
01_random_68.txt AC 1 ms 3700 KiB