Submission #1137847

#TimeUsernameProblemLanguageResultExecution timeMemory
1137847eggx50000Taxis (POI13_tak)C++20
90 / 100
83 ms4168 KiB
#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
#include <random>
using namespace std;
using ll = long long;
const ll mod = 1000000007;

int n;
ll m, d, arr[500099];
int main()
{
    scanf("%lld %lld %d", &m, &d, &n);
    for(int i = 1; i <= n; i ++){
        scanf("%lld", arr + i);
    }
    sort(arr + 1, arr + n + 1);
    reverse(arr + 1, arr + n + 1);
    ll h = 0;
    int r = n + 1;
    for(int i = 1; i <= n; i ++){
        if(abs(d - h) > arr[i]) continue;
        h += arr[i] - abs(d - h);
        if(h >= m){
            r = min(r, i);
            break;
        }
        if(h >= d) break;
    }
    arr[0] = 3e18;
    int c = 0;
    for(int i = n; i >= 1; i --){
        if(m - d <= arr[i] && arr[i] < arr[c]){
            c = i;
            break;
        }
    }
    if(c){
        h = 0;
        int k = 1;
        for(int i = 1; i <= n; i ++){
            if(i == c) continue;
            k ++;
            h += arr[i] - abs(d - h);
            if(arr[c] >= abs(d - h) + abs(h - m)){
                r = min(r, k);
                break;
            }
        }
    }
    if(r <= n) printf("%d", r);
    else printf("0");
    return 0;
}

Compilation message (stderr)

tak.cpp: In function 'int main()':
tak.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     scanf("%lld %lld %d", &m, &d, &n);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
tak.cpp:16:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |         scanf("%lld", arr + i);
      |         ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...