Submission #67877624
Source Code Expand
Copy
#include <stdio.h>#include <stdlib.h>#include <inttypes.h>int cmp(const void* x, const void* y) {int64_t a = *(const int64_t*)x, b = *(const int64_t*)y;return a < b ? -1 : a > b;}int N, M;int64_t X[512345];int64_t diffs[512345];int main(void) {int i;int64_t ans;if (scanf("%d%d", &N, &M) != 2) return 1;for (i = 0; i < N; i++) {if (scanf("%" SCNd64, &X[i]) != 1) return 1;}
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
int cmp(const void* x, const void* y) {
int64_t a = *(const int64_t*)x, b = *(const int64_t*)y;
return a < b ? -1 : a > b;
}
int N, M;
int64_t X[512345];
int64_t diffs[512345];
int main(void) {
int i;
int64_t ans;
if (scanf("%d%d", &N, &M) != 2) return 1;
for (i = 0; i < N; i++) {
if (scanf("%" SCNd64, &X[i]) != 1) return 1;
}
qsort(X, N, sizeof(*X), cmp);
for (i = 1; i < N; i++) {
diffs[i - 1] = X[i] - X[i - 1];
}
qsort(diffs, N - 1, sizeof(*diffs), cmp);
ans = X[N - 1] - X[0];
for (i = 0; i < M - 1 && i < N - 1; i++) {
ans -= diffs[N - 1 - 1 - i];
}
printf("%" PRId64 "\n", ans);
return 0;
}
/*
1個の基地局で長さxの範囲をカバーできる
家の間隔が空いている上位M-1個を抜く
*/
Submission Info
| Submission Time | |
|---|---|
| Task | D - Transmission Mission |
| User | mikecat |
| Language | C (gcc 12.2.0) |
| Score | 400 |
| Code Size | 845 Byte |
| Status | AC |
| Exec Time | 183 ms |
| Memory | 13376 KiB |
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 | 0 ms | 1652 KiB |
| 00-sample-02.txt | AC | 0 ms | 1612 KiB |
| 00-sample-03.txt | AC | 0 ms | 1744 KiB |
| 01-01.txt | AC | 0 ms | 1728 KiB |
| 01-02.txt | AC | 0 ms | 1664 KiB |
| 01-03.txt | AC | 0 ms | 1628 KiB |
| 01-04.txt | AC | 0 ms | 1728 KiB |
| 01-05.txt | AC | 1 ms | 1652 KiB |
| 01-06.txt | AC | 1 ms | 1736 KiB |
| 01-07.txt | AC | 71 ms | 11400 KiB |
| 01-08.txt | AC | 85 ms | 11408 KiB |
| 01-09.txt | AC | 151 ms | 12724 KiB |
| 01-10.txt | AC | 115 ms | 9868 KiB |
| 01-11.txt | AC | 157 ms | 13328 KiB |
| 01-12.txt | AC | 94 ms | 7812 KiB |
| 01-13.txt | AC | 183 ms | 13376 KiB |
| 01-14.txt | AC | 112 ms | 8988 KiB |
| 01-15.txt | AC | 114 ms | 13364 KiB |