problem_id stringlengths 6 6 | language stringclasses 2 values | original_status stringclasses 3 values | original_src stringlengths 19 243k | changed_src stringlengths 19 243k | change stringclasses 3 values | i1 int64 0 8.44k | i2 int64 0 8.44k | j1 int64 0 8.44k | j2 int64 0 8.44k | error stringclasses 270 values | stderr stringlengths 0 226k |
|---|---|---|---|---|---|---|---|---|---|---|---|
p03136 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> vec(N);
for (int i = 0; i < N; i++) {
cin >> vec.at(i);
}
int sum = 0;
for (int i = 0; i < N; i++) {
sum += vec.at(i);
}
sort(vec.begin(), vec.end());
if (vec.at(N) * 2 < sum) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> vec(N);
for (int i = 0; i < N; i++) {
cin >> vec.at(i);
}
int sum = 0;
for (int i = 0; i < N; i++) {
sum += vec.at(i);
}
sort(vec.begin(), vec.end());
if (vec.at(N - 1) * 2 < sum) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | replace | 16 | 17 | 16 | 17 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 4) >= this->size() (which is 4)
|
p03136 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <ciso646>
#include <cmath>
#include <complex>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop \
char nyaa; \
cin >> nyaa;
#define rep(i, n) for (int i = 0; i < n; i++)
#define per(i, n) for (int i = n - 1; i >= 0; i--)
#define Rep(i, sta, n) for (int i = sta; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define per1(i, n) for (int i = n; i >= 1; i--)
#define Rep1(i, sta, n) for (int i = sta; i <= n; i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-9;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int l[10];
random_device rnd;
mt19937 mt(rnd());
uniform_int_distribution<> rd(0, 65534);
void bogo_sort(int n) {
bool f = true;
bool used[10];
while (f) {
fill(used, used + n, false);
vector<int> v;
int cnt = 0;
while (cnt < n) {
int t = rd(mt) % n;
if (used[t])
continue;
v.push_back(l[t]);
used[t] = true;
cnt++;
}
rep(i, n) { l[i] = v[i]; }
f = false;
rep(i, n - 1) {
if (l[i] > l[i + 1])
f = true;
}
}
}
int main() {
int n;
cin >> n;
rep(i, n) { cin >> l[i]; }
bogo_sort(n);
int sum = 0;
rep(i, n - 1) { sum += l[i]; }
if (sum > l[n - 1]) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
// stop
return 0;
}
| #include <algorithm>
#include <bitset>
#include <ciso646>
#include <cmath>
#include <complex>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop \
char nyaa; \
cin >> nyaa;
#define rep(i, n) for (int i = 0; i < n; i++)
#define per(i, n) for (int i = n - 1; i >= 0; i--)
#define Rep(i, sta, n) for (int i = sta; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define per1(i, n) for (int i = n; i >= 1; i--)
#define Rep1(i, sta, n) for (int i = sta; i <= n; i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-9;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int l[10];
random_device rnd;
mt19937 mt(rnd());
uniform_int_distribution<> rd(0, 65533);
void bogo_sort(int n) {
bool f = true;
bool used[10];
while (f) {
fill(used, used + n, false);
vector<int> v;
int cnt = 0;
while (cnt < n) {
int t = rd(mt) % n;
if (used[t])
continue;
v.push_back(l[t]);
used[t] = true;
cnt++;
}
rep(i, n) { l[i] = v[i]; }
f = false;
rep(i, n - 1) {
if (l[i] > l[i + 1])
f = true;
}
}
}
int main() {
int n;
cin >> n;
rep(i, n) { cin >> l[i]; }
bogo_sort(n);
int sum = 0;
rep(i, n - 1) { sum += l[i]; }
if (sum > l[n - 1]) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
// stop
return 0;
}
| replace | 41 | 42 | 41 | 42 | TLE | |
p03136 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; i++) {
cin >> A.at(i);
}
sort(A.begin(), A.end());
int sum = 0;
for (int i = 0; i < N - 1; i++) {
sum += A.at(i);
}
if (sum > A.at(N)) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; i++) {
cin >> A.at(i);
}
sort(A.begin(), A.end());
int sum = 0;
for (int i = 0; i < N - 1; i++) {
sum += A.at(i);
}
if (sum > A.at(N - 1)) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
| replace | 16 | 17 | 16 | 17 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 4) >= this->size() (which is 4)
|
p03136 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int N, sum(0);
vector<int> L(N);
for (int i = 0; i < N; i++) {
cin >> L[i];
sum += L[i];
}
sort(L.begin(), L.end());
if (sum - L[N - 1] > L[N - 1])
cout << "Yes" << endl;
else
cout << "No" << endl;
} | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int N, sum(0);
cin >> N;
vector<int> L(N);
for (int i = 0; i < N; i++) {
cin >> L[i];
sum += L[i];
}
sort(L.begin(), L.end());
if (sum - L[N - 1] > L[N - 1])
cout << "Yes" << endl;
else
cout << "No" << endl;
} | insert | 7 | 7 | 7 | 8 | 0 | |
p03136 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#pragma region Macros
#define int long long
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i <= n; i++)
#define LAST(x) x[x.size() - 1]
#define ALL(x) (x).begin(), (x).end()
#define swap(a, b) (a += b, b = a - b, a -= b)
#define CEIL(a, b) ((a + b - 1) / b)
int GCD(int a, int b) // assuming a,b >= 1
{
if (a < b)
swap(a, b);
if (b == 0)
return a;
if (a % b == 0)
return b;
return GCD(b, a % b);
}
int LCM(int a, int b) // assuming a,b >= 1
{
return a * b / GCD(a, b);
}
double LOG(int a, int b) { return log(b) / log(a); }
inline bool BETWEEN(int x, int min, int max) {
if (min <= x && x <= max)
return true;
else
return false;
}
using namespace std;
#pragma endregion
signed main() {
int N, sum = 0;
cin >> N;
vector<int> L;
rep(i, N) {
cin >> L[i];
sum += L[i];
}
sort(ALL(L));
if (2 * LAST(L) < sum)
cout << "Yes";
else
cout << "No";
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#pragma region Macros
#define int long long
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i <= n; i++)
#define LAST(x) x[x.size() - 1]
#define ALL(x) (x).begin(), (x).end()
#define swap(a, b) (a += b, b = a - b, a -= b)
#define CEIL(a, b) ((a + b - 1) / b)
int GCD(int a, int b) // assuming a,b >= 1
{
if (a < b)
swap(a, b);
if (b == 0)
return a;
if (a % b == 0)
return b;
return GCD(b, a % b);
}
int LCM(int a, int b) // assuming a,b >= 1
{
return a * b / GCD(a, b);
}
double LOG(int a, int b) { return log(b) / log(a); }
inline bool BETWEEN(int x, int min, int max) {
if (min <= x && x <= max)
return true;
else
return false;
}
using namespace std;
#pragma endregion
signed main() {
int N, sum = 0;
cin >> N;
vector<int> L(N);
rep(i, N) {
cin >> L[i];
sum += L[i];
}
sort(ALL(L));
if (2 * LAST(L) < sum)
cout << "Yes";
else
cout << "No";
} | replace | 43 | 44 | 43 | 44 | -11 | |
p03136 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
typedef tree<pair<int, int>, // change type
null_type, less<pair<int, int>>, // change type
rb_tree_tag, tree_order_statistics_node_update>
ordered_set;
typedef long long ll;
#define rep(i, start, end) for (int i = start; i < end; ++i)
#define sz(x) (int)(x).size()
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(d, v) memset(d, v, sizeof(d))
#define pii pair<int, int>
const double PI = 3.14159265358979323846;
const double eps = (1e-8);
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
// freopen("facebook.txt", "w", stdout);
#endif
int n, mx = INT_MIN, sum = 0;
cin >> n;
rep(i, 0, n) {
int x;
cin >> x;
sum += x;
mx = max(mx, x);
}
if (mx < sum - mx)
cout << "Yes";
else
cout << "No";
return 0;
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
typedef tree<pair<int, int>, // change type
null_type, less<pair<int, int>>, // change type
rb_tree_tag, tree_order_statistics_node_update>
ordered_set;
typedef long long ll;
#define rep(i, start, end) for (int i = start; i < end; ++i)
#define sz(x) (int)(x).size()
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(d, v) memset(d, v, sizeof(d))
#define pii pair<int, int>
const double PI = 3.14159265358979323846;
const double eps = (1e-8);
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("facebook.txt", "w", stdout);
#endif
int n, mx = INT_MIN, sum = 0;
cin >> n;
rep(i, 0, n) {
int x;
cin >> x;
sum += x;
mx = max(mx, x);
}
if (mx < sum - mx)
cout << "Yes";
else
cout << "No";
return 0;
}
| replace | 28 | 29 | 28 | 29 | 0 | |
p03136 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
vector<int> v;
int i, x;
for (i = 0; i < n; i++) {
cin >> x;
v.push_back(x);
}
int c = 0;
sort(v.begin(), v.end());
for (i = 0; i < n - 1; i++)
c += v[i];
if (v[n - 1] < c)
cout << "Yes";
else
cout << "No";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> v;
int i, x;
for (i = 0; i < n; i++) {
cin >> x;
v.push_back(x);
}
int c = 0;
sort(v.begin(), v.end());
for (i = 0; i < n - 1; i++)
c += v[i];
if (v[n - 1] < c)
cout << "Yes";
else
cout << "No";
return 0;
}
| insert | 4 | 4 | 4 | 5 | 0 | |
p03136 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main() {
int n;
int i;
int max = 0;
int sum = 0;
int a[n];
cin >> n;
for (i = 0; i < n; i++) {
cin >> a[i];
if (a[i] > max)
max = a[i];
sum += a[i];
}
if (max >= (sum - max))
cout << "No" << endl;
else
cout << "Yes" << endl;
return 0;
}
| #include <iostream>
using namespace std;
int main() {
int n;
int i;
int max = 0;
int sum = 0;
int a[10];
cin >> n;
for (i = 0; i < n; i++) {
cin >> a[i];
if (a[i] > max)
max = a[i];
sum += a[i];
}
if (max >= (sum - max))
cout << "No" << endl;
else
cout << "Yes" << endl;
return 0;
}
| replace | 9 | 10 | 9 | 10 | -11 | |
p03136 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> L(N);
for (int i = 0; i, N; i++)
cin >> L.at(i);
sort(L.begin(), L.end());
int sum = 0;
for (int i = 0; i < N - 1; i++)
sum += L.at(i);
if (L.at(N - 1) >= sum)
cout << "No" << endl;
else
cout << "Yes" << endl;
return 0;
}
| #include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> L(N);
for (int i = 0; i < N; i++)
cin >> L.at(i);
sort(L.begin(), L.end());
int sum = 0;
for (int i = 0; i < N - 1; i++)
sum += L.at(i);
if (L.at(N - 1) >= sum)
cout << "No" << endl;
else
cout << "Yes" << endl;
return 0;
}
| replace | 10 | 11 | 10 | 11 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 4) >= this->size() (which is 4)
|
p03136 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> vec(N);
for (int i = 0; i < N; i++) {
cin >> vec.at(i);
}
sort(vec.begin(), vec.end());
int result = 0;
for (int i = 0; i < N - 1; i++) {
result += vec.at(i);
}
if (result > vec.at(N)) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> vec(N);
for (int i = 0; i < N; i++) {
cin >> vec.at(i);
}
sort(vec.begin(), vec.end());
int result = 0;
for (int i = 0; i < N - 1; i++) {
result += vec.at(i);
}
if (result > vec.at(N - 1)) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | replace | 19 | 20 | 19 | 20 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 4) >= this->size() (which is 4)
|
p03136 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, sum = 0;
cin >> N;
vector<int> L(N);
for (int i = 1; i <= N; i++) {
cin >> L.at(i);
sum += L.at(i);
}
sort(L.begin(), L.end());
if (2 * L.at(N - 1) - sum < 0)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N, sum = 0;
cin >> N;
vector<int> L(N);
for (int i = 0; i < N; i++) {
cin >> L.at(i);
sum += L.at(i);
}
sort(L.begin(), L.end());
if (2 * L.at(N - 1) - sum < 0)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
| replace | 8 | 9 | 8 | 9 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 4) >= this->size() (which is 4)
|
p03136 | C++ | Runtime Error | #pragma GCC optimize "-O3"
#pragma GCC target("avx")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < n; ++i)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int, int>
#define vp vector<pair<int, int>>
#define mp make_pair
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
#define inf (1ll << 60)
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
signed gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
signed lcm(int a, int b) { return a * b / gcd(a, b); }
using namespace std;
const int mod = 1e9 + 7;
void run();
void init() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(12);
}
signed main() {
init();
run();
return 0;
}
void run() {
int n;
vi l(n);
int sum = 0;
rep(i, n) {
cin >> l[i];
sum += l[i];
}
RSORT(l);
if (sum - l[0] > l[0])
cout << "Yes" << endl;
else
cout << "No" << endl;
} | #pragma GCC optimize "-O3"
#pragma GCC target("avx")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < n; ++i)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int, int>
#define vp vector<pair<int, int>>
#define mp make_pair
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
#define inf (1ll << 60)
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
signed gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
signed lcm(int a, int b) { return a * b / gcd(a, b); }
using namespace std;
const int mod = 1e9 + 7;
void run();
void init() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(12);
}
signed main() {
init();
run();
return 0;
}
void run() {
int n;
cin >> n;
vi l(n);
int sum = 0;
rep(i, n) {
cin >> l[i];
sum += l[i];
}
RSORT(l);
if (sum - l[0] > l[0])
cout << "Yes" << endl;
else
cout << "No" << endl;
} | insert | 41 | 41 | 41 | 42 | -11 | |
p03136 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> MY(N);
for (int i = 0; i < N; i++) {
cin >> MY.at(i);
}
sort(MY.begin(), MY.end());
int k = 0;
for (int i = 0; i < N - 1; i++) {
k += MY.at(i);
}
if (k > MY.at(N)) {
cout << "Yes" << endl;
} else
cout << "No" << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> MY(N);
for (int i = 0; i < N; i++) {
cin >> MY.at(i);
}
sort(MY.begin(), MY.end());
int k = 0;
for (int i = 0; i < N - 1; i++) {
k += MY.at(i);
}
if (k > MY.at(N - 1)) {
cout << "Yes" << endl;
} else
cout << "No" << endl;
} | replace | 15 | 16 | 15 | 16 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 4) >= this->size() (which is 4)
|
p03136 | Python | Runtime Error | N = int(input())
L = map(int, input().split())
if max(L) < sum(L) - max(L):
print("Yes")
else:
print("No")
| N = int(input())
L = list(map(int, input().split()))
if max(L) < sum(L) - max(L):
print("Yes")
else:
print("No")
| replace | 1 | 2 | 1 | 2 | ValueError: max() arg is an empty sequence | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03136/Python/s255983897.py", line 4, in <module>
if max(L) < sum(L) - max(L):
ValueError: max() arg is an empty sequence
|
p03136 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
vector<int> vec(N);
for (int i = 0; i < N; i++) {
cin >> vec.at(i);
}
int max;
max = *max_element(vec.begin(), vec.end());
int total = 0;
for (int i = 0; i < N; i++) {
total += vec.at(i);
}
if (max < (total - max)) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> vec(N);
for (int i = 0; i < N; i++) {
cin >> vec.at(i);
}
int max;
max = *max_element(vec.begin(), vec.end());
int total = 0;
for (int i = 0; i < N; i++) {
total += vec.at(i);
}
if (max < (total - max)) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
}
| insert | 6 | 6 | 6 | 8 | -6 | terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
|
p03136 | Python | Runtime Error | N = input()
L = map(int, input().split())
x = sorted(L)
Lmax = max(L)
y = x[0:-1]
ysum = sum(y)
print("Yes" if Lmax < ysum else "No")
| N = int(input())
L = list(map(int, input().split()))
x = sorted(L)
Lmax = max(L)
y = x[0:-1]
ysum = sum(y)
print("Yes" if Lmax < ysum else "No")
| replace | 0 | 2 | 0 | 2 | ValueError: max() arg is an empty sequence | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03136/Python/s642487988.py", line 4, in <module>
Lmax = max(L)
ValueError: max() arg is an empty sequence
|
p03137 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
ll n, m;
cin >> n >> m;
vector<ll> x(m);
for (ll i = 0; i < m; i++)
cin >> x[i];
sort(x.begin(), x.end());
vector<ll> y(m - 1);
for (ll i = 0; i < m - 1; i++)
y[i] = x[i + 1] - x[i];
sort(y.begin(), y.end());
ll sum = 0;
for (ll i = 0; i < y.size() - n + 1; i++)
sum += y[i];
cout << sum;
return 0;
} | #include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
ll n, m;
cin >> n >> m;
vector<ll> x(m);
if (n > m) {
cout << 0;
return 0;
}
for (ll i = 0; i < m; i++)
cin >> x[i];
sort(x.begin(), x.end());
vector<ll> y(m - 1);
for (ll i = 0; i < m - 1; i++)
y[i] = x[i + 1] - x[i];
sort(y.begin(), y.end());
ll sum = 0;
for (ll i = 0; i < y.size() - n + 1; i++)
sum += y[i];
cout << sum;
return 0;
} | insert | 8 | 8 | 8 | 12 | 0 | |
p03137 | C++ | Runtime Error | #define NOMINMAX
#define TEST_MODE true
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#include <random>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rrep2(i, a, b) for (int i = (a)-1; i >= (int)b; --i)
#define range(i, a, b, c) for (int i = a; c > 0 ? i < b : i > b; i += c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) begin(a), end(a)
#define ifnot(a) if (not(a))
#define int long long
#ifdef LOCAL_ENV
#if TEST_MODE == true
const bool test = true;
#define dump(x) cerr << #x << " : " << (x) << " "
#define dumpl(x) dump(x) << endl
#else
const bool test = false;
#define dump(x)
#define dumpl(x)
#endif
#else
const bool test = false;
#define dump(x)
#define dumpl(x)
#endif
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
const int INF = (int)1 << 60;
const int undefined = INF;
const ll INFL = (ll)1 << 60;
ll mod_n = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real &r) { return (r > eps) - (r < -eps); }
int sgn(const Real &a, const Real &b) { return sgn(a - b); }
//.....................
const int MAX = (int)2e5 + 5;
vector<string> split(const string &str, char sep) {
vector<string> v;
stringstream ss(str);
string buffer;
while (getline(ss, buffer, sep)) {
v.push_back(buffer);
}
return v;
}
string join(const vector<string> &v, const string delim = 0) {
string s;
if (!v.empty()) {
s += v[0];
for (decltype(v.size()) i = 1, c = v.size(); i < c; ++i) {
if (delim != "")
s += delim;
s += v[i];
}
}
return s;
}
string operator*(const string &s, const int &n) {
string res = "";
rep(i, n) res += s;
return res;
}
template <class InputIterator> int sum(InputIterator begin, InputIterator end) {
return accumulate(begin, end, 0ll);
}
template <typename T> T gcd(T a, T b) {
T c;
while (a != 0) {
c = a;
a = b % a;
b = c;
}
return b;
}
template <typename T> T bit_count(T N) {
T cnt = 0;
while (N) {
if (N & 1)
cnt++;
N >>= 1;
}
return cnt;
}
template <typename T> void print_vec(ostream &ostream, vector<T> a) {
rep(i, a.size() - 1) ostream << a[i] << " ";
ostream << a.back() << endl;
}
ll pow_n(ll x, ll n) {
ll res = 1;
while (n > 0) {
if (n & 1)
res = res * x;
x = x * x;
n >>= 1;
}
return res;
}
template <class T, class U> T mod_pow(T x, U n) {
T res = 1;
while (n > 0) {
if (n & 1)
res = res * x;
x = x * x;
x %= mod_n;
n >>= 1;
res %= mod_n;
}
return res;
}
template <class T> T mod_rev(T a) {
T res = 1;
return mod_pow(a, mod_n - 2);
}
int H, W;
bool grid_ng(int y, int x) { return y < 0 || y >= H || x < 0 || x >= W; }
struct Point {
int x, y;
Point(int y_, int x_) : y(y_), x(x_) {}
bool operator<(const Point &r) const {
if (y != r.y)
return y < r.y;
return x < r.x;
}
};
class Solver {
public:
int n, m;
vector<int> x;
int ans() {
int res = x.back() - x.front();
vector<int> diff(m - 1);
rep(i, m - 1) diff[i] = x[i + 1] - x[i];
sort(all(diff), greater<int>());
rep(i, min(n - 1, m)) res -= diff[i];
return res;
}
void solve() {
cin >> n >> m;
x.resize(m);
rep(i, m) cin >> x[i];
sort(all(x));
print_vec(cerr, x);
cout << ans() << endl;
}
};
signed main() {
srand((unsigned int)time(NULL));
cout << fixed << setprecision(20);
auto ptr = new Solver();
ptr->solve();
delete ptr;
// while (true) {
// if (cin.eof() == true) break;
// auto ptr = new Solver();
// ptr->solve();
// delete ptr;
// }
return 0;
}
| #define NOMINMAX
#define TEST_MODE true
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#include <random>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rrep2(i, a, b) for (int i = (a)-1; i >= (int)b; --i)
#define range(i, a, b, c) for (int i = a; c > 0 ? i < b : i > b; i += c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) begin(a), end(a)
#define ifnot(a) if (not(a))
#define int long long
#ifdef LOCAL_ENV
#if TEST_MODE == true
const bool test = true;
#define dump(x) cerr << #x << " : " << (x) << " "
#define dumpl(x) dump(x) << endl
#else
const bool test = false;
#define dump(x)
#define dumpl(x)
#endif
#else
const bool test = false;
#define dump(x)
#define dumpl(x)
#endif
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
const int INF = (int)1 << 60;
const int undefined = INF;
const ll INFL = (ll)1 << 60;
ll mod_n = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real &r) { return (r > eps) - (r < -eps); }
int sgn(const Real &a, const Real &b) { return sgn(a - b); }
//.....................
const int MAX = (int)2e5 + 5;
vector<string> split(const string &str, char sep) {
vector<string> v;
stringstream ss(str);
string buffer;
while (getline(ss, buffer, sep)) {
v.push_back(buffer);
}
return v;
}
string join(const vector<string> &v, const string delim = 0) {
string s;
if (!v.empty()) {
s += v[0];
for (decltype(v.size()) i = 1, c = v.size(); i < c; ++i) {
if (delim != "")
s += delim;
s += v[i];
}
}
return s;
}
string operator*(const string &s, const int &n) {
string res = "";
rep(i, n) res += s;
return res;
}
template <class InputIterator> int sum(InputIterator begin, InputIterator end) {
return accumulate(begin, end, 0ll);
}
template <typename T> T gcd(T a, T b) {
T c;
while (a != 0) {
c = a;
a = b % a;
b = c;
}
return b;
}
template <typename T> T bit_count(T N) {
T cnt = 0;
while (N) {
if (N & 1)
cnt++;
N >>= 1;
}
return cnt;
}
template <typename T> void print_vec(ostream &ostream, vector<T> a) {
rep(i, a.size() - 1) ostream << a[i] << " ";
ostream << a.back() << endl;
}
ll pow_n(ll x, ll n) {
ll res = 1;
while (n > 0) {
if (n & 1)
res = res * x;
x = x * x;
n >>= 1;
}
return res;
}
template <class T, class U> T mod_pow(T x, U n) {
T res = 1;
while (n > 0) {
if (n & 1)
res = res * x;
x = x * x;
x %= mod_n;
n >>= 1;
res %= mod_n;
}
return res;
}
template <class T> T mod_rev(T a) {
T res = 1;
return mod_pow(a, mod_n - 2);
}
int H, W;
bool grid_ng(int y, int x) { return y < 0 || y >= H || x < 0 || x >= W; }
struct Point {
int x, y;
Point(int y_, int x_) : y(y_), x(x_) {}
bool operator<(const Point &r) const {
if (y != r.y)
return y < r.y;
return x < r.x;
}
};
class Solver {
public:
int n, m;
vector<int> x;
int ans() {
int res = x.back() - x.front();
vector<int> diff(m - 1);
rep(i, m - 1) diff[i] = x[i + 1] - x[i];
sort(all(diff), greater<int>());
rep(i, min(n - 1, m - 1)) res -= diff[i];
return res;
}
void solve() {
cin >> n >> m;
x.resize(m);
rep(i, m) cin >> x[i];
sort(all(x));
print_vec(cerr, x);
cout << ans() << endl;
}
};
signed main() {
srand((unsigned int)time(NULL));
cout << fixed << setprecision(20);
auto ptr = new Solver();
ptr->solve();
delete ptr;
// while (true) {
// if (cin.eof() == true) break;
// auto ptr = new Solver();
// ptr->solve();
// delete ptr;
// }
return 0;
}
| replace | 167 | 168 | 167 | 168 | 0 | 1 2 10 12 14
|
p03137 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
int n, m, ans = 0;
cin >> n >> m;
vector<int> x(m);
vector<int> max(m - 1);
for (int i = 0; i < m; i++) {
cin >> x[i];
if (i < m - 1)
max[i] = 0;
}
sort(x.begin(), x.end());
for (int i = 0; i < m - 1; i++) {
max[i] = x[i + 1] - x[i];
ans += max[i];
}
if (n == 1) {
cout << ans << endl;
} else if (m == 1) {
cout << "0" << endl;
} else {
sort(max.begin(), max.end());
for (int i = m - 2; i >= m - n; i--) {
ans -= max[i];
}
cout << ans << endl;
}
} | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
int n, m, ans = 0;
cin >> n >> m;
vector<int> x(m);
vector<int> max(m - 1);
for (int i = 0; i < m; i++) {
cin >> x[i];
if (i < m - 1)
max[i] = 0;
}
sort(x.begin(), x.end());
for (int i = 0; i < m - 1; i++) {
max[i] = x[i + 1] - x[i];
ans += max[i];
}
if (n == 1) {
cout << ans << endl;
} else if (m <= n) {
cout << "0" << endl;
} else {
sort(max.begin(), max.end());
for (int i = m - 2; i >= m - n; i--) {
ans -= max[i];
}
cout << ans << endl;
}
}
| replace | 28 | 29 | 28 | 29 | 0 | |
p03137 | C++ | Runtime Error | #include <bits/stdc++.h>
/* #define int long long */
/* #define double long double */
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define repa(i, s, n) for (int i = s; i < (int)n; i++)
#define MOD 1000000007
using namespace std;
using ll = long long;
typedef vector<int> vi;
typedef pair<int, int> P;
#define rrep(i, a, b) for (int i = a; i >= b; i--)
signed main() {
int n, m;
cin >> n >> m;
vi x(m);
vi diff(m - 1);
rep(i, m) cin >> x[i];
sort(x.begin(), x.end());
if (m == 1) {
cout << 0 << endl;
return 0;
}
rep(i, m - 1) { diff[i] = x[i + 1] - x[i]; }
sort(diff.begin(), diff.end(), greater<int>());
int ans = *(x.end() - 1) - *x.begin();
rep(i, n - 1) {
/* cout << "diff = " << diff[i] << " "; */
ans -= diff[i];
}
cout << ans << endl;
} | #include <bits/stdc++.h>
/* #define int long long */
/* #define double long double */
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define repa(i, s, n) for (int i = s; i < (int)n; i++)
#define MOD 1000000007
using namespace std;
using ll = long long;
typedef vector<int> vi;
typedef pair<int, int> P;
#define rrep(i, a, b) for (int i = a; i >= b; i--)
signed main() {
int n, m;
cin >> n >> m;
vi x(m);
vi diff(m - 1);
rep(i, m) cin >> x[i];
sort(x.begin(), x.end());
if (n >= m) {
cout << 0 << endl;
return 0;
}
rep(i, m - 1) { diff[i] = x[i + 1] - x[i]; }
sort(diff.begin(), diff.end(), greater<int>());
int ans = *(x.end() - 1) - *x.begin();
rep(i, n - 1) {
/* cout << "diff = " << diff[i] << " "; */
ans -= diff[i];
}
cout << ans << endl;
} | replace | 20 | 21 | 20 | 21 | 0 | |
p03137 | C++ | Runtime Error | #pragma GCC optimize("Ofast")
#pragma GCC target("avx2,tune=native")
#include <bits/stdc++.h>
#include <x86intrin.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int N, M;
cin >> N >> M;
if (N >= M) {
cout << '0';
exit(EXIT_SUCCESS);
}
int X[M], dist[M - 1], res = 0;
cin >> X[0];
for (int i = 1; i < M; i++)
cin >> X[i];
sort(X, X + M);
for (int i = 0; i < M - 1; i++) {
dist[i] = X[i + 1] - X[i];
res += dist[i];
}
sort(dist, dist + M - 1, greater<int>());
for (int i = 0; i < N - 1; i++)
res -= dist[i];
cout << res;
return 0;
} | #pragma GCC optimize("Ofast")
#pragma GCC target("avx,tune=native")
#include <bits/stdc++.h>
#include <x86intrin.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int N, M;
cin >> N >> M;
if (N >= M) {
cout << '0';
exit(EXIT_SUCCESS);
}
int X[M], dist[M - 1], res = 0;
cin >> X[0];
for (int i = 1; i < M; i++)
cin >> X[i];
sort(X, X + M);
for (int i = 0; i < M - 1; i++) {
dist[i] = X[i + 1] - X[i];
res += dist[i];
}
sort(dist, dist + M - 1, greater<int>());
for (int i = 0; i < N - 1; i++)
res -= dist[i];
cout << res;
return 0;
} | replace | 1 | 2 | 1 | 2 | 0 | |
p03137 | C++ | Runtime Error | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N, M;
cin >> N >> M;
vector<int> X(M);
REP(i, M) cin >> X[i];
sort(X.begin(), X.end());
vector<int> D(M - 1);
REP(i, M - 1) D[i] = X[i + 1] - X[i];
sort(D.begin(), D.end());
REP(i, N - 1) { D.pop_back(); }
int ans = 0;
REP(i, D.size()) { ans += D[i]; }
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N, M;
cin >> N >> M;
vector<int> X(M);
REP(i, M) cin >> X[i];
sort(X.begin(), X.end());
vector<int> D(M - 1);
if (N >= M) {
cout << 0 << endl;
} else {
REP(i, M - 1) D[i] = X[i + 1] - X[i];
sort(D.begin(), D.end());
REP(i, N - 1) { D.pop_back(); }
int ans = 0;
REP(i, D.size()) { ans += D[i]; }
cout << ans << endl;
}
return 0;
} | replace | 15 | 21 | 15 | 25 | 0 | |
p03137 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, M;
vector<long> X;
cin >> N >> M;
for (int i = 0; i < M; i++) {
long x;
cin >> x;
X.push_back(x);
}
sort(X.begin(), X.end());
vector<long> ivl;
for (int i = 0; i < M - 1; i++) {
ivl.push_back(X[i + 1] - X[i]);
}
sort(ivl.begin(), ivl.end(), greater<long>());
if (M == 1) {
cout << "0" << endl;
return 0;
}
long ans = 0;
for (int i = 0; i < N - 1; i++) {
ans += ivl[i];
}
cout << X[M - 1] - X[0] - ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, M;
vector<long> X;
cin >> N >> M;
for (int i = 0; i < M; i++) {
long x;
cin >> x;
X.push_back(x);
}
sort(X.begin(), X.end());
vector<long> ivl;
for (int i = 0; i < M - 1; i++) {
ivl.push_back(X[i + 1] - X[i]);
}
sort(ivl.begin(), ivl.end(), greater<long>());
if (N >= M) {
cout << "0" << endl;
return 0;
}
long ans = 0;
for (int i = 0; i < N - 1; i++) {
ans += ivl[i];
}
cout << X[M - 1] - X[0] - ans << endl;
return 0;
} | replace | 20 | 21 | 20 | 21 | 0 | |
p03137 | C++ | Runtime Error | // Author: Fuadul Hasan(fuadul202@gmail.com)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e5 + 5;
int main() {
int n, k;
cin >> n >> k;
int a[n];
for (int i = 0; i < k; i++) {
cin >> a[i];
}
sort(a, a + k);
std::vector<int> v;
for (int i = 1; i < k; i++) {
v.push_back(a[i] - a[i - 1]);
}
sort(v.begin(), v.end());
ll sum = 0;
for (int i = (v.size() - n); i >= 0; i--) {
// cout<<v[i]<<" ";
sum += (ll)v[i];
} // cout<<endl;
cout << sum << endl;
return 0;
} | // Author: Fuadul Hasan(fuadul202@gmail.com)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e5 + 5;
int main() {
int n, k;
cin >> n >> k;
int a[k];
for (int i = 0; i < k; i++) {
cin >> a[i];
}
sort(a, a + k);
std::vector<int> v;
for (int i = 1; i < k; i++) {
v.push_back(a[i] - a[i - 1]);
}
sort(v.begin(), v.end());
ll sum = 0;
for (int i = (v.size() - n); i >= 0; i--) {
// cout<<v[i]<<" ";
sum += (ll)v[i];
} // cout<<endl;
cout << sum << endl;
return 0;
} | replace | 11 | 12 | 11 | 12 | 0 | |
p03137 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <numeric>
#include <vector>
using namespace std;
#define PI 3.14159265358979323846
#define MAXINF 1e18L
#define MININF -1e18L
#define REP(i, n) for (int i = 0; i < int(n); ++i)
#define RREP(i, n) for (int i = int(n) - 1; i >= 0; --i)
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<int>())
#define DEBUG(x) cerr << #x << ": " << x << endl;
#define DEBUG_VEC(v) \
cerr << #v << ":"; \
for (int i = 0; i < v.size(); i++) \
cerr << " " << v[i]; \
cerr << endl
#define pb push_back
template <class A> void pr(A a) { cout << (a) << endl; }
template <class A, class B> void pr(A a, B b) {
cout << a << " ";
pr(b);
}
template <class A, class B, class C> void pr(A a, B b, C c) {
cout << a << " ";
pr(b, c);
}
template <class A, class B, class C, class D> void pr(A a, B b, C c, D d) {
cout << a << " ";
pr(b, c, d);
}
typedef long long ll;
typedef pair<int, int> intint;
int main(void) {
int n, m;
cin >> n >> m;
vector<int> x(m);
for (int i = 0; i < m; i++) {
cin >> x[i];
}
SORT(x);
vector<int> diff(m - 1);
for (int i = 0; i < m - 1; i++) {
diff[i] = (x[i + 1] - x[i]);
}
RSORT(diff);
int ans = x[x.size() - 1] - x[0];
REP(i, n - 1) { ans -= diff[i]; }
pr(ans);
} | #include <bits/stdc++.h>
#include <numeric>
#include <vector>
using namespace std;
#define PI 3.14159265358979323846
#define MAXINF 1e18L
#define MININF -1e18L
#define REP(i, n) for (int i = 0; i < int(n); ++i)
#define RREP(i, n) for (int i = int(n) - 1; i >= 0; --i)
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<int>())
#define DEBUG(x) cerr << #x << ": " << x << endl;
#define DEBUG_VEC(v) \
cerr << #v << ":"; \
for (int i = 0; i < v.size(); i++) \
cerr << " " << v[i]; \
cerr << endl
#define pb push_back
template <class A> void pr(A a) { cout << (a) << endl; }
template <class A, class B> void pr(A a, B b) {
cout << a << " ";
pr(b);
}
template <class A, class B, class C> void pr(A a, B b, C c) {
cout << a << " ";
pr(b, c);
}
template <class A, class B, class C, class D> void pr(A a, B b, C c, D d) {
cout << a << " ";
pr(b, c, d);
}
typedef long long ll;
typedef pair<int, int> intint;
int main(void) {
int n, m;
cin >> n >> m;
vector<int> x(m);
for (int i = 0; i < m; i++) {
cin >> x[i];
}
if (n >= m) {
pr(0);
return 0;
}
SORT(x);
vector<int> diff(m - 1);
for (int i = 0; i < m - 1; i++) {
diff[i] = (x[i + 1] - x[i]);
}
RSORT(diff);
int ans = x[x.size() - 1] - x[0];
REP(i, n - 1) { ans -= diff[i]; }
pr(ans);
} | insert | 43 | 43 | 43 | 48 | 0 | |
p03137 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
using namespace std;
int input[100005];
int cache[100005];
long long ans = 0;
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++)
scanf("%d", &input[i]);
sort(input + 1, input + 1 + m);
for (int i = 1; i <= m - 1; i++) {
ans += input[i + 1] - input[i];
cache[i] = input[i + 1] - input[i];
}
sort(cache + 1, cache + m);
for (int i = 0; i < n - 1; i++) {
ans -= cache[m - 1 - i];
}
printf("%lld\n", ans);
return 0;
} | #include <algorithm>
#include <cstdio>
using namespace std;
int input[100005];
int cache[100005];
long long ans = 0;
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++)
scanf("%d", &input[i]);
if (n >= m) {
printf("0\n");
return 0;
}
sort(input + 1, input + 1 + m);
for (int i = 1; i <= m - 1; i++) {
ans += input[i + 1] - input[i];
cache[i] = input[i + 1] - input[i];
}
sort(cache + 1, cache + m);
for (int i = 0; i < n - 1; i++) {
ans -= cache[m - 1 - i];
}
printf("%lld\n", ans);
return 0;
} | insert | 15 | 15 | 15 | 19 | 0 | |
p03137 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; ++i)
using namespace std;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> x(m);
rep(i, m) cin >> x[i];
sort(x.begin(), x.end());
vector<int> dif(m - 1);
rep(i, m - 1) dif[i] = x[i + 1] - x[i];
sort(dif.begin(), dif.end(), greater<int>());
int ans = x[m - 1] - x[0];
rep(i, n - 1) ans -= dif[i];
cout << ans << '\n';
return 0;
}
| #include <algorithm>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; ++i)
using namespace std;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
if (n >= m) {
cout << 0 << '\n';
return 0;
}
vector<int> x(m);
rep(i, m) cin >> x[i];
sort(x.begin(), x.end());
vector<int> dif(m - 1);
rep(i, m - 1) dif[i] = x[i + 1] - x[i];
sort(dif.begin(), dif.end(), greater<int>());
int ans = x[m - 1] - x[0];
rep(i, n - 1) ans -= dif[i];
cout << ans << '\n';
return 0;
}
| insert | 12 | 12 | 12 | 16 | 0 | |
p03137 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int N, M;
int main() {
cin >> N >> M;
if (N >= M) {
cout << 0 << endl;
}
vector<int> Xs(M);
for (int i = 0; i < M; i++) {
cin >> Xs.at(i);
}
sort(Xs.begin(), Xs.end());
vector<int> Ds(M - 1);
for (int i = 0; i < M - 1; i++) {
Ds.at(i) = Xs.at(i + 1) - Xs.at(i);
}
sort(Ds.begin(), Ds.end());
int steps = accumulate(Ds.begin(), Ds.end() - (N - 1), 0);
cout << steps << endl;
} | #include <bits/stdc++.h>
using namespace std;
int N, M;
int main() {
cin >> N >> M;
if (N >= M) {
cout << 0 << endl;
return 0;
}
vector<int> Xs(M);
for (int i = 0; i < M; i++) {
cin >> Xs.at(i);
}
sort(Xs.begin(), Xs.end());
vector<int> Ds(M - 1);
for (int i = 0; i < M - 1; i++) {
Ds.at(i) = Xs.at(i + 1) - Xs.at(i);
}
sort(Ds.begin(), Ds.end());
int steps = accumulate(Ds.begin(), Ds.end() - (N - 1), 0);
cout << steps << endl;
} | insert | 8 | 8 | 8 | 9 | 0 | |
p03137 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
int main() {
int N, M;
int ans = 0;
vector<int> X(100000, 0);
vector<int> diffX(100000, 0);
cin >> N >> M;
for (int i = 0; i < M; i++) {
cin >> X[i];
}
X.erase(X.begin() + M, X.end());
diffX.erase(diffX.begin() + M - 1, diffX.end());
sort(X.begin(), X.end());
for (int i = 0; i < M - 1; i++) {
diffX[i] = X[i + 1] - X[i];
}
sort(diffX.begin(), diffX.end(), greater<int>());
if (N < M) {
ans = accumulate(diffX.begin() + N - 1, diffX.end(), 0);
} else {
ans = 0;
}
cout << ans;
return 1;
} | #include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
int main() {
int N, M;
int ans = 0;
vector<int> X(100000, 0);
vector<int> diffX(100000, 0);
cin >> N >> M;
for (int i = 0; i < M; i++) {
cin >> X[i];
}
X.erase(X.begin() + M, X.end());
diffX.erase(diffX.begin() + M - 1, diffX.end());
sort(X.begin(), X.end());
for (int i = 0; i < M - 1; i++) {
diffX[i] = X[i + 1] - X[i];
}
sort(diffX.begin(), diffX.end(), greater<int>());
if (N < M) {
ans = accumulate(diffX.begin() + N - 1, diffX.end(), 0);
} else {
ans = 0;
}
cout << ans;
} | delete | 31 | 32 | 31 | 31 | 1 | |
p03137 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
int X[M];
for (int i = 0; i < M; i++) {
cin >> X[i];
}
sort(X, X + M);
int distance[M];
distance[0] = 0;
for (int i = 1; i < M; i++) {
distance[i] = X[i] - X[i - 1];
}
sort(distance, distance + M, greater<int>());
int ans = abs(X[M - 1] - X[0]);
for (int i = 2; i <= N; i++) {
ans -= distance[i - 2];
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
int X[M];
for (int i = 0; i < M; i++) {
cin >> X[i];
}
sort(X, X + M);
int distance[M];
distance[0] = 0;
for (int i = 1; i < M; i++) {
distance[i] = X[i] - X[i - 1];
}
sort(distance, distance + M, greater<int>());
int ans = abs(X[M - 1] - X[0]);
for (int i = 2; i <= min(N, M); i++) {
ans -= distance[i - 2];
}
cout << ans << endl;
return 0;
} | replace | 21 | 22 | 21 | 22 | 0 | |
p03137 | C++ | Time Limit Exceeded | #ifdef _WIN32
#define DEBUG 1
#endif
#define _CRT_SECURE_NO_WARNINGS
#define MATH_PI 3.14159265358979323846264338327950288419716939
#include <fstream>
#include <iostream>
#include <string.h>
using namespace std;
#ifdef DEBUG
#include "include.h"
#else
inline void wait() {}
inline void dout(const char *arg, ...) {}
#endif
// template<typename T>inline void swap(T a, T b){T t = a; a = b; b = t;}
#define CLIP(ptr, min, max) \
{ \
if ((min) <= (max)) { \
if (ptr < (min)) { \
ptr = (min); \
} \
if (ptr > (max)) { \
ptr = (max); \
} \
} \
}
#define max(a, b) a > b ? a : b;
#define min(a, b) a > b ? b : a;
#define Sin(deg) sin((deg)*MATH_PI / 180)
#define Cos(deg) cos((deg)*MATH_PI / 180)
#define Tan(deg) tan((deg)*MATH_PI / 180)
#define Rad(deg) ((deg)*MATH_PI / 180)
#define ff(param, num) for (int param = 0; param < num; ++param)
#define fi(num) for (int i = 0; i < num; ++i)
#define fj(num) for (int j = 0; j < num; ++j)
#define fk(num) for (int k = 0; k < num; ++k)
#define fl(num) for (int l = 0; l < num; ++l)
#define fn(num) for (int n = 0; n < num; ++n)
#define ffr(param, num) for (int param = num - 1; param >= 0; --param)
#define fir(num) for (int i = num - 1; i >= 0; --i)
#define fjr(num) for (int j = num - 1; j >= 0; --j)
#define fkr(num) for (int k = num - 1; k >= 0; --k)
#define flr(num) for (int l = num - 1; l >= 0; --l)
#define fnr(num) for (int n = num - 1; n >= 0; --n)
#define gi(p) Scanf("%d", p)
#define gi2(p1, p2) Scanf2("%d %d", p1, p2)
#define gi3(p1, p2, p3) Scanf3("%d %d %d", p1, p2, p3)
#define gi4(p1, p2, p3, p4) Scanf4("%d %d %d %d", p1, p2, p3, p4)
#define gll(p) Scanf("%lld", p)
#define gll2(p1, p2) Scanf2("%lld %lld", p1, p2)
#define gll3(p1, p2, p3) Scanf3("%lld %lld %lld", p1, p2, p3)
#define gll4(p1, p2, p3, p4) Scanf4("%lld %lld %lld %lld", p1, p2, p3, p4)
#define gf(p) Scanf("%f", p)
#define gf2(p1, p2) Scanf2("%f %f", p1, p2)
#define gf3(p1, p2, p3) Scanf3("%f %f %f", p1, p2, p3)
#define gf4(p1, p2, p3, p4) Scanf4("%f %f %f %f", p1, p2, p3, p4)
#ifdef DEBUG
#define gc(buf) fscanf(local_in.fp, "%s", buf)
#define Scanf(expr, p) fscanf(local_in.fp, expr, &p)
#define Scanf2(expr, p1, p2) fscanf(local_in.fp, expr, &p1, &p2)
#define Scanf3(expr, p1, p2, p3) fscanf(local_in.fp, expr, &p1, &p2, &p3)
#define Scanf4(expr, p1, p2, p3, p4) \
fscanf(local_in.fp, expr, &p1, &p2, &p3, &p4)
#else
#define gc(buf) Scanf("%s", buf)
#define Scanf(expr, p) scanf(expr, &p)
#define Scanf2(expr, p1, p2) scanf(expr, &p1, &p2)
#define Scanf3(expr, p1, p2, p3) scanf(expr, &p1, &p2, &p3)
#define Scanf4(expr, p1, p2, p3, p4) scanf(expr, &p1, &p2, &p3, &p4)
#endif
#define ans(p) cout << p << endl;
void CombSort(int N, int *ar, int order_ascending = 1) {
int h = int(N / 1.3);
int flag;
int i;
while (true) {
flag = 0;
for (i = 0; i + h < N; ++i) {
if ((order_ascending && ar[i] > ar[i + h]) ||
(!order_ascending && ar[i] < ar[i + h])) {
swap<int>(ar[i], ar[i + h]);
flag = 1;
}
}
if (h == 1 && !flag)
break;
if (h == 9 || h == 10)
h = 11;
if (h > 1)
h = int(h / 1.3);
}
}
int EuclideanAlgorithm(int N, int *ar) {
fn(N - 1) {
while (true) {
if (ar[n] % ar[n + 1] == 0 || ar[n + 1] % ar[n] == 0) {
ar[n + 1] = min(ar[n], ar[n + 1]);
break;
}
if (ar[n] > ar[n + 1]) {
ar[n] %= ar[n + 1];
} else {
ar[n + 1] %= ar[n];
}
}
}
return ar[N - 1];
}
int X[100000], dist[100000];
signed main() {
int ii, jj, kk, ll;
int ret = 0;
int flag = 0;
char cbuf[8192];
int N, M;
gi2(N, M);
if (N >= M) {
ans(0);
return 0;
}
fi(M) { gi(X[i]); }
CombSort(M, X);
fi(M - 1) { dist[i] = X[i + 1] - X[i]; }
if (M >= 2)
CombSort(M - 1, dist);
int sum = 0;
fi(M - 1 - (N - 1)) { sum += dist[i]; }
ans(sum);
wait();
return 0;
} | #ifdef _WIN32
#define DEBUG 1
#endif
#define _CRT_SECURE_NO_WARNINGS
#define MATH_PI 3.14159265358979323846264338327950288419716939
#include <fstream>
#include <iostream>
#include <string.h>
using namespace std;
#ifdef DEBUG
#include "include.h"
#else
inline void wait() {}
inline void dout(const char *arg, ...) {}
#endif
// template<typename T>inline void swap(T a, T b){T t = a; a = b; b = t;}
#define CLIP(ptr, min, max) \
{ \
if ((min) <= (max)) { \
if (ptr < (min)) { \
ptr = (min); \
} \
if (ptr > (max)) { \
ptr = (max); \
} \
} \
}
#define max(a, b) a > b ? a : b;
#define min(a, b) a > b ? b : a;
#define Sin(deg) sin((deg)*MATH_PI / 180)
#define Cos(deg) cos((deg)*MATH_PI / 180)
#define Tan(deg) tan((deg)*MATH_PI / 180)
#define Rad(deg) ((deg)*MATH_PI / 180)
#define ff(param, num) for (int param = 0; param < num; ++param)
#define fi(num) for (int i = 0; i < num; ++i)
#define fj(num) for (int j = 0; j < num; ++j)
#define fk(num) for (int k = 0; k < num; ++k)
#define fl(num) for (int l = 0; l < num; ++l)
#define fn(num) for (int n = 0; n < num; ++n)
#define ffr(param, num) for (int param = num - 1; param >= 0; --param)
#define fir(num) for (int i = num - 1; i >= 0; --i)
#define fjr(num) for (int j = num - 1; j >= 0; --j)
#define fkr(num) for (int k = num - 1; k >= 0; --k)
#define flr(num) for (int l = num - 1; l >= 0; --l)
#define fnr(num) for (int n = num - 1; n >= 0; --n)
#define gi(p) Scanf("%d", p)
#define gi2(p1, p2) Scanf2("%d %d", p1, p2)
#define gi3(p1, p2, p3) Scanf3("%d %d %d", p1, p2, p3)
#define gi4(p1, p2, p3, p4) Scanf4("%d %d %d %d", p1, p2, p3, p4)
#define gll(p) Scanf("%lld", p)
#define gll2(p1, p2) Scanf2("%lld %lld", p1, p2)
#define gll3(p1, p2, p3) Scanf3("%lld %lld %lld", p1, p2, p3)
#define gll4(p1, p2, p3, p4) Scanf4("%lld %lld %lld %lld", p1, p2, p3, p4)
#define gf(p) Scanf("%f", p)
#define gf2(p1, p2) Scanf2("%f %f", p1, p2)
#define gf3(p1, p2, p3) Scanf3("%f %f %f", p1, p2, p3)
#define gf4(p1, p2, p3, p4) Scanf4("%f %f %f %f", p1, p2, p3, p4)
#ifdef DEBUG
#define gc(buf) fscanf(local_in.fp, "%s", buf)
#define Scanf(expr, p) fscanf(local_in.fp, expr, &p)
#define Scanf2(expr, p1, p2) fscanf(local_in.fp, expr, &p1, &p2)
#define Scanf3(expr, p1, p2, p3) fscanf(local_in.fp, expr, &p1, &p2, &p3)
#define Scanf4(expr, p1, p2, p3, p4) \
fscanf(local_in.fp, expr, &p1, &p2, &p3, &p4)
#else
#define gc(buf) Scanf("%s", buf)
#define Scanf(expr, p) scanf(expr, &p)
#define Scanf2(expr, p1, p2) scanf(expr, &p1, &p2)
#define Scanf3(expr, p1, p2, p3) scanf(expr, &p1, &p2, &p3)
#define Scanf4(expr, p1, p2, p3, p4) scanf(expr, &p1, &p2, &p3, &p4)
#endif
#define ans(p) cout << p << endl;
void CombSort(int N, int *ar, int order_ascending = 1) {
int h = int(N / 1.3);
int flag;
int i;
while (true) {
flag = 0;
for (i = 0; i + h < N; ++i) {
if ((order_ascending && ar[i] > ar[i + h]) ||
(!order_ascending && ar[i] < ar[i + h])) {
swap<int>(ar[i], ar[i + h]);
flag = 1;
}
}
if (h == 1 && !flag)
break;
if (h == 9 || h == 10)
h = 11;
if (h > 1)
h = int(h / 1.3);
}
}
int EuclideanAlgorithm(int N, int *ar) {
fn(N - 1) {
while (true) {
if (ar[n] % ar[n + 1] == 0 || ar[n + 1] % ar[n] == 0) {
ar[n + 1] = min(ar[n], ar[n + 1]);
break;
}
if (ar[n] > ar[n + 1]) {
ar[n] %= ar[n + 1];
} else {
ar[n + 1] %= ar[n];
}
}
}
return ar[N - 1];
}
int X[100000], dist[100000];
signed main() {
int ii, jj, kk, ll;
int ret = 0;
int flag = 0;
char cbuf[8192];
int N, M;
gi2(N, M);
if (N >= M) {
ans(0);
return 0;
}
fi(M) { gi(X[i]); }
CombSort(M, X);
fi(M - 1) { dist[i] = X[i + 1] - X[i]; }
if (M >= 3)
CombSort(M - 1, dist);
int sum = 0;
fi(M - 1 - (N - 1)) { sum += dist[i]; }
ans(sum);
wait();
return 0;
} | replace | 133 | 134 | 133 | 134 | TLE | |
p03137 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define REP1(i, n) for (int i = 1, i##_len = (n); i < i##_len; ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define pow(x) x *x
#define ll long long
static const ll MAX = 1000000;
static const ll INFTY = 1e12;
static const ll MOD = 1000000007;
template <typename T> inline string toString(const T &a) {
ostringstream oss;
oss << a;
return oss.str();
};
struct edge {
ll to, cost;
};
using Graph = vector<vector<int>>;
using _Graph = vector<vector<edge>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
// 深さ優先探索
vector<bool> seen;
vector<int> colors;
int H, W, N;
int sx, sy, gx, gy;
vector<vector<char>> field;
vector<vector<int>> dist;
// vector<pair<int, int>> gx, gy;
deque<pair<int, int>> que;
typedef vector<vector<int>> Matrix;
const int INF = 100000000;
int main() {
ll N, M;
cin >> N >> M;
vector<ll> X(M);
REP(i, M) { cin >> X[i]; }
sort(X.begin(), X.end());
vector<ll> diff(M - 1);
ll ans = 0;
REP(i, M - 1) {
diff[i] = X[i + 1] - X[i];
ans += X[i + 1] - X[i];
}
sort(diff.begin(), diff.end(), greater<ll>());
REP(i, N - 1) { ans -= diff[i]; }
cout << ans << endl;
}
/*
_ooOoo_
o8888888o
88" . "88
(| -_- |)
O\ = /O
____/`---'\____
.' \\| |// `.
/ \\||| : |||// \
/ _||||| -:- |||||- \
| | \\\ - /// | |
| \_| ''\---/'' | |
\ .-\__ `-` ___/-. /
___`. .' /--.--\ `. . __
."" '< `.___\_<|>_/___.' >'"".
| | : `- \`.;`\ _ /`;.`/ - ` : | |
\ \ `-. \_ __\ /__ _/ .-` / /
======`-.____`-.___\_____/___.-`____.-'======
`=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pass System Test!
*/
| #include <bits/stdc++.h>
using namespace std;
#define REP1(i, n) for (int i = 1, i##_len = (n); i < i##_len; ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define pow(x) x *x
#define ll long long
static const ll MAX = 1000000;
static const ll INFTY = 1e12;
static const ll MOD = 1000000007;
template <typename T> inline string toString(const T &a) {
ostringstream oss;
oss << a;
return oss.str();
};
struct edge {
ll to, cost;
};
using Graph = vector<vector<int>>;
using _Graph = vector<vector<edge>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
// 深さ優先探索
vector<bool> seen;
vector<int> colors;
int H, W, N;
int sx, sy, gx, gy;
vector<vector<char>> field;
vector<vector<int>> dist;
// vector<pair<int, int>> gx, gy;
deque<pair<int, int>> que;
typedef vector<vector<int>> Matrix;
const int INF = 100000000;
int main() {
ll N, M;
cin >> N >> M;
vector<ll> X(M);
REP(i, M) { cin >> X[i]; }
sort(X.begin(), X.end());
vector<ll> diff(M - 1);
ll ans = 0;
REP(i, M - 1) {
diff[i] = X[i + 1] - X[i];
ans += X[i + 1] - X[i];
}
sort(diff.begin(), diff.end(), greater<ll>());
long long res = X.back() - X[0];
for (int i = 0; i < min((ll)diff.size(), N - 1); ++i)
res -= diff[i];
cout << res << endl;
}
/*
_ooOoo_
o8888888o
88" . "88
(| -_- |)
O\ = /O
____/`---'\____
.' \\| |// `.
/ \\||| : |||// \
/ _||||| -:- |||||- \
| | \\\ - /// | |
| \_| ''\---/'' | |
\ .-\__ `-` ___/-. /
___`. .' /--.--\ `. . __
."" '< `.___\_<|>_/___.' >'"".
| | : `- \`.;`\ _ /`;.`/ - ` : | |
\ \ `-. \_ __\ /__ _/ .-` / /
======`-.____`-.___\_____/___.-`____.-'======
`=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pass System Test!
*/
| replace | 60 | 63 | 60 | 64 | 0 | |
p03137 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> x(m);
for (int i = 0; i < m; i++)
cin >> x[i];
if (m == 1) {
cout << 0 << endl;
return 0;
}
sort(x.begin(), x.end());
priority_queue<int> d;
for (int i = 0; i < m - 1; i++)
d.push(abs(x[i + 1] - x[i]));
for (int i = 0; i < n - 1; i++)
d.pop();
int ans = 0;
while (!d.empty()) {
ans += d.top();
d.pop();
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> x(m);
for (int i = 0; i < m; i++)
cin >> x[i];
if (n >= m) {
cout << 0 << endl;
return 0;
}
sort(x.begin(), x.end());
priority_queue<int> d;
for (int i = 0; i < m - 1; i++)
d.push(abs(x[i + 1] - x[i]));
for (int i = 0; i < n - 1; i++)
d.pop();
int ans = 0;
while (!d.empty()) {
ans += d.top();
d.pop();
}
cout << ans << endl;
return 0;
} | replace | 12 | 13 | 12 | 13 | TLE | |
p03137 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
int n, m;
cin >> n;
cin >> m;
int a[m];
int y[m - 1];
for (int i = 0; i < m; i++) {
cin >> a[i];
}
sort(a, a + m);
for (int i = 0; i < n - 1; i++) {
y[i] = 0;
}
for (int i = 0; i < m - 1; i++) {
y[i] = abs(a[i + 1] - a[i]);
}
sort(y, y + m - 1);
int all = 0;
for (int i = 0; i < m - 1 - (n - 1); i++) {
all += y[i];
}
cout << all << endl;
} | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
int n, m;
cin >> n;
cin >> m;
int a[m];
int y[n - 1];
for (int i = 0; i < m; i++) {
cin >> a[i];
}
sort(a, a + m);
for (int i = 0; i < n - 1; i++) {
y[i] = 0;
}
for (int i = 0; i < m - 1; i++) {
y[i] = abs(a[i + 1] - a[i]);
}
sort(y, y + m - 1);
int all = 0;
for (int i = 0; i < m - 1 - (n - 1); i++) {
all += y[i];
}
cout << all << endl;
} | replace | 13 | 14 | 13 | 14 | 0 | |
p03137 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define fi first
#define se second
#define pii pair<int, int>
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
int x[m];
for (int i = 0; i < m; i++) {
cin >> x[i];
}
sort(x, x + m);
int ans = x[m - 1] - x[0];
if (m > 1) {
vector<int> d(m - 1);
for (int i = 0; i < m - 1; i++) {
d[i] = x[i + 1] - x[i];
}
sort(d.rbegin(), d.rend());
for (int i = 2; i <= n; i++) {
ans -= d[i - 2];
}
}
cout << ans << "\n";
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define fi first
#define se second
#define pii pair<int, int>
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
int x[m];
for (int i = 0; i < m; i++) {
cin >> x[i];
}
sort(x, x + m);
int ans = x[m - 1] - x[0];
if (m > 1) {
vector<int> d(m - 1);
for (int i = 0; i < m - 1; i++) {
d[i] = x[i + 1] - x[i];
}
sort(d.rbegin(), d.rend());
for (int i = 0; i < min(n - 1, sz(d)); i++) {
ans -= d[i];
}
}
cout << ans << "\n";
} | replace | 25 | 27 | 25 | 27 | 0 | |
p03137 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;
#define REP(i, a, b) for (ll i = (a); i < (b); i++)
#define PER(i, a, b) for (ll i = (a); i >= (b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF = 1e16 + 18;
const ll MAX = 100005;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a, b)
#define Each(a, b) for (auto &a : b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) \
cerr << #mp << ":" << endl; \
for (auto i = mp.begin(); i != mp.end(); ++i) { \
cerr << i->first << ":" << i->second << endl; \
}
#define dbgarr(n, m, arr) \
rep(i, n) { \
rep(j, m) { cerr << arr[i][j] << " "; } \
cerr << endl; \
}
#define dbgdp(n, arr) \
rep(i, n) { cerr << arr[i] << " "; } \
cerr << endl;
#define sum(v) accumulate(ALL(v), 0)
#define fi first
#define se second
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) {
return s << "(" << p.first << ", " << p.second << ")";
}
// vector
template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) {
int len = v.size();
for (int i = 0; i < len; ++i) {
s << v[i];
if (i < len - 1)
s << " ";
}
return s;
}
// 2 dimentional vector
template <typename T>
ostream &operator<<(ostream &s, const vector<vector<T>> &vv) {
int len = vv.size();
for (int i = 0; i < len; ++i) {
s << vv[i] << endl;
}
return s;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << std::setprecision(10);
ll n, m;
cin >> n >> m;
Vec x(m);
Vec y(m - 1);
if (n >= m) {
cout << 0 << endl;
}
rep(i, m) { cin >> x[i]; }
sort(ALL(x));
rep(i, m - 1) { y[i] = x[i + 1] - x[i]; }
sort(ALL(y));
Vec s(m);
s[0] = y[0];
rep(i, m - 1) {
if (i == 0)
continue;
s[i] = s[i - 1] + y[i];
}
// dbg(s);
ll ans = s[m - n - 1];
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;
#define REP(i, a, b) for (ll i = (a); i < (b); i++)
#define PER(i, a, b) for (ll i = (a); i >= (b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF = 1e16 + 18;
const ll MAX = 100005;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a, b)
#define Each(a, b) for (auto &a : b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) \
cerr << #mp << ":" << endl; \
for (auto i = mp.begin(); i != mp.end(); ++i) { \
cerr << i->first << ":" << i->second << endl; \
}
#define dbgarr(n, m, arr) \
rep(i, n) { \
rep(j, m) { cerr << arr[i][j] << " "; } \
cerr << endl; \
}
#define dbgdp(n, arr) \
rep(i, n) { cerr << arr[i] << " "; } \
cerr << endl;
#define sum(v) accumulate(ALL(v), 0)
#define fi first
#define se second
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) {
return s << "(" << p.first << ", " << p.second << ")";
}
// vector
template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) {
int len = v.size();
for (int i = 0; i < len; ++i) {
s << v[i];
if (i < len - 1)
s << " ";
}
return s;
}
// 2 dimentional vector
template <typename T>
ostream &operator<<(ostream &s, const vector<vector<T>> &vv) {
int len = vv.size();
for (int i = 0; i < len; ++i) {
s << vv[i] << endl;
}
return s;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << std::setprecision(10);
ll n, m;
cin >> n >> m;
Vec x(m);
Vec y(m - 1);
if (n >= m) {
cout << 0 << endl;
return 0;
}
rep(i, m) { cin >> x[i]; }
sort(ALL(x));
rep(i, m - 1) { y[i] = x[i + 1] - x[i]; }
sort(ALL(y));
Vec s(m);
s[0] = y[0];
rep(i, m - 1) {
if (i == 0)
continue;
s[i] = s[i - 1] + y[i];
}
// dbg(s);
ll ans = s[m - n - 1];
cout << ans << endl;
return 0;
}
| insert | 81 | 81 | 81 | 82 | 0 | |
p03137 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
ll mod = 1e9 + 7;
// ll mod = 998244353;
#define rep(i, n) for (int i = 0; i < (n); ++i)
int main() {
int n, m;
cin >> n >> m;
vector<int> x(m);
rep(i, m) cin >> x[i];
if (m == 1) {
cout << 0 << endl;
return 0;
}
sort(x.begin(), x.end());
vector<int> diff(m - 1);
rep(i, m - 1) { diff[i] = x[i + 1] - x[i]; }
sort(diff.rbegin(), diff.rend());
int ans = 0;
rep(i, m - 1) { ans += diff[i]; }
rep(i, n - 1) { ans -= diff[i]; }
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
ll mod = 1e9 + 7;
// ll mod = 998244353;
#define rep(i, n) for (int i = 0; i < (n); ++i)
int main() {
int n, m;
cin >> n >> m;
vector<int> x(m);
rep(i, m) cin >> x[i];
if (m == 1 || n >= m) {
cout << 0 << endl;
return 0;
}
sort(x.begin(), x.end());
vector<int> diff(m - 1);
rep(i, m - 1) { diff[i] = x[i + 1] - x[i]; }
sort(diff.rbegin(), diff.rend());
int ans = 0;
rep(i, m - 1) { ans += diff[i]; }
rep(i, n - 1) { ans -= diff[i]; }
cout << ans << endl;
return 0;
}
| replace | 23 | 24 | 23 | 24 | 0 | |
p03137 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <vector>
#define MAX_N 100000
#define MAX_M 100000
template <class T, class InputIterator>
bool isin(T x, InputIterator first, InputIterator last) {
return std::any_of(first, last, [x](T y) { return x == y; });
}
int main() {
int n, m;
std::vector<int> x(MAX_M), mark(MAX_M - 1);
std::cin >> n >> m;
if (n >= m) {
std::cout << 0 << std::endl;
return 0;
}
for (int i = 0; i < m; ++i) {
std::cin >> x[i];
mark[i] = i;
}
std::sort(x.begin(), x.begin() + m);
int cost = *(x.begin() + m - 1) - *(x.begin());
std::vector<int> selected(MAX_N - 1);
int count = 0;
while (count < n - 1) {
int max_dist = 0;
int cand;
for (int i = 1; i < m; ++i) {
if (x[i] - x[i - 1] > max_dist &&
not isin(i, selected.begin(), selected.end() + count)) {
max_dist = x[i] - x[i - 1];
cand = i;
}
}
cost -= max_dist;
selected[count] = cand;
count++;
}
std::cout << cost << std::endl;
return 0;
}
| #include <algorithm>
#include <iostream>
#include <vector>
#define MAX_N 100000
#define MAX_M 100000
template <class T, class InputIterator>
bool isin(T x, InputIterator first, InputIterator last) {
return std::any_of(first, last, [x](T y) { return x == y; });
}
int main() {
int n, m;
std::vector<int> x(MAX_M), mark(MAX_M - 1);
std::cin >> n >> m;
if (n >= m) {
std::cout << 0 << std::endl;
return 0;
}
for (int i = 0; i < m; ++i) {
std::cin >> x[i];
mark[i] = i;
}
std::sort(x.begin(), x.begin() + m);
std::vector<int> dist(MAX_M - 1);
for (int i = 1; i < m; ++i) {
dist[i] = x[i] - x[i - 1];
}
std::sort(dist.begin(), dist.begin() + m);
int cost = x[m - 1] - x[0];
for (int i = 0; i < n - 1; ++i) {
cost -= dist[m - 1 - i];
}
std::cout << cost << std::endl;
return 0;
} | replace | 28 | 44 | 28 | 37 | TLE | |
p03137 | C++ | Runtime Error |
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
vector<int> a;
vector<int> b;
int n, x, m;
long long s;
int main() {
cin >> m >> n;
for (int i = 1; i <= n; i++) {
cin >> x;
a.push_back(x);
}
sort(a.begin(), a.end());
for (int i = 0; i < n - 1; i++)
b.push_back(a[i + 1] - a[i]);
sort(b.begin(), b.end(), greater<int>());
s = a[n - 1] - a[0] + 1 - m;
if (s <= 0) {
cout << 0;
} else {
for (int i = 0; i < m - 1; i++) {
s -= b[i] - 1;
}
cout << s;
}
}
|
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
vector<int> a;
vector<int> b;
int n, x, m;
long long s;
int main() {
cin >> m >> n;
for (int i = 1; i <= n; i++) {
cin >> x;
a.push_back(x);
}
sort(a.begin(), a.end());
for (int i = 0; i < n - 1; i++)
b.push_back(a[i + 1] - a[i]);
sort(b.begin(), b.end(), greater<int>());
s = a[n - 1] - a[0] + 1 - m;
if (s <= 0 || m > n) {
cout << 0;
} else {
for (int i = 0; i < m - 1; i++) {
s -= b[i] - 1;
}
cout << s;
}
}
| replace | 27 | 28 | 27 | 28 | 0 | |
p03137 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using vi = vector<int>;
using Graph = vector<vi>;
using P = pair<int, int>;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9;
const ll LINF = (ll)1e18;
int main() {
int n, m;
cin >> n >> m;
vi a(m);
rep(i, m) cin >> a[i];
sort(a.begin(), a.end());
// cout << a[0] << " " << a[m-1] << endl;
int lg = abs(a[0] - a[m - 1]);
if (m == 1) {
cout << 0 << endl;
return 0;
}
// cout << lg << endl;
vi b(m - 1);
rep(i, m - 1) { b[i] = abs(a[i] - a[i + 1]); }
sort(b.begin(), b.end(), greater<int>());
// cout << b[0] << endl;
int cnt = 0;
while (cnt < n - 1) {
lg -= b[cnt];
cnt++;
}
cout << lg << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using vi = vector<int>;
using Graph = vector<vi>;
using P = pair<int, int>;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9;
const ll LINF = (ll)1e18;
int main() {
int n, m;
cin >> n >> m;
vi a(m);
rep(i, m) cin >> a[i];
sort(a.begin(), a.end());
// cout << a[0] << " " << a[m-1] << endl;
int lg = abs(a[0] - a[m - 1]);
if (m == 1) {
cout << 0 << endl;
return 0;
}
// cout << lg << endl;
vi b(m - 1);
rep(i, m - 1) { b[i] = abs(a[i] - a[i + 1]); }
sort(b.begin(), b.end(), greater<int>());
// cout << b[0] << endl;
int cnt = 0;
while (cnt < n - 1 && cnt < m - 1) {
lg -= b[cnt];
cnt++;
}
cout << lg << endl;
} | replace | 29 | 30 | 29 | 30 | 0 | |
p03137 | C++ | Runtime Error | #include <algorithm>
#include <complex>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define REP(i, m, n) for (int i = int(m); i < int(n); i++)
#define RREP(i, m, n) for (int i = int(n) - 1; i >= int(m); --i)
#define EACH(i, c) for (auto &(i) : c)
#define all(c) begin(c), end(c)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(begin(c), end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x) cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) \
do { \
} while (0)
#define dump(x) \
do { \
} while (0)
#define BR
#endif
using namespace std;
using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int, int>;
using VP = vector<PII>;
// struct edge {int from, to, cost;};
constexpr double EPS = 1e-10;
// constexpr double PI = acos(-1.0);
// constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
// inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}
template <class T> inline T sqr(T x) { return x * x; }
void solve() {
int n, m;
cin >> n >> m;
VI x(m);
REP(i, 0, m) cin >> x[i];
REP(i, 0, m) x[i] += 100000;
sort(all(x));
if (m == 1) {
cout << 0 << endl;
return;
}
int sum = 0;
VI ds(m - 1);
REP(i, 0, m - 1) {
int d = x[i + 1] - x[i];
sum += d;
ds[i] = d;
}
sort(all(ds));
reverse(all(ds));
REP(i, 0, n - 1) sum -= ds[i];
cout << sum << endl;
}
int main() {
solve();
return 0;
} | #include <algorithm>
#include <complex>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define REP(i, m, n) for (int i = int(m); i < int(n); i++)
#define RREP(i, m, n) for (int i = int(n) - 1; i >= int(m); --i)
#define EACH(i, c) for (auto &(i) : c)
#define all(c) begin(c), end(c)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(begin(c), end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x) cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) \
do { \
} while (0)
#define dump(x) \
do { \
} while (0)
#define BR
#endif
using namespace std;
using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int, int>;
using VP = vector<PII>;
// struct edge {int from, to, cost;};
constexpr double EPS = 1e-10;
// constexpr double PI = acos(-1.0);
// constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
// inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}
template <class T> inline T sqr(T x) { return x * x; }
void solve() {
int n, m;
cin >> n >> m;
VI x(m);
REP(i, 0, m) cin >> x[i];
REP(i, 0, m) x[i] += 100000;
sort(all(x));
if (m == 1 || n >= m) {
cout << 0 << endl;
return;
}
int sum = 0;
VI ds(m - 1);
REP(i, 0, m - 1) {
int d = x[i + 1] - x[i];
sum += d;
ds[i] = d;
}
sort(all(ds));
reverse(all(ds));
REP(i, 0, n - 1) sum -= ds[i];
cout << sum << endl;
}
int main() {
solve();
return 0;
} | replace | 69 | 70 | 69 | 70 | 0 | |
p03137 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> xv(m);
for (auto &x : xv) {
cin >> x;
}
if (m <= n) {
cout << 0 << endl;
} else {
sort(xv.begin(), xv.end());
vector<int> lv(m - 1);
for (int i = 1; i < m; ++i) {
lv[i] = xv[i] - xv[i - 1];
}
sort(lv.begin(), lv.end());
int ret = 0;
for (int i = 0; i < m - n; ++i) {
ret += lv[i];
}
cout << ret << endl;
}
return 0;
} | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> xv(m);
for (auto &x : xv) {
cin >> x;
}
if (m <= n) {
cout << 0 << endl;
} else {
sort(xv.begin(), xv.end());
vector<int> lv(m - 1);
for (int i = 1; i < m; ++i) {
lv[i - 1] = xv[i] - xv[i - 1];
}
sort(lv.begin(), lv.end());
int ret = 0;
for (int i = 0; i < m - n; ++i) {
ret += lv[i];
}
cout << ret << endl;
}
return 0;
} | replace | 22 | 23 | 22 | 23 | 0 | |
p03137 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
int n, m;
cin >> n >> m;
vector<int> x(m);
for (int i = 0; i < m; i++) {
cin >> x[i];
}
if (m == 1)
cout << 0 << endl;
else {
sort(x.begin(), x.end());
vector<int> l(m - 1, 0);
for (int i = 0; i < m - 1; i++) {
l[i] = x[i + 1] - x[i];
}
sort(l.begin(), l.end());
reverse(l.begin(), l.end());
int sum = 0;
for (int i = 0; i < n - 1; i++) {
sum += l[i];
}
cout << x[m - 1] - x[0] - sum << endl;
}
return 0;
}
| #include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
int n, m;
cin >> n >> m;
vector<int> x(m);
for (int i = 0; i < m; i++) {
cin >> x[i];
}
if (n >= m)
cout << 0 << endl;
else {
sort(x.begin(), x.end());
vector<int> l(m - 1, 0);
for (int i = 0; i < m - 1; i++) {
l[i] = x[i + 1] - x[i];
}
sort(l.begin(), l.end());
reverse(l.begin(), l.end());
int sum = 0;
for (int i = 0; i < n - 1; i++) {
sum += l[i];
}
cout << x[m - 1] - x[0] - sum << endl;
}
return 0;
}
| replace | 22 | 23 | 22 | 23 | 0 | |
p03137 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <iomanip>
#define ll long long
using namespace std;
int main() {
ll N, M;
cin >> N >> M;
vector<ll> X(M);
if (M != 1) {
vector<ll> d(M - 1);
for (ll i = 0; i < M; i++)
cin >> X.at(i);
sort(X.begin(), X.end());
ll ans = X.at(M - 1) - X.at(0);
for (ll i = 0; i < M - 1; i++)
d.at(i) = X.at(i + 1) - X.at(i);
sort(d.begin(), d.end());
for (ll i = 0; i < N - 1; i++)
ans -= d.at(M - 2 - i);
cout << ans << endl;
} else
cout << 0 << endl;
}
| #include <bits/stdc++.h>
#include <iomanip>
#define ll long long
using namespace std;
int main() {
ll N, M;
cin >> N >> M;
vector<ll> X(M);
if (M != 1) {
if (N < M) {
vector<ll> d(M - 1);
for (ll i = 0; i < M; i++)
cin >> X.at(i);
sort(X.begin(), X.end());
ll ans = X.at(M - 1) - X.at(0);
for (ll i = 0; i < M - 1; i++)
d.at(i) = X.at(i + 1) - X.at(i);
sort(d.begin(), d.end());
for (ll i = 0; i < N - 1; i++)
ans -= d.at(M - 2 - i);
cout << ans << endl;
} else
cout << 0 << endl;
} else
cout << 0 << endl;
}
| replace | 10 | 21 | 10 | 24 | 0 | |
p03137 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, x, n) for (int i = (x); i < (n); i++)
#define reps(i, x, n) for (int i = (x); i <= (n); i++)
#define lol long long
#define SUM(n) (((n) + 1) * (n) / 2) // 1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed << setprecision(x + 1) // 小数点桁数を指定する
#define abs(x, y) (max(x, y) - min(x, y))
#define all(v) v.begin(), v.end()
#define UPDigit(a, b) ((a + b - 1) / b) // 小数点切り上げ
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD = int(1e9) + 7;
using namespace std;
using pii = pair<lol, lol>;
typedef vector<int> vit;
// 八方向を見るのに使うと便利(楽)
const int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
// 最大公約数
lol gcd(lol x, lol y) { return (y != 0 ? gcd(y, x % y) : x); }
// 最小公倍数
lol lcm(lol x, lol y) { return ((x * y) / gcd(max(x, y), min(x, y))); }
signed main(void) {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
int n, m;
cin >> n >> m;
int x[m + 5];
rep(i, 0, m) { cin >> x[i]; }
sort(x, x + m);
if (m == 1) {
cout << "0\n";
return 0;
}
priority_queue<int> que;
rep(i, 1, m) { que.push(abs(x[i - 1], x[i])); }
rep(i, 1, n) { que.pop(); }
lol ans = 0;
while (!que.empty()) {
ans += que.top();
que.pop();
}
cout << ans << '\n';
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, x, n) for (int i = (x); i < (n); i++)
#define reps(i, x, n) for (int i = (x); i <= (n); i++)
#define lol long long
#define SUM(n) (((n) + 1) * (n) / 2) // 1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed << setprecision(x + 1) // 小数点桁数を指定する
#define abs(x, y) (max(x, y) - min(x, y))
#define all(v) v.begin(), v.end()
#define UPDigit(a, b) ((a + b - 1) / b) // 小数点切り上げ
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD = int(1e9) + 7;
using namespace std;
using pii = pair<lol, lol>;
typedef vector<int> vit;
// 八方向を見るのに使うと便利(楽)
const int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
// 最大公約数
lol gcd(lol x, lol y) { return (y != 0 ? gcd(y, x % y) : x); }
// 最小公倍数
lol lcm(lol x, lol y) { return ((x * y) / gcd(max(x, y), min(x, y))); }
signed main(void) {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
int n, m;
cin >> n >> m;
n = min(n, m);
int x[m + 5];
rep(i, 0, m) { cin >> x[i]; }
sort(x, x + m);
if (m == 1) {
cout << "0\n";
return 0;
}
priority_queue<int> que;
rep(i, 1, m) { que.push(abs(x[i - 1], x[i])); }
rep(i, 1, n) { que.pop(); }
lol ans = 0;
while (!que.empty()) {
ans += que.top();
que.pop();
}
cout << ans << '\n';
return 0;
}
| insert | 34 | 34 | 34 | 35 | TLE | |
p03137 | C++ | Runtime Error | #include "bits/stdc++.h"
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<VVLL> VVVLL;
#define SORT_ASC(c) sort((c).begin(), (c).end())
#define SORT_DESC(c) \
sort((c).begin(), (c).end(), greater<typeof((c).begin())>())
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SIZE(a) int((a).size())
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INT_LARGE = 1000000100;
// debug func
template <typename T> void vecprint(vector<T> v) {
for (auto x : v) {
cerr << x << " ";
}
cerr << endl;
}
template <typename T> void vecvecprint(vector<vector<T>> vv) {
REP(i, SIZE(vv)) {
REP(j, SIZE(vv[i])) { cerr << vv[i][j] << " "; }
cerr << endl;
}
}
template <typename T> void pqprint(priority_queue<T> q) {
while (!q.empty()) {
cerr << q.top() << " ";
q.pop();
}
cerr << endl;
}
template <typename T> void qprint(queue<T> q) {
while (!q.empty()) {
cerr << q.front() << " ";
q.pop();
}
cerr << endl;
}
template <typename T> void vecqprint(vector<queue<T>> v) {
for (int i = 0; i < v.size(); i++) {
qprint(v[i]);
}
}
template <typename Iterator>
inline bool next_combination(const Iterator first, Iterator k,
const Iterator last) {
/* Credits: Thomas Draper */
if ((first == last) || (first == k) || (last == k))
return false;
Iterator itr1 = first;
Iterator itr2 = last;
++itr1;
if (last == itr1)
return false;
itr1 = last;
--itr1;
itr1 = k;
--itr2;
while (first != itr1) {
if (*--itr1 < *itr2) {
Iterator j = k;
while (!(*itr1 < *j))
++j;
iter_swap(itr1, j);
++itr1;
++j;
itr2 = k;
rotate(itr1, j, last);
while (last != j) {
++j;
++itr2;
}
rotate(k, itr2, last);
return true;
}
}
rotate(first, k, last);
return false;
}
inline double get_time_sec(void) {
return static_cast<double>(chrono::duration_cast<chrono::nanoseconds>(
chrono::steady_clock::now().time_since_epoch())
.count()) /
1000000000;
}
template <typename T> T gcd(T a, T b) {
if (a > b)
swap(a, b);
if (a == 0)
return b;
else
return gcd(b % a, a);
}
template <typename T> map<T, T> prime_list(T n) {
map<T, T> ret;
for (T i = 2; i * i <= n; i++) {
if (n % i == 0) {
ret[i] = 0;
while (n % i == 0) {
n /= i;
ret[i]++;
}
}
}
if (n != 1)
ret[n]++;
return ret;
}
int main(void) {
int n, m;
cin >> n >> m;
VI vm(m, 0);
REP(i, m) cin >> vm[i];
if (n >= m) {
cout << 0 << endl;
return 0;
}
sort(vm.begin(), vm.end());
VI vn(m - 1, 0);
REP(i, m) { vn[i] = vm[i + 1] - vm[i]; }
// vecprint(vm);
// vecprint(vn);
sort(vn.begin(), vn.end(), greater<int>());
int ans = vm[m - 1] - vm[0];
REP(i, n - 1) { ans -= vn[i]; }
cout << ans << endl;
} | #include "bits/stdc++.h"
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<VVLL> VVVLL;
#define SORT_ASC(c) sort((c).begin(), (c).end())
#define SORT_DESC(c) \
sort((c).begin(), (c).end(), greater<typeof((c).begin())>())
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SIZE(a) int((a).size())
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INT_LARGE = 1000000100;
// debug func
template <typename T> void vecprint(vector<T> v) {
for (auto x : v) {
cerr << x << " ";
}
cerr << endl;
}
template <typename T> void vecvecprint(vector<vector<T>> vv) {
REP(i, SIZE(vv)) {
REP(j, SIZE(vv[i])) { cerr << vv[i][j] << " "; }
cerr << endl;
}
}
template <typename T> void pqprint(priority_queue<T> q) {
while (!q.empty()) {
cerr << q.top() << " ";
q.pop();
}
cerr << endl;
}
template <typename T> void qprint(queue<T> q) {
while (!q.empty()) {
cerr << q.front() << " ";
q.pop();
}
cerr << endl;
}
template <typename T> void vecqprint(vector<queue<T>> v) {
for (int i = 0; i < v.size(); i++) {
qprint(v[i]);
}
}
template <typename Iterator>
inline bool next_combination(const Iterator first, Iterator k,
const Iterator last) {
/* Credits: Thomas Draper */
if ((first == last) || (first == k) || (last == k))
return false;
Iterator itr1 = first;
Iterator itr2 = last;
++itr1;
if (last == itr1)
return false;
itr1 = last;
--itr1;
itr1 = k;
--itr2;
while (first != itr1) {
if (*--itr1 < *itr2) {
Iterator j = k;
while (!(*itr1 < *j))
++j;
iter_swap(itr1, j);
++itr1;
++j;
itr2 = k;
rotate(itr1, j, last);
while (last != j) {
++j;
++itr2;
}
rotate(k, itr2, last);
return true;
}
}
rotate(first, k, last);
return false;
}
inline double get_time_sec(void) {
return static_cast<double>(chrono::duration_cast<chrono::nanoseconds>(
chrono::steady_clock::now().time_since_epoch())
.count()) /
1000000000;
}
template <typename T> T gcd(T a, T b) {
if (a > b)
swap(a, b);
if (a == 0)
return b;
else
return gcd(b % a, a);
}
template <typename T> map<T, T> prime_list(T n) {
map<T, T> ret;
for (T i = 2; i * i <= n; i++) {
if (n % i == 0) {
ret[i] = 0;
while (n % i == 0) {
n /= i;
ret[i]++;
}
}
}
if (n != 1)
ret[n]++;
return ret;
}
int main(void) {
int n, m;
cin >> n >> m;
VI vm(m, 0);
REP(i, m) cin >> vm[i];
if (n >= m) {
cout << 0 << endl;
return 0;
}
sort(vm.begin(), vm.end());
VI vn(m - 1, 0);
REP(i, m - 1) { vn[i] = vm[i + 1] - vm[i]; }
// vecprint(vm);
// vecprint(vn);
sort(vn.begin(), vn.end(), greater<int>());
int ans = vm[m - 1] - vm[0];
REP(i, n - 1) { ans -= vn[i]; }
cout << ans << endl;
} | replace | 147 | 148 | 147 | 148 | 0 | |
p03137 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define all(x) begin(x), end(x)
typedef long long ll;
typedef pair<int, int> pii;
const int inf = 1010001000;
const ll INF = 1001000100010001000;
const int mod = (int)1e9 + 7;
int main() {
int n, m;
cin >> n >> m;
vector<int> x(m);
rep(i, 0, m) { cin >> x.at(i); }
sort(all(x));
vector<int> sa(m - 1);
if (m == 1) {
cout << 0 << endl;
return 0;
}
rep(i, 0, m - 1) { sa.at(i) = abs(x.at(i + 1) - x.at(i)); }
sort(all(sa), greater<int>());
int sum = 0;
if (n == 1) {
cout << abs(x.at(m - 1) - x.at(0)) << endl;
return 0;
}
rep(i, 0, n - 1) {
sum += sa.at(i);
// cout<<sa.at(i)<<endl;
}
cout << abs(x.at(m - 1) - x.at(0)) - sum << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define all(x) begin(x), end(x)
typedef long long ll;
typedef pair<int, int> pii;
const int inf = 1010001000;
const ll INF = 1001000100010001000;
const int mod = (int)1e9 + 7;
int main() {
int n, m;
cin >> n >> m;
vector<int> x(m);
rep(i, 0, m) { cin >> x.at(i); }
sort(all(x));
vector<int> sa(m - 1);
if (m == 1 or n >= m) {
cout << 0 << endl;
return 0;
}
rep(i, 0, m - 1) { sa.at(i) = abs(x.at(i + 1) - x.at(i)); }
sort(all(sa), greater<int>());
int sum = 0;
if (n == 1) {
cout << abs(x.at(m - 1) - x.at(0)) << endl;
return 0;
}
rep(i, 0, n - 1) {
sum += sa.at(i);
// cout<<sa.at(i)<<endl;
}
cout << abs(x.at(m - 1) - x.at(0)) - sum << endl;
return 0;
}
| replace | 19 | 20 | 19 | 20 | 0 | |
p03137 | C++ | Runtime Error | #include <bits/stdc++.h>
const int INF = 1e9;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
#define SCIN(n) \
string(n); \
cin >> (n)
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define ALL(obj) (obj).begin(), (obj).end()
#define rt return
#define ENDL cout << endl
#define s second
#define f first
typedef string::const_iterator State;
class PalseError {};
class Edge {
public:
LL from, to, value;
Edge(LL a, LL b, LL c) {
from = a;
to = b;
value = c;
}
Edge(LL a, LL b) {
from = a;
to = b;
}
};
int main() {
int N, M;
cin >> N >> M;
vector<int> vec;
for (int a = 0; a < M; a++) {
int b;
cin >> b;
vec.push_back(b);
}
sort(vec.begin(), vec.end());
vector<int> diff;
for (int a = 0; a < M - 1; a++) {
diff.push_back(vec.at(a + 1) - vec.at(a));
}
sort(diff.begin(), diff.end());
reverse(diff.begin(), diff.end());
LL ans = vec.back() - vec.front();
for (int a = 0; a < N - 1; a++) {
ans -= diff.at(a);
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
const int INF = 1e9;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
#define SCIN(n) \
string(n); \
cin >> (n)
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define ALL(obj) (obj).begin(), (obj).end()
#define rt return
#define ENDL cout << endl
#define s second
#define f first
typedef string::const_iterator State;
class PalseError {};
class Edge {
public:
LL from, to, value;
Edge(LL a, LL b, LL c) {
from = a;
to = b;
value = c;
}
Edge(LL a, LL b) {
from = a;
to = b;
}
};
int main() {
int N, M;
cin >> N >> M;
if (N >= M) {
cout << 0 << endl;
return 0;
}
vector<int> vec;
for (int a = 0; a < M; a++) {
int b;
cin >> b;
vec.push_back(b);
}
sort(vec.begin(), vec.end());
vector<int> diff;
for (int a = 0; a < M - 1; a++) {
diff.push_back(vec.at(a + 1) - vec.at(a));
}
sort(diff.begin(), diff.end());
reverse(diff.begin(), diff.end());
LL ans = vec.back() - vec.front();
for (int a = 0; a < N - 1; a++) {
ans -= diff.at(a);
}
cout << ans << endl;
}
| insert | 40 | 40 | 40 | 44 | 0 | |
p03137 | C++ | Runtime Error | #include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9 + 7;
typedef pair<ll, ll> pairs;
typedef vector<pairs> p;
struct Edge {
ll to, weight;
Edge(ll t, ll w) : to(t), weight(w) {}
};
using graph = vector<vector<ll>>;
using Graph = vector<vector<Edge>>;
ll gcd(ll a, ll b) {
if (b == 0) {
return a;
} else {
return gcd(b, a % b);
}
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll keta(ll N) {
int tmp{};
while (N > 0) {
tmp += (N % 10);
N /= 10;
}
N = tmp;
return N;
}
// 回文
bool kai(string S) {
bool flag = true;
for (ll i = 0; i < S.size() / 2; ++i) {
if (S[i] != S[S.size() - i - 1]) {
flag = false;
break;
}
}
return flag;
}
// ---------------------------------------------
int main() {
ll n, m;
cin >> n >> m;
vector<ll> x(m);
for (ll i = 0; i < m; ++i) {
cin >> x[i];
}
sort(x.begin(), x.end());
vector<ll> d(m - 1);
for (ll i = 0; i < m - 1; ++i) {
d[i] = x[i + 1] - x[i];
}
sort(d.begin(), d.end());
ll ans = 0;
for (ll i = 0; i < d.size() - (n - 1); ++i) {
ans += d[i];
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9 + 7;
typedef pair<ll, ll> pairs;
typedef vector<pairs> p;
struct Edge {
ll to, weight;
Edge(ll t, ll w) : to(t), weight(w) {}
};
using graph = vector<vector<ll>>;
using Graph = vector<vector<Edge>>;
ll gcd(ll a, ll b) {
if (b == 0) {
return a;
} else {
return gcd(b, a % b);
}
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll keta(ll N) {
int tmp{};
while (N > 0) {
tmp += (N % 10);
N /= 10;
}
N = tmp;
return N;
}
// 回文
bool kai(string S) {
bool flag = true;
for (ll i = 0; i < S.size() / 2; ++i) {
if (S[i] != S[S.size() - i - 1]) {
flag = false;
break;
}
}
return flag;
}
// ---------------------------------------------
int main() {
ll n, m;
cin >> n >> m;
n = min(n, m);
vector<ll> x(m);
for (ll i = 0; i < m; ++i) {
cin >> x[i];
}
sort(x.begin(), x.end());
vector<ll> d(m - 1);
for (ll i = 0; i < m - 1; ++i) {
d[i] = x[i + 1] - x[i];
}
sort(d.begin(), d.end());
ll ans = 0;
for (ll i = 0; i < d.size() - (n - 1); ++i) {
ans += d[i];
}
cout << ans << endl;
return 0;
} | insert | 53 | 53 | 53 | 54 | 0 | |
p03137 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <math.h>
#include <stack>
#include <string>
#include <vector>
// #include<stdlib.h>
using namespace std;
int main() {
int n, m, a = 0;
cin >> n >> m;
vector<int> x(n);
vector<int> l(n - 1);
for (int i = 0; i < n; i++) {
cin >> x[i];
}
std::sort(x.begin(), x.end());
for (int i = 0; i < n - 1; i++) {
l[i] = x[i + 1] - x[i];
}
std::sort(l.begin(), l.end());
for (int i = 0; i < n + 1 - n; i++) {
a += l[i];
}
cout << a;
return 0;
} | #include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <math.h>
#include <stack>
#include <string>
#include <vector>
// #include<stdlib.h>
using namespace std;
int main() {
int n, m, a = 0;
cin >> n >> m;
vector<int> x(m);
vector<int> l(m - 1);
if (m == 1) {
a = 0;
} else {
for (int i = 0; i < m; i++) {
cin >> x[i];
}
std::sort(x.begin(), x.end());
for (int i = 0; i < m - 1; i++) {
l[i] = x[i + 1] - x[i];
}
std::sort(l.begin(), l.end());
for (int i = 0; i < m - n; i++) {
a += l[i];
}
}
cout << a;
return 0;
} | replace | 13 | 25 | 13 | 29 | 0 | |
p03137 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, N) for (int i = 0; i < (N); i++)
#define swap(a, b) (a += b, b = a - b, a -= b)
using namespace std;
int main() {
int N, M;
cin >> N >> M;
vector<int> a(M), b(M - 1);
rep(i, M) { cin >> a[i]; }
sort(a.begin(), a.end());
rep(i, M - 1) { b[i] = a[i + 1] - a[i]; }
sort(b.begin(), b.end());
reverse(b.begin(), b.end());
rep(i, N + 1) { b[i] = 0; }
int sum = 0;
rep(i, M) { sum += b[i]; }
cout << sum << endl;
} | #include <bits/stdc++.h>
#define rep(i, N) for (int i = 0; i < (N); i++)
#define swap(a, b) (a += b, b = a - b, a -= b)
using namespace std;
int main() {
int N, M;
cin >> N >> M;
vector<int> a(M), b(M - 1);
rep(i, M) { cin >> a[i]; }
if (N >= M) {
cout << 0 << endl;
} else {
sort(a.begin(), a.end());
rep(i, M - 1) { b[i] = abs(a[i + 1] - a[i]); }
sort(b.begin(), b.end());
reverse(b.begin(), b.end());
rep(i, N - 1) { b[i] = 0; }
int sum = 0;
rep(i, M - 1) { sum += b[i]; }
cout << sum << endl;
}
} | replace | 10 | 18 | 10 | 23 | 0 | |
p03137 | C++ | Runtime Error | #include <iostream>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long LL;
typedef unsigned int UI;
#define DescSort(a) sort(a.begin(), a.end(), std::greater<LL>())
#define Sort(a) sort(a.begin(), a.end())
int main(int argc, const char *argv[]) {
cin.tie(0);
ios::sync_with_stdio(false);
LL N, M;
LL ans = 0;
cin >> N >> M;
vector<LL> X((UI)M);
for (int i = 0; i < M; i++) {
cin >> X.at(i);
}
Sort(X);
vector<LL> L((UI)M - 1, 0); // 差分
for (int i = 1; i < M; i++) {
L[i - 1] = X[i] - X[i - 1];
}
Sort(L);
for (UI i = 0; i < L.size() - 1; i++) { // 最大のものだけ除く
ans += L[i];
}
cout << ans << endl;
return 0;
} | #include <iostream>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long LL;
typedef unsigned int UI;
#define DescSort(a) sort(a.begin(), a.end(), std::greater<LL>())
#define Sort(a) sort(a.begin(), a.end())
int main(int argc, const char *argv[]) {
cin.tie(0);
ios::sync_with_stdio(false);
LL N, M;
LL ans = 0;
cin >> N >> M;
vector<LL> X((UI)M);
for (int i = 0; i < M; i++) {
cin >> X.at(i);
}
Sort(X);
vector<LL> L((UI)M - 1, 0); // 差分
for (int i = 1; i < M; i++) {
L[i - 1] = X[i] - X[i - 1];
}
Sort(L);
for (UI i = 0; i < M - N; i++) {
ans += L[i];
}
cout << ans << endl;
return 0;
} | replace | 55 | 56 | 55 | 56 | 0 | |
p03137 | C++ | Time Limit Exceeded | #include <iostream>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long LL;
typedef unsigned int UI;
#define rSort(a) sort(a.rbegin(), a.rend())
#define Sort(a) sort(a.begin(), a.end())
#define Sum(a) accumulate(a.begin(), a.end(), 0)
#define rep(i, n) for (UI i = 0; i < n; i++)
int main(int argc, const char *argv[]) {
cin.tie(0);
ios::sync_with_stdio(false);
LL N, M;
LL calc = 0;
LL sum = 0;
LL ans = 0;
cin >> N >> M;
vector<LL> X((UI)M);
rep(i, M) { cin >> X[i]; }
Sort(X);
vector<LL> Y;
rep(i, X.size() - 1) {
Y.push_back(X[i + 1] - X[i]);
sum += Y[i];
}
rSort(Y);
if (N >= M) {
ans = 0;
} else {
rep(i, i < N - 1) {
calc += Y[i]; // 除去する分
}
ans = sum - calc;
}
cout << ans << endl;
return 0;
} | #include <iostream>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long LL;
typedef unsigned int UI;
#define rSort(a) sort(a.rbegin(), a.rend())
#define Sort(a) sort(a.begin(), a.end())
#define Sum(a) accumulate(a.begin(), a.end(), 0)
#define rep(i, n) for (UI i = 0; i < n; i++)
int main(int argc, const char *argv[]) {
cin.tie(0);
ios::sync_with_stdio(false);
LL N, M;
LL calc = 0;
LL sum = 0;
LL ans = 0;
cin >> N >> M;
vector<LL> X((UI)M);
rep(i, M) { cin >> X[i]; }
Sort(X);
vector<LL> Y;
rep(i, X.size() - 1) {
Y.push_back(X[i + 1] - X[i]);
sum += Y[i];
}
rSort(Y);
if (N >= M) {
ans = 0;
} else {
rep(i, N - 1) {
calc += Y[i]; // 除去する分
}
ans = sum - calc;
}
cout << ans << endl;
return 0;
} | replace | 61 | 62 | 61 | 62 | TLE | |
p03137 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, M, t;
long long res = 0;
cin >> N >> M;
if (M > 1) {
vector<int> v(M, 0);
vector<int> v2(M, 0);
for (int i = 0; i < M; i++) {
cin >> v[i];
}
sort(v.begin(), v.end());
res = v[M - 1] - v[0];
for (int i = 1; i < M; i++) {
t = v[i] - v[i - 1];
v2[i] = t;
}
sort(v2.rbegin(), v2.rend());
for (int j = 0; j < N - 1; j++) {
res -= v2[j];
}
}
cout << res << endl;
}
// sort(v.rbegin(), v.rend(), [](auto& x, auto& y){return x[1] < y[1];}); | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, M, t;
long long res = 0;
cin >> N >> M;
if (M > 1) {
vector<int> v(M, 0);
vector<int> v2(M, 0);
for (int i = 0; i < M; i++) {
cin >> v[i];
}
sort(v.begin(), v.end());
res = v[M - 1] - v[0];
for (int i = 1; i < M; i++) {
t = v[i] - v[i - 1];
v2[i] = t;
}
sort(v2.rbegin(), v2.rend());
t = min(N - 1, M);
for (int j = 0; j < t; j++) {
res -= v2[j];
}
}
cout << res << endl;
}
// sort(v.rbegin(), v.rend(), [](auto& x, auto& y){return x[1] < y[1];}); | replace | 23 | 24 | 23 | 25 | 0 | |
p03137 | C++ | Runtime Error | // AtCoder.cpp : このファイルには 'main'
// 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//
// AtCoder.cpp : このファイルには 'main'
// 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//
#ifndef ONLINE_JUDGE
#endif
#define _USE_MATH_DEFINES
#include <math.h>
// #include<cmath>
#include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <chrono>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_set>
#include <vector>
#pragma GCC optimize("Ofast")
// #include "Ants.h"
using namespace std;
typedef long long ll;
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (ll i = 0; i < n; i++)
#define show(s) cout << s << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define LINF (1LL << 50)
#define MOD (1e9 + 7)
#define rrep(i, n) for (int i = 1; i <= n; ++i)
typedef pair<ll, ll> P;
ll gcd(ll a, ll b) { // 最大公約数を求める///最大公倍数a*b/gcd(a,b)
if (b == 0)
return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) { // 最小公倍数を求める b=0のときaを返す
if (b == 0)
return a;
return (a / gcd(a, b)) * b;
}
vector<int> divnum(ll num) { // 分けたものを返す
int dig;
vector<int> p;
while (num) {
dig = num % 10;
p.push_back(dig);
num /= 10;
}
return p;
}
int digiter(ll num) { // 桁数を返す
int dig;
vector<int> p;
while (num) {
dig = num % 10;
p.push_back(dig);
num /= 10;
}
return p.size();
}
vector<int> convertstring(string s) {
vector<int> d;
ll n = s.size();
rep(i, n) { d.push_back(s[i] - '0'); }
return d;
}
map<ll, int> prime_factor(ll n) {
map<ll, int> ret;
for (ll i = 2; i * i <= n; i++) {
while (n % i == 0) {
ret[i]++;
n /= i;
}
}
if (n != 1)
ret[n] = 1;
return ret;
}
vector<ll> Enumeration(ll n) { // 約数列挙
vector<ll> res;
for (ll i = 1; i * i <= n; i++) {
if (n % i != 0)
continue;
res.push_back(i);
if (i * i != n)
res.push_back(n / i);
}
return res;
}
ll myPow(ll x, ll n, ll m) { // x^n
if (n == 0)
return 1;
if (n % 2 == 0)
return myPow(x * x % m, n / 2, m);
else
return x * myPow(x, n - 1, m) % m;
}
std::vector<int> Eratosthenes(const int N) // 素数列挙
{
std::vector<bool> is_prime(N + 1);
for (int i = 0; i <= N; i++) {
is_prime[i] = true;
}
std::vector<int> P;
for (int i = 2; i <= N; i++) {
if (is_prime[i]) {
for (int j = 2 * i; j <= N; j += i) {
is_prime[j] = false;
}
P.emplace_back(i);
}
}
return P;
}
const ll mod = MOD;
struct mint {
ll x; // typedef long long ll;
mint(ll x = 0) : x((x % mod + mod) % mod) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint a) {
if ((x += a.x) >= mod)
x -= mod;
return *this;
}
mint &operator-=(const mint a) {
if ((x += mod - a.x) >= mod)
x -= mod;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const { return mint(*this) += a; }
mint operator-(const mint a) const { return mint(*this) -= a; }
mint operator*(const mint a) const { return mint(*this) *= a; }
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(mod - 2); }
mint &operator/=(const mint a) { return *this *= a.inv(); }
mint operator/(const mint a) const { return mint(*this) /= a; }
explicit operator int() const { return x; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
struct combination { // comb(a,b)でよぶaCb
vector<mint> fact, ifact;
combination(ll n) : fact(n + 1), ifact(n + 1) {
assert(n < mod);
fact[0] = 1;
for (ll i = 1; i <= n; ++i)
fact[i] = fact[i - 1] * i;
ifact[n] = fact[n].inv();
for (ll i = n; i >= 1; --i)
ifact[i - 1] = ifact[i] * i;
}
mint operator()(ll n, ll k) {
if (k < 0 || k > n)
return 0;
return fact[n] * ifact[k] * ifact[n - k];
}
} comb(1000005); // comb貯め
mint f(ll n, ll k) {
if (n < 0)
return 0;
// nPk = nCk * k!
mint res = comb(n, k);
res *= comb.fact[k];
return res;
}
struct SegmentTree {
private:
int n;
vector<int> node;
public:
SegmentTree(vector<int> v) { // SegmentTree seg(vector<int>(N,INF))で呼び出し
int sz = v.size();
n = 1;
while (n < sz)
n *= 2;
node.resize(2 * n - 1, INF);
for (int i = 0; i < sz; i++)
node[i + n - 1] = v[i];
for (int i = n - 2; i >= 0; i--)
node[i] = min(node[2 * i + 1], node[2 * i + 2]);
}
void update(int x, int val) {
x += (n - 1);
node[x] = val;
while (x > 0) {
x = (x - 1) / 2;
node[x] = min(node[2 * x + 1], node[2 * x + 2]);
}
}
int getmin(int a, int b, int k = 0, int l = 0, int r = -1) {
if (r < 0)
r = n;
if (r <= a || b <= l)
return INF;
if (a <= l && r <= b)
return node[k];
int vl = getmin(a, b, 2 * k + 1, l, (l + r) / 2);
int vr = getmin(a, b, 2 * k + 2, (l + r) / 2, r);
return min(vl, vr);
}
};
// 1-indexedなので注意。
struct BIT {
private:
vector<int> bit;
int N;
public:
BIT(int size) {
N = size;
bit.resize(N + 1);
}
// 一点更新です
void add(int a, int w) { // a番目にwを加算
for (int x = a; x <= N; x += x & -x)
bit[x] += w;
}
// 1~a(以下)までの和を求める。
int sum(int a) {
int ret = 0;
for (int x = a; x > 0; x -= x & -x)
ret += bit[x];
return ret;
}
};
/****Union-Ford-Tree***/
int par[int(0x7ffffff)]; // Parent
int Rank[int(0x7ffffff)]; // Deep_of_the_Tree
// int a[100] = { 4,2,3,1,5 }, m[100] ={3,2,2};
// int n = 0;
// const ll mod = 1000000007;
/*
//n要素で初期化
void init(int n) {
for (int i = 0; i < n; i++) {
par[i] = i;
Rank[i] = 0;
}
}
//木の根探し
int find(int x) {
if (par[x] == x) {
return x;
}
else {
return par[x] = find(par[x]);
}
}
//xとyの属する集合を併合
void unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y)return;
if (Rank[x] < Rank[y]) {
par[x] = y;
}
else {
par[y] = x;
if (Rank[x] == Rank[y])Rank[x]++;
}
}
bool same(int x, int y) {
return find(x) == find(y);
}*/
// queue古い順,stack新しい順
/************************************************************************************/
int N, M;
int X[100005];
int32_t main() {
cin >> N >> M;
rep(i, M) cin >> X[i];
sort(X, X + M);
vector<int> L;
rep(i, M - 1) { L.push_back(X[i + 1] - X[i]); }
sort(L.rbegin(), L.rend());
int res = 0;
rep(i, N - 1) { res += L[i]; }
cout << X[M - 1] - X[0] - res << endl;
}
| // AtCoder.cpp : このファイルには 'main'
// 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//
// AtCoder.cpp : このファイルには 'main'
// 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//
#ifndef ONLINE_JUDGE
#endif
#define _USE_MATH_DEFINES
#include <math.h>
// #include<cmath>
#include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <chrono>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_set>
#include <vector>
#pragma GCC optimize("Ofast")
// #include "Ants.h"
using namespace std;
typedef long long ll;
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (ll i = 0; i < n; i++)
#define show(s) cout << s << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define LINF (1LL << 50)
#define MOD (1e9 + 7)
#define rrep(i, n) for (int i = 1; i <= n; ++i)
typedef pair<ll, ll> P;
ll gcd(ll a, ll b) { // 最大公約数を求める///最大公倍数a*b/gcd(a,b)
if (b == 0)
return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) { // 最小公倍数を求める b=0のときaを返す
if (b == 0)
return a;
return (a / gcd(a, b)) * b;
}
vector<int> divnum(ll num) { // 分けたものを返す
int dig;
vector<int> p;
while (num) {
dig = num % 10;
p.push_back(dig);
num /= 10;
}
return p;
}
int digiter(ll num) { // 桁数を返す
int dig;
vector<int> p;
while (num) {
dig = num % 10;
p.push_back(dig);
num /= 10;
}
return p.size();
}
vector<int> convertstring(string s) {
vector<int> d;
ll n = s.size();
rep(i, n) { d.push_back(s[i] - '0'); }
return d;
}
map<ll, int> prime_factor(ll n) {
map<ll, int> ret;
for (ll i = 2; i * i <= n; i++) {
while (n % i == 0) {
ret[i]++;
n /= i;
}
}
if (n != 1)
ret[n] = 1;
return ret;
}
vector<ll> Enumeration(ll n) { // 約数列挙
vector<ll> res;
for (ll i = 1; i * i <= n; i++) {
if (n % i != 0)
continue;
res.push_back(i);
if (i * i != n)
res.push_back(n / i);
}
return res;
}
ll myPow(ll x, ll n, ll m) { // x^n
if (n == 0)
return 1;
if (n % 2 == 0)
return myPow(x * x % m, n / 2, m);
else
return x * myPow(x, n - 1, m) % m;
}
std::vector<int> Eratosthenes(const int N) // 素数列挙
{
std::vector<bool> is_prime(N + 1);
for (int i = 0; i <= N; i++) {
is_prime[i] = true;
}
std::vector<int> P;
for (int i = 2; i <= N; i++) {
if (is_prime[i]) {
for (int j = 2 * i; j <= N; j += i) {
is_prime[j] = false;
}
P.emplace_back(i);
}
}
return P;
}
const ll mod = MOD;
struct mint {
ll x; // typedef long long ll;
mint(ll x = 0) : x((x % mod + mod) % mod) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint a) {
if ((x += a.x) >= mod)
x -= mod;
return *this;
}
mint &operator-=(const mint a) {
if ((x += mod - a.x) >= mod)
x -= mod;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const { return mint(*this) += a; }
mint operator-(const mint a) const { return mint(*this) -= a; }
mint operator*(const mint a) const { return mint(*this) *= a; }
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(mod - 2); }
mint &operator/=(const mint a) { return *this *= a.inv(); }
mint operator/(const mint a) const { return mint(*this) /= a; }
explicit operator int() const { return x; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
struct combination { // comb(a,b)でよぶaCb
vector<mint> fact, ifact;
combination(ll n) : fact(n + 1), ifact(n + 1) {
assert(n < mod);
fact[0] = 1;
for (ll i = 1; i <= n; ++i)
fact[i] = fact[i - 1] * i;
ifact[n] = fact[n].inv();
for (ll i = n; i >= 1; --i)
ifact[i - 1] = ifact[i] * i;
}
mint operator()(ll n, ll k) {
if (k < 0 || k > n)
return 0;
return fact[n] * ifact[k] * ifact[n - k];
}
} comb(1000005); // comb貯め
mint f(ll n, ll k) {
if (n < 0)
return 0;
// nPk = nCk * k!
mint res = comb(n, k);
res *= comb.fact[k];
return res;
}
struct SegmentTree {
private:
int n;
vector<int> node;
public:
SegmentTree(vector<int> v) { // SegmentTree seg(vector<int>(N,INF))で呼び出し
int sz = v.size();
n = 1;
while (n < sz)
n *= 2;
node.resize(2 * n - 1, INF);
for (int i = 0; i < sz; i++)
node[i + n - 1] = v[i];
for (int i = n - 2; i >= 0; i--)
node[i] = min(node[2 * i + 1], node[2 * i + 2]);
}
void update(int x, int val) {
x += (n - 1);
node[x] = val;
while (x > 0) {
x = (x - 1) / 2;
node[x] = min(node[2 * x + 1], node[2 * x + 2]);
}
}
int getmin(int a, int b, int k = 0, int l = 0, int r = -1) {
if (r < 0)
r = n;
if (r <= a || b <= l)
return INF;
if (a <= l && r <= b)
return node[k];
int vl = getmin(a, b, 2 * k + 1, l, (l + r) / 2);
int vr = getmin(a, b, 2 * k + 2, (l + r) / 2, r);
return min(vl, vr);
}
};
// 1-indexedなので注意。
struct BIT {
private:
vector<int> bit;
int N;
public:
BIT(int size) {
N = size;
bit.resize(N + 1);
}
// 一点更新です
void add(int a, int w) { // a番目にwを加算
for (int x = a; x <= N; x += x & -x)
bit[x] += w;
}
// 1~a(以下)までの和を求める。
int sum(int a) {
int ret = 0;
for (int x = a; x > 0; x -= x & -x)
ret += bit[x];
return ret;
}
};
/****Union-Ford-Tree***/
int par[int(0x7ffffff)]; // Parent
int Rank[int(0x7ffffff)]; // Deep_of_the_Tree
// int a[100] = { 4,2,3,1,5 }, m[100] ={3,2,2};
// int n = 0;
// const ll mod = 1000000007;
/*
//n要素で初期化
void init(int n) {
for (int i = 0; i < n; i++) {
par[i] = i;
Rank[i] = 0;
}
}
//木の根探し
int find(int x) {
if (par[x] == x) {
return x;
}
else {
return par[x] = find(par[x]);
}
}
//xとyの属する集合を併合
void unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y)return;
if (Rank[x] < Rank[y]) {
par[x] = y;
}
else {
par[y] = x;
if (Rank[x] == Rank[y])Rank[x]++;
}
}
bool same(int x, int y) {
return find(x) == find(y);
}*/
// queue古い順,stack新しい順
/************************************************************************************/
int N, M;
int X[100005];
int32_t main() {
cin >> N >> M;
rep(i, M) cin >> X[i];
sort(X, X + M);
vector<int> L;
rep(i, M - 1) { L.push_back(X[i + 1] - X[i]); }
sort(L.rbegin(), L.rend());
int res = 0;
rep(i, min(N - 1, int(L.size()))) { res += L[i]; }
cout << X[M - 1] - X[0] - res << endl;
} | replace | 336 | 337 | 336 | 337 | -11 | |
p03137 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
if (M == 1) {
cout << 1 << endl;
return 0;
}
vector<int> X(M);
for (int i = 0; i < M; i++) {
cin >> X[i];
}
sort(X.begin(), X.end());
vector<int> sub;
for (int i = 1; i < X.size(); i++) {
sub.push_back(abs(X[i] - X[i - 1]));
// cout << abs(X[i] - X[i - 1]) << endl;
}
sort(sub.begin(), sub.end());
cout << accumulate(sub.begin(), sub.end() - (N - 1), 0LL);
return 0;
} | #include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
if (M <= N) {
cout << 0 << endl;
return 0;
}
vector<int> X(M);
for (int i = 0; i < M; i++) {
cin >> X[i];
}
sort(X.begin(), X.end());
vector<int> sub;
for (int i = 1; i < X.size(); i++) {
sub.push_back(abs(X[i] - X[i - 1]));
// cout << abs(X[i] - X[i - 1]) << endl;
}
sort(sub.begin(), sub.end());
cout << accumulate(sub.begin(), sub.end() - (N - 1), 0LL);
return 0;
} | replace | 9 | 11 | 9 | 11 | 0 | |
p03137 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, j, n) for (int i = (int)(j); i < (int)(n); i++)
#define REP(i, j, n) for (int i = (int)(j); i <= (int)(n); i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(), (a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int, int>
#define priq priority_queue<int>
signed main() {
int N, M;
cin >> N >> M;
if (N >= M)
cout << 0 << endl;
else {
vi A(M);
rep(i, 0, M) cin >> A[i];
sort(ALL(A));
vector<pii> B(M - 1);
rep(i, 0, M - 1) B[i] = make_pair(A[i + 1] - A[i], i);
sort(ALL(B));
vi C(N - 1);
rep(i, 0, N - 1) C[i] = B[M - 2 - i].second;
sort(ALL(C));
int ans = A[C[0]] - A[0];
rep(i, 1, N - 1) ans += A[C[i]] - A[C[i - 1] + 1];
ans += A[M - 1] - A[C[N - 2] + 1];
cout << ans << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, j, n) for (int i = (int)(j); i < (int)(n); i++)
#define REP(i, j, n) for (int i = (int)(j); i <= (int)(n); i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(), (a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int, int>
#define priq priority_queue<int>
signed main() {
int N, M;
cin >> N >> M;
if (N >= M)
cout << 0 << endl;
else {
vi A(M);
rep(i, 0, M) cin >> A[i];
sort(ALL(A));
if (N == 1)
cout << A[M - 1] - A[0] << endl;
else {
vector<pii> B(M - 1);
rep(i, 0, M - 1) B[i] = make_pair(A[i + 1] - A[i], i);
sort(ALL(B));
vi C(N - 1);
rep(i, 0, N - 1) C[i] = B[M - 2 - i].second;
sort(ALL(C));
int ans = A[C[0]] - A[0];
rep(i, 1, N - 1) ans += A[C[i]] - A[C[i - 1] + 1];
ans += A[M - 1] - A[C[N - 2] + 1];
cout << ans << endl;
}
}
} | replace | 20 | 30 | 20 | 34 | 0 | |
p03137 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
vector<long long> X(M);
for (int i = 0; i < M; ++i)
cin >> X[i];
sort(X.begin(), X.end());
vector<long long> diffs;
for (int i = 1; i < X.size(); ++i)
diffs.push_back(X[i] - X[i - 1]); // push_back=新たな要素を末尾に追加
sort(diffs.begin(), diffs.end(), greater<long long>()); // 大きい順にソート
long long res = X.back() - X[0]; // 座標の最大-最小
for (int i = 0; i < N - 1; ++i)
res -= diffs[i];
cout << res << endl;
}
| #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
vector<long long> X(M);
for (int i = 0; i < M; ++i)
cin >> X[i];
sort(X.begin(), X.end());
vector<long long> diffs;
for (int i = 1; i < X.size(); ++i)
diffs.push_back(X[i] - X[i - 1]); // push_back=新たな要素を末尾に追加
sort(diffs.begin(), diffs.end(), greater<long long>()); // 大きい順にソート
long long res = X.back() - X[0]; // 座標の最大-最小
for (int i = 0; i < min((int)diffs.size(),
N - 1) /*∵同じ座標に複数のコマを置いてもいい*/;
++i)
res -= diffs[i];
cout << res << endl;
}
| replace | 19 | 20 | 19 | 22 | 0 | |
p03137 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define mod ((ull)1e9 + 7)
#define MAX ((ull)1e9)
int main() {
int n, m;
cin >> n >> m;
ll x[m], d[m - 1];
for (int i = 0; i < m; i++) {
cin >> x[i];
}
if (m == 1) {
cout << 0 << endl;
return 0;
}
sort(x, x + m);
for (int i = 0; i < m - 1; i++) {
d[i] = x[i + 1] - x[i];
}
sort(d, d + m - 1, greater<int>());
ll ans = x[m - 1] - x[0];
for (int i = 0; i < n - 1; i++) {
ans -= d[i];
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define mod ((ull)1e9 + 7)
#define MAX ((ull)1e9)
int main() {
int n, m;
cin >> n >> m;
ll x[m], d[m - 1];
for (int i = 0; i < m; i++) {
cin >> x[i];
}
if (m == 1 || n >= m) {
cout << 0 << endl;
return 0;
}
sort(x, x + m);
for (int i = 0; i < m - 1; i++) {
d[i] = x[i + 1] - x[i];
}
sort(d, d + m - 1, greater<int>());
ll ans = x[m - 1] - x[0];
for (int i = 0; i < n - 1; i++) {
ans -= d[i];
}
cout << ans << endl;
return 0;
} | replace | 27 | 28 | 27 | 28 | 0 | |
p03137 | C++ | Runtime Error | #define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
const int INF = 1 << 30;
const uint64_t MOD = 1000000000 + 7;
int main() {
int n, m;
cin >> n >> m;
vector<int> a(m);
for (int i = 0; i < m; i++) {
cin >> a.at(i);
}
sort(a.begin(), a.end());
vector<int> b(m);
for (int i = 0; i < m - 1; i++) {
b.at(i) = a.at(i + 1) - a.at(i);
b.at(i) *= (b.at(i) < 0) ? -1 : 1;
}
sort(b.begin(), b.end());
cout << accumulate(b.begin(), b.end() - (n - 1), 0) << endl;
} | #define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
const int INF = 1 << 30;
const uint64_t MOD = 1000000000 + 7;
int main() {
int n, m;
cin >> n >> m;
vector<int> a(m);
for (int i = 0; i < m; i++) {
cin >> a.at(i);
}
if (n >= m) {
cout << 0 << endl;
return 0;
}
sort(a.begin(), a.end());
vector<int> b(m);
for (int i = 0; i < m - 1; i++) {
b.at(i) = a.at(i + 1) - a.at(i);
b.at(i) *= (b.at(i) < 0) ? -1 : 1;
}
sort(b.begin(), b.end());
cout << accumulate(b.begin(), b.end() - (n - 1), 0) << endl;
} | insert | 34 | 34 | 34 | 39 | 0 | |
p03137 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m;
cin >> n >> m;
if (m == 1) {
cout << "0";
return 0;
}
vector<long long> x(m), a(m - 1);
for (long long i = 0; i < m; i++) {
cin >> x[i];
}
sort(x.begin(), x.end());
for (long long i = m - 2; i >= 0; i--) {
a[i] = x[i + 1] - x[i];
}
sort(a.begin(), a.end());
int64_t ans = x[m - 1] - x[0];
for (long long i = 0; i < n - 1; i++) {
ans -= a[m - 2 - i];
}
cout << ans;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m;
cin >> n >> m;
if (n >= m) {
cout << "0";
return 0;
}
vector<long long> x(m), a(m - 1);
for (long long i = 0; i < m; i++) {
cin >> x[i];
}
sort(x.begin(), x.end());
for (long long i = m - 2; i >= 0; i--) {
a[i] = x[i + 1] - x[i];
}
sort(a.begin(), a.end());
int64_t ans = x[m - 1] - x[0];
for (long long i = 0; i < n - 1; i++) {
ans -= a[m - 2 - i];
}
cout << ans;
} | replace | 6 | 7 | 6 | 7 | 0 | |
p03137 | C++ | Runtime Error | /*Code by : Harry_Singh*/
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define io ios_base::sync_with_stdio(false), cin.tie(nullptr);
#define ipair pair<int, int>
#define pb push_back
#define f(i, n) for (int i = 0; i < n; i++)
#define F(i, n) for (int i = 1; i <= n; i++)
#define FF(a, b) for (int i = a; i <= b; i++)
#define lc(i) (i - '0' - 49)
#define uc(i) (i - '0' - 17)
#define char_to_number_int(i) (i - 48)
// const long INF=100000000000000005;
#define c_b(i) __builtin_popcount(i)
#define MAXX 100005
#define mod 1000000007
#define sz(g) g.size()
using namespace std;
#define tr cout << "\n"
//****************************************INITILIZE
//GRAPHS***************************/
// vector<int> graph[MAXX];
// vector<ipair> graph_p[MAXX];
// // vector<ipair> op;
// vector<int> vis(MAXX, 0);
/************************************************ pow(2,n)%mod
* *******************************/
int power(int x, int y) {
int res = 1; // Initialize result
x = x % mod; // Update x if it is more than or
if (x == 0)
return 0; // In case x is divisible by p;
while (y > 0) {
if (y & 1)
res = ((res % mod) * (x % mod)) % mod;
// y must be even now
y = y >> 1; // y = y/2
x = ((x % mod) * (x % mod)) % mod;
}
return res;
}
/************************************************ INIT GRAPH
* *******************************/
/************************************************ INIT SEIVE
* *******************************/
vector<int> pr;
void sieve(int n) {
bool prime[n + 1];
memset(prime, true, sizeof(prime));
for (int p = 2; p * p <= n; p++) {
if (prime[p] == true) {
for (int i = p * p; i <= n; i += p)
prime[i] = false;
}
}
// just add the primes in some vector
for (int i = 2; i <= n; i++)
if (prime[i])
pr.pb(i);
}
////////////////////////////****GCD////////////////////////
int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
// int mx(int a,int b){if(a<=b)return b;else return a;}
// this is the DFS which'll visit all the connectd components in a matrix baby.
// int dx[4]={-1,0,1,0};
// int dy[4]={0,1,0,-1};
/********************************* IN SOME Problem think about the top down
* apraoch every recursion step just save the previous step';*/
// int dfs(int x,int y)
// {
// if(dp[x][y])return dp[x][y];
// // vsiited true
// // visit all four directions
// for(int i=0;i<4;i++){
// int tx=x+dx[i];
// int ty=y+dy[i];
// // now visit the dfs call the dfs
// // some operatoins on the dp[x][y]
// }
// // we are here after when we can't able to make any move,, we can do
// anytiung here we can return dp here
// return dp[x][y];
// }
// void reduce_to_zero()
// {
// int range=100,add=0;
// int x=1;// x can be increasing by some vaalue
// while(range)
// {
// add+=min(range,x);
// x;// apply condiiton
// range-=min(x,range);// it will make to zero
// }
// }
//****************IDEAS******************
/*
some of first n even numbers is n*n+1;
some of first n odd numbers is n*n;
*/
/* Some HINTS*/ /* SOME VALUABLE **HINTS**
1. We can use the binary_search in which by fixiing some n we can find the
optimal solutions... specialluy for the div2 c and d problems binary serach
works well
2. We can use the DFS or BFS for the problems specially for the matrixes or for
char matrix where we have to visitd all and find answer then
3. Finding some elements in which we have to do searchng in each or one
diretions or some talk about connecrted components DFS is used. 4.XOR-> If the
bits are same. then if i xor the first or second bit with 0 then the answer
will be the same bit 0 1 = 0^1=1 but if bits are different i xor the first or
second bit with 1 anwer will be same as second or first, if with zero, answer
will be different.
5. just suppose n is a sum of k mumbers ->
5=2+3 make 5*5 ways to make
// cut 1-> 5*5=2*5+3*5
// cut 2-> 2*5-> 2*2+2*3
// 3*5= 3*3+3*2 now add -> 5*5= 2*2+3*3+2*3+3*3
done. just cutting we are.
6. If (1,6,8,9) number is divisible by n, take n =7, then we can make its
permutation so that we can get the mod divide by 7 is 0,1,2,3,4,5,6
****************************BINARY SEARCH**********************
7. Binary search on all evens or odds->
evens-> if(can(mid*2))nas=mid*2,l=mid+1;else r=mid-1;
Binary search on all odds
odds-> if(can(mid*2-1))nas=mid*2-1,l=mid+1;else r=mid-1;
8. directed acyclic graphs means,, someway talking about topological sorting
baby
*/
/*******************************N CHOOSE K ***************************/
// const int N = 1e6 + 100;
// int fact[N], modulo = INF + 7;
// long long binpow(long long val, long long deg, long long modi) {
// if (!deg) return 1 % modi;
// if (deg & 1) return binpow(val, deg - 1, mod) * val % modi;
// long long res = binpow(val ,deg >> 1, modi);
// return (res*res) % modi;
// }
// void initfact() {
// fact[0] = 1;
// for(int i = 1; i < N; i++) {
// fact[i] = (fact[i-1] * i);
// fact[i] %= modulo;
// }
// }
// int getC(int n, int i) {
// int res = fact[n];
// int div = fact[n-i] * fact[i];
// div %= modulo; div = binpow(div, modulo - 2, modulo);
// return (res * div) % modulo;
// }
// bool cmp(int first, inNt second){
// if (a[first] == a[second])return first < second;// smae then inex wise
// baby return a[first] < a[second];
// }
//**********************Things we have to practise list is going on DP
//topic.*****************
// Classic 2d DP
// Dp with probability
// Dp with prefix_sums
// Dp with Bitmasks
// Dp with trees,graphs,segment_trees or any data structrue
// .. list is going on
// bool compare(const pair<int,int> &a, const pair<int,int> &b) {
// return (a.first>b.first);
// }
bool isPrime(int n) {
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
void we_have_choices() {
int n, m;
cin >> n >> m;
int a[n + 1];
F(i, m) cin >> a[i];
int sum = 0;
sort(a + 1, a + 1 + m);
priority_queue<int> p; // always descending order
F(i, m) {
if (i >= 2)
p.push(a[i] - a[i - 1]), sum += a[i] - a[i - 1];
}
for (int i = 0; i < n - 1 and !p.empty(); i++)
sum -= p.top(), p.pop();
cout << sum;
tr;
}
int32_t main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("op.txt", "w", stdout);
#endif
io;
int t = 1; // cin>>t;
while (t--)
we_have_choices();
return 0;
} | /*Code by : Harry_Singh*/
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define io ios_base::sync_with_stdio(false), cin.tie(nullptr);
#define ipair pair<int, int>
#define pb push_back
#define f(i, n) for (int i = 0; i < n; i++)
#define F(i, n) for (int i = 1; i <= n; i++)
#define FF(a, b) for (int i = a; i <= b; i++)
#define lc(i) (i - '0' - 49)
#define uc(i) (i - '0' - 17)
#define char_to_number_int(i) (i - 48)
// const long INF=100000000000000005;
#define c_b(i) __builtin_popcount(i)
#define MAXX 100005
#define mod 1000000007
#define sz(g) g.size()
using namespace std;
#define tr cout << "\n"
//****************************************INITILIZE
//GRAPHS***************************/
// vector<int> graph[MAXX];
// vector<ipair> graph_p[MAXX];
// // vector<ipair> op;
// vector<int> vis(MAXX, 0);
/************************************************ pow(2,n)%mod
* *******************************/
int power(int x, int y) {
int res = 1; // Initialize result
x = x % mod; // Update x if it is more than or
if (x == 0)
return 0; // In case x is divisible by p;
while (y > 0) {
if (y & 1)
res = ((res % mod) * (x % mod)) % mod;
// y must be even now
y = y >> 1; // y = y/2
x = ((x % mod) * (x % mod)) % mod;
}
return res;
}
/************************************************ INIT GRAPH
* *******************************/
/************************************************ INIT SEIVE
* *******************************/
vector<int> pr;
void sieve(int n) {
bool prime[n + 1];
memset(prime, true, sizeof(prime));
for (int p = 2; p * p <= n; p++) {
if (prime[p] == true) {
for (int i = p * p; i <= n; i += p)
prime[i] = false;
}
}
// just add the primes in some vector
for (int i = 2; i <= n; i++)
if (prime[i])
pr.pb(i);
}
////////////////////////////****GCD////////////////////////
int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
// int mx(int a,int b){if(a<=b)return b;else return a;}
// this is the DFS which'll visit all the connectd components in a matrix baby.
// int dx[4]={-1,0,1,0};
// int dy[4]={0,1,0,-1};
/********************************* IN SOME Problem think about the top down
* apraoch every recursion step just save the previous step';*/
// int dfs(int x,int y)
// {
// if(dp[x][y])return dp[x][y];
// // vsiited true
// // visit all four directions
// for(int i=0;i<4;i++){
// int tx=x+dx[i];
// int ty=y+dy[i];
// // now visit the dfs call the dfs
// // some operatoins on the dp[x][y]
// }
// // we are here after when we can't able to make any move,, we can do
// anytiung here we can return dp here
// return dp[x][y];
// }
// void reduce_to_zero()
// {
// int range=100,add=0;
// int x=1;// x can be increasing by some vaalue
// while(range)
// {
// add+=min(range,x);
// x;// apply condiiton
// range-=min(x,range);// it will make to zero
// }
// }
//****************IDEAS******************
/*
some of first n even numbers is n*n+1;
some of first n odd numbers is n*n;
*/
/* Some HINTS*/ /* SOME VALUABLE **HINTS**
1. We can use the binary_search in which by fixiing some n we can find the
optimal solutions... specialluy for the div2 c and d problems binary serach
works well
2. We can use the DFS or BFS for the problems specially for the matrixes or for
char matrix where we have to visitd all and find answer then
3. Finding some elements in which we have to do searchng in each or one
diretions or some talk about connecrted components DFS is used. 4.XOR-> If the
bits are same. then if i xor the first or second bit with 0 then the answer
will be the same bit 0 1 = 0^1=1 but if bits are different i xor the first or
second bit with 1 anwer will be same as second or first, if with zero, answer
will be different.
5. just suppose n is a sum of k mumbers ->
5=2+3 make 5*5 ways to make
// cut 1-> 5*5=2*5+3*5
// cut 2-> 2*5-> 2*2+2*3
// 3*5= 3*3+3*2 now add -> 5*5= 2*2+3*3+2*3+3*3
done. just cutting we are.
6. If (1,6,8,9) number is divisible by n, take n =7, then we can make its
permutation so that we can get the mod divide by 7 is 0,1,2,3,4,5,6
****************************BINARY SEARCH**********************
7. Binary search on all evens or odds->
evens-> if(can(mid*2))nas=mid*2,l=mid+1;else r=mid-1;
Binary search on all odds
odds-> if(can(mid*2-1))nas=mid*2-1,l=mid+1;else r=mid-1;
8. directed acyclic graphs means,, someway talking about topological sorting
baby
*/
/*******************************N CHOOSE K ***************************/
// const int N = 1e6 + 100;
// int fact[N], modulo = INF + 7;
// long long binpow(long long val, long long deg, long long modi) {
// if (!deg) return 1 % modi;
// if (deg & 1) return binpow(val, deg - 1, mod) * val % modi;
// long long res = binpow(val ,deg >> 1, modi);
// return (res*res) % modi;
// }
// void initfact() {
// fact[0] = 1;
// for(int i = 1; i < N; i++) {
// fact[i] = (fact[i-1] * i);
// fact[i] %= modulo;
// }
// }
// int getC(int n, int i) {
// int res = fact[n];
// int div = fact[n-i] * fact[i];
// div %= modulo; div = binpow(div, modulo - 2, modulo);
// return (res * div) % modulo;
// }
// bool cmp(int first, inNt second){
// if (a[first] == a[second])return first < second;// smae then inex wise
// baby return a[first] < a[second];
// }
//**********************Things we have to practise list is going on DP
//topic.*****************
// Classic 2d DP
// Dp with probability
// Dp with prefix_sums
// Dp with Bitmasks
// Dp with trees,graphs,segment_trees or any data structrue
// .. list is going on
// bool compare(const pair<int,int> &a, const pair<int,int> &b) {
// return (a.first>b.first);
// }
bool isPrime(int n) {
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
void we_have_choices() {
int n, m;
cin >> n >> m;
int a[m + 1];
F(i, m) cin >> a[i];
int sum = 0;
sort(a + 1, a + 1 + m);
priority_queue<int> p; // always descending order
F(i, m) {
if (i >= 2)
p.push(a[i] - a[i - 1]), sum += a[i] - a[i - 1];
}
for (int i = 0; i < n - 1 and !p.empty(); i++)
sum -= p.top(), p.pop();
cout << sum;
tr;
}
int32_t main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("op.txt", "w", stdout);
#endif
io;
int t = 1; // cin>>t;
while (t--)
we_have_choices();
return 0;
} | replace | 212 | 213 | 212 | 213 | TLE | |
p03137 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
using namespace std;
typedef long long ll;
int main() {
ll N, M;
cin >> N >> M;
vector<ll> x(M);
vector<ll> l(M - 1);
for (ll i = 0; i < M; i++) {
cin >> x[i];
}
sort(x.begin(), x.end());
for (ll i = 0; i < M - 1; i++) {
l[i] = x[i + 1] - x[i];
}
sort(l.begin(), l.end());
reverse(l.begin(), l.end());
ll ans = 0;
for (ll i = 0; i < N - 1; i++) {
ans += l[i];
}
cout << x[M - 1] - x[0] - ans << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
using namespace std;
typedef long long ll;
int main() {
ll N, M;
cin >> N >> M;
if (N >= M) {
cout << 0 << endl;
return 0;
}
vector<ll> x(M);
vector<ll> l(M - 1);
for (ll i = 0; i < M; i++) {
cin >> x[i];
}
sort(x.begin(), x.end());
for (ll i = 0; i < M - 1; i++) {
l[i] = x[i + 1] - x[i];
}
sort(l.begin(), l.end());
reverse(l.begin(), l.end());
ll ans = 0;
for (ll i = 0; i < N - 1; i++) {
ans += l[i];
}
cout << x[M - 1] - x[0] - ans << endl;
return 0;
} | insert | 14 | 14 | 14 | 18 | 0 | |
p03137 | C++ | Runtime Error | /* Accepted. */
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
#define MAXN 100006
int n, m;
int X[MAXN], d[MAXN], S;
int main() {
// freopen( "input","r",stdin );
cin >> m >> n;
if (m <= n)
return puts("0"), 0;
for (int i = 1; i <= n; ++i)
scanf("%d", &X[i]);
sort(X + 1, X + 1 + n);
for (int i = 1; i <= n; ++i)
d[i] = i != 1 ? X[i] - X[i - 1] : -0x3f3f3f3f;
S = X[n] - X[1];
sort(d + 1, d + 1 + n);
for (int i = 0; i < m - 1; ++i)
S -= d[n - i];
cout << S;
} // qwq
| /* Accepted. */
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
#define MAXN 100006
int n, m;
int X[MAXN], d[MAXN], S;
int main() {
// freopen( "input","r",stdin );
cin >> m >> n;
if (n <= m)
return puts("0"), 0;
for (int i = 1; i <= n; ++i)
scanf("%d", &X[i]);
sort(X + 1, X + 1 + n);
for (int i = 1; i <= n; ++i)
d[i] = i != 1 ? X[i] - X[i - 1] : -0x3f3f3f3f;
S = X[n] - X[1];
sort(d + 1, d + 1 + n);
for (int i = 0; i < m - 1; ++i)
S -= d[n - i];
cout << S;
} // qwq
| replace | 14 | 15 | 14 | 15 | 0 | |
p03137 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
using namespace std;
long long X[10010];
long long subX[10010];
int main(void) {
long long N, M;
cin >> N >> M;
for (long long i = 0; i < M; i++) {
cin >> X[i];
}
sort(X, X + M);
for (long long i = 0; i < M - 1; i++) {
subX[i] = X[i + 1] - X[i];
}
sort(subX, subX + M - 1);
long long cost = 0;
for (long long i = 0; i < M - 1 - (N - 1); i++) {
cost += subX[i];
}
cout << cost << endl;
return 0;
}
| #include <algorithm>
#include <iostream>
using namespace std;
long long X[100100];
long long subX[100100];
int main(void) {
long long N, M;
cin >> N >> M;
for (long long i = 0; i < M; i++) {
cin >> X[i];
}
sort(X, X + M);
for (long long i = 0; i < M - 1; i++) {
subX[i] = X[i + 1] - X[i];
}
sort(subX, subX + M - 1);
long long cost = 0;
for (long long i = 0; i < M - 1 - (N - 1); i++) {
cost += subX[i];
}
cout << cost << endl;
return 0;
}
| replace | 5 | 7 | 5 | 7 | 0 | |
p03137 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <queue>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
int ans = 0;
vector<int> X(M);
for (int i = 0; i < M; i++) {
cin >> X[i];
}
if (N >= M) {
cout << 0 << endl;
return 0;
}
sort(X.begin(), X.end());
int length = X[M - 1] - X[0];
vector<int> dif(M - 1);
for (int i = 0; i < M; i++) {
dif[i] = X[i + 1] - X[i];
}
sort(dif.begin(), dif.end());
reverse(dif.begin(), dif.end());
for (int i = 0; i < N - 1; i++) {
length = length - dif[i];
}
cout << length << endl;
} | #include <bits/stdc++.h>
#include <queue>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
int ans = 0;
vector<int> X(M);
for (int i = 0; i < M; i++) {
cin >> X[i];
}
if (N >= M) {
cout << 0 << endl;
return 0;
}
sort(X.begin(), X.end());
int length = X[M - 1] - X[0];
vector<int> dif(M - 1);
for (int i = 0; i < M - 1; i++) {
dif[i] = X[i + 1] - X[i];
}
sort(dif.begin(), dif.end());
reverse(dif.begin(), dif.end());
for (int i = 0; i < N - 1; i++) {
length = length - dif[i];
}
cout << length << endl;
} | replace | 19 | 20 | 19 | 20 | 0 | |
p03137 | C++ | Runtime Error | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)
using namespace std;
using ll = long long;
int main() {
ll N, M, ans;
cin >> N >> M;
vector<ll> A(M);
vector<ll> gap(M - 1);
rep(i, M) { cin >> A[i]; }
sort(A.begin(), A.end());
ans = A[M - 1] - A[0];
rep(i, M - 1) { gap[i] = A[i + 1] - A[i]; }
sort(gap.begin(), gap.end(), greater<>());
rep(i, N - 1) { ans -= gap[i]; }
if (M == 1) {
ans = 0;
}
cout << ans;
return 0;
}
| #include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)
using namespace std;
using ll = long long;
int main() {
ll N, M, ans;
cin >> N >> M;
vector<ll> A(M);
vector<ll> gap(M - 1);
rep(i, M) { cin >> A[i]; }
sort(A.begin(), A.end());
ans = A[M - 1] - A[0];
rep(i, M - 1) { gap[i] = A[i + 1] - A[i]; }
sort(gap.begin(), gap.end(), greater<>());
rep(i, min(N - 1, M - 1)) { ans -= gap[i]; }
cout << ans;
return 0;
}
| replace | 32 | 37 | 32 | 33 | 0 | |
p03137 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long
#define fort(i, n) for (int i = 1; i <= n; ++i)
#define pi pair<int, int>
#define pl pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define sz size()
#define er erase
#define fr first
#define sc second
#define rc(x) return cout << x, 0
using namespace std;
ll n, m, x[100005], a[100005], s;
int32_t main() {
ios_base ::sync_with_stdio(0);
cin.tie();
cout.tie();
cin >> n >> m;
fort(i, m) cin >> x[i];
sort(x + 1, x + m + 1);
fort(i, m - 1) a[i] = x[i + 1] - x[i], s += a[i];
sort(a + 1, a + m);
fort(i, n - 1) s -= a[m - i];
cout << max(s, 0ll);
}
| #include <bits/stdc++.h>
#define ll long long
#define fort(i, n) for (int i = 1; i <= n; ++i)
#define pi pair<int, int>
#define pl pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define sz size()
#define er erase
#define fr first
#define sc second
#define rc(x) return cout << x, 0
using namespace std;
ll n, m, x[100005], a[100005], s;
int32_t main() {
ios_base ::sync_with_stdio(0);
cin.tie();
cout.tie();
cin >> n >> m;
if (n >= m)
rc(0);
fort(i, m) cin >> x[i];
sort(x + 1, x + m + 1);
fort(i, m - 1) a[i] = x[i + 1] - x[i], s += a[i];
sort(a + 1, a + m);
fort(i, n - 1) s -= a[m - i];
cout << max(s, 0ll);
}
| insert | 22 | 22 | 22 | 24 | 0 | |
p03137 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
long long int n, m;
vector<long long int> m_v;
cin >> n >> m;
for (int i = 0; i < m; i++) {
long long int mi;
cin >> mi;
m_v.push_back(mi);
}
sort(m_v.begin(), m_v.end());
vector<long long int> diffs;
for (int i = 0; i < m - 1; i++) {
diffs.push_back(abs(m_v[i] - m_v[i + 1]));
}
sort(diffs.begin(), diffs.end());
int ans = 0;
for (int i = 0; i < diffs.size() - n + 1; i++) {
ans += diffs[i];
}
cout << ans << endl;
} | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
long long int n, m;
vector<long long int> m_v;
cin >> n >> m;
if (m <= n) {
cout << 0 << endl;
return 0;
}
for (int i = 0; i < m; i++) {
long long int mi;
cin >> mi;
m_v.push_back(mi);
}
sort(m_v.begin(), m_v.end());
vector<long long int> diffs;
for (int i = 0; i < m - 1; i++) {
diffs.push_back(abs(m_v[i] - m_v[i + 1]));
}
sort(diffs.begin(), diffs.end());
int ans = 0;
for (int i = 0; i < diffs.size() - n + 1; i++) {
ans += diffs[i];
}
cout << ans << endl;
} | insert | 10 | 10 | 10 | 15 | 0 | |
p03137 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <vector>
using namespace std;
int main(int argc, char const *argv[]) {
int n, m;
cin >> n >> m;
vector<int> x(m);
for (int i = 0; i < m; i++)
cin >> x[i];
sort(x.begin(), x.end());
vector<int> defs(m - 1);
for (int i = 0; i < m - 1; i++)
defs[i] = x[i + 1] - x[i];
int res = x[m - 1] - x[0];
sort(defs.begin(), defs.end(), greater<>());
for (int i = 0; i < n - 1; i++)
res -= defs[i];
cout << res << endl;
return 0;
}
| #include <algorithm>
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <vector>
using namespace std;
int main(int argc, char const *argv[]) {
int n, m;
cin >> n >> m;
vector<int> x(m);
for (int i = 0; i < m; i++)
cin >> x[i];
if (n >= m) {
cout << 0 << endl;
return 0;
}
sort(x.begin(), x.end());
vector<int> defs(m - 1);
for (int i = 0; i < m - 1; i++)
defs[i] = x[i + 1] - x[i];
int res = x[m - 1] - x[0];
sort(defs.begin(), defs.end(), greater<>());
for (int i = 0; i < n - 1; i++)
res -= defs[i];
cout << res << endl;
return 0;
}
| insert | 16 | 16 | 16 | 20 | 0 | |
p03137 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
int N, M;
int d[10000];
int dis[10000];
int counter = 0;
cin >> N >> M;
for (int i = 0; i < M; i++) {
cin >> d[i];
}
sort(d, d + M);
for (int i = 0; i < M - 1; i++) {
dis[i] = d[i + 1] - d[i];
}
sort(dis, dis + M - 1, greater<int>());
for (int i = N - 1; i < M - 1; i++) {
counter += dis[i];
}
cout << counter << endl;
} | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
int N, M;
int d[110000];
int dis[110000];
int counter = 0;
cin >> N >> M;
for (int i = 0; i < M; i++) {
cin >> d[i];
}
sort(d, d + M);
for (int i = 0; i < M - 1; i++) {
dis[i] = d[i + 1] - d[i];
}
sort(dis, dis + M - 1, greater<int>());
for (int i = N - 1; i < M - 1; i++) {
counter += dis[i];
}
cout << counter << endl;
} | replace | 6 | 8 | 6 | 8 | 0 | |
p03137 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(), (a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int, int> P;
typedef long long ll;
int main() {
int n, m;
cin >> n >> m;
vector<int> x(m);
vector<int> xbet(m - 1);
rep(i, m) cin >> x[i];
sort(all(x));
rep(i, m - 1) xbet[i] = x[i + 1] - x[i];
sort(all(xbet));
reverse(all(xbet));
rep(i, n - 1) xbet[i] = 0;
ll ans = 0;
rep(i, m - 1) ans += xbet[i];
dunk(ans);
}
| #include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(), (a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int, int> P;
typedef long long ll;
int main() {
int n, m;
cin >> n >> m;
if (n >= m) {
dunk(0);
return 0;
}
vector<int> x(m);
vector<int> xbet(m - 1);
rep(i, m) cin >> x[i];
sort(all(x));
rep(i, m - 1) xbet[i] = x[i + 1] - x[i];
sort(all(xbet));
reverse(all(xbet));
rep(i, n - 1) xbet[i] = 0;
ll ans = 0;
rep(i, m - 1) ans += xbet[i];
dunk(ans);
}
| insert | 14 | 14 | 14 | 20 | 0 | |
p03137 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
if (M == 1) {
cout << "0" << endl;
} else {
vector<int> X(M);
for (int i = 0; i < M; i++) {
cin >> X.at(i);
}
sort(X.begin(), X.end());
int a = X.at(M - 1) - X.at(0);
vector<int> Y(M - 1);
Y.at(0) = 0;
for (int i = 0; i < M - 1; i++) {
Y.at(i) = X.at(i + 1) - X.at(i);
}
sort(Y.begin(), Y.end());
reverse(Y.begin(), Y.end());
int b = 0;
for (int i = 0; i < N - 1; i++) {
b = b + Y.at(i);
}
cout << a - b << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
if (N >= M) {
cout << "0" << endl;
} else {
vector<int> X(M);
for (int i = 0; i < M; i++) {
cin >> X.at(i);
}
sort(X.begin(), X.end());
int a = X.at(M - 1) - X.at(0);
vector<int> Y(M - 1);
Y.at(0) = 0;
for (int i = 0; i < M - 1; i++) {
Y.at(i) = X.at(i + 1) - X.at(i);
}
sort(Y.begin(), Y.end());
reverse(Y.begin(), Y.end());
int b = 0;
for (int i = 0; i < N - 1; i++) {
b = b + Y.at(i);
}
cout << a - b << endl;
}
}
| replace | 6 | 7 | 6 | 7 | 0 | |
p03137 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
vector<int> yop, yoc;
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int x;
cin >> x;
yop.push_back(x);
}
sort(yop.begin(), yop.end());
int ans = yop[m - 1] - yop[0];
for (int i = 0; i < m - 1; i++)
yoc.push_back(yop[i + 1] - yop[i]);
sort(yoc.begin(), yoc.end(), greater<int>());
for (int i = 0; i < n - 1; i++)
ans -= yoc[i];
cout << ans << endl;
}
| #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
vector<int> yop, yoc;
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int x;
cin >> x;
yop.push_back(x);
}
sort(yop.begin(), yop.end());
int ans = yop[m - 1] - yop[0];
for (int i = 0; i < m - 1; i++)
yoc.push_back(yop[i + 1] - yop[i]);
sort(yoc.begin(), yoc.end(), greater<int>());
for (int i = 0; i < n - 1 && i < yoc.size(); i++)
ans -= yoc[i];
cout << ans << endl;
}
| replace | 20 | 21 | 20 | 21 | 0 | |
p03137 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define agewari(a, b) ((ll)a + ((ll)b - 1)) / b
const int MOD = 1000000007;
const long long INF = 1LL << 60;
using Graph = vector<vector<ll>>;
int main() {
ll n, m;
cin >> n >> m;
vector<ll> X(m);
rep(i, m) cin >> X[i];
sort(X.begin(), X.end());
ll moto = X[m - 1] - X[0];
vector<ll> sa(m - 1);
rep(i, m - 1) sa[i] = X[i + 1] - X[i];
ll hiku = 0;
sort(sa.begin(), sa.end(), greater<ll>());
rep(i, n - 1) hiku += sa[i];
cout << moto - hiku << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define agewari(a, b) ((ll)a + ((ll)b - 1)) / b
const int MOD = 1000000007;
const long long INF = 1LL << 60;
using Graph = vector<vector<ll>>;
int main() {
ll n, m;
cin >> n >> m;
vector<ll> X(m);
rep(i, m) cin >> X[i];
if (n >= m) {
cout << 0 << endl;
return 0;
}
sort(X.begin(), X.end());
ll moto = X[m - 1] - X[0];
vector<ll> sa(m - 1);
rep(i, m - 1) sa[i] = X[i + 1] - X[i];
ll hiku = 0;
sort(sa.begin(), sa.end(), greater<ll>());
rep(i, n - 1) hiku += sa[i];
cout << moto - hiku << endl;
} | insert | 15 | 15 | 15 | 20 | 0 | |
p03137 | C++ | Runtime Error | #include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
// typedef pair<int, int> P;
const int INF = 111111111;
const ll LLINF = 1e17 + 1;
const int DX[9] = {0, 0, 1, -1, 1, 1, -1, -1, 0}; // 4;4近傍
const int DY[9] = {1, -1, 0, 0, 1, -1, 1, -1, 0}; // 8:8近傍 9:(0,0)を含む
const int DIV = 1000000007; // 10^9 + 7
const double PI = 3.14159265358979323846264338327950288;
int main() {
//==================================
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(15);
//==================================
int N, M;
cin >> N >> M;
vector<int> X(M);
for (int i = 0; i < M; i++) {
cin >> X[i];
}
sort(X.begin(), X.end());
if (M != 1) {
vector<int> aida(M - 1);
for (int i = 0; i < M - 1; i++) {
aida[i] = X[i + 1] - X[i];
}
sort(aida.begin(), aida.end(), greater<int>());
ll none = 0;
for (int i = 0; i < N - 1; i++) {
none += aida[i];
}
cout << X[M - 1] - X[0] - none;
} else {
cout << 0;
}
}
| #include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
// typedef pair<int, int> P;
const int INF = 111111111;
const ll LLINF = 1e17 + 1;
const int DX[9] = {0, 0, 1, -1, 1, 1, -1, -1, 0}; // 4;4近傍
const int DY[9] = {1, -1, 0, 0, 1, -1, 1, -1, 0}; // 8:8近傍 9:(0,0)を含む
const int DIV = 1000000007; // 10^9 + 7
const double PI = 3.14159265358979323846264338327950288;
int main() {
//==================================
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(15);
//==================================
int N, M;
cin >> N >> M;
vector<int> X(M);
for (int i = 0; i < M; i++) {
cin >> X[i];
}
sort(X.begin(), X.end());
if (M != 1 && N < M) {
vector<int> aida(M - 1);
for (int i = 0; i < M - 1; i++) {
aida[i] = X[i + 1] - X[i];
}
sort(aida.begin(), aida.end(), greater<int>());
ll none = 0;
for (int i = 0; i < N - 1; i++) {
none += aida[i];
}
cout << X[M - 1] - X[0] - none;
} else {
cout << 0;
}
}
| replace | 44 | 45 | 44 | 45 | 0 | |
p03137 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, m, x[N], ans;
priority_queue<int> q;
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; ++i)
scanf("%d", &x[i]);
sort(x + 1, x + m + 1);
ans = x[m] - x[1];
for (int i = 1; i < m; ++i)
q.push(x[i + 1] - x[i]);
for (int i = 1; i <= n - 1; ++i) {
ans -= q.top();
q.pop();
}
printf("%d\n", ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, m, x[N], ans;
priority_queue<int> q;
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; ++i)
scanf("%d", &x[i]);
sort(x + 1, x + m + 1);
ans = x[m] - x[1];
for (int i = 1; i < m; ++i)
q.push(x[i + 1] - x[i]);
for (int i = 1; i <= n - 1; ++i) {
if (q.empty())
break;
ans -= q.top();
q.pop();
}
printf("%d\n", ans);
return 0;
} | insert | 15 | 15 | 15 | 17 | 0 | |
p03137 | C++ | Runtime Error | /*......................*/
#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <functional>
// using namespace __gnu_pbds;
// typedef tree<int, null_type, less<int>,
// rb_tree_tag,tree_order_statistics_node_update> OST; //unique
// elements
#define f(i, j, n) for (int i = j; i <= n; i++)
#define r(i, n, j) for (int i = n; i >= j; i--)
#define mod 1000000007
#define speed ios_base::sync_with_stdio(false);
#define upp cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define T \
int t; \
cin >> t; \
while (t--)
#define ff first
#define ss second
#define all(container) container.begin(), container.end()
#define sz(container) (int)container.size()
#define pii pair<int, int>
#define pll pair<long long int, long long int>
#define ook(x) order_of_key(x)
#define fbo(x) find_by_order(x)
int main() { // constraints , long long
speed upp int n, m, k;
cin >> k >> n;
int arr[n + 5];
vector<int> v;
f(i, 1, n) { cin >> arr[i]; }
sort(arr + 1, arr + n + 1);
multiset<int> ms;
f(i, 2, n) { v.pb(arr[i] - arr[i - 1]); }
ll total = 0;
sort(all(v));
int j = 0;
while (n) {
if (n == k) {
break;
}
n--;
total += (v[j]);
j++;
}
cout << total << '\n';
}
| /*......................*/
#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <functional>
// using namespace __gnu_pbds;
// typedef tree<int, null_type, less<int>,
// rb_tree_tag,tree_order_statistics_node_update> OST; //unique
// elements
#define f(i, j, n) for (int i = j; i <= n; i++)
#define r(i, n, j) for (int i = n; i >= j; i--)
#define mod 1000000007
#define speed ios_base::sync_with_stdio(false);
#define upp cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define T \
int t; \
cin >> t; \
while (t--)
#define ff first
#define ss second
#define all(container) container.begin(), container.end()
#define sz(container) (int)container.size()
#define pii pair<int, int>
#define pll pair<long long int, long long int>
#define ook(x) order_of_key(x)
#define fbo(x) find_by_order(x)
int main() { // constraints , long long
speed upp int n, m, k;
cin >> k >> n;
int arr[n + 5];
vector<int> v;
f(i, 1, n) { cin >> arr[i]; }
sort(arr + 1, arr + n + 1);
multiset<int> ms;
f(i, 2, n) { v.pb(arr[i] - arr[i - 1]); }
ll total = 0;
sort(all(v));
int j = 0;
if (k > n) {
cout << "0\n";
return 0;
}
while (n) {
if (n == k) {
break;
}
n--;
total += (v[j]);
j++;
}
cout << total << '\n';
}
| insert | 49 | 49 | 49 | 53 | 0 | |
p03137 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
int main() {
long long n, m;
cin >> n >> m;
vector<long long> v(m);
for (long long i = 0; i < m; i++) {
cin >> v[i];
}
if (m == 1) {
printf("0\n");
return 0;
}
sort(v.begin(), v.end());
/*for(int i = 0; i < m; i++){
printf("v[i] %d\n", v[i]);
}*/
long long sum = v[m - 1] - v[0];
if (n == 1) {
printf("%lld\n", sum);
return 0;
}
// printf("sum %d\n", sum);
vector<long long> distance(m - 1);
for (long long i = 0; i < m - 1; i++) {
distance[i] = v[i + 1] - v[i];
// printf("distance[i] %d\n", distance[i]);
}
sort(distance.begin(), distance.end());
reverse(distance.begin(), distance.end());
/*for(int i = 0; i < m-1; i++){
//printf("sort distance[i] %d\n", distance[i]);
}*/
long long avoid = 0;
for (long long i = 0; i < n - 1; i++) {
avoid += distance[i];
// printf("avoid %d\n", avoid);
}
printf("%lld\n", sum - avoid);
return 0;
} | #include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
int main() {
long long n, m;
cin >> n >> m;
vector<long long> v(m);
for (long long i = 0; i < m; i++) {
cin >> v[i];
}
if (m == 1) {
printf("0\n");
return 0;
}
sort(v.begin(), v.end());
/*for(int i = 0; i < m; i++){
printf("v[i] %d\n", v[i]);
}*/
long long sum = v[m - 1] - v[0];
if (n >= m) {
printf("0");
return 0;
}
// printf("sum %d\n", sum);
vector<long long> distance(m - 1);
for (long long i = 0; i < m - 1; i++) {
distance[i] = v[i + 1] - v[i];
// printf("distance[i] %d\n", distance[i]);
}
sort(distance.begin(), distance.end());
reverse(distance.begin(), distance.end());
/*for(int i = 0; i < m-1; i++){
//printf("sort distance[i] %d\n", distance[i]);
}*/
long long avoid = 0;
for (long long i = 0; i < n - 1; i++) {
avoid += distance[i];
// printf("avoid %d\n", avoid);
}
printf("%lld\n", sum - avoid);
return 0;
} | replace | 30 | 32 | 30 | 32 | 0 | |
p03137 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> x(m), len(m - 1);
for (int i = 0; i < m; i++) {
cin >> x[i];
}
if (m == 1) {
cout << "0" << endl;
return 0;
}
sort(x.begin(), x.end());
for (int i = 0; i < m - 1; i++) {
len[i] = abs(x[i] - x[i + 1]);
// cout << "len:" << len[i] << endl;
}
sort(len.begin(), len.end());
cout << accumulate(len.begin(), len.end() - (n - 1), 0) << endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> x(m), len(m - 1);
for (int i = 0; i < m; i++) {
cin >> x[i];
}
if (m == 1) {
cout << "0" << endl;
return 0;
}
if (n > m) {
n = m;
}
sort(x.begin(), x.end());
for (int i = 0; i < m - 1; i++) {
len[i] = abs(x[i] - x[i + 1]);
// cout << "len:" << len[i] << endl;
}
sort(len.begin(), len.end());
cout << accumulate(len.begin(), len.end() - (n - 1), 0) << endl;
return 0;
} | insert | 19 | 19 | 19 | 23 | 0 | |
p03137 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
int main(int argc, char const *argv[]) {
int N, M, len = 0;
scanf("%d %d", &N, &M);
int dest[M], space[M - 1];
for (int i = 0; i < M; ++i)
scanf("%d", &(dest[i]));
std::sort(dest, dest + M);
for (int i = 0; i < M - 1; ++i)
space[i] = dest[i + 1] - dest[i];
std::sort(space, space + M - 1);
std::reverse(space, space + M - 1);
for (int i = 0; i < N - 1; ++i)
len += space[i];
printf("%d\n", dest[M - 1] - dest[0] - len);
return 0;
}
| #include <algorithm>
#include <cstdio>
int main(int argc, char const *argv[]) {
int N, M, len = 0;
scanf("%d %d", &N, &M);
if (N > M) {
printf("0\n");
exit(0);
}
int dest[M], space[M - 1];
for (int i = 0; i < M; ++i)
scanf("%d", &(dest[i]));
std::sort(dest, dest + M);
for (int i = 0; i < M - 1; ++i)
space[i] = dest[i + 1] - dest[i];
std::sort(space, space + M - 1);
std::reverse(space, space + M - 1);
for (int i = 0; i < N - 1; ++i)
len += space[i];
printf("%d\n", dest[M - 1] - dest[0] - len);
return 0;
}
| insert | 6 | 6 | 6 | 10 | 0 | |
p03137 | C++ | Runtime Error |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
const ll INF = 1LL << 60;
// n個のコマの担当範囲をどう区切るかの問題に帰着できる
// 範囲を決めることは、その右端から次の担当コマまでの区間をカウントしなくてよくすることと同義
int main() {
int n, m;
cin >> n >> m;
vector<int> x{m};
rep(i, m) cin >> x[i];
int ans = 0;
vector<int> d(m - 1);
sort(all(x));
rep(i, m - 1) d[i] = x[i + 1] - x[i];
sort(all(d));
// 距離dが大きい上位n-1個のdはカウントしなくて良い
rep(i, m - n) ans += d[i];
cout << ans << endl;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
const ll INF = 1LL << 60;
// n個のコマの担当範囲をどう区切るかの問題に帰着できる
// 範囲を決めることは、その右端から次の担当コマまでの区間をカウントしなくてよくすることと同義
int main() {
int n, m;
cin >> n >> m;
vector<int> x(m);
rep(i, m) cin >> x[i];
int ans = 0;
vector<int> d(m - 1);
sort(all(x));
rep(i, m - 1) d[i] = x[i + 1] - x[i];
sort(all(d));
// 距離dが大きい上位n-1個のdはカウントしなくて良い
rep(i, m - n) ans += d[i];
cout << ans << endl;
} | replace | 13 | 14 | 13 | 14 | 0 | |
p03137 | C++ | Runtime Error |
#include <algorithm>
#include <cmath>
#include <fstream>
#include <iostream>
#include <numeric>
#include <type_traits>
#include <vector>
using namespace std;
int main(int argc, const char *argv[]) {
int n, m;
cin >> n >> m;
vector<int> x(m);
for (int i = 0; i < m; i++) {
cin >> x[i];
}
sort(x.begin(), x.end());
vector<int> d(m - 1);
for (int i = 0; i < m - 1; i++) {
d[i] = x[i + 1] - x[i];
}
sort(d.begin(), d.end());
int ans = 0;
for (int i = 0; i < d.size() - n + 1; i++) {
ans += d[i];
}
cout << ans << endl;
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <fstream>
#include <iostream>
#include <numeric>
#include <type_traits>
#include <vector>
using namespace std;
int main(int argc, const char *argv[]) {
int n, m;
cin >> n >> m;
vector<int> x(m);
if (n >= m) {
cout << 0 << endl;
return 0;
}
for (int i = 0; i < m; i++) {
cin >> x[i];
}
sort(x.begin(), x.end());
vector<int> d(m - 1);
for (int i = 0; i < m - 1; i++) {
d[i] = x[i + 1] - x[i];
}
sort(d.begin(), d.end());
int ans = 0;
for (int i = 0; i < d.size() - n + 1; i++) {
ans += d[i];
}
cout << ans << endl;
return 0;
}
| insert | 16 | 16 | 16 | 20 | 0 | |
p03137 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x, y) CPP_CAT_I(x, y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x, y) x##y
#define FOR(i, start, end) \
for (i64 i = (start), CPP_CAT(i, xxxx_end) = (end); \
i < CPP_CAT(i, xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f, c, ...) \
(([&](decltype((c)) cccc) { \
return (f)(std::begin(cccc), std::end(cccc), ##__VA_ARGS__); \
})(c))
using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
void solve() {
int n, m;
cin >> n >> m;
vector<int> d;
FOR(i, 0, m) {
int x;
cin >> x;
d.push_back(x);
}
std::sort(d.begin(), d.end());
vector<int> dn;
FOR(i, 0, m - 1) dn.push_back(d[i + 1] - d[i]);
std::sort(dn.begin(), dn.end());
int ans = 0;
if (m != 1) {
FOR(i, 0, n + 1) ans = ans + dn[i];
}
cout << ans << endl;
}
signed main() {
solve();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x, y) CPP_CAT_I(x, y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x, y) x##y
#define FOR(i, start, end) \
for (i64 i = (start), CPP_CAT(i, xxxx_end) = (end); \
i < CPP_CAT(i, xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f, c, ...) \
(([&](decltype((c)) cccc) { \
return (f)(std::begin(cccc), std::end(cccc), ##__VA_ARGS__); \
})(c))
using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
void solve() {
int n, m;
cin >> n >> m;
vector<int> d;
FOR(i, 0, m) {
int x;
cin >> x;
d.push_back(x);
}
std::sort(d.begin(), d.end());
vector<int> dn;
FOR(i, 0, m - 1) dn.push_back(d[i + 1] - d[i]);
std::sort(dn.begin(), dn.end());
int ans = 0;
FOR(i, 0, m - n) ans += dn[i];
cout << ans << endl;
}
signed main() {
solve();
return 0;
} | replace | 44 | 47 | 44 | 45 | 0 | |
p03137 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define LARGE 1000000000
#define MOD 100000
int N, M, sum;
int aim[100009], dis[100009];
int main() {
dis[0] = 0;
cin >> N >> M;
if (N == M)
sum = 0;
else {
for (int i = 0; i < M; i++)
cin >> aim[i];
sort(aim, aim + M);
for (int i = 1; i < M; i++)
dis[i] = aim[i] - aim[i - 1];
sort(dis, dis + M);
sum = aim[M - 1] - aim[0];
for (int i = 0; i < N - 1; i++)
sum -= dis[M - 1 - i];
}
cout << sum << endl;
return 0;
}
// チーズ
/*
int H, W, N, ans, tag, si, sj;
char MAP[1009][1009];
int dp[1009][1009];
bool inmap(int i, int j) {
return ((i >= 0 && i <= H - 1) && (j >= 0 && j <= W - 1));
}
bool pass(int i, int j) {
return (MAP[i][j] != 'X');
}
int DFS(int i, int j) {
if (dp[i][j] != LARGE)return dp[i][j];
if (MAP[i][j] - '0' == tag) {
si = i; sj = j;
return 0;
}
if (inmap(i + 1, j) && pass(i + 1, j)) dp[i][j] = min(dp[i][j], DFS(i + 1, j) +
1); if (inmap(i - 1, j) && pass(i - 1, j)) dp[i][j] = min(dp[i][j], DFS(i - 1,
j) + 1); if (inmap(i, j + 1) && pass(i, j + 1)) dp[i][j] = min(dp[i][j], DFS(i,
j + 1) + 1); if (inmap(i, j - 1) && pass(i, j - 1)) dp[i][j] = min(dp[i][j],
DFS(i, j - 1) + 1); cout << i << " " << j << " " << dp[i][j] << endl; return
dp[i][j];
}
int main() {
cin >> H >> W >> N;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
cin >> MAP[i][j];
if (MAP[i][j] == 'S') {
si = i; sj = j;
}
}
}
for (int i = 1; i <= N; i++) {
cout << i << " " << si << " " << sj << endl << endl;
for (int j = 0; j < H; j++) {
for (int k = 0; k < W; k++) {
dp[j][k] = LARGE;
}
}
tag = i;
ans += DFS(si, sj);
}
cout << ans << endl;
return 0;
}
*/
| #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define LARGE 1000000000
#define MOD 100000
int N, M, sum;
int aim[100009], dis[100009];
int main() {
dis[0] = 0;
cin >> N >> M;
if (N >= M)
sum = 0;
else {
for (int i = 0; i < M; i++)
cin >> aim[i];
sort(aim, aim + M);
for (int i = 1; i < M; i++)
dis[i] = aim[i] - aim[i - 1];
sort(dis, dis + M);
sum = aim[M - 1] - aim[0];
for (int i = 0; i < N - 1; i++)
sum -= dis[M - 1 - i];
}
cout << sum << endl;
return 0;
}
// チーズ
/*
int H, W, N, ans, tag, si, sj;
char MAP[1009][1009];
int dp[1009][1009];
bool inmap(int i, int j) {
return ((i >= 0 && i <= H - 1) && (j >= 0 && j <= W - 1));
}
bool pass(int i, int j) {
return (MAP[i][j] != 'X');
}
int DFS(int i, int j) {
if (dp[i][j] != LARGE)return dp[i][j];
if (MAP[i][j] - '0' == tag) {
si = i; sj = j;
return 0;
}
if (inmap(i + 1, j) && pass(i + 1, j)) dp[i][j] = min(dp[i][j], DFS(i + 1, j) +
1); if (inmap(i - 1, j) && pass(i - 1, j)) dp[i][j] = min(dp[i][j], DFS(i - 1,
j) + 1); if (inmap(i, j + 1) && pass(i, j + 1)) dp[i][j] = min(dp[i][j], DFS(i,
j + 1) + 1); if (inmap(i, j - 1) && pass(i, j - 1)) dp[i][j] = min(dp[i][j],
DFS(i, j - 1) + 1); cout << i << " " << j << " " << dp[i][j] << endl; return
dp[i][j];
}
int main() {
cin >> H >> W >> N;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
cin >> MAP[i][j];
if (MAP[i][j] == 'S') {
si = i; sj = j;
}
}
}
for (int i = 1; i <= N; i++) {
cout << i << " " << si << " " << sj << endl << endl;
for (int j = 0; j < H; j++) {
for (int k = 0; k < W; k++) {
dp[j][k] = LARGE;
}
}
tag = i;
ans += DFS(si, sj);
}
cout << ans << endl;
return 0;
}
*/
| replace | 23 | 24 | 23 | 24 | 0 | |
p03137 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> x(m), d(m);
for (int i = 0; i < m; i++)
cin >> x[i];
sort(x.begin(), x.end());
int ans = 0;
for (int i = 0; i < m - 1; i++) {
d[i] = x[i + 1] - x[i];
ans += d[i];
}
sort(d.begin(), d.end(), greater<int>());
for (int i = 0; i < n - 1; i++) {
ans -= d[i];
}
cout << ans << endl;
} | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> x(m), d(m);
for (int i = 0; i < m; i++)
cin >> x[i];
if (n >= m) {
cout << 0 << endl;
return 0;
}
sort(x.begin(), x.end());
int ans = 0;
for (int i = 0; i < m - 1; i++) {
d[i] = x[i + 1] - x[i];
ans += d[i];
}
sort(d.begin(), d.end(), greater<int>());
for (int i = 0; i < n - 1; i++) {
ans -= d[i];
}
cout << ans << endl;
} | insert | 13 | 13 | 13 | 17 | 0 | |
p03137 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(), (a).end()
#define pb push_back
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
int main() {
int n, m;
cin >> n >> m;
long long x[100000];
vector<long> d(m - 1);
for (int i = 0; i < m; ++i) {
cin >> x[i];
}
if (m == 1) {
cout << 0 << endl;
return 0;
}
sort(x, x + m);
int total = 0;
for (int i = 1; i < m; ++i) {
total += abs(x[i] - x[i - 1]);
d.push_back(abs(x[i] - x[i - 1]));
}
sort(all(d), greater<int>());
for (int i = 0; i < n - 1; ++i) {
total -= d[i];
}
cout << total << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(), (a).end()
#define pb push_back
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
int main() {
int n, m;
cin >> n >> m;
long long x[100000];
vector<long> d(m - 1);
for (int i = 0; i < m; ++i) {
cin >> x[i];
}
if (n >= m) {
cout << 0 << endl;
return 0;
}
sort(x, x + m);
int total = 0;
for (int i = 1; i < m; ++i) {
total += abs(x[i] - x[i - 1]);
d.push_back(abs(x[i] - x[i - 1]));
}
sort(all(d), greater<int>());
for (int i = 0; i < n - 1; ++i) {
total -= d[i];
}
cout << total << endl;
} | replace | 19 | 20 | 19 | 20 | 0 | |
p03137 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
if (n >= m) {
cout << 0;
}
vector<int> x(m);
for (int i = 0; i < m; i++) {
cin >> x[i];
}
sort(x.begin(), x.end());
vector<int> d(m - 1);
for (int i = 0; i < m - 1; i++) {
d[i] = x[i + 1] - x[i];
}
sort(d.begin(), d.end());
int ans = 0;
for (int i = 0; i < d.size() - (n - 1); i++) {
ans += d[i];
}
cout << ans;
} | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
if (n >= m) {
cout << 0;
return 0;
}
vector<int> x(m);
for (int i = 0; i < m; i++) {
cin >> x[i];
}
sort(x.begin(), x.end());
vector<int> d(m - 1);
for (int i = 0; i < m - 1; i++) {
d[i] = x[i + 1] - x[i];
}
sort(d.begin(), d.end());
int ans = 0;
for (int i = 0; i < d.size() - (n - 1); i++) {
ans += d[i];
}
cout << ans;
} | insert | 11 | 11 | 11 | 12 | 0 | |
p03137 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <vector>
int main() {
int N, M;
std::cin >> N >> M;
std::vector<int> x(M);
for (auto i = x.begin(); i != x.end(); i++) {
std::cin >> *i;
}
if (N >= M) {
std::cout << 0 << std::endl;
} else {
std::sort(x.begin(), x.end());
int sum = *(x.end() - 1) - *(x.begin());
for (auto i = x.begin(); i != x.end(); i++) {
if (i != x.end() - 1) {
*i = *(i + 1) - *i;
} else {
*i = 0;
}
}
std::sort(x.begin(), x.end());
int minus = 0;
for (auto i = x.crbegin(); x.crbegin() - i != N - 1; i++) {
minus += *i;
}
std::cout << sum - minus << std::endl;
}
return 0;
}
| #include <algorithm>
#include <iostream>
#include <vector>
int main() {
int N, M;
std::cin >> N >> M;
std::vector<int> x(M);
for (auto i = x.begin(); i != x.end(); i++) {
std::cin >> *i;
}
if (N >= M) {
std::cout << 0 << std::endl;
} else {
std::sort(x.begin(), x.end());
int sum = *(x.end() - 1) - *(x.begin());
for (auto i = x.begin(); i != x.end(); i++) {
if (i != x.end() - 1) {
*i = *(i + 1) - *i;
} else {
*i = 0;
}
}
std::sort(x.begin(), x.end());
int minus = 0;
for (auto i = x.crbegin(); i - x.crbegin() != N - 1; i++) {
minus += *i;
}
std::cout << sum - minus << std::endl;
}
return 0;
}
| replace | 28 | 29 | 28 | 29 | -11 | |
p03137 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = INT32_MAX;
const long long int Mod = 1000000007;
const long long int mod = 100000; // 10^5
using ll = long long int; // long long int は64bit
using ci = const int;
using vi = vector<int>;
using Vi = vector<long long int>;
using pii = pair<int, int>;
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#define rep(i, N) for (int i = 0; i < N; i++)
#define np nullptr
template <class T> bool chmax(T &former, const T &b) {
if (former <= b) {
former = b;
return true;
}
return false;
}
template <class T> bool chmin(T &former, const T &b) {
if (b < former) {
former = b;
return true;
}
return false;
}
template <class T> T sqar(T x) { return x * x; } // sqrt(x)は平方根;
#define Sort(v) \
std::sort(v.begin(), v.end(), \
std::greater<decltype(v[0])>()) // 降順でVをソート
#define fill(x, num) memset(x, num, sizeof(x));
typedef vector<vector<ll>> matrix;
// cin.tie(0);ios::sync_with_stdio(false);
void cinit() {
cin.tie(0);
ios::sync_with_stdio(false);
}
//////////////////////////^^ *Emile
///^^^//////////////////////////////////////////////////////
int main() {
ll n, m;
cin >> n >> m;
vi v;
ll aa;
rep(i, m) {
cin >> aa;
v.pb(aa);
}
sort(all(v));
vi vd;
if (m == 1) {
cout << v[v.size() - 1] - v[0] << endl;
return 0;
}
rep(i, v.size() - 1) { vd.pb(v[i + 1] - v[i]); }
Sort(vd);
ll ans = v[v.size() - 1] - v[0];
rep(i, n - 1) { ans -= vd[i]; }
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = INT32_MAX;
const long long int Mod = 1000000007;
const long long int mod = 100000; // 10^5
using ll = long long int; // long long int は64bit
using ci = const int;
using vi = vector<int>;
using Vi = vector<long long int>;
using pii = pair<int, int>;
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#define rep(i, N) for (int i = 0; i < N; i++)
#define np nullptr
template <class T> bool chmax(T &former, const T &b) {
if (former <= b) {
former = b;
return true;
}
return false;
}
template <class T> bool chmin(T &former, const T &b) {
if (b < former) {
former = b;
return true;
}
return false;
}
template <class T> T sqar(T x) { return x * x; } // sqrt(x)は平方根;
#define Sort(v) \
std::sort(v.begin(), v.end(), \
std::greater<decltype(v[0])>()) // 降順でVをソート
#define fill(x, num) memset(x, num, sizeof(x));
typedef vector<vector<ll>> matrix;
// cin.tie(0);ios::sync_with_stdio(false);
void cinit() {
cin.tie(0);
ios::sync_with_stdio(false);
}
//////////////////////////^^ *Emile
///^^^//////////////////////////////////////////////////////
int main() {
ll n, m;
cin >> n >> m;
vi v;
ll aa;
rep(i, m) {
cin >> aa;
v.pb(aa);
}
sort(all(v));
vi vd;
if (m == 1) {
cout << v[v.size() - 1] - v[0] << endl;
return 0;
}
rep(i, v.size() - 1) { vd.pb(v[i + 1] - v[i]); }
Sort(vd);
ll ans = v[v.size() - 1] - v[0];
rep(i, n - 1) {
if (i >= vd.size()) {
break;
}
ans -= vd[i];
}
cout << ans << endl;
return 0;
} | replace | 63 | 64 | 63 | 69 | 0 | |
p03137 | C++ | Runtime Error |
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define INF 2147483647
#define int long long
// #define MODE 1
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " ";
#define END cout << endl;
#else
#define DEB(X) \
{}
#define ARDEB(i, X) \
{}
#define END \
{}
#endif
// typedef long long int ll;
signed main() {
int n, m, x[111111], ans = 0;
;
cin >> n >> m;
for (int i = 0; i < m; i++)
cin >> x[i];
sort(x, x + m);
pair<int, int> v[111111];
for (int i = 0; i < m - 1; i++) {
v[i] = make_pair(x[i + 1] - x[i], x[i + 1]);
}
sort(v, v + m - 1);
/*for(int i=0;i<m-1;i++){
cout<<v[i].first<<" "<<v[i].second<<endl;
}*/
// cout<<endl;
int xf[222222] = {0};
for (int i = m - 2; m - 2 - i != n - 1; i--) {
xf[v[i].second] = 1;
// cout<<v[i].second<<endl;
}
xf[x[0]] = 1;
int place = x[0], co = 0;
for (int i = 0; i < m; i++) {
if (xf[x[i]] == 1 && i != 0) {
ans += x[i - 1] - place;
// cout<<place<<" "<<x[i]<<endl;
place = x[i];
// co++;
}
// if(co==n)break;
}
ans += x[m - 1] - place;
cout << ans << endl;
} |
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define INF 2147483647
#define int long long
// #define MODE 1
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " ";
#define END cout << endl;
#else
#define DEB(X) \
{}
#define ARDEB(i, X) \
{}
#define END \
{}
#endif
// typedef long long int ll;
signed main() {
int n, m, x[111111], ans = 0;
;
cin >> n >> m;
for (int i = 0; i < m; i++)
cin >> x[i];
sort(x, x + m);
pair<int, int> v[111111];
for (int i = 0; i < m - 1; i++) {
v[i] = make_pair(x[i + 1] - x[i], x[i + 1]);
}
sort(v, v + m - 1);
/*for(int i=0;i<m-1;i++){
cout<<v[i].first<<" "<<v[i].second<<endl;
}*/
// cout<<endl;
unordered_map<int, int> xf;
for (int i = m - 2; m - 2 - i != n - 1; i--) {
xf[v[i].second] = 1;
// cout<<v[i].second<<endl;
}
xf[x[0]] = 1;
int place = x[0], co = 0;
for (int i = 0; i < m; i++) {
if (xf[x[i]] == 1 && i != 0) {
ans += x[i - 1] - place;
// cout<<place<<" "<<x[i]<<endl;
place = x[i];
// co++;
}
// if(co==n)break;
}
ans += x[m - 1] - place;
cout << ans << endl;
} | replace | 52 | 53 | 52 | 53 | 0 | |
p03137 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define all(x) begin(x), end(x)
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
vi a(m);
for (int i = 0; i < m; ++i)
cin >> a[i];
sort(all(a));
a.erase(unique(all(a)), end(a));
// can skip n - 1 gaps
vi b;
for (int i = 1; i < a.size(); ++i) {
b.push_back(a[i] - a[i - 1]);
}
sort(all(b));
for (int i = 0; i < n - 1; ++i)
b.pop_back();
ll ans = 0LL;
for (int x : b)
ans += x;
cout << ans << '\n';
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define all(x) begin(x), end(x)
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
vi a(m);
for (int i = 0; i < m; ++i)
cin >> a[i];
sort(all(a));
a.erase(unique(all(a)), end(a));
// can skip n - 1 gaps
vi b;
for (int i = 1; i < a.size(); ++i) {
b.push_back(a[i] - a[i - 1]);
}
sort(all(b));
for (int i = 0; !b.empty() and i < n - 1; ++i)
b.pop_back();
ll ans = 0LL;
for (int x : b)
ans += x;
cout << ans << '\n';
return 0;
}
| replace | 31 | 32 | 31 | 32 | 0 | |
p03137 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int a[123456], b[123456];
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> a[i];
}
sort(a, a + m);
for (int i = 1; i < m; i++) {
b[i - 1] = a[i] - a[i - 1];
}
sort(b, b + m - 1);
cout << accumulate(b, b + m - n, 0LL) << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int a[123456], b[123456];
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> a[i];
}
sort(a, a + m);
for (int i = 1; i < m; i++) {
b[i - 1] = a[i] - a[i - 1];
}
sort(b, b + m - 1);
cout << accumulate(b, max(b + m - n, b + 0), 0LL) << endl;
return 0;
} | replace | 15 | 16 | 15 | 16 | 0 | |
p03137 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
int main(int argc, char const *argv[]) {
int N, M;
cin >> N >> M;
vector<int> X;
X.resize(M);
for (int i = 0; i < M; i++) {
cin >> X[i];
}
if (N >= M) {
cout << 0 << endl;
return 0;
}
sort(X.begin(), X.end());
vector<int> d;
d.resize(M - 1);
for (int i = 0; i < M; i++) {
d[i] = X[i + 1] - X[i];
}
sort(d.begin(), d.end());
int sum = accumulate(d.begin(), d.end() - (N - 1), 0);
cout << sum << endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
int main(int argc, char const *argv[]) {
int N, M;
cin >> N >> M;
vector<int> X;
X.resize(M);
for (int i = 0; i < M; i++) {
cin >> X[i];
}
if (N >= M) {
cout << 0 << endl;
return 0;
}
sort(X.begin(), X.end());
vector<int> d;
d.resize(M - 1);
for (int i = 0; i < M - 1; i++) {
d[i] = X[i + 1] - X[i];
}
sort(d.begin(), d.end());
int sum = accumulate(d.begin(), d.end() - (N - 1), 0);
cout << sum << endl;
return 0;
} | replace | 25 | 26 | 25 | 26 | 0 | |
p03137 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#define MAX 10001
using namespace std;
int main() {
int n;
int m;
int zahyo[MAX];
long long int ans = 0;
bool ff = true;
cin >> n >> m;
if (n > m) {
ff = false;
}
for (int i = 0; i < m; ++i) {
cin >> zahyo[i];
}
sort(zahyo, zahyo + m);
int diff[MAX];
for (int j = 0; j < m - 1; ++j) {
diff[j] = zahyo[j + 1] - zahyo[j];
}
sort(diff, diff + m - 1);
for (int k = 0; k < m - n; ++k) {
ans += diff[k];
}
if (ff) {
cout << ans;
} else {
cout << 0;
}
return 0;
} | #include <algorithm>
#include <iostream>
#define MAX 100001
using namespace std;
int main() {
int n;
int m;
int zahyo[MAX];
long long int ans = 0;
bool ff = true;
cin >> n >> m;
if (n > m) {
ff = false;
}
for (int i = 0; i < m; ++i) {
cin >> zahyo[i];
}
sort(zahyo, zahyo + m);
int diff[MAX];
for (int j = 0; j < m - 1; ++j) {
diff[j] = zahyo[j + 1] - zahyo[j];
}
sort(diff, diff + m - 1);
for (int k = 0; k < m - n; ++k) {
ans += diff[k];
}
if (ff) {
cout << ans;
} else {
cout << 0;
}
return 0;
} | replace | 2 | 3 | 2 | 3 | 0 | |
p03137 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int main() {
int n, m;
cin >> n >> m;
vector<int> x(m);
vector<int> diff(m - 1);
rep(i, m) { cin >> x[i]; }
if (m == 1) {
puts("0");
return 0;
}
sort(x.begin(), x.end());
ll ans = 0LL;
rep(i, m - 1) {
diff[i] = x[i + 1] - x[i];
ans += diff[i];
}
sort(diff.begin(), diff.end(), greater<int>());
rep(i, n - 1) { ans -= diff[i]; }
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int main() {
int n, m;
cin >> n >> m;
vector<int> x(m);
vector<int> diff(m - 1);
rep(i, m) { cin >> x[i]; }
if (m <= n) {
puts("0");
return 0;
}
sort(x.begin(), x.end());
ll ans = 0LL;
rep(i, m - 1) {
diff[i] = x[i + 1] - x[i];
ans += diff[i];
}
sort(diff.begin(), diff.end(), greater<int>());
rep(i, n - 1) { ans -= diff[i]; }
cout << ans << endl;
return 0;
} | replace | 12 | 13 | 12 | 13 | 0 | |
p03137 | C++ | Runtime Error | #include <algorithm>
#include <climits>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long unsigned int ll;
typedef pair<int, int> P;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define fillInt(xs, x) \
for (int i = 0; i < (x); i++) \
scanf("%d", &xs[i]);
#define fillLong(xs, x) \
for (int i = 0; i < (x); i++) \
scanf("%ld", &xs[i]);
#define fillString(xs, x) \
for (int i = 0; i < (x); i++) \
cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvdi(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)
#define rep(i, n) for (auto i = 0; i < (n); i++)
#define isValidPoint(x, y, mx, my) x >= 0 && x < mx &&y >= 0 && y < my
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const int MOD = 1000000007;
long a[10010];
long b[10010];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
long n, m;
cin >> n >> m;
fillLong(a, m);
sort(a, a + m);
rep(i, m - 1) { b[i] = a[i + 1] - a[i]; }
sort(b, b + m - 1, greater<long>());
if (m == 1) {
cout << 0 << endl;
} else {
long res = a[m - 1] - a[0];
long j = 0;
while (j < min(m - 1, n - 1)) {
res -= b[j];
j++;
}
cout << res << endl;
}
}
| #include <algorithm>
#include <climits>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long unsigned int ll;
typedef pair<int, int> P;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define fillInt(xs, x) \
for (int i = 0; i < (x); i++) \
scanf("%d", &xs[i]);
#define fillLong(xs, x) \
for (int i = 0; i < (x); i++) \
scanf("%ld", &xs[i]);
#define fillString(xs, x) \
for (int i = 0; i < (x); i++) \
cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvdi(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)
#define rep(i, n) for (auto i = 0; i < (n); i++)
#define isValidPoint(x, y, mx, my) x >= 0 && x < mx &&y >= 0 && y < my
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const int MOD = 1000000007;
long a[100010];
long b[100010];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
long n, m;
cin >> n >> m;
fillLong(a, m);
sort(a, a + m);
rep(i, m - 1) { b[i] = a[i + 1] - a[i]; }
sort(b, b + m - 1, greater<long>());
if (m == 1) {
cout << 0 << endl;
} else {
long res = a[m - 1] - a[0];
long j = 0;
while (j < min(m - 1, n - 1)) {
res -= b[j];
j++;
}
cout << res << endl;
}
}
| replace | 49 | 51 | 49 | 51 | 0 | |
p03137 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;
int main() {
ll n, m;
in2(n, m);
if (m == 1) {
out(0);
memi;
return 0;
}
vector<ll> a(m), b(m - 1);
rep(i, m) in(a[i]);
sort(all(a));
rep(i, m - 1) b[i] = a[i + 1] - a[i];
sort(all(b));
rep(i, n - 1) b[m - i - 2] = 0;
n = 0;
rep(i, b.size()) n += b[i];
out(n);
memi;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;
int main() {
ll n, m;
in2(n, m);
if (m == 1) {
out(0);
memi;
return 0;
}
vector<ll> a(m), b(m - 1);
rep(i, m) in(a[i]);
sort(all(a));
rep(i, m - 1) b[i] = a[i + 1] - a[i];
sort(all(b));
rep(i, n - 1) b[max(0ll, m - i - 2)] = 0;
n = 0;
rep(i, b.size()) n += b[i];
out(n);
memi;
}
| replace | 29 | 30 | 29 | 30 | 0 | |
p03137 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
using namespace std;
const int INF = 1145141919, MOD = 1e9 + 7;
const long long LINF = 8931145141919364364, LMOD = 998244353;
inline long long mod(long long n, long long m) { return (n % m + m) % m; }
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};
int main() {
long long n, m;
cin >> n >> m;
long long x[m];
rep(i, m) cin >> x[i];
if (n >= m) {
cout << 0 << endl;
}
sort(x, x + m);
vector<long long> diff;
long long ans = 0;
for (int i = 1; i < m; i++) {
diff.push_back(x[i] - x[i - 1]);
ans += x[i] - x[i - 1];
}
sort(all(diff));
reverse(all(diff));
for (int i = 0; i < n - 1; i++) {
ans -= diff[i];
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
using namespace std;
const int INF = 1145141919, MOD = 1e9 + 7;
const long long LINF = 8931145141919364364, LMOD = 998244353;
inline long long mod(long long n, long long m) { return (n % m + m) % m; }
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};
int main() {
long long n, m;
cin >> n >> m;
long long x[m];
rep(i, m) cin >> x[i];
if (n >= m) {
cout << 0 << endl;
return 0;
}
sort(x, x + m);
vector<long long> diff;
long long ans = 0;
for (int i = 1; i < m; i++) {
diff.push_back(x[i] - x[i - 1]);
ans += x[i] - x[i - 1];
}
sort(all(diff));
reverse(all(diff));
for (int i = 0; i < n - 1; i++) {
ans -= diff[i];
}
cout << ans << endl;
return 0;
}
| insert | 16 | 16 | 16 | 17 | 0 | |
p03137 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long
#define rep(i, a, b) for (long long i = a; i < b; i += 1)
#define repr(i, a, b) for (long long i = a; i <= b; i += 1)
#define vec vector<ll>
#define map map<string, int>
#define repa(p, A) for (auto p : A)
#define pb push_back
#define sort(a) sort(a.begin(), a.end())
#define reverse(a) reverse(a.begin(), a.end())
const double PI = acos(-1);
using namespace std;
int main() {
ll N, K;
cin >> K >> N;
vec A(N), B(N);
rep(i, 0, N) { cin >> A[i]; }
sort(A);
rep(i, 0, N - 1) { B[i] = A[i + 1] - A[i]; }
sort(B);
reverse(B);
ll count = 0;
rep(i, 0, K - 1) {
count += B[i];
// cout<<B[i]<<endl;
}
ll a = A[N - 1] - A[0];
a -= count;
cout << a << endl;
} | #include <bits/stdc++.h>
#define ll long long
#define rep(i, a, b) for (long long i = a; i < b; i += 1)
#define repr(i, a, b) for (long long i = a; i <= b; i += 1)
#define vec vector<ll>
#define map map<string, int>
#define repa(p, A) for (auto p : A)
#define pb push_back
#define sort(a) sort(a.begin(), a.end())
#define reverse(a) reverse(a.begin(), a.end())
const double PI = acos(-1);
using namespace std;
int main() {
ll N, K;
cin >> K >> N;
vec A(N), B(N);
rep(i, 0, N) { cin >> A[i]; }
sort(A);
rep(i, 0, N - 1) { B[i] = A[i + 1] - A[i]; }
sort(B);
reverse(B);
ll count = 0;
rep(i, 0, min(K - 1, N - 1)) {
count += B[i];
// cout<<B[i]<<endl;
}
ll a = A[N - 1] - A[0];
a -= count;
cout << a << endl;
} | replace | 23 | 24 | 23 | 25 | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.