Search is not available for this dataset
name
stringlengths 2
88
| description
stringlengths 31
8.62k
| public_tests
dict | private_tests
dict | solution_type
stringclasses 2
values | programming_language
stringclasses 5
values | solution
stringlengths 1
983k
|
---|---|---|---|---|---|---|
p00926 Shopping | Example
Input
10 3
3 7
8 9
2 5
Output
23 | {
"input": [
"10 3\n3 7\n8 9\n2 5"
],
"output": [
"23"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const long long INF = 1107110711071107;
long long N, m;
vector<pair<long long, long long> > d;
long long dp[501][501][1001];
long long dfs(long long pre, long long now, long long n) {
if (n == m) {
return (now - pre + (N + 1) - pre);
}
long long ret = dfs(pre, d[n].first, n + 1) + (d[n].first - now);
ret = min(ret, dfs(d[n].second, d[n].first, n + 1) +
(now - pre + d[n].first - pre));
return dp[pre][now][n] = ret;
}
signed main() {
cin >> N >> m;
for (long long i = 0; i < (m); i++) {
long long c, b;
cin >> c >> b;
d.push_back(pair<long long, long long>(b, c));
}
sort(d.begin(), d.end());
if (m == 0)
cout << N + 1 << endl;
else
cout << dfs(d[0].second, d[0].first, 1) + d[0].first << endl;
}
|
p00926 Shopping | Example
Input
10 3
3 7
8 9
2 5
Output
23 | {
"input": [
"10 3\n3 7\n8 9\n2 5"
],
"output": [
"23"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int dx[8] = {1, 0, 0, -1, 1, 1, -1, -1};
int dy[8] = {0, -1, 1, 0, -1, 1, -1, 1};
long long gcd(long long a, long long b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
bool isprime[1000000 + 5];
void init_prime() {
fill(isprime, isprime + 1000000 + 5, true);
isprime[0] = isprime[1] = false;
for (int i = (0), loop_end_i = (1000000 + 5); i < (loop_end_i); i++) {
if (isprime[i]) {
for (int j = i * 2; j < 1000000; j += i) {
isprime[j] = false;
}
}
}
}
vector<long long> factors(long long n) {
vector<long long> v;
for (long long i = (0), loop_end_i = (1000000); i < (loop_end_i); i++) {
if (!isprime[i]) continue;
while (n % i == 0) {
v.push_back(i);
n /= i;
}
}
if (n > 1) {
v.push_back(n);
}
return v;
}
template <typename T = int>
class bit {
public:
T *bit_arr;
int size;
bit(int n) {
size = n;
bit_arr = new T[n];
fill(bit_arr, bit_arr + n, 0);
}
~bit() { delete bit_arr; }
T sum(int a) {
T ret = 0;
while (a) {
ret += bit_arr[a];
a -= a & -a;
}
return ret;
}
T sum(int a, int b) { return sum(b) - sum(a); }
T get(int a) { return sum(a, a + 1); }
void add(int a, T x) {
a++;
while (a < size) {
bit_arr[a] += x;
a += a & -a;
}
}
void set(int a, T x) { add(a, x - get(a)); }
};
template <typename T = int, class Compare = less<T> >
class rmq {
public:
int size;
Compare comp;
pair<T, int> *dat;
T init;
pair<T, int> mymin(pair<T, int> x, pair<T, int> y) {
if (x.first == y.first)
return make_pair(x.first, min(x.second, y.second));
else if (min(x.first, y.first, comp) == x.first)
return x;
else
return y;
}
rmq(int n, T init_ = INT_MAX) {
init = init_;
size = 2;
while (size < n) size *= 2;
dat = new pair<T, int>[2 * size - 1];
for (int i = (0), loop_end_i = (n); i < (loop_end_i); i++)
dat[size - 1 + i] = make_pair(init, i);
for (int i = size - 2; i >= 0; i--)
dat[i] = mymin(dat[i * 2 + 1], dat[i * 2 + 2]);
}
~rmq() { delete dat; }
void set(int k, T a) {
k += size - 1;
dat[k] = make_pair(a, k - (size - 1));
while (k > 0) {
k = (k - 1) / 2;
dat[k] = mymin(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
pair<T, int> get(int a, int b, int k, int l, int r) {
if (r <= a || b <= l) return make_pair(init, -1);
if (a <= l && r <= b)
return dat[k];
else {
pair<T, int> vl = get(a, b, k * 2 + 1, l, (l + r) / 2);
pair<T, int> vr = get(a, b, k * 2 + 2, (l + r) / 2, r);
return mymin(vl, vr);
}
}
pair<T, int> getp(int a, int b) { return get(a, b, 0, 0, size); }
T get(int a, int b) { return getp(a, b).first; }
int geti(int a, int b) { return getp(a, b).second; }
};
vector<pair<int, int> > v;
int main() {
int n, m;
{
scanf("%d", &(n));
scanf("%d", &(m));
};
for (int i = (0), loop_end_i = (m); i < (loop_end_i); i++) {
int a, b;
{
scanf("%d", &(a));
scanf("%d", &(b));
};
v.push_back(make_pair(a, b));
}
v.push_back(make_pair(n + 1, n + 1));
sort((v).begin(), (v).end());
int ans = 0, mi = 0, mx = 0, j = 0;
for (int i = (1), loop_end_i = (n + 1); i < (loop_end_i); i++) {
while (v[j].first == i) {
if (mi == 0) mi = i;
((mx) = max((mx), (v[j].second)));
j++;
}
((mx) = max((mx), (i)));
ans++;
printf("%d->%d\n", i - 1, i);
if (mi == 0) {
} else if (i == mx) {
ans += (mx - mi) * 2;
mi = 0;
}
}
printf("%d\n", ans + 1);
}
|
p00926 Shopping | Example
Input
10 3
3 7
8 9
2 5
Output
23 | {
"input": [
"10 3\n3 7\n8 9\n2 5"
],
"output": [
"23"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, d, flg[1002] = {};
cin >> n >> d;
for (int i = 0; i < d; i++) {
int a, b;
cin >> a >> b;
flg[a] = max(flg[a], b);
}
int sta = 0, sum = 0, L, R;
for (int i = 0; i <= n; i++)
if (flg[i] != 0 && sta == 1)
R = max(R, flg[i]);
else if (flg[i] != 0)
L = i, R = flg[i], sta = 1;
else if (i == R)
sum += 3 * (R - L) + 1, sta = 0;
else if (sta == 0)
sum++;
cout << sum << endl;
return 0;
}
|
p00926 Shopping | Example
Input
10 3
3 7
8 9
2 5
Output
23 | {
"input": [
"10 3\n3 7\n8 9\n2 5"
],
"output": [
"23"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include<bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]){
int n, m;
cin >> n >> m;
int c[m], d[m];
int road[n + 1] = {0};
for (int i = 0; i < m; i++) {
cin >> c[i] >> d[i];
for (int j = c[i]; j < d[i]; j++) {
road[j] = 1;
}
}
int ans = 0;
for (int i = 0; i <= n; i++) {
if(road[i] == 1)ans++;
// std::cout << road[i];
// if(i == n)std::cout << std::endl;
// else std::cout << " ";
}
std::cout << ans*2 + n + 1 << std::endl;
return 0;
} |
p00926 Shopping | Example
Input
10 3
3 7
8 9
2 5
Output
23 | {
"input": [
"10 3\n3 7\n8 9\n2 5"
],
"output": [
"23"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java | public class Main{
public void run(java.io.InputStream in, java.io.PrintStream out){
java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
int n, m;
int[] c, d;
int i, j, k, tmp, ans;
n = sc.nextInt();
m = sc.nextInt();
c = new int[m];
d = new int[m];
ans = 0;
for(i = 0;i < m;i++){
c[i] = sc.nextInt();
d[i] = sc.nextInt();
}
sc.close();
for(i = 0;i < m;i++){
for(j = 0;j < (m - i - 1);j++){
if(c[j] > c[j + 1]){
tmp = c[j];
c[j] = c[j + 1];
c[j + 1] = tmp;
tmp = d[j];
d[j] = d[j + 1];
d[j + 1] = tmp;
}
}
}
for(j = 0;j < m;j++){
tmp = j;
for(k = j;k < m;k++){
if(d[j] < c[k]){
d[j] = d[k - 1];
j = k - 1;
break;
}
}
ans = ans + (d[j] - c[tmp]) * 2;
}
ans += (n + 1);
System.out.println(ans);
/*fin*/
}
public static void main(String[] args){
(new Main()).run(System.in, System.out);
}
} |
p00926 Shopping | Example
Input
10 3
3 7
8 9
2 5
Output
23 | {
"input": [
"10 3\n3 7\n8 9\n2 5"
],
"output": [
"23"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
const int INF = 1e9;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
using namespace std;
int main() {
int N, m;
cin >> N >> m;
vector<pair<int, int> > list(m), tmp;
for (int i = 0; i < (int)(m); i++) cin >> list[i].second >> list[i].first;
sort((list).begin(), (list).end(), greater<pair<int, int> >());
list.push_back(pair<int, int>(-1, -1));
int a = list[0].first, b = list[0].second;
for (int i = 1; i < m + 1; i++) {
if (b < list[i].first) {
b = list[i].second;
} else {
tmp.push_back(pair<int, int>(a, b));
a = list[i].first, b = list[i].second;
}
}
tmp.push_back(pair<int, int>(0, 0));
tmp.push_back(pair<int, int>(N + 1, N + 1));
sort((tmp).begin(), (tmp).end());
int ans = 0;
for (int i = 1; i < tmp.size(); i++) {
ans += tmp[i].first - tmp[i - 1].second;
ans += tmp[i].first - tmp[i].second;
}
cout << ans << endl;
}
|
p00926 Shopping | Example
Input
10 3
3 7
8 9
2 5
Output
23 | {
"input": [
"10 3\n3 7\n8 9\n2 5"
],
"output": [
"23"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<ll>;
using VVI = vector<VI>;
using PII = pair<ll, ll>;
const ll LLINF = (1LL << 60);
const ll INF = (1LL << 30);
const ll MOD = 1000000007;
template <typename T>
T &chmin(T &a, const T &b) {
return a = min(a, b);
}
template <typename T>
T &chmax(T &a, const T &b) {
return a = max(a, b);
}
template <typename T>
bool IN(T a, T b, T x) {
return a <= x && x < b;
}
template <typename T>
T ceil(T a, T b) {
return a / b + !!(a % b);
}
template <class S, class T>
ostream &operator<<(ostream &out, const pair<S, T> &a) {
out << '(' << a.first << ',' << a.second << ')';
return out;
}
template <class T>
ostream &operator<<(ostream &out, const vector<T> &a) {
out << '[';
for (ll i = (ll)0; i < (ll)a.size(); ++i) {
out << a[i];
if (i != a.size() - 1) out << ',';
}
out << ']';
return out;
}
ll dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
signed main(void) {
ll n, m;
cin >> n >> m;
vector<PII> v;
for (ll i = (ll)0; i < (ll)m; ++i) {
ll c, d;
cin >> c >> d;
if (c < d) v.push_back({d, c});
}
sort(v.begin(), v.end());
if (v.size() == 0) {
cout << n + 1 << endl;
return 0;
}
ll ret = n + 1;
ll l = v[0].second, r = v[0].first;
for (ll i = (ll)1; i < (ll)v.size(); ++i) {
if (l <= v[i].second && v[i].second <= r) {
r = v[i].first;
} else if (v[i].second < l) {
l = v[i].second;
r = v[i].first;
} else {
ret += (r - l) * 2;
l = v[i].second, r = v[i].first;
}
}
ret += (r - l) * 2;
cout << ret << endl;
return 0;
}
|
p00926 Shopping | Example
Input
10 3
3 7
8 9
2 5
Output
23 | {
"input": [
"10 3\n3 7\n8 9\n2 5"
],
"output": [
"23"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | java |
import java.io.*;
import java.util.*;
public class Q3 {
FastScanner in = new FastScanner(System.in);
PrintWriter out = new PrintWriter(System.out);
public void run() {
int n = in.nextInt(), m = in.nextInt();
int[] array = new int[n+1];
for (int i = 0; i < m; i++) {
int c = in.nextInt(), d = in.nextInt();
for (int j = c; j < d; j++) {
array[j] = 1;
}
}
int cnt = 0;
for (int i = 0; i < n; i++)
if (array[i] == 1) cnt++;
System.out.println(cnt * 2 + n + 1);
out.close();
}
public static void main(String[] args) {
new Q3().run();
}
public void mapDebug(int[][] a) {
System.out.println("--------map display---------");
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < a[i].length; j++) {
System.out.printf("%3d ", a[i][j]);
}
System.out.println();
}
System.out.println("----------------------------");
System.out.println();
}
public void debug(Object... obj) {
System.out.println(Arrays.deepToString(obj));
}
class FastScanner {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
public FastScanner(InputStream stream) {
this.stream = stream;
//stream = new FileInputStream(new File("dec.in"));
}
int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
boolean isEndline(int c) {
return c == '\n' || c == '\r' || c == -1;
}
int nextInt() {
return Integer.parseInt(next());
}
int[] nextIntArray(int n) {
int[] array = new int[n];
for (int i = 0; i < n; i++)
array[i] = nextInt();
return array;
}
long nextLong() {
return Long.parseLong(next());
}
long[] nextLongArray(int n) {
long[] array = new long[n];
for (int i = 0; i < n; i++)
array[i] = nextLong();
return array;
}
double nextDouble() {
return Double.parseDouble(next());
}
double[] nextDoubleArray(int n) {
double[] array = new double[n];
for (int i = 0; i < n; i++)
array[i] = nextDouble();
return array;
}
String next() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
String[] nextStringArray(int n) {
String[] array = new String[n];
for (int i = 0; i < n; i++)
array[i] = next();
return array;
}
String nextLine() {
int c = read();
while (isEndline(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isEndline(c));
return res.toString();
}
}
} |
p00926 Shopping | Example
Input
10 3
3 7
8 9
2 5
Output
23 | {
"input": [
"10 3\n3 7\n8 9\n2 5"
],
"output": [
"23"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int st[1024];
int main() {
int N, m;
cin >> N >> m;
for (int(i) = (0); ((i)) < ((m)); ++(i)) {
int c, d;
cin >> c >> d;
st[c]++;
st[d]--;
}
for (int(i) = (0); ((i)) < ((N)); ++(i)) st[i + 1] += st[i];
int res = 0;
for (int(i) = (0); ((i)) < ((N + 1)); ++(i))
if (st[i + 1])
res += 3;
else
res += 1;
for (int(i) = (0); ((i)) < ((10)); ++(i)) cout << st[i] << " ";
cout << endl;
for (int(i) = (0); ((i)) < ((10)); ++(i)) cout << st[i + 991] << " ";
cout << endl;
cout << res << endl;
return 0;
}
|
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
int main(){
int n,m;
cin>>n>>m;
vi in(m);
rep(i,m)cin>>in[i];
int ma=in[0]-1;
rep(i,m-1){
int q=in[i+1]-in[i];
q/=2;
ma=max(ma,q);
}
ma=max(ma,n-in[m-1]);
cout<<ma<<endl;
} |
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | python3 | n, m = map(int, input().split())
a =list(map(int, input().split()))
t = max(a[0] - 1, n - a[-1])
for i in range(1, m):t = max(t, (a[i] - a[i - 1]) // 2)
print(t)
|
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
long long int ans = LLONG_MIN / 6;
long long int now;
cin >> ans;
now = ans;
ans--;
for( size_t i = 1; i < M; i++ ) {
long long int a;
cin >> a;
ans = max( (a - now) / 2, ans );
now = a;
}
ans = max( N - now, ans );
cout << ans << endl;
} |
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<bits/stdc++.h>
using namespace std;
const int INF = 1 << 28;
int N, M, B[100000];
int dp[100000][4];
int rec(int idx, int dir)
{
if(idx < 0 || idx >= N) return(INF);
if(~dp[idx][dir + 1]) return(dp[idx][dir + 1]);
if(B[idx]) return(0);
return(dp[idx][dir + 1] = rec(idx + dir, dir) + 1);
}
int main()
{
fill_n(*dp, 4 * 100000, -1);
cin >> N >> M;
for(int i = 0; i < M; i++) {
int A;
cin >> A;
B[--A] = true;
}
int ret = 0;
for(int i = 0; i < N; i++) {
ret = max(ret, min(rec(i, -1), rec(i, +1)));
}
cout << ret << endl;
} |
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp make_pair
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
int main(){
int n,m;
cin>>n>>m;
vector<int> a(m);
rep(i,m) cin>>a[i];
int ans = max(a[0]-1, n - a.back());
rep(i,m-1){
ans = max(ans, (a[i+1] - a[i])/2);
}
cout << ans << endl;
return 0;
}
|
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <iostream>
using namespace std;
int main()
{
int n, m;
int a, last_a;
int max_diff = 0;
int diff;
cin >> n >> m;
cin >> a;
last_a = a;
max_diff = a -1;
for (int i = 1; i < m; i++) {
cin >> a;
diff = a - last_a - 1;
!(diff % 2) ? diff /= 2 : diff = diff / 2 + 1;
if (diff > max_diff) max_diff = diff;
last_a = a;
}
if (n - a > max_diff) max_diff = n - a;
cout << max_diff << endl;
}
|
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;
int a[100000];
int main(){
int n, m; cin >> n >> m;
int ans = 0;
rep(i, m) cin >> a[i];
rep(i, m - 1) ans = max(ans, (a[i + 1] - a[i]) / 2);
ans = max(ans, a[0] - 1);
ans = max(ans, n - a[m - 1]);
cout << ans << endl;
return 0;
} |
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <iostream>
#include <vector>
using namespace std;
int main(){
int n,m;
cin >> n >> m;
if(m == 1){
int a;
cin >> a;
cout << max(a-1,n-a) << endl;
return 0;
}
vector<int> a(m);
for(int i = 0; i < m; i++){
cin >> a[i];
}
int ans = 0;
for(int i = 0; i < m-1; i++){
ans = max(ans,(a[i+1]-a[i])/2);
}
ans = max(ans,max(a[0]-1,n-a[m-1]));
cout << ans << '\n';
return 0;
}
|
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | python3 | n, m = map(int, input().split())
li = list(map(int, input().split()))
print(max(li[0]-1, n-li[-1], *[(li[i]-li[i-1])//2 for i in range(1,m)]))
|
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<iostream>
#include<algorithm>
using namespace std;
int main(){
int n, m, a[100000], ans=0;
cin>>n>>m;
for(int i=0;i<m;i++) cin>>a[i];
for(int i=1;i<m;i++) ans=max(ans, (a[i]-a[i-1])/2);
ans=max(ans, a[0]-1);
ans=max(ans, n-a[m-1]);
cout<<ans<<endl;
return 0;
} |
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include<vector>
#include<algorithm>
using namespace std;
struct init{
init(){
cin.tie(0); ios::sync_with_stdio(false);
}
}________init;
int main() {
#ifdef INPUT_FROM_FILE
ifstream cin("sample.in");
ofstream cout("sample.out");
#endif
int n, m;
cin >> n >> m;
vector<int> a(m);
for (auto& it : a){
cin >> it;
}
int res = 0;
res = max(res, n - a[m - 1]);
res = max(res, a[0] - 1);
for (int i = 1; i < m; i++){
res = max(res, (a[i] - a[i - 1]) / 2);
}
cout << res << endl;
return 0;
} |
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>
using namespace std;
#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
typedef long long ll;
int const inf = 1<<29;
int main() {
int N, M; cin >> N >> M;
vector<int> v(N, inf);
rep(i, M) {
int x; cin >> x; x--;
v[x] = 0;
}
REP(i, 1, N) {
v[i] = min(v[i], v[i-1] + 1);
}
for(int i=N-2; i>=0; i--) {
v[i] = min(v[i], v[i+1] + 1);
}
cout << *max_element(all(v)) << endl;
return 0;
} |
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | java | import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
public class Main{
int N,M;
int[] a;
public void solve() {
N = nextInt();
M = nextInt();
a = new int[M];
for(int i = 0;i < M;i++)a[i] = nextInt();
int ans = 0;
for(int i = 0;i <= M;i++){
if(i == 0)ans = Math.max(ans, a[i]-1);
else if(i==M)ans = Math.max(ans,N-a[i-1]);
else ans = Math.max(ans, (a[i]-a[i-1])/2);
}
out.println(ans);
}
public static void main(String[] args) {
out.flush();
new Main().solve();
out.close();
}
/* Input */
private static final InputStream in = System.in;
private static final PrintWriter out = new PrintWriter(System.out);
private final byte[] buffer = new byte[2048];
private int p = 0;
private int buflen = 0;
private boolean hasNextByte() {
if (p < buflen)
return true;
p = 0;
try {
buflen = in.read(buffer);
} catch (IOException e) {
e.printStackTrace();
}
if (buflen <= 0)
return false;
return true;
}
public boolean hasNext() {
while (hasNextByte() && !isPrint(buffer[p])) {
p++;
}
return hasNextByte();
}
private boolean isPrint(int ch) {
if (ch >= '!' && ch <= '~')
return true;
return false;
}
private int nextByte() {
if (!hasNextByte())
return -1;
return buffer[p++];
}
public String next() {
if (!hasNext())
throw new NoSuchElementException();
StringBuilder sb = new StringBuilder();
int b = -1;
while (isPrint((b = nextByte()))) {
sb.appendCodePoint(b);
}
return sb.toString();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
} |
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
int n,m;
cin >> n >> m;
vector<int> a(m);
cin >> a[0];
int ma=0;
for(int i=1;i<m;i++){
cin >> a[i];
int tmp = (a[i]-a[i-1])/2;
ma = max(ma,tmp);
}
//cout << ma << endl;
// cout << a[0]-1 << endl;
ma = max(ma,n-a[m-1]);
if(ma <= a[0]-1){
cout << a[0]-1 << endl;
}else{
cout << ma << endl;
}
} |
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n,m;
cin >> n >> m;
int d[n],d2[n],ans=0;
fill(d,d+n,1<<29);
fill(d2,d2+n,1<<29);
for(int i=0,x; i<m; i++) {
cin >> x;
d[x-1]=d2[x-1]=0;
}
for(int i=1; i<n; i++) d[i]=min(d[i],d[i-1]+1);
for(int i=n-2; i>=0; i--) d2[i]=min(d2[i],d2[i+1]+1);
for(int i=0; i<n; i++) ans=max(ans,min(d[i],d2[i]));
cout << ans << endl;
return 0;
}
|
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | /*
* a.cc:
*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
/* constant */
const int MAX_N = 100000;
/* typedef */
/* global variables */
int as[MAX_N];
/* subroutines */
/* main */
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) (cin >> as[i]), as[i]--;
int ans = max(as[0], n - 1 - as[m - 1]);
for (int i = 0; i < m - 1; i++) {
int c = (as[i + 1] - as[i]) / 2;
if (ans < c) ans = c;
}
printf("%d\n", ans);
return 0;
} |
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int t[100000];
int main(){
int n,m; cin>>n>>m;
vector<int> a(m);
for(int i=0;i<n;i++) t[i]=1e9;
queue<int> q;
for(int i=0;i<m;i++){
cin>>a[i]; a[i]--;
t[a[i]]=0;
q.push(a[i]);
}
while(!q.empty()){
int cur=q.front(); q.pop();
if(cur+1<n){
if(t[cur+1]>t[cur]+1){
t[cur+1]=t[cur]+1;
q.push(cur+1);
}
}
if(cur-1>=0){
if(t[cur-1]>t[cur]+1){
t[cur-1]=t[cur]+1;
q.push(cur-1);
}
}
}
int ans=0;
for(int i=0;i<n;i++) ans=max(ans,t[i]);
cout<<ans<<endl;
return 0;
} |
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <stack>
#include <queue>
#include <utility>
#define rep(i,l,n) for(lint i=l;i<n;i++)
#define rer(i,l,n) for(lint i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef vector<lint> vli;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
int main(){
int n,m;
cin>>n>>m;
vi know(m+1);
rep(i,0,m) cin>>know[i];
know[m]=1e8;
int MAX=0,l=0,r=1;
rep(i,1,n+1){
if(i==know[r]){
l=r; r++;
}
int tmp=min(know[r]-i,abs(i-know[l]));
MAX=max(tmp,MAX);
}
o(MAX);
} |
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #define _USE_MATH_DEFINES
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<iostream>
#include<fstream>
#include<iomanip>
using namespace std;
int n, m;
int data[100000];
int main(){
scanf("%d%d", &n, &m);
for (int i = 0; i < m; ++i){
scanf("%d", &data[i]);
}
int Max = data[0] - 1;
for (int i = 1; i < m; ++i) {
if ((data[i] - data[i - 1])/2>Max){
Max = (data[i] - data[i - 1])/2;
}
}
if (n - data[m - 1] > Max) {
Max = n - data[m - 1];
}
printf("%d\n", Max);
return 0;
} |
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define Rep(i, n) for( int i = 0; i < (n); i++ )
#define Rrep(i, a, n) for( int i = (a); i < (n); i++ )
#define All(v) v.begin(), v.end()
typedef pair<int, int> Pii;
typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;
signed main() {
int n, m;
cin >> n >> m;
int a[100010];
Rep(i, m) cin >> a[i];
int mx = 0;
for ( int i = 0; i < m-1; i++ ) {
mx = max(mx, (a[i+1]-a[i]) / 2);
}
cout << max(mx, max(a[0]-1, n - a[m-1])) << endl;
} |
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <iostream>
#include <queue>
#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
using namespace std;
int main() {
int n; cin >> n;
int m; cin >> m;
vector<int> a;
rep(i, m) {
int x; cin >> x; x--;
a.push_back(x);
}
int ans = 0;
REP(i, 0, (int)a.size()-1) {
ans = max(ans, (a[i+1]-a[i]) / 2);
}
if(a[0] != 0) {
ans = max(ans, a[0]);
}
if(a[m-1] != n-1) {
ans = max(ans, n - a[m-1] - 1);
}
cout << ans << endl;
return 0;
} |
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define LL long long
#define Fi first
#define Se second
using namespace std;
static const LL INF = 1LL<<61LL;
typedef pair<int,int> PII;
int N,M;
int A[100010];
int temp=1;
int ans;
int main(){
cin>>N>>M;
rep(i,M){
int a;
cin>>a;
A[a]=1;
}
FOR(i,1,N){
//cout<<temp<<endl;
if(A[i]==1){
if(temp==1&&A[1]!=1){
int t=(i-temp);
temp=i;
ans=max(ans,t);
continue;
}
int t=(i-temp-1)/2;
if(i-temp-1<=0)t=0;
else if((i-temp-1)%2!=0)t++;
temp=i;
ans=max(ans,t);
}
else if(i==N){
ans=max(ans,N-temp);
}
}
cout<<ans<<endl;
} |
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <iostream>
using namespace std;
int main(){
int n,m,a[100000],r=0;;
cin>>n>>m;
for(int i=0;i<m;i++) cin>>a[i];
r=max(a[0]-1,n-a[m-1]);
for(int i=1;i<m;i++) r=max(r,(a[i]-a[i-1])/2);
cout<<r<<endl;
return 0;
} |
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
int N,M,a[100000];
int main(){
cin>>N>>M;
rep(i,M) cin>>a[i];
int ans=0;
rep(i,M-1) chmax(ans,(a[i+1]-a[i])/2);
chmax(ans,a[0]-1);
chmax(ans,N-a[M-1]);
cout<<ans<<endl;
} |
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | python3 | n,m = map(int,input().split())
a = list(map(int,input().split()))
c = [a[0]-1, n-a[m-1]]
for i in range(m-1):
c.append((a[i+1]-a[i])//2)
print(max(c))
|
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD
int main(){
int n,m;
cin>>n>>m;
vi a(m);
REP(i,m)cin>>a[i];
REP(i,m)--a[i];
vi d(n,1145141919);
queue<int> Q;
REP(i,m){
d[a[i]]=0;
Q.push(a[i]);
}
while(!Q.empty()){
int p = Q.front(); Q.pop();
if(p>0){
if(d[p-1]>d[p]+1){
d[p-1] = d[p]+1;
Q.push(p-1);
}
}
if(p<n-1){
if(d[p+1]>d[p]+1){
d[p+1] = d[p]+1;
Q.push(p+1);
}
}
}
int res = 0;
REP(i,n)res=max(res,d[i]);
cout<<res<<endl;
return 0;
} |
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <iostream>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int n,m;
int a[200005];
int b[200005];
int main() {
cin>>n>>m;
rep(i,m) cin>>a[i];
rep(i,m) a[i]--;
rep(i,200005) b[i]=1e8;
rep(i,m) b[a[i]]=0;
rep(i,n) if(i) {
b[i]=min(b[i],b[i-1]+1);
}
for(int i=n-1;i>=0;i--) if(i+1!=n) b[i]=min(b[i],b[i+1]+1);
int ans=0;
rep(i,n) ans=max(ans,b[i]);
cout<<ans<<endl;
return 0;
} |
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<iostream>
#include<vector>
#include<cassert>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<tuple>
#include<numeric>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
typedef ll int__;
#define rep(i,j) for(int__ i=0;i<(int__)(j);i++)
#define repeat(i,j,k) for(int__ i=(j);i<(int__)(k);i++)
#define all(v) v.begin(),v.end()
template<typename T>
ostream& operator << (ostream &os , const vector<T> &v){
rep(i,v.size()) os << v[i] << (i!=v.size()-1 ? " " : "\n"); return os;
}
template<typename T>
istream& operator >> (istream &is , vector<T> &v){
rep(i,v.size()) is >> v[i]; return is;
}
bool solve(){
int n, m; cin >> n >> m;
vector<int> a(m); cin >> a;
int ans = max(a[0] - 1, n - a.back());
rep(i, m-1){
ans = max(ans, (a[i+1] - a[i]) / 2);
}
cout << ans << endl;
return false;
}
int main(){
ios::sync_with_stdio(false);
while(solve());
return 0;
} |
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define pb push_back
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = 1; i <= n; ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
using namespace std;
typedef vector<int> vi;
const int MX = 100005;
const int INF = 1001001001;
int n, m;
int a[MX];
int main() {
scanf("%d%d",&n,&m);
rrep(i,n) a[i] = INF;
rep(i,m) {
int x;
scanf("%d",&x);
a[x] = 0;
}
rrep(i,n) mins(a[i+1],a[i]+1);
drep(i,n) mins(a[i],a[i+1]+1);
int ans = 0;
rrep(i,n) maxs(ans, a[i]);
cout<<ans<<endl;
return 0;
} |
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | python3 | n, m = map(int, input().split())
lst = [100000 for _ in range(n)]
a_lst = list(map(int, input().split()))
for a in a_lst:
lst[a - 1] = 0
for i in range(n - 1):
lst[i + 1] = min(lst[i] + 1, lst[i + 1])
for i in range(n - 1, 0, -1):
lst[i - 1] = min(lst[i - 1], lst[i] + 1)
print(max(lst))
|
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | python3 | # AOJ 1574: Gossip
# Python3 2018.7.13 bal4u
n, m = map(int, input().split())
a = list(map(int, input().split()))
pre = a[0]; d = 0
for x in a[1:]:
d = max(d, x-pre)
pre = x
print(max(n-pre, max(d>>1, a[0]-1)))
|
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n,m;cin>>n>>m;
int ans=0;
int b;
for(int i=0;i<m;i++){
int a;cin>>a;
if(i==0)ans=max(ans,a-1);
else ans=max(ans,(a-b)/2);
b=a;
}
ans=max(ans,n-b);
cout<<ans<<endl;
return 0;
}
|
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | python3 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
def solve(n, received):
not_relayed = received.copy()
for t in range(n + 1):
if len(received) >= n:
return t
new_not_relayed = set()
for person in not_relayed:
if person >= 1:
if (person - 1) not in received:
received.add(person - 1)
new_not_relayed.add(person - 1)
if person <= n - 2:
if (person + 1) not in received:
received.add(person + 1)
new_not_relayed.add(person + 1)
not_relayed = new_not_relayed
def main():
n, m = map(int, input().split())
received_people = set(map(lambda x: int(x) - 1, input().split()))
print(solve(n, received_people.copy()))
if __name__ == '__main__':
main() |
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | java | import java.io.PrintWriter;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws Exception {
PrintWriter pw=new PrintWriter(System.out);
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int m=sc.nextInt();
int[] L=new int[m];
for(int i=0;i<m;i++){
L[i]=sc.nextInt();
}
int gap=0;
for(int i=0;i<m-1;i++){
if(gap<Math.abs(L[i]-L[i+1])){
gap=Math.abs(L[i]-L[i+1]);
}
}
if(gap<Math.abs(L[0]-(1-L[0]))){
gap=Math.abs(L[0]-(1-L[0]));
}
if(gap<Math.abs(L[m-1]-(n+1+n-L[m-1]))){
gap=Math.abs(L[m-1]-(n+1+n-L[m-1]));
}
if((gap-1)%2==0){
pw.println((gap-1)/2);
}
if((gap-1)%2==1){
pw.println((gap-1-1)/2+1);
}
sc.close();
pw.close();
}
} |
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <iostream>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
int n, m;
int a[100000];
int main(){
cin >> n >> m;
rep(i, m){
cin >> a[i];
}
int ans = max(a[0] - 1, n - a[m - 1]);
rep(i, m - 1){
ans = max((a[i + 1] - a[i]) / 2, ans);
}
cout << ans << endl;
return 0;
} |
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <cstdio>
#include <algorithm>
using namespace std;
int main() {
int n, m, t, prev = 1, curr, ans = 0;
scanf("%d %d", &n, &m);
scanf("%d", &curr);
if (curr > 1) {
ans = curr - 1;
prev = curr;
}
for (int i = 1; i < m; i++) {
scanf("%d", &curr);
t = (curr - prev) / 2;
ans = max(ans, t);
prev = curr;
}
if (prev < n) {
t = n - prev;
ans = max(ans, t);
}
printf("%d\n", ans);
return 0;
}
|
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | /* _/ _/ _/_/_/ _/
_/_/_/_/ _/_/ _/_/_/_/ _/_/ _/ _/_/
_/ _/ _/ _/ _/ _/ _/_/_/ _/
_/ _/ _/ _/ _/ _/ _/ _/ _/
_/_/ _/_/ _/_/ _/_/ _/_/ _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=1e18;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
cin.tie(0),cout.tie(0);
ios::sync_with_stdio(false);
int n,m,a,x[100005]={},ans=0;
cin >> n >> m;
for(int i=1; i<=n; i++) {
x[i]=inf;
}
for(int i=0; i<m; i++) {
cin >> a;
x[a]=0;
}
for(int i=2; i<=n; i++) {
if(x[i-1]!=inf) {
x[i]=min(x[i-1]+1,x[i]);
}
}
for(int i=n-1; i>=1; i--) {
if(x[i+1]!=inf) {
x[i]=min(x[i+1]+1,x[i]);
}
}
for(int i=1; i<=n; i++) {
ans=max(ans,x[i]);
}
cout << ans << endl;
}
|
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | java | import java.util.*;
public class Main {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int max = 0;
int prev = 0;
for (int i = 0; i < m; i++) {
int x = sc.nextInt();
max = Math.max((x - prev) / 2, max);
prev = x;
if (i == 0) {
max = Math.max(max, x - 1);
}
if(i == m - 1) {
max = Math.max(max, n - x);
}
}
System.out.println(max);
}
}
|
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <iostream>
using namespace std;
int N,M;
const int MAX_N = 100010;
const int INF = 1 << 20;
int A[MAX_N];
int Left[MAX_N];
int Right[MAX_N];
int main(){
cin >> N >> M;
int result = 0;
for (int i = 0; i < M; i++){
int x;
cin >> x;
x--;
A[x]++;
}
int tmp = INF;
for (int i = 0; i < N; i++){
if (A[i]){
tmp = 0;
}
Left[i] = tmp;
tmp++;
}
tmp = INF;
for (int i = N - 1; i >= 0; i--){
if (A[i]){
tmp = 0;
}
Right[i] = tmp;
tmp++;
}
int res = 0;
for (int i = 0; i < N; i++){
res = max(res, min(Left[i], Right[i]));
}
cout << res << endl;
return 0;
} |
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<iostream>
#include<algorithm>
using namespace std;
int main() {
int n, m, i, in, def = 0, ans = 0, before = 0;
cin >> n >> m;
for(i = 0; i < m; i++) {
cin >> in;
if(i == 0 && in != 1) {
def = in - 1;
}
else def = (in-before)/2 +0.5;
ans = max(ans, def);
before = in;
}
ans = max(ans, n - in);
cout << ans << endl;
return 0;
} |
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<iostream>
using namespace std;
int main()
{
int n, m, d;
cin >> n >> m;
bool a[n+2];
for( int i = 0; i < n + 2; i++ )
a[i] = 0;
a[0] = a[n+1] = 1;
int ma = 0;
for( int i = 0; i < m; i++ )
{
cin >> d;
if( i == 0 )
ma = d - 1;
if( i == m - 1 )
ma = max( ma, n - d );
a[d] = 1;
}
int sum = 0;
for( int i = 0; i < n + 2; i++ )
{
if( a[i] )
sum = 0;
if( !a[i] )
sum++;
if( ma < ( sum + 1 ) / 2 )
ma = ( sum + 1 ) / 2;
}
cout << ma << endl;
return 0;
}
|
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>
//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else
//#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define VV(T) vector<vector< T > >
template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
v.assign(a, vector<T>(b, t));
}
template <class F, class T>
void convert(const F &f, T &t){
stringstream ss;
ss << f;
ss >> t;
}
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x) cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x)
#define debug(x)
#endif
#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
void mainmain(){
int ans=0;
int n,m;
cin>>n>>m;
vint v(m);
rep(i,m){
cin>>v[i];
}
sort(ALL(v));
rep(i,v.size()-1){
maxs(ans,v[i+1]-v[i]-1);
}
ans=(ans+1)/2;
// cout<<ans<<endl;
maxs(ans,v[0]-1);
maxs(ans,n-v.back());
cout<<ans<<endl;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout<<fixed<<setprecision(20);
mainmain();
} |
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include "bits/stdc++.h"
using namespace std;
int main() {
int N, M; cin >> N >> M;
vector<int>v;
for (int i = 0; i < M; ++i) {
int a; cin >> a;
v.emplace_back(a);
}
int ans = 0;
ans = max(ans, v[0] - 1);
ans = max(ans, N - v.back());
for (int i = 0; i < M-1; ++i) {
ans = max(ans, (v[i + 1] - v[i]) / 2);
}
cout << ans << endl;
return 0;
} |
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | java | import java.util.BitSet;
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int m = in.nextInt();
// int[] a = new int[n];
BitSet bs = new BitSet(n);
for(int i=0; i<m; i++){
// a[in.nextInt()] = 1;
bs.set(in.nextInt()-1);
}
int bf = -1;
int[] dist = new int[n];
for(int i=0; i<n; i++){
if(bs.get(i)) bf = i;
if(bf>=0){
dist[i] = Math.abs(i-bf);
}else{
dist[i] = Integer.MAX_VALUE;
}
}
bf = -1;
for(int i=n-1; i>=0; i--){
if(bs.get(i)) bf = i;
if(bf>=0){
dist[i] = Math.min(dist[i], Math.abs(i-bf));
}
}
int max = 0;
for(int i=0; i<n; i++){
}
for(int i=0; i<n; i++) max = Math.max(max, dist[i]);
System.out.println(max);
}
} |
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <fstream>
#include <iostream>
#include <vector>
#include <iomanip>
#include <algorithm>
using namespace std;
#define ALL(c) (c).begin(), (c).end()
#define REP(i,n) for(ll i=0; i < (n); ++i)
using ll = long long;
using vl = vector<ll>;
int main(){
#ifdef _WIN32
ifstream cin("sample.in");
ofstream cout("sample.out");
#endif
cout << fixed << setprecision(8);
ll n, m; cin >> n >> m;
vl a(m); REP(i, m) cin >> a[i];
REP(i, m) a[i]--;
sort(ALL(a));
ll mi = 0;
REP(i, n){
auto it = lower_bound(ALL(a), i);
ll mii = 100000;
if(it != a.end()) mii = min<ll>(mii, abs(*it - i));
if (it != a.begin()) mii = min<ll>(mii, abs(*--it - i));
mi = max(mi, mii);
}
cout << mi << endl;
} |
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | python3 | # -*- coding: utf-8 -*-
n, m = map(int, input().split())
a = list(map(int, input().split()))
ma = a[0] - 1
for i in range(m-1):
ma = max(ma, (a[i + 1] - a[i]) // 2)
ma = max(ma, n - a[-1])
print(ma) |
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n,m;
int a[100001];
int main(void){
scanf("%d%d",&n,&m);
for(int i=0;i<m;i++){
scanf("%d",&a[i]);
}
int ans=max(a[0]-1,n-a[m-1]);
for(int i=0;i<m-1;i++){
ans=max(ans,(a[i+1]-a[i])/2);
}
printf("%d\n",ans);
return 0;
}
|
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | python3 | n,m=map(int,input().split(" "))
a=list(map(int,input().split(" ")))
print(max(a[0]-1,n-a[-1],*[(a[i+1]-a[i])//2 for i in range(m-1)]))
|
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <stdio.h>
int main(void) {
int m, n, i, j, be = 1, ans = 0, t;
scanf("%d%d", &n, &m);
for(i = 0; i < m; ++i) {
scanf("%d", &t);
if(!i) ans = t - 1;
else if((t - be) / 2 > ans) ans = (t - be) / 2;
be = t;
}
if(n - be > ans) ans = n - be;
printf("%d\n", ans);
return 0;
}
|
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #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()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
int main(){
int n,m;
cin >>n >>m;
const int INF = 10000000;
vector<int> a;
a.pb(-INF);
rep(i,m){
int v;
cin >>v;
a.pb(v);
}
a.pb(INF);
int idx = 0;
int ans = 0;
for(int i=1; i<=n; ++i){
ans = max(ans, min(i-a[idx], a[idx+1]-i));
if(a[idx+1] == i) ++idx;
}
cout << ans << endl;
return 0;
}
|
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<iostream>
using namespace std;
int main(){
int sum;
while(cin >> sum){
int number, info[100005], ans;
cin >> number;
for(int i = 0; i < number; i++){
cin >> info[i];
}
for(int i = 0; i < number + 1; i++){
if(!i){
ans = info[i] - 1;
}else if(i == number){
ans = max(ans, sum - info[i - 1]);
}else{
int a = (info[i] - info[i - 1]) / 2;
ans = max(ans, a);
}
}
cout << ans << endl;
}
} |
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | /*
_ooOoo_
o8888888o
88" . "88
(| -_- |)
O\ = /O
____/`---'\____
.' \\| |// `.
/ \\||| : |||// \
/ _||||| -:- |||||- \
| | \\\ - /// | |
| \_| ''\---/'' | |
\ .-\__ `-` ___/-. /
___`. .' /--.--\ `. . __
."" '< `.___\_<|>_/___.' >'"".
| | : `- \`.;`\ _ /`;.`/ - ` : | |
\ \ `-. \_ __\ /__ _/ .-` / /
======`-.____`-.___\_____/___.-`____.-'======
`=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pass System Test!
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template <typename T>
std::ostream& operator<<(std::ostream& out, const std::vector<T>& v) {
if (!v.empty()) {
out << '[';
std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
out << "\b\b]";
}
return out;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N, M;
cin >> N >> M;
set<int> a;
for (int i = 0; i < M; ++i) {
int b;
cin >> b;
b--;
a.insert(b);
}
int ma = 0;
for (int i = 0; i < N; ++i) {
if (i >= *(a.rbegin())) {
ma = max(ma, i - *(a.rbegin()));
continue;
}
auto it = a.lower_bound(i);
int mi = N;
mi = min(mi, *it - i);
if (it != a.begin()) {
it--;
mi = min(mi, i - *it);
}
// cerr << mi << endl;
ma = max(ma, mi);
}
cout << ma << endl;
} |
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
using namespace std;
#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;
int gcd(int a, int b){
if(b==0) return a;
return gcd(b,a%b);
}
int lcm(int a, int b){
return a/gcd(a,b)*b;
}
signed main(void) {
int n,m;
cin >> n >> m;
vi a(m);
rep(i,m)cin >> a[i];
int ans = max(a[0]-1, n-a[m-1]);
rep(i,m-1){
ans = max(ans, (a[i+1]-a[i])/2);
}
cout << ans << endl;
}
|
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <iostream>
#include <vector>
int main()
{
int n, m;
std::cin >> n >> m;
std::vector<int> min_t(n, (1 << 29));
for (int i = 0; i < m; i++) {
int a;
std::cin >> a;
min_t[a - 1] = 0;
}
for (int i = 1; i < n; i++) {
min_t[i] = std::min(min_t[i], min_t[i - 1] + 1);
}
for (int i = n - 2; i >= 0; i--) {
min_t[i] = std::min(min_t[i], min_t[i + 1] + 1);
}
int ret = 0;
for (int t : min_t) {
ret = std::max(ret, t);
}
std::cout << ret << std::endl;
return 0;
} |
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <iostream>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#define rep(i,a,b) for(int (i)=(a);i<(b);i++)
#define INF 100000000
#define MAX_N 1000000
using namespace std;
int main(){
int n,m,a=0,b=0;
cin>>n>>m;
int ans=0;
cin>>a;
int z=a;
b=a;
rep(i,1,m){
cin>>a;
ans=max(a-b,ans);
//cout<<ans<<endl;
b=a;
}
//cout<<ans<<endl;
if(ans/2<n-a&&z-1<n-a){
cout<<n-a<<endl;
}else{
cout<<max(ans/2,z-1)<<endl;
}
return 0;
} |
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;
int main(){
int N,M;
scanf("%d %d",&N,&M);
int left_len,maximum = 0,right_len,tmp,pre;
scanf("%d",&tmp);
left_len = tmp-1;
pre = tmp;
if(M == 1){
right_len = N-tmp;
printf("%d\n",max(left_len,right_len));
}else{
for(int i = 0; i < M-1; i++){
scanf("%d",&tmp);
maximum = max(maximum,tmp-pre);
pre = tmp;
}
right_len = N-tmp;
printf("%d\n",max(max(left_len,right_len),maximum/2));
}
return 0;
} |
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}
int N,M;
int dp[111111];
signed main(){
cin>>N>>M;
fill_n(dp,N,1<<25);
rep(i,M){
int a;
cin>>a;
dp[--a]=0;
}
reps(i,1,N)chmin(dp[i],dp[i-1]+1);
for(int i=N-2;i>=0;i--)chmin(dp[i],dp[i+1]+1);
cout<<*max_element(dp,dp+N)<<endl;
return 0;
} |
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<iostream>
#include<iomanip>
#include<string>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<vector>
#include<iomanip>
using namespace std;
int main() {
int n,m;
cin >> n >> m;
int count = 0;
int input;
int ex;
for(int i=0; i<m; i++) {
cin >> input;
if(i == 0 && input-1 > count) count = input-1;
if(i == m-1 && n-input > count) count = n-input;
if(i != 0 && (input-ex)/2 > count) count = (input-ex)/2;
ex=input;
}
cout << count << endl;
return 0;
} |
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int n ;
int m;
int a[100000];
int b;
int ans = 0;
cin >> n >> m;
for (int i = 0; i < m; i++){
cin >> a[i];
}
for (int i = 0; i < m + 1; i++){
if (i == 0){
b = a[i] - 1;
} else if (i == m){
b = n - a[i - 1];
}
else{
b = a[i] - a[i-1] - 1;
if (b % 2 == 0){
b /= 2;
}
else{
b++;
b /= 2;
}
}
ans = max(b, ans);
}
cout << ans << endl;
return 0;
} |
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
using namespace std;
int main(void)
{
int n,m;
cin >> n >> m;
vector<int> se;
se.resize(m);
REP(i,m) cin >> se[i];
int answer=0;
answer=max(answer,se[0]-1);
REP(i,m-1) answer=max(answer,(se[i+1]-se[i])/2);
answer=max(answer,n-se[m-1]);
cout << answer << endl;
return 0;
} |
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
int main() {
int n; int m;
while(~scanf("%d%d", &n, &m)) {
vector<int> a(m);
for(int i = 0; i < m; ++ i)
scanf("%d", &a[i]), -- a[i];
int ans = max(a[0], n - 1 - a[m-1]);
rep(i, m - 1)
amax(ans, (a[i + 1] - a[i]) / 2);
printf("%d\n", ans);
}
return 0;
} |
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define rep(i,x) for(int i=0;i<(x);++i)
#define rep1(i,x) for(int i=1;i<=(x);++i)
#define rrep(i,x) for(int i=(x)-1;i>=0;--i)
#define rrep1(i,x) for(int i=(x);i>=1;--i)
#define FOR(i,a,x) for(int i=(a);i<(x);++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T get(){T a;cin>>a;return a;}
template<typename T>T rev(T a){reverse(all(a));return a;}
template<typename T>istream&operator>>(istream&is,vector<T>&vec){rep(i,vec.size())is>>vec[i];return is;}
template<typename T>vector<T>&sort(vector<T>&a){sort(all(a));return a;}
const int inf = 1e9;
const ll linf = 3e18;
const double eps = 1e-9;
int dx[2] = {-1, 1};
int a[100000];
signed main()
{
omajinai;
int N, M; cin >> N >> M;
memset(a, -1, sizeof(a));
queue<int> q;
rep(i, M) {
int b; cin >> b; b--;
a[b] = 0;
q.push(b);
}
int ma = 0;
while (q.size()) {
int x = q.front(); q.pop();
rep(i, 2) {
int nx = x + dx[i];
if (0 <= nx && nx < N) {
if (~a[nx]) continue;
a[nx] = a[x] + 1;
q.push(nx);
ma = max(ma, a[nx]);
}
}
}
cout << ma << endl;
} |
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
set<int> ok;
for(int i = 0; i < m; ++i) {
int a;
cin >> a;
ok.emplace(a);
}
int ans = 0;
for(int i = 1; i <= n; ++i) {
auto it = ok.lower_bound(i);
int mn = INT_MAX;
if(it != ok.end()) {
mn = min(mn, *it - i);
}
if(it != ok.begin()) {
--it;
mn = min(mn, i - *it);
}
ans = max(ans, mn);
}
cout << ans << endl;
return 0;
} |
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main()
{
int n, m;
cin >> n >> m;
vector<int> A;
A.push_back(1);
int a;
for(int i = 1; i <= m; i++)
{
cin >> a;
A.push_back(a);
}
A.push_back(n);
int ans = 0;
for(int i = 1; i < A.size(); i++)
{
int tmp;
if(i == 1 || i == A.size() - 1)
tmp = A[i] - A[i - 1];
else
tmp = (A[i] - A[i - 1]) / 2;
ans = max(tmp, ans);
}
cout << ans << endl;
return 0;
}
|
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
struct init {
init() {
cin.tie(0);
ios::sync_with_stdio(false);
}
} ________init;
int main() {
int n, m;
cin >> n >> m;
vector<int> a(m);
for (auto& it : a) {
cin >> it;
}
int res = 0;
res = max(res, n - a[m - 1]);
res = max(res, a[0] - 1);
for (int i = 1; i < m; i++) {
res = max(res, (a[i] - a[i - 1] + 1) / 2);
}
cout << res << endl;
return 0;
}
|
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
static const long long INF = 1LL << 61LL;
int N, M;
int A[100010];
int temp = 1;
int ans;
int main() {
cin >> N >> M;
for (int i = 0; i < M; ++i) {
int a;
cin >> a;
A[a] = 1;
}
for (int i = 1; i <= N; ++i) {
if (A[i] == 1) {
int t = (i - temp - 1) / 2;
if ((i - temp - 1) % 2 != 0) t++;
temp = i;
ans = max(ans, t);
} else if (i == N) {
ans = max(ans, N - temp);
}
}
cout << ans << endl;
}
|
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int sum;
while (cin >> sum) {
int number, info[100005], ans;
cin >> number;
for (int i = 0; i < number; i++) {
cin >> info[i];
}
if (sum == number) {
cout << '0' << endl;
} else {
for (int i = 0; i < number + 1; i++) {
if (!i) {
ans = info[i] - 1;
} else if (i == number) {
ans = max(ans, sum - info[i - 1]);
} else {
int a = (info[i] - info[i - 1] - 1) / 2;
if (!a) a++;
ans = max(ans, a);
}
}
cout << ans << endl;
}
}
}
|
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
long long esp_org, esp_new;
int deg[100010];
vector<int> g[100010];
set<int> A, B;
int N;
void rekkyo(int x, int p) {
A.erase(x);
B.insert(x);
for (auto e : g[x]) {
if (e != p) {
rekkyo(e, x);
}
}
}
int subtree(int x, int p) {
int ans = 0;
for (auto e : g[x]) {
if (e != p) {
int sz = subtree(e, x);
ans += sz;
if (N - sz == sz) {
deg[e]--;
deg[x]--;
rekkyo(e, x);
}
}
}
return ans + 1;
}
int u, v;
bool check(set<int> A) {
int X;
if (A.count(u))
X = u;
else
X = v;
if (deg[X] != 1) return false;
int D[3] = {};
for (auto a : A) {
if (deg[a] != 1 && deg[a] != 2) return false;
D[deg[a]]++;
}
return D[1] == 2;
}
int _main() {
cin >> N;
cin >> u >> v;
u--, v--;
for (int i = 0; i < N; i++) A.insert(i);
for (int i = 0; i < N - 1; i++) {
int a, b;
cin >> a >> b;
--a, --b;
g[a].push_back(b);
g[b].push_back(a);
deg[a]++;
deg[b]++;
}
subtree(0, -1);
if (A.size() != B.size()) {
cout << "No" << endl;
return 0;
}
if (A.count(u) && A.count(v) || A.count(u) && A.count(v))
cout << "No" << endl;
else if (check(A) && check(B)) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
int main() {
const int size = 256 * 1024 * 1024;
void *p = malloc(size);
esp_new = (long long)p + size - 1;
__asm__("mov %rsp, esp_org");
__asm__("mov esp_new, %rsp");
_main();
__asm__("mov esp_org, %rsp");
}
|
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | /*
N???2??????
t???+-2pi/n
a????????§in space???FFT?????????
*/
typedef double D;
typedef complex<D> P;
D pi=acos(-1);
void FFT(vector<P>& a,int N,double t){
for(int m=N;m>=2;m/=2){
int mh=m/2;
rep(i,mh){
P w=polar(1.0,t*i);
for(int j=i;j<N;j+=m){
int k=j+mh;
P x=a[j]-a[k];
a[j]+=a[k];
a[k]=w*x;
}
}
t*=2;
}
int i=0;
rep1(j,N-2){
for(int k=N/2;k>(i^=k);k/=2);
if(j<i) swap(a[i],a[j]);
}
}
vector<P> conv(vector<P> a,vector<P> b){
int n=a.size()+b.size();
int N=1;
while(N<n) N*=2;
a.resize(N);
b.resize(N);
FFT(a,N,2*pi/N);
FFT(b,N,2*pi/N);
rep(i,N) a[i]*=b[i];
FFT(a,N,-2*pi/N);
rep(i,N) a[i]/=N;
return a;
} |
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | /*
suffix array
sa[i]= i??????????°???????suffix???????????????index (sa[0]=N)
_k,_N?????°????????????????????£?????????(compare???2?????°???????????????)
RMQ??¨????????° s?????§????????????t?????????????????´??? ???????????????????????????(jag2014summerday4F)
lcp[i]= len of common prefix of s[sa[i]..],s[sa[i+1]..]
????§????RMQ???????????°?????????substring???common prefix?????????????????????
*/
const int MAX_N=;
int _k,_N,_rank[MAX_N+1],tmp[MAX_N+1],sa[MAX_N+1],lcp[MAX_N];
bool compare_sa(int i,int j){
if(_rank[i]!=_rank[j]) return _rank[i]<_rank[j];
else{
int ri= i+_k<=_N ? _rank[i+_k] : -1;
int rj= j+_k<=_N ? _rank[j+_k] : -1;
return ri<rj;
}
}
void make_sa(string s){ //(string s,int *sa)
_N=s.length();
rep(i,_N+1){
sa[i]=i;
_rank[i]= i<_N?s[i]:-1;
}
for(_k=1;_k<=_N;_k*=2){
sort(sa,sa+_N+1,compare_sa);
tmp[sa[0]]=0;
rep1(i,_N){
tmp[sa[i]]=tmp[sa[i-1]]+( compare_sa(sa[i-1],sa[i]) ? 1 : 0 );
}
rep(i,_N+1) _rank[i]=tmp[i];
}
}
void make_lcp(string s){
int N=s.length();
rep(i,N+1) _rank[sa[i]]=i;
int h=0;
lcp[0]=0;
rep(i,N){
int j=sa[_rank[i]-1];
if(h>0) h--;
for(;j+h<N&&i+h<N;h++){
if(s[j+h]!=s[i+h]) break;
}
lcp[_rank[i]-1]=h;
}
} |
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int n;
int m;
int a[100000];
int b;
int ans = 0;
int main() {
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> a[i];
}
for (int i = 0; i < m + 1; i++) {
if (i == 0) {
b = a[i] - 1;
} else if (i == m) {
b = n - a[i];
} else {
b = a[i + 1] - a[i] - 1;
if (b % 2 == 0) {
b /= 2;
} else {
b--;
b /= 2;
}
}
ans = max(b, ans);
}
cout << ans << endl;
return 0;
}
|
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
static const long long INF = 1LL << 61LL;
int N, M;
int A[100010];
int temp = 1;
int ans;
int main() {
cin >> N >> M;
for (int i = 0; i < M; ++i) {
int a;
cin >> a;
A[a] = 1;
}
for (int i = 1; i <= N; ++i) {
if (A[i] == 1) {
if (temp == 1 && A[1] != 1) {
int t = (i - temp);
temp = i;
ans = max(ans, t);
continue;
}
int t = (i - temp - 1) / 2;
if (t <= 0)
t = 0;
else if ((i - temp - 1) % 2 != 0)
t++;
temp = i;
ans = max(ans, t);
} else if (i == N) {
ans = max(ans, N - temp);
}
}
cout << ans << endl;
}
|
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, a = 0, b = 0;
cin >> n >> m;
int ans = 0;
for (int(i) = (0); i < (m); i++) {
cin >> a;
ans = max(a - b, ans);
b = a;
}
if (ans / 2 < n - a)
cout << n - a << endl;
else
cout << ans / 2 << endl;
return 0;
}
|
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main(void) {
long long n, m, a[100000], x[100000];
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> a[i];
}
for (int j = 0; j < n; j++) {
x[j] = 0;
for (int i = 0; i < m; i++) {
if (j == a[i] - 1) {
x[j] = 1;
}
}
}
int gg = 0, dame[100000];
for (long long j = 0; j < n; j++) {
dame[j] = 0;
}
for (long long k = 1; k < 100000; k++) {
for (long long j = 0; j < n; j++) {
if (x[j] == 1 && dame[j] != -1) {
if (j != 0 && j != n - 1) {
if (x[j + 1] == 0) {
x[j + 1] = 1;
dame[j + 1] = -1;
}
if (x[j - 1] == 0) {
x[j - 1] = 1;
dame[j - 1] = -1;
}
} else if (j == 0) {
if (x[j + 1] == 0) {
x[j + 1] = 1;
dame[j + 1] = -1;
}
} else {
if (x[j - 1] == 0) {
x[j - 1] = 1;
dame[j - 1] = -1;
}
}
}
}
for (long long j = 0; j < n; j++) {
if (x[j] != 1) {
break;
} else if (j == n - 1) {
gg++;
break;
}
}
if (gg != 0) {
cout << k << endl;
break;
}
for (long long j = 0; j < n; j++) {
dame[j] = 0;
}
}
}
|
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | n, m = map(int, input().split())
a =[0] + list(map(int, input().split())) + [n]
t = max(a[0] - 1, n - a[-1])
for i in range(1, m):t = max(t, -((a[i - 1] - a[i]) // 2))
print(t)
|
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, A[100000], ans;
int i;
cin >> n >> m;
for (i = 0; i < m; i++) {
cin >> A[i];
if (m == 1) {
cout << max(n - A[0], A[0] - 1) << endl;
return -1;
} else if (m == 2 && i == 1) {
ans = max(A[0] - 1, n - A[1]);
ans = (ans, (A[1] - A[0]) / 2);
cout << ans << endl;
return -1;
} else {
if (i == 0) {
ans = A[0] - 1;
continue;
} else if (i = m - 1) {
ans = max(ans, n - A[m - 1]);
cout << ans << endl;
return 0;
} else {
ans = max(ans, A[i] - A[i - 1]);
}
}
}
return 0;
}
|
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
template <class X>
void print(X Target) {
cout << Target << '\n';
}
bool check[100001];
bool tmp[100001];
signed main() {
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int a;
cin >> a;
check[a] = true;
}
if (m == 1) {
print(n - m);
} else {
print(n / m);
}
return (0);
}
|
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
static const long long INF = 1LL << 61LL;
int N, M;
int A[100010];
int temp = 1;
int ans;
int main() {
cin >> N >> M;
for (int i = 0; i < M; ++i) {
int a;
cin >> a;
A[a] = 1;
}
for (int i = 1; i <= N; ++i) {
if (A[i] == 1) {
if (temp == 1 && A[1] != 1) {
int t = (i - temp);
temp = i;
ans = max(ans, t);
continue;
}
int t = (i - temp - 1) / 2;
if ((i - temp - 1) % 2 != 0) t++;
temp = i;
ans = max(ans, t);
} else if (i == N) {
ans = max(ans, N - temp);
}
}
cout << ans << endl;
}
|
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
bool ok(long long t, long long n, long long m, vector<long long> x) {
long long p = 0;
for (int i = 0; i < m; i++) {
if (p < x[i]) {
if (x[i] - p > t) {
return false;
}
p = max(x[i] + (t - 2 * (x[i] - p)) + 1, x[i] + (t - (x[i] - p)) / 2 + 1);
} else {
p = max(p, x[i] + t + 1);
}
if (p >= n) {
return true;
}
}
return false;
}
int main(void) {
int n, m;
cin >> n >> m;
vector<long long> x(m);
for (int i = 0; i < m; i++) {
cin >> x[i];
x[i]--;
}
if (n == m) {
cout << 0 << endl;
return 0;
}
long long l = 0;
long long r = 1e9;
while (r - l > 1) {
long long mid = (r + l) / 2;
if (ok(mid, n, m, x)) {
r = mid;
} else {
l = mid;
}
}
cout << r << endl;
}
|
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | n,m,*a=$<.read.split.map &:to_i;p [a[1]-1,*a.each_cons(2).map{|x,y|(y-x)/2},n-a[-1]].max |
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
using namespace std;
int main(void)
{
int n,m;
cin >> n >> m;
vector<int> se;
se.resize(m);
REP(i,m) cin >> se[i];
int answer=0;
answer=max(answer,se[0]-1);
REP(i,m-1) answer=max(se[i+1]-se[i]-1)/2;
answer=max(answer,n-se[m-1]);
cout << answer << endl;
return 0;
} |
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int sum;
while (cin >> sum) {
int number, info[10005], ans;
cin >> number;
for (int i = 0; i < number; i++) {
cin >> info[i];
}
for (int i = 0; i < number + 1; i++) {
if (!i) {
ans = info[i] - 1;
} else if (i == number) {
ans = max(ans, sum - info[i - 1]);
} else {
int a = (info[i] - info[i - 1]) / 2;
if (!a) a++;
ans = max(ans, a);
}
}
cout << ans << endl;
}
}
|
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
template <class X>
void print(X Target) {
cout << Target << '\n';
}
bool check[100001];
bool tmp[100001];
signed main() {
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
int a;
for (int i = 0; i < m; i++) {
cin >> a;
}
if (m == 1) {
print(n - a);
} else {
print(n / m);
}
return (0);
}
|
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | python3 | n, m = map(int, input().split())
a =list(map(int, input().split()))
t = max(a[0] - 1, n - a[-1])
for i in range(1, m):t = max(t, -((a[i - 1] - a[i]) // 2))
print(t)
|
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
for (long long i = 0; i < (long long)(v.size()); i++)
os << v[i] << (i != v.size() - 1 ? " " : "\n");
return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
for (long long i = 0; i < (long long)(v.size()); i++) is >> v[i];
return is;
}
bool solve() {
int n, m;
cin >> n >> m;
vector<int> a(m);
cin >> a;
int ans = max(a[0] - 1, n - a.back());
for (long long i = 0; i < (long long)(m - 1); i++) {
ans = max(ans, (a[i + 1] - a[i]) / 2);
}
cout << ans << endl;
return false;
}
int main() {
ios::sync_with_stdio(false);
while (solve())
;
return 0;
}
|
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | n,m,*a=$<.read.split.map &:to_i;p [a[1]-1]+a.each_cons(2).map{|x,y|(y-x+1)/2}+[n-a[-1]] |
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
const double PI = acos(-1);
const double EPS = 1e-10;
const int inf = 1e8;
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> in(m);
for (int i = 0; i < m; i++) cin >> in[i];
int ma = in[0] - 1;
for (int i = 0; i < m; i++) {
int q = in[i + 1] - in[i];
q /= 2;
ma = max(ma, q);
}
ma = max(ma, n - in[m - 1]);
cout << ma << endl;
}
|
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | https://www.slideshare.net/cocoa_chan/rupc2016-day2-d?qid=1931cae0-cc15-435b-ba12-0e9bc5aeb296&v=&b=&from_search=1 |
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
static const long long INF = 1LL << 61LL;
int N, M;
int A[100010];
int temp = 1;
int ans;
int main() {
cin >> N >> M;
for (int i = 0; i < M; ++i) {
int a;
cin >> a;
A[a] = 1;
}
for (int i = 1; i <= N; ++i) {
if (A[i] == 1) {
int t = (i - temp - 1) / 2;
if ((i - temp) % 2 == 0) t++;
temp = i;
ans = max(ans, t);
} else if (i == N) {
ans = max(ans, N - temp);
}
}
cout << ans << endl;
}
|
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | UNKNOWN | n,m,*a=$<.read.split.map &:to_i;p [a[1]-1,*a.each_cons(2).map{|x,y|(y-x+1)/2},n-a[-1]].max |
p01059 Gossip | Problem
N idols, numbered from 1 to n in order, are lined up in a row.
Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1.
At time 0, m idols with numbers a1, a2, ..., am have secret information. Find the minimum amount of time all idols can get confidential information.
Constraints
* 2 ≤ n ≤ 105
* 1 ≤ m ≤ n
* 1 ≤ ai ≤ n
* All ai values are different
* ai are given in ascending order
Input
The input is given in the following format.
n m
a1 a2 ... am
Two integers n and m are given on the first line, separated by blanks.
On the second line, m integers a1, a2, ..., am are given, separated by blanks.
Output
Outputs the minimum time that information is transmitted to all idles on one line.
Examples
Input
3 2
1 3
Output
1
Input
10 3
2 5 7
Output
3
Input
10 5
2 5 6 8 10
Output
1
Input
100000 1
1
Output
99999 | {
"input": [
"10 3\n2 5 7",
"100000 1\n1",
"10 5\n2 5 6 8 10",
"3 2\n1 3"
],
"output": [
"3",
"99999",
"1",
"1"
]
} | {
"input": [],
"output": []
} | IN-CORRECT | cpp | #include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;
int a[100000];
int main(){
int n, m; cin >> n >> m;
int ans = 0;
rep(i, m) cin >> a[i];
rep(i, m - 1) ans = max(ans, (a[i + 1] - a[i]) / 2);
ans = max(ans, a[i] - 1);
ans = max(ans, n - a[i]);
cout << ans << endl;
return 0;
} |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.