Submission #67527742
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const int N = 500005;
const int INF = 0x3f3f3f3f;
ll X[N], dis[N];
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> X[i];
if (m >= n) {
cout << "0\n";
return 0;
}
sort(X, X + n);
for (int i = 0; i < n - 1; i++) dis[i] = X[i + 1] - X[i];
sort(dis, dis + n - 1);
reverse(dis, dis + n - 1);
ll res = 0;
for (int i = 0; i < m - 1; i++) res += dis[i];
cout << X[n - 1] - X[0] - res << "\n";
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - Transmission Mission |
| User | jiangxinyang2012 |
| Language | C++ 20 (gcc 12.2) |
| Score | 400 |
| Code Size | 606 Byte |
| Status | AC |
| Exec Time | 213 ms |
| Memory | 11484 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 | 1 ms | 3616 KiB |
| 00-sample-02.txt | AC | 1 ms | 3528 KiB |
| 00-sample-03.txt | AC | 1 ms | 3676 KiB |
| 01-01.txt | AC | 1 ms | 3540 KiB |
| 01-02.txt | AC | 1 ms | 3616 KiB |
| 01-03.txt | AC | 1 ms | 3544 KiB |
| 01-04.txt | AC | 1 ms | 3484 KiB |
| 01-05.txt | AC | 1 ms | 3456 KiB |
| 01-06.txt | AC | 1 ms | 3488 KiB |
| 01-07.txt | AC | 161 ms | 11484 KiB |
| 01-08.txt | AC | 157 ms | 11480 KiB |
| 01-09.txt | AC | 186 ms | 11024 KiB |
| 01-10.txt | AC | 137 ms | 9224 KiB |
| 01-11.txt | AC | 192 ms | 11300 KiB |
| 01-12.txt | AC | 112 ms | 7608 KiB |
| 01-13.txt | AC | 213 ms | 11296 KiB |
| 01-14.txt | AC | 131 ms | 8392 KiB |
| 01-15.txt | AC | 191 ms | 11340 KiB |