Submission #59597190


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main(){
    int n,m;
    cin>>n>>m;
    vector<int>a(m),b(m);
    map<int,int,greater<int>>v;
    for(int i=0;i<m;i++)cin>>a[i];
    for(int i=0;i<m;i++){
        cin>>b[i];
        v[a[i]]=b[i];
    }
    int last=n;
    int ans=0;
    bool flag=true;
    for(auto &val:v){
        int i=val.first;
        int c=val.second;
        int give=last-i+1;
        if(give==c){
            give--;
            ans=ans+((give)*1ll*(give+1ll))/2ll;
            last=i-1;
        }
        else if(give<c){
            flag=false;
            break;
        }
        else{
            last-=c;
            ans=ans+(last-i+1)*c;
            c--;
            ans=ans+(c*1ll*(c+1))/2ll;
        }
    }
    if(last||!flag)cout<<-1<<endl;
    else cout<<ans<<endl;
}

Submission Info

Submission Time
Task C - Sowing Stones
User shaik1967
Language C++ 20 (gcc 12.2)
Score 300
Code Size 870 Byte
Status AC
Exec Time 158 ms
Memory 18740 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 2
AC × 43
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt
All 00_sample_00.txt, 00_sample_01.txt, 01_random_00.txt, 01_random_01.txt, 01_random_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, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 02_hand_00.txt, 02_hand_01.txt, 02_hand_02.txt, 02_hand_03.txt, 02_hand_04.txt, 02_hand_05.txt, 02_hand_06.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3532 KiB
00_sample_01.txt AC 1 ms 3492 KiB
01_random_00.txt AC 80 ms 13412 KiB
01_random_01.txt AC 84 ms 13948 KiB
01_random_02.txt AC 116 ms 18112 KiB
01_random_03.txt AC 79 ms 13728 KiB
01_random_04.txt AC 73 ms 12908 KiB
01_random_05.txt AC 92 ms 14680 KiB
01_random_06.txt AC 105 ms 16844 KiB
01_random_07.txt AC 94 ms 15568 KiB
01_random_08.txt AC 124 ms 17432 KiB
01_random_09.txt AC 136 ms 18420 KiB
01_random_10.txt AC 56 ms 9980 KiB
01_random_11.txt AC 76 ms 12356 KiB
01_random_12.txt AC 39 ms 8960 KiB
01_random_13.txt AC 45 ms 10024 KiB
01_random_14.txt AC 47 ms 9976 KiB
01_random_15.txt AC 60 ms 11776 KiB
01_random_16.txt AC 158 ms 17888 KiB
01_random_17.txt AC 108 ms 13324 KiB
01_random_18.txt AC 35 ms 6736 KiB
01_random_19.txt AC 81 ms 11316 KiB
01_random_20.txt AC 144 ms 18636 KiB
01_random_21.txt AC 135 ms 18688 KiB
01_random_22.txt AC 135 ms 18736 KiB
01_random_23.txt AC 136 ms 18644 KiB
01_random_24.txt AC 144 ms 18636 KiB
01_random_25.txt AC 138 ms 18632 KiB
01_random_26.txt AC 141 ms 18740 KiB
01_random_27.txt AC 136 ms 18676 KiB
01_random_28.txt AC 1 ms 3456 KiB
01_random_29.txt AC 1 ms 3456 KiB
01_random_30.txt AC 1 ms 3456 KiB
01_random_31.txt AC 1 ms 3452 KiB
01_random_32.txt AC 1 ms 3648 KiB
01_random_33.txt AC 1 ms 3492 KiB
02_hand_00.txt AC 147 ms 16780 KiB
02_hand_01.txt AC 96 ms 12564 KiB
02_hand_02.txt AC 54 ms 10728 KiB
02_hand_03.txt AC 35 ms 8336 KiB
02_hand_04.txt AC 1 ms 3464 KiB
02_hand_05.txt AC 1 ms 3452 KiB
02_hand_06.txt AC 140 ms 18604 KiB