[HDU-5246] Super ACMer (Greedy), hdu-5246acmer

Source: Internet
Author: User

[HDU-5246] Super ACMer (Greedy), hdu-5246acmer

Previously, an nlogn algorithm times out and can only be changed to an n algorithm.

The greedy idea of the big question is to sort the abilities of each person from small to large. The current competency value is now, so we can find a person's abilities to make this competency value <= now, now + the ability of this person to continue searching

In this case, we ran more than 600 MS. It seems that the nlogn's TLE was not inappropriate ..

#include<cstdio>#include<cstring>#include<algorithm>using namespace std;typedef long long LL;const int maxn = 10005;LL arr[maxn];LL m,k;int n;int main(){    int T,Case = 1;    scanf("%d",&T);    while(T--){        scanf("%d%I64d%I64d",&n,&m,&k);        for(int i = 0; i < n; i++)            scanf("%I64d",&arr[i]);        sort(arr,arr + n);        LL now = m;        int ok = 0;        printf("Case #%d:\n",Case++);        if(m < arr[0]){            printf("madan!\n");            continue;        }        for(int i = 0; i < n; ){            if(arr[i] <= now) i ++;            else{                now = arr[i - 1] + k;                if(now < arr[i]) break;                else i++;                k --;            }            if(i == n){                ok = 1;                break;            }        }        if(ok)            printf("why am I so diao?\n");        else            printf("madan!\n");    }    return 0;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.