Submission #67540294
Source Code Expand
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
int cmp(const void *pa, const void *pb) {
long long a = *(const long long*)pa;
long long b = *(const long long*)pb;
if (a < b) return -1;
if (a > b) return 1;
return 0;
}
int main(){
int N, M;
scanf("%d %d", &N, &M);
long long X[N];
// long long strength[M];
// long long
for (int i = 0; i < N; i++) {
scanf("%lld", &X[i]);
}
qsort(X, N, sizeof(long long), cmp);
long long gap[N-1];
for(int i = 0; i < N-1; i++){
gap[i] = X[i+1] - X[i];
}
qsort(gap, N-1, sizeof(long long), cmp);
long long total_span = X[N-1] - X[0];
long long cut = 0;
long long cuts = M - 1;
if(cuts > N-1) cuts = N-1;
for(int i = 0; i < cuts; i++){
cut += gap[N-2-i];
}
long long ans = total_span - cut;
printf("%lld\n", ans);
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - Transmission Mission |
| User | oinucha |
| Language | C (gcc 12.2.0) |
| Score | 400 |
| Code Size | 959 Byte |
| Status | AC |
| Exec Time | 184 ms |
| Memory | 13476 KiB |
Compile Error
Main.c: In function ‘main’:
Main.c:15:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
15 | scanf("%d %d", &N, &M);
| ^~~~~~~~~~~~~~~~~~~~~~
Main.c:20:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
20 | scanf("%lld", &X[i]);
| ^~~~~~~~~~~~~~~~~~~~
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 400 / 400 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt |
| All | 00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00-sample-01.txt | AC | 1 ms | 1616 KiB |
| 00-sample-02.txt | AC | 1 ms | 1616 KiB |
| 00-sample-03.txt | AC | 1 ms | 1572 KiB |
| 01-01.txt | AC | 1 ms | 1728 KiB |
| 01-02.txt | AC | 1 ms | 1624 KiB |
| 01-03.txt | AC | 0 ms | 1568 KiB |
| 01-04.txt | AC | 0 ms | 1696 KiB |
| 01-05.txt | AC | 0 ms | 1624 KiB |
| 01-06.txt | AC | 1 ms | 1700 KiB |
| 01-07.txt | AC | 70 ms | 11376 KiB |
| 01-08.txt | AC | 85 ms | 11480 KiB |
| 01-09.txt | AC | 151 ms | 12908 KiB |
| 01-10.txt | AC | 112 ms | 9976 KiB |
| 01-11.txt | AC | 157 ms | 13296 KiB |
| 01-12.txt | AC | 95 ms | 7836 KiB |
| 01-13.txt | AC | 184 ms | 13280 KiB |
| 01-14.txt | AC | 113 ms | 8968 KiB |
| 01-15.txt | AC | 113 ms | 13476 KiB |