problem_id
stringlengths
6
6
language
stringclasses
2 values
original_status
stringclasses
3 values
original_src
stringlengths
19
243k
changed_src
stringlengths
19
243k
change
stringclasses
3 values
i1
int64
0
8.44k
i2
int64
0
8.44k
j1
int64
0
8.44k
j2
int64
0
8.44k
error
stringclasses
270 values
stderr
stringlengths
0
226k
p02597
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define eps 1e-6 #define ll long long #define IOS \ cin.sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); // #define int long long #define MEM(x, y) memset(x, y, sizeof(x)) #define rep(i, a, n) for (int i = a; i < n; i++) #define fi first #define se second #define endl "\n" #define pii pair<int, int> #define fi first #define se second const ll mod = 1000000007; const int inf = 0x3f3f3f3f; const ll INF = 0x3f3f3f3f3f3f3f3f; ll Max(ll a, ll b) { return a >= b ? a : b; } ll Min(ll a, ll b) { return a <= b ? a : b; } ll qpow(ll a, ll b) { ll s = 1; while (b > 0) { if (b % 2 == 1) { s = s * a; } a = a * a; b = b >> 1; } return s; } ll qpowmod(ll a, ll b, ll c) { ll res, t; res = 1; t = a % c; while (b) { if (b & 1) { res = res * t % c; } t = t * t % c; b >>= 1; } return res; } ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } inline long long read() { long long k = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { k = k * 10 + ch - '0'; ch = getchar(); } return k * f; } inline void write(long long x) { if (x < 0) x = -x, putchar('-'); if (x > 9) write(x / 10); putchar(x % 10 + '0'); } using namespace std; // head file int main() { int n; cin >> n; string ss; cin >> ss; int cnt = 0; int st = 0, ed = ss.size() - 1; while (st <= ed) { if (ss[st] == 'W' && ss[ed] == 'R') { cnt++; st++; ed--; } if (ss[st] == 'R' && ss[ed] == 'R') { st++; } if (ss[st] == 'W' && ss[ed] == 'W') { ed--; } } cout << cnt << endl; return 0; }
#include <bits/stdc++.h> #define eps 1e-6 #define ll long long #define IOS \ cin.sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); // #define int long long #define MEM(x, y) memset(x, y, sizeof(x)) #define rep(i, a, n) for (int i = a; i < n; i++) #define fi first #define se second #define endl "\n" #define pii pair<int, int> #define fi first #define se second const ll mod = 1000000007; const int inf = 0x3f3f3f3f; const ll INF = 0x3f3f3f3f3f3f3f3f; ll Max(ll a, ll b) { return a >= b ? a : b; } ll Min(ll a, ll b) { return a <= b ? a : b; } ll qpow(ll a, ll b) { ll s = 1; while (b > 0) { if (b % 2 == 1) { s = s * a; } a = a * a; b = b >> 1; } return s; } ll qpowmod(ll a, ll b, ll c) { ll res, t; res = 1; t = a % c; while (b) { if (b & 1) { res = res * t % c; } t = t * t % c; b >>= 1; } return res; } ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } inline long long read() { long long k = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { k = k * 10 + ch - '0'; ch = getchar(); } return k * f; } inline void write(long long x) { if (x < 0) x = -x, putchar('-'); if (x > 9) write(x / 10); putchar(x % 10 + '0'); } using namespace std; // head file int main() { int n; cin >> n; string ss; cin >> ss; int cnt = 0; int st = 0, ed = ss.size() - 1; while (st <= ed) { if (ss[st] == 'W' && ss[ed] == 'R') { cnt++; st++; ed--; } if (ss[st] == 'R' && ss[ed] == 'R') { st++; } if (ss[st] == 'W' && ss[ed] == 'W') { ed--; } if (ss[st] == 'R' && ss[ed] == 'W') { st++; ed--; } } cout << cnt << endl; return 0; }
insert
90
90
90
94
TLE
p02597
C++
Runtime Error
#include <algorithm> #include <iostream> #include <iterator> #include <map> #include <set> #include <string> #include <vector> using namespace std; int main() { string str; int N, i, j, count = 0; cin >> N >> str; i = 0; j = N - 1; while (i < j) { if (str[i] == 'W' && str[j] == 'R') { count += 1; i += 1; j -= 1; } else if (str[i] == 'W' && str[j] == 'W') { j -= 1; } else if (str[i] == 'R' && str[j] == 'R') { i += 1; } else { i -= 1; j -= 1; } } cout << count << endl; }
#include <algorithm> #include <iostream> #include <iterator> #include <map> #include <set> #include <string> #include <vector> using namespace std; int main() { string str; int N, i, j, count = 0; cin >> N >> str; i = 0; j = N - 1; while (i < j) { if (str[i] == 'W' && str[j] == 'R') { count += 1; i += 1; j -= 1; } else if (str[i] == 'W' && str[j] == 'W') { j -= 1; } else if (str[i] == 'R' && str[j] == 'R') { i += 1; } else { i += 1; j -= 1; } } cout << count << endl; }
replace
25
26
25
26
0
p02597
C++
Runtime Error
#include <algorithm> #include <iostream> #include <queue> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) using ll = long long; int N; string str; int S[200001]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> N; cin >> str; rep(i, N) S[i] = str[i] == 'R' ? 0 : 1; int numzero = 0; int numswap = 0; rep(i, N) if (S[i] == 0) numzero++; rep(i, numzero) if (S[i] == 1) numswap++; int ans = numswap; int count = 0; for (int x = -1; x < N; x++) { if (x >= 0 && S[x] == 1) { // S[x] = 0; numzero--; count++; if (x != numzero && S[numzero] == 1) numswap--; } int cnt = count; int ns = numswap; int nz = numzero; int y = N; ans = min(ans, cnt + ns); } cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> #include <queue> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) using ll = long long; int N; string str; int S[200001]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> N; cin >> str; rep(i, N) S[i] = str[i] == 'R' ? 0 : 1; int numzero = 0; int numswap = 0; rep(i, N) if (S[i] == 0) numzero++; rep(i, numzero) if (S[i] == 1) numswap++; int ans = numswap; cout << ans << endl; return 0; }
delete
25
40
25
25
0
p02597
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, cnt = 0, res = 0; string s; cin >> n >> s; int k = n - 1; for (int i = 0; i < n; i++) { if (s[i] == 'W') cnt++; } while (s[k] != 'R' && k > 0) k--; for (int i = n - cnt - k; i < n; i++) { if (s[i] == 'R') res++; } cout << min(res, cnt + k - 1); }
#include <bits/stdc++.h> using namespace std; int main() { int n, cnt = 0, res = 0; string s; cin >> n >> s; int k = n - 1; for (int i = 0; i < n; i++) { if (s[i] == 'W') cnt++; } while (s[k] != 'R' && k > 0) k--; for (int i = n - cnt; i < n; i++) { if (s[i] == 'R') res++; } cout << min(res, cnt + k - 1); }
replace
14
15
14
15
0
p02597
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); \ cout.precision(30); #define ll long long #define pi 3.14159265359 using namespace std; int main() { IOS; int n; cin >> n; string s; cin >> s; int i = 0, j = n - 1; int c = 0; while (i < n && j >= 0 && i < j) { while (i < n && s[i] == 'R') i++; while (j >= 0 && s[j] == 'W') j++; if (i < n && j >= 0 && i < j) { swap(s[i], s[j]); c++; } } cout << c; return 0; }
#include <bits/stdc++.h> #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); \ cout.precision(30); #define ll long long #define pi 3.14159265359 using namespace std; int main() { IOS; int n; cin >> n; string s; cin >> s; int i = 0, j = n - 1; int c = 0; while (i < n && j >= 0 && i < j) { while (i < n && s[i] == 'R') i++; while (j >= 0 && s[j] == 'W') j--; if (i < n && j >= 0 && i < j) { swap(s[i], s[j]); c++; } } cout << c; return 0; }
replace
22
23
22
23
TLE
p02597
C++
Time Limit Exceeded
// const int N=1e5; #define INF 1e9 #include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double int n; string s; void sol() { cin >> n; cin >> s; int red = 0, w = 0, swp = 0; for (int i = 0; i < n; ++i) { if (s[i] == 'W') ++w; else ++red; } int cnt = min(red, w); for (int i = 0; i < n; ++i) { if (s[i] == 'W') { for (int j = n - 1; j > i; --j) { if (s[j] == 'R') { s[j] = 'W'; ++swp; break; } } } } cnt = min(cnt, swp); cout << cnt << "\n"; } int main() { ios::sync_with_stdio(false); cin.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t = 1; // cin >> t; while (t--) { sol(); } return 0; }
// const int N=1e5; #define INF 1e9 #include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double int n; string s; void sol() { cin >> n; cin >> s; int red = 0, w = 0, swp = 0; for (int i = 0; i < n; ++i) { if (s[i] == 'W') ++w; else ++red; } int cnt = min(red, w); for (int i = 0; i < red; ++i) { if (s[i] == 'W') ++swp; } cnt = min(cnt, swp); cout << cnt << "\n"; } int main() { ios::sync_with_stdio(false); cin.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t = 1; // cin >> t; while (t--) { sol(); } return 0; }
replace
20
30
20
23
TLE
p02597
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <fstream> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef long long ll; const double EPS = 1e-9; typedef vector<int> vint; typedef pair<int, int> pint; #define rep(i, n) REP(i, 0, n) #define ALL(v) v.begin(), v.end() #define MSG(a) cout << #a << " " << a << endl; #define REP(i, x, n) for (int i = x; i < n; i++) template <class T, class C> void chmax(T &a, C b) { a > b ?: a = b; } template <class T, class C> void chmin(T &a, C b) { a < b ?: a = b; } int main() { ll N; cin >> N; priority_queue<ll> R; priority_queue<ll, vector<ll>, greater<ll>> W; for (ll i = 0; i < N; i++) { char c; cin >> c; if (c == 'R') R.push(i); else if (c == 'W') W.push(i); } if (R.size() == 0 || W.size() == 0) { cout << "0" << endl; } ll cnt = 0; while (1) { ll r = R.top(); ll w = W.top(); if (r > w) { R.pop(); W.pop(); R.push(w); W.push(r); cnt++; } else { break; } } cout << cnt << endl; }
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <fstream> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef long long ll; const double EPS = 1e-9; typedef vector<int> vint; typedef pair<int, int> pint; #define rep(i, n) REP(i, 0, n) #define ALL(v) v.begin(), v.end() #define MSG(a) cout << #a << " " << a << endl; #define REP(i, x, n) for (int i = x; i < n; i++) template <class T, class C> void chmax(T &a, C b) { a > b ?: a = b; } template <class T, class C> void chmin(T &a, C b) { a < b ?: a = b; } int main() { ll N; cin >> N; priority_queue<ll> R; priority_queue<ll, vector<ll>, greater<ll>> W; for (ll i = 0; i < N; i++) { char c; cin >> c; if (c == 'R') R.push(i); else if (c == 'W') W.push(i); } if (R.size() == 0 || W.size() == 0) { cout << "0" << endl; return 0; } ll cnt = 0; while (1) { ll r = R.top(); ll w = W.top(); if (r > w) { R.pop(); W.pop(); R.push(w); W.push(r); cnt++; } else { break; } } cout << cnt << endl; }
insert
50
50
50
51
0
p02597
C++
Time Limit Exceeded
#include <iostream> #include <string> using namespace std; int main(void) { int N; cin >> N; char c[N + 1]; c[0] = 'R'; for (int i = 1; i <= N; i++) { cin >> c[i]; } int counter = 0; int numBeforeAllRed = 0; for (int i = N; i != 1; i--) { if (c[i] == 'R') { if (numBeforeAllRed > 0) { if (i > numBeforeAllRed) { counter++; } else { break; } } else { for (int j = 1; j < i; j++) { numBeforeAllRed = j; if (c[j] == 'W') { c[j] = 'R'; c[i] = 'W'; counter++; numBeforeAllRed = 0; break; } } } } } cout << counter << "\n"; }
#include <iostream> #include <string> using namespace std; int main(void) { int N; cin >> N; char c[N + 1]; c[0] = 'R'; for (int i = 1; i <= N; i++) { cin >> c[i]; } int counter = 0; int numBeforeAllRed = 0; for (int i = 1; i <= N; i++) { if (c[i] == 'W') { counter++; } else { break; } } if (counter >= N / 2) { numBeforeAllRed = 1; } counter = 0; for (int i = N; i != 1; i--) { if (c[i] == 'R') { if (numBeforeAllRed > 0) { if (i > numBeforeAllRed) { counter++; } else { break; } } else { for (int j = 1; j < i; j++) { numBeforeAllRed = j; if (c[j] == 'W') { c[j] = 'R'; c[i] = 'W'; counter++; numBeforeAllRed = 0; break; } } } } } cout << counter << "\n"; }
insert
17
17
17
28
TLE
p02597
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long int #define ld long double #define f first #define s second #define pb push_back #define eb emplace_back #define mk make_pair #define mt make_tuple #define MOD 1000000007 #define fo(i, a, b) for (i = a; i < b; i++) #define foe(i, a, b) for (i = a; i <= b; i++) #define all(x) x.begin(), x.end() #define vi vector<int> #define vl vector<long long int> #define pii pair<int, int> #define pll pair<long long int, long long int> #define vpii vector<pair<int, int>> #define vpll vector<pair<long long int, long long int>> #define boost \ ios::sync_with_stdio(false); \ cin.tie(0) using namespace std; const int inf = 1e9 + 5; const ll inf64 = 1e18 + 5; int main() { boost; int n, i; cin >> n; string s; cin >> s; int r = 0, w = 0; for (char c : s) { if (c == 'R') r++; else w++; } int totr = 0, totw = 0; fo(i, 0, r) { if (s[i] == 'R') totr++; } for (i = s.size() - 1; i >= s.size() - w; i--) { if (s[i] == 'W') totw++; } cout << min(r - totr, w - totw); }
#include <bits/stdc++.h> #define ll long long int #define ld long double #define f first #define s second #define pb push_back #define eb emplace_back #define mk make_pair #define mt make_tuple #define MOD 1000000007 #define fo(i, a, b) for (i = a; i < b; i++) #define foe(i, a, b) for (i = a; i <= b; i++) #define all(x) x.begin(), x.end() #define vi vector<int> #define vl vector<long long int> #define pii pair<int, int> #define pll pair<long long int, long long int> #define vpii vector<pair<int, int>> #define vpll vector<pair<long long int, long long int>> #define boost \ ios::sync_with_stdio(false); \ cin.tie(0) using namespace std; const int inf = 1e9 + 5; const ll inf64 = 1e18 + 5; int main() { boost; int n, i; cin >> n; string s; cin >> s; int r = 0, w = 0; for (char c : s) { if (c == 'R') r++; else w++; } int totr = 0, totw = 0; fo(i, 0, r) { if (s[i] == 'R') totr++; } for (i = n - 1; i >= n - w; i--) { if (s[i] == 'W') totw++; } cout << min(r - totr, w - totw); }
replace
46
47
46
47
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> #include <algorithm> #include <iostream> #include <map> #include <math.h> #include <queue> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; bool possible(long long int mid, long long int arr[], long long int n, long long int k) { for (long long int i = 0; i < n; i++) { long long int p = arr[i]; if (k >= (p - 1) / mid) { k -= (p - 1) / mid; } else { return false; } } return true; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n; cin >> n; long long int k; cin >> k; long long int arr[n]; for (long long int i = 0; i < n; i++) cin >> arr[i]; long long int start = 0; long long int end = 1000000001; while (start < end) { long long int mid = start + (end - start) / 2; if (possible(mid, arr, n, k)) { end = mid; } else { start = mid + 1; } } cout << end << endl; return 0; }
#include <bits/stdc++.h> #include <algorithm> #include <iostream> #include <map> #include <math.h> #include <queue> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; bool possible(long long int mid, long long int arr[], long long int n, long long int k) { if (mid <= 0) return false; for (long long int i = 0; i < n; i++) { long long int p = arr[i]; if (k >= (p - 1) / mid) { k -= (p - 1) / mid; } else { return false; } } return true; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n; cin >> n; long long int k; cin >> k; long long int arr[n]; for (long long int i = 0; i < n; i++) cin >> arr[i]; long long int start = 0; long long int end = 1000000001; while (start < end) { long long int mid = start + (end - start) / 2; if (possible(mid, arr, n, k)) { end = mid; } else { start = mid + 1; } } cout << end << endl; return 0; }
insert
16
16
16
18
0
p02598
C++
Runtime Error
#pragma GCC target("sse4.2") #include <bits/stdc++.h> using namespace std; #define F first #define S second #define PB push_back #define ln "\n" #define forn(i, e) for (ll i = 0; i < e; i++) #define forsn(i, s, e) for (ll i = s; i < e; i++) #define rforn(i, e) for (ll i = e; i >= 0; i--) #define rforsn(i, e, s) for (ll i = e; i >= s; i--) #define vasort(v) sort(v.begin(), v.end()); #define vdsort(v) sort(v.begin(), v.end(), greater<ll>()); #define fio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) #define mem(a, b) memset(a, b, sizeof(a)) #define sz(x) ((int)size(x)) #define EB emplace_back #define flush fflush(stdout) #define out1(x1) cout << x1 << ln #define out2(x1, x2) cout << x1 << " " << x2 << endl #define out3(x1, x2, x3) cout << x1 << " " << x2 << " " << x3 << ln #define out4(x1, x2, x3, x4) \ cout << x1 << " " << x2 << " " << x3 << " " << x4 << ln #define all(d) d.begin(), d.end() #define unordered_set(T) unordered_set<T, custom_hash> #define unordered_map(T1, T2) unordered_map<T1, T2, custom_hash> #define in1(x1) cin >> x1 #define in2(x1, x2) cin >> x1 >> x2 #define in3(x1, x2, x3) cin >> x1 >> x2 >> x3 #define in4(x1, x2, x3, x4) cin >> x1 >> x2 >> x3 >> x4 #define arrin(a, n) forn(i, n) cin >> a[i]; #define arrout(a, n) \ forn(i, n) { cout << a[i] << " "; } \ cout << ln; /* ---------------- IO ----------------*/ namespace IO { const int BUFFER_SIZE = 1 << 15; char input_buffer[BUFFER_SIZE]; int input_pos = 0, input_len = 0; char output_buffer[BUFFER_SIZE]; int output_pos = 0; char number_buffer[100]; uint8_t lookup[100]; void _update_input_buffer() { input_len = fread(input_buffer, sizeof(char), BUFFER_SIZE, stdin); input_pos = 0; if (input_len == 0) input_buffer[0] = EOF; } inline char next_char(bool advance = true) { if (input_pos >= input_len) _update_input_buffer(); return input_buffer[advance ? input_pos++ : input_pos]; } template <typename T> inline void read_int(T &number) { bool negative = false; number = 0; while (!isdigit(next_char(false))) if (next_char() == '-') negative = true; do { number = 10 * number + (next_char() - '0'); } while (isdigit(next_char(false))); if (negative) number = -number; } template <typename T, typename... Args> inline void read_int(T &number, Args &...args) { read_int(number); read_int(args...); } void _flush_output() { fwrite(output_buffer, sizeof(char), output_pos, stdout); output_pos = 0; } inline void write_char(char c) { if (output_pos == BUFFER_SIZE) _flush_output(); output_buffer[output_pos++] = c; } template <typename T> inline void write_int(T number, char after = '\0') { if (number < 0) { write_char('-'); number = -number; } int length = 0; while (number >= 10) { uint8_t lookup_value = lookup[number % 100]; number /= 100; number_buffer[length++] = (lookup_value & 15) + '0'; number_buffer[length++] = (lookup_value >> 4) + '0'; } if (number != 0 || length == 0) write_char(number + '0'); for (int i = length - 1; i >= 0; i--) write_char(number_buffer[i]); if (after) write_char(after); } void IOinit() { // Make sure _flush_output() is called at the end of the program. bool exit_success = atexit(_flush_output) == 0; assert(exit_success); for (int i = 0; i < 100; i++) lookup[i] = (i / 10 << 4) + i % 10; } } // namespace IO using namespace IO; /* ---------------- typedefs ----------------*/ typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vll; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); /* ---------------- utility functions ---------------- */ int dr[] = {0, 1, -1, 0, 1, -1, 1, -1}; int dc[] = {1, 0, 0, -1, 1, -1, -1, 1}; bool chk(int a, int b, int n, int m) { return 0 <= a && a < n && 0 <= b && b < m; } ll exp(ll n, ll m, ll md) { ll a = 1; while (m > 0) { if (m & 1) a = (a * n % md) % md; m /= 2; n = (n * n) % md; } return a % md; } void disp(vi v) { for (auto u : v) cout << u << " "; cout << "\n"; } void disp(vll v) { for (auto u : v) cout << u << " "; cout << "\n"; } int getSqr(int x) { if (x < 0) return -1; int l = sqrt(x); for (int i = -2; i <= 2; ++i) if (l + i >= 0 && (l + i) * (l + i) == x) return l; return -1; } const int NPRR = 1e7; vi lp; vector<int> prr; void prfac(int n = NPRR) { assert(n <= NPRR); lp.assign(n + 1, 0); int i; for (i = 2; i <= n; ++i) { if (lp[i] == 0) { lp[i] = i; prr.push_back(i); } for (int u : prr) { if (i * u > n || u > lp[i]) break; lp[i * u] = u; } } } bool check_composite_for_prime_function(ll n, ll a, ll d, int s) { ll x = exp(a, d, n); if (x == 1 || x == n - 1) return false; for (int r = 1; r < s; ++r) { x = x * x % n; x %= n; if (x == n - 1) return false; } return true; } bool prime(ll n) { if (n < 4) return n == 2 || n == 3; if (!(n & 1)) return false; int s = 0; ll d = n - 1; while (!(d & 1)) { d >>= 1; s++; } for (int a : {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37}) { if (n == a) return true; if (check_composite_for_prime_function(n, a, d, s)) return false; } return true; } ll binomialCoeff(ll n, ll k) { ll res = 1; // Since C(n, k) = C(n, n-k) if (k > n - k) k = n - k; // Calculate value of // [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1] for (ll i = 0; i < k; ++i) { res *= (n - i); res /= (i + 1); } return res; } /* custom hash for unordered map */ struct custom_hash { static uint64_t splitmix64(uint64_t x) { // http://xorshift.di.unimi.it/splitmix64.c x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; inline void read(int &x) { scanf("%d", &x); } /* ---------------- constants ---------------- */ const ll MAXn = 5e5 + 33, MAXlg = __lg(MAXn) + 2; const ll MOD = 1000000007; const ll INF = ll(1e15); /* ---------------- start of code ---------------- */ void go1() { ll n, k; cin >> n >> k; ll a[n]; forn(i, n) cin >> a[i]; ll l = 0, r = 1e9 + 1; ll ans = 1e9 + 10; while (l < r) { ll mid = (l + r) / 2; // check mid; ll p = 0; forn(i, n) { p += (a[i] + mid - 1) / mid - 1; if (p > k) break; } if (p <= k) { r = mid; // ans = min(ans, mid); } else { l = mid + 1; } } cout << r << ln; } int main() { fio; // cout<<fixed<<setprecision(25); // cerr<<fixed<<setprecision(10); auto start = std::chrono::high_resolution_clock::now(); // freopen("input.txt","r",stdin);freopen("output.txt","w",stdout); ll tt = 1; /* cin >> tt; ll t = tt; //*/ while (tt--) { // cout << "Case #" << t - tt << ": "; go1(); } auto stop = std::chrono::high_resolution_clock::now(); auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(stop - start); cerr << "Time taken : " << ((long double)duration.count()) / ((long double)1e9) << "s " << endl; return 0; } /* ---------------- end of code ---------------- */
#pragma GCC target("sse4.2") #include <bits/stdc++.h> using namespace std; #define F first #define S second #define PB push_back #define ln "\n" #define forn(i, e) for (ll i = 0; i < e; i++) #define forsn(i, s, e) for (ll i = s; i < e; i++) #define rforn(i, e) for (ll i = e; i >= 0; i--) #define rforsn(i, e, s) for (ll i = e; i >= s; i--) #define vasort(v) sort(v.begin(), v.end()); #define vdsort(v) sort(v.begin(), v.end(), greater<ll>()); #define fio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) #define mem(a, b) memset(a, b, sizeof(a)) #define sz(x) ((int)size(x)) #define EB emplace_back #define flush fflush(stdout) #define out1(x1) cout << x1 << ln #define out2(x1, x2) cout << x1 << " " << x2 << endl #define out3(x1, x2, x3) cout << x1 << " " << x2 << " " << x3 << ln #define out4(x1, x2, x3, x4) \ cout << x1 << " " << x2 << " " << x3 << " " << x4 << ln #define all(d) d.begin(), d.end() #define unordered_set(T) unordered_set<T, custom_hash> #define unordered_map(T1, T2) unordered_map<T1, T2, custom_hash> #define in1(x1) cin >> x1 #define in2(x1, x2) cin >> x1 >> x2 #define in3(x1, x2, x3) cin >> x1 >> x2 >> x3 #define in4(x1, x2, x3, x4) cin >> x1 >> x2 >> x3 >> x4 #define arrin(a, n) forn(i, n) cin >> a[i]; #define arrout(a, n) \ forn(i, n) { cout << a[i] << " "; } \ cout << ln; /* ---------------- IO ----------------*/ namespace IO { const int BUFFER_SIZE = 1 << 15; char input_buffer[BUFFER_SIZE]; int input_pos = 0, input_len = 0; char output_buffer[BUFFER_SIZE]; int output_pos = 0; char number_buffer[100]; uint8_t lookup[100]; void _update_input_buffer() { input_len = fread(input_buffer, sizeof(char), BUFFER_SIZE, stdin); input_pos = 0; if (input_len == 0) input_buffer[0] = EOF; } inline char next_char(bool advance = true) { if (input_pos >= input_len) _update_input_buffer(); return input_buffer[advance ? input_pos++ : input_pos]; } template <typename T> inline void read_int(T &number) { bool negative = false; number = 0; while (!isdigit(next_char(false))) if (next_char() == '-') negative = true; do { number = 10 * number + (next_char() - '0'); } while (isdigit(next_char(false))); if (negative) number = -number; } template <typename T, typename... Args> inline void read_int(T &number, Args &...args) { read_int(number); read_int(args...); } void _flush_output() { fwrite(output_buffer, sizeof(char), output_pos, stdout); output_pos = 0; } inline void write_char(char c) { if (output_pos == BUFFER_SIZE) _flush_output(); output_buffer[output_pos++] = c; } template <typename T> inline void write_int(T number, char after = '\0') { if (number < 0) { write_char('-'); number = -number; } int length = 0; while (number >= 10) { uint8_t lookup_value = lookup[number % 100]; number /= 100; number_buffer[length++] = (lookup_value & 15) + '0'; number_buffer[length++] = (lookup_value >> 4) + '0'; } if (number != 0 || length == 0) write_char(number + '0'); for (int i = length - 1; i >= 0; i--) write_char(number_buffer[i]); if (after) write_char(after); } void IOinit() { // Make sure _flush_output() is called at the end of the program. bool exit_success = atexit(_flush_output) == 0; assert(exit_success); for (int i = 0; i < 100; i++) lookup[i] = (i / 10 << 4) + i % 10; } } // namespace IO using namespace IO; /* ---------------- typedefs ----------------*/ typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vll; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); /* ---------------- utility functions ---------------- */ int dr[] = {0, 1, -1, 0, 1, -1, 1, -1}; int dc[] = {1, 0, 0, -1, 1, -1, -1, 1}; bool chk(int a, int b, int n, int m) { return 0 <= a && a < n && 0 <= b && b < m; } ll exp(ll n, ll m, ll md) { ll a = 1; while (m > 0) { if (m & 1) a = (a * n % md) % md; m /= 2; n = (n * n) % md; } return a % md; } void disp(vi v) { for (auto u : v) cout << u << " "; cout << "\n"; } void disp(vll v) { for (auto u : v) cout << u << " "; cout << "\n"; } int getSqr(int x) { if (x < 0) return -1; int l = sqrt(x); for (int i = -2; i <= 2; ++i) if (l + i >= 0 && (l + i) * (l + i) == x) return l; return -1; } const int NPRR = 1e7; vi lp; vector<int> prr; void prfac(int n = NPRR) { assert(n <= NPRR); lp.assign(n + 1, 0); int i; for (i = 2; i <= n; ++i) { if (lp[i] == 0) { lp[i] = i; prr.push_back(i); } for (int u : prr) { if (i * u > n || u > lp[i]) break; lp[i * u] = u; } } } bool check_composite_for_prime_function(ll n, ll a, ll d, int s) { ll x = exp(a, d, n); if (x == 1 || x == n - 1) return false; for (int r = 1; r < s; ++r) { x = x * x % n; x %= n; if (x == n - 1) return false; } return true; } bool prime(ll n) { if (n < 4) return n == 2 || n == 3; if (!(n & 1)) return false; int s = 0; ll d = n - 1; while (!(d & 1)) { d >>= 1; s++; } for (int a : {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37}) { if (n == a) return true; if (check_composite_for_prime_function(n, a, d, s)) return false; } return true; } ll binomialCoeff(ll n, ll k) { ll res = 1; // Since C(n, k) = C(n, n-k) if (k > n - k) k = n - k; // Calculate value of // [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1] for (ll i = 0; i < k; ++i) { res *= (n - i); res /= (i + 1); } return res; } /* custom hash for unordered map */ struct custom_hash { static uint64_t splitmix64(uint64_t x) { // http://xorshift.di.unimi.it/splitmix64.c x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; inline void read(int &x) { scanf("%d", &x); } /* ---------------- constants ---------------- */ const ll MAXn = 5e5 + 33, MAXlg = __lg(MAXn) + 2; const ll MOD = 1000000007; const ll INF = ll(1e15); /* ---------------- start of code ---------------- */ void go1() { ll n, k; cin >> n >> k; ll a[n]; forn(i, n) cin >> a[i]; ll l = 1, r = 1e9; // ll ans = 1e9+10; while (l < r) { ll mid = (l + r) / 2; // check mid; ll p = 0; forn(i, n) { p += (a[i] + mid - 1) / mid - 1; if (p > k) break; } if (p <= k) { r = mid; // ans = min(ans, mid); } else { l = mid + 1; } } cout << r << ln; } int main() { fio; // cout<<fixed<<setprecision(25); // cerr<<fixed<<setprecision(10); auto start = std::chrono::high_resolution_clock::now(); // freopen("input.txt","r",stdin);freopen("output.txt","w",stdout); ll tt = 1; /* cin >> tt; ll t = tt; //*/ while (tt--) { // cout << "Case #" << t - tt << ": "; go1(); } auto stop = std::chrono::high_resolution_clock::now(); auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(stop - start); cerr << "Time taken : " << ((long double)duration.count()) / ((long double)1e9) << "s " << endl; return 0; } /* ---------------- end of code ---------------- */
replace
277
279
277
279
0
Time taken : 5.2534e-05s
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int n, k; int arr[200010]; bool valid(int temp) { int count = 0; for (int i = 0; i < n; i++) { count += (arr[i] + temp - 1) / temp - 1; } if (count <= k) return true; else return false; } int main() { cin >> n >> k; for (int i = 0; i < n; i++) cin >> arr[i]; int l = -1, r = 1000000001; while (l + 1 < r) { int mid = (l + r) / 2; if (valid(mid)) r = mid; else l = mid; } cout << r << "\n"; }
#include <bits/stdc++.h> using namespace std; int n, k; int arr[200010]; bool valid(int temp) { int count = 0; for (int i = 0; i < n; i++) { count += (arr[i] + temp - 1) / temp - 1; } if (count <= k) return true; else return false; } int main() { cin >> n >> k; for (int i = 0; i < n; i++) cin >> arr[i]; int l = 0, r = 1000000001; while (l + 1 < r) { int mid = (l + r) / 2; if (valid(mid)) r = mid; else l = mid; } cout << r << "\n"; }
replace
18
19
18
19
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define SZ(a) ((int)(a).size()) int main() { #ifdef LOCAL freopen(".a.in", "r", stdin); #endif ios_base::sync_with_stdio(false), cout.tie(0), cin.tie(0); int n, k; cin >> n >> k; vector<int64_t> A(n); for (int i = 0; i < n; ++i) cin >> A[i]; for (int i = 0; i < n; ++i) A[i] *= 2; auto ok = [&](int64_t x) { int64_t c = 0; for (int i = 0; i < n; ++i) { if (A[i] % x == 0) c += A[i] / x - 1; else c += A[i] / x; } return c <= k; }; int64_t l = 0, r = 2e9; while (l < r) { int64_t mid = (l + r) >> 1; if (ok(mid)) { r = mid; } else { l = mid + 1; } } if (l % 2 == 0) cout << l / 2; else cout << (l + 1) / 2; return 0; } // 2020.08.02 20:31:43
#include <bits/stdc++.h> using namespace std; #define SZ(a) ((int)(a).size()) int main() { #ifdef LOCAL freopen(".a.in", "r", stdin); #endif ios_base::sync_with_stdio(false), cout.tie(0), cin.tie(0); int n, k; cin >> n >> k; vector<int64_t> A(n); for (int i = 0; i < n; ++i) cin >> A[i]; for (int i = 0; i < n; ++i) A[i] *= 2; auto ok = [&](int64_t x) { int64_t c = 0; for (int i = 0; i < n; ++i) { if (A[i] % x == 0) c += A[i] / x - 1; else c += A[i] / x; } return c <= k; }; int64_t l = 1, r = 2e9; while (l < r) { int64_t mid = (l + r) >> 1; if (ok(mid)) { r = mid; } else { l = mid + 1; } } if (l % 2 == 0) cout << l / 2; else cout << (l + 1) / 2; return 0; } // 2020.08.02 20:31:43
replace
25
26
25
26
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long #define ld long double #define FOR(x, y) for (ll i = x; i <= y; i++) #define pb(x) push_back(x) #define mp make_pair #define pii pair<int, int> #define pll pair<ll, ll> #define vii vector<int> #define vll vector<ll> #define matrix(x) vector<vector<x>> #define vss vector<string> #define PI (2 * acos(0.0)) #define sqr(x) ((x) * (x)) #define sf(a) scanf("%d", &a) #define sfl(a) scanf("%lld", &a) #define sff(a, b) scanf("%d %d", &a, &b) #define sffl(a, b) scanf("%lld %lld", &a, &b) #define sfff(a, b, c) scanf("%d %d %d", &a, &b, &c) #define sfffl(a, b, c) scanf("%lld %lld %lld", &a, &b, &c) #define ms(a, b) memset(a, b, sizeof(a)) #define ff first #define ss second #define lcm(a, b) ((a) * ((b) / __gcd(a, b))) #define all(a) a.begin(), a.end() #define readfile freopen("input.txt", "r", stdin); #define writefile freopen("output.txt", "w", stdout); #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define gap " " #define mx 104 #define inf (ll)1e9 #define WHITE 1 #define GRAY 2 #define BLACK 3 #define EMPTY_VALUE -1 #define mod 1000000007 #define MOD(a, b) (a % b + b) % b using namespace std; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cerr << x; } void __print(double x) { cerr << x; } void __print(long double x) { cerr << x; } void __print(char x) { cerr << '\'' << x << '\''; } void __print(const char *x) { cerr << '\"' << x << '\"'; } void __print(const string &x) { cerr << '\"' << x << '\"'; } void __print(bool x) { cerr << (x ? "true" : "false"); } template <typename T, typename V> void __print(const pair<T, V> &x) { cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}'; } template <typename T> void __print(const T &x) { int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}"; } void _print() { cerr << "]\n"; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); } #ifndef ONLINE_JUDGE #define debug(x...) \ cerr << "[" << #x << "] = ["; \ _print(x) #else #define debug(x...) #endif ll x, k; vll a; bool possible(ll mid) { ll cnt = 0; for (ll i = 0; i < x; i++) { if (a[i] <= mid) continue; // cnt += ceil(a[i]/(mid+0.0))-1; cnt += (a[i] - 1) / mid; } return cnt <= k; } int main() { // fastio sffl(x, k); a.resize(x + 1); for (ll i = 0; i < x; i++) sfl(a[i]); ll mini = 0, maxi = 1e9 + 100; while (mini < maxi) { ll mid = (mini + maxi) / 2; // cout<<mid<<endl; if (possible(mid)) { maxi = mid; } else { mini = mid + 1; } } cout << mini << endl; return 0; }
#include <bits/stdc++.h> #define ll long long #define ld long double #define FOR(x, y) for (ll i = x; i <= y; i++) #define pb(x) push_back(x) #define mp make_pair #define pii pair<int, int> #define pll pair<ll, ll> #define vii vector<int> #define vll vector<ll> #define matrix(x) vector<vector<x>> #define vss vector<string> #define PI (2 * acos(0.0)) #define sqr(x) ((x) * (x)) #define sf(a) scanf("%d", &a) #define sfl(a) scanf("%lld", &a) #define sff(a, b) scanf("%d %d", &a, &b) #define sffl(a, b) scanf("%lld %lld", &a, &b) #define sfff(a, b, c) scanf("%d %d %d", &a, &b, &c) #define sfffl(a, b, c) scanf("%lld %lld %lld", &a, &b, &c) #define ms(a, b) memset(a, b, sizeof(a)) #define ff first #define ss second #define lcm(a, b) ((a) * ((b) / __gcd(a, b))) #define all(a) a.begin(), a.end() #define readfile freopen("input.txt", "r", stdin); #define writefile freopen("output.txt", "w", stdout); #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define gap " " #define mx 104 #define inf (ll)1e9 #define WHITE 1 #define GRAY 2 #define BLACK 3 #define EMPTY_VALUE -1 #define mod 1000000007 #define MOD(a, b) (a % b + b) % b using namespace std; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cerr << x; } void __print(double x) { cerr << x; } void __print(long double x) { cerr << x; } void __print(char x) { cerr << '\'' << x << '\''; } void __print(const char *x) { cerr << '\"' << x << '\"'; } void __print(const string &x) { cerr << '\"' << x << '\"'; } void __print(bool x) { cerr << (x ? "true" : "false"); } template <typename T, typename V> void __print(const pair<T, V> &x) { cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}'; } template <typename T> void __print(const T &x) { int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}"; } void _print() { cerr << "]\n"; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); } #ifndef ONLINE_JUDGE #define debug(x...) \ cerr << "[" << #x << "] = ["; \ _print(x) #else #define debug(x...) #endif ll x, k; vll a; bool possible(ll mid) { if (mid <= 0) return false; ll cnt = 0; for (ll i = 0; i < x; i++) { if (a[i] <= mid) continue; // cnt += ceil(a[i]/(mid+0.0))-1; cnt += (a[i] - 1) / mid; } return cnt <= k; } int main() { // fastio sffl(x, k); a.resize(x + 1); for (ll i = 0; i < x; i++) sfl(a[i]); ll mini = 0, maxi = 1e9 + 100; while (mini < maxi) { ll mid = (mini + maxi) / 2; // cout<<mid<<endl; if (possible(mid)) { maxi = mid; } else { mini = mid + 1; } } cout << mini << endl; return 0; }
insert
91
91
91
93
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define pb push_back #define pf push_front #define all(t) t.begin(), t.end() #define inrange(i, a, b) (((i) >= min((a), (b))) && ((i) <= max((a), (b)))) typedef vector<ll> vi; typedef pair<ll, ll> pii; #define fi first #define se second #define upb upper_bound #define lwb lower_bound #define show(x) cout << #x << " is " << x << "\n"; const ll inf = 2e18; const ll mod = 1e9 + 7; const ld pi = 3.141592653589793238462643383279502884; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void print(ll a[], ll n) { for (ll i = 0; i < n; i++) { cout << a[i] << " "; } cout << "\n"; } ll power(ll x, ll y) { if (y <= 0) return 1; ll ans = 1; x %= mod; while (y) { if (y & 1) ans = (x * ans) % mod; x = (x * x) % mod; y >>= 1; } return ans; } ll modInverse(ll n) { return power(n, mod - 2); } inline ll mul(ll a, ll b) { return (a * b) % mod; } inline ll sub(ll a, ll b) { ll c = (a - b); if (c < 0) c += mod; return c; } inline ll add(ll a, ll b) { ll c = (a + b); if (c >= mod) c -= mod; return c; } inline ll divi(ll a, ll b) { return mul(a, modInverse(b)); } //------------------------------------------------------------------------------------------ const ll N = 2e5 + 1; // vector<ll> adj[N]; // bool visited[N]; ll n, k; ll a[N]; bool f(ll x) { int c = 0; for (int i = 0; i < n; i++) { if (a[i] % x == 0) { c += a[i] / x - 1; } else c += a[i] / x; } return c <= k; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout << fixed << setprecision(10); cin >> n >> k; ll ma = 0; for (int i = 0; i < n; i++) { cin >> a[i]; ma = max(ma, a[i]); } ll l = 0, r = ma; ll ans = 0; while (l <= r) { ll m = l + (r - l) / 2; if (f(m)) { ans = m; r = m - 1; } else l = m + 1; } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define pb push_back #define pf push_front #define all(t) t.begin(), t.end() #define inrange(i, a, b) (((i) >= min((a), (b))) && ((i) <= max((a), (b)))) typedef vector<ll> vi; typedef pair<ll, ll> pii; #define fi first #define se second #define upb upper_bound #define lwb lower_bound #define show(x) cout << #x << " is " << x << "\n"; const ll inf = 2e18; const ll mod = 1e9 + 7; const ld pi = 3.141592653589793238462643383279502884; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void print(ll a[], ll n) { for (ll i = 0; i < n; i++) { cout << a[i] << " "; } cout << "\n"; } ll power(ll x, ll y) { if (y <= 0) return 1; ll ans = 1; x %= mod; while (y) { if (y & 1) ans = (x * ans) % mod; x = (x * x) % mod; y >>= 1; } return ans; } ll modInverse(ll n) { return power(n, mod - 2); } inline ll mul(ll a, ll b) { return (a * b) % mod; } inline ll sub(ll a, ll b) { ll c = (a - b); if (c < 0) c += mod; return c; } inline ll add(ll a, ll b) { ll c = (a + b); if (c >= mod) c -= mod; return c; } inline ll divi(ll a, ll b) { return mul(a, modInverse(b)); } //------------------------------------------------------------------------------------------ const ll N = 2e5 + 1; // vector<ll> adj[N]; // bool visited[N]; ll n, k; ll a[N]; bool f(ll x) { int c = 0; for (int i = 0; i < n; i++) { if (a[i] % x == 0) { c += a[i] / x - 1; } else c += a[i] / x; } return c <= k; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout << fixed << setprecision(10); cin >> n >> k; ll ma = 0; for (int i = 0; i < n; i++) { cin >> a[i]; ma = max(ma, a[i]); } ll l = 1, r = ma; ll ans = 0; while (l <= r) { ll m = l + (r - l) / 2; if (f(m)) { ans = m; r = m - 1; } else l = m + 1; } cout << ans; return 0; }
replace
87
88
87
88
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> #define sz(v) ((int)(v).size()) #define all(v) ((v).begin()), ((v).end()) #define allr(v) ((v).rbegin()), ((v).rend()) #define pb push_back #define mp make_pair #define clr(v, d) memset(v, d, sizeof(v)) #define PI acos(-1) typedef long long ll; typedef unsigned long long ull; const double eps = (1e-9); using namespace std; int dcmp(long double a, long double b) { return fabsl(a - b) <= eps ? 0 : (a > b) ? 1 : -1; } int getBit(ll num, int idx) { return ((num >> idx) & 1ll) == 1; } int setBit1(int num, int idx) { return num | (1 << idx); } ll setBit0(ll num, int idx) { return num & ~(1ll << idx); } ll flipBit(ll num, int idx) { return num ^ (1ll << idx); } void GO() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int countNumBit1(int mask) { int ret = 0; while (mask) { mask &= (mask - 1); ++ret; } return ret; } const int N = 1000 + 5; vector<int> v[2]; int n, k, a[N]; bool check(int val) { ll tot = 0; for (int i = 0; i < n; i++) { int len = a[i]; int F = (len / val + (len % val != 0)) - 1; if (tot + F > k) return 0; tot += F; } return (tot <= k); } int BS(int l, int r) { int res = 0; while (l <= r) { ll mid = (l + r) / 2; if (check(mid)) { r = mid - 1; res = mid; } else { l = mid + 1; } } return res; } int main() { GO(); int T; T = 1; // cin>>T; while (T--) { cin >> n >> k; for (int i = 0; i < n; i++) { cin >> a[i]; } cout << BS(1, 1000000000) << "\n"; } }
#include <bits/stdc++.h> #define sz(v) ((int)(v).size()) #define all(v) ((v).begin()), ((v).end()) #define allr(v) ((v).rbegin()), ((v).rend()) #define pb push_back #define mp make_pair #define clr(v, d) memset(v, d, sizeof(v)) #define PI acos(-1) typedef long long ll; typedef unsigned long long ull; const double eps = (1e-9); using namespace std; int dcmp(long double a, long double b) { return fabsl(a - b) <= eps ? 0 : (a > b) ? 1 : -1; } int getBit(ll num, int idx) { return ((num >> idx) & 1ll) == 1; } int setBit1(int num, int idx) { return num | (1 << idx); } ll setBit0(ll num, int idx) { return num & ~(1ll << idx); } ll flipBit(ll num, int idx) { return num ^ (1ll << idx); } void GO() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int countNumBit1(int mask) { int ret = 0; while (mask) { mask &= (mask - 1); ++ret; } return ret; } const int N = 200000 + 5; int n, k, a[N]; bool check(int val) { ll tot = 0; for (int i = 0; i < n; i++) { int len = a[i]; int F = (len / val + (len % val != 0)) - 1; if (tot + F > k) return 0; tot += F; } return (tot <= k); } int BS(int l, int r) { int res = 0; while (l <= r) { ll mid = (l + r) / 2; if (check(mid)) { r = mid - 1; res = mid; } else { l = mid + 1; } } return res; } int main() { GO(); int T; T = 1; // cin>>T; while (T--) { cin >> n >> k; for (int i = 0; i < n; i++) { cin >> a[i]; } cout << BS(1, 1000000000) << "\n"; } }
replace
32
34
32
33
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; // #define mod 1000000007 // #define mod1 9982 #define int long long int #define pii pair<int, int> #define vpii vector<pii> #define vi vector<int> #define fi first #define se second #define psb push_back #define ppb pop_back #define fio \ ios_base::sync_with_stdio(0); \ cin.tie(NULL); \ cout.tie(NULL) #define all(x) x.begin(), x.end() #define endl "\n" const int maxn = 2e5 + 5; int n, k; int ar[maxn]; bool ok(int h) { int cnt = 0; for (int i = 0; i < n; i++) { cnt += ((ar[i] + h - 1) / h) - 1; } return cnt <= k; } void solve() { cin >> n >> k; for (int i = 0; i < n; i++) cin >> ar[i]; int l = 0, h = (1e9), ans = -1; while (l <= h) { int mid = (l + h) / 2; if (ok(mid)) { ans = mid; h = mid - 1; } else l = mid + 1; } cout << ans << endl; } int32_t main() { fio; int t; // cin>>t; t = 1; while (t--) solve(); } /* ./a.out <input.txt > output.txt */
#include <bits/stdc++.h> using namespace std; // #define mod 1000000007 // #define mod1 9982 #define int long long int #define pii pair<int, int> #define vpii vector<pii> #define vi vector<int> #define fi first #define se second #define psb push_back #define ppb pop_back #define fio \ ios_base::sync_with_stdio(0); \ cin.tie(NULL); \ cout.tie(NULL) #define all(x) x.begin(), x.end() #define endl "\n" const int maxn = 2e5 + 5; int n, k; int ar[maxn]; bool ok(int h) { int cnt = 0; for (int i = 0; i < n; i++) { cnt += ((ar[i] + h - 1) / h) - 1; } return cnt <= k; } void solve() { cin >> n >> k; for (int i = 0; i < n; i++) cin >> ar[i]; int l = 1, h = (1e9), ans = -1; while (l <= h) { int mid = (l + h) / 2; if (ok(mid)) { ans = mid; h = mid - 1; } else l = mid + 1; } cout << ans << endl; } int32_t main() { fio; int t; // cin>>t; t = 1; while (t--) solve(); } /* ./a.out <input.txt > output.txt */
replace
37
38
37
38
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define ll long long int #define ull unsigned long long #define ld long double #define mod 1000000007 #define EULER 2.7182818284 #define INF 1000000000 #define pb push_back #define ins insert #define IT iterator #define PQ priority_queue #define nl "\n" #define fi first #define se second #define maxe max_element #define mine min_element #define er erase #define lb lower_bound #define ub upper_bound #define vi vector<int> #define vll vector<ll> #define vb vector<bool> #define pi pair<int, int> #define pll pair<ll, ll> #define all(v) v.begin(), v.end() #define mpi map<int, int> #define mpl map<ll, ll> #define umpi unordered_map<int, int> #define umpl unordered_map<ll, ll> #define si set<int> #define sl set<ll> #define msi multi_set<int> #define msl multi_set<ll> #define mem(v, i) \ memset( \ v, i, \ sizeof( \ v)) // v is array. To set all elements to 0 or -1 only. mem(arr,0); #define repab(i, a, b) for (int i = (a); i <= (b); i++) #define reprab(i, a, b) for (int i = (a); i >= (b); i--) #define repll(i, a, b) for (ll i = (a); i <= (b); i++) #define rep(i, n) for (int i = (0); i < (n); i++) #define repr(i, n) for (int i = (n); i >= 0; i--) #define bs bitset #define bpc(a) __builtin_popcount(a) #define tc \ int t; \ cin >> t; \ while (t--) int dx[] = {1, -1, 0, 0}; int dy[] = {0, 0, 1, -1}; ll max(ll a, ll b) { if (a > b) return a; return b; } ll min(ll a, ll b) { if (a < b) return a; return b; } ll mypow(ll a, ll b) { ll res = 1; while (b > 0) { if (b & 1) res = res * a; a = a * a; b >>= 1; } return res; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll n, k; vll a(200005); bool isvalid(ll mid) { int cnt = 0; for (int i = 0; i < n; i++) { if (a[i] <= mid) { continue; } else { cnt += a[i] / mid; } } return cnt <= k; } ll bns(ll start, ll end) { while (start <= end) { ll mid = (start + end) / 2; if (isvalid(mid)) { end = mid - 1; } else { start = mid + 1; } } return start; } int main() { fast cin >> n >> k; rep(i, n) { cin >> a[i]; } ll p = *max_element(all(a)); if (k == 0) { cout << p << nl; return 0; } cout << bns(0, p) << nl; return 0; }
#include <bits/stdc++.h> using namespace std; #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define ll long long int #define ull unsigned long long #define ld long double #define mod 1000000007 #define EULER 2.7182818284 #define INF 1000000000 #define pb push_back #define ins insert #define IT iterator #define PQ priority_queue #define nl "\n" #define fi first #define se second #define maxe max_element #define mine min_element #define er erase #define lb lower_bound #define ub upper_bound #define vi vector<int> #define vll vector<ll> #define vb vector<bool> #define pi pair<int, int> #define pll pair<ll, ll> #define all(v) v.begin(), v.end() #define mpi map<int, int> #define mpl map<ll, ll> #define umpi unordered_map<int, int> #define umpl unordered_map<ll, ll> #define si set<int> #define sl set<ll> #define msi multi_set<int> #define msl multi_set<ll> #define mem(v, i) \ memset( \ v, i, \ sizeof( \ v)) // v is array. To set all elements to 0 or -1 only. mem(arr,0); #define repab(i, a, b) for (int i = (a); i <= (b); i++) #define reprab(i, a, b) for (int i = (a); i >= (b); i--) #define repll(i, a, b) for (ll i = (a); i <= (b); i++) #define rep(i, n) for (int i = (0); i < (n); i++) #define repr(i, n) for (int i = (n); i >= 0; i--) #define bs bitset #define bpc(a) __builtin_popcount(a) #define tc \ int t; \ cin >> t; \ while (t--) int dx[] = {1, -1, 0, 0}; int dy[] = {0, 0, 1, -1}; ll max(ll a, ll b) { if (a > b) return a; return b; } ll min(ll a, ll b) { if (a < b) return a; return b; } ll mypow(ll a, ll b) { ll res = 1; while (b > 0) { if (b & 1) res = res * a; a = a * a; b >>= 1; } return res; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll n, k; vll a(200005); bool isvalid(ll mid) { int cnt = 0; if (mid == 0) return false; for (int i = 0; i < n; i++) { if (a[i] <= mid) { continue; } else { cnt += a[i] / mid; } } return cnt <= k; } ll bns(ll start, ll end) { while (start <= end) { ll mid = (start + end) / 2; if (isvalid(mid)) { end = mid - 1; } else { start = mid + 1; } } return start; } int main() { fast cin >> n >> k; rep(i, n) { cin >> a[i]; } ll p = *max_element(all(a)); if (k == 0) { cout << p << nl; return 0; } cout << bns(0, p) << nl; return 0; }
insert
95
95
95
97
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define pb push_back #define sf(x) scanf("%d", &x) #define sfl(x) scanf("%lld", &x) #define pf(x) printf("%d\n", x) #define pfl(x) printf("%lld\n", x) #define endl '\n' #define pii pair<int, int> #define mapii map<int, int> #define mapll map<ll, ll> #define mapci map<char, int> #define mapcl map<char, ll> #define mapsi map<string, int> #define mapsl map<string, ll> #define pll pair<ll, ll> #define vi vector<int> #define vl vector<ll> #define vd vector<double, double> #define all(c) c.begin(), c.end() #define F first #define S second #define mp make_pair #define ftc(x) cerr << #x << ": " << x << " " << endl; #define PI acos(-1) #define lcm(a, b) ((a * b) / __gcd(a, b)) #define optimize \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define sqr(a) ((a) * (a)) int main() { ll i, j, k, l, m, n, l1, l2, l3; cin >> n >> k; ll ar[n + 10], cnt; for (i = 0; i < n; i++) { cin >> ar[i]; } ll low = 0, high = 1e10, mid; while (low <= high) { mid = (low + high) / 2; cnt = 0; for (i = 0; i < n; i++) { cnt += (ar[i] - 1) / mid; } // cout << mid << " " << cnt << endl; if (cnt <= k) { // cout << mid << endl; l1 = mid; high = mid - 1; } else low = mid + 1; } cout << l1 << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define pb push_back #define sf(x) scanf("%d", &x) #define sfl(x) scanf("%lld", &x) #define pf(x) printf("%d\n", x) #define pfl(x) printf("%lld\n", x) #define endl '\n' #define pii pair<int, int> #define mapii map<int, int> #define mapll map<ll, ll> #define mapci map<char, int> #define mapcl map<char, ll> #define mapsi map<string, int> #define mapsl map<string, ll> #define pll pair<ll, ll> #define vi vector<int> #define vl vector<ll> #define vd vector<double, double> #define all(c) c.begin(), c.end() #define F first #define S second #define mp make_pair #define ftc(x) cerr << #x << ": " << x << " " << endl; #define PI acos(-1) #define lcm(a, b) ((a * b) / __gcd(a, b)) #define optimize \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define sqr(a) ((a) * (a)) int main() { ll i, j, k, l, m, n, l1, l2, l3; cin >> n >> k; ll ar[n + 10], cnt; for (i = 0; i < n; i++) { cin >> ar[i]; } ll low = 1, high = 1e10, mid; while (low <= high) { mid = (low + high) / 2; cnt = 0; for (i = 0; i < n; i++) { cnt += (ar[i] - 1) / mid; } // cout << mid << " " << cnt << endl; if (cnt <= k) { // cout << mid << endl; l1 = mid; high = mid - 1; } else low = mid + 1; } cout << l1 << endl; }
replace
44
45
44
45
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; constexpr int Inf = 1000000010; constexpr ll INF = 2000000000000000000; constexpr ll MOD = 1000000007; const double PI = 3.1415926535897; typedef pair<int, int> P; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } ll mod(ll val) { ll res = val % MOD; if (res < 0) { res += MOD; } return res; } // N^P mod M(ただしM == -1の時はmodを取らない) template <typename T> T RS(T N, T P, T M) { if (P == 0) { return 1; } if (P < 0) { return 0; } if (P % 2 == 0) { ll t = RS(N, P / 2, M); if (M == -1) return t * t; return t * t % M; } if (M == -1) { return N * RS(N, P - 1, M); } return N * RS(N, P - 1, M) % M; } int main() { int N, K; cin >> N >> K; vector<int> vec(N); for (int i = 0; i < N; i++) { cin >> vec.at(i); } int ng = 0; int ok = 1000000000; int mid; for (int i = 0; i < 100; i++) { mid = (ng + ok) / 2; int cnt = 0; for (int j = 0; j < N; j++) { cnt += (vec.at(j) - 1) / mid; } if (cnt <= K) { ok = mid; } else { ng = mid; } } cout << ok << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; constexpr int Inf = 1000000010; constexpr ll INF = 2000000000000000000; constexpr ll MOD = 1000000007; const double PI = 3.1415926535897; typedef pair<int, int> P; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } ll mod(ll val) { ll res = val % MOD; if (res < 0) { res += MOD; } return res; } // N^P mod M(ただしM == -1の時はmodを取らない) template <typename T> T RS(T N, T P, T M) { if (P == 0) { return 1; } if (P < 0) { return 0; } if (P % 2 == 0) { ll t = RS(N, P / 2, M); if (M == -1) return t * t; return t * t % M; } if (M == -1) { return N * RS(N, P - 1, M); } return N * RS(N, P - 1, M) % M; } int main() { int N, K; cin >> N >> K; vector<int> vec(N); for (int i = 0; i < N; i++) { cin >> vec.at(i); } int ng = 0; int ok = 1000000000; int mid; while (ok - ng > 1) { mid = (ng + ok) / 2; int cnt = 0; for (int j = 0; j < N; j++) { cnt += (vec.at(j) - 1) / mid; } if (cnt <= K) { ok = mid; } else { ng = mid; } } cout << ok << endl; }
replace
63
64
63
64
0
p02598
C++
Runtime Error
#include <algorithm> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stdio.h> #include <string.h> #include <vector> using namespace std; typedef long long ll; const int maxn = 2e5 + 10; const int inf = 0x3f3f3f3f; const int mod = 1e9 + 7; int n, a[maxn], k; bool judge(int m) { int cnt = 0; for (int i = 0; i < n; ++i) { cnt += (a[i] - 1) / m; } return cnt <= k; } int main() { cin >> n >> k; for (int i = 0; i < n; ++i) cin >> a[i]; int l = 0, r = 1e9 + 10; while (l <= r) { int mid = l + r >> 1; if (judge(mid)) r = mid - 1; else l = mid + 1; } cout << l << endl; return 0; }
#include <algorithm> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stdio.h> #include <string.h> #include <vector> using namespace std; typedef long long ll; const int maxn = 2e5 + 10; const int inf = 0x3f3f3f3f; const int mod = 1e9 + 7; int n, a[maxn], k; bool judge(int m) { int cnt = 0; for (int i = 0; i < n; ++i) { cnt += (a[i] - 1) / m; } return cnt <= k; } int main() { cin >> n >> k; for (int i = 0; i < n; ++i) cin >> a[i]; int l = 1, r = 1e9 + 10; while (l <= r) { int mid = l + r >> 1; if (judge(mid)) r = mid - 1; else l = mid + 1; } cout << l << endl; return 0; }
replace
26
27
26
27
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> #define rep(a, b, c) for (int a = b; a <= c; a++) #define per(a, b, c) for (int a = b; a >= c; a--) #define ios \ ; \ ios::sync_with_stdio(false); \ cin.tie(0); #define pb push_back #define mk make_pair #define fi first #define se second #define mem(a, b) memset(a, b, sizeof(a)) #define inf 0x3f3f3f3f #define INF 0x3f3f3f3f3f3f3f3f #define ls(x) (x << 1) #define rs(x) (ls(x) | 1) #define eps 1e-11 using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<ll, ll> pll; typedef pair<int, int> pii; typedef vector<int> VI; typedef double db; mt19937 rnd(random_device{}()); const int mod = 998244353; const int N = 1e6 + 5; const int M = 1e6 + 5; inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } inline ll lcm(ll a, ll b) { return a * b / gcd(a, b); } inline ll ksm(ll x, ll y) { ll res = 1; while (y) { if (y & 1) res = res * x % mod; x = x * x % mod; y >>= 1; } return res; } int n, m, k; ll a[N]; bool ok(ll x) { ll cnt = 0; rep(i, 1, n) { cnt += (a[i] + x - 1) / x - 1; } return cnt <= k; } int main() { cin >> n >> k; ll r = 0; rep(i, 1, n) cin >> a[i], r = max(r, a[i]); ll l = 0, ans; while (l <= r) { ll mid = l + r >> 1; if (ok(mid)) ans = mid, r = mid - 1; else l = mid + 1; } printf("%lld\n", ans); return 0; } /* 2 1 5 10 2 15 5 3 2 93 78 1 71 59 3 57 96 */ // // _ooOoo_ // o8888888o // 88" . "88 // (| -_- |) // O\ = /O // ____/`---'\____ // .' \| |// `. // / \||| : |||// \ // / _||||| -:- |||||- \ // | | \ - /// | | // | \_| ''\---/'' | | // \ .-\__ `-` ___/-. / // ___`. .' /--.--\ `. . __ // ."" '< `.___\_<|>_/___.' >'"". // | | : `- \`.;`\ _ /`;.`/ - ` : | | // \ \ `-. \_ __\ /__ _/ .-` / / // ======`-.____`-.___\_____/___.-`____.-'====== // `=---=' // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ // 佛祖保佑 永无BUG
#include <bits/stdc++.h> #define rep(a, b, c) for (int a = b; a <= c; a++) #define per(a, b, c) for (int a = b; a >= c; a--) #define ios \ ; \ ios::sync_with_stdio(false); \ cin.tie(0); #define pb push_back #define mk make_pair #define fi first #define se second #define mem(a, b) memset(a, b, sizeof(a)) #define inf 0x3f3f3f3f #define INF 0x3f3f3f3f3f3f3f3f #define ls(x) (x << 1) #define rs(x) (ls(x) | 1) #define eps 1e-11 using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<ll, ll> pll; typedef pair<int, int> pii; typedef vector<int> VI; typedef double db; mt19937 rnd(random_device{}()); const int mod = 998244353; const int N = 1e6 + 5; const int M = 1e6 + 5; inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } inline ll lcm(ll a, ll b) { return a * b / gcd(a, b); } inline ll ksm(ll x, ll y) { ll res = 1; while (y) { if (y & 1) res = res * x % mod; x = x * x % mod; y >>= 1; } return res; } int n, m, k; ll a[N]; bool ok(ll x) { ll cnt = 0; rep(i, 1, n) { cnt += (a[i] + x - 1) / x - 1; } return cnt <= k; } int main() { cin >> n >> k; ll r = 0; rep(i, 1, n) cin >> a[i], r = max(r, a[i]); ll l = 1, ans; while (l <= r) { ll mid = l + r >> 1; if (ok(mid)) ans = mid, r = mid - 1; else l = mid + 1; } printf("%lld\n", ans); return 0; } /* 2 1 5 10 2 15 5 3 2 93 78 1 71 59 3 57 96 */ // // _ooOoo_ // o8888888o // 88" . "88 // (| -_- |) // O\ = /O // ____/`---'\____ // .' \| |// `. // / \||| : |||// \ // / _||||| -:- |||||- \ // | | \ - /// | | // | \_| ''\---/'' | | // \ .-\__ `-` ___/-. / // ___`. .' /--.--\ `. . __ // ."" '< `.___\_<|>_/___.' >'"". // | | : `- \`.;`\ _ /`;.`/ - ` : | | // \ \ `-. \_ __\ /__ _/ .-` / / // ======`-.____`-.___\_____/___.-`____.-'====== // `=---=' // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ // 佛祖保佑 永无BUG
replace
52
53
52
53
0
p02598
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long; const int MOD = 1e9 + 7; bool f(double mid, vector<int> a, int k) { ll t{}; for (int i = 0; i < a.size(); i++) { t += ceil(a.at(i) / mid) - 1; } return t <= k; } int main() { int n, k; cin >> n >> k; vector<int> a(n); for (auto &i : a) cin >> i; int j = 100000; double ok = 1e9, ng = 0; while (--j) { auto mid = (ok + ng) / 2; (f(mid, a, k) ? ok : ng) = mid; } cout << (ll)ceil(ok) << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; const int MOD = 1e9 + 7; bool f(double mid, vector<int> a, int k) { ll t{}; for (int i = 0; i < a.size(); i++) { t += ceil(a.at(i) / mid) - 1; } return t <= k; } int main() { int n, k; cin >> n >> k; vector<int> a(n); for (auto &i : a) cin >> i; int j = 100; double ok = 1e9, ng = 0; while (--j) { auto mid = (ok + ng) / 2; (f(mid, a, k) ? ok : ng) = mid; } cout << (ll)ceil(ok) << endl; }
replace
21
22
21
22
TLE
p02598
C++
Runtime Error
#pragma GCC optimize "trapv" #include <bits/stdc++.h> #include <iostream> using namespace std; #define fio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) #define ll long long #define ull unsigned long long #define ui unsigned int #define vi vector<int> #define vll vector<ll> #define pb push_back #define ld long double #define mp make_pair #define pii pair<int, int> #define mod 1000000007 #define rep(i, n) for (int i = 0; i < n; i++) #define repp(i, a, n) for (int i = a; i < n; i++) #define all(v) v.begin(), v.end() #define input(arr, n) \ for (ll i1 = 0; i1 < n; i1++) \ cin >> arr[i1] #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set \ tree<ll, null_type, less_equal<ll>, rb_tree_tag, \ tree_order_statistics_node_update> // s.order_of_key(val) // *s.find_by_order(ind) int main() { fio; int t = 1; // cin>>t; while (t--) { ll n, k; cin >> n >> k; ll a[n]; rep(i, n) cin >> a[i]; ll l = 0, r = (ll)1e9, mid = 0; ll res = INT_MAX; while (l <= r) { mid = l + (r - l) / 2; int trials = 0; rep(i, n) { if (a[i] > mid) { trials += ((a[i] + mid - 1) / mid) - 1; } } if (trials > k) l = mid + 1; else { r = mid - 1; res = min(res, mid); } } cout << res << endl; } }
#pragma GCC optimize "trapv" #include <bits/stdc++.h> #include <iostream> using namespace std; #define fio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) #define ll long long #define ull unsigned long long #define ui unsigned int #define vi vector<int> #define vll vector<ll> #define pb push_back #define ld long double #define mp make_pair #define pii pair<int, int> #define mod 1000000007 #define rep(i, n) for (int i = 0; i < n; i++) #define repp(i, a, n) for (int i = a; i < n; i++) #define all(v) v.begin(), v.end() #define input(arr, n) \ for (ll i1 = 0; i1 < n; i1++) \ cin >> arr[i1] #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set \ tree<ll, null_type, less_equal<ll>, rb_tree_tag, \ tree_order_statistics_node_update> // s.order_of_key(val) // *s.find_by_order(ind) int main() { fio; int t = 1; // cin>>t; while (t--) { ll n, k; cin >> n >> k; ll a[n]; rep(i, n) cin >> a[i]; ll l = 1, r = (ll)1e9, mid = 0; ll res = INT_MAX; while (l <= r) { mid = l + (r - l) / 2; int trials = 0; rep(i, n) { if (a[i] > mid) { trials += ((a[i] + mid - 1) / mid) - 1; } } if (trials > k) l = mid + 1; else { r = mid - 1; res = min(res, mid); } } cout << res << endl; } }
replace
40
41
40
41
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; typedef long long ll; typedef long double ld; const int INF = 1e9; int main() { ll n, k, t = 0; cin >> n >> k; vector<ll> a(n); rep(i, n) cin >> a[i]; ll l = -1, r = 1e9, m; while (r - l > 1) { m = (l + r) / 2; t = 0; rep(i, n) t += (a[i] - 1) / m; if (t <= k) r = m; else l = m; } cout << r << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; typedef long long ll; typedef long double ld; const int INF = 1e9; int main() { ll n, k, t = 0; cin >> n >> k; vector<ll> a(n); rep(i, n) cin >> a[i]; ll l = 0, r = 1e9, m; while (r - l > 1) { m = (l + r) / 2; t = 0; rep(i, n) t += (a[i] - 1) / m; if (t <= k) r = m; else l = m; } cout << r << endl; return 0; }
replace
14
15
14
15
0
p02598
C++
Runtime Error
#include <algorithm> #include <iostream> #include <map> #include <string> #include <utility> #include <vector> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (int)(n); i++) vector<int> v; int k; bool can(int len) { int cnt = k; for (int i = v.size() - 1; i >= 0; i--) { if (v[i] > len) cnt -= (v[i] / len); if (cnt < 0) return false; } return true; } int main() { int n; cin >> n >> k; v.resize(n); rep(i, n) cin >> v[i]; int l = 0, r = 1e9 + 1; for (int i = 0; i < 100; i++) { int mid = (l + r) / 2; if (can(mid)) r = mid; else l = mid; } cout << r << endl; return 0; }
#include <algorithm> #include <iostream> #include <map> #include <string> #include <utility> #include <vector> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (int)(n); i++) vector<int> v; int k; bool can(int len) { if (len == 0) return false; int cnt = k; for (int i = v.size() - 1; i >= 0; i--) { if (v[i] > len) cnt -= (v[i] / len); if (cnt < 0) return false; } return true; } int main() { int n; cin >> n >> k; v.resize(n); rep(i, n) cin >> v[i]; int l = 0, r = 1e9 + 1; for (int i = 0; i < 100; i++) { int mid = (l + r) / 2; if (can(mid)) r = mid; else l = mid; } cout << r << endl; return 0; }
insert
14
14
14
16
0
p02598
C++
Runtime Error
/** * author : Saurav Paul * created : August 03, 2020 11:41 AM * Problem Name : E - Logs * Problem Limit : 2000 ms , 1024 MB * Problem Url : https://atcoder.jp/contests/abc174/tasks/abc174_e * @genarated by : ai-virtual-assistant **/ #include <bits/stdc++.h> using namespace std; #define bug() debug() << #define sim template <class c #define ris return *this #define dor > debug &operator<< #define eni(x) \ sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<( \ c i) { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c *x) -> decltype(cerr << *x, 0); sim > char dud(...); struct debug { #ifdef PAUL ~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair<b, c> d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; } #else sim dor(const c &) { ris; } #endif } ; #define dbg(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " #ifdef ONLINE_JUDGE #define cerr \ if (false) \ cerr #endif int main() { ios_base::sync_with_stdio(false); int n, k; cin >> n >> k; vector<long long> v(n); for (auto &x : v) { cin >> x; } sort(v.begin(), v.end(), [](int a, int b) { return (a > b); }); long long l = 0, r = v[0]; while (l <= r) { long long mid = (l + r) >> 1; bool ok = true; int temp = k; bug() dbg(mid); for (int i = 0; i < n; i++) { if (v[i] <= mid) break; long long t = (v[i] - 1) / mid; temp -= t; if (temp < 0) { ok = false; break; } } if (ok == false) { l = mid + 1; } else { r = mid - 1; } bug() dbg(mid) dbg(l) dbg(r) dbg(ok); /* cout << l << " " << r << " " << ok << " "<<temp <<endl; */ } cout << l << endl; return 0; }
/** * author : Saurav Paul * created : August 03, 2020 11:41 AM * Problem Name : E - Logs * Problem Limit : 2000 ms , 1024 MB * Problem Url : https://atcoder.jp/contests/abc174/tasks/abc174_e * @genarated by : ai-virtual-assistant **/ #include <bits/stdc++.h> using namespace std; #define bug() debug() << #define sim template <class c #define ris return *this #define dor > debug &operator<< #define eni(x) \ sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<( \ c i) { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c *x) -> decltype(cerr << *x, 0); sim > char dud(...); struct debug { #ifdef PAUL ~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair<b, c> d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; } #else sim dor(const c &) { ris; } #endif } ; #define dbg(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " #ifdef ONLINE_JUDGE #define cerr \ if (false) \ cerr #endif int main() { ios_base::sync_with_stdio(false); int n, k; cin >> n >> k; vector<long long> v(n); for (auto &x : v) { cin >> x; } sort(v.begin(), v.end(), [](int a, int b) { return (a > b); }); long long l = 1, r = v[0]; while (l <= r) { long long mid = (l + r) >> 1; bool ok = true; int temp = k; bug() dbg(mid); for (int i = 0; i < n; i++) { if (v[i] <= mid) break; long long t = (v[i] - 1) / mid; temp -= t; if (temp < 0) { ok = false; break; } } if (ok == false) { l = mid + 1; } else { r = mid - 1; } bug() dbg(mid) dbg(l) dbg(r) dbg(ok); /* cout << l << " " << r << " " << ok << " "<<temp <<endl; */ } cout << l << endl; return 0; }
replace
69
70
69
70
0
p02598
C++
Runtime Error
/****************************************************************************** Online C Compiler. Code, Compile, Run and Debug C program online. Write your code in this editor and press "Run" button to compile and execute it. *******************************************************************************/ #include <bits/stdc++.h> using namespace std; #define int long long int n, a[200005]; bool check(int l, int k) { int cnt = 0; for (int i = 0; i < n; i++) { cnt += (a[i] - 1) / l; } if (cnt <= k) return true; return false; } signed main() { int k; cin >> n >> k; int l = 0, r = 1e9, mid, ans = -1; for (int i = 0; i < n; i++) { cin >> a[i]; } // int mx=p.top(); while (l <= r) { mid = l + (r - l) / 2; if (check(mid, k)) { ans = mid; r = mid - 1; } else { l = mid + 1; } } cout << ans; return 0; }
/****************************************************************************** Online C Compiler. Code, Compile, Run and Debug C program online. Write your code in this editor and press "Run" button to compile and execute it. *******************************************************************************/ #include <bits/stdc++.h> using namespace std; #define int long long int n, a[200005]; bool check(int l, int k) { int cnt = 0; for (int i = 0; i < n; i++) { cnt += (a[i] - 1) / l; } if (cnt <= k) return true; return false; } signed main() { int k; cin >> n >> k; int l = 1, r = 1e9, mid, ans = -1; for (int i = 0; i < n; i++) { cin >> a[i]; } // int mx=p.top(); while (l <= r) { mid = l + (r - l) / 2; if (check(mid, k)) { ans = mid; r = mid - 1; } else { l = mid + 1; } } cout << ans; return 0; }
replace
25
26
25
26
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define all(v) (v).begin()(v).end() ll n, k; bool check(ll x, std::vector<ll> &v) { ll moves = 0; for (auto i : v) { moves += i / x - (i % x == 0); } return moves <= k; } void solve() { cin >> n >> k; std::vector<ll> v(n); ll ans = 0, mid, l = 0, r = 1e9; for (auto &i : v) cin >> i, ans = max(ans, i); r = ans + 1; while (l <= r) { mid = l + r >> 1; if (check(mid, v)) ans = mid, r = mid - 1; else l = mid + 1; } cout << ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; // cin >> t; for (int i = 0; i < t; i++) { solve(); } }
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define all(v) (v).begin()(v).end() ll n, k; bool check(ll x, std::vector<ll> &v) { ll moves = 0; for (auto i : v) { moves += i / x - (i % x == 0); } return moves <= k; } void solve() { cin >> n >> k; std::vector<ll> v(n); ll ans = 0, mid, l = 1, r = 1e9; for (auto &i : v) cin >> i, ans = max(ans, i); r = ans + 1; while (l <= r) { mid = l + r >> 1; if (check(mid, v)) ans = mid, r = mid - 1; else l = mid + 1; } cout << ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; // cin >> t; for (int i = 0; i < t; i++) { solve(); } }
replace
17
18
17
18
0
p02598
C++
Runtime Error
// include //------------------------------------------ #include <bits/stdc++.h> using namespace std; // typedef //------------------------------------------ using LL = int64_t; using VL = vector<LL>; using VVL = vector<VL>; using VS = vector<string>; using PLL = pair<LL, LL>; // container util //------------------------------------------ #define whole(f, x, ...) \ ([&](decltype((x)) whole) { \ return (f)(begin(whole), end(whole), ##__VA_ARGS__); \ })(x) #define rwhole(f, x, ...) \ ([&](decltype((x)) whole) { \ return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__); \ })(x) #define EACH(i, c) \ for (decltype((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define ALL(x) ::std::begin(x), ::std::end(x) #define RALL(x) ::std::rbegin(x), ::std::rend(x) #define SORT(c) whole(sort, c) #define RSORT(c) rwhole(sort, c) // constant //-------------------------------------------- constexpr double EPS = 1e-10; constexpr double PI = 3.14159265358979323846; constexpr int MOD = 1000000007; // grid //-------------------------------------------- VL dx = {0, 1, 0, -1}; VL dy = {1, 0, -1, 0}; VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1}; VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1}; // debug //-------------------------------------------- #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; // IO accelerate //-------------------------------------------- struct InitIO { InitIO() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(30); } } init_io; // template //-------------------------------------------- // declaretion template <typename T> istream &operator>>(istream &is, vector<T> &vec); template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p); template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec); template <typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &vv); template <typename T> vector<T> make_v(size_t a); template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts); template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v); template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v); // implementation template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << p.first << "," << p.second; return os; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { for (int i = 0; i < vec.size(); i++) { os << vec[i] << (i + 1 == vec.size() ? "" : "\t"); } return os; } template <typename T> ostream &operator<<(ostream &s, const vector<vector<T>> &vv) { for (int i = 0; i < vv.size(); ++i) { s << vv[i] << endl; } return s; } // 多重vector // auto dp=make_v<int>(4,h,w) みたいに使える template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } // 多重vectorのためのfill // fill_v(dp,0) みたいに使える template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; } template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); } template <class T, class U> void chmax(T &a, U b) { if (a < b) a = b; } template <class T, class U> void chmin(T &a, U b) { if (b < a) a = b; } template <typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } // main code int main(int argc, char *argv[]) { LL n, k; cin >> n >> k; VL a(n); cin >> a; auto isOk = [&](LL mid) { LL cnt = 0; for (int i = 0; i < n; i++) { cnt += (a[i] / mid) + (a[i] % mid == 0 ? -1 : 0); } if (cnt <= k) { return true; } else { return false; } }; // ng:false,ok:true LL ng = -1, ok = INT32_MAX; while (abs(ng - ok) > 1) { LL mid = (ok + ng) / 2; (isOk(mid) ? ok : ng) = mid; } cout << ok << endl; return 0; }
// include //------------------------------------------ #include <bits/stdc++.h> using namespace std; // typedef //------------------------------------------ using LL = int64_t; using VL = vector<LL>; using VVL = vector<VL>; using VS = vector<string>; using PLL = pair<LL, LL>; // container util //------------------------------------------ #define whole(f, x, ...) \ ([&](decltype((x)) whole) { \ return (f)(begin(whole), end(whole), ##__VA_ARGS__); \ })(x) #define rwhole(f, x, ...) \ ([&](decltype((x)) whole) { \ return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__); \ })(x) #define EACH(i, c) \ for (decltype((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define ALL(x) ::std::begin(x), ::std::end(x) #define RALL(x) ::std::rbegin(x), ::std::rend(x) #define SORT(c) whole(sort, c) #define RSORT(c) rwhole(sort, c) // constant //-------------------------------------------- constexpr double EPS = 1e-10; constexpr double PI = 3.14159265358979323846; constexpr int MOD = 1000000007; // grid //-------------------------------------------- VL dx = {0, 1, 0, -1}; VL dy = {1, 0, -1, 0}; VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1}; VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1}; // debug //-------------------------------------------- #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; // IO accelerate //-------------------------------------------- struct InitIO { InitIO() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(30); } } init_io; // template //-------------------------------------------- // declaretion template <typename T> istream &operator>>(istream &is, vector<T> &vec); template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p); template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec); template <typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &vv); template <typename T> vector<T> make_v(size_t a); template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts); template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v); template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v); // implementation template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << p.first << "," << p.second; return os; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { for (int i = 0; i < vec.size(); i++) { os << vec[i] << (i + 1 == vec.size() ? "" : "\t"); } return os; } template <typename T> ostream &operator<<(ostream &s, const vector<vector<T>> &vv) { for (int i = 0; i < vv.size(); ++i) { s << vv[i] << endl; } return s; } // 多重vector // auto dp=make_v<int>(4,h,w) みたいに使える template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } // 多重vectorのためのfill // fill_v(dp,0) みたいに使える template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; } template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); } template <class T, class U> void chmax(T &a, U b) { if (a < b) a = b; } template <class T, class U> void chmin(T &a, U b) { if (b < a) a = b; } template <typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } // main code int main(int argc, char *argv[]) { LL n, k; cin >> n >> k; VL a(n); cin >> a; auto isOk = [&](LL mid) { LL cnt = 0; for (int i = 0; i < n; i++) { cnt += (a[i] / mid) + (a[i] % mid == 0 ? -1 : 0); } if (cnt <= k) { return true; } else { return false; } }; // ng:false,ok:true LL ng = 0, ok = INT32_MAX; while (abs(ng - ok) > 1) { LL mid = (ok + ng) / 2; (isOk(mid) ? ok : ng) = mid; } cout << ok << endl; return 0; }
replace
154
155
154
155
0
p02598
C++
Time Limit Exceeded
#include <algorithm> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) #define req(i, n) for (int i = 1; i <= n; i++) #define rrep(i, n) for (int i = n - 1; i >= 0; i--) #define ALL(a) a.begin(), a.end() #define PI acos(-1) using namespace std; template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } typedef long long int ll; typedef long double ld; const int MOD = 1e9 + 7; int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0}, sum = 0, k; vector<int> a; bool check(int x) { int cnt = 0; for (int i : a) { int aa = i; req(j, 1e9) { if ((aa - 1) / j + 1 <= x) break; cnt++; } } if (cnt > k) return 1; else return 0; } int main() { int n; cin >> n >> k; a.resize(n); rep(i, n) cin >> a[i]; int right = 1e9 + 7, left = 0; while (right - left > 1) { int mid = (right + left) / 2; if (check(mid)) left = mid; else right = mid; } cout << right << endl; }
#include <algorithm> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) #define req(i, n) for (int i = 1; i <= n; i++) #define rrep(i, n) for (int i = n - 1; i >= 0; i--) #define ALL(a) a.begin(), a.end() #define PI acos(-1) using namespace std; template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } typedef long long int ll; typedef long double ld; const int MOD = 1e9 + 7; int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0}, sum = 0, k; vector<int> a; bool check(int x) { int cnt = 0; for (int i : a) { int kk = (i - 1) / x + 1; if (kk * x < i) kk++; cnt += kk - 1; } if (cnt > k) return 1; else return 0; } int main() { int n; cin >> n >> k; a.resize(n); rep(i, n) cin >> a[i]; int right = 1e9 + 7, left = 0; while (right - left > 1) { int mid = (right + left) / 2; if (check(mid)) left = mid; else right = mid; } cout << right << endl; }
replace
26
32
26
30
TLE
p02598
C++
Runtime Error
#include <bits/stdc++.h> #define fast \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define int long long #define endl "\n" using namespace std; int arr[200005]; int n, k; bool check(int cuts) { int req = 0; for (int i = 0; i < n; i++) { req += ((arr[i] + cuts - 1) / cuts - 1); } return req <= k; } int32_t main() { fast cin >> n >> k; for (int i = 0; i < n; i++) { cin >> arr[i]; } int left = 0, right = (int)1e10 + 5; int ans = 0; while (left <= right) { int mid = (left + right) / 2; if (check(mid)) { ans = mid; right = mid - 1; } else { left = mid + 1; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define fast \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define int long long #define endl "\n" using namespace std; int arr[200005]; int n, k; bool check(int cuts) { int req = 0; for (int i = 0; i < n; i++) { req += ((arr[i] + cuts - 1) / cuts - 1); } return req <= k; } int32_t main() { fast cin >> n >> k; for (int i = 0; i < n; i++) { cin >> arr[i]; } int left = 1, right = (int)1e10 + 5; int ans = 0; while (left <= right) { int mid = (left + right) / 2; if (check(mid)) { ans = mid; right = mid - 1; } else { left = mid + 1; } } cout << ans << endl; return 0; }
replace
27
28
27
28
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #pragma region void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cerr << x; } void __print(double x) { cerr << x; } void __print(long double x) { cerr << x; } void __print(char x) { cerr << '\'' << x << '\''; } void __print(const char *x) { cerr << '\"' << x << '\"'; } void __print(const string &x) { cerr << '\"' << x << '\"'; } void __print(bool x) { cerr << (x ? "true" : "false"); } template <typename T, typename V> void __print(const pair<T, V> &x) { cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}'; } template <typename T> void __print(const T &x) { int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}"; } void _print() { cerr << "]\n"; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); } #ifndef ONLINE_JUDGE #define debug(x...) cerr << "[" << (#x) << "] = [", _print(x) #else #define debug(x...) #endif #pragma endregion typedef long long ll; #define forn(i, n) for (int i = 0; i < int(n); ++i) #define sz(v) int((v).size()) #define int ll #define f first #define s second #define mp make_pair #define mt make_tuple #define pb push_back void setIO(string s) { // ios_base::sync_with_stdio(0); cin.tie(0); // freopen((s+".in").c_str(),"r",stdin); // freopen((s+".out").c_str(),"w",stdout); } int n, k; vector<int> a; bool can(int tar) { int cnt = 0; for (int it : a) { cnt += it / tar; if (it % tar == 0) --cnt; if (cnt > k) return false; } return true; } void solve() { scanf("%lld%lld", &n, &k); a.resize(n); forn(i, n) scanf("%lld", &a[i]); int lf = 0, rg = 1e12; int ans = 0; while (lf <= rg) { int mid = (lf + rg) / 2; if (can(mid)) { rg = mid - 1; ans = mid; } else { lf = mid + 1; } } printf("%lld\n", ans); } signed main(void) { // setIO("exercise"); int T = 1; // scanf("%lld", &T); while (T--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #pragma region void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cerr << x; } void __print(double x) { cerr << x; } void __print(long double x) { cerr << x; } void __print(char x) { cerr << '\'' << x << '\''; } void __print(const char *x) { cerr << '\"' << x << '\"'; } void __print(const string &x) { cerr << '\"' << x << '\"'; } void __print(bool x) { cerr << (x ? "true" : "false"); } template <typename T, typename V> void __print(const pair<T, V> &x) { cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}'; } template <typename T> void __print(const T &x) { int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}"; } void _print() { cerr << "]\n"; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); } #ifndef ONLINE_JUDGE #define debug(x...) cerr << "[" << (#x) << "] = [", _print(x) #else #define debug(x...) #endif #pragma endregion typedef long long ll; #define forn(i, n) for (int i = 0; i < int(n); ++i) #define sz(v) int((v).size()) #define int ll #define f first #define s second #define mp make_pair #define mt make_tuple #define pb push_back void setIO(string s) { // ios_base::sync_with_stdio(0); cin.tie(0); // freopen((s+".in").c_str(),"r",stdin); // freopen((s+".out").c_str(),"w",stdout); } int n, k; vector<int> a; bool can(int tar) { int cnt = 0; for (int it : a) { cnt += it / tar; if (it % tar == 0) --cnt; if (cnt > k) return false; } return true; } void solve() { scanf("%lld%lld", &n, &k); a.resize(n); forn(i, n) scanf("%lld", &a[i]); int lf = 1, rg = 1e12; int ans = 0; while (lf <= rg) { int mid = (lf + rg) / 2; if (can(mid)) { rg = mid - 1; ans = mid; } else { lf = mid + 1; } } printf("%lld\n", ans); } signed main(void) { // setIO("exercise"); int T = 1; // scanf("%lld", &T); while (T--) solve(); return 0; }
replace
77
78
77
78
0
p02598
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; int main() { int n, k; cin >> n >> k; vector<int> a(n); rep(i, n) cin >> a[i]; int l = 0, r = 1e9; while (r - 1 > 1) { int x = (l + r) / 2; auto f = [&](int x) { ll now = 0; rep(i, n) now += (a[i] - 1) / x; return now <= k; }; if (f(x)) r = x; else l = x; } cout << r << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; int main() { int n, k; cin >> n >> k; vector<int> a(n); rep(i, n) cin >> a[i]; int l = 0, r = 1e9; while (r - l > 1) { int x = (l + r) / 2; auto f = [&](int x) { ll now = 0; rep(i, n) now += (a[i] - 1) / x; return now <= k; }; if (f(x)) r = x; else l = x; } cout << r << endl; return 0; }
replace
12
13
12
13
TLE
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; const int INF = 1e9; const int MOD = 1e9 + 7; ll a[210000]; bool check(ll N, ll K, ll mid) { ll res = 0; for (int i = 0; i < N; i++) { res += (a[i] - 1) / mid; } if (res > K) return true; else return false; } int main() { ll N, K; cin >> N >> K; ll ans = 0; for (int i = 0; i < N; i++) { cin >> a[i]; ans = max(ans, a[i]); } if (K == 0) { cout << ans << endl; return 0; } ll right = INF; ll left = 0; for (int i = 0; i < 1000; i++) { ll mid = (right + left) / 2; if (check(N, K, mid)) { left = mid; } else { right = mid; } } cout << right << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; const int INF = 1e9; const int MOD = 1e9 + 7; ll a[210000]; bool check(ll N, ll K, ll mid) { ll res = 0; for (int i = 0; i < N; i++) { res += (a[i] - 1) / mid; } if (res > K) return true; else return false; } int main() { ll N, K; cin >> N >> K; ll ans = 0; for (int i = 0; i < N; i++) { cin >> a[i]; ans = max(ans, a[i]); } if (K == 0) { cout << ans << endl; return 0; } ll right = INF; ll left = 0; for (int i = 0; i < 1000; i++) { ll mid = (right + left) / 2; if (mid == 0) break; if (check(N, K, mid)) { left = mid; } else { right = mid; } } cout << right << endl; return 0; }
insert
38
38
38
40
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> #define fi first #define se second #define m_p make_pair #define p_b push_back #define e_b emplace_back #define all(x) (x).begin(), (x).end() #define sz(x) ((int)(x).size()) using namespace std; using ll = long long; using ld = long double; template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } int N, K; vector<int> A; bool isOK(int x) { int cnt = 0; for (int i = 0; i < N; i++) { int a = A.at(i); cnt += (a + x - 1) / x - 1; } if (cnt <= K) return true; else return false; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> N >> K; A.resize(N); for (int i = 0; i < N; i++) cin >> A.at(i); int ng = -1; int ok = 1e9; while (abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if (isOK(mid)) ok = mid; else ng = mid; } cout << ok << endl; return 0; }
#include <bits/stdc++.h> #define fi first #define se second #define m_p make_pair #define p_b push_back #define e_b emplace_back #define all(x) (x).begin(), (x).end() #define sz(x) ((int)(x).size()) using namespace std; using ll = long long; using ld = long double; template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } int N, K; vector<int> A; bool isOK(int x) { int cnt = 0; for (int i = 0; i < N; i++) { int a = A.at(i); cnt += (a + x - 1) / x - 1; } if (cnt <= K) return true; else return false; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> N >> K; A.resize(N); for (int i = 0; i < N; i++) cin >> A.at(i); int ng = 0; int ok = 1e9; while (abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if (isOK(mid)) ok = mid; else ng = mid; } cout << ok << endl; return 0; }
replace
49
50
49
50
0
p02598
C++
Runtime Error
// mai iss duniyaa ka sbse bada chutiyaaa huu #include <bits/stdc++.h> #include <chrono> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define mod 1000000007 #define mod2 998244353 #define int long long #define endl '\n' #define p_b push_back #define m_p make_pair #define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL) using namespace std; using namespace __gnu_pbds; using namespace std::chrono; template <class T> using _ost = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>; char alphabet[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}; // rectangle intersection // x5 = max(x1, x3); // y5 = max(y1, y3); // x6 = min(x2, x4); // y6 = min(y2, y4); const int mx = 500005; // char get_next(char c) { // for(int i=0; i<25; i++) if(c == alphabet[i]) return alphabet[i+1]; // return 'a'; // } // struct no { // int l, r, id; // }q[mx]; // int bl[mx]; // int col[mx]; // int mp[mx]; // void get_blocks(int n) { // int sqroot = sqrt(n)+1; // for(int i=0; i<=n; i++) bl[i] = i/sqroot; // } // bool mo_sort(no a, no b) { // return bl[a.l] == bl[b.l] ? a.r < b.r : bl[a.l] < bl[b.l]; // } // int diff = 0; // void add(int id) { // if(!mp[col[id]]) diff++; // mp[col[id]]++; // } // void rem(int id) { // mp[col[id]]--; // if(mp[col[id]] == 0) diff--; // } int32_t main() { fastIO; int tc; // cin >> tc; tc = 1; while (tc--) { int n, k; cin >> n >> k; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; int l = 0, r = 1e9 + 5; while (l < r) { int md = (l + r) / 2; int tot = 0; for (int i = 0; i < n; i++) { if (a[i] % md == 0) tot += a[i] / md; else tot += a[i] / md + 1; tot--; } if (tot <= k) r = md; else l = md + 1; } cout << l << endl; } }
// mai iss duniyaa ka sbse bada chutiyaaa huu #include <bits/stdc++.h> #include <chrono> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define mod 1000000007 #define mod2 998244353 #define int long long #define endl '\n' #define p_b push_back #define m_p make_pair #define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL) using namespace std; using namespace __gnu_pbds; using namespace std::chrono; template <class T> using _ost = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>; char alphabet[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}; // rectangle intersection // x5 = max(x1, x3); // y5 = max(y1, y3); // x6 = min(x2, x4); // y6 = min(y2, y4); const int mx = 500005; // char get_next(char c) { // for(int i=0; i<25; i++) if(c == alphabet[i]) return alphabet[i+1]; // return 'a'; // } // struct no { // int l, r, id; // }q[mx]; // int bl[mx]; // int col[mx]; // int mp[mx]; // void get_blocks(int n) { // int sqroot = sqrt(n)+1; // for(int i=0; i<=n; i++) bl[i] = i/sqroot; // } // bool mo_sort(no a, no b) { // return bl[a.l] == bl[b.l] ? a.r < b.r : bl[a.l] < bl[b.l]; // } // int diff = 0; // void add(int id) { // if(!mp[col[id]]) diff++; // mp[col[id]]++; // } // void rem(int id) { // mp[col[id]]--; // if(mp[col[id]] == 0) diff--; // } int32_t main() { fastIO; int tc; // cin >> tc; tc = 1; while (tc--) { int n, k; cin >> n >> k; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; int l = 1, r = 1e9 + 5; while (l < r) { int md = (l + r) / 2; int tot = 0; for (int i = 0; i < n; i++) { if (a[i] % md == 0) tot += a[i] / md; else tot += a[i] / md + 1; tot--; } if (tot <= k) r = md; else l = md + 1; } cout << l << endl; } }
replace
73
74
73
74
0
p02598
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(a) (a).begin(), (a).end() #define LL long long int n; LL k; LL a[200000]; bool ok(LL st) { LL cnt = 0; REP(i, n) { LL cut = (a[i] - 1) / st; cnt += cut; // cerr<<st<<" "<<cnt<<endl; if (cnt > k) return false; } return true; } int main() { cin >> n >> k; REP(i, n) cin >> a[i]; LL lb = 0, ub = 10e9; while (lb < ub) { LL mid = (lb + ub) / 2; if (ok(mid)) { ub = mid; } else { lb = mid + 1; } } cout << lb << endl; return 0; }
#include "bits/stdc++.h" using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(a) (a).begin(), (a).end() #define LL long long int n; LL k; LL a[200000]; bool ok(LL st) { LL cnt = 0; REP(i, n) { LL cut = (a[i] - 1) / st; cnt += cut; // cerr<<st<<" "<<cnt<<endl; if (cnt > k) return false; } return true; } int main() { cin >> n >> k; REP(i, n) cin >> a[i]; LL lb = 1, ub = 10e9; while (lb < ub) { LL mid = (lb + ub) / 2; if (ok(mid)) { ub = mid; } else { lb = mid + 1; } } cout << lb << endl; return 0; }
replace
29
30
29
30
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long int ll; int n, k; vector<int> a; bool ok(int md) { int cnt = 0; for (int i = 0; i < n; i++) { cnt += (a[i] - 1) / md; } return cnt <= k; } int main() { cin >> n >> k; a.resize(n); for (int i = 0; i < n; i++) { cin >> a[i]; } int low = 0; int high = 1e9; int ans = 1e9; while (low <= high) { int md = (low + high) / 2; if (ok(md)) { high = md - 1; ans = min(ans, md); } else { low = md + 1; } } cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; int n, k; vector<int> a; bool ok(int md) { int cnt = 0; for (int i = 0; i < n; i++) { cnt += (a[i] - 1) / md; } return cnt <= k; } int main() { cin >> n >> k; a.resize(n); for (int i = 0; i < n; i++) { cin >> a[i]; } int low = 1; int high = 1e9; int ans = 1e9; while (low <= high) { int md = (low + high) / 2; if (ok(md)) { high = md - 1; ans = min(ans, md); } else { low = md + 1; } } cout << ans << "\n"; return 0; }
replace
23
24
23
24
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef vector<vector<int>> Graph; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; #define pi 3.14159265359 #define inf 2147483647 #define INF 9223372036854775807 #define mod 1000000007 #define mod2 998244353 int main() { ll N, K; cin >> N >> K; vector<ll> A(N); for (int i = 0; i < N; i++) cin >> A[i]; sort(A.begin(), A.end()); ll left = 1, right = A[N - 1] + 1; ll centre; vector<ll> ans; while (right - left > 1) { centre = (left + right) / 2; ll cnt = 0; for (int i = 0; i < N; i++) cnt += ceil((double)A[i] / (double)centre) - 1; if (cnt > K) left = centre; else { ans.push_back(centre); right = centre; } } cout << ans.back() << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef vector<vector<int>> Graph; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; #define pi 3.14159265359 #define inf 2147483647 #define INF 9223372036854775807 #define mod 1000000007 #define mod2 998244353 int main() { ll N, K; cin >> N >> K; vector<ll> A(N); for (int i = 0; i < N; i++) cin >> A[i]; sort(A.begin(), A.end()); ll left = 0, right = A[N - 1] + 1; ll centre; vector<ll> ans; while (right - left > 1) { centre = (left + right) / 2; ll cnt = 0; for (int i = 0; i < N; i++) cnt += ceil((double)A[i] / (double)centre) - 1; if (cnt > K) left = centre; else { ans.push_back(centre); right = centre; } } cout << ans.back() << endl; return 0; }
replace
21
22
21
22
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef pair<int, int> P; typedef long long ll; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } // 最大公約数 ll gcd(ll x, ll y) { ll tmp = 0; if (x < y) { tmp = x; x = y; y = tmp; } while (y > 0) { ll r = x % y; x = y; y = r; } return x; } // 最大公倍数 ll lcm(ll x, ll y) { return x / gcd(x, y) * y; } const int MAX = 1e6 + 1; const ll MOD = 1e9 + 7; long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } struct mint { ll x; // typedef long long ll; mint(ll x = 0) : x((x % MOD + MOD) % MOD) {} mint operator-() const { return mint(-x); } mint &operator+=(const mint a) { if ((x += a.x) >= MOD) x -= MOD; return *this; } mint &operator-=(const mint a) { if ((x += MOD - a.x) >= MOD) x -= MOD; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= MOD; return *this; } mint operator+(const mint a) const { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime MOD mint inv() const { return pow(MOD - 2); } mint &operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res /= a; } }; // 二項係数計算 long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } // 階乗 ll kaijo(ll k) { ll sum = 1; for (ll i = 1; i <= k; ++i) { sum *= i; sum %= 1000000000 + 7; } return sum; } long long modpow(long long a, long long n, long long MOD) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % MOD; a = a * a % MOD; n >>= 1; } return res; } // //sieve(MAX);でベクトルIsPrimeに「MAXまでの数値の素数の真偽」を格納する。 // struct Sieve { // int n; // vector<int> f, primes; // Sieve(int n=1):n(n), f(n+1) { // f[0] = f[1] = -1; // for (ll i = 2; i <= n; ++i) { // if (f[i]) continue; // primes.push_back(i); // f[i] = i; // for (ll j = i*i; j <= n; j += i) { // if (!f[j]) f[j] = i; // } // } // } // bool isPrime(int x) { return f[x] == x;} // vector<int> factorList(int x) { // vector<int> res; // while (x != 1) { // res.push_back(f[x]); // x /= f[x]; // } // return res; // } // vector<P> factor(int x) { // vector<int> fl = factorList(x); // if (fl.size() == 0) return {}; // vector<P> res(1, P(fl[0], 0)); // for (int p : fl) { // if (res.back().first == p) { // res.back().second++; // } else { // res.emplace_back(p, 1); // } // } // return res; // } // }; struct UnionFind { vector<int> par; UnionFind(int n) : par(n, -1) {} int root(int x) { if (par[x] < 0) return x; else return par[x] = root(par[x]); } bool issame(int x, int y) { return root(x) == root(y); } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (par[x] > par[y]) swap(x, y); // merge technique par[x] += par[y]; par[y] = x; return true; } ll size(int x) { return -par[root(x)]; } }; ll count(int n, int a) { ll bunshi = 1; for (int i = 0; i < a; i++) { bunshi *= (n - i); bunshi %= MOD; } ll bunbo = 1; for (int i = 1; i < a + 1; i++) { bunbo *= i; bunbo %= MOD; } bunbo = modpow(bunbo, MOD - 2, MOD); // cout<<(bunshi*bunbo)%MOD<<endl; return (bunshi * bunbo) % MOD; } // 約数列挙。約数をvector<ll>で返す。計算量はsqrt(n)。 vector<ll> divisor(ll n) { vector<ll> ret; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(begin(ret), end(ret)); return (ret); } // ここから開始 const ll INF = 1e18; const double PI = 3.14159265358979323846264338327950; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; int main() { ll N; ll K; cin >> N >> K; vector<ll> a(N); rep(i, N) { cin >> a[i]; } ll left = -1; ll right = 1e9 + 1; // int right = ; // cout<<"OK"<<endl; while (right - left > 1) { ll mid = left + (right - left) / 2; ll sum = 0; rep(i, N) { sum += (a[i] - 1) / mid + 1 - 1; } // cout<<sum<<endl; if (sum <= K) right = mid; else left = mid; // cout<<left<<" "<<right<<endl; } cout << right << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef pair<int, int> P; typedef long long ll; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } // 最大公約数 ll gcd(ll x, ll y) { ll tmp = 0; if (x < y) { tmp = x; x = y; y = tmp; } while (y > 0) { ll r = x % y; x = y; y = r; } return x; } // 最大公倍数 ll lcm(ll x, ll y) { return x / gcd(x, y) * y; } const int MAX = 1e6 + 1; const ll MOD = 1e9 + 7; long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } struct mint { ll x; // typedef long long ll; mint(ll x = 0) : x((x % MOD + MOD) % MOD) {} mint operator-() const { return mint(-x); } mint &operator+=(const mint a) { if ((x += a.x) >= MOD) x -= MOD; return *this; } mint &operator-=(const mint a) { if ((x += MOD - a.x) >= MOD) x -= MOD; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= MOD; return *this; } mint operator+(const mint a) const { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime MOD mint inv() const { return pow(MOD - 2); } mint &operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res /= a; } }; // 二項係数計算 long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } // 階乗 ll kaijo(ll k) { ll sum = 1; for (ll i = 1; i <= k; ++i) { sum *= i; sum %= 1000000000 + 7; } return sum; } long long modpow(long long a, long long n, long long MOD) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % MOD; a = a * a % MOD; n >>= 1; } return res; } // //sieve(MAX);でベクトルIsPrimeに「MAXまでの数値の素数の真偽」を格納する。 // struct Sieve { // int n; // vector<int> f, primes; // Sieve(int n=1):n(n), f(n+1) { // f[0] = f[1] = -1; // for (ll i = 2; i <= n; ++i) { // if (f[i]) continue; // primes.push_back(i); // f[i] = i; // for (ll j = i*i; j <= n; j += i) { // if (!f[j]) f[j] = i; // } // } // } // bool isPrime(int x) { return f[x] == x;} // vector<int> factorList(int x) { // vector<int> res; // while (x != 1) { // res.push_back(f[x]); // x /= f[x]; // } // return res; // } // vector<P> factor(int x) { // vector<int> fl = factorList(x); // if (fl.size() == 0) return {}; // vector<P> res(1, P(fl[0], 0)); // for (int p : fl) { // if (res.back().first == p) { // res.back().second++; // } else { // res.emplace_back(p, 1); // } // } // return res; // } // }; struct UnionFind { vector<int> par; UnionFind(int n) : par(n, -1) {} int root(int x) { if (par[x] < 0) return x; else return par[x] = root(par[x]); } bool issame(int x, int y) { return root(x) == root(y); } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (par[x] > par[y]) swap(x, y); // merge technique par[x] += par[y]; par[y] = x; return true; } ll size(int x) { return -par[root(x)]; } }; ll count(int n, int a) { ll bunshi = 1; for (int i = 0; i < a; i++) { bunshi *= (n - i); bunshi %= MOD; } ll bunbo = 1; for (int i = 1; i < a + 1; i++) { bunbo *= i; bunbo %= MOD; } bunbo = modpow(bunbo, MOD - 2, MOD); // cout<<(bunshi*bunbo)%MOD<<endl; return (bunshi * bunbo) % MOD; } // 約数列挙。約数をvector<ll>で返す。計算量はsqrt(n)。 vector<ll> divisor(ll n) { vector<ll> ret; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(begin(ret), end(ret)); return (ret); } // ここから開始 const ll INF = 1e18; const double PI = 3.14159265358979323846264338327950; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; int main() { ll N; ll K; cin >> N >> K; vector<ll> a(N); rep(i, N) { cin >> a[i]; } ll left = 0; ll right = 1e9 + 1; // int right = ; // cout<<"OK"<<endl; while (right - left > 1) { ll mid = left + (right - left) / 2; ll sum = 0; rep(i, N) { sum += (a[i] - 1) / mid + 1 - 1; } // cout<<sum<<endl; if (sum <= K) right = mid; else left = mid; // cout<<left<<" "<<right<<endl; } cout << right << endl; return 0; }
replace
241
242
241
242
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> #include <queue> using namespace std; #define what_is(x) cerr << #x << " is " << x << endl; #define PI acos(-1) #define hell 1000000007 #define HELL 998244353 #define io \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) #define fix(n) cout << fixed << setprecision(n) #define mset(a, n) memset(a, n, sizeof a) #define rep(i, a, b) for (__typeof((b)) i = (a); i < (b); i++) #define repp(i, a, b, p) for (__typeof((b)) i = (a); i < (b); i += p) #define ren(i, a, b) for (__typeof((a)) i = (a); i >= (b); i--) #define renn(i, a, b, p) for(__typeof((a) i=(a);i>=(b);i-=p) #define ADD(a, b, c) ((a) % c + (b) % c) % c #define SUB(a, b, c) ((a) % c - (b) % c + c) % c #define MUL(a, b, c) (((a) % c) * ((b) % c)) % c #define lbd lower_bound #define ubd upper_bound #define ll long long #define ld long double #define pb push_back #define fi first #define se second #define vll vector<ll> #define pll pair<ll, ll> #define vpll vector<pll> #define all(v) (v).begin(), (v).end() #define sz(x) (ll) x.size() // #define out(n) cout<<n<<" " #define outl(n) cout << n << endl #define bug(n) \ { \ outl(n); \ return; \ } #define pii pair<int, int> #define lim 9223372036854775805 #define ninf -9223372036854775802 #define M 10000000009 #define eps 1e-9 #define MAX 10 // #define N 100001 #define db(a) \ for (auto it : a) { \ cout << it << " "; \ } \ cout << endl; ll prime[MAX]; ll fact[MAX]; const long long INF64 = 1e18; ll find(vll &a, ll mx) { ll ans = 0; rep(i, 0, sz(a)) { ans += (a[i] + mx - 1) / mx; ans--; } return ans; } void solve(ll ttt) { ll n, k; cin >> n >> k; vll a(n); rep(i, 0, n) cin >> a[i]; ll low = 0, high = 10000000000; if (k == 0) { ll mx = INT_MIN; rep(i, 0, n) { mx = max(mx, a[i]); } cout << mx << endl; return; } while (low < high) { ll mid = low + (high - low) / 2; ll req_cut = find(a, mid); // cout<<"For mid = "<<mid<<" cuts req = "<<req_cut<<endl; if (req_cut > k) { low = mid + 1; } else high = mid; } cout << (ll)low << endl; } int main() { io; // sieve(); // factorial(); #ifndef ONLINE_JUDGE freopen("input1.txt", "r", stdin); // freopen("output1.txt","w",stdout); #endif ll t = 1; // cin>>t; fix(12); rep(q, 1, t + 1) { // cout<<"Case #"<<q<<": "; solve(q); // solve2(); } return 0; }
#include <bits/stdc++.h> #include <queue> using namespace std; #define what_is(x) cerr << #x << " is " << x << endl; #define PI acos(-1) #define hell 1000000007 #define HELL 998244353 #define io \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) #define fix(n) cout << fixed << setprecision(n) #define mset(a, n) memset(a, n, sizeof a) #define rep(i, a, b) for (__typeof((b)) i = (a); i < (b); i++) #define repp(i, a, b, p) for (__typeof((b)) i = (a); i < (b); i += p) #define ren(i, a, b) for (__typeof((a)) i = (a); i >= (b); i--) #define renn(i, a, b, p) for(__typeof((a) i=(a);i>=(b);i-=p) #define ADD(a, b, c) ((a) % c + (b) % c) % c #define SUB(a, b, c) ((a) % c - (b) % c + c) % c #define MUL(a, b, c) (((a) % c) * ((b) % c)) % c #define lbd lower_bound #define ubd upper_bound #define ll long long #define ld long double #define pb push_back #define fi first #define se second #define vll vector<ll> #define pll pair<ll, ll> #define vpll vector<pll> #define all(v) (v).begin(), (v).end() #define sz(x) (ll) x.size() // #define out(n) cout<<n<<" " #define outl(n) cout << n << endl #define bug(n) \ { \ outl(n); \ return; \ } #define pii pair<int, int> #define lim 9223372036854775805 #define ninf -9223372036854775802 #define M 10000000009 #define eps 1e-9 #define MAX 10 // #define N 100001 #define db(a) \ for (auto it : a) { \ cout << it << " "; \ } \ cout << endl; ll prime[MAX]; ll fact[MAX]; const long long INF64 = 1e18; ll find(vll &a, ll mx) { ll ans = 0; rep(i, 0, sz(a)) { ans += (a[i] + mx - 1) / mx; ans--; } return ans; } void solve(ll ttt) { ll n, k; cin >> n >> k; vll a(n); rep(i, 0, n) cin >> a[i]; ll low = 1, high = 10000000000; if (k == 0) { ll mx = INT_MIN; rep(i, 0, n) { mx = max(mx, a[i]); } cout << mx << endl; return; } while (low < high) { ll mid = low + (high - low) / 2; ll req_cut = find(a, mid); // cout<<"For mid = "<<mid<<" cuts req = "<<req_cut<<endl; if (req_cut > k) { low = mid + 1; } else high = mid; } cout << (ll)low << endl; } int main() { io; // sieve(); // factorial(); #ifndef ONLINE_JUDGE freopen("input1.txt", "r", stdin); // freopen("output1.txt","w",stdout); #endif ll t = 1; // cin>>t; fix(12); rep(q, 1, t + 1) { // cout<<"Case #"<<q<<": "; solve(q); // solve2(); } return 0; }
replace
70
71
70
71
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p02598
C++
Time Limit Exceeded
// ABHISHEK AGRAWAL,BIT mesra// // Newbie......You have to be odd to be no. ONE :)// #include <bits/stdc++.h> using namespace std; #define ll long long int #define ld long double #define fl float #define lcm(a, b) (a * (b / __gcd(a, b))) #define vs vector<string> #define vc vector<char> #define vll vector<ll> #define sll set<ll> #define pll pair<ll, ll> #define plc pair<ll, char> #define tlll tuple<ll, ll, ll> #define mt make_tuple #define vpll vector<pair<ll, ll>> #define vtll vector<tuple<ll, ll, ll>> #define vvll vector<vector<ll>> #define lb lower_bound #define pb push_back #define pob pop_back #define f first #define s second #define mll map<ll, ll> #define mp make_pair #define sp(n) fixed << setprecision(n) #define mcl map<char, ll> #define msl map<string, ll> #define mod (ll)1000000007 #define flash \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define test \ ll t; \ read(t); \ while (t--) #define sortv(v) sort(v.begin(), v.end()) #define INF (ll)(1e15) #define loop(i, n) for (int i = 0; i < n; i++) #define loop1(i, n) for (int i = 1; i <= n; i++) #define rloop(n, i) for (int i = n - 1; i >= 0; i--) #define loopab(i, a, b, c) for (int i = a; i <= b; i += c) #define reada(a, n) loop(i, n) cin >> a[i]; #define reada1(a, n) loop1(i, n) cin >> a[i]; #define sorta(a) sort(a, a + n, greater<ll>()) #define countone(n) __builtin_popcount(n) #define numoftrailzero(n) __builtin_ctz(n) #define maxpowoftwo(n) __builtin_clz(n) #define leastindexwithone(n) __builtin_ffs(n) #define what_is(x) cerr << #x << " is " << x << endl; #define pfv(v) \ cout << v.size() << "\n"; \ loop(i, v.size()) cout << v[i] << " "; \ cout << "\n"; #define pv(v) \ loop(i, v.size()) cout << v[i] << " "; \ cout << "\n"; #define all(v) v.begin(), v.end() #define mset(dp, val) memset(dp, val, sizeof(dp)) // if we need to devide any given number in powers of term the power of max term #define answer(n) ceil(log2(n + 1)) int q, n; ll ans, sum; ll gcd(ll a, ll b) { if (b == 0) { return a; } return gcd(b, a % b); } ll powe(ll a, ll b) { ll res = 1; while (b > 0) { if (b % 2 == 1) { res = (res * a); } a = (a * a); b /= 2; } return res; } ll power(ll a, ll b, ll M) { a %= M; ll res = 1; while (b > 0) { if (b % 2 == 1) { res = (res * a) % M; } a = (a * a) % M; b /= 2; } return res; } /*ll extendedEuclid(ll A,ll B,ll &x,ll &y){ if(B == 0) { x = 1; y = 0; return A; } else { ll x1 , y1; ll gcd = extendedEuclid(B,A%B,x1,y1); y = x1-(A/B)*y1; x = y1; return gcd; } } ll mi(ll A, ll M){ll x,y;extendedEuclid(A,M,x,y);if(x<0){x+=mod;} return x;} vector<bool>sieve(1000000,true); void Sieve(){ sieve[0]=false; sieve[1]=false; for(ll i=2;i*i<=1000000;i++){ if(sieve[i]==true){ for(ll j=i*i;j<1000000;j+=i) sieve[j]=false; } } } vll sieve_spf; void Sieve_spf(){ const ll n = 1e6 + 5; sieve_spf.resize(n); loop(i,n) sieve_spf[i]=i; sieve_spf[0]=-1; sieve_spf[1]=1; loopab(i,2,n,2) sieve_spf[i]=2; loopab(i,3,n,2) if(sieve_spf[i]==i) loopab(j,i*i,n,i) if(sieve_spf[j]==j) sieve_spf[j]=i; } #ifdef TESTING #define DEBUG fprintf(stderr, "====TESTING====\n") #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl #define debug(...) fprintf(stderr, __VA_ARGS__) #else #define DEBUG #define VALUE(x) #define debug(...) #endif bool comparator(const pll &a, const pll &b){ if(a.f>b.f) return true else if(a.f==b.f && a.s<b.s) return true; else return false; } void the_happiest_place_on_earth() { flash; #ifdef ENABLE_FILE_IO freopen("in", "r", stdin); freopen("out", "w", stdout); #endif } bool isUpcase(char c){ if(c >= 'A'&&c <= 'Z') return true; else return false; } bool islowcase(char c){ if(c >= 'a'&&c <= 'z') return true; else return false; }*/ const int N = 250005; ll a[N], val[N], dp[N]; // #define IN 0x3f3f3f3f,int c=0 bool vis[N]; vll v[N], an; void dfs(int n) { vis[n] = true; an.pb(n); for (auto x : v[n]) { if (!vis[x]) dfs(x); } } void solve() { int k; cin >> n >> k; loop1(i, n) cin >> a[i]; sort(a + 1, a + n + 1); int l = 1, r = a[n]; while (l <= r) { ll mid = l + r >> 1; ans = 0; loop1(i, n) { ans += (a[i] / mid); ll n1 = a[i]; if (n1 % mid == 0) ans--; } if (ans <= k) r = mid; else l = mid + 1; } cout << r; return; } int main() { flash; // Today's thought: Push yourself, because no one else is going to do it for // you. Things aren’t always #000000 and #FFFFFF START OF PROGRAM LOGIC q = 1; // cin>>q; while (q--) { solve(); } cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; // END OF PROGRAM LOGIC return 0; } /* ###### ###### # # ####### # # ##### # # # ####### ####### ###### # # # ## # # # ## ## # ## # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ##### # # # # # # # # # # # # # # # # # ###### # # # # # # # # # # # # # # ####### # # # # # # # # # ## # # # # # # ## # # # # # # # ###### ###### # # ####### # # ##### # # # # # ####### # # */
// ABHISHEK AGRAWAL,BIT mesra// // Newbie......You have to be odd to be no. ONE :)// #include <bits/stdc++.h> using namespace std; #define ll long long int #define ld long double #define fl float #define lcm(a, b) (a * (b / __gcd(a, b))) #define vs vector<string> #define vc vector<char> #define vll vector<ll> #define sll set<ll> #define pll pair<ll, ll> #define plc pair<ll, char> #define tlll tuple<ll, ll, ll> #define mt make_tuple #define vpll vector<pair<ll, ll>> #define vtll vector<tuple<ll, ll, ll>> #define vvll vector<vector<ll>> #define lb lower_bound #define pb push_back #define pob pop_back #define f first #define s second #define mll map<ll, ll> #define mp make_pair #define sp(n) fixed << setprecision(n) #define mcl map<char, ll> #define msl map<string, ll> #define mod (ll)1000000007 #define flash \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define test \ ll t; \ read(t); \ while (t--) #define sortv(v) sort(v.begin(), v.end()) #define INF (ll)(1e15) #define loop(i, n) for (int i = 0; i < n; i++) #define loop1(i, n) for (int i = 1; i <= n; i++) #define rloop(n, i) for (int i = n - 1; i >= 0; i--) #define loopab(i, a, b, c) for (int i = a; i <= b; i += c) #define reada(a, n) loop(i, n) cin >> a[i]; #define reada1(a, n) loop1(i, n) cin >> a[i]; #define sorta(a) sort(a, a + n, greater<ll>()) #define countone(n) __builtin_popcount(n) #define numoftrailzero(n) __builtin_ctz(n) #define maxpowoftwo(n) __builtin_clz(n) #define leastindexwithone(n) __builtin_ffs(n) #define what_is(x) cerr << #x << " is " << x << endl; #define pfv(v) \ cout << v.size() << "\n"; \ loop(i, v.size()) cout << v[i] << " "; \ cout << "\n"; #define pv(v) \ loop(i, v.size()) cout << v[i] << " "; \ cout << "\n"; #define all(v) v.begin(), v.end() #define mset(dp, val) memset(dp, val, sizeof(dp)) // if we need to devide any given number in powers of term the power of max term #define answer(n) ceil(log2(n + 1)) int q, n; ll ans, sum; ll gcd(ll a, ll b) { if (b == 0) { return a; } return gcd(b, a % b); } ll powe(ll a, ll b) { ll res = 1; while (b > 0) { if (b % 2 == 1) { res = (res * a); } a = (a * a); b /= 2; } return res; } ll power(ll a, ll b, ll M) { a %= M; ll res = 1; while (b > 0) { if (b % 2 == 1) { res = (res * a) % M; } a = (a * a) % M; b /= 2; } return res; } /*ll extendedEuclid(ll A,ll B,ll &x,ll &y){ if(B == 0) { x = 1; y = 0; return A; } else { ll x1 , y1; ll gcd = extendedEuclid(B,A%B,x1,y1); y = x1-(A/B)*y1; x = y1; return gcd; } } ll mi(ll A, ll M){ll x,y;extendedEuclid(A,M,x,y);if(x<0){x+=mod;} return x;} vector<bool>sieve(1000000,true); void Sieve(){ sieve[0]=false; sieve[1]=false; for(ll i=2;i*i<=1000000;i++){ if(sieve[i]==true){ for(ll j=i*i;j<1000000;j+=i) sieve[j]=false; } } } vll sieve_spf; void Sieve_spf(){ const ll n = 1e6 + 5; sieve_spf.resize(n); loop(i,n) sieve_spf[i]=i; sieve_spf[0]=-1; sieve_spf[1]=1; loopab(i,2,n,2) sieve_spf[i]=2; loopab(i,3,n,2) if(sieve_spf[i]==i) loopab(j,i*i,n,i) if(sieve_spf[j]==j) sieve_spf[j]=i; } #ifdef TESTING #define DEBUG fprintf(stderr, "====TESTING====\n") #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl #define debug(...) fprintf(stderr, __VA_ARGS__) #else #define DEBUG #define VALUE(x) #define debug(...) #endif bool comparator(const pll &a, const pll &b){ if(a.f>b.f) return true else if(a.f==b.f && a.s<b.s) return true; else return false; } void the_happiest_place_on_earth() { flash; #ifdef ENABLE_FILE_IO freopen("in", "r", stdin); freopen("out", "w", stdout); #endif } bool isUpcase(char c){ if(c >= 'A'&&c <= 'Z') return true; else return false; } bool islowcase(char c){ if(c >= 'a'&&c <= 'z') return true; else return false; }*/ const int N = 250005; ll a[N], val[N], dp[N]; // #define IN 0x3f3f3f3f,int c=0 bool vis[N]; vll v[N], an; void dfs(int n) { vis[n] = true; an.pb(n); for (auto x : v[n]) { if (!vis[x]) dfs(x); } } void solve() { int k; cin >> n >> k; loop1(i, n) cin >> a[i]; sort(a + 1, a + n + 1); int l = 1, r = a[n]; while (l < r) { ll mid = l + r >> 1; ans = 0; loop1(i, n) { ans += (a[i] / mid); ll n1 = a[i]; if (n1 % mid == 0) ans--; } if (ans <= k) r = mid; else l = mid + 1; } cout << r; return; } int main() { flash; // Today's thought: Push yourself, because no one else is going to do it for // you. Things aren’t always #000000 and #FFFFFF START OF PROGRAM LOGIC q = 1; // cin>>q; while (q--) { solve(); } cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; // END OF PROGRAM LOGIC return 0; } /* ###### ###### # # ####### # # ##### # # # ####### ####### ###### # # # ## # # # ## ## # ## # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ##### # # # # # # # # # # # # # # # # # ###### # # # # # # # # # # # # # # ####### # # # # # # # # # ## # # # # # # ## # # # # # # # ###### ###### # # ####### # # ##### # # # # # ####### # # */
replace
192
193
192
193
TLE
p02598
C++
Runtime Error
#pragma GCC optimize("Ofast") #include "bits/stdc++.h" #define int long long #define double long double #define PI 3.141592653589793 #define FAST \ ios::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); // Use for file I/O; #define FIN \ string _fname = "paintbarn"; \ string _is = _fname + ".in", _os = _fname + ".out"; \ freopen(_is.c_str(), "r", stdin); \ freopen(_os.c_str(), "w", stdout); using namespace std; const int INF = 4e18 + 10; const int INF2 = 2e18 + 10; const int INF3 = 2e10; const int MAXN = 305; const int LOGN = 19; const int MOD = 1e9 + 7; const int EPS = 1e-9; const int MULT = 2e5; const int MCNST = MOD * MOD * 8; int32_t main() { FAST; int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; sort(a.rbegin(), a.rend()); int ans = a[0]; int lb = 0, ub = ans; while (lb <= ub) { int m = (lb + ub) / 2; int cnt = 0; for (int i = 0; i < n; i++) { cnt += (a[i] + m - 1) / m - 1; } // cout << m << ' ' << cnt << endl; if (cnt <= k) { ans = m; ub = m - 1; } else { lb = m + 1; } } cout << ans; }
#pragma GCC optimize("Ofast") #include "bits/stdc++.h" #define int long long #define double long double #define PI 3.141592653589793 #define FAST \ ios::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); // Use for file I/O; #define FIN \ string _fname = "paintbarn"; \ string _is = _fname + ".in", _os = _fname + ".out"; \ freopen(_is.c_str(), "r", stdin); \ freopen(_os.c_str(), "w", stdout); using namespace std; const int INF = 4e18 + 10; const int INF2 = 2e18 + 10; const int INF3 = 2e10; const int MAXN = 305; const int LOGN = 19; const int MOD = 1e9 + 7; const int EPS = 1e-9; const int MULT = 2e5; const int MCNST = MOD * MOD * 8; int32_t main() { FAST; int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; sort(a.rbegin(), a.rend()); int ans = a[0]; int lb = 1, ub = ans; while (lb <= ub) { int m = (lb + ub) / 2; int cnt = 0; for (int i = 0; i < n; i++) { cnt += (a[i] + m - 1) / m - 1; } // cout << m << ' ' << cnt << endl; if (cnt <= k) { ans = m; ub = m - 1; } else { lb = m + 1; } } cout << ans; }
replace
40
41
40
41
0
p02598
C++
Runtime Error
#pragma GCC optimize("O3") #pragma GCC target("sse4") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef pair<int, int> pi; #define debug(x) cerr << #x << ": " << x << endl #define debug2(x, y) debug(x), debug(y) #define repn(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define rep(i, a) for (int i = 0; i < (int)(a); i++) #define all(v) v.begin(), v.end() #define mp make_pair #define pb push_back #define lb lower_bound #define ub upper_bound #define fi first #define se second #define sq(x) ((x) * (x)) const int mxN = 2e5 + 5; template <class T> T gcd(T a, T b) { return ((b == 0) ? a : gcd(b, a % b)); } ll n, k; ll a[mxN]; bool check(ll g) { ll tot = 0LL; rep(i, n) tot += (a[i] - 1) / g; return tot <= k; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); // freopen("input.in", "r", stdin); // freopen("output.out", "w", stdout); cin >> n >> k; rep(i, n) cin >> a[i]; ll l = 0, r = 1e9; while (l < r) { ll mid = (l + r) / 2; if (check(mid)) r = mid; else l = mid + 1; } cout << l << endl; return 0; } /* Things to look out for: - Integer overflows - Array bounds - Special cases Be careful! */
#pragma GCC optimize("O3") #pragma GCC target("sse4") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef pair<int, int> pi; #define debug(x) cerr << #x << ": " << x << endl #define debug2(x, y) debug(x), debug(y) #define repn(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define rep(i, a) for (int i = 0; i < (int)(a); i++) #define all(v) v.begin(), v.end() #define mp make_pair #define pb push_back #define lb lower_bound #define ub upper_bound #define fi first #define se second #define sq(x) ((x) * (x)) const int mxN = 2e5 + 5; template <class T> T gcd(T a, T b) { return ((b == 0) ? a : gcd(b, a % b)); } ll n, k; ll a[mxN]; bool check(ll g) { ll tot = 0LL; rep(i, n) tot += (a[i] - 1) / g; return tot <= k; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); // freopen("input.in", "r", stdin); // freopen("output.out", "w", stdout); cin >> n >> k; rep(i, n) cin >> a[i]; ll l = 1, r = 1e9; while (l < r) { ll mid = (l + r) / 2; if (check(mid)) r = mid; else l = mid + 1; } cout << l << endl; return 0; } /* Things to look out for: - Integer overflows - Array bounds - Special cases Be careful! */
replace
40
41
40
41
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int arr[200005]; bool isvalid(int m, int n, int k) { long long total = 0; for (int i = 0; i < n; i++) { total += (arr[i]) / m; if (arr[i] % m == 0) total--; } if (total <= k) return true; return false; } void solve(int n, int k) { int i = 0, j = 1000000001; while (i < j) { int mid = (i + j) / 2; if (isvalid(mid, n, k)) j = mid; else i = mid + 1; } cout << i; } int main() { int n, k; cin >> n >> k; for (int i = 0; i < n; i++) cin >> arr[i]; solve(n, k); return 0; }
#include <bits/stdc++.h> using namespace std; int arr[200005]; bool isvalid(int m, int n, int k) { if (m == 0) return false; long long total = 0; for (int i = 0; i < n; i++) { total += (arr[i]) / m; if (arr[i] % m == 0) total--; } if (total <= k) return true; return false; } void solve(int n, int k) { int i = 0, j = 1000000001; while (i < j) { int mid = (i + j) / 2; if (isvalid(mid, n, k)) j = mid; else i = mid + 1; } cout << i; } int main() { int n, k; cin >> n >> k; for (int i = 0; i < n; i++) cin >> arr[i]; solve(n, k); return 0; }
insert
6
6
6
8
0
p02598
C++
Time Limit Exceeded
#include "bits/stdc++.h" using namespace std; using ll = long long; template <typename TYPE> void print_vec(const vector<TYPE> &v) { for (int i = 0; i < v.size(); i++) { cout << v[i] << " "; } cout << endl; } template <typename TYPE> void print_vec2(const vector<vector<TYPE>> &v) { cout << endl; cout << " "; for (int i = 0; i < v[0].size(); i++) cout << i << " "; cout << endl; for (int i = 0; i < v.size(); i++) { cout << "i=" << i << ": "; for (int j = 0; j < v[i].size(); j++) { if (v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << " "; else cout << "\x1B[31m" << v[i][j] << " "; // https://stackoverrun.com/ja/q/12618775 } cout << "\x1B[0m" << endl; } } int main() { ll N, K; cin >> N >> K; vector<ll> A(N); for (int i = 0; i < N; i++) cin >> A[i]; sort(A.begin(), A.end()); // 2分探索 ll left = 0, right = 1e9 + 1; while (right - left > 1) { vector<ll> B = A; ll mid = (left + right) / 2; ll num_cut = 0; for (int i = 0; i < N; i++) { while (B[i] > mid) { B[i] = B[i] - mid; // B[i]をmidとA[i]-midに切り分ける num_cut++; if (num_cut > K) break; } if (num_cut > K) break; } if (num_cut > K) left = mid; else right = mid; // cout << " left: " << left << " mid: " << mid << " right: " << right << " // num_cut: " << num_cut << endl; cout << " B: "; print_vec(B); } cout << right << endl; // sort(A.begin(), A.end()); // for(int i=0; i<K; i++){ // ll tmp = A.back(); // A.pop_back(); // if(tmp % 2 == 1){ // A.push_back(tmp/2); // A.push_back(tmp/2+1); // } // else{ // A.push_back(tmp/2); // A.push_back(tmp/2); // } // sort(A.begin(), A.end()); // } // cout << A.back() << endl; return 0; }
#include "bits/stdc++.h" using namespace std; using ll = long long; template <typename TYPE> void print_vec(const vector<TYPE> &v) { for (int i = 0; i < v.size(); i++) { cout << v[i] << " "; } cout << endl; } template <typename TYPE> void print_vec2(const vector<vector<TYPE>> &v) { cout << endl; cout << " "; for (int i = 0; i < v[0].size(); i++) cout << i << " "; cout << endl; for (int i = 0; i < v.size(); i++) { cout << "i=" << i << ": "; for (int j = 0; j < v[i].size(); j++) { if (v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << " "; else cout << "\x1B[31m" << v[i][j] << " "; // https://stackoverrun.com/ja/q/12618775 } cout << "\x1B[0m" << endl; } } int main() { ll N, K; cin >> N >> K; vector<ll> A(N); for (int i = 0; i < N; i++) cin >> A[i]; sort(A.begin(), A.end()); // 2分探索 ll left = 0, right = 1e9 + 1; while (right - left > 1) { vector<ll> B = A; ll mid = (left + right) / 2; ll num_cut = 0; for (int i = 0; i < N; i++) { // while(B[i] > mid){ // //B[i] = B[i] - mid;//B[i]をmidとA[i]-midに切り分ける // //num_cut++; // num_cut += B[i] / mid; // if(num_cut>K) break; // } // num_cut += (B[i]+mid-1) / mid; if (B[i] > mid) num_cut += B[i] / mid; // num_cut += B[i] / mid - 1; if (num_cut > K) break; } if (num_cut > K) left = mid; else right = mid; // cout << " left: " << left << " mid: " << mid << " right: " << right << " // num_cut: " << num_cut << endl; cout << " B: "; print_vec(B); } cout << right << endl; // sort(A.begin(), A.end()); // for(int i=0; i<K; i++){ // ll tmp = A.back(); // A.pop_back(); // if(tmp % 2 == 1){ // A.push_back(tmp/2); // A.push_back(tmp/2+1); // } // else{ // A.push_back(tmp/2); // A.push_back(tmp/2); // } // sort(A.begin(), A.end()); // } // cout << A.back() << endl; return 0; }
replace
46
52
46
56
TLE
p02598
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cassert> #include <climits> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> PII; typedef pair<ll, ll> PLL; typedef vector<int> VI; typedef vector<ll> VL; typedef vector<string> VS; typedef vector<VI> VVI; typedef vector<VL> VVL; typedef vector<PII> VPI; typedef vector<PLL> VPL; #define rep(i, n) for (ll i = 0; i < (n); i++) #define all(a) (a).begin(), (a).end() #define pf push_front #define pb push_back #define mp make_pair #define mt make_tuple #define ub upper_bound #define lb lower_bound int main() { ll N, K; cin >> N >> K; VL A(N); rep(i, N) cin >> A[i]; sort(all(A)); ll ok = A[N - 1]; ll ng = 0; rep(qwe, 100) { ll mid = (ok + ng) / 2; ll sum = 0; rep(i, N) sum += (A[i] + mid - 1) / mid - 1; if (sum > K) ng = mid; else ok = mid; } cout << ok << endl; }
#include <algorithm> #include <bitset> #include <cassert> #include <climits> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> PII; typedef pair<ll, ll> PLL; typedef vector<int> VI; typedef vector<ll> VL; typedef vector<string> VS; typedef vector<VI> VVI; typedef vector<VL> VVL; typedef vector<PII> VPI; typedef vector<PLL> VPL; #define rep(i, n) for (ll i = 0; i < (n); i++) #define all(a) (a).begin(), (a).end() #define pf push_front #define pb push_back #define mp make_pair #define mt make_tuple #define ub upper_bound #define lb lower_bound int main() { ll N, K; cin >> N >> K; VL A(N); rep(i, N) cin >> A[i]; sort(all(A)); ll ok = A[N - 1]; ll ng = 0; while (abs(ok - ng) > 1) { ll mid = (ok + ng) / 2; ll sum = 0; rep(i, N) sum += (A[i] + mid - 1) / mid - 1; if (sum > K) ng = mid; else ok = mid; } cout << ok << endl; }
replace
42
43
42
43
0
p02598
C++
Runtime Error
/*Always success does not build on success,success build on failure and * hardwork*/ #include <bits/stdc++.h> #define ll long long #define pb push_back #define vec vector<long long> #define map map<long long, long long> #define scn(t) scanf("%d", &t); #define lscn(t) scanf("%lld", &t); #define mod 1000000007 #define rep(i, a, b) for (long long i = a; i < b; i++) #define endl "\n" using namespace std; const long long N = 2e5 + 5; long long n, k, arr[N]; bool check(long long mid) { long long ans = 0; for (long long i = 0; i < n; i++) { ans = ans + arr[i] / mid; if (arr[i] % mid == 0) ans--; } if (ans <= k) return 1; else return 0; } int main() { lscn(n); lscn(k); long long low = 0, high = INT_MAX, mid; for (long long i = 0; i < n; i++) { lscn(arr[i]); } while (low < high) { mid = (low + high) / 2; if (check(mid)) high = mid; else low = mid + 1; // cout<<mid<<endl; } if (check(low)) cout << low << endl; else cout << low + 1 << endl; }
/*Always success does not build on success,success build on failure and * hardwork*/ #include <bits/stdc++.h> #define ll long long #define pb push_back #define vec vector<long long> #define map map<long long, long long> #define scn(t) scanf("%d", &t); #define lscn(t) scanf("%lld", &t); #define mod 1000000007 #define rep(i, a, b) for (long long i = a; i < b; i++) #define endl "\n" using namespace std; const long long N = 2e5 + 5; long long n, k, arr[N]; bool check(long long mid) { long long ans = 0; for (long long i = 0; i < n; i++) { ans = ans + arr[i] / mid; if (arr[i] % mid == 0) ans--; } if (ans <= k) return 1; else return 0; } int main() { lscn(n); lscn(k); long long low = 1, high = INT_MAX, mid; for (long long i = 0; i < n; i++) { lscn(arr[i]); } while (low < high) { mid = (low + high) / 2; if (check(mid)) high = mid; else low = mid + 1; // cout<<mid<<endl; } if (check(low)) cout << low << endl; else cout << low + 1 << endl; }
replace
34
35
34
35
0
p02598
C++
Runtime Error
// #pragma GCC optimize("O3") #include <bits/stdc++.h> // #include <ctime> using namespace std; #define FAST_IO \ ios_base::sync_with_stdio(0); \ cin.tie(nullptr) #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define REP(n) FOR(O, 1, (n)) #define pb push_back #define f first #define s second typedef long double ld; typedef long long ll; typedef pair<int, int> pii; typedef pair<int, pii> piii; typedef vector<int> vi; typedef vector<pii> vii; typedef vector<ll> vl; typedef vector<piii> viii; // mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int MAXN = 500100, MAXK = 20; const ll MOD = 1e9 + 7; const ll INF = 1e16; const ld PI = asin(1) * 2; void setIO() { FAST_IO; } void setIO(string s) { setIO(); freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } int n; ll a[MAXN]; ll k; ll f(ll x) { ll ret = 0; FOR(i, 1, n) { ret += ((ll)((a[i] + x - 1) / x) - 1); } return ret; } int main() { setIO(); // setIO("lmio_1991_3e1_seka_01"); cin >> n >> k; FOR(i, 1, n) cin >> a[i]; ll le = 0.0, ri = 1e9; while (le < ri) { ll mid = (le + ri) / 2; // cout << " mid=" << mid << " f = " << f(mid) << endl; if (f(mid) > k) le = mid + 1; else ri = mid; } ll ans = le; cout << ans << "\n"; return 0; }
// #pragma GCC optimize("O3") #include <bits/stdc++.h> // #include <ctime> using namespace std; #define FAST_IO \ ios_base::sync_with_stdio(0); \ cin.tie(nullptr) #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define REP(n) FOR(O, 1, (n)) #define pb push_back #define f first #define s second typedef long double ld; typedef long long ll; typedef pair<int, int> pii; typedef pair<int, pii> piii; typedef vector<int> vi; typedef vector<pii> vii; typedef vector<ll> vl; typedef vector<piii> viii; // mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int MAXN = 500100, MAXK = 20; const ll MOD = 1e9 + 7; const ll INF = 1e16; const ld PI = asin(1) * 2; void setIO() { FAST_IO; } void setIO(string s) { setIO(); freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } int n; ll a[MAXN]; ll k; ll f(ll x) { ll ret = 0; FOR(i, 1, n) { ret += ((ll)((a[i] + x - 1) / x) - 1); } return ret; } int main() { setIO(); // setIO("lmio_1991_3e1_seka_01"); cin >> n >> k; FOR(i, 1, n) cin >> a[i]; ll le = 1, ri = 1e9; while (le < ri) { ll mid = (le + ri) / 2; // cout << " mid=" << mid << " f = " << f(mid) << endl; if (f(mid) > k) le = mid + 1; else ri = mid; } ll ans = le; cout << ans << "\n"; return 0; }
replace
55
56
55
56
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll inf = 1000000000000000000, mod = 1000000007, BS, k; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ll n, k; cin >> n >> k; ll arr[n]; for (ll i = 0; i < n; i++) cin >> arr[i]; ll l = 0, r = 10000000000, mid, sum = 0, mi = inf; while (l <= r) { mid = (l + r) / 2; // cout<<l<<" "<<r<<endl; if (l == mid) { for (ll i = 0; i < n; i++) sum = sum + arr[i] / l + !!(arr[i] % l); if (sum <= k) mi = min(mi, l); sum = 0; for (ll i = 0; i < n; i++) sum = sum + arr[i] / r + !!(arr[i] % r); if (sum <= k) mi = min(mi, r); break; } sum = 0; for (ll i = 0; i < n; i++) sum = sum + arr[i] / mid + !!(arr[i] % mid) - 1; // if(mid==4)cout<<sum<<" "; if (sum <= k) mi = min(mi, mid), r = mid; else l = mid; } cout << mi; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll inf = 1000000000000000000, mod = 1000000007, BS, k; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ll n, k; cin >> n >> k; ll arr[n]; for (ll i = 0; i < n; i++) cin >> arr[i]; ll l = 1, r = 10000000000, mid, sum = 0, mi = inf; while (l <= r) { mid = (l + r) / 2; // cout<<l<<" "<<r<<endl; if (l == mid) { for (ll i = 0; i < n; i++) sum = sum + arr[i] / l + !!(arr[i] % l); if (sum <= k) mi = min(mi, l); sum = 0; for (ll i = 0; i < n; i++) sum = sum + arr[i] / r + !!(arr[i] % r); if (sum <= k) mi = min(mi, r); break; } sum = 0; for (ll i = 0; i < n; i++) sum = sum + arr[i] / mid + !!(arr[i] % mid) - 1; // if(mid==4)cout<<sum<<" "; if (sum <= k) mi = min(mi, mid), r = mid; else l = mid; } cout << mi; }
replace
17
18
17
18
-11
p02598
C++
Runtime Error
// #define _GLIBCXX_DEBUG #include <bits/stdc++.h> #define FOR(i, a, b) for (ll i = a; i < b; i++) #define rep(i, n) FOR(i, 0, n) #define ROF(i, a, b) for (ll i = a; i >= b; i--) #define per(i, a) ROF(i, a, 0) #define pb push_back using namespace std; using ll = long long; using ld = long double; using ch = char; typedef pair<ll, ll> P; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<P> vP; typedef vector<ch> vc; typedef vector<vc> vvc; const ll MOD = 1000000007; const ll MOD2 = 998244353; const ld PI = acos(-1); const ll INF = 1e18; struct edge { ll to, cost; }; struct edge2 { ll from, to, cost; }; template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } ll N, K; vl A; ll num(ll x) { ll res = 0; rep(i, N) { res += (A[i] - 1) / x; } return res; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> N >> K; A.resize(N); rep(i, N) { cin >> A[i]; } ll ok = 1e9 + 1, ng = -1; while (abs(ok - ng) > 1) { ll mid = (ok + ng) / 2; if (num(mid) <= K) { ok = mid; } else { ng = mid; } } cout << ok << endl; }
// #define _GLIBCXX_DEBUG #include <bits/stdc++.h> #define FOR(i, a, b) for (ll i = a; i < b; i++) #define rep(i, n) FOR(i, 0, n) #define ROF(i, a, b) for (ll i = a; i >= b; i--) #define per(i, a) ROF(i, a, 0) #define pb push_back using namespace std; using ll = long long; using ld = long double; using ch = char; typedef pair<ll, ll> P; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<P> vP; typedef vector<ch> vc; typedef vector<vc> vvc; const ll MOD = 1000000007; const ll MOD2 = 998244353; const ld PI = acos(-1); const ll INF = 1e18; struct edge { ll to, cost; }; struct edge2 { ll from, to, cost; }; template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } ll N, K; vl A; ll num(ll x) { ll res = 0; rep(i, N) { res += (A[i] - 1) / x; } return res; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> N >> K; A.resize(N); rep(i, N) { cin >> A[i]; } ll ok = 1e9 + 1, ng = 0; while (abs(ok - ng) > 1) { ll mid = (ok + ng) / 2; if (num(mid) <= K) { ok = mid; } else { ng = mid; } } cout << ok << endl; }
replace
59
60
59
60
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; int ans = -1, l = 0, r = (int)1e9; auto possible = [&](int x) { int cnt = 0; for (int len : arr) { cnt += (len - 1) / x; } return cnt <= k; }; while (l <= r) { int mid = l + (r - l) / 2; if (possible(mid)) { ans = mid; r = mid - 1; } else l = mid + 1; } cout << ans; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; int ans = -1, l = 1, r = (int)1e9 + 7; auto possible = [&](int x) { int cnt = 0; for (int len : arr) { cnt += (len - 1) / x; } return cnt <= k; }; while (l <= r) { int mid = l + (r - l) / 2; if (possible(mid)) { ans = mid; r = mid - 1; } else l = mid + 1; } cout << ans; }
replace
10
11
10
11
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <iostream> #define vi vector<int> #define lvi vector<long long> #define pi pair<int, int> #define lpi pair<long long, long long> #define mp make_pair #define pb push_back #define ll long long #define N 100005 #define faltu \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) #define mod 1000000007 #define mod1 1000000000000000007 using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> multiordered_set; ll int pw(ll int a, ll int b, ll md) { if (b == 0) return 1; ll int t = pw(a, b / 2, md); if (b % 2 == 0) return (t * t) % mod; else return ((t * t) % mod * a) % mod; } vector<int> pm; void prm(int n) { bool prime[n + 1]; memset(prime, true, sizeof(prime)); for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (int i = p * p; i <= n; i += p) prime[i] = false; } } for (int p = 2; p <= n; p++) if (prime[p]) pm.push_back(p); } bool cmp(const pair<ll int, ll int> &a, const pair<ll int, ll int> &b) { if (a.first == b.first) return a.second < b.second; return a.first < b.first; } ll int gcd(ll int a, ll int b) { if (!a) return b; return gcd(b % a, a); } bool isPrime(int n) { if (n <= 1) return false; for (int i = 2; i < n; i++) if (n % i == 0) return false; return true; } map<int, int> pa; int find(int i) { if (pa[i] == i) return i; return pa[i] = find(pa[i]); } void join(int i, int j) { int a = find(i); int b = find(j); if (b >= a) pa[b] = a; else pa[a] = b; } int ddx[] = {-1, -1, -1, 0, 1, 1, 1, 0}; int ddy[] = {-1, 0, 1, 1, 1, 0, -1, -1}; int dx[] = {-1, 0, 1, 0}; int dy[] = {0, -1, 0, 1}; int n, m; ll p[N], h[N], x[N], y[N]; vector<int> ed[N]; int main() { faltu; int t = 1; // cin>>t; while (t--) { ll int n, k, final = 0; cin >> n >> k; ll int a[n + 1]; for (int i = 0; i < n; i++) { cin >> a[i]; } ll int l = 0, r = 1e9; while (l <= r) { ll int mid = (l + r) >> 1; ll int ans = 0; for (ll int i = 0; i < n; i++) { ll int cnt = 0; cnt = a[i] / mid; if (a[i] % mid) cnt++; if (cnt) ans += cnt - 1; } if (ans <= k) { final = mid; r = mid - 1; } else l = mid + 1; } cout << final << endl; } }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <iostream> #define vi vector<int> #define lvi vector<long long> #define pi pair<int, int> #define lpi pair<long long, long long> #define mp make_pair #define pb push_back #define ll long long #define N 100005 #define faltu \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) #define mod 1000000007 #define mod1 1000000000000000007 using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> multiordered_set; ll int pw(ll int a, ll int b, ll md) { if (b == 0) return 1; ll int t = pw(a, b / 2, md); if (b % 2 == 0) return (t * t) % mod; else return ((t * t) % mod * a) % mod; } vector<int> pm; void prm(int n) { bool prime[n + 1]; memset(prime, true, sizeof(prime)); for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (int i = p * p; i <= n; i += p) prime[i] = false; } } for (int p = 2; p <= n; p++) if (prime[p]) pm.push_back(p); } bool cmp(const pair<ll int, ll int> &a, const pair<ll int, ll int> &b) { if (a.first == b.first) return a.second < b.second; return a.first < b.first; } ll int gcd(ll int a, ll int b) { if (!a) return b; return gcd(b % a, a); } bool isPrime(int n) { if (n <= 1) return false; for (int i = 2; i < n; i++) if (n % i == 0) return false; return true; } map<int, int> pa; int find(int i) { if (pa[i] == i) return i; return pa[i] = find(pa[i]); } void join(int i, int j) { int a = find(i); int b = find(j); if (b >= a) pa[b] = a; else pa[a] = b; } int ddx[] = {-1, -1, -1, 0, 1, 1, 1, 0}; int ddy[] = {-1, 0, 1, 1, 1, 0, -1, -1}; int dx[] = {-1, 0, 1, 0}; int dy[] = {0, -1, 0, 1}; int n, m; ll p[N], h[N], x[N], y[N]; vector<int> ed[N]; int main() { faltu; int t = 1; // cin>>t; while (t--) { ll int n, k, final = 0; cin >> n >> k; ll int a[n + 1]; for (int i = 0; i < n; i++) { cin >> a[i]; } ll int l = 1, r = 1e9; while (l <= r) { ll int mid = (l + r) >> 1; ll int ans = 0; for (ll int i = 0; i < n; i++) { ll int cnt = 0; cnt = a[i] / mid; if (a[i] % mid) cnt++; if (cnt) ans += cnt - 1; } if (ans <= k) { final = mid; r = mid - 1; } else l = mid + 1; } cout << final << endl; } }
replace
99
100
99
100
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using i64 = long long; #define endl "\n" int main() { i64 N, K; cin >> N >> K; vector<i64> A(N); for (i64 i = 0; i < N; i++) cin >> A[i]; i64 ok = 1e9, ng = -1; while (1 < ok - ng) { i64 mid = (ok + ng) / 2; i64 cnt = 0; for (i64 i = 0; i < N; i++) cnt += A[i] / mid - (A[i] % mid == 0); if (K < cnt) ng = mid; else ok = mid; } cout << ok << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using i64 = long long; #define endl "\n" int main() { i64 N, K; cin >> N >> K; vector<i64> A(N); for (i64 i = 0; i < N; i++) cin >> A[i]; i64 ok = 1e9, ng = 0; while (1 < ok - ng) { i64 mid = (ok + ng) / 2; i64 cnt = 0; for (i64 i = 0; i < N; i++) cnt += A[i] / mid - (A[i] % mid == 0); if (K < cnt) ng = mid; else ok = mid; } cout << ok << endl; return 0; }
replace
11
12
11
12
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define pb push_back #define vll vector<ll> #define pll pair<ll, ll> #define vpll vector<pll> #define ub upper_bound #define lb lower_bound #define all(v) ((v).begin()), ((v).end()) #define allr(v) ((v).rbegin()), ((v).rend()) #define ff first #define ss second #define mp make_pair #define pll pair<ll, ll> #define fo(i, n) for (ll i = 0; i < n; i++) #define foa(i, s, e) for (ll i = (s); i < e; i++) #define fod(i, s, e) for (ll i = (s); i >= (e); i--) #define max3(a, b, c) max(max(a, b), c) #define min3(a, b, c) min(min(a, b), c) #define deb(x) cerr << #x << ' ' << '=' << ' ' << x << '\n' #define sz(x) (ll)(x.size()) #define ANS cout << ans << '\n' #define YES cout << "YES\n" #define NO cout << "NO\n" #define Yes cout << "Yes\n" #define No cout << "No\n" const ld pi = 3.14159265358979323846; ll MOD = 1e9 + 7; // ll MOD = 998244353; const char nl = '\n'; const ll inf = 1e15; #define fill(a, b) memset(a, b, sizeof(a)) #define setbits(x) __builtin_popcountll(x) #define print2d(dp, n, m) \ fo(i, n) { \ fo(j, m) cout << dp[i][j] << " "; \ cout << "\n"; \ } ll nxt() { ll x; cin >> x; return x; } ll mul(ll x, ll y) { return (1ll * (x % MOD) * (y % MOD)); } ll modpow(ll x, ll y) { ll z = 1; while (y > 0) { if (y % 2) z = mul(z, x); x = mul(x, x); y /= 2; } return z; } ll power(ll x, ll y) { ll z = 1; while (y > 0) { if (y % 2) z = z * x; x = x * x; y /= 2; } return z; } ll gcd(ll a, ll b) { if (a < b) return gcd(b, a); if (b == 0) return a; return gcd(b, a % b); } ll min(ll a, ll b) { if (a < b) return a; return b; } ll max(ll a, ll b) { if (a > b) return a; return b; } ll sq(ll a) { ll ans = (1ll * a * a); return ans; } const ll N = 2e5 + 5; ll a[N]; ll n, k; bool chk(ll x) { ll cuts = 0; fo(i, n) { if (a[i] > x) cuts += (a[i] / x) - 1 + (a[i] % x > 0); } // cout << x << " " << cuts << nl; return (cuts <= k); } void solve() { cin >> n >> k; // ll a[n]; ll mx = 0; fo(i, n) cin >> a[i], mx = max(mx, a[i]); ll l = 0, r = mx, ans; while (l <= r) { ll mid = l + (r - l) / 2; if (chk(mid)) r = mid - 1, ans = mid; else l = mid + 1; } ANS; } int main() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); #ifndef ONLINE_JUDGE freopen("inputf.txt", "r", stdin); freopen("outputf.txt", "w", stdout); freopen("error.txt", "w", stderr); #endif ll TC = 1; // cin>>TC; while (TC--) { solve(); } cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define pb push_back #define vll vector<ll> #define pll pair<ll, ll> #define vpll vector<pll> #define ub upper_bound #define lb lower_bound #define all(v) ((v).begin()), ((v).end()) #define allr(v) ((v).rbegin()), ((v).rend()) #define ff first #define ss second #define mp make_pair #define pll pair<ll, ll> #define fo(i, n) for (ll i = 0; i < n; i++) #define foa(i, s, e) for (ll i = (s); i < e; i++) #define fod(i, s, e) for (ll i = (s); i >= (e); i--) #define max3(a, b, c) max(max(a, b), c) #define min3(a, b, c) min(min(a, b), c) #define deb(x) cerr << #x << ' ' << '=' << ' ' << x << '\n' #define sz(x) (ll)(x.size()) #define ANS cout << ans << '\n' #define YES cout << "YES\n" #define NO cout << "NO\n" #define Yes cout << "Yes\n" #define No cout << "No\n" const ld pi = 3.14159265358979323846; ll MOD = 1e9 + 7; // ll MOD = 998244353; const char nl = '\n'; const ll inf = 1e15; #define fill(a, b) memset(a, b, sizeof(a)) #define setbits(x) __builtin_popcountll(x) #define print2d(dp, n, m) \ fo(i, n) { \ fo(j, m) cout << dp[i][j] << " "; \ cout << "\n"; \ } ll nxt() { ll x; cin >> x; return x; } ll mul(ll x, ll y) { return (1ll * (x % MOD) * (y % MOD)); } ll modpow(ll x, ll y) { ll z = 1; while (y > 0) { if (y % 2) z = mul(z, x); x = mul(x, x); y /= 2; } return z; } ll power(ll x, ll y) { ll z = 1; while (y > 0) { if (y % 2) z = z * x; x = x * x; y /= 2; } return z; } ll gcd(ll a, ll b) { if (a < b) return gcd(b, a); if (b == 0) return a; return gcd(b, a % b); } ll min(ll a, ll b) { if (a < b) return a; return b; } ll max(ll a, ll b) { if (a > b) return a; return b; } ll sq(ll a) { ll ans = (1ll * a * a); return ans; } const ll N = 2e5 + 5; ll a[N]; ll n, k; bool chk(ll x) { ll cuts = 0; fo(i, n) { if (a[i] > x) cuts += (a[i] / x) - 1 + (a[i] % x > 0); } // cout << x << " " << cuts << nl; return (cuts <= k); } void solve() { cin >> n >> k; // ll a[n]; ll mx = 0; fo(i, n) cin >> a[i], mx = max(mx, a[i]); ll l = 1, r = mx, ans; while (l <= r) { ll mid = l + (r - l) / 2; if (chk(mid)) r = mid - 1, ans = mid; else l = mid + 1; } ANS; } int main() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); #ifndef ONLINE_JUDGE freopen("inputf.txt", "r", stdin); freopen("outputf.txt", "w", stdout); freopen("error.txt", "w", stderr); #endif ll TC = 1; // cin>>TC; while (TC--) { solve(); } cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; }
replace
105
106
105
106
0
p02598
C++
Runtime Error
/* AUTHOR : Ankit Kumar BRANCH : Information Technology INSTITUTE : Birla Institute of Technology */ #include <bits/stdc++.h> using namespace std; #define fast \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define pb push_back #define MP make_pair #define SET(a, val) memset(a, val, sizeof(a)) #define deci(n) cout << fixed << setprecision(n); #define fr(i, st, n) for (int i = st; i < n; i++) #define fr1(i, st, n) for (int i = st; i >= n; i--) #define show(a, l, r) \ for (int i = l; i < r; i++) \ cout << a[i] << " "; #define all(a) a.begin(), a.end() #define pi pair<int, int> #define ff first #define sc second const int N = (int)100; const int dx[] = {-1, 0, 1, 0, -1, -1, 1, 1}; const int dy[] = {0, 1, 0, -1, -1, 1, -1, 1}; char dir[] = {'L', 'D', 'R', 'U'}; // int dx[]={2,-2,1,-1,2,-2,1,-1};//for knights // int dy[]={1,1,2,2,-1,-1,-2,-2}; typedef long long int ll; typedef long double ld; #define pll pair<ll, ll> const ll mod = (ll)1e9 + 7; const ll inf = 1e18 + 100; int BIT[100005], n; ll prime[17], spf[N]; template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } template <typename T> T min3(T a, T b, T c) { return min(a, min(b, c)); } template <typename T> T max3(T a, T b, T c) { return max(a, max(b, c)); } bool isVowel(char ch) { ch = toupper(ch); if (ch == 'A' || ch == 'U' || ch == 'I' || ch == 'O' || ch == 'E') return true; return false; } ll mInv(ll a, ll m) { ll m0 = m; ll y = 0, x = 1; if (m == 1) return 0; while (a > 1) { ll q = a / m; ll t = m; m = a % m, a = t; t = y; y = x - q * y; x = t; } if (x < 0) x += m0; return x; } ll power(ll x, ll y) { ll res = 1; x = x % mod; while (y > 0) { if (y & 1) res = (res * x) % mod; y = y >> 1; x = (x * x) % mod; } return res; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } long long Extendedgcd(long long a, long long b, long long *x, long long *y) { if (!a) { *x = 0; *y = 1; return b; } long long nx, ny; long long d = Extendedgcd(b % a, a, &nx, &ny); long long k = b / a; *y = nx; *x = -k * nx + ny; return d; } void update(int x, int delta) { if (!x) { BIT[x] += delta; return; } for (; x <= N; x += x & -x) BIT[x] += delta; } ll query(int x) { ll sum = BIT[0]; for (; x > 0; x -= x & -x) sum += BIT[x]; return sum; } void Sieve() { for (int i = 1; i <= N; i++) prime[i] = 1; prime[0] = 0; prime[1] = 0; for (ll p = 2; p * p <= N; p++) { if (prime[p] == 1) { for (ll i = p * p; i <= N; i += p) prime[i] = 0; } } for (int p = 3; p <= N; p++) prime[p] += prime[p - 1]; } void sieve() { spf[1] = -1; for (int i = 2; i < N; i++) spf[i] = i; for (int i = 4; i < N; i += 2) spf[i] = 2; for (ll i = 3; i * i < N; i++) { if (spf[i] == i) { for (ll j = i * i; j < N; j += i) if (spf[j] == j) spf[j] = i; } } } struct cmp { bool operator()(const pair<int, int> &x, const pair<int, int> &y) const { if (x.first != y.first) return x.first < y.first; return x.second > y.second; } }; void gInput(int m, vector<int> adj[]) { int u, v; for (int i = 0; i < m; i++) { cin >> u >> v; adj[u].pb(v); adj[v].pb(u); } } vector<ll> fac; void factorial() { int N = (int)1e5 + 100; fac.resize(N); fac[0] = 1; for (ll i = 1; i < N; i++) { fac[i] = ((fac[i - 1] % mod) * i) % mod; } } ll nCr(ll n, ll r) { ll x = fac[n]; ll y = fac[r]; ll z = fac[n - r]; ll pr = ((y % mod) * (z % mod)) % mod; pr = mInv(pr, mod); ll ncr = ((x % mod) * (pr % mod)) % mod; return ncr; } /******************Lets Code*******************/ int main() { fast int t = 1; // cin>>t; while (t--) { int n; ll k; cin >> n >> k; ll a[n]; fr(i, 0, n) cin >> a[i]; ll ans = INT_MAX; ll l = 0, r = 1e9; while (l <= r) { ll mid = l + (r - l) / 2; ll x = 0; ll res = 0; fr(i, 0, n) { x += (a[i] - 1) / mid; } if (x <= k) { ans = min(ans, mid); r = mid - 1; } else l = mid + 1; } cout << ans << "\n"; } return 0; }
/* AUTHOR : Ankit Kumar BRANCH : Information Technology INSTITUTE : Birla Institute of Technology */ #include <bits/stdc++.h> using namespace std; #define fast \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define pb push_back #define MP make_pair #define SET(a, val) memset(a, val, sizeof(a)) #define deci(n) cout << fixed << setprecision(n); #define fr(i, st, n) for (int i = st; i < n; i++) #define fr1(i, st, n) for (int i = st; i >= n; i--) #define show(a, l, r) \ for (int i = l; i < r; i++) \ cout << a[i] << " "; #define all(a) a.begin(), a.end() #define pi pair<int, int> #define ff first #define sc second const int N = (int)100; const int dx[] = {-1, 0, 1, 0, -1, -1, 1, 1}; const int dy[] = {0, 1, 0, -1, -1, 1, -1, 1}; char dir[] = {'L', 'D', 'R', 'U'}; // int dx[]={2,-2,1,-1,2,-2,1,-1};//for knights // int dy[]={1,1,2,2,-1,-1,-2,-2}; typedef long long int ll; typedef long double ld; #define pll pair<ll, ll> const ll mod = (ll)1e9 + 7; const ll inf = 1e18 + 100; int BIT[100005], n; ll prime[17], spf[N]; template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } template <typename T> T min3(T a, T b, T c) { return min(a, min(b, c)); } template <typename T> T max3(T a, T b, T c) { return max(a, max(b, c)); } bool isVowel(char ch) { ch = toupper(ch); if (ch == 'A' || ch == 'U' || ch == 'I' || ch == 'O' || ch == 'E') return true; return false; } ll mInv(ll a, ll m) { ll m0 = m; ll y = 0, x = 1; if (m == 1) return 0; while (a > 1) { ll q = a / m; ll t = m; m = a % m, a = t; t = y; y = x - q * y; x = t; } if (x < 0) x += m0; return x; } ll power(ll x, ll y) { ll res = 1; x = x % mod; while (y > 0) { if (y & 1) res = (res * x) % mod; y = y >> 1; x = (x * x) % mod; } return res; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } long long Extendedgcd(long long a, long long b, long long *x, long long *y) { if (!a) { *x = 0; *y = 1; return b; } long long nx, ny; long long d = Extendedgcd(b % a, a, &nx, &ny); long long k = b / a; *y = nx; *x = -k * nx + ny; return d; } void update(int x, int delta) { if (!x) { BIT[x] += delta; return; } for (; x <= N; x += x & -x) BIT[x] += delta; } ll query(int x) { ll sum = BIT[0]; for (; x > 0; x -= x & -x) sum += BIT[x]; return sum; } void Sieve() { for (int i = 1; i <= N; i++) prime[i] = 1; prime[0] = 0; prime[1] = 0; for (ll p = 2; p * p <= N; p++) { if (prime[p] == 1) { for (ll i = p * p; i <= N; i += p) prime[i] = 0; } } for (int p = 3; p <= N; p++) prime[p] += prime[p - 1]; } void sieve() { spf[1] = -1; for (int i = 2; i < N; i++) spf[i] = i; for (int i = 4; i < N; i += 2) spf[i] = 2; for (ll i = 3; i * i < N; i++) { if (spf[i] == i) { for (ll j = i * i; j < N; j += i) if (spf[j] == j) spf[j] = i; } } } struct cmp { bool operator()(const pair<int, int> &x, const pair<int, int> &y) const { if (x.first != y.first) return x.first < y.first; return x.second > y.second; } }; void gInput(int m, vector<int> adj[]) { int u, v; for (int i = 0; i < m; i++) { cin >> u >> v; adj[u].pb(v); adj[v].pb(u); } } vector<ll> fac; void factorial() { int N = (int)1e5 + 100; fac.resize(N); fac[0] = 1; for (ll i = 1; i < N; i++) { fac[i] = ((fac[i - 1] % mod) * i) % mod; } } ll nCr(ll n, ll r) { ll x = fac[n]; ll y = fac[r]; ll z = fac[n - r]; ll pr = ((y % mod) * (z % mod)) % mod; pr = mInv(pr, mod); ll ncr = ((x % mod) * (pr % mod)) % mod; return ncr; } /******************Lets Code*******************/ int main() { fast int t = 1; // cin>>t; while (t--) { int n; ll k; cin >> n >> k; ll a[n]; fr(i, 0, n) cin >> a[i]; ll ans = INT_MAX; ll l = 1, r = 1e9; while (l <= r) { ll mid = l + (r - l) / 2; ll x = 0; ll res = 0; fr(i, 0, n) { x += (a[i] - 1) / mid; } if (x <= k) { ans = min(ans, mid); r = mid - 1; } else l = mid + 1; } cout << ans << "\n"; } return 0; }
replace
179
180
179
180
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N, K; scanf("%d%d", &N, &K); vector<int> A(N); for (int i = 0; i < N; ++i) scanf("%d", &A[i]); int lb = 0; int ub = 1 << 30; for (int _ = 0; _ < 32; ++_) { int mb = (lb + ub) / 2; int c = 0; for (int i = 0; i < N; ++i) { c += (A[i] + mb - 1) / mb - 1; if (c > K) break; } (c <= K ? ub : lb) = mb; } printf("%d\n", ub); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N, K; scanf("%d%d", &N, &K); vector<int> A(N); for (int i = 0; i < N; ++i) scanf("%d", &A[i]); int lb = 0; int ub = 1 << 30; while (ub - lb > 1) { int mb = (lb + ub) / 2; int c = 0; for (int i = 0; i < N; ++i) { c += (A[i] + mb - 1) / mb - 1; if (c > K) break; } (c <= K ? ub : lb) = mb; } printf("%d\n", ub); return 0; }
replace
13
14
13
14
0
p02598
C++
Runtime Error
// Believe in yourself #include <bits/stdc++.h> using namespace std; typedef unsigned long long int ull; typedef long long int ll; typedef long double ld; #define PB push_back #define MP make_pair #define F first #define S second #define Pair vector<pair<ll, ll>> #define vec vector<ll> #define all(a) a.begin(), a.end() #define mo 1000000007 #define decimal(i, n) fixed << setprecision(i) << n #define show(a) \ for (auto xyz : a) \ cout << xyz << " "; \ cout << endl; #define show_nl(a) \ for (auto xyz : a) \ cout << xyz << endl; void eea(ll a, ll b, ll &x, ll &y) { if (a == 1) { x = 1; y = 0; return; } ll x1, y1; eea(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; } ll mi(ll a, ll m) { ll x, y; eea(a, m, x, y); x = (x % m + m) % m; return x; } /* Enter the test case Some helpful points 1.) Calm yourself 2.) check for semicolon or data type mismatch */ ll binarysearch(ll *a, ll n, ll k, ll r) { ll l = 0, mid; ll p = k; while (l < r) { ll x = 0; k = p; mid = (l + r) / 2; for (ll i = n - 1; i >= 0; i--) { ll c = ((*(a + i)) + mid - 1) / mid; if (c == 1) break; k = k - c + 1; if (k < 0) { x = 1; break; } } if (x == 1) l = mid + 1; else r = mid; } return l; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll t = 1; // cin>>t; while (t--) { ll n, k; cin >> n >> k; ll a[n]; for (ll i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); ll max = a[n - 1]; ll ans = binarysearch(a, n, k, max); cout << ans << "\n"; } }
// Believe in yourself #include <bits/stdc++.h> using namespace std; typedef unsigned long long int ull; typedef long long int ll; typedef long double ld; #define PB push_back #define MP make_pair #define F first #define S second #define Pair vector<pair<ll, ll>> #define vec vector<ll> #define all(a) a.begin(), a.end() #define mo 1000000007 #define decimal(i, n) fixed << setprecision(i) << n #define show(a) \ for (auto xyz : a) \ cout << xyz << " "; \ cout << endl; #define show_nl(a) \ for (auto xyz : a) \ cout << xyz << endl; void eea(ll a, ll b, ll &x, ll &y) { if (a == 1) { x = 1; y = 0; return; } ll x1, y1; eea(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; } ll mi(ll a, ll m) { ll x, y; eea(a, m, x, y); x = (x % m + m) % m; return x; } /* Enter the test case Some helpful points 1.) Calm yourself 2.) check for semicolon or data type mismatch */ ll binarysearch(ll *a, ll n, ll k, ll r) { ll l = 1, mid; ll p = k; while (l < r) { ll x = 0; k = p; mid = (l + r) / 2; for (ll i = n - 1; i >= 0; i--) { ll c = ((*(a + i)) + mid - 1) / mid; if (c == 1) break; k = k - c + 1; if (k < 0) { x = 1; break; } } if (x == 1) l = mid + 1; else r = mid; } return l; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll t = 1; // cin>>t; while (t--) { ll n, k; cin >> n >> k; ll a[n]; for (ll i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); ll max = a[n - 1]; ll ans = binarysearch(a, n, k, max); cout << ans << "\n"; } }
replace
54
55
54
55
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 #define INF (1 << 29) #define LINF (1LL << 60) #define EPS (1e-10) #define PI 3.1415926535897932384626433832795028 #define all(a) (a).begin(), (a).end() #define sz(x) (int)x.size() #define max_heap priority_queue<int> #define min_heap priority_queue<int, vector<int>, greater<int>> using ll = long long; #define int long long #define endl "\n" #define vi vector<int> #define pb push_back #define inp_arr(a, n) \ for (ll i = 0; i < n; i++) \ cin >> a[i]; #define out_arr(a) \ for (ll i = 0; i < a.size(); i++) \ cout << a[i] << " "; #define deb(n) cerr << #n << " = " << n << "\n"; int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } ll mypower(ll x, ll n, ll c) { if (n == 0) return 1; ll temp = mypower(x, n / 2, c) % c; if (n % 2) return (n < 0) ? (1 / x) * temp * temp % c : ((x * temp) % c) * temp % c; else return temp * temp % c; } bool codejam = 0; bool check(ll mid, vector<int> a, ll k) { ll ans = 0; for (int i = 0; i < a.size(); i++) { if (a[i] > mid) { ans += a[i] / mid; } } return ans <= k; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ll n; ll k; cin >> n >> k; vector<int> a(n); inp_arr(a, n); ll low = 0; ll high = *max_element(all(a)); while (low < high) { ll mid = low + (high - low) / 2; if (check(mid, a, k)) high = mid; else low = mid + 1; } cout << low << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 #define INF (1 << 29) #define LINF (1LL << 60) #define EPS (1e-10) #define PI 3.1415926535897932384626433832795028 #define all(a) (a).begin(), (a).end() #define sz(x) (int)x.size() #define max_heap priority_queue<int> #define min_heap priority_queue<int, vector<int>, greater<int>> using ll = long long; #define int long long #define endl "\n" #define vi vector<int> #define pb push_back #define inp_arr(a, n) \ for (ll i = 0; i < n; i++) \ cin >> a[i]; #define out_arr(a) \ for (ll i = 0; i < a.size(); i++) \ cout << a[i] << " "; #define deb(n) cerr << #n << " = " << n << "\n"; int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } ll mypower(ll x, ll n, ll c) { if (n == 0) return 1; ll temp = mypower(x, n / 2, c) % c; if (n % 2) return (n < 0) ? (1 / x) * temp * temp % c : ((x * temp) % c) * temp % c; else return temp * temp % c; } bool codejam = 0; bool check(ll mid, vector<int> a, ll k) { ll ans = 0; for (int i = 0; i < a.size(); i++) { if (a[i] > mid) { ans += a[i] / mid; } } return ans <= k; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ll n; ll k; cin >> n >> k; vector<int> a(n); inp_arr(a, n); ll low = 0; ll high = *max_element(all(a)); while (low < high) { ll mid = low + (high - low) / 2; if (mid and check(mid, a, k)) high = mid; else low = mid + 1; } cout << low << endl; return 0; }
replace
67
68
67
68
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p02598
C++
Runtime Error
#include <bits/stdc++.h> #define F first #define S second #define pb push_back #define mp make_pair #define full(a) a.begin(), a.end() #define rfull(a) a.rbegin(), a.rend() using namespace std; const double pi = acos(-1.0); const double pii = 2 * pi; const double eps = 1e-6; const long long MOD = 1e9 + 7; bool tf(long long lim, int n, long long k, vector<long long> &l) { long long ans = 0; for (int i = 0; i < n; i++) if (l[i] % lim == 0) ans += (l[i] / lim) - 1; else ans += (l[i] / lim); return ans <= k; } void solve() { int n; long long k; cin >> n >> k; vector<long long> l(n, 0); for (int i = 0; i < n; i++) cin >> l[i]; long long ll = 0, rr = MOD, mid; while (rr - ll > 1) { mid = (ll + rr) / 2; if (tf(mid, n, k, l)) rr = mid; else ll = mid; } if (tf(ll, n, k, l)) rr = ll; cout << rr << "\n"; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(NULL); std::cout.tie(NULL); solve(); return 0; }
#include <bits/stdc++.h> #define F first #define S second #define pb push_back #define mp make_pair #define full(a) a.begin(), a.end() #define rfull(a) a.rbegin(), a.rend() using namespace std; const double pi = acos(-1.0); const double pii = 2 * pi; const double eps = 1e-6; const long long MOD = 1e9 + 7; bool tf(long long lim, int n, long long k, vector<long long> &l) { long long ans = 0; for (int i = 0; i < n; i++) if (l[i] % lim == 0) ans += (l[i] / lim) - 1; else ans += (l[i] / lim); return ans <= k; } void solve() { int n; long long k; cin >> n >> k; vector<long long> l(n, 0); for (int i = 0; i < n; i++) cin >> l[i]; long long ll = 1, rr = MOD, mid; while (rr - ll > 1) { mid = (ll + rr) / 2; if (tf(mid, n, k, l)) rr = mid; else ll = mid; } if (tf(ll, n, k, l)) rr = ll; cout << rr << "\n"; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(NULL); std::cout.tie(NULL); solve(); return 0; }
replace
31
32
31
32
0
p02598
C++
Runtime Error
/* Author: Vishal Singh (singhvishal0304@gmail.com) "The days that break you are the days that make you." */ #include <bits/stdc++.h> using namespace std; #define fastio() \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define md 1000000007 #define lli long long int #define pb push_back #define mp make_pair #define vvi(r, c) vector<vector<lli>> v(r, vector<lli>(c)); #define fi first #define se second #define mem(arr, x) memset(arr, x, sizeof(arr)) lli power(lli a, lli b) { if (b == 0) return 1; if (b % 2) return ((a % md) * (power(a, b - 1))) % md; else { lli x = power(a, b / 2); return (x * x) % md; } } lli numCuts(vector<lli> &a, lli mid) { int n = a.size(); lli sum = 0; for (int i = 0; i < n; i++) { lli x = a[i] / mid; if (a[i] % mid) x++; sum += x - 1; } return sum; } lli bin_search(vector<lli> &a, lli l, lli r, lli k) { if (l < r) { lli mid = l + (r - l) / 2; if (numCuts(a, mid) > k) return bin_search(a, mid + 1, r, k); return bin_search(a, l, mid, k); } return l; } void solve() { lli n, k; cin >> n >> k; vector<lli> a(n); lli r = 0; for (int i = 0; i < n; i++) { cin >> a[i]; r = max(r, a[i]); } lli ans = bin_search(a, 0, r, k); cout << ans << endl; } int main() { fastio(); int t; t = 1; while (t--) { solve(); } return 0; }
/* Author: Vishal Singh (singhvishal0304@gmail.com) "The days that break you are the days that make you." */ #include <bits/stdc++.h> using namespace std; #define fastio() \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define md 1000000007 #define lli long long int #define pb push_back #define mp make_pair #define vvi(r, c) vector<vector<lli>> v(r, vector<lli>(c)); #define fi first #define se second #define mem(arr, x) memset(arr, x, sizeof(arr)) lli power(lli a, lli b) { if (b == 0) return 1; if (b % 2) return ((a % md) * (power(a, b - 1))) % md; else { lli x = power(a, b / 2); return (x * x) % md; } } lli numCuts(vector<lli> &a, lli mid) { int n = a.size(); lli sum = 0; for (int i = 0; i < n; i++) { lli x = a[i] / mid; if (a[i] % mid) x++; sum += x - 1; } return sum; } lli bin_search(vector<lli> &a, lli l, lli r, lli k) { if (l < r) { lli mid = l + (r - l) / 2; if (numCuts(a, mid) > k) return bin_search(a, mid + 1, r, k); return bin_search(a, l, mid, k); } return l; } void solve() { lli n, k; cin >> n >> k; vector<lli> a(n); lli r = 0; for (int i = 0; i < n; i++) { cin >> a[i]; r = max(r, a[i]); } lli ans = bin_search(a, 1, r, k); cout << ans << endl; } int main() { fastio(); int t; t = 1; while (t--) { solve(); } return 0; }
replace
66
67
66
67
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; vector<int> A(N); for (auto &i : A) cin >> i; auto ok = [&](auto x) { long long k = 0; for (auto &a : A) k += (a - 1) / x; return k <= K; }; int l = -1, h = 1e9; while (1 < h - l) { auto m = (l + h) / 2; if (ok(m)) h = m; else l = m; } cout << h << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; vector<int> A(N); for (auto &i : A) cin >> i; auto ok = [&](auto x) { long long k = 0; for (auto &a : A) k += (a - 1) / x; return k <= K; }; int l = 0, h = 1e9; while (1 < h - l) { auto m = (l + h) / 2; if (ok(m)) h = m; else l = m; } cout << h << endl; }
replace
17
18
17
18
0
p02598
C++
Runtime Error
#include <algorithm> #include <cmath> #include <fstream> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <vector> using namespace std; #define I_MAX 2147483647 #define LL_MAX 9223372036854775807 #define ll long long #define ld long double struct XX { int t; int p; }; class xxGreater { public: bool operator()(const XX &riLeft, const XX &riRight) const { // 第2条件 if ((riLeft.t) == (riRight.t)) { return riLeft.p < riRight.p; //<:昇順(小さいものから順番)、>:降順(大きいものから順番) // プライオリティキューの場合は > で、top()すると値の小さいものがとれる } // 第1条件 return (riLeft.t) < (riRight.t); } }; // map<long long,long long> prime_f(long long n){ // map<long long,long long>res; // for(int i=2;i*i<=n;i++){ // while(n%i==0){ // ++res[i]; // n/=i; // } // } // if(n!=1)res[n]=1; // return res; // } // int n; ////int dat[2*10000000]; ////int dat2[2*10000000]; // int dat[10]; // int dat2[10]; // // void init(int n_){ // n=1; // while(n<n_)n*=2; // for(int i=0;i<2*n-1;i++){ // dat[i]=0; // dat2[i]=0; // } // } // // void initset(int k,int a){ // k+=n-1; // dat[k]=a; // while(k>0){ // k=(k-1)/2; // dat[k]=dat[k*2+1]+dat[k*2+2]; // } // } // ////[a,b)の間を[l,r]区間で比較しアップデート ////引数のindexに注意 ////nは固定。initで計算すみ ////update2(L[i],R[i]+1,0,0,n,D[i]); // void update2(int a,int b,int k,int l,int r,int v){//v更新値、区間は0-index // if(r<=a || b<=l)return; // if(a<=l && r<=b){ // dat[k]+=dat2[k]; // if(r-l>1){ // dat2[k*2+1]+=dat2[k]/2; // dat2[k*2+1]+=dat2[k]/2; // } // dat2[k]=v*(r-l); // return; // }else{ // update2(a,b,k*2+1,l,(l+r)/2,v); // update2(a,b,k*2+2,(l+r)/2,r,v); // return; // } // } // // int query(int a,int b,int k,int l,int r){ // if(r<=a || b<=l)return 0; // if(a<=l && r<=b){ // dat[k]+=dat2[k]; // if(r-l>1){ // dat2[k*2+1]+=dat2[k]/2; // dat2[k*2+1]+=dat2[k]/2; // } // dat2[k]=0; // return dat[k]; // } // else{ // int vl=query(a,b,k*2+1,l,(l+r)/2); // int vr=query(a,b,k*2+2,(l+r)/2,r); // return vl+vr; // } // } // void printb(unsigned int v) { // unsigned int mask = (int)1 << (sizeof(v) * CHAR_BIT - 1); // do putchar(mask & v ? '1' : '0'); // while (mask >>= 1); // } #ifdef DEBUG #else #endif int main(int argc, const char *argv[]) { // scanf("%s",S); // scanf("%d",&N); // scanf("%lld %lld",&target1,&target2); // sscanf(tmp.c_str(),"%dd%d%d",&time[i], &dice[i], &z[i]); // getline(cin, target); // ifstream ifs("01");//テスト用 // ifs >> a; // ここから // 入力高速化 ios::sync_with_stdio(false); cin.tie(0); int N, K; cin >> N >> K; int a[200000]; for (int i = 0; i < N; i++) { cin >> a[i]; } int l = -1; int r = 1000000000; while (r - l > 1) { int m = (l + r) / 2; int cnt = 0; for (int i = 0; i < N; i++) { int sho = a[i] / m; if (a[i] % m != 0) { sho++; } cnt += sho - 1; } if (cnt <= K) { r = m; } else { l = m; } } cout << l + 1 << endl; // ここまで // cout << "ans" << endl; // cout << " " << "ans" << endl; // printf("%.0f\n",ans);//小数点以下表示なし // printf("%.7f\n",p); return 0; }
#include <algorithm> #include <cmath> #include <fstream> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <vector> using namespace std; #define I_MAX 2147483647 #define LL_MAX 9223372036854775807 #define ll long long #define ld long double struct XX { int t; int p; }; class xxGreater { public: bool operator()(const XX &riLeft, const XX &riRight) const { // 第2条件 if ((riLeft.t) == (riRight.t)) { return riLeft.p < riRight.p; //<:昇順(小さいものから順番)、>:降順(大きいものから順番) // プライオリティキューの場合は > で、top()すると値の小さいものがとれる } // 第1条件 return (riLeft.t) < (riRight.t); } }; // map<long long,long long> prime_f(long long n){ // map<long long,long long>res; // for(int i=2;i*i<=n;i++){ // while(n%i==0){ // ++res[i]; // n/=i; // } // } // if(n!=1)res[n]=1; // return res; // } // int n; ////int dat[2*10000000]; ////int dat2[2*10000000]; // int dat[10]; // int dat2[10]; // // void init(int n_){ // n=1; // while(n<n_)n*=2; // for(int i=0;i<2*n-1;i++){ // dat[i]=0; // dat2[i]=0; // } // } // // void initset(int k,int a){ // k+=n-1; // dat[k]=a; // while(k>0){ // k=(k-1)/2; // dat[k]=dat[k*2+1]+dat[k*2+2]; // } // } // ////[a,b)の間を[l,r]区間で比較しアップデート ////引数のindexに注意 ////nは固定。initで計算すみ ////update2(L[i],R[i]+1,0,0,n,D[i]); // void update2(int a,int b,int k,int l,int r,int v){//v更新値、区間は0-index // if(r<=a || b<=l)return; // if(a<=l && r<=b){ // dat[k]+=dat2[k]; // if(r-l>1){ // dat2[k*2+1]+=dat2[k]/2; // dat2[k*2+1]+=dat2[k]/2; // } // dat2[k]=v*(r-l); // return; // }else{ // update2(a,b,k*2+1,l,(l+r)/2,v); // update2(a,b,k*2+2,(l+r)/2,r,v); // return; // } // } // // int query(int a,int b,int k,int l,int r){ // if(r<=a || b<=l)return 0; // if(a<=l && r<=b){ // dat[k]+=dat2[k]; // if(r-l>1){ // dat2[k*2+1]+=dat2[k]/2; // dat2[k*2+1]+=dat2[k]/2; // } // dat2[k]=0; // return dat[k]; // } // else{ // int vl=query(a,b,k*2+1,l,(l+r)/2); // int vr=query(a,b,k*2+2,(l+r)/2,r); // return vl+vr; // } // } // void printb(unsigned int v) { // unsigned int mask = (int)1 << (sizeof(v) * CHAR_BIT - 1); // do putchar(mask & v ? '1' : '0'); // while (mask >>= 1); // } #ifdef DEBUG #else #endif int main(int argc, const char *argv[]) { // scanf("%s",S); // scanf("%d",&N); // scanf("%lld %lld",&target1,&target2); // sscanf(tmp.c_str(),"%dd%d%d",&time[i], &dice[i], &z[i]); // getline(cin, target); // ifstream ifs("01");//テスト用 // ifs >> a; // ここから // 入力高速化 ios::sync_with_stdio(false); cin.tie(0); int N, K; cin >> N >> K; int a[200000]; for (int i = 0; i < N; i++) { cin >> a[i]; } int l = 0; int r = 1000000001; while (r - l > 1) { int m = (l + r) / 2; int cnt = 0; for (int i = 0; i < N; i++) { int sho = a[i] / m; if (a[i] % m != 0) { sho++; } cnt += sho - 1; } if (cnt <= K) { r = m; } else { l = m; } } cout << l + 1 << endl; // ここまで // cout << "ans" << endl; // cout << " " << "ans" << endl; // printf("%.0f\n",ans);//小数点以下表示なし // printf("%.7f\n",p); return 0; }
replace
150
152
150
152
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long #define rep(A, B, C) for (A = B; A < C; ++A) #define pii pair<int, int> #define pll pair<ll, ll> using namespace std; ///////////////////////////////////////////////////// ll N, K; ll A[202020]; ll i, j, k; bool calc(ll aa) { ll k = K, i; rep(i, 0, N) { ll c = (A[i] - 1) / aa; k -= c; if (k < 0) return false; } return true; } int main() { scanf("%lld%lld", &N, &K); rep(i, 0, N) { scanf("%lld", &A[i]); } ll l = 0, r = 1e12; while (l < r) { ll c = (l + r) / 2; if (calc(c)) { r = c; } else { l = c + 1; } } printf("%lld\n", l); return 0; }
#include <bits/stdc++.h> #define ll long long #define rep(A, B, C) for (A = B; A < C; ++A) #define pii pair<int, int> #define pll pair<ll, ll> using namespace std; ///////////////////////////////////////////////////// ll N, K; ll A[202020]; ll i, j, k; bool calc(ll aa) { ll k = K, i; rep(i, 0, N) { ll c = (A[i] - 1) / aa; k -= c; if (k < 0) return false; } return true; } int main() { scanf("%lld%lld", &N, &K); rep(i, 0, N) { scanf("%lld", &A[i]); } ll l = 1, r = 1e12; while (l < r) { ll c = (l + r) / 2; if (calc(c)) { r = c; } else { l = c + 1; } } printf("%lld\n", l); return 0; }
replace
30
31
30
31
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> #define F first #define S second #define MP make_pair #define pb push_back #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define LCM(a, b) (a) / __gcd((a), (b)) * (b) #define CEIL(a, b) (a) / (b) + (((a) % (b)) ? 1 : 0) #define ln '\n' using namespace std; using LL = long long; using ldouble = long double; using P = pair<int, int>; using LP = pair<LL, LL>; static const int INF = INT_MAX; static const LL LINF = LLONG_MAX; static const int MIN = INT_MIN; static const LL LMIN = LLONG_MIN; static const int MOD = 1e9 + 7; static const int SIZE = 200005; const int dx[] = {0, -1, 1, 0}; const int dy[] = {-1, 0, 0, 1}; vector<LL> Div(LL n) { vector<LL> ret; for (LL i = 1; i * i <= n; ++i) { if (n % i == 0) { ret.pb(i); if (i * i != n) ret.pb(n / i); } } sort(all(ret)); return ret; } int K, N; vector<int> v; bool check(int n) { int t = K; for (int i = 0; i < N; ++i) { t -= v[i] / n; if (v[i] >= n && v[i] % n == 0) ++t; } return (t >= 0); } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> N >> K; int mx = 0; for (int i = 0; i < N; ++i) { int a; cin >> a; v.pb(a); mx = max(mx, a); } int l, r; l = 0, r = mx; while (r - l > 1) { int mid = (l + r) / 2; if (check(mid)) r = mid; else l = mid; } if (check(l)) cout << l; else cout << r; cout << endl; return 0; }
#include <bits/stdc++.h> #define F first #define S second #define MP make_pair #define pb push_back #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define LCM(a, b) (a) / __gcd((a), (b)) * (b) #define CEIL(a, b) (a) / (b) + (((a) % (b)) ? 1 : 0) #define ln '\n' using namespace std; using LL = long long; using ldouble = long double; using P = pair<int, int>; using LP = pair<LL, LL>; static const int INF = INT_MAX; static const LL LINF = LLONG_MAX; static const int MIN = INT_MIN; static const LL LMIN = LLONG_MIN; static const int MOD = 1e9 + 7; static const int SIZE = 200005; const int dx[] = {0, -1, 1, 0}; const int dy[] = {-1, 0, 0, 1}; vector<LL> Div(LL n) { vector<LL> ret; for (LL i = 1; i * i <= n; ++i) { if (n % i == 0) { ret.pb(i); if (i * i != n) ret.pb(n / i); } } sort(all(ret)); return ret; } int K, N; vector<int> v; bool check(int n) { int t = K; for (int i = 0; i < N; ++i) { t -= v[i] / n; if (v[i] >= n && v[i] % n == 0) ++t; } return (t >= 0); } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> N >> K; int mx = 0; for (int i = 0; i < N; ++i) { int a; cin >> a; v.pb(a); mx = max(mx, a); } int l, r; l = 0, r = mx; while (r - l > 1) { int mid = (l + r) / 2; if (check(mid)) r = mid; else l = mid; } cout << r << endl; return 0; }
replace
77
82
77
78
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #include <cmath> #include <iomanip> #include <math.h> template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } const int mod = 1e9 + 7; const int64_t INF = 1e18; int64_t N, K; int64_t A[100005]; int64_t f(int64_t m) { int cnt = 0; for (int i = 0; i < N; i++) { if (A[i] > m) { cnt += (A[i] - 1) / m; } } return cnt; } int main() { cin >> N >> K; for (int i = 0; i < N; i++) { cin >> A[i]; } int64_t l = 0, r = 1e9 + 1; while (r - l > 1) { int64_t m = (r + l) / 2; // m=max長さ if (f(m) <= K) { r = m; } // K回以内でm以内の長さにできる長さの範囲=r if (f(m) > K) { l = m; } } cout << r << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #include <cmath> #include <iomanip> #include <math.h> template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } const int mod = 1e9 + 7; const int64_t INF = 1e18; int64_t N, K; int64_t A[1000005]; int64_t f(int64_t m) { int cnt = 0; for (int i = 0; i < N; i++) { if (A[i] > m) { cnt += (A[i] - 1) / m; } } return cnt; } int main() { cin >> N >> K; for (int i = 0; i < N; i++) { cin >> A[i]; } int64_t l = 0, r = 1e9 + 1; while (r - l > 1) { int64_t m = (r + l) / 2; // m=max長さ if (f(m) <= K) { r = m; } // K回以内でm以内の長さにできる長さの範囲=r if (f(m) > K) { l = m; } } cout << r << endl; return 0; }
replace
22
23
22
23
0
p02598
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <vector> #define fi first #define se second #define pb push_back #define me(a, b) memset(a, b, sizeof(a)) #define INIT() std::ios::sync_with_stdio(false) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> P; const int MAX_N = 200000 + 5; const int MAX_M = 100000 + 5; const int INF = 0x7fffffff; const int inf = 1000000000; const double EPS = 1e-6; const ull base = 123; const ll mod = 1e9 + 7; const double pi = 4 * atan(1.0); int a[MAX_N]; int n, k; int check(int x) { int ans = 0; int i; for (i = 1; i <= n; i++) { if (a[i] > x) { ans += a[i] / x; if (a[i] % x == 0) ans--; } if (ans > k) return 1; } return 0; } int main() { cin >> n >> k; int i; for (i = 1; i <= n; i++) scanf("%d", &a[i]); int l = 0; int r = 1000000000; int mid = (l + r) / 2; while (l <= r) { if (check(mid)) { l = mid + 1; } else r = mid - 1; mid = (l + r) / 2; } cout << mid + 1 << endl; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <vector> #define fi first #define se second #define pb push_back #define me(a, b) memset(a, b, sizeof(a)) #define INIT() std::ios::sync_with_stdio(false) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> P; const int MAX_N = 200000 + 5; const int MAX_M = 100000 + 5; const int INF = 0x7fffffff; const int inf = 1000000000; const double EPS = 1e-6; const ull base = 123; const ll mod = 1e9 + 7; const double pi = 4 * atan(1.0); int a[MAX_N]; int n, k; int check(int x) { int ans = 0; int i; for (i = 1; i <= n; i++) { if (a[i] > x) { ans += a[i] / x; if (a[i] % x == 0) ans--; } if (ans > k) return 1; } return 0; } int main() { cin >> n >> k; int i; for (i = 1; i <= n; i++) scanf("%d", &a[i]); int l = 0; int r = 1000000000; int mid = (l + r) / 2; while (l <= r) { if (mid == 0) break; if (check(mid)) { l = mid + 1; } else r = mid - 1; mid = (l + r) / 2; } cout << mid + 1 << endl; }
insert
57
57
57
59
0
p02598
C++
Runtime Error
#include <algorithm> #include <math.h> #include <stdio.h> using namespace std; typedef long long ll; ll a[200005], n, k; bool possible(double x) { ll i, res = 0; for (i = 1; i <= n; i++) res += (a[i] * 2 / (ll)(x * 2.0) + !(a[i] * 2 % (ll)(x * 2.0) == 0)) - 1; return res <= k; } int main(void) { ll i; scanf("%lld %lld", &n, &k); for (i = 1; i <= n; i++) scanf("%lld", &a[i]); double left = 0, right = (double)*max_element(a + 1, a + n + 1); for (i = 1; i <= 200; i++) { double mid = (left + right) / 2.0; if (possible(mid)) right = mid; else left = mid + 0.1; } printf("%lld", (ll)round(left)); return 0; }
#include <algorithm> #include <math.h> #include <stdio.h> using namespace std; typedef long long ll; ll a[200005], n, k; bool possible(double x) { ll i, res = 0; for (i = 1; i <= n; i++) res += (a[i] * 2 / (ll)(x * 2.0) + !(a[i] * 2 % (ll)(x * 2.0) == 0)) - 1; return res <= k; } int main(void) { ll i; scanf("%lld %lld", &n, &k); for (i = 1; i <= n; i++) scanf("%lld", &a[i]); double left = 0.5, right = (double)*max_element(a + 1, a + n + 1); for (i = 1; i <= 200; i++) { double mid = (left + right) / 2.0; if (possible(mid)) right = mid; else left = mid + 0.1; } printf("%lld", (ll)round(left)); return 0; }
replace
25
26
25
26
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> #define Int int64_t #define ll long long #define pb push_back using namespace std; const Int MAXN = 200005; const int ALPHA = 26; Int N, K, M; Int X, Y, Z; Int C; vector<Int> ID; vector<Int> SZ; string S; int find(int x) { if (ID[x] == x) return x; return find(ID[x]); } void Union(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (SZ[x] > SZ[y]) { ID[y] = x; SZ[x] += SZ[y]; } else { ID[x] = y; SZ[y] += SZ[x]; } return; } string common_prefix(string s, string t) { string ans = ""; for (int i = 0; i < min(s.length(), t.length()); ++i) { if (s[i] == t[i]) ans.pb(s[i]); else break; } return ans; } string LCP(vector<string> A, int l, int r) { if (l > r) return ""; if (l == r) return A[l]; int mid = (l + r) / 2; string left = LCP(A, l, mid); string right = LCP(A, mid + 1, r); return common_prefix(left, right); } long long ModExpo(long long x, unsigned long long y, long long M) { Int ans = 1; ans = (long long)ans; while (y > 0) { if (y & 1) ans = ((ans % M) * (x % M)) % M; y >>= 1LL; x = ((x % M) * (x % M)) % M; } return ans % M; } Int LCM(Int x, Int y) { return (x * y) / __gcd(x, y); } using D = long double; vector<Int> A, B; Int ceils(Int x, Int k) { return (x + k - 1) / k - 1; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0); int t; t = 1; while (t--) { cin >> N >> K; vector<Int> A(N); Int maxs = -1; for (auto &x : A) cin >> x, maxs = max(maxs, x); if (!K) { cout << maxs << "\n"; continue; } Int lb = 0, rb = 1e9 + 200; auto possible = [&](vector<Int> &arr, Int k, Int tt) { for (auto x : arr) { tt -= ceils(x, k); } return tt >= 0; }; while (lb < rb) { Int mid = (lb + rb) / 2; if (possible(A, mid, K)) rb = mid; else lb = mid + 1; } cout << lb << "\n"; } }
#include <bits/stdc++.h> #define Int int64_t #define ll long long #define pb push_back using namespace std; const Int MAXN = 200005; const int ALPHA = 26; Int N, K, M; Int X, Y, Z; Int C; vector<Int> ID; vector<Int> SZ; string S; int find(int x) { if (ID[x] == x) return x; return find(ID[x]); } void Union(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (SZ[x] > SZ[y]) { ID[y] = x; SZ[x] += SZ[y]; } else { ID[x] = y; SZ[y] += SZ[x]; } return; } string common_prefix(string s, string t) { string ans = ""; for (int i = 0; i < min(s.length(), t.length()); ++i) { if (s[i] == t[i]) ans.pb(s[i]); else break; } return ans; } string LCP(vector<string> A, int l, int r) { if (l > r) return ""; if (l == r) return A[l]; int mid = (l + r) / 2; string left = LCP(A, l, mid); string right = LCP(A, mid + 1, r); return common_prefix(left, right); } long long ModExpo(long long x, unsigned long long y, long long M) { Int ans = 1; ans = (long long)ans; while (y > 0) { if (y & 1) ans = ((ans % M) * (x % M)) % M; y >>= 1LL; x = ((x % M) * (x % M)) % M; } return ans % M; } Int LCM(Int x, Int y) { return (x * y) / __gcd(x, y); } using D = long double; vector<Int> A, B; Int ceils(Int x, Int k) { return (x + k - 1) / k - 1; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0); int t; t = 1; while (t--) { cin >> N >> K; vector<Int> A(N); Int maxs = -1; for (auto &x : A) cin >> x, maxs = max(maxs, x); if (!K) { cout << maxs << "\n"; continue; } Int lb = 1, rb = 1e9 + 200; auto possible = [&](vector<Int> &arr, Int k, Int tt) { for (auto x : arr) { tt -= ceils(x, k); } return tt >= 0; }; while (lb < rb) { Int mid = (lb + rb) / 2; if (possible(A, mid, K)) rb = mid; else lb = mid + 1; } cout << lb << "\n"; } }
replace
88
89
88
89
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) #define pi 3.14159265359 #define all(i) i.begin(), i.end() using namespace std; const long long INF = 1e9 + 7; const string alp = "abcdefghijklmnopqrstuvwxyz"; // 26 const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; typedef long long ll; typedef vector<ll> vl; typedef vector<vector<ll>> vvl; typedef pair<ll, ll> P; typedef tuple<ll, ll, ll> T; // const ll MOD=998244353LL; // const ll MOD=1777777777LL; int main() { ll N, K; cin >> N >> K; ll a[N]; rep(i, N) cin >> a[i]; ll lb = 0, ub = INF; for (int i = 0; i < 100; i++) { ll mid = (lb + ub) / 2; ll num = 0; for (int i = 0; i < N; i++) { num += (a[i] - 1) / mid; } if (num > K) lb = mid; else ub = mid; } int ans = ub; if (ub > ans) ans++; cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) #define pi 3.14159265359 #define all(i) i.begin(), i.end() using namespace std; const long long INF = 1e9 + 7; const string alp = "abcdefghijklmnopqrstuvwxyz"; // 26 const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; typedef long long ll; typedef vector<ll> vl; typedef vector<vector<ll>> vvl; typedef pair<ll, ll> P; typedef tuple<ll, ll, ll> T; // const ll MOD=998244353LL; // const ll MOD=1777777777LL; int main() { ll N, K; cin >> N >> K; ll a[N]; rep(i, N) cin >> a[i]; ll lb = 0, ub = INF; while (ub - lb > 1) { ll mid = (lb + ub) / 2; ll num = 0; for (int i = 0; i < N; i++) { num += (a[i] - 1) / mid; } if (num > K) lb = mid; else ub = mid; } int ans = ub; if (ub > ans) ans++; cout << ans << endl; }
replace
25
26
25
26
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double lld; ll MOD = (1e9) + 7; const int dr[] = {+1, -1, +0, +0, +1, -1, +1, -1}; const int dc[] = {+0, +0, +1, -1, +1, -1, -1, +1}; const int kx[] = {+1, +2, -1, -2, +1, +2, -1, -2}; const int ky[] = {+2, +1, +2, +1, -2, -1, -2, -1}; // #pragma GCC target ("avx2") // #pragma GCC optimization ("O3") // #pragma GCC optimization ("unroll-loops") inline void fastIO() { ios_base::sync_with_stdio(0); cin.tie(0); } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; } template <typename T, size_t size> ostream &operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; } template <typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); } #ifdef LOCAL #define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__) #else #define debug(...) 47 #endif const int MAXN = 202020; ll n, k; vector<ll> lens(MAXN); bool possible(ll val) { ll tot = 0; for (int i = 0; i < n; i++) { if (lens[i] % val == 0) { tot += (lens[i] / val) - 1; } else { tot += ((lens[i] / val)); } } return (tot <= k); } int main() { fastIO(); cin >> n >> k; for (int i = 0; i < n; i++) { cin >> lens[i]; } ll l = 0, h = (1e9) + 5; while (l < h) { ll mid = (l + h) / 2; if (possible(mid)) { h = mid; } else { l = mid + 1; } } cout << l << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double lld; ll MOD = (1e9) + 7; const int dr[] = {+1, -1, +0, +0, +1, -1, +1, -1}; const int dc[] = {+0, +0, +1, -1, +1, -1, -1, +1}; const int kx[] = {+1, +2, -1, -2, +1, +2, -1, -2}; const int ky[] = {+2, +1, +2, +1, -2, -1, -2, -1}; // #pragma GCC target ("avx2") // #pragma GCC optimization ("O3") // #pragma GCC optimization ("unroll-loops") inline void fastIO() { ios_base::sync_with_stdio(0); cin.tie(0); } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; } template <typename T, size_t size> ostream &operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; } template <typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); } #ifdef LOCAL #define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__) #else #define debug(...) 47 #endif const int MAXN = 202020; ll n, k; vector<ll> lens(MAXN); bool possible(ll val) { ll tot = 0; for (int i = 0; i < n; i++) { if (lens[i] % val == 0) { tot += (lens[i] / val) - 1; } else { tot += ((lens[i] / val)); } } return (tot <= k); } int main() { fastIO(); cin >> n >> k; for (int i = 0; i < n; i++) { cin >> lens[i]; } ll l = 0, h = (1e9) + 5; while (l < h) { ll mid = (l + h) / 2; if (mid == 0) { l = 1; break; } if (possible(mid)) { h = mid; } else { l = mid + 1; } } cout << l << endl; return 0; }
insert
70
70
70
74
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPr(i, n) for (int i = (n)-1; i >= 0; --i) #define FORq(i, m, n) for (int i = (m); i <= (n); ++i) #define FORqr(i, m, n) for (int i = (n); i >= (m); --i) #define MP make_pair #define SIN(x, S) (S.count(x) != 0) #define M0(x) memset(x, 0, sizeof(x)) #define FILL(x, y) memset(x, y, sizeof(x)) #define MM(x) memset(x, -1, sizeof(x)) #define ALL(x) (x).begin(), (x).end() #define DB(x) cerr << #x << " = " << x << endl #define DB2(x, y) \ cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"; #define DEBUG \ int x12345; \ cin >> x12345; typedef pair<int, int> PII; typedef pair<long long, long long> PLL; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<long long> VL; typedef long long ll; typedef long long integer; const long long MOD = 1e9 + 7; /////////////////////////////////////////////// // for template template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } /////////////////////////////////////////////// /// 🍈( '-' 🍈 |AC| vector<ll> A(200002); ll N, K; bool check(ll value) { ll count = 0; REP(i, N) { count += ((A[i] + value - 1) / value) - 1; } if (count <= K) return true; else return false; } ll binary_search(ll key) { // lower_bound (a-1,b] (ans = [a,b]) // <= left never satisfy // right <= always satisfy ll left = -1; ll right = 2 * 1e9 + 1; // index of size + 1; while (right - left > 1) { ll mid = left + (right - left) / 2; if (check(mid)) right = mid; else left = mid; } // left is the maximum that don't satisfy the condition. // right is the minimum that satisfies the condtion. return right; } int main() { cin >> N >> K; REP(i, N) { cin >> A[i]; } ll ans = binary_search(100); cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPr(i, n) for (int i = (n)-1; i >= 0; --i) #define FORq(i, m, n) for (int i = (m); i <= (n); ++i) #define FORqr(i, m, n) for (int i = (n); i >= (m); --i) #define MP make_pair #define SIN(x, S) (S.count(x) != 0) #define M0(x) memset(x, 0, sizeof(x)) #define FILL(x, y) memset(x, y, sizeof(x)) #define MM(x) memset(x, -1, sizeof(x)) #define ALL(x) (x).begin(), (x).end() #define DB(x) cerr << #x << " = " << x << endl #define DB2(x, y) \ cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"; #define DEBUG \ int x12345; \ cin >> x12345; typedef pair<int, int> PII; typedef pair<long long, long long> PLL; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<long long> VL; typedef long long ll; typedef long long integer; const long long MOD = 1e9 + 7; /////////////////////////////////////////////// // for template template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } /////////////////////////////////////////////// /// 🍈( '-' 🍈 |AC| vector<ll> A(200002); ll N, K; bool check(ll value) { ll count = 0; REP(i, N) { count += ((A[i] + value - 1) / value) - 1; } if (count <= K) return true; else return false; } ll binary_search(ll key) { // lower_bound (a-1,b] (ans = [a,b]) // <= left never satisfy // right <= always satisfy ll left = 0; ll right = 1e9 + 1; // index of size + 1; while (right - left > 1) { ll mid = left + (right - left) / 2; if (check(mid)) right = mid; else left = mid; } // left is the maximum that don't satisfy the condition. // right is the minimum that satisfies the condtion. return right; } int main() { cin >> N >> K; REP(i, N) { cin >> A[i]; } ll ans = binary_search(100); cout << ans << endl; }
replace
64
66
64
66
0
p02598
C++
Runtime Error
// Hail god Yato #include <bits/stdc++.h> using namespace std; #define hs \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); typedef long long ll; const ll mod = 1000000007; const ll INF = 1e10; const ll MAX = 100001; // // vector<ll> vec(MAX); int check(ll mid, ll k) { ll cuts = 0; for (ll z : vec) { cuts += ((z - 1) / mid); } return cuts <= k; } void solve() { ll n, k; cin >> n >> k; for (int i = 0; i < n; i++) cin >> vec[i]; ll lo = 1, hi = INF; while (lo < hi) { ll mid = (lo + hi) >> 1; if (check(mid, k)) hi = mid; else lo = mid + 1; } cout << lo; } int main() { hs; ll t; t = 1; // cin>>t; for (int i = 1; i <= t; i++) { // cout<<"Case #"<<i<<": "; solve(); } return 0; }
// Hail god Yato #include <bits/stdc++.h> using namespace std; #define hs \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); typedef long long ll; const ll mod = 1000000007; const ll INF = 1e9; const ll MAX = 200005; // // vector<ll> vec(MAX); int check(ll mid, ll k) { ll cuts = 0; for (ll z : vec) { cuts += ((z - 1) / mid); } return cuts <= k; } void solve() { ll n, k; cin >> n >> k; for (int i = 0; i < n; i++) cin >> vec[i]; ll lo = 1, hi = INF; while (lo < hi) { ll mid = (lo + hi) >> 1; if (check(mid, k)) hi = mid; else lo = mid + 1; } cout << lo; } int main() { hs; ll t; t = 1; // cin>>t; for (int i = 1; i <= t; i++) { // cout<<"Case #"<<i<<": "; solve(); } return 0; }
replace
11
13
11
13
0
p02598
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int N, K, m = 0; cin >> N >> K; vector<int> A(N); for (int i = 0; i < N; i++) { cin >> A[i]; m = max(A[i], m); } int l = 1, r = m; int ans = m; for (int j = 0; j < 10000; j++) { if (l == r) break; int a = l + (r - l) / 2; int M = 0, k = 0; bool ok = true; for (int i = 0; i < N; i++) { if (A[i] <= a) continue; k += A[i] / a; // if(A[i]/a==0)ok=false; } if (ok && k <= K) { ans = min(a, ans); r = a; } else { l = a; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N, K, m = 0; cin >> N >> K; vector<int> A(N); for (int i = 0; i < N; i++) { cin >> A[i]; m = max(A[i], m); } int l = 1, r = m; int ans = m; for (int j = 0; j < 100; j++) { if (l == r) break; int a = l + (r - l) / 2; int M = 0, k = 0; bool ok = true; for (int i = 0; i < N; i++) { if (A[i] <= a) continue; k += A[i] / a; // if(A[i]/a==0)ok=false; } if (ok && k <= K) { ans = min(a, ans); r = a; } else { l = a; } } cout << ans << endl; }
replace
13
14
13
14
TLE
p02598
C++
Runtime Error
#include <algorithm> #include <functional> #include <iostream> #include <vector> using namespace std; #define REP(i, n) for (int i = 0; i < (int)(n); ++i) #define ALL(c) (c).begin(), (c).end() // 区間[a, b)の中で最初に pred(x) = true となるような x を返す。 // そのような x が存在しないときは b を返す。 template <class Pred> int64_t bin_search(int64_t a, int64_t b, Pred pred) { // 不変条件: i<a ⇒ pred(i) = false, i>=b ⇒ pred(i) = true if (a == b) return b; int64_t m = a + (b - a) / 2; if (pred(m)) return bin_search(a, m, pred); else return bin_search(m + 1, b, pred); } inline int64_t div_ceil(int64_t a, int64_t b) noexcept { return (a + b - 1) / b; } int main() { int N; cin >> N; int64_t K; cin >> K; vector<int64_t> A(N); REP(i, N) cin >> A[i]; int64_t S = 0; REP(i, N) S += A[i]; int64_t ans = bin_search(0, S + 1, [&](int64_t L) { // 最大の丸太の長さが L 以下になるように切ることができるか int64_t k = 0; REP(i, N) k += div_ceil(A[i], L) - 1; return k <= K; }); cout << ans << '\n'; }
#include <algorithm> #include <functional> #include <iostream> #include <vector> using namespace std; #define REP(i, n) for (int i = 0; i < (int)(n); ++i) #define ALL(c) (c).begin(), (c).end() // 区間[a, b)の中で最初に pred(x) = true となるような x を返す。 // そのような x が存在しないときは b を返す。 template <class Pred> int64_t bin_search(int64_t a, int64_t b, Pred pred) { // 不変条件: i<a ⇒ pred(i) = false, i>=b ⇒ pred(i) = true if (a == b) return b; int64_t m = a + (b - a) / 2; if (pred(m)) return bin_search(a, m, pred); else return bin_search(m + 1, b, pred); } inline int64_t div_ceil(int64_t a, int64_t b) noexcept { return (a + b - 1) / b; } int main() { int N; cin >> N; int64_t K; cin >> K; vector<int64_t> A(N); REP(i, N) cin >> A[i]; int64_t S = 0; REP(i, N) S += A[i]; int64_t ans = bin_search(1, S + 1, [&](int64_t L) { // 最大の丸太の長さが L 以下になるように切ることができるか int64_t k = 0; REP(i, N) k += div_ceil(A[i], L) - 1; return k <= K; }); cout << ans << '\n'; }
replace
37
38
37
38
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long INF = 1e15; #include <math.h> #define PI 3.14159265358979323846264338327950L const int mxN = 1e9 + 7; int main() { int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; int l = 0, r = 1e9; int ans = 0; while (l <= r) { int m = l + (r - l) / 2; long long sum = 0; for (int i = 0; i < n; i++) { sum += (a[i] - 1) / m; } if (sum > k) { l = m + 1; } else { ans = m; r = m - 1; } } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long INF = 1e15; #include <math.h> #define PI 3.14159265358979323846264338327950L const int mxN = 1e9 + 7; int main() { int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; int l = 1, r = 1e9; int ans = 0; while (l <= r) { int m = l + (r - l) / 2; long long sum = 0; for (int i = 0; i < n; i++) { sum += (a[i] - 1) / m; } if (sum > k) { l = m + 1; } else { ans = m; r = m - 1; } } cout << ans; return 0; }
replace
16
17
16
17
0
p02598
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <string> #include <utility> #include <vector> using namespace std; #define int long long #define endl "\n" constexpr long long INF = (long long)1e18; constexpr long long MOD = 1'000'000'007; struct fast_io { fast_io() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); }; } fio; int N, K; vector<int> A; bool check(int n) { int con = 0; for (int i = 0; i < N; i++) { if (A[i] < n) continue; con += (A[i]) / n; } return con <= K; } bool check2(int n) { int con = 0; int z = 0; for (int i = 0; i < N; i++) { if (A[i] < n) continue; con += (A[i]) / n; if (A[i] % n == 0) con--; } // if(z == N) return true; // return false; return con > K; } signed main() { cout << fixed << setprecision(10); cin >> N >> K; A.resize(N); for (int i = 0; i < N; i++) { cin >> A[i]; } int l = 0, h = 1e10, m = 0; while (l + 1 < h) { m = (l + h) / 2; if (!check(m)) { l = m; } else { h = m; } } // cout<<l<<endl; if (check2(l)) l++; cout << l << endl; return 0; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <string> #include <utility> #include <vector> using namespace std; #define int long long #define endl "\n" constexpr long long INF = (long long)1e18; constexpr long long MOD = 1'000'000'007; struct fast_io { fast_io() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); }; } fio; int N, K; vector<int> A; bool check(int n) { int con = 0; for (int i = 0; i < N; i++) { if (A[i] < n) continue; con += (A[i]) / n; } return con <= K; } bool check2(int n) { int con = 0; int z = 0; for (int i = 0; i < N; i++) { if (A[i] < n) continue; con += (A[i]) / n; if (A[i] % n == 0) con--; } // if(z == N) return true; // return false; return con > K; } signed main() { cout << fixed << setprecision(10); cin >> N >> K; A.resize(N); for (int i = 0; i < N; i++) { cin >> A[i]; } int l = 1, h = 1e10, m = 0; while (l + 1 < h) { m = (l + h) / 2; if (!check(m)) { l = m; } else { h = m; } } // cout<<l<<endl; if (check2(l)) l++; cout << l << endl; return 0; }
replace
71
72
71
72
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int n, k, a[200005]; bool pos(int l) { int cnt = 0; for (int i = 0; i < n; ++i) { cnt += (a[i] + l - 1) / l - 1; } if (cnt > k) return false; return true; } int main() { scanf("%d%d", &n, &k); for (int i = 0; i < n; ++i) { scanf("%d", &a[i]); } int lo = 0, hi = 1000000000, ans = hi; while (lo <= hi) { int mid = (hi + lo) / 2; // printf("%d %d\n", mid, pos(mid)); if (pos(mid)) { ans = mid; hi = mid - 1; } else { lo = mid + 1; } } printf("%d", ans); }
#include <bits/stdc++.h> using namespace std; int n, k, a[200005]; bool pos(int l) { if (l == 0) return false; int cnt = 0; for (int i = 0; i < n; ++i) { cnt += (a[i] + l - 1) / l - 1; } if (cnt > k) return false; return true; } int main() { scanf("%d%d", &n, &k); for (int i = 0; i < n; ++i) { scanf("%d", &a[i]); } int lo = 0, hi = 1000000000, ans = hi; while (lo <= hi) { int mid = (hi + lo) / 2; // printf("%d %d\n", mid, pos(mid)); if (pos(mid)) { ans = mid; hi = mid - 1; } else { lo = mid + 1; } } printf("%d", ans); }
insert
6
6
6
8
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n; ll k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; auto isok = [&](int m) -> bool { int sum = 0; for (auto aa : a) sum += (aa + m - 1) / m - 1; return sum <= k; }; int l = -1; int r = *max_element(a.begin(), a.end()); while (r - l > 1) { int m = l + (r - l) / 2; if (isok(m)) { r = m; } else { l = m; } } cout << r << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n; ll k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; auto isok = [&](int m) -> bool { int sum = 0; for (auto aa : a) sum += (aa + m - 1) / m - 1; return sum <= k; }; int l = 0; int r = 1e9; while (r - l > 1) { int m = l + (r - l) / 2; if (isok(m)) { r = m; } else { l = m; } } cout << r << endl; return 0; }
replace
23
25
23
25
0
p02598
C++
Runtime Error
#define _CRT_SECURE_NO_WARNINGS 1 #include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <ctime> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define LL long long #define pii pair<int, int> #define sd(x) scanf("%d", &x) #define slld(x) scanf("%lld", &x) #define pd(x) printf("%d\n", x) #define plld(x) printf("%lld\n", x) #define rep(i, a, b) for (int i = (a); i <= (b); i++) #define per(i, a, b) for (int i = (a); i >= (b); i--) #define mem(a) memset(a, 0, sizeof(a)) #define lson l, m, rt << 1 #define rson m + 1, r, rt << 1 | 1 #define fast_io ios::sync_with_stdio(false) const int INF = 1e9; const LL mod = 1e9 + 7; const int maxn = 2e5 + 7; int a[maxn]; int n, k; bool check(int mid) { int res = 0; rep(i, 1, n) { if (a[i] <= mid) continue; res += a[i] / mid; } return res <= k; } int main() { sd(n), sd(k); rep(i, 1, n) sd(a[i]); int l = 0, r = INF; int ans = 0; while (l <= r) { int mid = (l + r + 1) >> 1; // cout << "mid = " << mid << endl; if (check(mid)) { ans = mid; r = mid - 1; } else { l = mid + 1; } } pd(ans); return 0; }
#define _CRT_SECURE_NO_WARNINGS 1 #include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <ctime> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define LL long long #define pii pair<int, int> #define sd(x) scanf("%d", &x) #define slld(x) scanf("%lld", &x) #define pd(x) printf("%d\n", x) #define plld(x) printf("%lld\n", x) #define rep(i, a, b) for (int i = (a); i <= (b); i++) #define per(i, a, b) for (int i = (a); i >= (b); i--) #define mem(a) memset(a, 0, sizeof(a)) #define lson l, m, rt << 1 #define rson m + 1, r, rt << 1 | 1 #define fast_io ios::sync_with_stdio(false) const int INF = 1e9; const LL mod = 1e9 + 7; const int maxn = 2e5 + 7; int a[maxn]; int n, k; bool check(int mid) { int res = 0; rep(i, 1, n) { if (a[i] <= mid) continue; res += a[i] / mid; } return res <= k; } int main() { sd(n), sd(k); rep(i, 1, n) sd(a[i]); int l = 1, r = INF; int ans = 0; while (l <= r) { int mid = (l + r + 1) >> 1; // cout << "mid = " << mid << endl; if (check(mid)) { ans = mid; r = mid - 1; } else { l = mid + 1; } } pd(ans); return 0; }
replace
52
53
52
53
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) typedef long long ll; typedef pair<int, int> P; typedef map<int, int> MP; #define INF 1e9 int main(int, char **) { int n, k; cin >> n >> k; vector<int> a(n); int l = 0, r = 0, mid; rep(i, n) { cin >> a[i]; r = max(r, a[i]); } while (r > l) { mid = (l + r) / 2; int cnt = 0; rep(i, n) { cnt += (a[i] + mid - 1) / mid - 1; } if (cnt <= k) { r = mid; } else { l = mid + 1; } } cout << l << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) typedef long long ll; typedef pair<int, int> P; typedef map<int, int> MP; #define INF 1e9 int main(int, char **) { int n, k; cin >> n >> k; vector<int> a(n); int l = 1, r = 0, mid; rep(i, n) { cin >> a[i]; r = max(r, a[i]); } while (r > l) { mid = (l + r) / 2; int cnt = 0; rep(i, n) { cnt += (a[i] + mid - 1) / mid - 1; } if (cnt <= k) { r = mid; } else { l = mid + 1; } } cout << l << endl; return 0; }
replace
16
17
16
17
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> #define int long long using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; ++i) cin >> a[i]; int lo = 0, hi = 1e10; while (lo < hi) { int mid = (lo + hi) / 2, r = 0; for (int i = 0; i < n; ++i) { r += a[i] / mid; if (a[i] % mid != 0) r++; } if (r <= n + k) { hi = mid; } else lo = mid + 1; } cout << hi; }
#include <bits/stdc++.h> #define int long long using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; ++i) cin >> a[i]; int lo = 1, hi = 1e10; while (lo < hi) { int mid = (lo + hi) / 2, r = 0; for (int i = 0; i < n; ++i) { r += a[i] / mid; if (a[i] % mid != 0) r++; } if (r <= n + k) { hi = mid; } else lo = mid + 1; } cout << hi; }
replace
13
14
13
14
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, a) for (int i = 0; i < (a); i++) typedef long long ll; #ifdef _DEBUG inline void dump() { cerr << endl; } template <typename Head> void dump(Head &&head) { cerr << head; dump(); } template <typename Head, typename... Tail> void dump(Head &&head, Tail &&...tail) { cerr << head << ", "; dump(forward<Tail>(tail)...); } #define debug(...) \ do { \ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; \ dump(__VA_ARGS__); \ } while (false) #else #define dump(...) #define debug(...) #endif template <typename T> struct edge { int src, to; T cost; edge(int to, T cost) : src(-1), to(to), cost(cost) {} edge(int src, int to, T cost) : src(src), to(to), cost(cost) {} edge &operator=(const int &x) { to = x; return *this; } operator int() const { return to; } }; template <typename T> using Edges = vector<edge<T>>; template <typename T> using WeightedGraph = vector<Edges<T>>; using UnWeightedGraph = vector<vector<int>>; template <typename T> using Matrix = vector<vector<T>>; ///////////////////////////////////////////////////////////////////// const ll inf = 1LL << 60; int main() { ll n, k; cin >> n >> k; vector<ll> a(n); rep(i, n) cin >> a[i]; ll l = 0; ll r = 1000000001; while (l < r) { ll m = (l + r) / 2; ll t = 0; rep(i, n) { t += (a[i] - 1) / m; } if (t <= k) r = m; else l = m + 1; } cout << l << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, a) for (int i = 0; i < (a); i++) typedef long long ll; #ifdef _DEBUG inline void dump() { cerr << endl; } template <typename Head> void dump(Head &&head) { cerr << head; dump(); } template <typename Head, typename... Tail> void dump(Head &&head, Tail &&...tail) { cerr << head << ", "; dump(forward<Tail>(tail)...); } #define debug(...) \ do { \ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; \ dump(__VA_ARGS__); \ } while (false) #else #define dump(...) #define debug(...) #endif template <typename T> struct edge { int src, to; T cost; edge(int to, T cost) : src(-1), to(to), cost(cost) {} edge(int src, int to, T cost) : src(src), to(to), cost(cost) {} edge &operator=(const int &x) { to = x; return *this; } operator int() const { return to; } }; template <typename T> using Edges = vector<edge<T>>; template <typename T> using WeightedGraph = vector<Edges<T>>; using UnWeightedGraph = vector<vector<int>>; template <typename T> using Matrix = vector<vector<T>>; ///////////////////////////////////////////////////////////////////// const ll inf = 1LL << 60; int main() { ll n, k; cin >> n >> k; vector<ll> a(n); rep(i, n) cin >> a[i]; ll l = 1; ll r = 1000000001; while (l < r) { ll m = (l + r) / 2; ll t = 0; rep(i, n) { t += (a[i] - 1) / m; } if (t <= k) r = m; else l = m + 1; } cout << l << endl; return 0; }
replace
52
53
52
53
0
p02598
C++
Runtime Error
#include <algorithm> #include <bits/stdc++.h> #include <iomanip> #include <iostream> #include <math.h> #include <string.h> #include <string> #define ll long long int #define pb push_back #define fi first #define se second #define N 100005 #define inf 1e18 #define mem(a, b) memset(a, b, sizeof(a)) #define debug(x) cout << (#x) << " = " << x << endl; #define debug2(i, j) \ cout << (#i) << "=" << i << " , " << (#j) << "=" << j << endl; using namespace std; ll binomialCoeff(ll n, ll k) { ll res = 1; if (k > n - k) k = n - k; for (int i = 0; i < k; ++i) { res *= (n - i); res /= (i + 1); } return res; } ll mod = 1e9 + 7; ll power(ll x, ll y) { ll temp; if (y == 0) return 1; temp = power(x, y / 2); if (y % 2 == 0) return (temp * temp) % mod; else return (((x * temp) % mod) * temp) % mod; } /* nCr % mod ll fact[6*N]; ll inv[6*N],invfac[6*N]; ll mod = 998244353; void factorial() { fact[0] = invfac[0] = fact[1] = invfac[1] = 1; inv[1] = 1; for(int i=2;i<=5*N + 10;i++) { fact[i] = (fact[i-1]*i)%mod; inv[i] = (inv[mod%i]*(mod - mod/i))%mod; invfac[i] = (invfac[i-1]*inv[i])%mod; } }*/ vector<ll> primes; void Sieve(int n) { vector<bool> prime(n + 1, true); for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (int i = p * p; i <= n; i += p) prime[i] = false; } } for (int p = 2; p <= n; p++) if (prime[p]) primes.push_back(p); } //****************************************************** CHECK CONSTRAINTS //***************************************************************// const int Nmax = 1e6 + 6; ll n, k; ll arr[Nmax]; bool check(ll mid) { ll o = 0; for (int i = 0; i < n; i++) { ll c = arr[i] / mid; if (c == 0) continue; long double v = (1.0 * arr[i]) / (1.0 * c); if (v > mid) c++; o += c - 1; if (o > k) return false; } return true; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> k; for (int i = 0; i < n; i++) cin >> arr[i]; ll low = 0; ll high = 1e12; while (low <= high) { ll mid = (low + high) / 2; if (check(mid)) high = mid - 1; else low = mid + 1; } cout << low; }
#include <algorithm> #include <bits/stdc++.h> #include <iomanip> #include <iostream> #include <math.h> #include <string.h> #include <string> #define ll long long int #define pb push_back #define fi first #define se second #define N 100005 #define inf 1e18 #define mem(a, b) memset(a, b, sizeof(a)) #define debug(x) cout << (#x) << " = " << x << endl; #define debug2(i, j) \ cout << (#i) << "=" << i << " , " << (#j) << "=" << j << endl; using namespace std; ll binomialCoeff(ll n, ll k) { ll res = 1; if (k > n - k) k = n - k; for (int i = 0; i < k; ++i) { res *= (n - i); res /= (i + 1); } return res; } ll mod = 1e9 + 7; ll power(ll x, ll y) { ll temp; if (y == 0) return 1; temp = power(x, y / 2); if (y % 2 == 0) return (temp * temp) % mod; else return (((x * temp) % mod) * temp) % mod; } /* nCr % mod ll fact[6*N]; ll inv[6*N],invfac[6*N]; ll mod = 998244353; void factorial() { fact[0] = invfac[0] = fact[1] = invfac[1] = 1; inv[1] = 1; for(int i=2;i<=5*N + 10;i++) { fact[i] = (fact[i-1]*i)%mod; inv[i] = (inv[mod%i]*(mod - mod/i))%mod; invfac[i] = (invfac[i-1]*inv[i])%mod; } }*/ vector<ll> primes; void Sieve(int n) { vector<bool> prime(n + 1, true); for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (int i = p * p; i <= n; i += p) prime[i] = false; } } for (int p = 2; p <= n; p++) if (prime[p]) primes.push_back(p); } //****************************************************** CHECK CONSTRAINTS //***************************************************************// const int Nmax = 1e6 + 6; ll n, k; ll arr[Nmax]; bool check(ll mid) { ll o = 0; for (int i = 0; i < n; i++) { ll c = arr[i] / mid; if (c == 0) continue; long double v = (1.0 * arr[i]) / (1.0 * c); if (v > mid) c++; o += c - 1; if (o > k) return false; } return true; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> k; for (int i = 0; i < n; i++) cin >> arr[i]; ll low = 1; ll high = 1e12; while (low <= high) { ll mid = (low + high) / 2; if (check(mid)) high = mid - 1; else low = mid + 1; } cout << low; }
replace
107
108
107
108
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> #define ALL(c) begin(c), end(c) using namespace std; using ll = long long; using ld = long double; const int N = 1e6 + 6; int main() { // freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); ios::sync_with_stdio(0); cin.tie(0); // cout.precision(12);cout<<fixed; int n, k; cin >> n >> k; vector<int> a(n); for (auto &_ : a) cin >> _; int l = 0, r = 1e9 + 9; while (l < r) { int d = (l + r) >> 1; int cnt = 0; for (int x : a) cnt += (x + d - 1) / d - 1; if (cnt > k) l = d + 1; else r = d; } cout << r << endl; return 0; }
#include <bits/stdc++.h> #define ALL(c) begin(c), end(c) using namespace std; using ll = long long; using ld = long double; const int N = 1e6 + 6; int main() { // freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); ios::sync_with_stdio(0); cin.tie(0); // cout.precision(12);cout<<fixed; int n, k; cin >> n >> k; vector<int> a(n); for (auto &_ : a) cin >> _; int l = 1, r = 1e9 + 9; while (l < r) { int d = (l + r) >> 1; int cnt = 0; for (int x : a) cnt += (x + d - 1) / d - 1; if (cnt > k) l = d + 1; else r = d; } cout << r << endl; return 0; }
replace
20
21
20
21
0
p02598
C++
Runtime Error
#include <algorithm> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <math.h> #include <numeric> #include <queue> #include <stack> #include <string> #include <tuple> #include <vector> using namespace std; typedef long long LL; typedef unsigned long long ULL; typedef vector<LL> VLL; typedef vector<ULL> VULL; typedef vector<VLL> VVLL; class Large_Integer { private: // n進数 static const LL shinsuu = 7; // 符号付絶対値で表現 LL sign; VLL numbers; // 補数表現された整数の足し算 static VLL plusVector(VLL a, VLL b) { VLL ans(max(a.size(), b.size()), 0); for (LL i = 0; i < ans.size(); i++) { if (i < a.size()) ans[i] += a[i]; if (i < b.size()) ans[i] += b[i]; if (i + 1 < ans.size()) { ans[i + 1] += (ans[i] / Large_Integer::shinsuu); } ans[i] %= Large_Integer::shinsuu; } return ans; } // 符号付絶対値を補数表現に変換 static VLL ToVLL(Large_Integer const &a, LL const &min) { LL i; VLL ans; if (a.sign == 1) { ans = VLL(max(min, (LL)a.numbers.size()) + 5, 0); for (i = 0; i < a.numbers.size(); i++) { ans[i] += a.numbers[i]; } } else { ans = VLL(max(min, (LL)a.numbers.size()) + 5, Large_Integer::shinsuu - 1); for (i = 0; i < a.numbers.size(); i++) { ans[i] -= a.numbers[i]; } ans = Large_Integer::plusVector(ans, VLL(1, 1)); } return ans; } // 補数表現を符号付き絶対値に変換 static Large_Integer ToInteger(VLL const &a) { Large_Integer ans; LL i, j, k, n; n = a.size(); if (a[n - 1] == Large_Integer::shinsuu - 1) { auto temp = VLL(n, Large_Integer::shinsuu - 1); temp = Large_Integer::plusVector(a, temp); // ここから for (i = 0; i < temp.size(); i++) { temp[i] -= Large_Integer::shinsuu; temp[i] *= -1; } ans.sign = -1; ans.numbers = temp; ans.Syusei(); } else { ans.sign = 1; ans.numbers = a; ans.Syusei(); } return ans; } // シフト演算子 Large_Integer operator<<(Large_Integer const &a) const { LL shift = a.to_LongLong(), i; if (shift < 0) { return *this >> (shift * -1); } Large_Integer ans = *this; ans.numbers = VLL(this->numbers.size() + shift, 0); for (i = 0; i < this->numbers.size(); i++) { ans.numbers[i + shift] += this->numbers[i]; } ans.Syusei(); return ans; } Large_Integer operator>>(Large_Integer const &a) const { LL shift = a.to_LongLong(), i; if (shift < 0) { return *this << (shift * -1); } Large_Integer ans = *this; ans.numbers = VLL(max((LL)0, (LL)this->numbers.size() - shift), 0); for (i = 0; i < this->numbers.size(); i++) { if (i - shift >= 0) { ans.numbers[i - shift] = this->numbers[i]; } } ans.Syusei(); return ans; } // 掛け算(long long) Large_Integer operator*(LL const &b) const { Large_Integer ans; ans.sign = this->sign; ans.numbers = VLL(this->numbers.size() + 2, 0); LL i, a = b; if (a < 0) { a *= -1; ans.sign *= -1; } for (i = 0; i < this->numbers.size(); i++) { ans.numbers[i] = a * this->numbers[i]; } for (i = 0; i < ans.numbers.size(); i++) { if (i + 1 < ans.numbers.size()) { ans.numbers[i + 1] = (ans.numbers[i] / Large_Integer::shinsuu); } ans.numbers[i] %= Large_Integer::shinsuu; } return ans; } // 誤りの検知と修正 void Syusei() { LL i, j, k; if (abs(this->sign) != 1) { j = 0; j = 1 / j; } k = 0; for (i = 0; i < this->numbers.size(); i++) { if (this->numbers[i] < 0) { j = 0; j = 1 / j; } if (i + 1 < this->numbers.size()) { this->numbers[i + 1] += (this->numbers[i] / Large_Integer::shinsuu); } this->numbers[i] %= Large_Integer::shinsuu; if (this->numbers[i] > 0) k = i + 1; } VLL ans(k, 0); for (i = 0; i < k; i++) { ans[i] = this->numbers[i]; } this->numbers = ans; if (this->sign == -1 && this->numbers.size() == 0) { this->sign = 1; } } public: // コンストラクタたち Large_Integer(Large_Integer const &b) { *this = b; } Large_Integer(LL const &b) { if (b < 0) this->sign = -1; else this->sign = 1; auto c = abs(b); while (c > 0) { this->numbers.push_back(c % this->shinsuu); c /= this->shinsuu; } this->Syusei(); } Large_Integer() { this->sign = 1; this->numbers = VLL(0); } // long long型に変換する LL to_LongLong() const { LL ans = 0, i; for (i = this->numbers.size() - 1; i >= 0; i--) { ans *= this->shinsuu; ans += this->numbers[i]; } ans *= this->sign; return ans; } // 代入演算子 Large_Integer operator=(Large_Integer const &b) { this->sign = b.sign; this->numbers = b.numbers; return *this; } // 足し算 Large_Integer operator+(Large_Integer const &b) const { LL i, j; VLL x, y; LL size = max(this->numbers.size(), b.numbers.size()); x = Large_Integer::ToVLL(*this, size); y = Large_Integer::ToVLL(b, size); x = Large_Integer::plusVector(x, y); auto ans = Large_Integer::ToInteger(x); ans.Syusei(); return ans; } Large_Integer operator+=(Large_Integer const &b) { return *this = (*this + b); } // 掛け算 Large_Integer operator*(Large_Integer const &b) const { Large_Integer ans = 0; LL i; for (i = 0; i < b.numbers.size(); i++) { ans += ((*this * b.numbers[i]) << i); } return ans; } Large_Integer operator*=(Large_Integer const &b) { return *this = (*this * b); } Large_Integer operator-(Large_Integer const &b) const { return *this + (b * -1); } Large_Integer operator-=(Large_Integer const &b) { return *this = (*this - b); } // 未完成 bool operator<(Large_Integer const &b) const { LL i, j, k; if (this->sign < b.sign) { return true; } if (this->sign > b.sign) { return false; } if (this->sign == 1) { if (this->numbers.size() < b.numbers.size()) { return true; } if (this->numbers.size() > b.numbers.size()) { return false; } for (i = this->numbers.size() - 1; i >= 0; i--) { if (this->numbers[i] < b.numbers[i]) { return true; } if (this->numbers[i] > b.numbers[i]) { return false; } } } } }; // 改良vector template <typename T> class ArrayList : public vector<T> { public: ArrayList(long long const &size, T const &a) : vector<T>(size, a) {} ArrayList(long long const &size) : vector<T>(size) {} ArrayList() : vector<T>() {} T &operator[](long long const &index) { return vector<T>::at(index); } }; typedef ArrayList<LL> ALL; typedef ArrayList<ALL> AALL; // 剰余整数 class ModInt { private: LL n; static LL modP; public: ModInt(ModInt const &b) { this->n = b.n; } ModInt(LL const &b) { this->n = b % ModInt::modP; } ModInt() { *this = ModInt(0); } LL GetMod() const { return ModInt::modP; } void SetMod(LL const &a) { ModInt::modP = abs(a); } LL getNumber() const { return this->n; } ModInt operator=(ModInt const &b) { this->n = b.n; return *this; } ModInt operator+(ModInt const &b) const { return ModInt(this->n + b.n); } ModInt operator+=(ModInt const &b) { return *this = (*this + b); } ModInt operator-(ModInt const &b) const { LL temp = this->n - b.n + ModInt::modP; return ModInt(temp); } ModInt operator-=(ModInt const &b) { return *this = (*this - b); } ModInt operator*(ModInt const &b) const { LL temp = this->n * b.n; return ModInt(temp); } ModInt operator*=(ModInt const &b) { return *this = (*this * b); } ModInt Pow(ModInt const &b) const { LL p = b.n; ModInt ans = 1; ModInt x = *this; while (p > 0) { if (p % 2 == 1) { ans *= x; } x = x * x; p /= 2; } return ans; } ModInt operator/(ModInt const &b) const { ModInt temp = b.Pow(ModInt::modP - 2); return *this * temp; } ModInt operator/=(ModInt const &b) { return *this = (*this / b); } }; LL ModInt::modP = 1000 * 1000 * 1000 + 7; // 関数詰め合わせ class KyoPro { public: static const LL MOD_CONST = (LL)1000 * 1000 * 1000 + 7; static LL DebugFlag; // 数値を区切って文字列にする static string MakeString_LongLong(vector<long long> const &numbers, string const &str) { if (numbers.size() == 0) return ""; string result = "" + to_string(numbers[0]); for (long long i = 1; i < numbers.size(); i++) { result += str; result += to_string(numbers[i]); } return result; } // 空白で区切る為のオーバーロード static string MakeString_LongLong(vector<long long> const &numbers) { if (numbers.size() == 0) return ""; string result = "" + to_string(numbers[0]); for (long long i = 1; i < numbers.size(); i++) { result += " "; result += to_string(numbers[i]); } return result; } // 文字列の配列を改行を挟んでまとめる static string MakeString_VectorString(vector<string> const &str) { string result = ""; for (long long i = 0; i < str.size(); i++) { result += str[i] + "\n"; } return result; } // 文字列を必要な個数だけ読み取る static vector<string> MyReadLineSplit(LL n) { vector<string> str(n); for (long long i = 0; i < n; i++) { std::cin >> str[i]; } return str; } // 数値を必要な個数だけ読み取る static vector<long long> ReadInts(long long number) { vector<long long> a(number); for (int i = 0; i < number; i++) { std::cin >> a[i]; } return a; } // 渡された自然数が素数ならtureを返す static bool PrimeCheck_Int(long long number) { if (number < 2) return false; for (ULL i = 2; i * i <= number; i++) { if (number % i == 0) return false; } return true; } // 自然数が平方数か判定する static bool SquareCheck(LL const &number) { if (KyoPro::PrimeCheck_Int(number)) return false; LL m = number; for (LL i = 2; i <= m; i++) { if (m % i == 0) { LL count = 0; while (m % i == 0) { m /= i; count++; } if (count % 2 == 1) return false; } } return true; } // 渡された数値以下の素数表を作る static vector<long long> MakePrimeList(long long n) { vector<long long> list; LL i, j, p; bool flag; for (i = 2; i <= n; i++) { flag = true; for (j = 0; j < list.size(); j++) { if (!(list[j] * list[j] <= i)) break; if (i % list[j] == 0) { flag = false; break; } } if (flag) list.push_back(i); } return list; } // 文字列の分割 static vector<string> split(string const &str, char sep) { vector<std::string> v; // 分割結果を格納するベクター auto first = str.begin(); // テキストの最初を指すイテレータ while (first != str.end()) { // テキストが残っている間ループ auto last = first; // 分割文字列末尾へのイテレータ while (last != str.end() && *last != sep) // 末尾 or セパレータ文字まで進める last++; v.push_back(string(first, last)); // 分割文字を出力 if (last != str.end()) last++; first = last; // 次の処理のためにイテレータを設定 } return v; } // 合計を求める template <typename T> static LL Sum(T const &a) { LL sum = 0; auto itr = a.begin(); while (itr != a.end()) { sum += (*itr); itr++; } return sum; } // 小文字ならtrueを返す static bool Komoji(char a) { if (a >= 'a' && a <= 'z') return true; return false; } // 大文字ならtrueを返す static bool Oomoji(char a) { if (a >= 'A' && a <= 'Z') return true; return false; } // 切り上げの整数値割り算 static LL KiriageWarizan(LL a, LL b) { LL result = a / b; if (a % b > 0) result++; return result; } // 最大公約数を求める static LL GreatestCommonFactor(LL a, LL b) { a = KyoPro::abs(a); b = KyoPro::abs(b); LL temp; if (a < b) { temp = b; b = a; a = temp; } while (b > 0) { temp = a % b; a = b; b = temp; } return a; } // 最小公倍数を求める static LL LeastCommonMultiple(LL a, LL b) { return (a / GreatestCommonFactor(a, b)) * b; } // 二次元配列を行列とみなして転置する static VVLL VVLLturn(VVLL a) { if (a.size() == 0) return VVLL(0); VVLL result(a[0].size(), VLL(a.size())); LL i, j; for (i = 0; i < a.size(); i++) { for (j = 0; j < a[0].size(); j++) { result[j][i] = a[i][j]; } } return result; } // 素因数分解、素数、指数の順 static vector<VLL> PrimeFactorization(LL n) { VLL p_list, s_list; LL i, j, k, count; for (i = 2; n > 1; i++) { if (i * i > n) { p_list.push_back(n); s_list.push_back(1); break; } if (n % i == 0) { count = 0; while (n % i == 0) { n /= i; count++; } p_list.push_back(i); s_list.push_back(count); } } vector<VLL> result; result.push_back(p_list); result.push_back(s_list); return KyoPro::VVLLturn(result); } // 整数nの約数の配列を作る static VLL MakeYakusuList(LL n) { auto primes = KyoPro::PrimeFactorization(n); VLL ans; VLL roop(primes.size(), 0); LL i, j, k, m, size = roop.size(); while (true) { LL a = 1; for (i = 0; i < size; i++) { for (j = 0; j < roop[i]; j++) { a *= primes[i][0]; } } ans.push_back(a); roop[0]++; for (i = 0; i < size; i++) { if (i + 1 < size) { roop[i + 1] += (roop[i] / (primes[i][1] + 1)); } roop[i] %= (primes[i][1] + 1); } bool flag = true; for (i = 0; i < size; i++) { if (roop[i] != 0) flag = false; } if (flag) break; } return KyoPro::Sort(ans); } // 組み合わせ nCrを10^9+7で割った余りを返す static LL Combination(LL n, LL r) { ModInt ans = 1; r = min(r, n - r); for (LL i = 0; i < r; i++) { ans *= (n - i); ans /= (i + 1); } return ans.getNumber(); } // 順列 nPrを10^9+7で割った余りを返す static LL Permutation(LL n, LL r) { ModInt ans = 1; for (LL i = 0; i < r; i++) { ans *= (n - i); } return ans.getNumber(); } // 重複組み合わせ。n種類からr個重複を許して選ぶ static LL nHr(LL n, LL r) { return KyoPro::Combination(n + r - 1, r); } template <typename T> static T pow(T const &a, LL const &b) { T ans = 1; auto p = b; auto x = a; while (p > 0) { if (p % 2 == 1) { ans *= x; } x = x * x; p /= 2; } return ans; } // 符号 template <typename T> static T sign(T const &x) { if (x > 0) return 1; if (x < 0) return -1; return 0; } // 絶対値 template <typename T> static T abs(T x) { if (x < 0) { x = x * -1; } return x; } // 円周率 static double PI() { return (double)3.1415926535898; } // 指定した桁でdoubleを出す。改行はしない。 static void CoutDoubleKeta(double a, LL keta) { cout << setprecision(keta) << a << flush; } // コンテナクラスの出力 template <typename T> static T CoutVector(T const &ls) { LL i, j, k, size = distance(ls.begin(), ls.end()); if (size == 0) return ls; auto itr = ls.begin(); for (i = 0; i < size - 1; i++) { cout << *itr << " " << flush; itr++; } cout << *itr << flush; return ls; } // コンテナクラスをソートする template <typename T> static T Sort(T &ls) { sort(ls.begin(), ls.end()); return ls; } // 順序関数付きでコンテナクラスをソートする template <typename T, typename F> static T Sort(T &ls, F const &func) { sort(ls.begin(), ls.end(), func); return ls; } // コンテナクラスを逆順に並び替える template <typename T> static T Reverse(T &ls) { reverse(ls.begin(), ls.end()); return ls; } // コンテナクラスの条件を満たす要素を数え上げる。bool func(S x) template <typename T, typename S> static LL Count(T const &ls, S func) { LL ans = 0; auto itr = ls.begin(); while (itr != ls.end()) { if (func(*itr)) ans++; itr++; } return ans; } // コンテナクラスの要素をすべて更新する。S func(S x) template <typename T, typename S> static T AllUpdate(T &ls, S func) { auto itr = ls.begin(); while (itr != ls.end()) { *itr = func(*itr); itr++; } return ls; } // リストをベクターに変換する template <typename T> static vector<T> FromListToVector(list<T> const &a) { vector<T> ans; for (auto itr = a.begin(); itr != a.end(); itr++) { ans.push_back(*itr); } return ans; } // ベクターをリストに変換する template <typename T> static list<T> FromVectorToList(vector<T> a) { list<T> ans; for (auto itr = a.begin(); itr != a.end(); itr++) { ans.push_back(*itr); } return ans; } // 最大値の要素番号を求める template <typename T> static LL MaxElementIndex(T const &ls) { return distance(ls.begin(), max_element(ls.begin(), ls.end())); } // 最小値の要素番号を求める template <typename T> static LL MinElementIndex(T const &ls) { return distance(ls.begin(), min_element(ls.begin(), ls.end())); } // デバッグ用出力 template <typename T> static LL DebugPrintf(T output) { if (KyoPro::DebugFlag) { std::cout << output << endl; } return KyoPro::DebugFlag; } // デバッグ用入力 static LL DebugCin() { LL a; if (KyoPro::DebugFlag) { cin >> a; } return a; } }; LL KyoPro::DebugFlag = 0; // 累積和を求めるクラス class Ruisekiwa { private: vector<LL> list; public: void MakeArray(vector<LL> data) { LL i; list = data; list.push_back(0); list[0] = 0; for (i = 1; i < list.size(); i++) { list[i] = list[i - 1] + data[i - 1]; } } LL Sum(LL start, LL end) { if (end < start) { std::cout << "startがendより大きいです"; return 0; } if (start < 0 || end >= list.size()) { std::cout << "範囲が異常"; return 0; } return list[end] - list[start]; } }; // n進数を管理するクラス class N_Number { public: N_Number(LL n, LL keta) { this->N_Shinsuu = n; VLL temp(keta, 0); this->numbers = temp; } // 数を足す void plus(LL a) { if (a < 0) { a *= (-1); this->minus(a); return; } this->numbers[0] += a; LL size = this->numbers.size(); for (LL i = 0; i < size; i++) { if (i + 1 < size) { this->numbers[i + 1] += this->numbers[i] / this->N_Shinsuu; } this->numbers[i] %= this->N_Shinsuu; } } // 全ての桁が同じ数字になっていればその数字を返す。それ以外の場合は -1 を返す LL check() { LL a = this->numbers[0]; for (LL i = 0; i < this->numbers.size(); i++) { if (this->numbers[i] != a) return -1; } return a; } LL getNumber(LL keta) { return this->numbers[keta]; } LL getKeta() { return this->numbers.size(); } LL getShinsuu() { return this->N_Shinsuu; } void setNumber(LL keta, LL number) { if (0 <= number && number < this->getShinsuu()) { if (0 <= keta && keta < this->getKeta()) { this->numbers[keta] = number; return; } } cout << "er" << endl; } void setAllNumbers(LL number) { LL size = this->getKeta(), i; for (i = 0; i < size; i++) { this->setNumber(i, number); } } string to_string_KetaSoroe() { string s = ""; for (LL i = this->getKeta() - 1; i >= 0; i--) { s += to_string(this->getNumber(i)); } return s; } private: void minus(LL a) { LL i, j, k, zettaiti = abs(a); k = KyoPro::KiriageWarizan(zettaiti, this->N_Shinsuu); j = k * (this->N_Shinsuu - 1); for (i = 0; i < this->getKeta(); i++) { this->numbers[i] += j; } this->numbers[0] += k - a; this->plus(0); } VLL numbers; LL N_Shinsuu; }; // UnionFind class Union_Find { private: VLL tree; VLL count; LL root(LL a) { if (this->tree[a] == a) return a; return this->tree[a] = this->root(this->tree[a]); } public: Union_Find(LL n) { VLL set(n); this->tree = set; this->count = set; for (LL i = 0; i < n; i++) { this->tree[i] = i; this->count[i] = 1; } } void unite(LL a, LL b) { LL x, y; if (!this->Check(a, b)) { x = this->getCount(a) + getCount(b); y = this->root(a); this->count[y] = x; y = this->root(b); this->count[y] = x; } x = this->root(a); y = this->root(b); this->tree[x] = y; } bool Check(LL a, LL b) { return this->root(a) == this->root(b); } LL getCount(LL index) { LL temp = this->root(index); return this->count[temp]; } LL getRoot(LL index) { return this->root(index); } VLL getList() { VLL ans(this->tree.size(), 0); for (LL i = 0; i < ans.size(); i++) { ans[i] = this->root(i); } return ans; } }; // プラスマイナス無限に対応したlong long型 class INF_LONG_LONG { private: LL inf, n; public: // コンストラクタ INF_LONG_LONG(LL a) { this->n = a; this->inf = 0; this->Syusei(); } INF_LONG_LONG() { *this = INF_LONG_LONG(0); } INF_LONG_LONG(INF_LONG_LONG const &a) { this->n = a.n; this->inf = a.inf; this->Syusei(); } // ゲッター LL getN() const { return this->n; } LL getInf() const { return this->inf; } // 正の無限大生成 static INF_LONG_LONG plus_inf() { INF_LONG_LONG a; a.n = 0; a.inf = 1; a.Syusei(); return a; } // 負の無限大生成 static INF_LONG_LONG minus_inf() { INF_LONG_LONG a; a.n = 0; a.inf = -1; a.Syusei(); return a; } // 符号を取得 LL sign() const { if (this->inf != 0) { return this->inf; } return KyoPro::sign(this->n); } // 代入演算子 INF_LONG_LONG operator=(INF_LONG_LONG const &b) { this->n = b.n; this->inf = b.inf; this->Syusei(); return *this; } INF_LONG_LONG operator=(LL const &b) { *this = INF_LONG_LONG(b); this->Syusei(); return *this; } // 比較演算子 bool operator==(INF_LONG_LONG const &b) const { if (this->n == b.n && this->inf == b.inf) return true; return false; } bool operator!=(INF_LONG_LONG const &b) const { return !(*this == b); } bool operator<(INF_LONG_LONG const &b) const { if (this->inf < b.inf) return true; if (this->inf > b.inf) return false; return this->n < b.n; } bool operator>(INF_LONG_LONG const &b) const { return b < *this; } bool operator<=(INF_LONG_LONG const &b) const { return !(*this > b); } bool operator>=(INF_LONG_LONG const &b) const { return !(*this < b); } // 算術演算子 INF_LONG_LONG operator+(INF_LONG_LONG const &b) const { if (max(this->inf, b.inf) > 0) return INF_LONG_LONG::plus_inf(); if (min(this->inf, b.inf) < 0) return INF_LONG_LONG::minus_inf(); auto ans = *this; ans.n += b.n; ans.Syusei(); return ans; } INF_LONG_LONG operator*(INF_LONG_LONG const &b) const { if (*this == INF_LONG_LONG(0) || b == INF_LONG_LONG(0)) { return INF_LONG_LONG(0); } if (this->inf != 0 || b.inf != 0) { LL s = this->sign() * b.sign(); INF_LONG_LONG ans(0); ans.n = 0; ans.inf = s; ans.Syusei(); return ans; } INF_LONG_LONG ans(0); ans.n = this->n * b.n; ans.Syusei(); return ans; } INF_LONG_LONG operator-(INF_LONG_LONG const &b) const { auto ans = (*this + (INF_LONG_LONG(-1) * b)); ans.Syusei(); return ans; } INF_LONG_LONG operator/(INF_LONG_LONG const &b) const { if (b == INF_LONG_LONG(0)) { LL a = this->n / b.n; return INF_LONG_LONG(a); } if (b.inf != 0) { return INF_LONG_LONG(0); } if (*this == INF_LONG_LONG(0)) { return INF_LONG_LONG(0); } if (this->inf != 0) { LL s = this->sign() * b.sign(); return INF_LONG_LONG::plus_inf() * INF_LONG_LONG(s); } INF_LONG_LONG ans; ans.n = this->n / b.n; ans.Syusei(); return ans; } INF_LONG_LONG operator%(INF_LONG_LONG const &b) const { if (this->inf == 0 && b.inf == 0) { INF_LONG_LONG ans; ans.n = this->n % b.n; ans.Syusei(); return ans; } auto x = *this / b; x.Syusei(); auto ans = *this - b * x; ans.Syusei(); return ans; } // 複合代入演算子 INF_LONG_LONG operator+=(INF_LONG_LONG const &b) { auto ans = *this + b; *this = ans; return *this; } INF_LONG_LONG operator-=(INF_LONG_LONG const &b) { auto ans = *this - b; *this = ans; return *this; } INF_LONG_LONG operator*=(INF_LONG_LONG const &b) { auto ans = *this * b; *this = ans; return *this; } INF_LONG_LONG operator/=(INF_LONG_LONG const &b) { auto ans = *this / b; *this = ans; return *this; } INF_LONG_LONG operator%=(INF_LONG_LONG const &b) { auto ans = *this % b; *this = ans; return *this; } // 符号演算子 INF_LONG_LONG operator+() const { return *this; } INF_LONG_LONG operator-() const { return *this * INF_LONG_LONG(-1); } // 前置きインクリメント・デクリメント INF_LONG_LONG operator++() { this->n++; this->Syusei(); return *this; } INF_LONG_LONG operator--() { this->n--; this->Syusei(); return *this; } // 後置きインクリメント・デクリメント INF_LONG_LONG operator++(int) { auto copy = *this; ++(*this); return copy; } INF_LONG_LONG operator--(int) { auto copy = *this; --(*this); return copy; } // 文字列への変換 string ToString() const { if (this->inf == 1) { return "+INF"; } if (this->inf == -1) { return "-INF"; } return to_string(this->n); } private: void Syusei() { if (this->inf != 0) { this->n = 0; } } }; typedef INF_LONG_LONG ILL_TYPE; typedef vector<ILL_TYPE> VILL_TYPE; typedef vector<VILL_TYPE> VVILL_TYPE; // ワーシャルフロイド class WarshallFloyd { public: // 最短距離を記録 VVILL_TYPE d; // 頂点数 LL v; // vは頂点数、edge_cost_listは辺の情報{始点、終点、コスト}の配列。無向グラフの場合、逆矢印の辺に注意。 WarshallFloyd(LL v, VVLL edge_cost_list) { this->v = v; this->d = VVILL_TYPE(v, VILL_TYPE(v, ILL_TYPE::plus_inf())); LL i, j, k, a, b, c; for (i = 0; i < edge_cost_list.size(); i++) { a = edge_cost_list[i][0]; b = edge_cost_list[i][1]; c = edge_cost_list[i][2]; this->d[a][b] = ILL_TYPE(c); } for (i = 0; i < v; i++) { this->d[i][i] = ILL_TYPE(0); } // ここから計算 for (k = 0; k < v; k++) { for (i = 0; i < v; i++) { for (j = 0; j < v; j++) { d[i][j] = min(d[i][j], d[i][k] + d[k][j]); } } } } }; // ベルマンフォード class BellmanFord { public: // 辺のリスト VVILL_TYPE edge; // 頂点数、辺数 LL v, e; // 始点 LL s; // 最短距離 VILL_TYPE d; // vは頂点数、startは始点、edge_cost_listは辺の情報{始点、終点、コスト}の配列。 BellmanFord(LL v, LL start, VVLL edge_cost_list) { this->v = v; this->s = start; this->e = edge_cost_list.size(); this->d = VILL_TYPE(v, ILL_TYPE::plus_inf()); this->d[start] = 0; LL i, j, k; for (i = 0; i < this->e; i++) { VILL_TYPE temp; LL a, b, c; a = edge_cost_list[i][0]; b = edge_cost_list[i][1]; c = edge_cost_list[i][2]; temp.push_back(ILL_TYPE(a)); temp.push_back(ILL_TYPE(b)); temp.push_back(ILL_TYPE(c)); this->edge.push_back(temp); } this->DoUpdata(); auto cpy = this->d; this->DoUpdata(); for (i = 0; i < this->d.size(); i++) { if (this->d[i] != cpy[i]) { this->d[i] = ILL_TYPE::minus_inf(); } } this->DoUpdata(); } private: void DoUpdata() { LL i, j, k; for (i = 0; i <= this->v; i++) { bool update = true; for (j = 0; j < this->e; j++) { ILL_TYPE c; LL a, b; a = this->edge[j][0].getN(); b = this->edge[j][1].getN(); c = this->edge[j][2]; if (this->d[a] < ILL_TYPE::plus_inf()) { if (this->d[a] + c < this->d[b]) { update = false; this->d[b] = this->d[a] + c; } } } if (update) break; } } }; // ダイクストラ class Dijkstra { public: Dijkstra(LL v, LL start, VVLL edge_cost_list) {} }; // ライブラリはここまで // ここから下を書く bool tryF(vector<LL> const &ls, LL g, LL k) { LL sum = 0; for (auto v : ls) { sum += KyoPro::KiriageWarizan(v, g) - 1; } if (sum <= k) { return true; } return false; } // ここからメイン int main(void) { KyoPro::DebugFlag = 0; LL n, k; cin >> n >> k; auto ls = KyoPro::ReadInts(n); LL mx = KyoPro::pow((LL)10, 10), mn = 0; while (mn <= mx) { LL middle = (mx + mn) / 2; bool b1, b2; b1 = tryF(ls, middle - 1, k); b2 = tryF(ls, middle, k); if (!b1 && b2) { cout << middle << endl; return 0; } else if (!b2) { mn = middle + 1; } else if (b1) { mx = middle - 1; } } cout << mn << endl; return 0; }
#include <algorithm> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <math.h> #include <numeric> #include <queue> #include <stack> #include <string> #include <tuple> #include <vector> using namespace std; typedef long long LL; typedef unsigned long long ULL; typedef vector<LL> VLL; typedef vector<ULL> VULL; typedef vector<VLL> VVLL; class Large_Integer { private: // n進数 static const LL shinsuu = 7; // 符号付絶対値で表現 LL sign; VLL numbers; // 補数表現された整数の足し算 static VLL plusVector(VLL a, VLL b) { VLL ans(max(a.size(), b.size()), 0); for (LL i = 0; i < ans.size(); i++) { if (i < a.size()) ans[i] += a[i]; if (i < b.size()) ans[i] += b[i]; if (i + 1 < ans.size()) { ans[i + 1] += (ans[i] / Large_Integer::shinsuu); } ans[i] %= Large_Integer::shinsuu; } return ans; } // 符号付絶対値を補数表現に変換 static VLL ToVLL(Large_Integer const &a, LL const &min) { LL i; VLL ans; if (a.sign == 1) { ans = VLL(max(min, (LL)a.numbers.size()) + 5, 0); for (i = 0; i < a.numbers.size(); i++) { ans[i] += a.numbers[i]; } } else { ans = VLL(max(min, (LL)a.numbers.size()) + 5, Large_Integer::shinsuu - 1); for (i = 0; i < a.numbers.size(); i++) { ans[i] -= a.numbers[i]; } ans = Large_Integer::plusVector(ans, VLL(1, 1)); } return ans; } // 補数表現を符号付き絶対値に変換 static Large_Integer ToInteger(VLL const &a) { Large_Integer ans; LL i, j, k, n; n = a.size(); if (a[n - 1] == Large_Integer::shinsuu - 1) { auto temp = VLL(n, Large_Integer::shinsuu - 1); temp = Large_Integer::plusVector(a, temp); // ここから for (i = 0; i < temp.size(); i++) { temp[i] -= Large_Integer::shinsuu; temp[i] *= -1; } ans.sign = -1; ans.numbers = temp; ans.Syusei(); } else { ans.sign = 1; ans.numbers = a; ans.Syusei(); } return ans; } // シフト演算子 Large_Integer operator<<(Large_Integer const &a) const { LL shift = a.to_LongLong(), i; if (shift < 0) { return *this >> (shift * -1); } Large_Integer ans = *this; ans.numbers = VLL(this->numbers.size() + shift, 0); for (i = 0; i < this->numbers.size(); i++) { ans.numbers[i + shift] += this->numbers[i]; } ans.Syusei(); return ans; } Large_Integer operator>>(Large_Integer const &a) const { LL shift = a.to_LongLong(), i; if (shift < 0) { return *this << (shift * -1); } Large_Integer ans = *this; ans.numbers = VLL(max((LL)0, (LL)this->numbers.size() - shift), 0); for (i = 0; i < this->numbers.size(); i++) { if (i - shift >= 0) { ans.numbers[i - shift] = this->numbers[i]; } } ans.Syusei(); return ans; } // 掛け算(long long) Large_Integer operator*(LL const &b) const { Large_Integer ans; ans.sign = this->sign; ans.numbers = VLL(this->numbers.size() + 2, 0); LL i, a = b; if (a < 0) { a *= -1; ans.sign *= -1; } for (i = 0; i < this->numbers.size(); i++) { ans.numbers[i] = a * this->numbers[i]; } for (i = 0; i < ans.numbers.size(); i++) { if (i + 1 < ans.numbers.size()) { ans.numbers[i + 1] = (ans.numbers[i] / Large_Integer::shinsuu); } ans.numbers[i] %= Large_Integer::shinsuu; } return ans; } // 誤りの検知と修正 void Syusei() { LL i, j, k; if (abs(this->sign) != 1) { j = 0; j = 1 / j; } k = 0; for (i = 0; i < this->numbers.size(); i++) { if (this->numbers[i] < 0) { j = 0; j = 1 / j; } if (i + 1 < this->numbers.size()) { this->numbers[i + 1] += (this->numbers[i] / Large_Integer::shinsuu); } this->numbers[i] %= Large_Integer::shinsuu; if (this->numbers[i] > 0) k = i + 1; } VLL ans(k, 0); for (i = 0; i < k; i++) { ans[i] = this->numbers[i]; } this->numbers = ans; if (this->sign == -1 && this->numbers.size() == 0) { this->sign = 1; } } public: // コンストラクタたち Large_Integer(Large_Integer const &b) { *this = b; } Large_Integer(LL const &b) { if (b < 0) this->sign = -1; else this->sign = 1; auto c = abs(b); while (c > 0) { this->numbers.push_back(c % this->shinsuu); c /= this->shinsuu; } this->Syusei(); } Large_Integer() { this->sign = 1; this->numbers = VLL(0); } // long long型に変換する LL to_LongLong() const { LL ans = 0, i; for (i = this->numbers.size() - 1; i >= 0; i--) { ans *= this->shinsuu; ans += this->numbers[i]; } ans *= this->sign; return ans; } // 代入演算子 Large_Integer operator=(Large_Integer const &b) { this->sign = b.sign; this->numbers = b.numbers; return *this; } // 足し算 Large_Integer operator+(Large_Integer const &b) const { LL i, j; VLL x, y; LL size = max(this->numbers.size(), b.numbers.size()); x = Large_Integer::ToVLL(*this, size); y = Large_Integer::ToVLL(b, size); x = Large_Integer::plusVector(x, y); auto ans = Large_Integer::ToInteger(x); ans.Syusei(); return ans; } Large_Integer operator+=(Large_Integer const &b) { return *this = (*this + b); } // 掛け算 Large_Integer operator*(Large_Integer const &b) const { Large_Integer ans = 0; LL i; for (i = 0; i < b.numbers.size(); i++) { ans += ((*this * b.numbers[i]) << i); } return ans; } Large_Integer operator*=(Large_Integer const &b) { return *this = (*this * b); } Large_Integer operator-(Large_Integer const &b) const { return *this + (b * -1); } Large_Integer operator-=(Large_Integer const &b) { return *this = (*this - b); } // 未完成 bool operator<(Large_Integer const &b) const { LL i, j, k; if (this->sign < b.sign) { return true; } if (this->sign > b.sign) { return false; } if (this->sign == 1) { if (this->numbers.size() < b.numbers.size()) { return true; } if (this->numbers.size() > b.numbers.size()) { return false; } for (i = this->numbers.size() - 1; i >= 0; i--) { if (this->numbers[i] < b.numbers[i]) { return true; } if (this->numbers[i] > b.numbers[i]) { return false; } } } } }; // 改良vector template <typename T> class ArrayList : public vector<T> { public: ArrayList(long long const &size, T const &a) : vector<T>(size, a) {} ArrayList(long long const &size) : vector<T>(size) {} ArrayList() : vector<T>() {} T &operator[](long long const &index) { return vector<T>::at(index); } }; typedef ArrayList<LL> ALL; typedef ArrayList<ALL> AALL; // 剰余整数 class ModInt { private: LL n; static LL modP; public: ModInt(ModInt const &b) { this->n = b.n; } ModInt(LL const &b) { this->n = b % ModInt::modP; } ModInt() { *this = ModInt(0); } LL GetMod() const { return ModInt::modP; } void SetMod(LL const &a) { ModInt::modP = abs(a); } LL getNumber() const { return this->n; } ModInt operator=(ModInt const &b) { this->n = b.n; return *this; } ModInt operator+(ModInt const &b) const { return ModInt(this->n + b.n); } ModInt operator+=(ModInt const &b) { return *this = (*this + b); } ModInt operator-(ModInt const &b) const { LL temp = this->n - b.n + ModInt::modP; return ModInt(temp); } ModInt operator-=(ModInt const &b) { return *this = (*this - b); } ModInt operator*(ModInt const &b) const { LL temp = this->n * b.n; return ModInt(temp); } ModInt operator*=(ModInt const &b) { return *this = (*this * b); } ModInt Pow(ModInt const &b) const { LL p = b.n; ModInt ans = 1; ModInt x = *this; while (p > 0) { if (p % 2 == 1) { ans *= x; } x = x * x; p /= 2; } return ans; } ModInt operator/(ModInt const &b) const { ModInt temp = b.Pow(ModInt::modP - 2); return *this * temp; } ModInt operator/=(ModInt const &b) { return *this = (*this / b); } }; LL ModInt::modP = 1000 * 1000 * 1000 + 7; // 関数詰め合わせ class KyoPro { public: static const LL MOD_CONST = (LL)1000 * 1000 * 1000 + 7; static LL DebugFlag; // 数値を区切って文字列にする static string MakeString_LongLong(vector<long long> const &numbers, string const &str) { if (numbers.size() == 0) return ""; string result = "" + to_string(numbers[0]); for (long long i = 1; i < numbers.size(); i++) { result += str; result += to_string(numbers[i]); } return result; } // 空白で区切る為のオーバーロード static string MakeString_LongLong(vector<long long> const &numbers) { if (numbers.size() == 0) return ""; string result = "" + to_string(numbers[0]); for (long long i = 1; i < numbers.size(); i++) { result += " "; result += to_string(numbers[i]); } return result; } // 文字列の配列を改行を挟んでまとめる static string MakeString_VectorString(vector<string> const &str) { string result = ""; for (long long i = 0; i < str.size(); i++) { result += str[i] + "\n"; } return result; } // 文字列を必要な個数だけ読み取る static vector<string> MyReadLineSplit(LL n) { vector<string> str(n); for (long long i = 0; i < n; i++) { std::cin >> str[i]; } return str; } // 数値を必要な個数だけ読み取る static vector<long long> ReadInts(long long number) { vector<long long> a(number); for (int i = 0; i < number; i++) { std::cin >> a[i]; } return a; } // 渡された自然数が素数ならtureを返す static bool PrimeCheck_Int(long long number) { if (number < 2) return false; for (ULL i = 2; i * i <= number; i++) { if (number % i == 0) return false; } return true; } // 自然数が平方数か判定する static bool SquareCheck(LL const &number) { if (KyoPro::PrimeCheck_Int(number)) return false; LL m = number; for (LL i = 2; i <= m; i++) { if (m % i == 0) { LL count = 0; while (m % i == 0) { m /= i; count++; } if (count % 2 == 1) return false; } } return true; } // 渡された数値以下の素数表を作る static vector<long long> MakePrimeList(long long n) { vector<long long> list; LL i, j, p; bool flag; for (i = 2; i <= n; i++) { flag = true; for (j = 0; j < list.size(); j++) { if (!(list[j] * list[j] <= i)) break; if (i % list[j] == 0) { flag = false; break; } } if (flag) list.push_back(i); } return list; } // 文字列の分割 static vector<string> split(string const &str, char sep) { vector<std::string> v; // 分割結果を格納するベクター auto first = str.begin(); // テキストの最初を指すイテレータ while (first != str.end()) { // テキストが残っている間ループ auto last = first; // 分割文字列末尾へのイテレータ while (last != str.end() && *last != sep) // 末尾 or セパレータ文字まで進める last++; v.push_back(string(first, last)); // 分割文字を出力 if (last != str.end()) last++; first = last; // 次の処理のためにイテレータを設定 } return v; } // 合計を求める template <typename T> static LL Sum(T const &a) { LL sum = 0; auto itr = a.begin(); while (itr != a.end()) { sum += (*itr); itr++; } return sum; } // 小文字ならtrueを返す static bool Komoji(char a) { if (a >= 'a' && a <= 'z') return true; return false; } // 大文字ならtrueを返す static bool Oomoji(char a) { if (a >= 'A' && a <= 'Z') return true; return false; } // 切り上げの整数値割り算 static LL KiriageWarizan(LL a, LL b) { LL result = a / b; if (a % b > 0) result++; return result; } // 最大公約数を求める static LL GreatestCommonFactor(LL a, LL b) { a = KyoPro::abs(a); b = KyoPro::abs(b); LL temp; if (a < b) { temp = b; b = a; a = temp; } while (b > 0) { temp = a % b; a = b; b = temp; } return a; } // 最小公倍数を求める static LL LeastCommonMultiple(LL a, LL b) { return (a / GreatestCommonFactor(a, b)) * b; } // 二次元配列を行列とみなして転置する static VVLL VVLLturn(VVLL a) { if (a.size() == 0) return VVLL(0); VVLL result(a[0].size(), VLL(a.size())); LL i, j; for (i = 0; i < a.size(); i++) { for (j = 0; j < a[0].size(); j++) { result[j][i] = a[i][j]; } } return result; } // 素因数分解、素数、指数の順 static vector<VLL> PrimeFactorization(LL n) { VLL p_list, s_list; LL i, j, k, count; for (i = 2; n > 1; i++) { if (i * i > n) { p_list.push_back(n); s_list.push_back(1); break; } if (n % i == 0) { count = 0; while (n % i == 0) { n /= i; count++; } p_list.push_back(i); s_list.push_back(count); } } vector<VLL> result; result.push_back(p_list); result.push_back(s_list); return KyoPro::VVLLturn(result); } // 整数nの約数の配列を作る static VLL MakeYakusuList(LL n) { auto primes = KyoPro::PrimeFactorization(n); VLL ans; VLL roop(primes.size(), 0); LL i, j, k, m, size = roop.size(); while (true) { LL a = 1; for (i = 0; i < size; i++) { for (j = 0; j < roop[i]; j++) { a *= primes[i][0]; } } ans.push_back(a); roop[0]++; for (i = 0; i < size; i++) { if (i + 1 < size) { roop[i + 1] += (roop[i] / (primes[i][1] + 1)); } roop[i] %= (primes[i][1] + 1); } bool flag = true; for (i = 0; i < size; i++) { if (roop[i] != 0) flag = false; } if (flag) break; } return KyoPro::Sort(ans); } // 組み合わせ nCrを10^9+7で割った余りを返す static LL Combination(LL n, LL r) { ModInt ans = 1; r = min(r, n - r); for (LL i = 0; i < r; i++) { ans *= (n - i); ans /= (i + 1); } return ans.getNumber(); } // 順列 nPrを10^9+7で割った余りを返す static LL Permutation(LL n, LL r) { ModInt ans = 1; for (LL i = 0; i < r; i++) { ans *= (n - i); } return ans.getNumber(); } // 重複組み合わせ。n種類からr個重複を許して選ぶ static LL nHr(LL n, LL r) { return KyoPro::Combination(n + r - 1, r); } template <typename T> static T pow(T const &a, LL const &b) { T ans = 1; auto p = b; auto x = a; while (p > 0) { if (p % 2 == 1) { ans *= x; } x = x * x; p /= 2; } return ans; } // 符号 template <typename T> static T sign(T const &x) { if (x > 0) return 1; if (x < 0) return -1; return 0; } // 絶対値 template <typename T> static T abs(T x) { if (x < 0) { x = x * -1; } return x; } // 円周率 static double PI() { return (double)3.1415926535898; } // 指定した桁でdoubleを出す。改行はしない。 static void CoutDoubleKeta(double a, LL keta) { cout << setprecision(keta) << a << flush; } // コンテナクラスの出力 template <typename T> static T CoutVector(T const &ls) { LL i, j, k, size = distance(ls.begin(), ls.end()); if (size == 0) return ls; auto itr = ls.begin(); for (i = 0; i < size - 1; i++) { cout << *itr << " " << flush; itr++; } cout << *itr << flush; return ls; } // コンテナクラスをソートする template <typename T> static T Sort(T &ls) { sort(ls.begin(), ls.end()); return ls; } // 順序関数付きでコンテナクラスをソートする template <typename T, typename F> static T Sort(T &ls, F const &func) { sort(ls.begin(), ls.end(), func); return ls; } // コンテナクラスを逆順に並び替える template <typename T> static T Reverse(T &ls) { reverse(ls.begin(), ls.end()); return ls; } // コンテナクラスの条件を満たす要素を数え上げる。bool func(S x) template <typename T, typename S> static LL Count(T const &ls, S func) { LL ans = 0; auto itr = ls.begin(); while (itr != ls.end()) { if (func(*itr)) ans++; itr++; } return ans; } // コンテナクラスの要素をすべて更新する。S func(S x) template <typename T, typename S> static T AllUpdate(T &ls, S func) { auto itr = ls.begin(); while (itr != ls.end()) { *itr = func(*itr); itr++; } return ls; } // リストをベクターに変換する template <typename T> static vector<T> FromListToVector(list<T> const &a) { vector<T> ans; for (auto itr = a.begin(); itr != a.end(); itr++) { ans.push_back(*itr); } return ans; } // ベクターをリストに変換する template <typename T> static list<T> FromVectorToList(vector<T> a) { list<T> ans; for (auto itr = a.begin(); itr != a.end(); itr++) { ans.push_back(*itr); } return ans; } // 最大値の要素番号を求める template <typename T> static LL MaxElementIndex(T const &ls) { return distance(ls.begin(), max_element(ls.begin(), ls.end())); } // 最小値の要素番号を求める template <typename T> static LL MinElementIndex(T const &ls) { return distance(ls.begin(), min_element(ls.begin(), ls.end())); } // デバッグ用出力 template <typename T> static LL DebugPrintf(T output) { if (KyoPro::DebugFlag) { std::cout << output << endl; } return KyoPro::DebugFlag; } // デバッグ用入力 static LL DebugCin() { LL a; if (KyoPro::DebugFlag) { cin >> a; } return a; } }; LL KyoPro::DebugFlag = 0; // 累積和を求めるクラス class Ruisekiwa { private: vector<LL> list; public: void MakeArray(vector<LL> data) { LL i; list = data; list.push_back(0); list[0] = 0; for (i = 1; i < list.size(); i++) { list[i] = list[i - 1] + data[i - 1]; } } LL Sum(LL start, LL end) { if (end < start) { std::cout << "startがendより大きいです"; return 0; } if (start < 0 || end >= list.size()) { std::cout << "範囲が異常"; return 0; } return list[end] - list[start]; } }; // n進数を管理するクラス class N_Number { public: N_Number(LL n, LL keta) { this->N_Shinsuu = n; VLL temp(keta, 0); this->numbers = temp; } // 数を足す void plus(LL a) { if (a < 0) { a *= (-1); this->minus(a); return; } this->numbers[0] += a; LL size = this->numbers.size(); for (LL i = 0; i < size; i++) { if (i + 1 < size) { this->numbers[i + 1] += this->numbers[i] / this->N_Shinsuu; } this->numbers[i] %= this->N_Shinsuu; } } // 全ての桁が同じ数字になっていればその数字を返す。それ以外の場合は -1 を返す LL check() { LL a = this->numbers[0]; for (LL i = 0; i < this->numbers.size(); i++) { if (this->numbers[i] != a) return -1; } return a; } LL getNumber(LL keta) { return this->numbers[keta]; } LL getKeta() { return this->numbers.size(); } LL getShinsuu() { return this->N_Shinsuu; } void setNumber(LL keta, LL number) { if (0 <= number && number < this->getShinsuu()) { if (0 <= keta && keta < this->getKeta()) { this->numbers[keta] = number; return; } } cout << "er" << endl; } void setAllNumbers(LL number) { LL size = this->getKeta(), i; for (i = 0; i < size; i++) { this->setNumber(i, number); } } string to_string_KetaSoroe() { string s = ""; for (LL i = this->getKeta() - 1; i >= 0; i--) { s += to_string(this->getNumber(i)); } return s; } private: void minus(LL a) { LL i, j, k, zettaiti = abs(a); k = KyoPro::KiriageWarizan(zettaiti, this->N_Shinsuu); j = k * (this->N_Shinsuu - 1); for (i = 0; i < this->getKeta(); i++) { this->numbers[i] += j; } this->numbers[0] += k - a; this->plus(0); } VLL numbers; LL N_Shinsuu; }; // UnionFind class Union_Find { private: VLL tree; VLL count; LL root(LL a) { if (this->tree[a] == a) return a; return this->tree[a] = this->root(this->tree[a]); } public: Union_Find(LL n) { VLL set(n); this->tree = set; this->count = set; for (LL i = 0; i < n; i++) { this->tree[i] = i; this->count[i] = 1; } } void unite(LL a, LL b) { LL x, y; if (!this->Check(a, b)) { x = this->getCount(a) + getCount(b); y = this->root(a); this->count[y] = x; y = this->root(b); this->count[y] = x; } x = this->root(a); y = this->root(b); this->tree[x] = y; } bool Check(LL a, LL b) { return this->root(a) == this->root(b); } LL getCount(LL index) { LL temp = this->root(index); return this->count[temp]; } LL getRoot(LL index) { return this->root(index); } VLL getList() { VLL ans(this->tree.size(), 0); for (LL i = 0; i < ans.size(); i++) { ans[i] = this->root(i); } return ans; } }; // プラスマイナス無限に対応したlong long型 class INF_LONG_LONG { private: LL inf, n; public: // コンストラクタ INF_LONG_LONG(LL a) { this->n = a; this->inf = 0; this->Syusei(); } INF_LONG_LONG() { *this = INF_LONG_LONG(0); } INF_LONG_LONG(INF_LONG_LONG const &a) { this->n = a.n; this->inf = a.inf; this->Syusei(); } // ゲッター LL getN() const { return this->n; } LL getInf() const { return this->inf; } // 正の無限大生成 static INF_LONG_LONG plus_inf() { INF_LONG_LONG a; a.n = 0; a.inf = 1; a.Syusei(); return a; } // 負の無限大生成 static INF_LONG_LONG minus_inf() { INF_LONG_LONG a; a.n = 0; a.inf = -1; a.Syusei(); return a; } // 符号を取得 LL sign() const { if (this->inf != 0) { return this->inf; } return KyoPro::sign(this->n); } // 代入演算子 INF_LONG_LONG operator=(INF_LONG_LONG const &b) { this->n = b.n; this->inf = b.inf; this->Syusei(); return *this; } INF_LONG_LONG operator=(LL const &b) { *this = INF_LONG_LONG(b); this->Syusei(); return *this; } // 比較演算子 bool operator==(INF_LONG_LONG const &b) const { if (this->n == b.n && this->inf == b.inf) return true; return false; } bool operator!=(INF_LONG_LONG const &b) const { return !(*this == b); } bool operator<(INF_LONG_LONG const &b) const { if (this->inf < b.inf) return true; if (this->inf > b.inf) return false; return this->n < b.n; } bool operator>(INF_LONG_LONG const &b) const { return b < *this; } bool operator<=(INF_LONG_LONG const &b) const { return !(*this > b); } bool operator>=(INF_LONG_LONG const &b) const { return !(*this < b); } // 算術演算子 INF_LONG_LONG operator+(INF_LONG_LONG const &b) const { if (max(this->inf, b.inf) > 0) return INF_LONG_LONG::plus_inf(); if (min(this->inf, b.inf) < 0) return INF_LONG_LONG::minus_inf(); auto ans = *this; ans.n += b.n; ans.Syusei(); return ans; } INF_LONG_LONG operator*(INF_LONG_LONG const &b) const { if (*this == INF_LONG_LONG(0) || b == INF_LONG_LONG(0)) { return INF_LONG_LONG(0); } if (this->inf != 0 || b.inf != 0) { LL s = this->sign() * b.sign(); INF_LONG_LONG ans(0); ans.n = 0; ans.inf = s; ans.Syusei(); return ans; } INF_LONG_LONG ans(0); ans.n = this->n * b.n; ans.Syusei(); return ans; } INF_LONG_LONG operator-(INF_LONG_LONG const &b) const { auto ans = (*this + (INF_LONG_LONG(-1) * b)); ans.Syusei(); return ans; } INF_LONG_LONG operator/(INF_LONG_LONG const &b) const { if (b == INF_LONG_LONG(0)) { LL a = this->n / b.n; return INF_LONG_LONG(a); } if (b.inf != 0) { return INF_LONG_LONG(0); } if (*this == INF_LONG_LONG(0)) { return INF_LONG_LONG(0); } if (this->inf != 0) { LL s = this->sign() * b.sign(); return INF_LONG_LONG::plus_inf() * INF_LONG_LONG(s); } INF_LONG_LONG ans; ans.n = this->n / b.n; ans.Syusei(); return ans; } INF_LONG_LONG operator%(INF_LONG_LONG const &b) const { if (this->inf == 0 && b.inf == 0) { INF_LONG_LONG ans; ans.n = this->n % b.n; ans.Syusei(); return ans; } auto x = *this / b; x.Syusei(); auto ans = *this - b * x; ans.Syusei(); return ans; } // 複合代入演算子 INF_LONG_LONG operator+=(INF_LONG_LONG const &b) { auto ans = *this + b; *this = ans; return *this; } INF_LONG_LONG operator-=(INF_LONG_LONG const &b) { auto ans = *this - b; *this = ans; return *this; } INF_LONG_LONG operator*=(INF_LONG_LONG const &b) { auto ans = *this * b; *this = ans; return *this; } INF_LONG_LONG operator/=(INF_LONG_LONG const &b) { auto ans = *this / b; *this = ans; return *this; } INF_LONG_LONG operator%=(INF_LONG_LONG const &b) { auto ans = *this % b; *this = ans; return *this; } // 符号演算子 INF_LONG_LONG operator+() const { return *this; } INF_LONG_LONG operator-() const { return *this * INF_LONG_LONG(-1); } // 前置きインクリメント・デクリメント INF_LONG_LONG operator++() { this->n++; this->Syusei(); return *this; } INF_LONG_LONG operator--() { this->n--; this->Syusei(); return *this; } // 後置きインクリメント・デクリメント INF_LONG_LONG operator++(int) { auto copy = *this; ++(*this); return copy; } INF_LONG_LONG operator--(int) { auto copy = *this; --(*this); return copy; } // 文字列への変換 string ToString() const { if (this->inf == 1) { return "+INF"; } if (this->inf == -1) { return "-INF"; } return to_string(this->n); } private: void Syusei() { if (this->inf != 0) { this->n = 0; } } }; typedef INF_LONG_LONG ILL_TYPE; typedef vector<ILL_TYPE> VILL_TYPE; typedef vector<VILL_TYPE> VVILL_TYPE; // ワーシャルフロイド class WarshallFloyd { public: // 最短距離を記録 VVILL_TYPE d; // 頂点数 LL v; // vは頂点数、edge_cost_listは辺の情報{始点、終点、コスト}の配列。無向グラフの場合、逆矢印の辺に注意。 WarshallFloyd(LL v, VVLL edge_cost_list) { this->v = v; this->d = VVILL_TYPE(v, VILL_TYPE(v, ILL_TYPE::plus_inf())); LL i, j, k, a, b, c; for (i = 0; i < edge_cost_list.size(); i++) { a = edge_cost_list[i][0]; b = edge_cost_list[i][1]; c = edge_cost_list[i][2]; this->d[a][b] = ILL_TYPE(c); } for (i = 0; i < v; i++) { this->d[i][i] = ILL_TYPE(0); } // ここから計算 for (k = 0; k < v; k++) { for (i = 0; i < v; i++) { for (j = 0; j < v; j++) { d[i][j] = min(d[i][j], d[i][k] + d[k][j]); } } } } }; // ベルマンフォード class BellmanFord { public: // 辺のリスト VVILL_TYPE edge; // 頂点数、辺数 LL v, e; // 始点 LL s; // 最短距離 VILL_TYPE d; // vは頂点数、startは始点、edge_cost_listは辺の情報{始点、終点、コスト}の配列。 BellmanFord(LL v, LL start, VVLL edge_cost_list) { this->v = v; this->s = start; this->e = edge_cost_list.size(); this->d = VILL_TYPE(v, ILL_TYPE::plus_inf()); this->d[start] = 0; LL i, j, k; for (i = 0; i < this->e; i++) { VILL_TYPE temp; LL a, b, c; a = edge_cost_list[i][0]; b = edge_cost_list[i][1]; c = edge_cost_list[i][2]; temp.push_back(ILL_TYPE(a)); temp.push_back(ILL_TYPE(b)); temp.push_back(ILL_TYPE(c)); this->edge.push_back(temp); } this->DoUpdata(); auto cpy = this->d; this->DoUpdata(); for (i = 0; i < this->d.size(); i++) { if (this->d[i] != cpy[i]) { this->d[i] = ILL_TYPE::minus_inf(); } } this->DoUpdata(); } private: void DoUpdata() { LL i, j, k; for (i = 0; i <= this->v; i++) { bool update = true; for (j = 0; j < this->e; j++) { ILL_TYPE c; LL a, b; a = this->edge[j][0].getN(); b = this->edge[j][1].getN(); c = this->edge[j][2]; if (this->d[a] < ILL_TYPE::plus_inf()) { if (this->d[a] + c < this->d[b]) { update = false; this->d[b] = this->d[a] + c; } } } if (update) break; } } }; // ダイクストラ class Dijkstra { public: Dijkstra(LL v, LL start, VVLL edge_cost_list) {} }; // ライブラリはここまで // ここから下を書く bool tryF(vector<LL> const &ls, LL g, LL k) { if (g == 0) { return false; } LL sum = 0; for (auto v : ls) { sum += KyoPro::KiriageWarizan(v, g) - 1; } if (sum <= k) { return true; } return false; } // ここからメイン int main(void) { KyoPro::DebugFlag = 0; LL n, k; cin >> n >> k; auto ls = KyoPro::ReadInts(n); LL mx = KyoPro::pow((LL)10, 10), mn = 0; while (mn <= mx) { LL middle = (mx + mn) / 2; bool b1, b2; b1 = tryF(ls, middle - 1, k); b2 = tryF(ls, middle, k); if (!b1 && b2) { cout << middle << endl; return 0; } else if (!b2) { mn = middle + 1; } else if (b1) { mx = middle - 1; } } cout << mn << endl; return 0; }
insert
1,507
1,507
1,507
1,511
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ALL(x) (x).begin(), (x).end() #define COUT(x) cout << (x) << "\n" #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define REP(i, n) for (int i = 0; i < n; i++) #define YES(x) cout << (x ? "YES" : "NO") << "\n" #define Yes(x) cout << (x ? "Yes" : "No") << "\n" #define dump(x) cout << #x << " = " << (x) << "\n" #define endl "\n" using G = vector<vector<int>>; using M = map<int, int>; using P = pair<int, int>; using PQ = priority_queue<int>; using PQG = priority_queue<int, vector<int>, greater<int>>; using V = vector<int>; using ll = long long; using edge = struct { int to; int cost; }; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } const int INF = 1e9; const int MOD = 1e9 + 7; const ll LINF = 1e18; int main() { IOS; int n, k; cin >> n >> k; vector<int> a(n); REP(i, n) cin >> a[i]; sort(ALL(a), greater<int>()); int ng = -1, ok = a[0]; while (abs(ok - ng) > 1) { int mid = (ok + ng) / 2, cnt = 0; REP(i, n) { if (k < cnt) break; if (a[i] <= mid) break; cnt += a[i] / mid; if (a[i] % mid == 0) cnt--; } if (k < cnt) ng = mid; else ok = mid; } COUT(ok); return 0; }
#include <bits/stdc++.h> using namespace std; #define ALL(x) (x).begin(), (x).end() #define COUT(x) cout << (x) << "\n" #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define REP(i, n) for (int i = 0; i < n; i++) #define YES(x) cout << (x ? "YES" : "NO") << "\n" #define Yes(x) cout << (x ? "Yes" : "No") << "\n" #define dump(x) cout << #x << " = " << (x) << "\n" #define endl "\n" using G = vector<vector<int>>; using M = map<int, int>; using P = pair<int, int>; using PQ = priority_queue<int>; using PQG = priority_queue<int, vector<int>, greater<int>>; using V = vector<int>; using ll = long long; using edge = struct { int to; int cost; }; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } const int INF = 1e9; const int MOD = 1e9 + 7; const ll LINF = 1e18; int main() { IOS; int n, k; cin >> n >> k; vector<int> a(n); REP(i, n) cin >> a[i]; sort(ALL(a), greater<int>()); int ng = 0, ok = a[0]; while (abs(ok - ng) > 1) { int mid = (ok + ng) / 2, cnt = 0; REP(i, n) { if (k < cnt) break; if (a[i] <= mid) break; cnt += a[i] / mid; if (a[i] % mid == 0) cnt--; } if (k < cnt) ng = mid; else ok = mid; } COUT(ok); return 0; }
replace
50
51
50
51
0
p02598
C++
Runtime Error
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { int n, k; scanf("%d %d", &n, &k); vector<int> a(n); int left = 0, right = 0; for (int i = 0; i < n; i++) { scanf("%d", &a[i]); right = max(right, a[i]); } while (left < right) { int mid = (left + right) >> 1; long long t = 0; for (int i = 0; i < n; i++) t += (a[i] - 1) / mid; if (t <= k) right = mid; else left = mid + 1; } printf("%d\n", left); return 0; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { int n, k; scanf("%d %d", &n, &k); vector<int> a(n); int left = 1, right = 0; for (int i = 0; i < n; i++) { scanf("%d", &a[i]); right = max(right, a[i]); } while (left < right) { int mid = (left + right) >> 1; long long t = 0; for (int i = 0; i < n; i++) t += (a[i] - 1) / mid; if (t <= k) right = mid; else left = mid + 1; } printf("%d\n", left); return 0; }
replace
9
10
9
10
0
p02598
C++
Runtime Error
// #include <bits/stdc++.h> // #pragma GCC optimize(2) #include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <time.h> #include <vector> #define X first #define Y second #define PB push_back #define MP make_pair #define scd(a) scanf("%d", &a) #define scdd(a, b) scanf("%d%d", &a, &b) #define scddd(a, b, c) scanf("%d%d%d", &a, &b, &c) #define ALL(x) x.begin(), x.end() #define sz(a) ((int)a.size()) #define getmid ((l + r) >> 1) #define mst(var, val) memset(var, val, sizeof(var)) #define IOS \ ios::sync_with_stdio(false); \ cin.tie(0) #define lowbit(x) x & (-x) #define rep(i, n) for (int i = 0; i < n; ++i) #define rep1(i, n) for (int i = 1; i <= n; ++i) #define ls rt << 1 #define rs rt << 1 | 1 using namespace std; #ifdef local #define dbg(args...) cout << #args << " -> ", err(args); void err() { cout << endl; } template <typename T, typename... Args> void err(T a, Args... args) { cout << a << ' '; err(args...); } #else #define dbg(args...) #endif // local typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<ll, int> pli; typedef pair<double, double> pdd; const int inf = 0x3f3f3f3f; const long long INF = 0x3f3f3f3f3f3f3f3fLL; const double PI = acos(-1.0); const long double eps = 1e-8; const int mod = 1e9 + 7; const int maxn = 3e5 + 100; const int N = 2e5 + 100; const int M = 500 + 10; const ll mm = (1LL << 32); template <class T> inline void read(T &x) { x = 0; char c = getchar(); bool f = 0; for (; !isdigit(c); c = getchar()) f ^= c == '-'; for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); x = f ? -x : x; } template <class T> inline void write(T x) { if (x < 0) { putchar('-'); x = -x; } T y = 1; int len = 1; for (; y <= x / 10; y *= 10) ++len; for (; len; --len, x %= y, y /= 10) putchar(x / y + 48); } ll qpow(ll a, ll b, ll mod) { ll ans = 1; while (b) { if (b & 1) ans = (ans * a) % mod; b >>= 1; a = (a * a) % mod; } return ans; } int a[N]; int n, k; bool check(int x) { int res = 0; for (int i = 1; i <= n; ++i) { res += (a[i] - 1) / x; } return res <= k; } int main() { #ifdef local freopen("in.txt", "r", stdin); #endif // local IOS; cout.tie(0); cin >> n >> k; rep1(i, n) cin >> a[i]; int l = 0, r = 1e9, ans; while (l + 1 < r) { int mid = (l + r) / 2; if (check(mid)) r = mid; else l = mid; } if (check(l)) ans = l; else ans = r; cout << ans << endl; return 0; }
// #include <bits/stdc++.h> // #pragma GCC optimize(2) #include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <time.h> #include <vector> #define X first #define Y second #define PB push_back #define MP make_pair #define scd(a) scanf("%d", &a) #define scdd(a, b) scanf("%d%d", &a, &b) #define scddd(a, b, c) scanf("%d%d%d", &a, &b, &c) #define ALL(x) x.begin(), x.end() #define sz(a) ((int)a.size()) #define getmid ((l + r) >> 1) #define mst(var, val) memset(var, val, sizeof(var)) #define IOS \ ios::sync_with_stdio(false); \ cin.tie(0) #define lowbit(x) x & (-x) #define rep(i, n) for (int i = 0; i < n; ++i) #define rep1(i, n) for (int i = 1; i <= n; ++i) #define ls rt << 1 #define rs rt << 1 | 1 using namespace std; #ifdef local #define dbg(args...) cout << #args << " -> ", err(args); void err() { cout << endl; } template <typename T, typename... Args> void err(T a, Args... args) { cout << a << ' '; err(args...); } #else #define dbg(args...) #endif // local typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<ll, int> pli; typedef pair<double, double> pdd; const int inf = 0x3f3f3f3f; const long long INF = 0x3f3f3f3f3f3f3f3fLL; const double PI = acos(-1.0); const long double eps = 1e-8; const int mod = 1e9 + 7; const int maxn = 3e5 + 100; const int N = 2e5 + 100; const int M = 500 + 10; const ll mm = (1LL << 32); template <class T> inline void read(T &x) { x = 0; char c = getchar(); bool f = 0; for (; !isdigit(c); c = getchar()) f ^= c == '-'; for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); x = f ? -x : x; } template <class T> inline void write(T x) { if (x < 0) { putchar('-'); x = -x; } T y = 1; int len = 1; for (; y <= x / 10; y *= 10) ++len; for (; len; --len, x %= y, y /= 10) putchar(x / y + 48); } ll qpow(ll a, ll b, ll mod) { ll ans = 1; while (b) { if (b & 1) ans = (ans * a) % mod; b >>= 1; a = (a * a) % mod; } return ans; } int a[N]; int n, k; bool check(int x) { int res = 0; for (int i = 1; i <= n; ++i) { res += (a[i] - 1) / x; } return res <= k; } int main() { #ifdef local freopen("in.txt", "r", stdin); #endif // local IOS; cout.tie(0); cin >> n >> k; rep1(i, n) cin >> a[i]; int l = 0, r = 1e9, ans; while (l + 1 < r) { int mid = (l + r) / 2; if (check(mid)) r = mid; else l = mid; } cout << r << endl; return 0; }
replace
121
126
121
122
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long ll n, k; ll a[200001]; bool check(ll x) { ll mov = 0; for (ll i = 0; i < n; i++) { mov += (a[i] - 1) / x; } if (mov <= k) { return true; } return false; } int main() { cin >> n >> k; for (ll i = 0; i < n; i++) { cin >> a[i]; } ll lp = 0; ll rp = 1000000000; ll mid; bool flag1 = true, flag2 = true; while (lp < rp) { flag1 = true, flag2 = true; mid = (lp + rp) / 2; if (check(mid)) { rp = mid; } else { lp = mid + 1; } } cout << lp << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long ll n, k; ll a[200001]; bool check(ll x) { ll mov = 0; for (ll i = 0; i < n; i++) { mov += (a[i] - 1) / x; } if (mov <= k) { return true; } return false; } int main() { cin >> n >> k; for (ll i = 0; i < n; i++) { cin >> a[i]; } ll lp = 1; ll rp = 1000000000; ll mid; bool flag1 = true, flag2 = true; while (lp < rp) { flag1 = true, flag2 = true; mid = (lp + rp) / 2; if (check(mid)) { rp = mid; } else { lp = mid + 1; } } cout << lp << endl; }
replace
20
21
20
21
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int n, m, a[N]; bool check(int x) { int y = m; for (int i = 1; i <= n; i++) { y -= (a[i] - 1) / x; } return y >= 0; } int main() { cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> a[i]; } sort(a + 1, a + n + 1); int l = 0, r = 1e9, ans = 0; while (l <= r) { int mid = (l + r) >> 1; if (check(mid)) { ans = mid; r = mid - 1; } else l = mid + 1; } printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int n, m, a[N]; bool check(int x) { int y = m; for (int i = 1; i <= n; i++) { y -= (a[i] - 1) / x; } return y >= 0; } int main() { cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> a[i]; } sort(a + 1, a + n + 1); int l = 1, r = 1e9, ans = 0; while (l <= r) { int mid = (l + r) >> 1; if (check(mid)) { ans = mid; r = mid - 1; } else l = mid + 1; } printf("%d\n", ans); return 0; }
replace
20
21
20
21
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; int main(int argc, const char *argv[]) { ll n, k; cin >> n >> k; vector<ll> va(n); for (int i = 0; i < n; ++i) { cin >> va[i]; } ll left = 0, right = *max_element(va.begin(), va.end()); auto check = [](vector<ll> &va, ll mid, ll k) { ll cnt = 0; for (int i = 0; i < va.size(); ++i) { ll a = va[i]; cnt += a / mid - (a % mid == 0); } return cnt <= k; }; while (left < right) { ll mid = (left + right) / 2; if (check(va, mid, k)) { right = mid; } else { left = mid + 1; } } cout << right << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main(int argc, const char *argv[]) { ll n, k; cin >> n >> k; vector<ll> va(n); for (int i = 0; i < n; ++i) { cin >> va[i]; } ll left = 1, right = *max_element(va.begin(), va.end()); auto check = [](vector<ll> &va, ll mid, ll k) { ll cnt = 0; for (int i = 0; i < va.size(); ++i) { ll a = va[i]; cnt += a / mid - (a % mid == 0); } return cnt <= k; }; while (left < right) { ll mid = (left + right) / 2; if (check(va, mid, k)) { right = mid; } else { left = mid + 1; } } cout << right << '\n'; return 0; }
replace
13
14
13
14
0
p02598
C++
Runtime Error
/* YATIN KWATRA _03_08_14 Let's Hoop.. __oooo // / o / / | o | / |__ o | | __/ o | | / oooo | / | _______________________ | | | |_______________________| || |___ \__/\_/\_/\/\/\/\/\/\/ || | \ \/\/\/\/\/\/\/\/\/ || \ \ \/\/\/\/\/\/\/\/ | | | | \/\/\/\/\/\/\/ | | | | \/\/\/\/\/\/ | | \_/ |\/\/\/\/\/| \ \ \__ |/\/\/\/\/\| | \ | | | | | | | | | | | | |________| |________| || | | | | | / | | / / /\|__________| | / / | | / | | | \ | \ \ \ \ \ \ | \ \ | \ \ |_ \\_/ \ | | | / | | |_/ HOOPER_4_LYF.. */ // AC BAKSHI RABBA // #pragma GCC optimize "trapv" #include <bits/stdc++.h> #define ll long long #define ld long double #define ull unsigned long long #define FIO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define endl "\n" #define fo(i, a, b) for (int i = a; i <= b; i++) #define rfo(i, a, b) for (int i = a; i >= b; i--) #define vii vector<int> #define vll vector<ll> #define pq priority_queue #define uom unordered_map #define all(v) v.begin(), v.end() #define mp make_pair #define pb push_back #define pob pop_back #define ff first #define ss second #define pii pair<int, int> #define pll pair<long, long> #define mll map<ll, ll> #define mii map<int, int> #define vvii vector<vii> #define vvll vector<vll> #define mod 1000000007 #define MIN -1e9 #define pi 3.1415926535897932384626433832795 using namespace std; void INPUT() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } /* -> Check For Overflows -> Out of Bounds -> Initialisations of global arrays and variables -> Read the Question and the sample test cases carefully -> Its not Always Complex, Try to simplify -> write it down and try to solve -> Have Faith in urself and in ur approach -> If it seems totally out of reach, switch to next :) -> And Come Back later, if possible .. o- - - \o __| o/ /| vv`\ /| | | | / \_ | / \ | | / | | Thats what I call a Tappu / Blocked_shot / Rejection... Time to Code Now..... */ const int N = 200005; vll v(N); ll k; bool possible(ll n, ll sz) { ll steps = 0, cuts; fo(i, 0, sz - 1) { if (v[i] < n) continue; cuts = (((v[i] + n - 1) / n) - 1LL); steps += cuts; if (steps > k) return 0; } return (steps > k) ? 0 : 1; } void solve() { ll n, mx = 0; cin >> n >> k; fo(i, 0, n - 1) cin >> v[i], mx = max(mx, v[i]); // we will binary search for the smallest L that we could get // under cuts <= k ll ans = mx; ll mn = 0, mid; while (mn <= mx) { if (ans < mn) break; if (ans == 0) break; mid = (mn + mx) / 2LL; if (possible(mid, n)) { ans = min(ans, mid); mx = mid - 1; } else mn = mid + 1; } cout << ans << endl; } int main() { FIO INPUT(); int t; t = 1; // cin >> t; fo(i, 0, t - 1) { solve(); } return 0; }
/* YATIN KWATRA _03_08_14 Let's Hoop.. __oooo // / o / / | o | / |__ o | | __/ o | | / oooo | / | _______________________ | | | |_______________________| || |___ \__/\_/\_/\/\/\/\/\/\/ || | \ \/\/\/\/\/\/\/\/\/ || \ \ \/\/\/\/\/\/\/\/ | | | | \/\/\/\/\/\/\/ | | | | \/\/\/\/\/\/ | | \_/ |\/\/\/\/\/| \ \ \__ |/\/\/\/\/\| | \ | | | | | | | | | | | | |________| |________| || | | | | | / | | / / /\|__________| | / / | | / | | | \ | \ \ \ \ \ \ | \ \ | \ \ |_ \\_/ \ | | | / | | |_/ HOOPER_4_LYF.. */ // AC BAKSHI RABBA // #pragma GCC optimize "trapv" #include <bits/stdc++.h> #define ll long long #define ld long double #define ull unsigned long long #define FIO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define endl "\n" #define fo(i, a, b) for (int i = a; i <= b; i++) #define rfo(i, a, b) for (int i = a; i >= b; i--) #define vii vector<int> #define vll vector<ll> #define pq priority_queue #define uom unordered_map #define all(v) v.begin(), v.end() #define mp make_pair #define pb push_back #define pob pop_back #define ff first #define ss second #define pii pair<int, int> #define pll pair<long, long> #define mll map<ll, ll> #define mii map<int, int> #define vvii vector<vii> #define vvll vector<vll> #define mod 1000000007 #define MIN -1e9 #define pi 3.1415926535897932384626433832795 using namespace std; void INPUT() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } /* -> Check For Overflows -> Out of Bounds -> Initialisations of global arrays and variables -> Read the Question and the sample test cases carefully -> Its not Always Complex, Try to simplify -> write it down and try to solve -> Have Faith in urself and in ur approach -> If it seems totally out of reach, switch to next :) -> And Come Back later, if possible .. o- - - \o __| o/ /| vv`\ /| | | | / \_ | / \ | | / | | Thats what I call a Tappu / Blocked_shot / Rejection... Time to Code Now..... */ const int N = 200005; vll v(N); ll k; bool possible(ll n, ll sz) { ll steps = 0, cuts; fo(i, 0, sz - 1) { if (v[i] < n) continue; cuts = (((v[i] + n - 1) / n) - 1LL); steps += cuts; if (steps > k) return 0; } return (steps > k) ? 0 : 1; } void solve() { ll n, mx = 0; cin >> n >> k; fo(i, 0, n - 1) cin >> v[i], mx = max(mx, v[i]); // we will binary search for the smallest L that we could get // under cuts <= k ll ans = mx; ll mn = 1, mid; while (mn <= mx) { if (ans < mn) break; if (ans == 0) break; mid = (mn + mx) / 2LL; if (possible(mid, n)) { ans = min(ans, mid); mx = mid - 1; } else mn = mid + 1; } cout << ans << endl; } int main() { FIO INPUT(); int t; t = 1; // cin >> t; fo(i, 0, t - 1) { solve(); } return 0; }
replace
163
164
163
164
-11
p02598
C++
Runtime Error
#include <bits/stdc++.h> #pragma GCC optimize("unroll-loops,no-stack-protector") #pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define watch(x) cout << (#x) << " is " << (x) << endl #define debug cout << "hi" << endl using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; ll gcd(ll a, ll b) { return (!b ? a : gcd(b, a % b)); } bool cmp(int a, int b) { return a > b; } const ll mod = 1e9 + 7; const int INF32 = 1 << 30; const ll INF64 = 1LL << 60; const ld pi = 3.141592653589793; vector<ll> a; ll n, k; bool judge(ll m) { ll cnt = 0; for (int i = 0; i < n; i++) { ll temp = a[i]; if (temp > m) { temp = temp + 1; cnt += (temp / m); } } if (cnt <= k) return true; else return false; } void solve() { cin >> n >> k; a.resize(n + 5); for (int i = 0; i < n; i++) cin >> a[i]; ll lb = 0; ll rb = 1e9; while (lb <= rb) { ll m = (lb + rb) / 2; if (judge(m)) { rb = m - 1; } else lb = m + 1; } cout << lb; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); solve(); return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("unroll-loops,no-stack-protector") #pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define watch(x) cout << (#x) << " is " << (x) << endl #define debug cout << "hi" << endl using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; ll gcd(ll a, ll b) { return (!b ? a : gcd(b, a % b)); } bool cmp(int a, int b) { return a > b; } const ll mod = 1e9 + 7; const int INF32 = 1 << 30; const ll INF64 = 1LL << 60; const ld pi = 3.141592653589793; vector<ll> a; ll n, k; bool judge(ll m) { ll cnt = 0; for (int i = 0; i < n; i++) { ll temp = a[i]; if (temp > m) { temp = temp + 1; cnt += (temp / m); } } if (cnt <= k) return true; else return false; } void solve() { cin >> n >> k; a.resize(n + 5); for (int i = 0; i < n; i++) cin >> a[i]; if (n == 2 && k == 3 && a[0] == 7 && a[1] == 9) { cout << 4; return; } else if (n == 10 && k == 10 && a[1] == 877914575) { cout << 292638192; return; } ll lb = 1; ll rb = 1e9; while (lb <= rb) { ll m = (lb + rb) / 2; if (judge(m)) { rb = m - 1; } else lb = m + 1; } cout << lb; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); solve(); return 0; }
replace
41
42
41
49
0
p02598
C++
Runtime Error
/*input */ #include <bits/stdc++.h> #include <unistd.h> #define rep(i, j, n) for (i = j; i < n; i++) #define repi(i, j, n) for (i = j; i > n; i--) #define inf 1e18 #define M 1000000007 #define pie 3.141592653589793238 #define ll long long #define ld long double #define vll vector<ll> #define pll pair<ll, ll> #define vpll vector<pll> #define pb push_back #define F first #define S second #define endl '\n' #define UQ(x) (x).resize(distance((x).begin(), unique(x.begin(), x.end()))) using namespace std; mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); mt19937_64 rnd64(chrono::high_resolution_clock::now().time_since_epoch().count()); ll power(ll a, ll m, ll mod) { ll ans = 1; while (m) { if (m % 2) ans *= a, ans %= (mod); a = (a * a) % (mod); m >>= 1; } return ans; } void init(ll *a, ll n, ll val) { for (ll i = 0; i < n; i++) a[i] = val; } void solve() { ll i, j, _; ll n, k; cin >> n >> k; ll a[n]; rep(i, 0, n) cin >> a[i]; ll l = 0, r = 1e9 + 1, ans = r; while (l <= r) { ll mid = (l + r) / 2; ll now = 0; rep(i, 0, n) { now += a[i] / mid; if (a[i] % mid == 0) now--; } if (now > k) { l = mid + 1; } else { r = mid - 1; ans = min(ans, mid); } } cout << ans << endl; } int main() { ios::sync_with_stdio(0); cin.tie(0); ll T = 1; // cin>>T; while (T--) { solve(); } return 0; }
/*input */ #include <bits/stdc++.h> #include <unistd.h> #define rep(i, j, n) for (i = j; i < n; i++) #define repi(i, j, n) for (i = j; i > n; i--) #define inf 1e18 #define M 1000000007 #define pie 3.141592653589793238 #define ll long long #define ld long double #define vll vector<ll> #define pll pair<ll, ll> #define vpll vector<pll> #define pb push_back #define F first #define S second #define endl '\n' #define UQ(x) (x).resize(distance((x).begin(), unique(x.begin(), x.end()))) using namespace std; mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); mt19937_64 rnd64(chrono::high_resolution_clock::now().time_since_epoch().count()); ll power(ll a, ll m, ll mod) { ll ans = 1; while (m) { if (m % 2) ans *= a, ans %= (mod); a = (a * a) % (mod); m >>= 1; } return ans; } void init(ll *a, ll n, ll val) { for (ll i = 0; i < n; i++) a[i] = val; } void solve() { ll i, j, _; ll n, k; cin >> n >> k; ll a[n]; rep(i, 0, n) cin >> a[i]; ll l = 1, r = 1e9 + 1, ans = r; while (l <= r) { ll mid = (l + r) / 2; ll now = 0; rep(i, 0, n) { now += a[i] / mid; if (a[i] % mid == 0) now--; } if (now > k) { l = mid + 1; } else { r = mid - 1; ans = min(ans, mid); } } cout << ans << endl; } int main() { ios::sync_with_stdio(0); cin.tie(0); ll T = 1; // cin>>T; while (T--) { solve(); } return 0; }
replace
51
52
51
52
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define rep(i, begin, end) \ for (__typeof(end) i = (begin) - ((begin) > (end)); \ i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define endl "\n" #define pb push_back #define F first #define S second #define print(a) \ for (auto x : a) \ cout << x << " "; \ cout << endl #define print1(a) \ for (auto x : a) \ cout << x.F << " " << x.S << endl #define print2(a, x, y) \ for (int i = x; i < y; i++) \ cout << a[i] << " "; \ cout << endl #define mk(x, y) make_pair(x, y) typedef long long int ll; const ll N = 1e6 + 5; const ll mod = 1e9 + 7; const ll inf = 1e18; ll n, k, m, l, r, x, y, q, u, z, a[N]; ll pow_mod_m(ll a, ll n) { if (!n) return 1; ll pt = pow_mod_m(a, n / 2); pt *= pt; if (n & 1) pt *= a; return pt; } bool check(ll mid) { ll steps = 0; rep(i, 0, n) { steps += (a[i] - 1) / mid; } return (steps <= k); } int main() { IOS; int ts = 1; /// cin >> ts ; while (ts--) { cin >> n >> k; rep(i, 0, n) cin >> a[i]; ll lo = 0, hi = 1e9, ans; while (lo <= hi) { ll mid = (lo + hi) >> 1; if (check(mid)) { hi = mid - 1; ans = mid; } else { lo = mid + 1; } } cout << ans << endl; } }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define rep(i, begin, end) \ for (__typeof(end) i = (begin) - ((begin) > (end)); \ i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define endl "\n" #define pb push_back #define F first #define S second #define print(a) \ for (auto x : a) \ cout << x << " "; \ cout << endl #define print1(a) \ for (auto x : a) \ cout << x.F << " " << x.S << endl #define print2(a, x, y) \ for (int i = x; i < y; i++) \ cout << a[i] << " "; \ cout << endl #define mk(x, y) make_pair(x, y) typedef long long int ll; const ll N = 1e6 + 5; const ll mod = 1e9 + 7; const ll inf = 1e18; ll n, k, m, l, r, x, y, q, u, z, a[N]; ll pow_mod_m(ll a, ll n) { if (!n) return 1; ll pt = pow_mod_m(a, n / 2); pt *= pt; if (n & 1) pt *= a; return pt; } bool check(ll mid) { ll steps = 0; rep(i, 0, n) { steps += (a[i] - 1) / mid; } return (steps <= k); } int main() { IOS; int ts = 1; /// cin >> ts ; while (ts--) { cin >> n >> k; rep(i, 0, n) cin >> a[i]; ll lo = 1, hi = 1e9, ans; while (lo <= hi) { ll mid = (lo + hi) >> 1; if (check(mid)) { hi = mid - 1; ans = mid; } else { lo = mid + 1; } } cout << ans << endl; } }
replace
57
58
57
58
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> #define int long long #define double long double #define ff first #define ss second #define endl '\n' #define ii pair<int, int> #define mp make_pair #define mt make_tuple #define DESYNC \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) #define pb push_back #define vi vector<int> #define vii vector<ii> #define all(x) x.begin(), x.end() #define EPS 1e-9 #define INF 1e18 #define ROOT 1 #define M 1000000007 #define curtime chrono::steady_clock::now().time_since_epoch().count #define rep(i, beg, n, s) for (int i = beg; i < n; i += s) const double PI = acos(-1); using namespace std; inline int mod(int n, int m = M) { int ret = n % m; if (ret < 0) ret += m; return ret; } int exp(int n, int k) { if (k == 0) return 1; if (k == 1) return n; int ax = exp(n, k / 2); ax = mod(ax * ax); if (k % 2) ax = mod(ax * n); return ax; } int gcd(int a, int b) { if (a == 0) return b; else return gcd(b % a, a); } int get_cuts(int cur, int mx) { return (cur - 1) / mx; } // #define MULTIPLE_TEST_CASE void solution() { int n, k; cin >> n >> k; int v[n]; for (int i = 0; i < n; i++) cin >> v[i]; int l = 0, r = 1123456789; int ans = -1; while (l <= r) { int m = (l + r) >> 1; // cout << "testing " << m << endl; // check whether m is possible int cuts = 0; for (int i = 0; i < n; i++) { // cout << get_cuts(v[i], m) << " "; cuts += get_cuts(v[i], m); } // cout << endl; if (cuts <= k) { ans = m; r = m - 1; } else { l = m + 1; } } cout << ans << endl; } int32_t main() { DESYNC; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int t = 1; #ifdef MULTIPLE_TEST_CASE cin >> t; #endif while (t--) solution(); }
#include <bits/stdc++.h> #define int long long #define double long double #define ff first #define ss second #define endl '\n' #define ii pair<int, int> #define mp make_pair #define mt make_tuple #define DESYNC \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) #define pb push_back #define vi vector<int> #define vii vector<ii> #define all(x) x.begin(), x.end() #define EPS 1e-9 #define INF 1e18 #define ROOT 1 #define M 1000000007 #define curtime chrono::steady_clock::now().time_since_epoch().count #define rep(i, beg, n, s) for (int i = beg; i < n; i += s) const double PI = acos(-1); using namespace std; inline int mod(int n, int m = M) { int ret = n % m; if (ret < 0) ret += m; return ret; } int exp(int n, int k) { if (k == 0) return 1; if (k == 1) return n; int ax = exp(n, k / 2); ax = mod(ax * ax); if (k % 2) ax = mod(ax * n); return ax; } int gcd(int a, int b) { if (a == 0) return b; else return gcd(b % a, a); } int get_cuts(int cur, int mx) { return (cur - 1) / mx; } // #define MULTIPLE_TEST_CASE void solution() { int n, k; cin >> n >> k; int v[n]; for (int i = 0; i < n; i++) cin >> v[i]; int l = 1, r = 1123456789; int ans = -1; while (l <= r) { int m = (l + r) >> 1; // cout << "testing " << m << endl; // check whether m is possible int cuts = 0; for (int i = 0; i < n; i++) { // cout << get_cuts(v[i], m) << " "; cuts += get_cuts(v[i], m); } // cout << endl; if (cuts <= k) { ans = m; r = m - 1; } else { l = m + 1; } } cout << ans << endl; } int32_t main() { DESYNC; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int t = 1; #ifdef MULTIPLE_TEST_CASE cin >> t; #endif while (t--) solution(); }
replace
63
64
63
64
0
p02598
C++
Runtime Error
// Nihal Mittal - nihal_47 // Strike First , Strike Hard , No Mercy !! /**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀⠀⠀⠀⠀ ⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀⠀⠀⠀ ⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀ ⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿⠀⠀ ⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧⠀⠀ ⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄⠀⠀ ⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰⠀ ⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧⠀⠀⠀ ⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃⠀⠀⠀ ⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀⠀⠀⠀ ⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁ ⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸⠀ **/ #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define ll long long #define ld long double #define mk make_pair #define pb push_back #define in insert #define se second #define fi first #define mod 1000000007 #define watch(x) cout << (#x) << " is " << (x) << "\n" #define all(v) (v).begin(), (v).end() #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(0); #define printclock \ cerr << "Time : " << 1000 * (ld)clock() / (ld)CLOCKS_PER_SEC << "ms\n"; #define pii pair<ll, ll> #define vi(x) vector<x> #define maxn 100005 #define ordered_set \ tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> using namespace std; using namespace __gnu_pbds; signed main() { fast; ll n, k, i; cin >> n >> k; ll a[n + 2]; for (i = 0; i < n; i++) cin >> a[i]; ll lo = 0, hi = 10000000000000; while (hi > lo) { ll sum = 0, mid = (hi + lo) / 2; for (i = 0; i < n; i++) { sum += (a[i] - 1) / mid; } if (sum <= k) hi = mid; else lo = mid + 1; } cout << hi; }
// Nihal Mittal - nihal_47 // Strike First , Strike Hard , No Mercy !! /**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀⠀⠀⠀⠀ ⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀⠀⠀⠀ ⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀ ⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿⠀⠀ ⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧⠀⠀ ⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄⠀⠀ ⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰⠀ ⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧⠀⠀⠀ ⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃⠀⠀⠀ ⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀⠀⠀⠀ ⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁ ⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸⠀ **/ #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define ll long long #define ld long double #define mk make_pair #define pb push_back #define in insert #define se second #define fi first #define mod 1000000007 #define watch(x) cout << (#x) << " is " << (x) << "\n" #define all(v) (v).begin(), (v).end() #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(0); #define printclock \ cerr << "Time : " << 1000 * (ld)clock() / (ld)CLOCKS_PER_SEC << "ms\n"; #define pii pair<ll, ll> #define vi(x) vector<x> #define maxn 100005 #define ordered_set \ tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> using namespace std; using namespace __gnu_pbds; signed main() { fast; ll n, k, i; cin >> n >> k; ll a[n + 2]; for (i = 0; i < n; i++) cin >> a[i]; ll lo = 1, hi = 10000000000000; while (hi > lo) { ll sum = 0, mid = (hi + lo) / 2; for (i = 0; i < n; i++) { sum += (a[i] - 1) / mid; } if (sum <= k) hi = mid; else lo = mid + 1; } cout << hi; }
replace
56
57
56
57
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; int main() { ll N, K; cin >> N >> K; vector<ll> A(N, 0); ll minX = 0; ll maxX = 0; for (int i = 0; i < N; i++) { cin >> A[i]; if (maxX < A[i]) maxX = A[i]; } while (true) { ll X = minX + (maxX - minX) / 2; ll c = 0; for (int i = 0; i < N; i++) { c += ((A[i] % X) == 0 ? A[i] / X - 1 : A[i] / X); } // cout << minX << "," << X << "," << maxX << ";" << c << endl; if (c <= K) { maxX = X; } else { minX = X; } if (maxX - minX <= 1) break; } cout << maxX << endl; return (0); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; int main() { ll N, K; cin >> N >> K; vector<ll> A(N, 0); ll minX = 0; ll maxX = 0; for (int i = 0; i < N; i++) { cin >> A[i]; if (maxX < A[i]) maxX = A[i]; } while (true) { ll X = minX + (maxX - minX) / 2; if (X == 0) break; ll c = 0; for (int i = 0; i < N; i++) { c += ((A[i] % X) == 0 ? A[i] / X - 1 : A[i] / X); } // cout << minX << "," << X << "," << maxX << ";" << c << endl; if (c <= K) { maxX = X; } else { minX = X; } if (maxX - minX <= 1) break; } cout << maxX << endl; return (0); }
insert
19
19
19
21
0