Submission #14454

#TimeUsernameProblemLanguageResultExecution timeMemory
14454yys980정전 (OJUZ10_blackout)C++98
50 / 100
50 ms5772 KiB
#include <stdio.h>
#include <algorithm>
using namespace std;
int n,l,sum;
int slight[300000],elight[300000];
int allight[300000][2],acnt;
int main()
{
    scanf("%d %d",&n, &l);
    int i;
    for(i = 1 ; i <= n ; i++){
        scanf("%d",&slight[i]);
        slight[i]-=l;
    }
    sort(slight+1,slight+1+n);
    for(i = 1 ; i <= n ; i++){
        elight[i]=slight[i]+l*2;
    }
    for(i = 1 ; i < n ; i++){
        if(slight[i+1] >= elight[i])continue;
        allight[acnt][0]=slight[i+1];
        allight[acnt][1]=elight[i];
        if(acnt>=1 && allight[acnt][0]<allight[acnt-1][1]){
            allight[acnt-1][1]=allight[acnt][1];
            allight[acnt][0]=allight[acnt][1]=0;
        }
        else acnt++;
    }
    for(i = 0 ; i < acnt ; i++){
        sum+=(allight[i][1]-allight[i][0]);
    }
    printf("%d",sum);
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...