buggy_code
stringlengths
11
625k
fixed_code
stringlengths
17
625k
bug_type
stringlengths
2
4.45k
language
int64
0
8
token_count
int64
5
200k
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> // #include<ext/pb_ds/assoc_container.hpp> // #include<ext/pb_ds/tree_policy.hpp> // #include<ext/pb_ds/tag_and_trait.hpp> // using namespace __gnu_pbds; // #include<boost/multiprecision/cpp_int.hpp> // namespace multiprecisioninteger = boost::multiprecision; // us...
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> // #include<ext/pb_ds/assoc_container.hpp> // #include<ext/pb_ds/tree_policy.hpp> // #include<ext/pb_ds/tag_and_trait.hpp> // using namespace __gnu_pbds; // #include<boost/multiprecision/cpp_int.hpp> // namespace multiprecisioninteger = boost::multiprecision; // us...
[["-", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 14, 8, 9, 0, 14, 49, 53, 49, 22], ["-", 0, 1, 0, 2, 3, 4, 0, 16, 17, 33], ["-", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13], ["-", 0, 1, 0, 2, 3, 4, 0, 25, 0, 35]]
1
893
K,N = (int(x) for x in input().split()) al = [int(x) for x in input().split()] d = [al[x+1]-al[x] for x in range(0, N-1)] d.append(K-al[-1]-al[0]) print(sum(d)-max(d))
K,N = (int(x) for x in input().split()) al = [int(x) for x in input().split()] d = [al[x+1]-al[x] for x in range(0, N-1)] d.append(K-al[-1]+al[0]) print(sum(d)-max(d))
[["-", 0, 1, 0, 652, 3, 4, 0, 657, 17, 33], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 72]]
5
93
K,N=map(int,input().split()) A=list(map(int,input().split())) b=[] for i in range(N-1): b.append(K-(A[i+1]-A[i])) b.append(A[N-1]-A[i]) print(min(b))
K,N=map(int,input().split()) A=list(map(int,input().split())) b=[] for i in range(N-1): b.append(K-(A[i+1]-A[i])) b.append(A[N-1]-A[0]) print(min(b))
[["-", 0, 652, 3, 4, 0, 657, 12, 206, 206, 22], ["+", 0, 652, 3, 4, 0, 657, 12, 206, 206, 612]]
5
90
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { long K, N, max = 0; cin >> K >> N; vector<int> A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } for (int i = 0; i < N; i++) { if (i != N - 1) { if (max < A[i + 1] - A[i]) { max = A[i - 1] - A...
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { long K, N, max = 0; cin >> K >> N; vector<int> A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } for (int i = 0; i < N; i++) { if (i != N - 1) { if (max < A[i + 1] - A[i]) { max = A[i + 1] - A...
[["-", 12, 16, 31, 69, 341, 342, 0, 16, 17, 33], ["+", 12, 16, 31, 69, 341, 342, 0, 16, 17, 72]]
1
162
#include <bits/stdc++.h> using namespace std; #include <cstdlib> #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) int main() { int64_t N, K; cin >> K >> N; vector<int64_t> A(N); rep(i, N) cin >> A.at(i); int64_t max = K + A.at(0) - A.at(N - 1); for (int64_t i = 0; i < N - 1; i++) { if (A.at(i +...
#include <bits/stdc++.h> using namespace std; #include <cstdlib> #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) int main() { int64_t N, K; cin >> K >> N; vector<int64_t> A(N); rep(i, N) cin >> A.at(i); int64_t max = K + A.at(0) - A.at(N - 1); for (int64_t i = 0; i < N - 1; i++) { if (A.at(i +...
[["+", 8, 9, 0, 1, 0, 16, 12, 16, 31, 22], ["+", 8, 9, 0, 1, 0, 16, 12, 16, 17, 33]]
1
139
#include <bits/stdc++.h> #define ll long long using namespace std; int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; } const double PI = 3.14159265358979323846; int main() { int k, n; cin >> k >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } int max = 0; int num1 = 0; int num2 ...
#include <bits/stdc++.h> #define ll long long using namespace std; int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; } const double PI = 3.14159265358979323846; int main() { int k, n; cin >> k >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } int max = 0; int num1 = 0; int num2 ...
[["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 24], ["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 25]]
1
191
#include <iostream> #include <vector> using namespace std; int main() { int dis, num; cin >> dis >> num; vector<int> vec(num); for (int i = 0; i < num; i++) { cin >> vec.at(i); } int x, y; x = 20 - (vec[num - 1] - vec[0]); y = vec[1] - vec[0]; int range; if (x <= y) { range = dis - y; ...
#include <iostream> #include <vector> using namespace std; int main() { int dis, num; cin >> dis >> num; vector<int> vec(num); for (int i = 0; i < num; i++) { cin >> vec.at(i); } int x, y; x = dis - (vec[num - 1] - vec[0]); y = vec[1] - vec[0]; int range; if (x <= y) { range = dis - y; ...
[["-", 8, 9, 0, 1, 0, 11, 12, 16, 31, 13], ["+", 8, 9, 0, 1, 0, 11, 12, 16, 31, 22]]
1
213
K, N = map(int,input().split()) A = list(map(int, input().split())) a = A[0] sub = [] for _ in range(N): p = A.pop() sub.append(K-p) K = p sub[0] += a print(sub) sub.remove(max(sub)) print(sum(sub))
K, N = map(int,input().split()) A = list(map(int, input().split())) a = A[0] sub = [] for _ in range(N): p = A.pop() sub.append(K-p) K = p sub[0] += a sub.remove(max(sub)) print(sum(sub))
[["-", 36, 36, 0, 656, 0, 1, 0, 652, 63, 22], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 24], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 22], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 25]]
5
95
#include <bits/stdc++.h> using namespace std; int main() { int K, N; cin >> K >> N; vector<int> A; for (int i = 0; i < N; i++) { int x; cin >> x; A.push_back(x); } sort(A.begin(), A.end()); int max_dist = 0; for (int i = 0; i < N - 1; i++) { max_dist = max(A[i + 1] - A[i], max_dist);...
#include <bits/stdc++.h> using namespace std; int main() { int K, N; cin >> K >> N; vector<int> A; for (int i = 0; i < N; i++) { int x; cin >> x; A.push_back(x); } sort(A.begin(), A.end()); int max_dist = 0; for (int i = 0; i < N - 1; i++) { max_dist = max(A[i + 1] - A[i], max_dis...
[["+", 8, 9, 0, 1, 0, 16, 12, 16, 31, 22], ["+", 8, 9, 0, 1, 0, 16, 12, 16, 17, 33]]
1
143
K,N = map(int,input().split(sep=" ")) A = list(map(int,input().split(sep=" "))) maxA = 0 for i in range(0,N,1): if i == N-1: tmp = K + A[0] - A[i] else: tmp = A[i+1] - A[i] if maxA < tmp: maxA = tmp print(maxA)
K,N = map(int,input().split(sep=" ")) A = list(map(int,input().split(sep=" "))) maxA = 0 for i in range(0,N,1): if i == N-1: tmp = K + A[0] - A[i] else: tmp = A[i+1] - A[i] if maxA < tmp: maxA = tmp print(K-maxA)
[["+", 0, 1, 0, 652, 3, 4, 0, 657, 31, 22], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 33]]
5
105
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) int main() { int k, n; cin >> k >> n; vector<int> a(n); rep(i, n) cin >> a.at(i); vector<int> gap(n); rep(i, n) { if (i == n - 1) { gap.at(i) = 2 * k - (a.at(0) + a.at(n - 1)); } else { gap.at(...
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) int main() { int k, n; cin >> k >> n; vector<int> a(n); rep(i, n) cin >> a.at(i); vector<int> gap(n); rep(i, n) { if (i == n - 1) { gap.at(i) = k + a.at(0) - a.at(n - 1); } else { gap.at(i) = a...
[["-", 0, 1, 0, 11, 12, 16, 31, 16, 31, 13], ["-", 0, 1, 0, 11, 12, 16, 31, 16, 17, 48], ["-", 64, 9, 0, 1, 0, 11, 12, 16, 17, 33], ["-", 0, 1, 0, 11, 12, 16, 12, 23, 0, 24], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 17, 72], ["-", 0, 11, 12, 16, 12, 23, 0, 16, 17, 72], ["+", 64, 9, 0, 1, 0, 11, 12, 16, 17, 33], ["-", 12, 23,...
1
181
#include <bits/stdc++.h> #include <cmath> using namespace std; int main() { int K, N, i, j, k; cin >> K >> N; vector<int> A(N); for (i = 0; i < N; i++) { cin >> A[i]; } int min = K - A[N - 1] + A[0]; vector<int> B(N); for (j = 0; j < N; j++) { if (j = N - 1) { B[N - 1] = K - A[N - 1] + A[...
#include <bits/stdc++.h> #include <cmath> using namespace std; int main() { int K, N, i, j, k; cin >> K >> N; vector<int> A(N); for (i = 0; i < N; i++) { cin >> A[i]; } int min = K - A[N - 1] + A[0]; vector<int> B(N); for (j = 0; j < N; j++) { if (j == N - 1) { B[N - 1] = K - A[N - 1] + A...
[["-", 8, 9, 0, 57, 15, 339, 51, 11, 17, 32], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 60], ["-", 0, 14, 8, 9, 0, 7, 10, 11, 12, 13], ["+", 0, 14, 8, 9, 0, 7, 10, 11, 12, 13]]
1
192
#include <algorithm> #include <iostream> using namespace std; int main() { int k, n; cin >> k >> n; int a1, previous, next; cin >> a1; int m = 0; for (int i = 1; i < n; i++) { if (i == 1) { previous = a1; cin >> next; } else { previous = next; cin >> next; } m = max(n...
#include <algorithm> #include <iostream> using namespace std; int main() { int k, n; cin >> k >> n; int a1, previous, next; cin >> a1; int m = 0; for (int i = 1; i < n; i++) { if (i == 1) { previous = a1; cin >> next; } else { previous = next; cin >> next; } m = max(n...
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 31, 22], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 33]]
1
119
#include <stdio.h> int main() { int K, N; int i; scanf("%d %d", &K, &N); // int a[N] = {0}; int a[200000 + 1] = {0}; int d; int ans = 0; scanf("%d", &a[0]); for (i = 1; i <= N - 1; i++) { scanf("%d", &a[i]); d = a[i] - a[i - 1]; if (d > ans) { ans = d; } } if (K - (a[N ...
#include <stdio.h> int main() { int K, N; int i; scanf("%d %d", &K, &N); // int a[N] = {0}; int a[200000 + 1] = {0}; int d; int ans = 0; scanf("%d", &a[0]); for (i = 1; i <= N - 1; i++) { scanf("%d", &a[i]); d = a[i] - a[i - 1]; if (d > ans) { ans = d; } } if (K - (a[N ...
[["-", 64, 9, 0, 1, 0, 11, 12, 11, 17, 32], ["+", 64, 9, 0, 1, 0, 11, 12, 16, 17, 33]]
0
174
k,n =map(int,input().split()) a=list(map(int,input().split())) a.sort() a.append(k+a[0]) ans = 0 for i in range(n): ans = max(ans,a[i+1]-a[i]) print(ans)
k,n =map(int,input().split()) a=list(map(int,input().split())) a.sort() a.append(k+a[0]) ans = 0 for i in range(n): ans = max(ans,a[i+1]-a[i]) print(k - ans)
[["+", 0, 1, 0, 652, 3, 4, 0, 657, 31, 22], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 33]]
5
82
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; int main() { int k, n; cin >> k >> n; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; sort(a.begin(), a.end()); int MAX = k - a[n - 1] - a[0]; for (int i = 0; i < n; i++) { MAX = max(MAX, a[i...
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; int main() { ll k, n; cin >> k >> n; vector<ll> a(n); for (int i = 0; i < n; i++) cin >> a[i]; sort(a.begin(), a.end()); ll MAX = k - a[n - 1] + a[0]; for (int i = 0; i < n - 1; i++) { MAX = max(MAX, a[...
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 39, 78], ["-", 0, 43, 39, 344, 3, 347, 0, 77, 39, 40], ["+", 0, 43, 39, 344, 3, 347, 0, 77, 39, 78], ["-", 8, 9, 0, 43, 49, 50, 51, 16, 17, 33], ["+", 8, 9, 0, 43, 49, 50, 51, 16, 17, 72], ["+", 8, 9, 0, 7, 15, 16, 12, 16, 17, 33], ["+", 8, 9, ...
1
145
k, n = gets.split().map(&:to_i) a = gets.split().map(&:to_i) diff = 20 - a[-1] + a[0] (0..n-2).each do |i| diff = [diff, a[i+1] - a[i]].max end puts k - diff
k, n = gets.split().map(&:to_i) a = gets.split().map(&:to_i) diff = k - a[-1] + a[0] (0..n-2).each do |i| diff = [diff, a[i+1] - a[i]].max end puts k - diff
[["-", 0, 493, 0, 662, 12, 738, 31, 738, 31, 612], ["+", 0, 493, 0, 662, 12, 738, 31, 738, 31, 22]]
4
79
k,n=map(int,input().split()) a=list(map(int,input().split())) check_l =[] for i in range(len(a)-1): check_l.append(a[i+1]-a[i]) check_l.append(k+a[0]-a[n-1]) print(max(check_l))
k,n=map(int,input().split()) a=list(map(int,input().split())) check_l =[] for i in range(len(a)-1): check_l.append(a[i+1]-a[i]) check_l.append(k+a[0]-a[n-1]) print(k-max(check_l))
[["+", 0, 1, 0, 652, 3, 4, 0, 657, 31, 22], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 33]]
5
91
K, N = map(int,input().split()) a = list(map(int,input().split())) x = [a[0]-a[-1]+K] for i in range(1,N): x.append(a[i]-a[i-1]) print(x) print(K-max(x))
K, N = map(int,input().split()) a = list(map(int,input().split())) x = [a[0]-a[-1]+K] for i in range(1,N): x.append(a[i]-a[i-1]) print(K-max(x))
[["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 22], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 25], ["-", 36, 36, 0, 656, 0, 1, 0, 652, 63, 22], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 24]]
5
88
import numpy as np k,n=map(int,input().split()) a=list(int,input().split()) a=np.array(a) if max(abs(a[1:]-a[:-1])) < k-abs(a[0]-a[-1]):b=k-abs(a[0]-a[-1]) else:b= max(abs(a[1:]-a[:-1])) print(k-b)
import numpy as np k,n=map(int,input().split()) a=list(map(int,input().split())) a=np.array(a) if max(abs(a[1:]-a[:-1])) < k-abs(a[0]-a[-1]):b=k-abs(a[0]-a[-1]) else:b= max(abs(a[1:]-a[:-1])) print(k-b)
[["+", 0, 662, 12, 652, 3, 4, 0, 652, 63, 22], ["+", 12, 652, 3, 4, 0, 652, 3, 4, 0, 24], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 25]]
5
123
#include <bits/stdc++.h> using namespace std; int main() { int k; int n; cin >> k; cin >> n; int a[n]; int b[n]; //家と家との距離 int l = 0; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int h = 0; h < n; h++) { if (h != n - 1) { b[h] = a[h] - a[h + 1]; //(i+1)番目と(i+2)番目との距離 } else {...
#include <bits/stdc++.h> using namespace std; int main() { int k; int n; cin >> k; cin >> n; int a[n]; int b[n]; //家と家との距離 int l = 0; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int h = 0; h < n; h++) { if (h != n - 1) { b[h] = a[h + 1] - a[h]; //(i+1)番目と(i+2)番目との距離 } else {...
[["+", 12, 16, 31, 69, 341, 342, 0, 16, 17, 72], ["+", 12, 16, 31, 69, 341, 342, 0, 16, 12, 13], ["-", 12, 16, 12, 69, 341, 342, 0, 16, 17, 72], ["-", 12, 16, 12, 69, 341, 342, 0, 16, 12, 13]]
1
181
k, n = list(map(int, input().split())) a = list(map(int, input().split())) tmp = 0 for i in range(1, len(a)): if a[i]-a[i-1] >=0: tmp = a[i] - a[i-1] if a[0]+k-a[len(a)-1] > tmp: tmp = a[0]+k-a[len(a)-1] print(k-tmp)
k, n = list(map(int, input().split())) a = list(map(int, input().split())) tmp = 0 for i in range(1, len(a)): if a[i]-a[i-1] >=tmp: tmp = a[i] - a[i-1] if a[0]+k-a[len(a)-1] > tmp: tmp = a[0]+k-a[len(a)-1] print(k-tmp)
[["-", 0, 7, 8, 196, 0, 57, 15, 666, 0, 612], ["+", 0, 7, 8, 196, 0, 57, 15, 666, 0, 22]]
5
124
#include <iostream> #include <vector> using namespace std; int main(int argc, char const *argv[]) { int K, N; cin >> K >> N; vector<int> A(200010); A[0] = 0; int max = 0; int d; int tmp; for (int i = 1; i <= N + 1; i++) { if (i == N + 1) { d = K - A[N]; } else { cin >> A[i]; ...
#include <iostream> #include <vector> using namespace std; int main(int argc, char const *argv[]) { int K, N; cin >> K >> N; vector<int> A(200010); A[0] = 0; int max = 0; int d; int tmp; for (int i = 1; i <= N + 1; i++) { if (i == N + 1) { d = K - A[N] + A[1]; } else { cin >> A[i]...
[["+", 64, 9, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 0, 1, 0, 11, 12, 16, 12, 69, 28, 22], ["+", 0, 11, 12, 16, 12, 69, 341, 342, 0, 70], ["+", 0, 11, 12, 16, 12, 69, 341, 342, 0, 13], ["+", 0, 11, 12, 16, 12, 69, 341, 342, 0, 73]]
1
143
k, n = map(int, input().split()) aa = map(int, input().split()) B = [] for i in range(1, n): B.append(aa[i]-aa[i-1]) B.append(k-sum(B)) print(k-max(B))
k, n = map(int, input().split()) aa = list(map(int, input().split())) B = [] for i in range(1, n): B.append(aa[i] - aa[i - 1]) B.append(k - sum(B)) print(k - max(B))
[["+", 0, 656, 0, 1, 0, 662, 12, 652, 63, 22], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 24], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 25]]
5
80
K,N = map(int,input().split()) a = list(map(int,input().split())) ans = 0 for i in range(N-1): m=a[i+1]-a[i] ans = max(ans,m) h = K - a[N-1]+a[0] ans = max(ans,h) ans = K-ans
K,N = map(int,input().split()) a = list(map(int,input().split())) ans = 0 for i in range(N-1): m=a[i+1]-a[i] ans = max(ans,m) h = K - a[N-1]+a[0] ans = max(ans,h) ans = K-ans print(ans)
[["+", 36, 36, 0, 656, 0, 1, 0, 652, 63, 22], ["+", 0, 656, 0, 1, 0, 652, 3, 4, 0, 24], ["+", 0, 656, 0, 1, 0, 652, 3, 4, 0, 22], ["+", 0, 656, 0, 1, 0, 652, 3, 4, 0, 25]]
5
95
#include <algorithm> #include <cmath> #include <cstdio> #include <deque> #include <iostream> #include <numeric> #include <queue> #include <string> #include <utility> #include <vector> using namespace std; #define ALL(a) (a).begin(), (a).end() #define REP(i, n) for (size_t i = 0; i < (n); i++) #define nvec(T, v, n) ...
#include <algorithm> #include <cmath> #include <cstdio> #include <deque> #include <iostream> #include <numeric> #include <queue> #include <string> #include <utility> #include <vector> using namespace std; #define ALL(a) (a).begin(), (a).end() #define REP(i, n) for (size_t i = 0; i < (n); i++) #define nvec(T, v, n) ...
[["+", 8, 9, 0, 1, 0, 16, 12, 16, 31, 22], ["+", 8, 9, 0, 1, 0, 16, 12, 16, 17, 33]]
1
927
#include <algorithm> #include <chrono> #include <cstdio> #include <cstdlib> #include <cstring> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <math.h> #include <numeric> #include <queue> #include <random> #include <sstream> #include <stack> #inc...
#include <algorithm> #include <chrono> #include <cstdio> #include <cstdlib> #include <cstring> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <math.h> #include <numeric> #include <queue> #include <random> #include <sstream> #include <stack> #inc...
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 31, 22], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 33]]
1
372
#include <bits/stdc++.h> using namespace std; #define lli long long int #define mod 1000000007 lli k, n; lli arr[200005]; lli prefix[200005]; lli min(lli a, lli b) { if (a < b) { return a; } return b; } int main() { cin >> k >> n; for (int i = 0; i < n; i++) { cin >> arr[i]; } vector<int> v; f...
#include <bits/stdc++.h> using namespace std; #define lli long long int #define mod 1000000007 lli k, n; lli arr[200005]; lli prefix[200005]; lli min(lli a, lli b) { if (a < b) { return a; } return b; } int main() { cin >> k >> n; for (int i = 0; i < n; i++) { cin >> arr[i]; } vector<int> v; f...
[["-", 3, 4, 0, 16, 12, 23, 0, 16, 31, 13], ["+", 3, 4, 0, 16, 12, 23, 0, 16, 31, 22], ["-", 0, 11, 12, 2, 3, 4, 0, 16, 31, 13], ["+", 0, 11, 12, 2, 3, 4, 0, 16, 31, 22]]
1
199
#include <bits/stdc++.h> using namespace std; #define rep0(i, n) for (long long i = 0; i < (long long)(n); i++) #define rep1(i, n) for (long long i = 1; i <= (long long)(n); i++) #define all(v) v.begin(), v.end() typedef long long ll; #define out(i) cout << (i) << endl int main() { ll K, N, sum = 0; cin >> K >> N;...
#include <bits/stdc++.h> using namespace std; #define rep0(i, n) for (long long i = 0; i < (long long)(n); i++) #define rep1(i, n) for (long long i = 1; i <= (long long)(n); i++) #define all(v) v.begin(), v.end() typedef long long ll; #define out(i) cout << (i) << endl int main() { ll K, N, sum = 0; cin >> K >> N;...
[["+", 64, 9, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 0, 1, 0, 11, 12, 16, 12, 69, 28, 22], ["+", 0, 11, 12, 16, 12, 69, 341, 342, 0, 70], ["+", 0, 11, 12, 16, 12, 69, 341, 342, 0, 13], ["+", 0, 11, 12, 16, 12, 69, 341, 342, 0, 73]]
1
184
k,n=map(int,input.split()) l=list(map(int,input.split())) v=[k-l[-1]+l[0]] for i in range(n-1): v.append(l[i+1]-l[i]) v.sort() print(k-v[-1])
k,n=map(int,input().split()) l=list(map(int,input().split())) v=[k-l[-1]+l[0]] for i in range(n-1): v.append(l[i+1]-l[i]) v.sort() print(k-v[-1])
[["+", 0, 652, 63, 319, 500, 652, 3, 4, 0, 24], ["+", 0, 652, 63, 319, 500, 652, 3, 4, 0, 25]]
5
86
#include <iostream> using namespace std; int main() { int K, N; cin >> K >> N; int temp, a1; int len = 0; cin >> temp; a1 = temp; for (int i = 1; i < N; i++) { int a; cin >> a; if (abs(a - temp) > len) { len = abs(a - temp); } temp = a; } if (20 - temp + a1 > len) { cout...
#include <iostream> using namespace std; int main() { int K, N; cin >> K >> N; int temp, a1; int len = 0; cin >> temp; a1 = temp; for (int i = 1; i < N; i++) { int a; cin >> a; if (abs(a - temp) > len) { len = abs(a - temp); } temp = a; } if (K - temp + a1 > len) { cout ...
[["-", 15, 339, 51, 16, 31, 16, 31, 16, 31, 13], ["+", 15, 339, 51, 16, 31, 16, 31, 16, 31, 22], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 31, 22], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 33]]
1
124
k, n = map(int, input().split()) a = list(map(int, input().split())) space = [] for i in range(n - 1): s = a[i + 1] - a[i] space.append(s) space.append(k +a[1] - a[n - 1]) print(k - max(space))
k, n = map(int, input().split()) a = list(map(int, input().split())) space = [] for i in range(n - 1): s = a[i + 1] - a[i] space.append(s) space.append(k +a[0] - a[n - 1]) print(k - max(space))
[["-", 3, 4, 0, 657, 31, 657, 12, 206, 206, 612], ["+", 3, 4, 0, 657, 31, 657, 12, 206, 206, 612]]
5
93
k,n=map(int,input().split()) a=list(map(int,input().split())) a.sort() temp=a[0]+a[n-1] for i in range(1,n): temp=max(temp,a[i]-a[i-1]) print(k-temp)
k,n=map(int,input().split()) a=list(map(int,input().split())) a.sort() temp=a[0]+k-a[n-1] for i in range(1,n): temp=max(temp,a[i]-a[i-1]) print(k-temp)
[["+", 0, 1, 0, 662, 12, 657, 31, 657, 12, 22], ["+", 0, 656, 0, 1, 0, 662, 12, 657, 17, 33]]
5
85
k,n = map(int, input().split()) a = list(map(int, input().split())) dis = [0]*n for i in range(n): if i == n-1: dis[i] = k + a[0] - a[i] else: dis[i] = a[i+1] - a[0] print(k - max(dis))
k,n = map(int, input().split()) a = list(map(int, input().split())) dis = [0]*n for i in range(n): if i == n-1: dis[i] = k + a[0] - a[i] else: dis[i] = a[i+1] - a[i] print(k - max(dis))
[["-", 0, 1, 0, 662, 12, 657, 12, 206, 206, 612], ["+", 0, 1, 0, 662, 12, 657, 12, 206, 206, 22]]
5
98
k,n=map(int,input().split()) a=[int(i) for i in input().split()] dist = k-a[n-1]+a[0] for i in range(n-1): if a[i+1]-a[i] >= dist: dist = a[i+1]-a[i] print(dist)
k,n=map(int,input().split()) a=[int(i) for i in input().split()] dist = k-a[n-1]+a[0] for i in range(n-1): if a[i+1]-a[i] >= dist: dist = a[i+1]-a[i] print(k-dist)
[["+", 0, 1, 0, 652, 3, 4, 0, 657, 31, 22], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 33]]
5
91
k, n = map(int, input().split()) a = list(map(int, input().split())) d = 0 for i in range(n-1): d = (d, a[i+1] - a[i]) d = (d, k - a[-1] + a[0]) print(K - d)
k, n = map(int, input().split()) a = list(map(int, input().split())) d = 0 for i in range(n-1): d = max(d, a[i+1] - a[i]) d = max(d, k - a[-1] + a[0]) print(k - d)
[["+", 8, 196, 0, 1, 0, 662, 12, 652, 63, 22], ["+", 0, 656, 0, 1, 0, 662, 12, 652, 63, 22], ["-", 0, 1, 0, 652, 3, 4, 0, 657, 31, 22], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 31, 22]]
5
87
(k,n),*a = [list(map(int,i.split())) for i in open(0)] a.append(a[0]+k) print(k - min(a[i+1]-a[i] for i in range(n)))
(k,n),(*a,) = [list(map(int,i.split())) for i in open(0)] a.append(a[0]+k) print(k - max(a[i+1]-a[i] for i in range(n)))
[["+", 0, 1, 0, 662, 31, 684, 0, 289, 0, 24], ["+", 0, 1, 0, 662, 31, 684, 0, 289, 0, 21], ["+", 0, 1, 0, 662, 31, 684, 0, 289, 0, 25], ["-", 0, 652, 3, 4, 0, 657, 12, 652, 63, 22], ["+", 0, 652, 3, 4, 0, 657, 12, 652, 63, 22]]
5
68
/* URL_HERE */ /* */ #ifdef _WIN32 #pragma warning(disable : 4996) #endif #include <algorithm> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unordered_map> using namespace std; FILE *_fin = stdin; FILE *_fout = stdout; #define PI 3.141592653589793238462643383279502884197169399...
/* URL_HERE */ /* */ #ifdef _WIN32 #pragma warning(disable : 4996) #endif #include <algorithm> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unordered_map> using namespace std; FILE *_fin = stdin; FILE *_fout = stdout; #define PI 3.141592653589793238462643383279502884197169399...
[["-", 8, 9, 0, 57, 64, 1, 0, 11, 31, 22], ["-", 8, 9, 0, 57, 64, 1, 0, 11, 17, 32], ["+", 8, 9, 0, 57, 64, 1, 0, 11, 17, 32], ["+", 8, 9, 0, 57, 64, 1, 0, 11, 12, 22]]
1
912
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ios::sync_with_stdio(0); cin.tie(0); int k, n; cin >> k >> n; int seg[n]; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { if (i == n - 1) { seg[i] = k - a[i]; } el...
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ios::sync_with_stdio(0); cin.tie(0); int k, n; cin >> k >> n; int seg[n]; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { if (i == n - 1) { seg[i] = k + a[0] - a[i]; ...
[["+", 0, 1, 0, 11, 12, 16, 31, 16, 17, 72], ["+", 0, 11, 12, 16, 31, 16, 12, 69, 28, 22], ["+", 12, 16, 31, 16, 12, 69, 341, 342, 0, 70], ["+", 12, 16, 31, 16, 12, 69, 341, 342, 0, 13], ["+", 12, 16, 31, 16, 12, 69, 341, 342, 0, 73]]
1
178
// https://ei1333.github.io/luzhiled/ // http://beet-aizu.hatenablog.com/entry/2017/01/04/113233 // http://www.prefield.com/algorithm/ #include <bits/stdc++.h> constexpr char bn = '\n'; using namespace std; using ll = long long; using ld = long double; using vl = vector<ll>; using vd = vector<ld>; using vs = vector<str...
// https://ei1333.github.io/luzhiled/ // http://beet-aizu.hatenablog.com/entry/2017/01/04/113233 // http://www.prefield.com/algorithm/ #include <bits/stdc++.h> constexpr char bn = '\n'; using namespace std; using ll = long long; using ld = long double; using vl = vector<ll>; using vd = vector<ld>; using vs = vector<str...
[["-", 0, 14, 8, 9, 0, 43, 49, 50, 51, 22], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13]]
1
922
// https://ei1333.github.io/luzhiled/ // http://beet-aizu.hatenablog.com/entry/2017/01/04/113233 // http://www.prefield.com/algorithm/ #include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using vl = vector<ll>; using vd = vector<ld>; using vs = vector<string>; using vb = vector<bo...
// https://ei1333.github.io/luzhiled/ // http://beet-aizu.hatenablog.com/entry/2017/01/04/113233 // http://www.prefield.com/algorithm/ #include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using vl = vector<ll>; using vd = vector<ld>; using vs = vector<string>; using vb = vector<bo...
[["+", 0, 1, 0, 2, 3, 4, 0, 16, 31, 22], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 17, 33]]
1
806
k,n=map(int,input().split()) a=list(map(int,input().split())) a.append(a[-1]+k) l=0 for i in range(n): l=max(l,a[i+1]-a[i]) s=k-l print(s)
k,n=map(int,input().split()) a=list(map(int,input().split())) a.append(a[0]+k) l=0 for i in range(n): l=max(l,a[i+1]-a[i]) s=k-l print(s)
[["-", 3, 4, 0, 657, 31, 206, 206, 664, 17, 33], ["-", 3, 4, 0, 657, 31, 206, 206, 664, 28, 612], ["+", 0, 652, 3, 4, 0, 657, 31, 206, 206, 612]]
5
83
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int k, n; cin >> k >> n; int itv_max = 0, a0, a = 0, b; cin >> a0; for (int i = 1; i < n; ++i) { cin >> b; itv_max = max(itv_max, b - a); a = b; } itv_max = max(itv_max, k + a0 - a); ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int k, n; cin >> k >> n; int itv_max = 0, a0, a = 0, b; cin >> a0; a = a0; for (int i = 1; i < n; ++i) { cin >> b; itv_max = max(itv_max, b - a); a = b; } itv_max = max(itv_max, k + ...
[["+", 0, 14, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 14, 8, 9, 0, 1, 0, 11, 12, 22], ["+", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35]]
1
117
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++) using namespace std; template <class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, const T &b...
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++) using namespace std; template <class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, const T &b...
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 31, 22], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 33]]
1
217
k, n = map(int, input().split()) a = list(map(int, input().split())) a.append(a[0] + k) m = [] for i in range(n): m.append(m, a[i+1] - a[i]) print(k - max(m))
k, n = map(int, input().split()) a = list(map(int, input().split())) a.append(a[0] + k) m = [] for i in range(n): m.append(a[i+1] - a[i]) print(k - max(m))
[["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 22], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 21]]
5
83
k,n=map(int,input().split()) houses=list(map(int,input().split())) houses.sort() maxx=-float('INF') for i in range(n-1): if houses[i+1]-houses[i]>maxx: maxx=houses[i+1]-houses[i] maxx=max([maxx,k-(houses[-1]-houses[0])]) print(maxx)
k,n=map(int,input().split()) houses=list(map(int,input().split())) houses.sort() maxx=-float('INF') for i in range(n-1): if houses[i+1]-houses[i]>maxx: maxx=houses[i+1]-houses[i] maxx=max([maxx,k-(houses[-1]-houses[0])]) print(k-maxx)
[["+", 0, 1, 0, 652, 3, 4, 0, 657, 31, 22], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 33]]
5
112
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); #ifdef LOCAL freopen("in.txt", "r", stdin); #endif // LOCAL int k, n; cin >> k >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } int max_dist = 0; for (int i = 1; i < n; i++) { max_d...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); #ifdef LOCAL freopen("in.txt", "r", stdin); #endif // LOCAL int k, n; cin >> k >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } int max_dist = 0; for (int i = 1; i < n; i++) { max_d...
[["+", 0, 1, 0, 16, 31, 16, 12, 23, 0, 24], ["+", 0, 16, 31, 16, 12, 23, 0, 16, 31, 22], ["+", 0, 16, 31, 16, 12, 23, 0, 16, 17, 33], ["+", 0, 1, 0, 16, 31, 16, 12, 23, 0, 25]]
1
148
# import sys # import math # import itertools # from collections import deque # from collections import defaultdict # import heapq # import copy # import bisect # import numpy as np # from scipy.special import comb # def my_input(): return sys.stdin.readline().rstrip() # sys.setrecursionlimit(100000) # INF = 100100100...
# import sys # import math # import itertools # from collections import deque # from collections import defaultdict # import heapq # import copy # import bisect # import numpy as np # from scipy.special import comb # def my_input(): return sys.stdin.readline().rstrip() # sys.setrecursionlimit(100000) # INF = 100100100...
[["-", 0, 1, 0, 662, 12, 657, 31, 657, 31, 22], ["+", 0, 1, 0, 662, 12, 657, 31, 657, 31, 22]]
5
146
#include <bits/stdc++.h> using namespace std; int main() { int k, n; cin >> k >> n; int A[n]; for (int i = 0; i < n; i++) { cin >> A[i]; } int sum = 0; int right = A[1] - A[0]; int rightcnt = 0; int left = 20 - A[n - 1] + A[0]; int leftcnt = n; int x = 0; for (int i = 0; i < n - 1; i++) { ...
#include <bits/stdc++.h> using namespace std; int main() { int k, n; cin >> k >> n; int A[n]; for (int i = 0; i < n; i++) { cin >> A[i]; } int sum = 0; int right = A[1] - A[0]; int rightcnt = 0; int left = k - A[n - 1] + A[0]; int leftcnt = n; int x = 0; for (int i = 0; i < n - 1; i++) { ...
[["-", 0, 43, 49, 50, 51, 16, 31, 16, 31, 13], ["+", 0, 43, 49, 50, 51, 16, 31, 16, 31, 22]]
1
182
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll k = 0, n = 0; cin >> k >> n; vector<int> v(n, 0); for (int i = 0; i < n; i++) { cin >> v[i]; } vector<ll> dist; ll prev = v[0]; for (int i = 1; i < n;...
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll k = 0, n = 0; cin >> k >> n; vector<int> v(n, 0); for (int i = 0; i < n; i++) { cin >> v[i]; } vector<ll> dist; ll prev = v[0]; for (int i = 1; i < n;...
[["+", 0, 1, 0, 2, 3, 4, 0, 16, 17, 72], ["+", 0, 2, 3, 4, 0, 16, 12, 69, 28, 22], ["+", 3, 4, 0, 16, 12, 69, 341, 342, 0, 70], ["+", 3, 4, 0, 16, 12, 69, 341, 342, 0, 13], ["+", 3, 4, 0, 16, 12, 69, 341, 342, 0, 73]]
1
210
K,N=map(int,input().split()) A=list(map(int,input().split())) A.sort() dist=[A[0]+K-A[-1]]+[A[i]-A[i-1] for i in range(1,N)] print(k-max(dist))
K,N=map(int,input().split()) A=list(map(int,input().split())) A.sort() dist=[A[0]+K-A[-1]]+[A[i]-A[i-1] for i in range(1,N)] print(K-max(dist))
[["-", 0, 1, 0, 652, 3, 4, 0, 657, 31, 22], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 31, 22]]
5
86
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < (int)(n); ++i) using namespace std; int A[2 * 100000]; int main() { int K, N; cin >> K >> N; REP(i, N) cin >> A[i]; int maximum = 0; REP(i, N - 1) maximum = max(maximum, A[i + 1] - A[i]); cout << max(maximum, K - A[N - 1] + A[0]) << endl; }
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < (int)(n); ++i) using namespace std; int A[2 * 100000]; int main() { int K, N; cin >> K >> N; REP(i, N) cin >> A[i]; int maximum = 0; REP(i, N - 1) maximum = max(maximum, A[i + 1] - A[i]); cout << K - max(maximum, K - A[N - 1] + A[0]) << endl...
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 31, 22], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 33]]
1
108
K,N=map(int,input().split()) A=list(map(int,input().split())) for i in range(1,N): dis=0 tmp=A[i]-A[i-1] dis=max(dis,tmp) tmp=K+A[0]-A[N-1] dis=max(dis,tmp) print(K-dis)
K,N=map(int,input().split()) A=list(map(int,input().split())) dis=0 for i in range(1,N): tmp=A[i]-A[i-1] dis=max(dis,tmp) tmp=K+A[0]-A[N-1] dis=max(dis,tmp) print(K-dis)
[["+", 36, 36, 0, 656, 0, 1, 0, 662, 31, 22], ["+", 36, 36, 0, 656, 0, 1, 0, 662, 0, 32], ["+", 36, 36, 0, 656, 0, 1, 0, 662, 12, 612], ["-", 0, 7, 8, 196, 0, 1, 0, 662, 31, 22], ["-", 0, 7, 8, 196, 0, 1, 0, 662, 0, 32], ["-", 0, 7, 8, 196, 0, 1, 0, 662, 12, 612]]
5
96
K, N = map(int, input().split()) A = list(map(int, input().split())) longest = 0 for i in range(N): longest = max(longest, A[i + 1] - A[i]) longest = max(longest, A[0] + K - A[-1]) print(K - longest)
K, N = map(int, input().split()) A = list(map(int, input().split())) longest = 0 for i in range(N - 1): longest = max(longest, A[i + 1] - A[i]) longest = max(longest, A[0] + K - A[-1]) print(K - longest)
[["+", 0, 7, 12, 652, 3, 4, 0, 657, 17, 33], ["+", 0, 7, 12, 652, 3, 4, 0, 657, 12, 612]]
5
87
def main(): k, n = map(int, input().split()) As = list(map(int, input().split())) diffs = [0]*n for i in range(n): if i == n-1: diffs[i] = k - As[i] else: diffs[i] = As[i+1] - As[i] diffs.remove(max(diffs)) ans = sum(diffs) print(ans) if __name__ ==...
def main(): k, n = map(int, input().split()) As = list(map(int, input().split())) diffs = [0]*n for i in range(n): if i == n-1: diffs[i] = k+As[0] - As[i] else: diffs[i] = As[i+1] - As[i] diffs.remove(max(diffs)) ans = sum(diffs) print(ans) if __nam...
[["+", 0, 1, 0, 662, 12, 657, 31, 657, 17, 72], ["+", 0, 662, 12, 657, 31, 657, 12, 206, 51, 22], ["+", 0, 662, 12, 657, 31, 657, 12, 206, 0, 70], ["+", 0, 662, 12, 657, 31, 657, 12, 206, 206, 612], ["+", 0, 662, 12, 657, 31, 657, 12, 206, 0, 73]]
5
118
int main() { int a, b, i, max = 0, ans; int c[200000], d[200000]; scanf("%d%d\n", &a, &b); for (i = 0; i < b; i++) scanf("%d", &c[i]); for (i = 0; i < b - 1; i++) { d[i] = c[i + 1] - c[i]; if (max < d[i]) max = d[i]; } if (max < c[0] + a - c[b - 1]) max = c[0] + a - c[b - 1]; ans =...
int main() { int a, b, i, max = 0, ans; int c[200000], d[200000]; scanf("%d%d\n", &a, &b); for (i = 0; i < b; i++) scanf("%d", &c[i]); for (i = 0; i < b - 1; i++) { d[i] = c[i + 1] - c[i]; if (max < d[i]) max = d[i]; } if (max < c[0] + a - c[b - 1]) max = c[0] + a - c[b - 1]; ans =...
[["+", 8, 9, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 8, 9, 0, 1, 0, 11, 12, 16, 17, 33]]
0
170
#include <stdio.h> int main(void) { int k, n; scanf("%d", &k); scanf("%d", &n); int a[n], i, max; for (i = 0; i < n; i++) scanf("%d", &a[i]); max = a[0] + (k - a[n - 1]); for (i = 1; i < n; i++) if (a[i] - a[i - 1] > max) max = a[i] - a[i - 1]; printf("%d", max); return 0; }
#include <stdio.h> int main(void) { int k, n; scanf("%d", &k); scanf("%d", &n); int a[n], i, max; for (i = 0; i < n; i++) scanf("%d", &a[i]); max = a[0] + (k - a[n - 1]); for (i = 1; i < n; i++) if (a[i] - a[i - 1] > max) max = a[i] - a[i - 1]; printf("%d", k - max); return 0; }
[["+", 0, 1, 0, 2, 3, 4, 0, 16, 31, 22], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 17, 33]]
0
143
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define Rep(i, n) for (intl i = 0; i < (intl)(n); i++) #define Rep1(i, n) for (intl i = 1; i < (intl)(n) + 1; i++) #define vec vector #define fi first #define se second #define pushb push_back #define popb pop_back #define SortA(v) sort(v.begin(), v.e...
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define Rep(i, n) for (intl i = 0; i < (intl)(n); i++) #define Rep1(i, n) for (intl i = 1; i < (intl)(n) + 1; i++) #define vec vector #define fi first #define se second #define pushb push_back #define popb pop_back #define SortA(v) sort(v.begin(), v.e...
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 39, 78], ["+", 8, 9, 0, 1, 0, 16, 12, 16, 31, 22], ["+", 8, 9, 0, 1, 0, 16, 12, 16, 17, 33], ["-", 0, 1, 0, 16, 12, 66, 28, 23, 0, 24], ["-", 12, 66, 28, 23, 0, 2, 3, 4, 0, 25]]
1
258
k,n = map(int, input().split()) a = list(map(int, input().split())) l = [0]*n l[-1] = k-a[-1] for i in range(n-1): l[i] = a[i+1] - a[i] print(sum(sorted(l)[:-1]))
k,n = map(int, input().split()) a = list(map(int, input().split())) l = [0]*n l[-1] = k+a[0] - a[-1] for i in range(n-1): l[i] = a[i+1]-a[i] print(sum(sorted(l)[:-1]))
[["+", 0, 1, 0, 662, 12, 657, 31, 657, 17, 72], ["+", 0, 662, 12, 657, 31, 657, 12, 206, 51, 22], ["+", 0, 662, 12, 657, 31, 657, 12, 206, 0, 70], ["+", 0, 662, 12, 657, 31, 657, 12, 206, 206, 612], ["+", 0, 662, 12, 657, 31, 657, 12, 206, 0, 73]]
5
94
#C k, n = [int(_) for _ in input().split()] a = [int(_) for _ in input().split()] b = [] for i in range(len(a)): if i == 0: b.append(k - a[len(a)] + a[0]) else: b.append(a[i] - a[i - 1]) print(k - max(b))
#C k, n = [int(_) for _ in input().split()] a = [int(_) for _ in input().split()] b = [] for i in range(len(a)): if i == 0: b.append(k - a[len(a) - 1] + a[0]) else: b.append(a[i] - a[i - 1]) print(k - max(b))
[["+", 0, 657, 31, 657, 12, 206, 206, 657, 17, 33], ["+", 0, 657, 31, 657, 12, 206, 206, 657, 12, 612]]
5
105
#!/usr/bin/env python def input(): return sys.stdin.readline()[:-1] def main(): K, N = map(int, input().split()) A = tuple(map(int, input().split())) tmp = 0 for i in range(N-1): tmp = max(tmp, A[i+1] - A[i]) tmp = max(tmp, (K-A[N-1]+A[0])) print(K-tmp) if __name__ == '__main__': ...
#!/usr/bin/env python import sys def input(): return sys.stdin.readline()[:-1] def main(): K, N = map(int, input().split()) A = tuple(map(int, input().split())) tmp = 0 for i in range(N-1): tmp = max(tmp, A[i+1] - A[i]) tmp = max(tmp, (K-A[N-1]+A[0])) print(K-tmp) if __name__ == '...
[["+", 36, 36, 36, 36, 0, 656, 0, 596, 0, 487], ["+", 36, 36, 0, 656, 0, 596, 141, 673, 0, 22]]
5
126
#include <bits/stdc++.h> using namespace std; int main() { int k, n; cin >> k >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; int maxi = -1, prev = 0; for (int i = 0; i < n; i++) { maxi = max(maxi, abs(prev - a[i])); prev = a[i]; } maxi = max(maxi, k - a[n - 1] - a[0]); cout << k...
#include <bits/stdc++.h> using namespace std; int main() { int k, n; cin >> k >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; int maxi = -1, prev = 0; for (int i = 0; i < n; i++) { maxi = max(maxi, abs(prev - a[i])); prev = a[i]; } maxi = max(maxi, k - a[n - 1] + a[0]); cout << k...
[["-", 0, 11, 12, 2, 3, 4, 0, 16, 17, 33], ["+", 0, 11, 12, 2, 3, 4, 0, 16, 17, 72]]
1
128
K, N = map(int, input().split()) A = list(map(int, input().split())) A.sort() m = 0 for i in range(1, len(A)): if A[i]-A[i-1]>m: m=A[i]-A[i-1] if K-A[-1]+A[1]>m: print(A[-1]-A[1]) else: print(K-m)
K, N = map(int, input().split()) A = list(map(int, input().split())) A.sort() m = 0 for i in range(1, len(A)): if A[i]-A[i-1]>m: m=A[i]-A[i-1] if K-A[-1]+A[0]>m: print(A[-1]-A[0]) else: print(K-m)
[["-", 0, 57, 15, 666, 0, 657, 12, 206, 206, 612], ["+", 0, 57, 15, 666, 0, 657, 12, 206, 206, 612], ["-", 0, 652, 3, 4, 0, 657, 12, 206, 206, 612], ["+", 0, 652, 3, 4, 0, 657, 12, 206, 206, 612]]
5
119
k,n = list(map(int, input().split())) a_vector = list(map(int, input().split())) tonari_dif = 0 for i in range(1,n): tonari_dif = max(tonari_dif, a_vector[i] - a_vector[i-1]) true_tonari_dif = max(tonari_dif, a_vector[0]+(200-a_vector[-1])) print(k-true_tonari_dif)
k,n = list(map(int, input().split())) a_vector = list(map(int, input().split())) tonari_dif = 0 for i in range(1,n): tonari_dif = max(tonari_dif, a_vector[i] - a_vector[i-1]) # print(tonari_dif) true_tonari_dif = max(tonari_dif, a_vector[0]+(k-a_vector[-1])) print(k-true_tonari_dif)
[["-", 3, 4, 0, 657, 12, 23, 0, 657, 31, 612], ["+", 3, 4, 0, 657, 12, 23, 0, 657, 31, 22]]
5
94
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) int k, n, a, b, c, ans; int main() { scanf("%d%d", &k, &n); rep(i, n) { scanf("%d", &b); if (i) ans = max(ans, b - c); else a = b; c = b; } ans = max(ans, a + k - c); printf("%d\n", ans); ...
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) int k, n, a, b, c, ans; int main() { scanf("%d%d", &k, &n); rep(i, n) { scanf("%d", &b); if (i) ans = max(ans, b - c); else a = b; c = b; } ans = max(ans, a + k - c); printf("%d\n", k - an...
[["+", 0, 1, 0, 2, 3, 4, 0, 16, 31, 22], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 17, 33]]
1
111
#include "bits/stdc++.h" #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; int main() { int k, n, kmax, sa, i, j; kmax = 0; sa = 0; cin >> k >> n; int a[n + 1]; rep(i, n) cin >> a[i]; kmax = k - a[n - 1]; rep(j, n - 1) { // cout <<...
#include "bits/stdc++.h" #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; int main() { int k, n, kmax, sa, i, j; kmax = 0; sa = 0; cin >> k >> n; int a[n + 1]; rep(i, n) cin >> a[i]; kmax = k - a[n - 1] + a[0]; rep(j, n - 1) { // ...
[["+", 8, 9, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 0, 1, 0, 11, 12, 16, 12, 69, 28, 22], ["+", 0, 11, 12, 16, 12, 69, 341, 342, 0, 70], ["+", 0, 11, 12, 16, 12, 69, 341, 342, 0, 13], ["+", 0, 11, 12, 16, 12, 69, 341, 342, 0, 73]]
1
146
# Traveling Salesman around Lake https://atcoder.jp/contests/abc160/tasks/abc160_c N,K= map(int, input().split()) Travel_List=list(map(int,input().split())) for i in range(K): Travel_List.append(Travel_List[i]+N) Answer =0 for i in range(K): print(i) Temp = Travel_List[i+K-1]-Travel_List[i] if (i==0)...
# Traveling Salesman around Lake https://atcoder.jp/contests/abc160/tasks/abc160_c N,K= map(int, input().split()) Travel_List=list(map(int,input().split())) for i in range(K): Travel_List.append(Travel_List[i]+N) Answer =0 for i in range(K): Temp = Travel_List[i+K-1]-Travel_List[i] if (i==0) or (Temp<Ans...
[["-", 0, 7, 8, 196, 0, 1, 0, 652, 63, 22], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 24], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 22], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 25]]
5
103
k,n = gets.chomp.split(" ").map(&:to_i) a = gets.chomp.split(" ").map(&:to_i) max = 0 (n-1).times do |i| max = a[i+1] - a[i] if max < a[i+1] - a[i] end max = a[0] + k - a[n-1] if max < a[0] + k - a[n-1] puts max
k,n = gets.chomp.split(" ").map(&:to_i) a = gets.chomp.split(" ").map(&:to_i) max = 0 (n-1).times do |i| max = a[i+1] - a[i] if max < a[i+1] - a[i] end max = a[0] + k - a[n-1] if max < a[0] + k - a[n-1] puts k - max
[["+", 0, 493, 0, 652, 3, 4, 0, 738, 31, 22], ["+", 0, 493, 0, 652, 3, 4, 0, 738, 17, 33]]
4
113
k, n = map(int, input().split()) a = list(map(int, input().split())) m = 0 for i in range(n-1): m = max(m, a[i+1] - a[i]) m = max(m, a[0] + k - a[n-1]) print(m)
k, n = map(int, input().split()) a = list(map(int, input().split())) m = 0 for i in range(n-1): m = max(m, a[i+1] - a[i]) m = max(m, a[0] + k - a[n-1]) print(k - m)
[["+", 0, 1, 0, 652, 3, 4, 0, 657, 31, 22], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 33]]
5
88
#include <iostream> using namespace std; int n, k; int main() { int mx = 0, pre = 0, st; cin >> k >> n; cin >> pre; st = pre; for (int i = 2; i <= n; i++) { int now; cin >> now; if (now - pre > mx) mx = now - pre; pre = now; } if (st - pre > mx) mx = st - pre; cout << k - mx; ...
#include <iostream> using namespace std; int n, k; int main() { int mx = 0, pre = 0, st; cin >> k >> n; cin >> pre; st = pre; for (int i = 2; i <= n; i++) { int now; cin >> now; if (now - pre > mx) mx = now - pre; pre = now; } if (st - pre + k > mx) mx = k + st - pre; cout << k...
[["+", 0, 57, 15, 339, 51, 16, 31, 16, 17, 72], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 12, 22], ["+", 64, 1, 0, 11, 12, 16, 31, 16, 31, 22], ["+", 64, 1, 0, 11, 12, 16, 31, 16, 17, 72]]
1
106
K, N = map(int, input().split()) L = list(map(int, input().split())) sa = [L[i+1]-L[i] for i in range(N-1)] sa += K-L[N-1]+L[0] ans = K-max(sa) print(ans)
K, N = list(map(int, input().split())) L = list(map(int, input().split())) sa = [L[i+1]-L[i] for i in range(N-1)] sa += [K-L[N-1]+L[0]] ans = K-max(sa) print(ans)
[["+", 0, 656, 0, 1, 0, 662, 12, 652, 63, 22], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 24], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 25], ["+", 0, 656, 0, 1, 0, 677, 12, 634, 0, 70], ["+", 0, 677, 12, 634, 0, 657, 12, 206, 0, 73]]
5
84
import itertools import math import fractions import functools k, n = map(int, input().split()) a = list(map(int, input().split())) sub = [0] * n for i in range(n-1): sub[i] = a[i+1]-a[i] sub[n-1] = k - a[n-1] + a[0] print(sub) print(k-max(sub))
import itertools import math import fractions import functools k, n = map(int, input().split()) a = list(map(int, input().split())) sub = [0] * n for i in range(n-1): sub[i] = a[i+1]-a[i] sub[n-1] = k - a[n-1] + a[0] print(k-max(sub))
[["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 22], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 25], ["-", 36, 36, 0, 656, 0, 1, 0, 652, 63, 22], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 24]]
5
107
#include <iostream> #include <vector> using namespace std; int main() { int k, n, ans; int max = 0; ans = 0; cin >> k >> n; vector<int> v(n); vector<int> v2(n); for (int i = 0; i < n; i++) { cin >> v[i]; } for (int j = 0; j < n - 1; j++) { v2[j] = v[j + 1] - v[j]; } v2[n - 1] = (20 -...
#include <iostream> #include <vector> using namespace std; int main() { int k, n, ans; int max = 0; ans = 0; cin >> k >> n; vector<int> v(n); vector<int> v2(n); for (int i = 0; i < n; i++) { cin >> v[i]; } for (int j = 0; j < n - 1; j++) { v2[j] = v[j + 1] - v[j]; } v2[n - 1] = (k - ...
[["-", 0, 11, 12, 16, 31, 23, 0, 16, 31, 13], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 31, 22]]
1
189
#include <bits/stdc++.h> using namespace std; int main() { int k, n; cin >> k >> n; int a[n]; long long sum = 0; for (int i = 0; i < n; i++) { cin >> a[i]; } int mm = 0; for (int i = 1; i < n; ++i) { if (mm < a[i] - a[i - 1]) mm = a[i] - a[i - 1]; } if (mm < k - (a[n - 1] - a[0])...
#include <bits/stdc++.h> using namespace std; int main() { int k, n; cin >> k >> n; int a[n]; long long sum = 0; for (int i = 0; i < n; i++) { cin >> a[i]; } int mm = 0; for (int i = 1; i < n; ++i) { if (mm < a[i] - a[i - 1]) mm = a[i] - a[i - 1]; } if (mm < k - (a[n - 1] - a[0])...
[["-", 0, 11, 12, 16, 12, 23, 0, 16, 17, 72], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 17, 33]]
1
156
k, n = map(int, input().split()) A = input().split() a = [int(i) for i in A] kyori = k + a[0] - a[n-1] for i in range(n): if kyori < a[i] - a[i-1]: kyori = a[i] - a[i-1] print(kyori)
k, n = map(int, input().split()) A = input().split() a = [int(i) for i in A] kyori = k + a[0] - a[n-1] for i in range(n): if kyori < a[i] - a[i-1]: kyori = a[i] - a[i-1] print(k-kyori)
[["+", 0, 1, 0, 652, 3, 4, 0, 657, 31, 22], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 33]]
5
92
k, n = map(int, input().split()) array = list(map(int,input().split())) max_length = 0 sum_length = 0 for i in range(n - 1): length = array[i + 1] - array[i] sum_length += length if length > max_length: max_length = length last_length = k - array[n - 1] sum_length += last_length max_length = max(max_length, l...
k, n = map(int, input().split()) array = list(map(int,input().split())) max_length = 0 sum_length = 0 for i in range(n - 1): length = array[i + 1] - array[i] sum_length += length if length > max_length: max_length = length last_length = k - array[n - 1] + array[0] sum_length += last_length max_length = max(ma...
[["+", 0, 656, 0, 1, 0, 662, 12, 657, 17, 72], ["+", 0, 1, 0, 662, 12, 657, 12, 206, 51, 22], ["+", 0, 1, 0, 662, 12, 657, 12, 206, 0, 70], ["+", 0, 1, 0, 662, 12, 657, 12, 206, 206, 612], ["+", 0, 1, 0, 662, 12, 657, 12, 206, 0, 73]]
5
100
X = input().split() K = int(X[0]) N = int(X[1]) Y = input().split() Z = [] for i in range(N): Z.append(int(Y[i])) result = Z[0]+ K - Z[N-1] for i in range(N): if result < Z[i] - Z[i-1]: result = Z[i] - Z[i -1] i = i + 1 print(result)
X = input().split() K = int(X[0]) N = int(X[1]) Y = input().split() Z = [] for i in range(N): Z.append(int(Y[i])) result = Z[0]+ K - Z[N-1] for i in range(N): if result < Z[i] - Z[i-1]: result = Z[i] - Z[i -1] i = i + 1 print(K - result)
[["+", 0, 1, 0, 652, 3, 4, 0, 657, 31, 22], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 33]]
5
120
#include <algorithm> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; typedef long long ll; typedef vector<int> vec; typedef vector<vector<int>> mat; using P =...
#include <algorithm> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; typedef long long ll; typedef vector<int> vec; typedef vector<vector<int>> mat; using P =...
[["-", 0, 7, 10, 43, 49, 50, 51, 16, 12, 13], ["+", 0, 7, 10, 43, 49, 50, 51, 16, 12, 13]]
1
345
K, N = list(map(int, input().split(' '))) A = list(map(int, input().split(' '))) A.extend([K]) diff = [] for i in range(N): diff.append(A[i+1] - A[i]) sum_d = sum(sorted(diff)[:N-1]) print(sum_d)
K, N = list(map(int, input().split(' '))) A = list(map(int, input().split(' '))) A.extend([K+A[0]]) diff = [] for i in range(N): diff.append(A[i+1] - A[i]) sum_d = sum(sorted(diff)[:N-1]) print(sum_d)
[["+", 0, 652, 3, 4, 0, 634, 0, 657, 17, 72], ["+", 3, 4, 0, 634, 0, 657, 12, 206, 51, 22], ["+", 3, 4, 0, 634, 0, 657, 12, 206, 0, 70], ["+", 3, 4, 0, 634, 0, 657, 12, 206, 206, 612], ["+", 3, 4, 0, 634, 0, 657, 12, 206, 0, 73]]
5
97
k,n = map(int,input().split()) a = list(map(int,input().split())) ans = 0 a.reverse() for i in range(n-1): a[i]-=a[i+1]-a[n-1] a.append(k-sum(a)) ans = max(a) print(ans)
k,n = map(int,input().split()) a = list(map(int,input().split())) ans = 0 a.reverse() for i in range(n-1): a[i]-=a[i+1] a[n-1] = 0 a.append(k-sum(a)) ans = k-max(a) print(ans)
[["-", 8, 196, 0, 1, 0, 677, 12, 657, 17, 33], ["+", 36, 36, 0, 656, 0, 1, 0, 662, 0, 32], ["+", 36, 36, 0, 656, 0, 1, 0, 662, 12, 612], ["+", 0, 656, 0, 1, 0, 662, 12, 657, 31, 22], ["+", 0, 656, 0, 1, 0, 662, 12, 657, 17, 33]]
5
90
#include <bits/stdc++.h> #define watch(x) \ cerr << "at line " << __LINE__ << ", " << #x << " = " << x << "\n" using namespace std; int main() { int n, k; cin >> k >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n)...
#include <bits/stdc++.h> #define watch(x) \ cerr << "at line " << __LINE__ << ", " << #x << " = " << x << "\n" using namespace std; int main() { int n, k; cin >> k >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n)...
[["-", 0, 2, 3, 4, 0, 16, 31, 16, 31, 13], ["+", 0, 2, 3, 4, 0, 16, 31, 16, 31, 22]]
1
185
k, n = map(int, input().split()) a = list(map(int, input().split())) distance = [] for i in range(len(a) - 1): distance.append(a[i + 1] - a[i]) distance.append(k - a[n - 1] + a[0]) print(max(distance))
k, n = map(int, input().split()) a = list(map(int, input().split())) distance = [] for i in range(len(a) - 1): distance.append(a[i + 1] - a[i]) distance.append(k - a[n - 1] + a[0]) print(k - max(distance))
[["+", 0, 1, 0, 652, 3, 4, 0, 657, 31, 22], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 33]]
5
91
K,N=map(int,input().split()) A=[int(x) for x in input().split()] m=[] if N==2: if A[1]-A[0]<=K/2: ans=A[1]-A[0] else: ans=K+A[0]-A[1] else: for i in range(N-2): m.append(A[i+1]-A[i]) m.append(K+A[0]-A[N-1]) ans=K-max(m) print(ans)
K,N=map(int,input().split()) A=[int(x) for x in input().split()] m=[] if N==2: if A[1]-A[0]<=K/2: ans=A[1]-A[0] else: ans=K+A[0]-A[1] else: for i in range(N-1): m.append(A[i+1]-A[i]) m.append(K+A[0]-A[N-1]) ans=K-max(m) print(ans)
[["-", 0, 7, 12, 652, 3, 4, 0, 657, 12, 612], ["+", 0, 7, 12, 652, 3, 4, 0, 657, 12, 612]]
5
142
n,k=map(int,input().split()) max=0 l=list(map(int,input().split())) for i in range(k-1): s=l[i+1]-l[i] if s>max: max=s s=n-l[-1]+l[0] if s>max: max=s print(max)
n,k=map(int,input().split()) max=0 l=list(map(int,input().split())) for i in range(k-1): s=l[i+1]-l[i] if s>max: max=s s=n-l[-1]+l[0] if s>max: max=s print(n-max)
[["+", 0, 1, 0, 652, 3, 4, 0, 657, 31, 22], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 33]]
5
93
inputs = [int(i) for i in input().split()] K,N = inputs[0],inputs[1] input_lines = [int(i) for i in input().split()] max_range = input_lines[0]+(K-input_lines[-1]) for i in range(N): if i!=N-1: torange = input_lines[i+1]-input_lines[i] if torange>max_range: max_range = torange print(ma...
inputs = [int(i) for i in input().split()] K,N = inputs[0],inputs[1] input_lines = [int(i) for i in input().split()] max_range = input_lines[0]+(K-input_lines[-1]) for i in range(N): if i!=N-1: torange = input_lines[i+1]-input_lines[i] if torange>max_range: max_range = torange print(K-...
[["+", 0, 1, 0, 652, 3, 4, 0, 657, 31, 22], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 33]]
5
105
#include <bits/stdc++.h> using namespace std; #define for_(i, s, e) for (int i = s; i < e; i++) #define for__(i, s, e) for (ull i = s; i < e; i++) #define SSTR(x) \ static_cast<std::ostringstream &>((std::ostringstream() << std::dec << x)) \ .str(...
#include <bits/stdc++.h> using namespace std; #define for_(i, s, e) for (int i = s; i < e; i++) #define for__(i, s, e) for (ull i = s; i < e; i++) #define SSTR(x) \ static_cast<std::ostringstream &>((std::ostringstream() << std::dec << x)) \ .str(...
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 31, 22], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 33]]
1
207
import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); int N = stdIn.nextInt(); int K = stdIn.nextInt(); ArrayList<Integer> A = new ArrayList<Integer>(); for (int i = ...
import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); int K = stdIn.nextInt(); int N = stdIn.nextInt(); ArrayList<Integer> A = new ArrayList<Integer>(); for (int i =...
[["-", 0, 195, 8, 196, 0, 503, 49, 200, 141, 22], ["+", 0, 195, 8, 196, 0, 503, 49, 200, 141, 22], ["-", 8, 196, 0, 1, 0, 11, 12, 492, 141, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 492, 141, 22]]
3
284
#include <algorithm> #include <cmath> //abs()かfabs()で少数絶対値 #include <cstdlib> //abs()で整数絶対値 #include <iomanip> //cout<<setw(数字) で空白による桁揃え #include <iostream> //cout<<right で右揃え #include <queue> #include <string> #include <vector> using namespace std; using ll = long long int; int main(void) { int K, N; cin >...
#include <algorithm> #include <cmath> //abs()かfabs()で少数絶対値 #include <cstdlib> //abs()で整数絶対値 #include <iomanip> //cout<<setw(数字) で空白による桁揃え #include <iostream> //cout<<right で右揃え #include <queue> #include <string> #include <vector> using namespace std; using ll = long long int; int main(void) { int K, N; cin >...
[["-", 8, 9, 0, 7, 15, 16, 12, 16, 12, 13], ["+", 8, 9, 0, 7, 15, 16, 12, 16, 12, 13]]
1
135
#include <bits/stdc++.h> using namespace std; int main() { int K; int N; cin >> K >> N; vector<int> vec(N); for (int i = 1; i <= N; i++) { cin >> vec.at(i - 1); } int j = K + vec.at(0) - vec.at(N - 1); for (int k = 1; k < N; k++) { if (vec.at(k) - vec.at(k - 1) > j) { j = vec.at(k) - vec.a...
#include <bits/stdc++.h> using namespace std; int main() { int K; int N; cin >> K >> N; vector<int> vec(N); for (int i = 1; i <= N; i++) { cin >> vec.at(i - 1); } int j = K + vec.at(0) - vec.at(N - 1); for (int k = 1; k < N; k++) { if (vec.at(k) - vec.at(k - 1) > j) { j = vec.at(k) - vec.a...
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 31, 22], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 33]]
1
143
#include <stdio.h> int main() { int k, n; scanf("%d%d", &k, &n); int i; i = 0; int max; max = 0; int a[n]; while (i < n) { scanf("%d", &a[i]); if (i > 0 && max < a[i] - a[i - 1]) { max = a[i] - a[i - 1]; } i++; } if (max < a[0] - a[n - 1]) { max = a[0] - a[n - 1]; } pr...
#include <stdio.h> int main() { int k, n; scanf("%d%d", &k, &n); int i; i = 0; int max; max = 0; int a[n]; while (i < n) { scanf("%d", &a[i]); if (i > 0 && max < a[i] - a[i - 1]) { max = a[i] - a[i - 1]; } i++; } if (max < a[0] + k - a[n - 1]) { max = a[0] + k - a[n - 1]; ...
[["+", 15, 23, 0, 16, 12, 16, 31, 16, 17, 72], ["+", 15, 23, 0, 16, 12, 16, 31, 16, 12, 22], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 17, 72], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 12, 22]]
0
149
p, n = map(int, input().split()) l = list(map(int, input().split())) m = p - l[-1] + l[0] for i in range(1, n): m = max(m, l[i] - l[i - 1]) print(m)
p, n = map(int, input().split()) l = list(map(int, input().split())) m = p - l[-1] + l[0] for i in range(1, n): m = max(m, l[i] - l[i - 1]) print(p-m)
[["+", 0, 1, 0, 652, 3, 4, 0, 657, 31, 22], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 33]]
5
79
#include <iostream> #include <string> using namespace std; int main() { int K, N; int max; int a[200000], b[200001]; cin >> K >> N; for (int i = 0; i < N; i++) { cin >> a[i]; } b[0] = a[0] - a[N - 1]; max = b[0]; for (int j = 1; j < N; j++) { b[j] = a[j] - a[j - 1]; if (b[j] > max) { ...
#include <iostream> #include <string> using namespace std; int main() { int K, N; long long max; int a[200000], b[200001]; cin >> K >> N; for (int i = 0; i < N; i++) { cin >> a[i]; } b[0] = a[0] + K - a[N - 1]; max = b[0]; for (int j = 1; j < N; j++) { b[j] = a[j] - a[j - 1]; if (b[j] > m...
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 14, 8, 9, 0, 43, 39, 86, 0, 96], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 17, 72], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 12, 22]]
1
148
k, n = map(int, input().split(' ')) a = list(map(int, input().split(' '))) a.append(k) max_value = -1 ans = 0 for i in range(1, n+1): tmp_d = a[i] - a[i-1] ans += tmp_d max_value = max(max_value, tmp_d) ans -= max_value print(ans)
k, n = map(int, input().split(' ')) a = list(map(int, input().split(' '))) a.append(k+a[0]) max_value = -1 ans = 0 for i in range(1, n+1): tmp_d = a[i] - a[i-1] ans += tmp_d max_value = max(max_value, tmp_d) ans -= max_value print(ans)
[["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 652, 3, 4, 0, 657, 12, 206, 51, 22], ["+", 0, 652, 3, 4, 0, 657, 12, 206, 0, 70], ["+", 0, 652, 3, 4, 0, 657, 12, 206, 206, 612], ["+", 0, 652, 3, 4, 0, 657, 12, 206, 0, 73]]
5
95
K, N =map(int,input().split()) A_n =list(map(int,input().split())) A_n.sort() maxd =A_n[N-1]- A_n[0] for i in range(N-1): maxd =max(maxd,A_n[i+1]-A_n[i]) print(K-maxd)
K, N =map(int,input().split()) A_n =list(map(int,input().split())) A_n.sort() maxd =K -A_n[N-1]+ A_n[0] for i in range(N-1): maxd =max(maxd,A_n[i+1]-A_n[i]) print(K-maxd)
[["+", 0, 1, 0, 662, 12, 657, 31, 657, 31, 22], ["+", 0, 1, 0, 662, 12, 657, 31, 657, 17, 33], ["-", 0, 656, 0, 1, 0, 662, 12, 657, 17, 33], ["+", 0, 656, 0, 1, 0, 662, 12, 657, 17, 72]]
5
85
#include <bits/stdc++.h> using namespace std; int main() { int k, n; int maxed; cin >> k >> n; vector<int> v; for (int i = 0; i < n; i++) { int x; cin >> x; v.push_back(x); } sort(v.begin(), v.end()); int d = (k - v[v.size() - 1]) + v[0]; for (int i = 1; i < n; i++) { maxed = max...
#include <bits/stdc++.h> using namespace std; int main() { int k, n; cin >> k >> n; vector<int> v; for (int i = 0; i < n; i++) { int x; cin >> x; v.push_back(x); } sort(v.begin(), v.end()); int d = (k - v[v.size() - 1]) + v[0]; for (int i = 1; i < n; i++) { d = max(d, v[i] - v[i - ...
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["-", 0, 30, 0, 14, 8, 9, 0, 43, 49, 22], ["-", 0, 30, 0, 14, 8, 9, 0, 43, 0, 35], ["-", 0, 7, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 31, 22], ["-", 8, 9, 0, 43, 49, 50, 51, 16, 12, 22], ["+", 8, 9, 0, 43, 49, 50, 51, 16, 12, 22]]
1
148
#include <bits/stdc++.h> #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) (int)((x).size()) #define debug(x) cout << #x << ":" << x << ' '; #define debugg(x) cout << #x << ":" << x << ' ' << "\n"; #define endl "\n" #define L(X) ((X) << 1) #define R(X) (((X) << 1) | 1) #define...
#include <bits/stdc++.h> #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) (int)((x).size()) #define debug(x) cout << #x << ":" << x << ' '; #define debugg(x) cout << #x << ":" << x << ' ' << "\n"; #define endl "\n" #define L(X) ((X) << 1) #define R(X) (((X) << 1) | 1) #define...
[["-", 0, 1, 0, 16, 31, 16, 12, 2, 63, 22], ["-", 0, 16, 31, 16, 12, 2, 3, 4, 0, 24], ["-", 0, 16, 31, 16, 12, 2, 3, 4, 0, 22], ["-", 0, 16, 31, 16, 12, 2, 3, 4, 0, 21], ["-", 0, 16, 31, 16, 12, 2, 3, 4, 0, 25]]
1
636
#include <iostream> #include <vector> using namespace std; int main() { int K; int N; cin >> K >> N; vector<int> A(N); int total = 0; for (int i = 0; i < N; i++) { std::cin >> A[i]; } total = A[0] + K - A[N - 1]; for (int i = 1; i < N; i++) { if (total < A[i] - A[i - 1]) { total = A[i]...
#include <iostream> #include <vector> using namespace std; int main() { int K; int N; cin >> K >> N; vector<int> A(N); int total = 0; for (int i = 0; i < N; i++) { std::cin >> A[i]; } total = A[0] + K - A[N - 1]; for (int i = 1; i < N; i++) { if (total < A[i] - A[i - 1]) { total = A[i]...
[["-", 0, 1, 0, 16, 31, 16, 12, 16, 31, 22], ["-", 0, 1, 0, 16, 31, 16, 12, 16, 17, 33], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 33], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 22]]
1
141
package main import ( "bufio" "fmt" "os" "strconv" "strings" ) func main() { var input = irLine(2) var K, _ = input[0][0], input[0][1] var A = input[1] var max int // var imax int for i := 1; i < len(A); i++ { if A[i]-A[i-1] > max { // imax = i max = A[i+1] - A[i] } } if A[0]+K-A[len(A)-1] >...
package main import ( "bufio" "fmt" "os" "strconv" "strings" ) func main() { var input = irLine(2) var K, _ = input[0][0], input[0][1] var A = input[1] var max int // var imax int for i := 1; i < len(A); i++ { if A[i]-A[i-1] > max { // imax = i max = A[i] - A[i-1] } } if A[0]+K-A[len(A)-1] >...
[["-", 12, 432, 0, 16, 31, 437, 71, 16, 17, 72], ["-", 12, 432, 0, 16, 31, 437, 71, 16, 12, 433], ["+", 12, 432, 0, 16, 12, 437, 71, 16, 17, 33], ["+", 12, 432, 0, 16, 12, 437, 71, 16, 12, 433]]
7
716
k,n=map(int,input().split()) A=list(map(int,input().split())) ans=-1 for i in range(n-1): ans=max(ans,A[i+1]-A[i]) print(sum(A)- max(ans,k-(A[n-1]-A[0])))
k,n=map(int,input().split()) A=list(map(int,input().split())) ans=-1 for i in range(n-1): ans=max(ans,A[i+1]-A[i]) print(k- max(ans,k-(A[n-1]-A[0])))
[["-", 0, 652, 3, 4, 0, 657, 31, 652, 63, 22], ["-", 3, 4, 0, 657, 31, 652, 3, 4, 0, 24], ["-", 3, 4, 0, 657, 31, 652, 3, 4, 0, 22], ["-", 3, 4, 0, 657, 31, 652, 3, 4, 0, 25], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 31, 22]]
5
93
#include <bits/stdc++.h> using namespace std; int main() { int K, N; cin >> K >> N; vector<int> A(N + 1); for (int i = 0; i < N; i++) cin >> A.at(i); A.at(N) = K + A.at(0); int arch = 0; for (int i = 0; i < N - 1; i++) { arch = max(arch, A.at(i + 1) - A.at(i)); } cout << K - arch << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int K, N; cin >> K >> N; vector<int> A(N + 1); for (int i = 0; i < N; i++) cin >> A.at(i); A.at(N) = K + A.at(0); int arch = 0; for (int i = 0; i < N; i++) { arch = max(arch, A.at(i + 1) - A.at(i)); } cout << K - arch << endl; }
[["-", 8, 9, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 9, 0, 7, 15, 16, 12, 16, 12, 13]]
1
127