Submission #209547

# Submission time Handle Problem Language Result Execution time Memory
209547 2020-03-14T14:05:07 Z kdaojv Just Long Neckties (JOI20_ho_t1) C++14
0 / 100
5 ms 256 KB
#include<bits/stdc++.h>
using namespace std;
int gu[100010],itv[100010];
int main()
{
    int n,k,i,cnt=1;
    scanf("%d %d",&n,&k);
    for(i=1;i<=n;i++){
        scanf("%d",&gu[i]);
    }
    if(n<=k){
        printf("%d",n);
        return 0;
    }
    sort(gu+1,gu+1+n);
    for(i=2;i<=n;i++){
        if(gu[i]-gu[i-1]>1){
            cnt++;
            itv[cnt-1]=gu[i]-gu[i-1]-1;
        }
    }
    if(cnt<=k){
        printf("%d",n);
        return 0;
    }
    sort(itv+1,itv+cnt);
    for(i=1;i<=(cnt-k);i++){
        n+=itv[i];
    }
    printf("%d",n);
    return 0;
}

Compilation message

ho_t1.cpp: In function 'int main()':
ho_t1.cpp:7:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d",&n,&k);
     ~~~~~^~~~~~~~~~~~~~~
ho_t1.cpp:9:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&gu[i]);
         ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -