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
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; 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; } #define rep(i, cc, n) for (int i = cc; i < n; ++i) #define lrep(i, cc, n) for (long long i = cc; i < n; ++i) #define sqrep(i, cc, n) for (long long i = cc; i * i <= n; ++i) #define rrep(i, cc, n) for (long i = cc; i > n; --i) #define pii pair<int, int> #define pll pair<long long, long long> using ll = long long; const vector<int> dx = {1, 0, -1, 0}; const vector<int> dy = {0, 1, 0, -1}; const double PI = 3.1415926535; const ll inf = 1001001001; const ll e9 = 1000000000; const ll mod = 1000000007; int main() { int n; ll k; cin >> n >> k; vector<ll> a(n); rep(i, 0, n) cin >> a[i]; sort(a.begin(), a.end()); // 長さを置く ll right = a[n - 1] + 1; ll left = -1; ll p = 0; if (k == 0) { cout << a[n - 1] << endl; return 0; } while (right - left > 1) { ll templength = (right + left) / 2; ll cnt = 0; rep(i, 0, n) { cnt += (a[i] + templength - 1) / templength - 1; if (cnt > k) break; } if (cnt > k) { // 切る回数がkより大きい=templengthが小さすぎ left = templength; } else { // 切る回数がkより小さい=templengthが大きすぎ right = templength; } } cout << right << endl; return 0; // cout << left << " " << right << endl; }
#include <bits/stdc++.h> using namespace std; 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; } #define rep(i, cc, n) for (int i = cc; i < n; ++i) #define lrep(i, cc, n) for (long long i = cc; i < n; ++i) #define sqrep(i, cc, n) for (long long i = cc; i * i <= n; ++i) #define rrep(i, cc, n) for (long i = cc; i > n; --i) #define pii pair<int, int> #define pll pair<long long, long long> using ll = long long; const vector<int> dx = {1, 0, -1, 0}; const vector<int> dy = {0, 1, 0, -1}; const double PI = 3.1415926535; const ll inf = 1001001001; const ll e9 = 1000000000; const ll mod = 1000000007; int main() { int n; ll k; cin >> n >> k; vector<ll> a(n); rep(i, 0, n) cin >> a[i]; sort(a.begin(), a.end()); // 長さを置く ll right = e9 + 1; ll left = 0; ll p = 0; if (k == 0) { cout << a[n - 1] << endl; return 0; } while (right - left > 1) { ll templength = (right + left) / 2; ll cnt = 0; rep(i, 0, n) { cnt += (a[i] + templength - 1) / templength - 1; if (cnt > k) break; } if (cnt > k) { // 切る回数がkより大きい=templengthが小さすぎ left = templength; } else { // 切る回数がkより小さい=templengthが大きすぎ right = templength; } } cout << right << endl; return 0; // cout << left << " " << right << endl; }
replace
42
44
42
44
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define f first #define s second #define Fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define fo(a, b, c) for (int i = a; i < b; i += c) typedef pair<ll, pair<ll, ll>> pi; int pow(int x, int y) { int res = 1; while (y) { if (y & 1) res *= x; y >>= 1; x *= x; } return res; } struct Compare { constexpr bool operator()(pi const &a, pi const &b) const noexcept { return a.first < b.first || (a.first == b.first && a.second.first > b.second.first); } }; void prefix_function(string s, ll arr[]) { long long border = 0; arr[0] = 0; for (long long i = 1; i < s.size(); i++) { while (border > 0 && s[i] != s[border]) border = arr[border - 1]; if (s[i] == s[border]) border++; else border = 0; arr[i] = border; } } ll mod = 998244353; ll add(ll a, ll b) { return (((a % mod) + (b % mod)) % mod); } ll mul(ll a, ll b) { return (((a % mod) * (b % mod)) % mod); } // send mod-2 for a^-1 if mod is a prime number ll binpow(ll a, ll b) { ll res = 1; while (b) { if (b & 1) res = mul(res, a); a = mul(a, a); b >>= 1; } return res; } ll dsu_arr[100000]; ll dsu_sz[100000]; void dsu(ll n) { for (ll i = 0; i <= n; i++) { dsu_arr[i] = i; dsu_sz[i] = 1; } } ll find(ll x) { ll root = x; while (root != dsu_arr[root]) { root = dsu_arr[root]; } while (x != dsu_arr[x]) { dsu_arr[x] = root; x = dsu_arr[x]; } return root; } ll merge(ll x, ll y) { ll root1 = find(x); ll root2 = find(y); if (root1 == root2) return 0ll; if (dsu_sz[x] > dsu_sz[y]) { dsu_arr[root2] = root1; dsu_sz[x] += dsu_sz[y]; } else { dsu_sz[y] += dsu_sz[x]; dsu_arr[root1] = root2; } return 1ll; } vector<ll> sura; ll k; ll n; bool solve(ll x) { ll d = k; for (ll i = 0; i < n; i++) { if (sura[i] % x == 0) { d -= ((sura[i] / x) - 1); } else d -= (sura[i] / x); } if (d >= 0) return true; else return false; } int main() { cin >> n >> k; for (ll i = 0; i < n; i++) { ll d; cin >> d; sura.push_back(d); } ll l = 0; ll r = 1000000000; ll ans = 0; while (r >= l) { ll mid = (l + r) / 2; if (solve(mid)) { ans = mid; r = mid - 1; } else l = mid + 1; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define f first #define s second #define Fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define fo(a, b, c) for (int i = a; i < b; i += c) typedef pair<ll, pair<ll, ll>> pi; int pow(int x, int y) { int res = 1; while (y) { if (y & 1) res *= x; y >>= 1; x *= x; } return res; } struct Compare { constexpr bool operator()(pi const &a, pi const &b) const noexcept { return a.first < b.first || (a.first == b.first && a.second.first > b.second.first); } }; void prefix_function(string s, ll arr[]) { long long border = 0; arr[0] = 0; for (long long i = 1; i < s.size(); i++) { while (border > 0 && s[i] != s[border]) border = arr[border - 1]; if (s[i] == s[border]) border++; else border = 0; arr[i] = border; } } ll mod = 998244353; ll add(ll a, ll b) { return (((a % mod) + (b % mod)) % mod); } ll mul(ll a, ll b) { return (((a % mod) * (b % mod)) % mod); } // send mod-2 for a^-1 if mod is a prime number ll binpow(ll a, ll b) { ll res = 1; while (b) { if (b & 1) res = mul(res, a); a = mul(a, a); b >>= 1; } return res; } ll dsu_arr[100000]; ll dsu_sz[100000]; void dsu(ll n) { for (ll i = 0; i <= n; i++) { dsu_arr[i] = i; dsu_sz[i] = 1; } } ll find(ll x) { ll root = x; while (root != dsu_arr[root]) { root = dsu_arr[root]; } while (x != dsu_arr[x]) { dsu_arr[x] = root; x = dsu_arr[x]; } return root; } ll merge(ll x, ll y) { ll root1 = find(x); ll root2 = find(y); if (root1 == root2) return 0ll; if (dsu_sz[x] > dsu_sz[y]) { dsu_arr[root2] = root1; dsu_sz[x] += dsu_sz[y]; } else { dsu_sz[y] += dsu_sz[x]; dsu_arr[root1] = root2; } return 1ll; } vector<ll> sura; ll k; ll n; bool solve(ll x) { ll d = k; for (ll i = 0; i < n; i++) { if (sura[i] % x == 0) { d -= ((sura[i] / x) - 1); } else d -= (sura[i] / x); } if (d >= 0) return true; else return false; } int main() { cin >> n >> k; for (ll i = 0; i < n; i++) { ll d; cin >> d; sura.push_back(d); } ll l = 1; ll r = 1000000000; ll ans = 0; while (r >= l) { ll mid = (l + r) / 2; if (solve(mid)) { ans = mid; r = mid - 1; } else l = mid + 1; } cout << ans << endl; }
replace
115
116
115
116
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define endl '\n' typedef pair<int, int> P; typedef long long ll; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; ll r = 1e9; ll l = 0; vector<int> a(n); rep(i, n) { cin >> a[i]; } rep(tmp, 200) { ll mid = (l + r) / 2; int cnt = 0; for (auto j : a) { cnt += (j + mid - 1) / mid - 1; } if (cnt <= k) { r = mid; } else { l = mid; } } cout << r << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define endl '\n' typedef pair<int, int> P; typedef long long ll; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; ll r = 1e9; ll l = 0; vector<int> a(n); rep(i, n) { cin >> a[i]; } rep(tmp, 200) { ll mid = (l + r) / 2; if (mid == 0) { cout << 1 << endl; return 0; } int cnt = 0; for (auto j : a) { cnt += (j + mid - 1) / mid - 1; } if (cnt <= k) { r = mid; } else { l = mid; } } cout << r << endl; }
insert
19
19
19
23
0
p02598
C++
Time Limit Exceeded
#include <bits/stdc++.h> #include <iostream> using namespace std; #define ll long long #define ld long double #define mp make_pair #define pb push_back #define fo(i, n) for (ll i = 0; i < n; i++) #define fo1(i, n) for (ll i = 1; i <= n; i++) #define loop(i, a, b) for (ll i = a; i <= b; i++) #define loopr(i, a, b) for (ll i = b; i >= a; i--) #define all(x) x.begin(), x.end() #define sz(x) (ll)(x).size() #define vll vector<ll> #define vvl vector<vll> #define vpll vector<pll> #define pll pair<ll, ll> #define F first #define S second #define MOD 1000000007 ll max(ll a, ll b) { if (a > b) return a; else return b; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { return a * b / gcd(a, b); } ll fexp(ll a, ll b) { ll ans = 1; while (b) { if (b & 1) ans = ans * a % MOD; b /= 2; a = a * a % MOD; } return ans; } ll inverse(ll a, ll p) { return fexp(a, p - 2); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll T = 1; // cin >> T; ll t = 0; while (t++ < T) { ll n, k; cin >> n >> k; vll a(n); fo(i, n) cin >> a[i]; ll lo = 1, hi = *max_element(all(a)), ans; ll m; while (lo <= hi) { m = (lo + hi) / 2; ll req = 0; fo(i, n) { if (a[i] % m == 0) req += a[i] / m - 1; else req += a[i] / m; } if (req <= k) { hi = m; } else lo = m + 1; } cout << lo << endl; } return 0; }
#include <bits/stdc++.h> #include <iostream> using namespace std; #define ll long long #define ld long double #define mp make_pair #define pb push_back #define fo(i, n) for (ll i = 0; i < n; i++) #define fo1(i, n) for (ll i = 1; i <= n; i++) #define loop(i, a, b) for (ll i = a; i <= b; i++) #define loopr(i, a, b) for (ll i = b; i >= a; i--) #define all(x) x.begin(), x.end() #define sz(x) (ll)(x).size() #define vll vector<ll> #define vvl vector<vll> #define vpll vector<pll> #define pll pair<ll, ll> #define F first #define S second #define MOD 1000000007 ll max(ll a, ll b) { if (a > b) return a; else return b; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { return a * b / gcd(a, b); } ll fexp(ll a, ll b) { ll ans = 1; while (b) { if (b & 1) ans = ans * a % MOD; b /= 2; a = a * a % MOD; } return ans; } ll inverse(ll a, ll p) { return fexp(a, p - 2); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll T = 1; // cin >> T; ll t = 0; while (t++ < T) { ll n, k; cin >> n >> k; vll a(n); fo(i, n) cin >> a[i]; ll lo = 1, hi = *max_element(all(a)), ans; ll m; while (lo < hi) { m = (lo + hi) / 2; ll req = 0; fo(i, n) { if (a[i] % m == 0) req += a[i] / m - 1; else req += a[i] / m; } if (req <= k) { hi = m; } else lo = m + 1; } cout << lo << endl; } return 0; }
replace
57
58
57
58
TLE
p02598
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define ll long long #define pll pair<ll, ll> #define pii pair<int, int> #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 mem0(x) memset(x, 0, sizeof(x)) #define meminf(x) memset(x, 0x3f, sizeof(x)) #define VI vector<int> #define VL vector<ll> using namespace std; double a[200005]; int n, k; int check(double x) { ll cnt = 0; rep(i, 1, n) { cnt += (ll)(a[i] / x); if (fabs(a[i] - (ll)(a[i] / x) * x) <= 0.1) { --cnt; } } return cnt > k; } int main() { ios::sync_with_stdio(0); cin >> n >> k; double l = 1, r = 0; rep(i, 1, n) { cin >> a[i]; r = max(r, a[i]); } while (l <= r) { double mid = (l + r) / 2; if (check(mid)) { l = mid + 0.01; } else { r = mid; } } cout << (ll)ceil(l); }
#include <bits/stdc++.h> #define ll long long #define pll pair<ll, ll> #define pii pair<int, int> #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 mem0(x) memset(x, 0, sizeof(x)) #define meminf(x) memset(x, 0x3f, sizeof(x)) #define VI vector<int> #define VL vector<ll> using namespace std; double a[200005]; int n, k; int check(double x) { ll cnt = 0; rep(i, 1, n) { cnt += (ll)(a[i] / x); if (fabs(a[i] - (ll)(a[i] / x) * x) <= 0.1) { --cnt; } } return cnt > k; } int main() { ios::sync_with_stdio(0); cin >> n >> k; double l = 1, r = 0; rep(i, 1, n) { cin >> a[i]; r = max(r, a[i]); } int cnt = 0; while (cnt++ < 100) { double mid = (l + r) / 2; if (check(mid)) { l = mid + 0.01; } else { r = mid; } } cout << (ll)ceil(l); }
replace
34
35
34
36
TLE
p02598
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long int #define uu first #define vv second #define pii pair<int, int> #define pdp pair<double, pii> #define pll pair<ll, ll> #define fastio \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) using namespace std; const int INF = 1e9; const ll MOD = 1e9 + 7; const int N = 1e6 + 6; int main() { fastio; int n, k; cin >> n >> k; vector<int> vec(n); for (int i = 0; i < n; i++) cin >> vec[i]; int lo = 0, hi = INF, ret = -1; while (lo <= hi) { int mid = (lo + hi) / 2; int cnt = 0; for (auto x : vec) { cnt += (x - 1) / mid + 1 - 1; } if (cnt > k) { lo = mid + 1; } else { ret = mid; hi = mid - 1; } } cout << ret << '\n'; return 0; }
#include <bits/stdc++.h> #define ll long long int #define uu first #define vv second #define pii pair<int, int> #define pdp pair<double, pii> #define pll pair<ll, ll> #define fastio \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) using namespace std; const int INF = 1e9; const ll MOD = 1e9 + 7; const int N = 1e6 + 6; int main() { fastio; int n, k; cin >> n >> k; vector<int> vec(n); for (int i = 0; i < n; i++) cin >> vec[i]; int lo = 1, hi = INF, ret = -1; while (lo <= hi) { int mid = (lo + hi) / 2; int cnt = 0; for (auto x : vec) { cnt += (x - 1) / mid + 1 - 1; } if (cnt > k) { lo = mid + 1; } else { ret = mid; hi = mid - 1; } } cout << ret << '\n'; return 0; }
replace
25
26
25
26
0
p02598
C++
Runtime Error
#include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <unordered_map> #include <unordered_set> #include <vector> #define INF 0x3f3f3f3f #define MOD 1000000007 using namespace std; typedef long long ll; mt19937 mrand(random_device{}()); int rnd(int x) { return mrand() % x; } template <typename T> void read(T &x) { x = 0; char c = getchar(); T sig = 1; for (; !isdigit(c); c = getchar()) if (c == '-') sig = -1; for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0'; x *= sig; } class Solution { public: void solve() { int n, k; read(n), read(k); vector<int> a(n); for (int i = 0; i < n; ++i) read(a[i]); ll l = 0, r = *max_element(a.begin(), a.end()); while (l <= r) { ll mid = l + (r - l) / 2; ll req = 0; for (int i : a) req += (i - 1) / mid; if (req > k) l = mid + 1; else r = mid - 1; } printf("%lld", l); } }; int main() { ios::sync_with_stdio(false); cin.tie(0); Solution solution = Solution(); solution.solve(); }
#include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <unordered_map> #include <unordered_set> #include <vector> #define INF 0x3f3f3f3f #define MOD 1000000007 using namespace std; typedef long long ll; mt19937 mrand(random_device{}()); int rnd(int x) { return mrand() % x; } template <typename T> void read(T &x) { x = 0; char c = getchar(); T sig = 1; for (; !isdigit(c); c = getchar()) if (c == '-') sig = -1; for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0'; x *= sig; } class Solution { public: void solve() { int n, k; read(n), read(k); vector<int> a(n); for (int i = 0; i < n; ++i) read(a[i]); ll l = 1, r = *max_element(a.begin(), a.end()); while (l <= r) { ll mid = l + (r - l) / 2; ll req = 0; for (int i : a) req += (i - 1) / mid; if (req > k) l = mid + 1; else r = mid - 1; } printf("%lld", l); } }; int main() { ios::sync_with_stdio(false); cin.tie(0); Solution solution = Solution(); solution.solve(); }
replace
51
52
51
52
0
p02598
C++
Runtime Error
/** * @author: Mackenzie **/ #include <bits/stdc++.h> using namespace std; #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) (int)(x).size() #define F first #define S second #define forn(i, n) for (int i = 0; i < (int)n; i++) #define pb push_back #define fastIO ios::sync_with_stdio(0), cin.tie(0) #define endl '\n' typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAX = 2e5 + 5; int A[MAX]; int n, k; int check(int x) { int cnt = 0; forn(i, n) { if (A[i] > x) cnt += A[i] / x; } return cnt; } int main() { #ifdef LOCAL freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); #else fastIO; #endif cin >> n >> k; forn(i, n) cin >> A[i]; sort(A, A + n); int lo = 0, hi = 1e9; forn(it, 70) { int m = (lo + hi) / 2; // cout << m << endl; if (check(m) <= k) hi = m; else lo = m; } cout << hi << endl; return 0; }
/** * @author: Mackenzie **/ #include <bits/stdc++.h> using namespace std; #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) (int)(x).size() #define F first #define S second #define forn(i, n) for (int i = 0; i < (int)n; i++) #define pb push_back #define fastIO ios::sync_with_stdio(0), cin.tie(0) #define endl '\n' typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAX = 2e5 + 5; int A[MAX]; int n, k; int check(int x) { int cnt = 0; forn(i, n) { if (A[i] > x) cnt += A[i] / x; } return cnt; } int main() { #ifdef LOCAL freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); #else fastIO; #endif cin >> n >> k; forn(i, n) cin >> A[i]; sort(A, A + n); int lo = 1, hi = 1e9; forn(it, 70) { int m = (lo + hi) / 2; // cout << m << endl; if (check(m) <= k) hi = m; else lo = m; } cout << hi << endl; return 0; }
replace
43
44
43
44
0
p02598
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #define rep(i, x, n) for (int i = x; i <= n; i++) #define per(i, n, x) for (int i = n; i >= x; i--) #define sz(a) int(a.size()) #define rson mid + 1, r, p << 1 | 1 #define pii pair<int, int> #define lson l, mid, p << 1 #define ll long long #define pb push_back #define mp make_pair #define se second #define fi first using namespace std; const double eps = 1e-8; const int mod = 1e9 + 7; const int N = 2e5 + 10; const int inf = 1e9; int n, k; int a[N]; bool ck(int x) { int cnt = 0; rep(i, 1, n) { int y = a[i]; cnt += (y - 1) / x; if (cnt > k) return false; } return cnt <= k; } int main() { ios::sync_with_stdio(false); // freopen("in","r",stdin); cin >> n >> k; rep(i, 1, n) { cin >> a[i]; } int l = 0, r = 1e9; while (l <= r) { int mid = (l + r) / 2; if (ck(mid)) r = mid - 1; else l = mid + 1; } printf("%d\n", l); return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #define rep(i, x, n) for (int i = x; i <= n; i++) #define per(i, n, x) for (int i = n; i >= x; i--) #define sz(a) int(a.size()) #define rson mid + 1, r, p << 1 | 1 #define pii pair<int, int> #define lson l, mid, p << 1 #define ll long long #define pb push_back #define mp make_pair #define se second #define fi first using namespace std; const double eps = 1e-8; const int mod = 1e9 + 7; const int N = 2e5 + 10; const int inf = 1e9; int n, k; int a[N]; bool ck(int x) { int cnt = 0; rep(i, 1, n) { int y = a[i]; cnt += (y - 1) / x; if (cnt > k) return false; } return cnt <= k; } int main() { ios::sync_with_stdio(false); // freopen("in","r",stdin); cin >> n >> k; rep(i, 1, n) { cin >> a[i]; } int l = 1, r = 1e9; while (l <= r) { int mid = (l + r) / 2; if (ck(mid)) r = mid - 1; else l = mid + 1; } printf("%d\n", l); return 0; }
replace
47
48
47
48
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define fastIO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define int long long int #define fi first #define se second #define pub push_back #define pi pair<int, int> #define all(v) (v).begin(), (v).end() #define rep(i, l, r) for (int i = (int)(l); i < (int)(r); i++) #define repd(i, l, r) for (int i = (int)(l); i >= (int)(r); i--) #define clrg(i, l, r) \ for (int i = (int)(l); i < (int)(r); i++) \ vis[i] = 0, v[i].clear(); int power(int x, unsigned int y) { int res = 1; while (y > 0) { if (y & 1) { res = res * x; } y = y >> 1; x = x * x; } return res; } int powermod(int x, unsigned int y, int p) { int res = 1; x = x % p; while (y > 0) { if (y & 1) { res = (res * x) % p; } y = y >> 1; x = (x * x) % p; } return res; } #define print2d(mat, n, m) \ { \ for (int i = 0; i < (int)(n); i++) { \ for (int j = 0; j < (m); j++) { \ cout << mat[i][j] << " "; \ } \ cout << endl; \ } \ } #define clr(a, x) memset(a, x, sizeof(a)) #define rr(v) for (auto &val : v) #define print(v) \ for (const auto itr : v) { \ cout << itr << ' '; \ } \ cout << "\n"; #define ln length() #define sz size() #define mod 1000000007 #define elif else if vector<int> v; int k, n; bool check(int m) { int k0 = 0; rep(i, 0, v.sz) { if (v[i] <= m) continue; k0 += (v[i] - 1) / m; } return (k0 <= k); } int32_t main() { cin >> n >> k; rep(i, 0, n) { int t; cin >> t; v.pub(t); } int l = 0, r = 1e9; while (l < r) { int mid = (l + r) / 2; if (check(mid)) r = mid; else l = mid + 1; } cout << l << "\n"; return 0; } /* Edge cases? n=1? a[i]<=0? long vs int? 1LL? 64bits? Re-read question. Is it as easy as it seems? KEEP CORRECTING AND SUBMITTING! */
#include <bits/stdc++.h> using namespace std; #define fastIO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define int long long int #define fi first #define se second #define pub push_back #define pi pair<int, int> #define all(v) (v).begin(), (v).end() #define rep(i, l, r) for (int i = (int)(l); i < (int)(r); i++) #define repd(i, l, r) for (int i = (int)(l); i >= (int)(r); i--) #define clrg(i, l, r) \ for (int i = (int)(l); i < (int)(r); i++) \ vis[i] = 0, v[i].clear(); int power(int x, unsigned int y) { int res = 1; while (y > 0) { if (y & 1) { res = res * x; } y = y >> 1; x = x * x; } return res; } int powermod(int x, unsigned int y, int p) { int res = 1; x = x % p; while (y > 0) { if (y & 1) { res = (res * x) % p; } y = y >> 1; x = (x * x) % p; } return res; } #define print2d(mat, n, m) \ { \ for (int i = 0; i < (int)(n); i++) { \ for (int j = 0; j < (m); j++) { \ cout << mat[i][j] << " "; \ } \ cout << endl; \ } \ } #define clr(a, x) memset(a, x, sizeof(a)) #define rr(v) for (auto &val : v) #define print(v) \ for (const auto itr : v) { \ cout << itr << ' '; \ } \ cout << "\n"; #define ln length() #define sz size() #define mod 1000000007 #define elif else if vector<int> v; int k, n; bool check(int m) { int k0 = 0; rep(i, 0, v.sz) { if (v[i] <= m) continue; k0 += (v[i] - 1) / m; } return (k0 <= k); } int32_t main() { cin >> n >> k; rep(i, 0, n) { int t; cin >> t; v.pub(t); } int l = 1, r = 1e9; while (l < r) { int mid = (l + r) / 2; if (check(mid)) r = mid; else l = mid + 1; } cout << l << "\n"; return 0; } /* Edge cases? n=1? a[i]<=0? long vs int? 1LL? 64bits? Re-read question. Is it as easy as it seems? KEEP CORRECTING AND SUBMITTING! */
replace
78
79
78
79
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 // #define MOD 998244353 #define INF 1000000010 #define EPS 1e-9 #define F first #define S second #define debug(x) cout << x << endl; #define repi(i, x, n) for (int i = x; i < n; i++) #define rep(i, n) repi(i, 0, n) #define lp(i, n) repi(i, 0, n) #define repn(i, n) for (int i = n; i >= 0; i--) #define int long long #define endl "\n" typedef pair<int, int> PII; typedef pair<int, string> PIS; typedef pair<string, int> PSI; signed main() { cin.tie(0); ios::sync_with_stdio(false); int n, k; cin >> n >> k; int a[n]; rep(i, n) cin >> a[i]; sort(a, a + n); rep(i, n) { // cout<<a[i]<<" "; } // cout<<endl; int l = 0, r = 1000000000; int mid = (l + r) / 2; while (l != r) { int cnt = 0; rep(i, n) { // cout<<(a[i]+mid-1)/mid<<" "; cnt += (a[i] + mid - 1) / mid; cnt--; } // cout<<endl; // cout<<mid<<" "<<cnt<<endl; if (cnt > k) l = mid + 1; else r = mid; mid = (r + l) / 2; } cout << min(mid, a[n - 1]) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 // #define MOD 998244353 #define INF 1000000010 #define EPS 1e-9 #define F first #define S second #define debug(x) cout << x << endl; #define repi(i, x, n) for (int i = x; i < n; i++) #define rep(i, n) repi(i, 0, n) #define lp(i, n) repi(i, 0, n) #define repn(i, n) for (int i = n; i >= 0; i--) #define int long long #define endl "\n" typedef pair<int, int> PII; typedef pair<int, string> PIS; typedef pair<string, int> PSI; signed main() { cin.tie(0); ios::sync_with_stdio(false); int n, k; cin >> n >> k; int a[n]; rep(i, n) cin >> a[i]; sort(a, a + n); rep(i, n) { // cout<<a[i]<<" "; } // cout<<endl; int l = 1, r = 1000000000; int mid = (l + r) / 2; while (l != r) { int cnt = 0; rep(i, n) { // cout<<(a[i]+mid-1)/mid<<" "; cnt += (a[i] + mid - 1) / mid; cnt--; } // cout<<endl; // cout<<mid<<" "<<cnt<<endl; if (cnt > k) l = mid + 1; else r = mid; mid = (r + l) / 2; } cout << min(mid, a[n - 1]) << endl; return 0; }
replace
33
34
33
34
0
p02598
C++
Runtime Error
#include <algorithm> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <vector> using namespace std; // マクロ&定数&関数 ================================================ typedef unsigned int uint; typedef long long ll; typedef pair<ll, ll> pll; typedef vector<int> vint; typedef vector<ll> vll; typedef vector<double> vdouble; typedef vector<bool> vbool; typedef vector<string> vstring; typedef vector<pair<int, int>> vpint; typedef vector<pair<ll, ll>> vpll; typedef vector<pair<double, double>> vpdouble; typedef vector<vector<int>> vvint; typedef vector<vector<ll>> vvll; typedef vector<vpint> vvpint; typedef vector<vpll> vvpll; typedef vector<vector<double>> vvdouble; typedef vector<vector<string>> vvstring; typedef vector<vector<bool>> vvbool; typedef vector<vector<vector<ll>>> vvvll; const int INF = 1e9 + 1; const ll LLINF = 1e17 + 1; const int DX[9] = {0, 0, 1, -1, 1, 1, -1, -1, 0}; // 4;4近傍 const int DY[9] = {1, -1, 0, 0, 1, -1, 1, -1, 0}; // 8:8近傍 9:(0,0)を含む const double PI = 3.14159265358979323846264338327950288; // VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV const ll MOD = 1000000007; // 10^9 + 7 // VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } else return false; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } else return false; } int main() { //////================================== cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(25); //////================================== /* ~思いついたことはとりあえず絶対メモする!!~ */ ll N, K; cin >> N >> K; vll A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } if (K == 0) { ll ans = 0; for (int i = 0; i < N; i++) { chmax(ans, A[i]); } cout << ans; return 0; } ll start = 0; ll last = LLINF; ll mid = (start + last) / 2; while (last - start > 1 && (start + last) / 2 > 0) { mid = (start + last) / 2; // mid以下にできるか? ll count = 0; for (int i = 0; i < N; i++) { count += (A[i] - 1) / mid; } if (count <= K) { last = mid; } else { start = mid; } } // mid以下にできるか? ll c = 0; if (mid > 0) { mid = start; } for (int i = 0; i < N; i++) { c += (A[i] - 1) / mid; } if (c <= K) { cout << mid << endl; ; return 0; } else { cout << mid + 1 << endl; return 0; } }
#include <algorithm> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <vector> using namespace std; // マクロ&定数&関数 ================================================ typedef unsigned int uint; typedef long long ll; typedef pair<ll, ll> pll; typedef vector<int> vint; typedef vector<ll> vll; typedef vector<double> vdouble; typedef vector<bool> vbool; typedef vector<string> vstring; typedef vector<pair<int, int>> vpint; typedef vector<pair<ll, ll>> vpll; typedef vector<pair<double, double>> vpdouble; typedef vector<vector<int>> vvint; typedef vector<vector<ll>> vvll; typedef vector<vpint> vvpint; typedef vector<vpll> vvpll; typedef vector<vector<double>> vvdouble; typedef vector<vector<string>> vvstring; typedef vector<vector<bool>> vvbool; typedef vector<vector<vector<ll>>> vvvll; const int INF = 1e9 + 1; const ll LLINF = 1e17 + 1; const int DX[9] = {0, 0, 1, -1, 1, 1, -1, -1, 0}; // 4;4近傍 const int DY[9] = {1, -1, 0, 0, 1, -1, 1, -1, 0}; // 8:8近傍 9:(0,0)を含む const double PI = 3.14159265358979323846264338327950288; // VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV const ll MOD = 1000000007; // 10^9 + 7 // VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } else return false; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } else return false; } int main() { //////================================== cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(25); //////================================== /* ~思いついたことはとりあえず絶対メモする!!~ */ ll N, K; cin >> N >> K; vll A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } if (K == 0) { ll ans = 0; for (int i = 0; i < N; i++) { chmax(ans, A[i]); } cout << ans; return 0; } ll start = 0; ll last = LLINF; ll mid = (start + last) / 2; while (last - start > 1 && (start + last) / 2 > 0) { mid = (start + last) / 2; // mid以下にできるか? ll count = 0; for (int i = 0; i < N; i++) { count += (A[i] - 1) / mid; } if (count <= K) { last = mid; } else { start = mid; } } // mid以下にできるか? ll c = 0; if (start > 0) { mid = start; } for (int i = 0; i < N; i++) { c += (A[i] - 1) / mid; } if (c <= K) { cout << mid << endl; ; return 0; } else { cout << mid + 1 << endl; return 0; } }
replace
126
127
126
127
0
p02598
C++
Runtime Error
#include <algorithm> #include <iostream> #include <math.h> #include <string.h> #include <string> #include <vector> using namespace std; typedef long long ll; bool is_possible(int mid, vector<int> &v, int K) { int ret = 0; for (auto i : v) { ret += (i % mid == 0 ? i / mid - 1 : i / mid); } return (ret <= K); } int main() { int N, K; cin >> N >> K; vector<int> v(N); for (auto &i : v) cin >> i; int left = 0, right = 1e9 + 2, ret = -1; while (left <= right) { int mid = (left + right) / 2; if (is_possible(mid, v, K)) { ret = mid; right = mid - 1; } else left = mid + 1; } cout << ret << endl; }
#include <algorithm> #include <iostream> #include <math.h> #include <string.h> #include <string> #include <vector> using namespace std; typedef long long ll; bool is_possible(int mid, vector<int> &v, int K) { int ret = 0; for (auto i : v) { ret += (i % mid == 0 ? i / mid - 1 : i / mid); } return (ret <= K); } int main() { int N, K; cin >> N >> K; vector<int> v(N); for (auto &i : v) cin >> i; int left = 1, right = 1e9 + 2, ret = -1; while (left <= right) { int mid = (left + right) / 2; if (is_possible(mid, v, K)) { ret = mid; right = mid - 1; } else left = mid + 1; } cout << ret << endl; }
replace
24
25
24
25
0
p02598
C++
Runtime Error
//----------------------- // author : xyqkoala // time : 2020-08-03 //----------------------- #include <algorithm> #include <cmath> #include <deque> #include <iostream> #include <numeric> #include <queue> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; typedef long long LL; const int MOD = 1e9 + 7; void solve(); int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int T = 1; // cin>>T; while (T--) { solve(); } return 0; } LL check(vector<int> &nums, int m, int k) { LL res = 0; for (auto item : nums) { int cnt = item / m; if (item % m) cnt++; res += 1ll * (cnt - 1); if (res > k) return false; } return res <= k; } void solve() { int n, k; cin >> n >> k; vector<int> nums(n); for (int i = 0; i < n; i++) { cin >> nums[i]; } int l = 0, r = MOD; while (l < r) { int m = (r - l) / 2 + l; if (check(nums, m, k)) r = m; else l = m + 1; } cout << l << endl; }
//----------------------- // author : xyqkoala // time : 2020-08-03 //----------------------- #include <algorithm> #include <cmath> #include <deque> #include <iostream> #include <numeric> #include <queue> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; typedef long long LL; const int MOD = 1e9 + 7; void solve(); int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int T = 1; // cin>>T; while (T--) { solve(); } return 0; } LL check(vector<int> &nums, int m, int k) { LL res = 0; for (auto item : nums) { int cnt = item / m; if (item % m) cnt++; res += 1ll * (cnt - 1); if (res > k) return false; } return res <= k; } void solve() { int n, k; cin >> n >> k; vector<int> nums(n); for (int i = 0; i < n; i++) { cin >> nums[i]; } int l = 1, r = MOD; while (l < r) { int m = (r - l) / 2 + l; if (check(nums, m, k)) r = m; else l = m + 1; } cout << l << endl; }
replace
54
55
54
55
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N; long K; cin >> N >> K; vector<long> A(N); for (int i = 0; i < N; i++) cin >> A.at(i); sort(A.begin(), A.end()); long left = 1; long right = 1000000000; while (left < right) { long X = (right - left) / 2; long count = 0; for (int i = 0; i < N; i++) { count += A.at(i) / X; if (A.at(i) % X == 0) count--; } if (count > K) left = X + 1; else right = X; } cout << right << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N; long K; cin >> N >> K; vector<long> A(N); for (int i = 0; i < N; i++) cin >> A.at(i); sort(A.begin(), A.end()); long left = 1; long right = 1000000000; while (left < right) { long X = (right + left) / 2; long count = 0; for (int i = 0; i < N; i++) { count += A.at(i) / X; if (A.at(i) % X == 0) count--; } if (count > K) left = X + 1; else right = X; } cout << right << endl; }
replace
14
15
14
15
TLE
p02598
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long #define db double using namespace std; const int M = 2e5 + 10; int a[M], n, k; bool check(int x) { int cnt = 0; for (int i = 0; i < n; i++) cnt += (a[i] - 1) / x; // printf("%d %d\n",x,cnt); return cnt <= k; } int main() { scanf("%d%d", &n, &k); for (int i = 0; i < n; i++) scanf("%d", &a[i]); sort(a, a + n); int l = 0, r = 1e9 + 10, 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> #define ll long long #define db double using namespace std; const int M = 2e5 + 10; int a[M], n, k; bool check(int x) { int cnt = 0; for (int i = 0; i < n; i++) cnt += (a[i] - 1) / x; // printf("%d %d\n",x,cnt); return cnt <= k; } int main() { scanf("%d%d", &n, &k); for (int i = 0; i < n; i++) scanf("%d", &a[i]); sort(a, a + n); int l = 1, r = 1e9 + 10, 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
18
19
18
19
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> #define all(X) (X).begin(), (X).end() #define rall(X) (X).rbegin(), (X).rend() #define pub push_back #define puf push_front #define pob pop_back #define pof pop_front #define ff first #define ss second #define P 1000000007 #define in(x, a, b) (a <= x && x < b) using namespace std; using ll = long long; typedef pair<int, int> ii; typedef vector<ii> vii; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<vii> vvii; const ll inf = 1000000001, INF = (ll)1e18 + 1; int n, k; vi a; bool check(int val) { int total = 0; for (int i = 0; i < n; i++) { if (a[i] <= val) continue; total += a[i] / val; if (a[i] % val == 0) total--; } return (total <= k); } void solve() { cin >> n >> k; a.resize(n); for (int i = 0; i < n; i++) cin >> a[i]; ll ans = INF; int l = 0, r = 1e9 + 10; while (l <= r) { int mid = (l + r) / 2; if (check(mid)) { ans = min(ans, (ll)mid); r = mid - 1; } else l = mid + 1; } cout << ans << endl; } int main() { ios_base::sync_with_stdio(false); solve(); return 0; }
#include <bits/stdc++.h> #define all(X) (X).begin(), (X).end() #define rall(X) (X).rbegin(), (X).rend() #define pub push_back #define puf push_front #define pob pop_back #define pof pop_front #define ff first #define ss second #define P 1000000007 #define in(x, a, b) (a <= x && x < b) using namespace std; using ll = long long; typedef pair<int, int> ii; typedef vector<ii> vii; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<vii> vvii; const ll inf = 1000000001, INF = (ll)1e18 + 1; int n, k; vi a; bool check(int val) { int total = 0; for (int i = 0; i < n; i++) { if (a[i] <= val) continue; total += a[i] / val; if (a[i] % val == 0) total--; } return (total <= k); } void solve() { cin >> n >> k; a.resize(n); for (int i = 0; i < n; i++) cin >> a[i]; ll ans = INF; int l = 1, r = 1e9 + 10; while (l <= r) { int mid = (l + r) / 2; if (check(mid)) { ans = min(ans, (ll)mid); r = mid - 1; } else l = mid + 1; } cout << ans << endl; } int main() { ios_base::sync_with_stdio(false); solve(); return 0; }
replace
44
45
44
45
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define pb push_back #define eb emplace_back #define all(v) (v).begin(), (v).end() #define sz(v) (int)((v).size()) #define fs first #define sd second typedef long long ll; typedef pair<int, int> pi; typedef pair<pi, int> ppi; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<pi> vpi; typedef vector<vpi> vvpi; typedef vector<ppi> vppi; void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); } vector<string> vec_splitter(string s) { s += ','; vector<string> res; while (!s.empty()) { res.push_back(s.substr(0, s.find(','))); s = s.substr(s.find(',') + 1); } return res; } void debug_out(vector<string> __attribute__((unused)) args, __attribute__((unused)) int idx, __attribute__((unused)) int LINE_NUM) { cerr << endl; } template <typename Head, typename... Tail> void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) { if (idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") "; stringstream ss; ss << H; cerr << args[idx] << " = " << ss.str(); debug_out(args, idx + 1, LINE_NUM, T...); } #ifdef LOCAL #define debug(...) \ debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__) #else #define debug(...) 42 #endif double get_time() { return 1.0 * clock() / CLOCKS_PER_SEC; } int main() { int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } int low = 0, high = 1E9 + 5; while (low < high) { int mid = (low + high) / 2; int need = 0; for (int i = 0; i < n; i++) need += (a[i] + mid - 1) / mid - 1; if (need <= k) high = mid; else low = mid + 1; } cout << low << '\n'; }
#include <bits/stdc++.h> using namespace std; #define pb push_back #define eb emplace_back #define all(v) (v).begin(), (v).end() #define sz(v) (int)((v).size()) #define fs first #define sd second typedef long long ll; typedef pair<int, int> pi; typedef pair<pi, int> ppi; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<pi> vpi; typedef vector<vpi> vvpi; typedef vector<ppi> vppi; void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); } vector<string> vec_splitter(string s) { s += ','; vector<string> res; while (!s.empty()) { res.push_back(s.substr(0, s.find(','))); s = s.substr(s.find(',') + 1); } return res; } void debug_out(vector<string> __attribute__((unused)) args, __attribute__((unused)) int idx, __attribute__((unused)) int LINE_NUM) { cerr << endl; } template <typename Head, typename... Tail> void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) { if (idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") "; stringstream ss; ss << H; cerr << args[idx] << " = " << ss.str(); debug_out(args, idx + 1, LINE_NUM, T...); } #ifdef LOCAL #define debug(...) \ debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__) #else #define debug(...) 42 #endif double get_time() { return 1.0 * clock() / CLOCKS_PER_SEC; } int main() { int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } int low = 1, high = 1E9 + 5; while (low < high) { int mid = (low + high) / 2; int need = 0; for (int i = 0; i < n; i++) need += (a[i] + mid - 1) / mid - 1; if (need <= k) high = mid; else low = mid + 1; } cout << low << '\n'; }
replace
70
71
70
71
0
p02598
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; bool chk(int arr[], int n, int mid, int k) { ll res = 0; for (int i = 0; i < n; i++) res += (arr[i] - 1) / mid; return (res <= k); } int main() { boost; int n, k, i; cin >> n >> k; int arr[n]; fo(i, 0, n) cin >> arr[i]; int f = 0, l = inf, mid, ans = inf; while (f <= l) { mid = (f + l) / 2; if (chk(arr, n, mid, k)) { ans = min(ans, mid); l = mid - 1; } else f = mid + 1; } cout << ans; }
#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; bool chk(int arr[], int n, int mid, int k) { ll res = 0; for (int i = 0; i < n; i++) res += (arr[i] - 1) / mid; return (res <= k); } int main() { boost; int n, k, i; cin >> n >> k; int arr[n]; fo(i, 0, n) cin >> arr[i]; int f = 1, l = inf, mid, ans = inf; while (f <= l) { mid = (f + l) / 2; if (chk(arr, n, mid, k)) { ans = min(ans, mid); l = mid - 1; } else f = mid + 1; } cout << ans; }
replace
39
40
39
40
0
p02598
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; using ll = long long; const int mx = 2e5 + 9; int n; ll k; ll a[mx]; ll ceill(ll x, ll y) { return (x + y - 1) / y; } bool ok(ll x) { ll ttl = 0; for (int i = 0; i < n; i++) { ttl += ceill(a[i], x); } return (ttl - n <= k); } int main() { scanf("%d %lld", &n, &k); for (int i = 0; i < n; i++) scanf("%lld", &a[i]); ll ans = 0; ll lo = 0, hi = 2e9; while (lo <= hi) { ll mid = (lo + hi) / 2; if (ok(mid)) { ans = mid; hi = mid - 1; } else { lo = mid + 1; } } printf("%lld\n", ans); }
#include "bits/stdc++.h" using namespace std; using ll = long long; const int mx = 2e5 + 9; int n; ll k; ll a[mx]; ll ceill(ll x, ll y) { return (x + y - 1) / y; } bool ok(ll x) { ll ttl = 0; for (int i = 0; i < n; i++) { ttl += ceill(a[i], x); } return (ttl - n <= k); } int main() { scanf("%d %lld", &n, &k); for (int i = 0; i < n; i++) scanf("%lld", &a[i]); ll ans = *max_element(a, a + n); ll lo = 1, hi = 2e9; while (lo <= hi) { ll mid = (lo + hi) / 2; if (ok(mid)) { ans = mid; hi = mid - 1; } else { lo = mid + 1; } } printf("%lld\n", ans); }
replace
27
29
27
29
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> #define int long long #define PI acos(-1) using namespace std; constexpr double EPS = 1e-8; constexpr int MAXN = 3e5 + 5; constexpr int INF = 0x3f3f3f3f; array<int, MAXN> a; int n, k; inline bool check(int mid) { int cnt(0); for (int i = 1; i <= n; i++) { if (a[i] % mid == 0) cnt += a[i] / mid - 1; else cnt += a[i] / mid; } return cnt <= k; // } signed main() { std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; int l = 0, r = 2e9, ans = 0; while (l <= r) { int mid = (l + r) >> 1; if (check(mid)) { ans = mid, r = mid - 1; } else l = mid + 1; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define int long long #define PI acos(-1) using namespace std; constexpr double EPS = 1e-8; constexpr int MAXN = 3e5 + 5; constexpr int INF = 0x3f3f3f3f; array<int, MAXN> a; int n, k; inline bool check(int mid) { int cnt(0); for (int i = 1; i <= n; i++) { if (a[i] % mid == 0) cnt += a[i] / mid - 1; else cnt += a[i] / mid; } return cnt <= k; // } signed main() { std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; int l = 1, r = 2e9, ans = 0; while (l <= r) { int mid = (l + r) >> 1; if (check(mid)) { ans = mid, r = mid - 1; } else l = mid + 1; } cout << ans << endl; return 0; }
replace
30
31
30
31
0
p02598
C++
Runtime Error
/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author aryssoncf */ // Taken from: // https://github.com/bqi343/USACO/blob/master/Implementations/content/contest/templateShort.cpp #include <algorithm> #include <array> #include <bitset> #include <cassert> #include <chrono> #include <complex> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef double db; typedef string str; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<ull> vul; typedef vector<ll> vl; typedef vector<pii> vpii; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define F0R(i, a) FOR(i, 0, a) #define ROF(i, a, b) for (int i = (b)-1; i >= (a); --i) #define R0F(i, a) ROF(i, 0, a) #define trav(a, x) for (auto &a : x) #define sz(x) (int)x.size() #define all(x) begin(x), end(x) #define rsz resize #define mp make_pair #define pb push_back #define f first #define s second const int MOD = 1e9 + 7; // 998244353; // = (119<<23)+1 const int MX = 2e5 + 5; template <class T> bool ckmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; } template <class T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count()); // // Created by aryssoncf on 28/10/2019. // #include <type_traits> #include <iterator> template <typename T> constexpr auto hasBegin(int) -> decltype(std::begin(std::declval<T>()), true) { return true; } constexpr bool hasBegin(...) { return false; } template <typename T> using IsContainer = std::integral_constant<bool, hasBegin<T>(0)>; #ifndef JHELPER_EXAMPLE_PROJECT_IO_HPP #define JHELPER_EXAMPLE_PROJECT_IO_HPP #endif // JHELPER_EXAMPLE_PROJECT_IO_HPP template <typename T> std::istream &operator>>(std::istream &is, std::vector<T> &vec) { for (T &element : vec) { is >> element; } return is; } template <typename T, typename U> std::istream &operator>>(std::istream &is, std::pair<T, U> &p) { is >> p.first; is >> p.second; return is; } template <class X, class Y> std::ostream &operator<<(std::ostream &os, std::pair<X, Y> const &p) { return os << p.first << " " << p.second; } template <class Ch, class Tr, class Container> std::basic_ostream<Ch, Tr> &operator<<(std::basic_ostream<Ch, Tr> &os, Container const &x) { bool first = true; for (auto &y : x) { if (first) { first = false; } else { os << " "; } os << y; } return os; } using namespace std; class ELogs { ll f(const vi &A, int len) { ll cuts = 0; trav(x, A) { int y = x - len; cuts += (y + len - 1) / len; } return cuts; } int search(const vi &A, int k) { int left = 0, right = *max_element(all(A)); while (left < right) { int mid = (left + right) / 2; if (f(A, mid) <= k) { right = mid; } else { left = mid + 1; } } return right; } public: void solve(std::istream &in, std::ostream &out) { int n, k; in >> n >> k; vi A(n); in >> A; int res = search(A, k); out << res << '\n'; } void setup() {} }; int main() { std::ios_base::sync_with_stdio(false); ELogs solver; solver.setup(); std::istream &in(std::cin); std::ostream &out(std::cout); in.tie(nullptr); out << std::fixed; out.precision(20); solver.solve(in, out); return 0; }
/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author aryssoncf */ // Taken from: // https://github.com/bqi343/USACO/blob/master/Implementations/content/contest/templateShort.cpp #include <algorithm> #include <array> #include <bitset> #include <cassert> #include <chrono> #include <complex> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef double db; typedef string str; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<ull> vul; typedef vector<ll> vl; typedef vector<pii> vpii; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define F0R(i, a) FOR(i, 0, a) #define ROF(i, a, b) for (int i = (b)-1; i >= (a); --i) #define R0F(i, a) ROF(i, 0, a) #define trav(a, x) for (auto &a : x) #define sz(x) (int)x.size() #define all(x) begin(x), end(x) #define rsz resize #define mp make_pair #define pb push_back #define f first #define s second const int MOD = 1e9 + 7; // 998244353; // = (119<<23)+1 const int MX = 2e5 + 5; template <class T> bool ckmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; } template <class T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count()); // // Created by aryssoncf on 28/10/2019. // #include <type_traits> #include <iterator> template <typename T> constexpr auto hasBegin(int) -> decltype(std::begin(std::declval<T>()), true) { return true; } constexpr bool hasBegin(...) { return false; } template <typename T> using IsContainer = std::integral_constant<bool, hasBegin<T>(0)>; #ifndef JHELPER_EXAMPLE_PROJECT_IO_HPP #define JHELPER_EXAMPLE_PROJECT_IO_HPP #endif // JHELPER_EXAMPLE_PROJECT_IO_HPP template <typename T> std::istream &operator>>(std::istream &is, std::vector<T> &vec) { for (T &element : vec) { is >> element; } return is; } template <typename T, typename U> std::istream &operator>>(std::istream &is, std::pair<T, U> &p) { is >> p.first; is >> p.second; return is; } template <class X, class Y> std::ostream &operator<<(std::ostream &os, std::pair<X, Y> const &p) { return os << p.first << " " << p.second; } template <class Ch, class Tr, class Container> std::basic_ostream<Ch, Tr> &operator<<(std::basic_ostream<Ch, Tr> &os, Container const &x) { bool first = true; for (auto &y : x) { if (first) { first = false; } else { os << " "; } os << y; } return os; } using namespace std; class ELogs { ll f(const vi &A, int len) { ll cuts = 0; trav(x, A) { int y = x - len; cuts += (y + len - 1) / len; } return cuts; } int search(const vi &A, int k) { int left = 1, right = *max_element(all(A)); while (left < right) { int mid = (left + right) / 2; if (f(A, mid) <= k) { right = mid; } else { left = mid + 1; } } return right; } public: void solve(std::istream &in, std::ostream &out) { int n, k; in >> n >> k; vi A(n); in >> A; int res = search(A, k); out << res << '\n'; } void setup() {} }; int main() { std::ios_base::sync_with_stdio(false); ELogs solver; solver.setup(); std::istream &in(std::cin); std::ostream &out(std::cout); in.tie(nullptr); out << std::fixed; out.precision(20); solver.solve(in, out); return 0; }
replace
138
139
138
139
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define pb push_back #define ff first #define ss second #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() using namespace std; using ll = long long; using vi = vector<int>; using pii = pair<ll, ll>; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fLL; ll bpow(ll b, ll p, ll m = 1000000007LL) { ll rt = 1; for (; p; p >>= 1, b = b * b % m) if (p & 1) rt = rt * b % m; return rt; } ll n, k; ll a[200005]; bool check(ll mi) { ll cnt = 0; for (int i = 0; i < n; i++) { if (a[i] > mi) cnt += a[i] / mi; } return cnt <= k; } int main() { IOS; cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; ll lo = 0, hi = 1000000000; while (lo <= hi) { ll mi = lo + hi >> 1; if (check(mi)) hi = mi - 1; else lo = mi + 1; } cout << lo << endl; }
#include <bits/stdc++.h> #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define pb push_back #define ff first #define ss second #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() using namespace std; using ll = long long; using vi = vector<int>; using pii = pair<ll, ll>; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fLL; ll bpow(ll b, ll p, ll m = 1000000007LL) { ll rt = 1; for (; p; p >>= 1, b = b * b % m) if (p & 1) rt = rt * b % m; return rt; } ll n, k; ll a[200005]; bool check(ll mi) { ll cnt = 0; for (int i = 0; i < n; i++) { if (a[i] > mi) cnt += a[i] / mi; } return cnt <= k; } int main() { IOS; cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; ll lo = 1, hi = 1000000000; while (lo <= hi) { ll mi = lo + hi >> 1; if (check(mi)) hi = mi - 1; else lo = mi + 1; } cout << lo << endl; }
replace
38
39
38
39
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i = (a); i < (b); i++) #define all(x) x.begin(), x.end() #define sz(x) (int)(x).size() #define trav(a, x) for (auto &a : x) typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<vi> vvi; typedef long double ld; int n, k; vi a; bool test(int m) { int cuts = 0; rep(i, 0, n) { cuts += (a[i] - 1) / m; } return cuts <= k; } int main() { cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit); cin >> n >> k; a = vi(n); rep(i, 0, n) { cin >> a[i]; } int lo = -1; int hi = 1e9 + 1; int mi; while (lo + 1 < hi) { mi = (lo + hi) / 2; if (test(mi)) { hi = mi; } else { lo = mi; } } cout << hi << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i = (a); i < (b); i++) #define all(x) x.begin(), x.end() #define sz(x) (int)(x).size() #define trav(a, x) for (auto &a : x) typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<vi> vvi; typedef long double ld; int n, k; vi a; bool test(int m) { int cuts = 0; rep(i, 0, n) { cuts += (a[i] - 1) / m; } return cuts <= k; } int main() { cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit); cin >> n >> k; a = vi(n); rep(i, 0, n) { cin >> a[i]; } int lo = 0; int hi = 1e9 + 1; int mi; while (lo + 1 < hi) { mi = (lo + hi) / 2; if (test(mi)) { hi = mi; } else { lo = mi; } } cout << hi << endl; return 0; }
replace
30
31
30
31
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int64_t divceil(int64_t numer, int64_t denom) { if (numer % denom == 0) { return numer / denom; } else { return 1L + numer / denom; } } int main() { int64_t N, K; cin >> N; cin >> K; int64_t max_a = -1; vector<int64_t> A(N); int64_t total_length = 0; for (uint64_t i = 0; i < N; i++) { cin >> A[i]; total_length += A[i]; } // 適当な初期値を与えて上界・下界とする double upper_bound = -1; double lower_bound = 10000000000; for (auto a : A) { int64_t split_num_heuristic = (K * a) / total_length; double val = 1.0 * a / (split_num_heuristic + 1); upper_bound = max(upper_bound, val); lower_bound = min(lower_bound, val); } int64_t result = upper_bound + 2; int64_t left = lower_bound - 1; int64_t right = upper_bound + 1; while (right >= left) { int64_t mid = (left + right) / 2; int64_t total_split = 0; for (uint64_t i = 0; i < N; i++) { int64_t split_num = divceil(A[i], mid) - 1L; total_split += split_num; } if (total_split <= K) { result = min(mid, result); right = mid - 1; } else { left = mid + 1; } } cout << result << endl; }
#include <bits/stdc++.h> using namespace std; int64_t divceil(int64_t numer, int64_t denom) { if (numer % denom == 0) { return numer / denom; } else { return 1L + numer / denom; } } int main() { int64_t N, K; cin >> N; cin >> K; int64_t max_a = -1; vector<int64_t> A(N); int64_t total_length = 0; for (uint64_t i = 0; i < N; i++) { cin >> A[i]; total_length += A[i]; } // 適当な初期値を与えて上界・下界とする double upper_bound = -1; double lower_bound = 10000000000; for (auto a : A) { int64_t split_num_heuristic = (K * a) / total_length; double val = 1.0 * a / (split_num_heuristic + 1); upper_bound = max(upper_bound, val); lower_bound = min(lower_bound, val); } int64_t result = upper_bound + 2; int64_t left = max(lower_bound, 1.0); int64_t right = upper_bound + 1; while (right >= left) { int64_t mid = (left + right) / 2; int64_t total_split = 0; for (uint64_t i = 0; i < N; i++) { int64_t split_num = divceil(A[i], mid) - 1L; total_split += split_num; } if (total_split <= K) { result = min(mid, result); right = mid - 1; } else { left = mid + 1; } } cout << result << endl; }
replace
34
35
34
35
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define MOD 1000000007 #define mod9 1000000009 #define fast \ ios_base ::sync_with_stdio(0); \ cin.tie(NULL); \ cout.tie(NULL); #define mp make_pair #define pb push_back #define ct \ ll t; \ cin >> t; \ while (t--) #define bi begin() #define ei end() #define fi first #define se second #define foe(i, a, b) for (ll i = a; i < b; i++) #define rfoe(i, a, b) for (ll i = a; i >= 0; i--) #define sz(s) s.size() #define mem(a, s) memset(a, s, sizeof(a)) #define all(v) v.bi, v.ei #define MAX 8000000000000000064LL #define MIN -8000000000000000064LL ll add(ll a, ll b) { return (a % MOD + b % MOD + ((MAX) / MOD) * MOD) % MOD; } ll sub(ll a, ll b) { return (a % MOD - b % MOD + ((MAX) / MOD) * MOD) % MOD; } ll mul(ll a, ll b) { return ((a % MOD) * (b % MOD) + ((MAX) / MOD) * MOD) % MOD; } bool isPrime(ll n) { // Corner case if (n <= 1) return false; // Check from 2 to n-1 for (ll i = 2; i * i <= n; i++) if (n % i == 0) return false; return true; } long long binpow(long long a, long long b) { long long res = 1; while (b > 0) { if (b & 1) res = mul(res, a); a = mul(a, a); b >>= 1; } return res % MOD; } bool compare(const pair<ll, ll> &a, const pair<ll, ll> &b) { return (a.se > b.se); } ll lcm(ll a, ll b) { return (a * b) / __gcd(a, b); } // vector<ll>s; // // set<ll>s1; // bool prime[10000009]={false}; // // set<ll>s1; // void Sieve() // { // ll n=10000009; // prime[0]=prime[1]=true; // // s[0]=0; // // s[1]=1; // // s.pb(1); // // t.insert(1); // for (int p=2; p*p<=n; p++) // { // if(prime[p]==false) // { // // s.pb(p); // for(ll j=p*p;j<=n;j+=p) // { // prime[j]=true; // } // } // } // for(ll i=2;i<n;i++) // { // if(prime[i]) // { // s.pb(i); // // s1.insert(i); // } // } // } // ll eea(ll a, ll b, ll & x, ll & y) { // if (a == 0) { // x = 0; // y = 1; // return b; // } // ll x1, y1; // ll d=eea(b % a, a, x1, y1); // x = y1 - (b / a) * x1; // y = x1; // return d; // } // bool find_any_solution(ll a, ll b, ll c, ll &x0, ll &y0, ll &g) { // g = eea(abs(a), abs(b), x0, y0); // if (c % g) { // return false; // } // x0 *= c / g; // y0 *= c / g; // if (a < 0) x0 = -x0; // if (b < 0) y0 = -y0; // return true; // } // ll modinverse(ll a,ll m) // { // ll x, y; // eea(a, m, x, y); // if (__gcd(a,m) != 1) { // return -1; // } // else { // x = (x % m + m) % m; // cout << x << endl; // return x; // } // } ll fact[1000007] = {0}; ll expo(ll x, ll y) { ll res = 1; x = x % MOD; while (y > 0) { if (y & 1) res = (1ll * res * x) % MOD; y = y >> 1; x = (1ll * x * x) % MOD; } return res; } void facto() { fact[0] = 1; fact[1] = 1; for (ll i = 2; i < 1000007; i++) fact[i] = (fact[i - 1] * i) % MOD; } ll ncr(ll n, ll r) { ll res = 1; res = fact[n]; res = (res * (expo(fact[r], MOD - 2))) % MOD; res = (res * (expo(fact[n - r], MOD - 2))) % MOD; return res; } ll npr(ll n, ll r) { facto(); ll res = 1; res = fact[n]; res = (res * (expo(fact[n - r], MOD - 2))) % MOD; return res; } int const N = 2e5 + 9; int const INF = 1e9 + 5; void solve() { ll n, k; cin >> n >> k; ll a[n]; foe(i, 0, n) cin >> a[i]; ll ans = 0, l = 0, r = 10000000006, mid; while (l <= r) { ll mid = l + r >> 1; ll cnt = 0; foe(i, 0, n) { cnt += (a[i] - 1) / mid; } if (cnt <= k) { ans = mid; r = mid - 1; } else { l = mid + 1; } } cout << ans << "\n"; } int main() { fast // Sieve(); // ct { solve(); } }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define MOD 1000000007 #define mod9 1000000009 #define fast \ ios_base ::sync_with_stdio(0); \ cin.tie(NULL); \ cout.tie(NULL); #define mp make_pair #define pb push_back #define ct \ ll t; \ cin >> t; \ while (t--) #define bi begin() #define ei end() #define fi first #define se second #define foe(i, a, b) for (ll i = a; i < b; i++) #define rfoe(i, a, b) for (ll i = a; i >= 0; i--) #define sz(s) s.size() #define mem(a, s) memset(a, s, sizeof(a)) #define all(v) v.bi, v.ei #define MAX 8000000000000000064LL #define MIN -8000000000000000064LL ll add(ll a, ll b) { return (a % MOD + b % MOD + ((MAX) / MOD) * MOD) % MOD; } ll sub(ll a, ll b) { return (a % MOD - b % MOD + ((MAX) / MOD) * MOD) % MOD; } ll mul(ll a, ll b) { return ((a % MOD) * (b % MOD) + ((MAX) / MOD) * MOD) % MOD; } bool isPrime(ll n) { // Corner case if (n <= 1) return false; // Check from 2 to n-1 for (ll i = 2; i * i <= n; i++) if (n % i == 0) return false; return true; } long long binpow(long long a, long long b) { long long res = 1; while (b > 0) { if (b & 1) res = mul(res, a); a = mul(a, a); b >>= 1; } return res % MOD; } bool compare(const pair<ll, ll> &a, const pair<ll, ll> &b) { return (a.se > b.se); } ll lcm(ll a, ll b) { return (a * b) / __gcd(a, b); } // vector<ll>s; // // set<ll>s1; // bool prime[10000009]={false}; // // set<ll>s1; // void Sieve() // { // ll n=10000009; // prime[0]=prime[1]=true; // // s[0]=0; // // s[1]=1; // // s.pb(1); // // t.insert(1); // for (int p=2; p*p<=n; p++) // { // if(prime[p]==false) // { // // s.pb(p); // for(ll j=p*p;j<=n;j+=p) // { // prime[j]=true; // } // } // } // for(ll i=2;i<n;i++) // { // if(prime[i]) // { // s.pb(i); // // s1.insert(i); // } // } // } // ll eea(ll a, ll b, ll & x, ll & y) { // if (a == 0) { // x = 0; // y = 1; // return b; // } // ll x1, y1; // ll d=eea(b % a, a, x1, y1); // x = y1 - (b / a) * x1; // y = x1; // return d; // } // bool find_any_solution(ll a, ll b, ll c, ll &x0, ll &y0, ll &g) { // g = eea(abs(a), abs(b), x0, y0); // if (c % g) { // return false; // } // x0 *= c / g; // y0 *= c / g; // if (a < 0) x0 = -x0; // if (b < 0) y0 = -y0; // return true; // } // ll modinverse(ll a,ll m) // { // ll x, y; // eea(a, m, x, y); // if (__gcd(a,m) != 1) { // return -1; // } // else { // x = (x % m + m) % m; // cout << x << endl; // return x; // } // } ll fact[1000007] = {0}; ll expo(ll x, ll y) { ll res = 1; x = x % MOD; while (y > 0) { if (y & 1) res = (1ll * res * x) % MOD; y = y >> 1; x = (1ll * x * x) % MOD; } return res; } void facto() { fact[0] = 1; fact[1] = 1; for (ll i = 2; i < 1000007; i++) fact[i] = (fact[i - 1] * i) % MOD; } ll ncr(ll n, ll r) { ll res = 1; res = fact[n]; res = (res * (expo(fact[r], MOD - 2))) % MOD; res = (res * (expo(fact[n - r], MOD - 2))) % MOD; return res; } ll npr(ll n, ll r) { facto(); ll res = 1; res = fact[n]; res = (res * (expo(fact[n - r], MOD - 2))) % MOD; return res; } int const N = 2e5 + 9; int const INF = 1e9 + 5; void solve() { ll n, k; cin >> n >> k; ll a[n]; foe(i, 0, n) cin >> a[i]; ll ans = 0, l = 1, r = 10000000006, mid; while (l <= r) { ll mid = l + r >> 1; ll cnt = 0; foe(i, 0, n) { cnt += (a[i] - 1) / mid; } if (cnt <= k) { ans = mid; r = mid - 1; } else { l = mid + 1; } } cout << ans << "\n"; } int main() { fast // Sieve(); // ct { solve(); } }
replace
171
172
171
172
0
p02598
C++
Runtime Error
// Konrad Paluszek,University of Warsaw(former XIV LO Staszic) // #STAY AT HOME #ifndef LOCAL #pragma GCC optimize("O3") #endif #define TIME (chrono::steady_clock::now().time_since_epoch().count()) #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define xfm(a, b) a##b #define xwb(a, b) xfm(a, b) #define _ xwb(nvj, __LINE__) #define __ xwb(kjy, __LINE__) #define ___ xwb(cjm, __LINE__) #define REP(i, n) for (urs(n) i = 0; i < (n); ++i) #define UNTIL(t) while (clock() < (t)*CLOCKS_PER_SEC) #define PER(r...) for (bool _ = 1; _ || next_permutation(r); _ = false) #define ALL(r) (r).begin(), (r).end() #define RALL(r) (r).rbegin(), (r).rend() #define FS(r) r.first, r.second #define SF(r) r.second, r.first #define M0(r) memset(r, 0, sizeof(r)) #define sim template <class c #define ros return o #define rans return ans #define forbits(i, m) \ if (m) \ for (urs(m) i = ctz(m), i##nvj = m; i##nvj; \ i##nvj ^= ((urs(m))1 << i), i = ctz(i##nvj)) #define fordbits(i, m) \ if (m) \ for (urs(m) i = 8 * sizeof(m) - clz(m) - 1, i##nxd = m; i##nxd; \ i##nxd ^= ((urs(m))1 << i), i = 8 * sizeof(m) - clz(i##nxd) - 1) #define ksets(t, m, k, n) \ for (t m = (((t)1 << (k)) - 1); m < ((t)1 << (n)); m = nux(m)) #define urs(r...) typename decay<decltype(r)>::type #define hur(f, g, r) \ sim > int f(c a) { \ if (sizeof(c) == 16) \ return r; \ if (sizeof(c) == 8) \ return g##ll(a); \ return g(a); \ } #define pwq(t, i) \ int clz(t x) { return clz<int>(x) - i; } #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wconversion" using namespace __gnu_pbds; using namespace std; using ll = long long; using ld = long double; using ull = unsigned long long; using vi = vector<int>; using vll = vector<ll>; using pii = pair<int, int>; using pll = pair<ll, ll>; using vpii = vector<pii>; using spii = set<pii>; using mii = map<int, int>; using unt = unsigned int; sim > using min_queue = priority_queue<c, vector<c>, greater<c>>; sim, class b, class cmp = less<c> > using ordered_map = tree<c, b, cmp, rb_tree_tag, tree_order_statistics_node_update>; sim, class cmp = less < c >> using ordered_set = ordered_map<c, null_type, cmp>; hur(popc, __builtin_popcount, popc<ull>(a) + popc<ull>(a >> 64)) hur(ctz, __builtin_ctz, (ull)a ? ctz<ull>(a) : 64 + ctz<ull>(a >> 64)) hur(clz, __builtin_clz, a >> 64 ? clz<ull>(a >> 64) : 64 + clz<ull>(a)) pwq(short, 16) pwq(uint16_t, 16) pwq(char, 24) pwq(int8_t, 24) pwq(uint8_t, 24) sim, class N > bool mini(c &o, const N &h) { if (o > h) ros = h, 1; return 0; } sim, class N > bool maxi(c &o, const N &h) { if (o < h) ros = h, 1; return 0; } sim, class n > using gyv = c; #if defined(LOCAL) // || defined(LOCAL2) #include </home/kjp/headers/debuglib.hpp> #else #define loc(...) #define onl(r...) r #define debug(...) #define print_stack(...) #define mark_stack(...) #define set_pre(...) #define reg_it(...) #define def_op(...) \ struct _ {}; #if !defined(LOCAL) && !defined(LOCAL2) #define exit my_exit void my_exit(int x) { fflush(stdout); _Exit(x); } #endif #endif #define next nexT #define prev preV #define tree trEE #define left lefT #define right righT #define div diV #define y1 y_1 #define pow \ do \ not use cmath pow unless you know what you are doing ull mix(ull o) { o += 0x9e3779b97f4a7c15; o = (o ^ (o >> 30)) * 0xbf58476d1ce4e5b9; o = (o ^ (o >> 27)) * 0x94d049bb133111eb; ros ^ (o >> 31); } ull SALT = 0x7a14a4b0881ebf9, tqu = 0x7a14a4b0881ebf9; ull my_rand() { return tqu = mix(tqu); } void my_srand(ull x) { SALT = tqu = x; } const int inf = 1023400000; const ll llinf = 1234567890000000000ll; ll fix(ll o, ll m) { o %= m; if (o < 0) o += m; ros; } #define rand my_rand #define srand my_srand #define random_shuffle(r...) \ random_shuffle(r, [](int _) { return my_rand() % _; }) sim > inline c nux(c m) { if (!m) return numeric_limits<c>::max(); c A = m & -m; c B = ~((A - 1) ^ m); c C = B & -B; c D = (C >> (1 + ctz(A))) - 1; return C | (m & ~(C - 1)) | D; } __attribute__((no_sanitize_undefined)) ll mul(ll a, ll b, ll m) { ll q = (ll)(a * (ld)b / m); ll o = a * b - q * m; o %= m; if (o < 0) o += m; ros; } sim > void unq(c &x) { x.resize(unique(ALL(x)) - x.begin()); } #pragma GCC diagnostic pop #if ((ULONG_MAX) != (UINT_MAX)) namespace std { template <> struct is_signed<__int128> : public true_type {}; } // namespace std #endif sim, class d > typename common_type<c, d>::type floor_div(c a, d b) { static_assert(is_signed<c>::value == is_signed<d>::value, "using floor_div with different signedness"); if (b < 0) b = -b, a = -a; return a / b - (a % b < 0); } sim, class d > typename common_type<c, d>::type ceil_div(c a, d b) { static_assert(is_signed<c>::value == is_signed<d>::value, "using ceil_div with different signedness"); if (b < 0) b = -b, a = -a; return a / b + (a % b > 0); } sim > struct REV { using value_type = typename c::value_type; c &x; using it = typename c::reverse_iterator; it begin() { return x.rbegin(); } it end() { return x.rend(); } }; sim > struct CREV { using value_type = typename c::value_type; const c &x; using it = typename c::const_reverse_iterator; it begin() { return x.rbegin(); } it end() { return x.rend(); } }; sim > REV<c> reversed(c &x) { return REV<c>{x}; } sim > CREV<c> reversed(const c &x) { return CREV<c>{x}; } #define done(r...) exit(0 * printf(r)) #if defined(LOCAL) || defined(LOCAL2) void __tmi() { cerr << setprecision(6) << fixed << "total time: " << clock() / (ld)CLOCKS_PER_SEC << "s" << endl; } int _ = (atexit(__tmi), 0); #endif // #STAY AT HOME void solve() { int n, k; scanf("%d%d", &n, &k); vi a(n); REP(i, n) scanf("%d", &a[i]); int low = 0, high = 1e9 + 10, ans = -1; while (low <= high) { int med = (low + high) / 2; ll need = 0; for (int x : a) need += ceil_div(x, med) - 1; if (need <= k) { ans = med; high = med - 1; } else low = med + 1; } printf("%d\n", ans); } int main() { // unt seed = TIME; debug(imie(seed));srand(seed); int t = 1; // scanf("%d", &t); REP(_, t) solve(); exit(0); } // #STAY AT HOME
// Konrad Paluszek,University of Warsaw(former XIV LO Staszic) // #STAY AT HOME #ifndef LOCAL #pragma GCC optimize("O3") #endif #define TIME (chrono::steady_clock::now().time_since_epoch().count()) #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define xfm(a, b) a##b #define xwb(a, b) xfm(a, b) #define _ xwb(nvj, __LINE__) #define __ xwb(kjy, __LINE__) #define ___ xwb(cjm, __LINE__) #define REP(i, n) for (urs(n) i = 0; i < (n); ++i) #define UNTIL(t) while (clock() < (t)*CLOCKS_PER_SEC) #define PER(r...) for (bool _ = 1; _ || next_permutation(r); _ = false) #define ALL(r) (r).begin(), (r).end() #define RALL(r) (r).rbegin(), (r).rend() #define FS(r) r.first, r.second #define SF(r) r.second, r.first #define M0(r) memset(r, 0, sizeof(r)) #define sim template <class c #define ros return o #define rans return ans #define forbits(i, m) \ if (m) \ for (urs(m) i = ctz(m), i##nvj = m; i##nvj; \ i##nvj ^= ((urs(m))1 << i), i = ctz(i##nvj)) #define fordbits(i, m) \ if (m) \ for (urs(m) i = 8 * sizeof(m) - clz(m) - 1, i##nxd = m; i##nxd; \ i##nxd ^= ((urs(m))1 << i), i = 8 * sizeof(m) - clz(i##nxd) - 1) #define ksets(t, m, k, n) \ for (t m = (((t)1 << (k)) - 1); m < ((t)1 << (n)); m = nux(m)) #define urs(r...) typename decay<decltype(r)>::type #define hur(f, g, r) \ sim > int f(c a) { \ if (sizeof(c) == 16) \ return r; \ if (sizeof(c) == 8) \ return g##ll(a); \ return g(a); \ } #define pwq(t, i) \ int clz(t x) { return clz<int>(x) - i; } #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wconversion" using namespace __gnu_pbds; using namespace std; using ll = long long; using ld = long double; using ull = unsigned long long; using vi = vector<int>; using vll = vector<ll>; using pii = pair<int, int>; using pll = pair<ll, ll>; using vpii = vector<pii>; using spii = set<pii>; using mii = map<int, int>; using unt = unsigned int; sim > using min_queue = priority_queue<c, vector<c>, greater<c>>; sim, class b, class cmp = less<c> > using ordered_map = tree<c, b, cmp, rb_tree_tag, tree_order_statistics_node_update>; sim, class cmp = less < c >> using ordered_set = ordered_map<c, null_type, cmp>; hur(popc, __builtin_popcount, popc<ull>(a) + popc<ull>(a >> 64)) hur(ctz, __builtin_ctz, (ull)a ? ctz<ull>(a) : 64 + ctz<ull>(a >> 64)) hur(clz, __builtin_clz, a >> 64 ? clz<ull>(a >> 64) : 64 + clz<ull>(a)) pwq(short, 16) pwq(uint16_t, 16) pwq(char, 24) pwq(int8_t, 24) pwq(uint8_t, 24) sim, class N > bool mini(c &o, const N &h) { if (o > h) ros = h, 1; return 0; } sim, class N > bool maxi(c &o, const N &h) { if (o < h) ros = h, 1; return 0; } sim, class n > using gyv = c; #if defined(LOCAL) // || defined(LOCAL2) #include </home/kjp/headers/debuglib.hpp> #else #define loc(...) #define onl(r...) r #define debug(...) #define print_stack(...) #define mark_stack(...) #define set_pre(...) #define reg_it(...) #define def_op(...) \ struct _ {}; #if !defined(LOCAL) && !defined(LOCAL2) #define exit my_exit void my_exit(int x) { fflush(stdout); _Exit(x); } #endif #endif #define next nexT #define prev preV #define tree trEE #define left lefT #define right righT #define div diV #define y1 y_1 #define pow \ do \ not use cmath pow unless you know what you are doing ull mix(ull o) { o += 0x9e3779b97f4a7c15; o = (o ^ (o >> 30)) * 0xbf58476d1ce4e5b9; o = (o ^ (o >> 27)) * 0x94d049bb133111eb; ros ^ (o >> 31); } ull SALT = 0x7a14a4b0881ebf9, tqu = 0x7a14a4b0881ebf9; ull my_rand() { return tqu = mix(tqu); } void my_srand(ull x) { SALT = tqu = x; } const int inf = 1023400000; const ll llinf = 1234567890000000000ll; ll fix(ll o, ll m) { o %= m; if (o < 0) o += m; ros; } #define rand my_rand #define srand my_srand #define random_shuffle(r...) \ random_shuffle(r, [](int _) { return my_rand() % _; }) sim > inline c nux(c m) { if (!m) return numeric_limits<c>::max(); c A = m & -m; c B = ~((A - 1) ^ m); c C = B & -B; c D = (C >> (1 + ctz(A))) - 1; return C | (m & ~(C - 1)) | D; } __attribute__((no_sanitize_undefined)) ll mul(ll a, ll b, ll m) { ll q = (ll)(a * (ld)b / m); ll o = a * b - q * m; o %= m; if (o < 0) o += m; ros; } sim > void unq(c &x) { x.resize(unique(ALL(x)) - x.begin()); } #pragma GCC diagnostic pop #if ((ULONG_MAX) != (UINT_MAX)) namespace std { template <> struct is_signed<__int128> : public true_type {}; } // namespace std #endif sim, class d > typename common_type<c, d>::type floor_div(c a, d b) { static_assert(is_signed<c>::value == is_signed<d>::value, "using floor_div with different signedness"); if (b < 0) b = -b, a = -a; return a / b - (a % b < 0); } sim, class d > typename common_type<c, d>::type ceil_div(c a, d b) { static_assert(is_signed<c>::value == is_signed<d>::value, "using ceil_div with different signedness"); if (b < 0) b = -b, a = -a; return a / b + (a % b > 0); } sim > struct REV { using value_type = typename c::value_type; c &x; using it = typename c::reverse_iterator; it begin() { return x.rbegin(); } it end() { return x.rend(); } }; sim > struct CREV { using value_type = typename c::value_type; const c &x; using it = typename c::const_reverse_iterator; it begin() { return x.rbegin(); } it end() { return x.rend(); } }; sim > REV<c> reversed(c &x) { return REV<c>{x}; } sim > CREV<c> reversed(const c &x) { return CREV<c>{x}; } #define done(r...) exit(0 * printf(r)) #if defined(LOCAL) || defined(LOCAL2) void __tmi() { cerr << setprecision(6) << fixed << "total time: " << clock() / (ld)CLOCKS_PER_SEC << "s" << endl; } int _ = (atexit(__tmi), 0); #endif // #STAY AT HOME void solve() { int n, k; scanf("%d%d", &n, &k); vi a(n); REP(i, n) scanf("%d", &a[i]); int low = 1, high = 1e9 + 10, ans = -1; while (low <= high) { int med = (low + high) / 2; ll need = 0; for (int x : a) need += ceil_div(x, med) - 1; if (need <= k) { ans = med; high = med - 1; } else low = med + 1; } printf("%d\n", ans); } int main() { // unt seed = TIME; debug(imie(seed));srand(seed); int t = 1; // scanf("%d", &t); REP(_, t) solve(); exit(0); } // #STAY AT HOME
replace
202
203
202
203
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, int>; using vint = vector<int>; using vvint = vector<vint>; using vll = vector<ll>; using vvll = vector<vll>; using vchar = vector<char>; using vvchar = vector<vchar>; using vp = vector<P>; using vpp = vector<pair<P, P>>; using vvp = vector<vp>; #define rep(i, n) for (int i = 0; i < n; ++i) #pragma region Debug istream &operator>>(istream &is, P &a) { return is >> a.first >> a.second; } ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; } template <typename T> void view(const std::vector<T> &v) { #ifndef ONLINE_JUDGE for (const auto &e : v) { std::cout << e << " "; } std::cout << std::endl; #endif } template <typename T> void view(const std::vector<std::vector<T>> &vv) { for (const auto &v : vv) { view(v); } } #pragma endregion int main() { int n, k; cin >> n >> k; vint a(n); rep(i, n) cin >> a[i]; auto pos = [&](int x) { int sum = 0; rep(i, n) { int cut = a[i] / x; if (a[i] % x) cut++; cut--; sum += cut; } return sum <= k; }; int l = 0, r = max_element(a.begin(), a.end())[0]; while (l < r) { int mid = (l + r) / 2; bool ok = pos(mid); if (ok) { r = mid; } else { l = mid + 1; } } cout << r << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, int>; using vint = vector<int>; using vvint = vector<vint>; using vll = vector<ll>; using vvll = vector<vll>; using vchar = vector<char>; using vvchar = vector<vchar>; using vp = vector<P>; using vpp = vector<pair<P, P>>; using vvp = vector<vp>; #define rep(i, n) for (int i = 0; i < n; ++i) #pragma region Debug istream &operator>>(istream &is, P &a) { return is >> a.first >> a.second; } ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; } template <typename T> void view(const std::vector<T> &v) { #ifndef ONLINE_JUDGE for (const auto &e : v) { std::cout << e << " "; } std::cout << std::endl; #endif } template <typename T> void view(const std::vector<std::vector<T>> &vv) { for (const auto &v : vv) { view(v); } } #pragma endregion int main() { int n, k; cin >> n >> k; vint a(n); rep(i, n) cin >> a[i]; auto pos = [&](int x) { int sum = 0; rep(i, n) { int cut = a[i] / x; if (a[i] % x) cut++; cut--; sum += cut; } return sum <= k; }; int l = 1, r = max_element(a.begin(), a.end())[0]; while (l < r) { int mid = (l + r) / 2; bool ok = pos(mid); if (ok) { r = mid; } else { l = mid + 1; } } cout << r << endl; return 0; }
replace
56
57
56
57
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (register int i = a; i <= b; i++) #define per(i, a, b) for (register int i = a; i >= b; i--) typedef long long LL; const LL mod = 1e9 + 7; const int N = 3e5 + 5; int n; LL k, a[N]; LL l, r; bool Check(LL s) { LL res = 0; rep(i, 1, n) res += (a[i] + s - 1) / s - 1; return res <= k; } int main() { cin >> n >> k; rep(i, 1, n) cin >> a[i]; l = 0, r = 1e9; while (l < r) { LL mid = (r + l) / 2; if (Check(mid)) r = mid; else l = mid + 1; } cout << l << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (register int i = a; i <= b; i++) #define per(i, a, b) for (register int i = a; i >= b; i--) typedef long long LL; const LL mod = 1e9 + 7; const int N = 3e5 + 5; int n; LL k, a[N]; LL l, r; bool Check(LL s) { LL res = 0; rep(i, 1, n) res += (a[i] + s - 1) / s - 1; return res <= k; } int main() { cin >> n >> k; rep(i, 1, n) cin >> a[i]; l = 1, r = 1e9; while (l < r) { LL mid = (r + l) / 2; if (Check(mid)) r = mid; else l = mid + 1; } cout << l << endl; }
replace
21
22
21
22
0
p02598
C++
Runtime Error
#include <cstdio> long long a[100005]; int isOk(int n, long long have, long long len) { long long left = have; for (int i = 1; i <= n; i++) { long long L = 0, R = left; long long res = -1; while (L <= R) { long long M = (L + R) / 2; if ((M + 1) * len >= a[i]) { res = M; R = M - 1; } else L = M + 1; } if (res == -1) return 0; else left -= res; } return 1; } int main() { int n; long long k; scanf("%d%lld", &n, &k); for (int i = 1; i <= n; i++) scanf("%lld", &a[i]); long long L = 1, R = 1000000000; long long res = -1; while (L <= R) { int M = (L + R) / 2; if (isOk(n, k, M)) { res = M; R = M - 1; } else L = M + 1; } printf("%lld\n", res); return 0; }
#include <cstdio> long long a[200005]; int isOk(int n, long long have, long long len) { long long left = have; for (int i = 1; i <= n; i++) { long long L = 0, R = left; long long res = -1; while (L <= R) { long long M = (L + R) / 2; if ((M + 1) * len >= a[i]) { res = M; R = M - 1; } else L = M + 1; } if (res == -1) return 0; else left -= res; } return 1; } int main() { int n; long long k; scanf("%d%lld", &n, &k); for (int i = 1; i <= n; i++) scanf("%lld", &a[i]); long long L = 1, R = 1000000000; long long res = -1; while (L <= R) { int M = (L + R) / 2; if (isOk(n, k, M)) { res = M; R = M - 1; } else L = M + 1; } printf("%lld\n", res); return 0; }
replace
1
2
1
2
0
p02598
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef long long int ll; typedef pair<int, int> P; bool check(int mid, vector<int> &a, int k) { int n = a.size(); priority_queue<double> que; // bool ret = false; rep(i, n) que.push(a[i]); rep(i, k) { double p = que.top(); que.pop(); que.push(mid); que.push(p - mid); } return (que.top() <= mid); } int main() { int n, k; cin >> n >> k; vector<int> a(n); rep(i, n) cin >> a[i]; int ok = 1e9, ng = 0; while (abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if (check(mid, a, k)) ok = mid; else ng = mid; } cout << ok << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef long long int ll; typedef pair<int, int> P; bool check(int mid, vector<int> &a, int k) { int n = a.size(); int cnt = 0; rep(i, n) cnt += (a[i] - 1) / mid; return (cnt <= k); } int main() { int n, k; cin >> n >> k; vector<int> a(n); rep(i, n) cin >> a[i]; int ok = 1e9, ng = 0; while (abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if (check(mid, a, k)) ok = mid; else ng = mid; } cout << ok << endl; return 0; }
replace
8
19
8
11
TLE
p02598
C++
Runtime Error
#include <algorithm> #include <bitset> #include <iomanip> #include <iostream> #include <list> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <time.h> #include <unordered_map> #include <vector> using namespace std; #define MOD 1000000007 #define int int64_t #define baba_shiv \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define mpii map<int, int> #define pb push_back #define mkp make_pair #define all(x) x.begin(), x.end() #define allr(x) x.rbegin(), x.rend() #define ub(v, x) upper_bound(all(v), x) #define lb(v, x) lower_bound(all(v), x) #define gcd(a, b) __gcd(a, b) #define lcm(a, b) (((a * b)) / __gcd(a, b)) #define vi vector<int> #define pii pair<int, int> #define vpii vector<pii> #define vs vector<string> #define ff first #define ss second #define foru(v, s, e) for (int v = s; v < e; v++) #define ford(v, s, e) for (int v = s; v > e; v--) // int MOD; inline void normal(int &a) { a %= MOD; (a < 0) && (a += MOD); } inline int modMul(int a, int b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a * b) % MOD; } inline int modAdd(int a, int b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a + b) % MOD; } inline int modSub(int a, int b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; } inline int modPow(int b, int p) { int r = 1; while (p) { if (p & 1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; } inline int modInverse(int a) { return modPow(a, MOD - 2); } inline int modDiv(int a, int b) { return modMul(a, modInverse(b)); } /***********************************************************************************************************************/ template <typename F, typename S> ostream &operator<<(ostream &os, const pair<F, S> &p) { return os << "(" << p.first << ", " << p.second << ")"; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "{"; typename vector<T>::const_iterator it; for (it = v.begin(); it != v.end(); it++) { if (it != v.begin()) os << ", "; os << *it; } return os << "}"; } template <typename T> ostream &operator<<(ostream &os, const set<T> &v) { os << "["; typename set<T>::const_iterator it; for (it = v.begin(); it != v.end(); it++) { if (it != v.begin()) os << ", "; os << *it; } return os << "]"; } template <typename F, typename S> ostream &operator<<(ostream &os, const map<F, S> &v) { os << "["; typename map<F, S>::const_iterator it; for (it = v.begin(); it != v.end(); it++) { if (it != v.begin()) os << ", "; os << it->first << " = " << it->second; } return os << "]"; } #define deb(x) cerr << #x << " = " << x << '\n'; /***********************************************************************************************************************/ int good(vi &arr, int x) { int n = arr.size(); int mov = 0; for (int i = 0; i < n; i++) { int cur = arr[i]; if (cur <= x) continue; mov += cur / x; } return mov; } signed main() { baba_shiv; int T = 1; // cin >> T; foru(trr, 1, T + 1) { int n, k; cin >> n >> k; vi arr(n); foru(i, 0, n) cin >> arr[i]; int ans = -1; int hi = 1e10, lo = 0; while (hi >= lo) { int mid = (hi + lo) / 2; if (good(arr, mid) <= k) { ans = mid; hi = mid - (int)1; } else lo = mid + (int)1; } cout << ans; } }
#include <algorithm> #include <bitset> #include <iomanip> #include <iostream> #include <list> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <time.h> #include <unordered_map> #include <vector> using namespace std; #define MOD 1000000007 #define int int64_t #define baba_shiv \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define mpii map<int, int> #define pb push_back #define mkp make_pair #define all(x) x.begin(), x.end() #define allr(x) x.rbegin(), x.rend() #define ub(v, x) upper_bound(all(v), x) #define lb(v, x) lower_bound(all(v), x) #define gcd(a, b) __gcd(a, b) #define lcm(a, b) (((a * b)) / __gcd(a, b)) #define vi vector<int> #define pii pair<int, int> #define vpii vector<pii> #define vs vector<string> #define ff first #define ss second #define foru(v, s, e) for (int v = s; v < e; v++) #define ford(v, s, e) for (int v = s; v > e; v--) // int MOD; inline void normal(int &a) { a %= MOD; (a < 0) && (a += MOD); } inline int modMul(int a, int b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a * b) % MOD; } inline int modAdd(int a, int b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a + b) % MOD; } inline int modSub(int a, int b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; } inline int modPow(int b, int p) { int r = 1; while (p) { if (p & 1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; } inline int modInverse(int a) { return modPow(a, MOD - 2); } inline int modDiv(int a, int b) { return modMul(a, modInverse(b)); } /***********************************************************************************************************************/ template <typename F, typename S> ostream &operator<<(ostream &os, const pair<F, S> &p) { return os << "(" << p.first << ", " << p.second << ")"; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "{"; typename vector<T>::const_iterator it; for (it = v.begin(); it != v.end(); it++) { if (it != v.begin()) os << ", "; os << *it; } return os << "}"; } template <typename T> ostream &operator<<(ostream &os, const set<T> &v) { os << "["; typename set<T>::const_iterator it; for (it = v.begin(); it != v.end(); it++) { if (it != v.begin()) os << ", "; os << *it; } return os << "]"; } template <typename F, typename S> ostream &operator<<(ostream &os, const map<F, S> &v) { os << "["; typename map<F, S>::const_iterator it; for (it = v.begin(); it != v.end(); it++) { if (it != v.begin()) os << ", "; os << it->first << " = " << it->second; } return os << "]"; } #define deb(x) cerr << #x << " = " << x << '\n'; /***********************************************************************************************************************/ int good(vi &arr, int x) { int n = arr.size(); int mov = 0; for (int i = 0; i < n; i++) { int cur = arr[i]; if (cur <= x) continue; mov += cur / x; } return mov; } signed main() { baba_shiv; int T = 1; // cin >> T; foru(trr, 1, T + 1) { int n, k; cin >> n >> k; vi arr(n); foru(i, 0, n) cin >> arr[i]; int ans = -1; int hi = 1e10, lo = 1; while (hi >= lo) { int mid = (hi + lo) / 2; if (good(arr, mid) <= k) { ans = mid; hi = mid - (int)1; } else lo = mid + (int)1; } cout << ans; } }
replace
146
147
146
147
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> #define int long long using namespace std; constexpr int mod = 1e9 + 7; signed main() { int n, k, a[200000]; cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; int ub = 0, lb = mod; for (int cnt = 0; cnt < 100; cnt++) { int mid = (lb + ub) / 2; int ans = 0; for (int i = 0; i < n; i++) ans += (a[i] + mid - 1) / mid; (ans <= n + k ? lb : ub) = mid; } cout << lb << endl; }
#include <bits/stdc++.h> #define int long long using namespace std; constexpr int mod = 1e9 + 7; signed main() { int n, k, a[200000]; cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; int ub = 0, lb = mod; while (lb - ub > 1) { int mid = (lb + ub) / 2; int ans = 0; for (int i = 0; i < n; i++) ans += (a[i] + mid - 1) / mid; (ans <= n + k ? lb : ub) = mid; } cout << lb << endl; }
replace
10
11
10
11
0
p02598
C++
Runtime Error
#include <algorithm> #include <cmath> #include <deque> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <utility> #include <vector> using namespace std; typedef long long ll; ll mod = 1e9 + 7; // ll mod = 998244353; #define rep(i, n) for (int i = 0; i < (n); ++i) int main() { int n; ll k; cin >> n >> k; vector<ll> a(n); ll max_num = 0; rep(i, n) { cin >> a[i]; max_num = max(max_num, a[i]); } if (k == 0) { cout << max_num << endl; return 0; } ll l = -1; ll r = 1e9 + 1; while (r - l > 1LL) { ll m = (l + r) / 2LL; ll cnt = 0; rep(i, n) { cnt += (a[i] + m - 1LL) / m - 1LL; } // cout << l << " " << r << " " << cnt << endl; if (cnt > k) { l = m; } else { r = m; } } cout << r << endl; return 0; }
#include <algorithm> #include <cmath> #include <deque> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <utility> #include <vector> using namespace std; typedef long long ll; ll mod = 1e9 + 7; // ll mod = 998244353; #define rep(i, n) for (int i = 0; i < (n); ++i) int main() { int n; ll k; cin >> n >> k; vector<ll> a(n); ll max_num = 0; rep(i, n) { cin >> a[i]; max_num = max(max_num, a[i]); } if (k == 0) { cout << max_num << endl; return 0; } ll l = 0; ll r = 1e9; while (r - l > 1LL) { ll m = (l + r) / 2LL; ll cnt = 0; rep(i, n) { cnt += (a[i] + m - 1LL) / m - 1LL; } // cout << l << " " << r << " " << cnt << endl; if (cnt > k) { l = m; } else { r = m; } } cout << r << endl; return 0; }
replace
32
34
32
34
0
p02598
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cmath> #include <ctime> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <vector> #ifndef M_PI #define M_PI 3.141592653589 #endif #define int long long #define double long double #ifdef TIME #define start \ cin.tie(NULL); \ cout.tie(NULL); \ cout.setf(ios::fixed); \ cout.precision(10); \ ios_base::sync_with_stdio(false); \ int32_t START = clock() #define finish \ cout << "\ntime: " << (clock() - START) / (CLOCKS_PER_SEC * 1.0); \ return 0 #endif #ifndef TIME #define start \ cin.tie(NULL); \ cout.tie(NULL); \ cout.setf(ios::fixed); \ cout.precision(10); \ ios_base::sync_with_stdio(false) #define finish return 0 #endif using namespace std; // vector input template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (auto &i : vec) { cin >> i; } return is; } // pair output template <typename E> ostream &operator<<(ostream &os, pair<E, E> &t) { os << t.first << ' ' << t.second; return os; } //"map" pair output template <typename E> ostream &operator<<(ostream &os, pair<const E, E> &t) { os << t.first << ' ' << t.second; return os; } // vector output template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) { for (T i : vec) { os << i << ' '; } return os; } // 2 dimensional vector output template <typename T> ostream &operator<<(ostream &os, vector<vector<T>> &vec) { for (vector<T> i : vec) { os << i << '\n'; } return os; } int n, k; vector<int> a; bool can(int len) { int amount = 0; for (int i = 0; i < n; ++i) { int el = a[i]; amount += (el + len - 1) / len - 1; if (amount > k) { return false; } } return amount <= k; } int32_t main() { start; cin >> n >> k; a.resize(n); int sum = 0; int mx = 0; for (int i = 0; i < n; ++i) { cin >> a[i]; sum += a[i]; if (mx < a[i]) { mx = a[i]; } } // sort(a.rbegin(), a.rend()); int l = sum / (n + k) - 1; int r = mx; while (r != l + 1) { int m = (l + r) / 2; if (can(m)) { r = m; } else { l = m; } } cout << r << '\n'; finish; }
#include <algorithm> #include <bitset> #include <cmath> #include <ctime> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <vector> #ifndef M_PI #define M_PI 3.141592653589 #endif #define int long long #define double long double #ifdef TIME #define start \ cin.tie(NULL); \ cout.tie(NULL); \ cout.setf(ios::fixed); \ cout.precision(10); \ ios_base::sync_with_stdio(false); \ int32_t START = clock() #define finish \ cout << "\ntime: " << (clock() - START) / (CLOCKS_PER_SEC * 1.0); \ return 0 #endif #ifndef TIME #define start \ cin.tie(NULL); \ cout.tie(NULL); \ cout.setf(ios::fixed); \ cout.precision(10); \ ios_base::sync_with_stdio(false) #define finish return 0 #endif using namespace std; // vector input template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (auto &i : vec) { cin >> i; } return is; } // pair output template <typename E> ostream &operator<<(ostream &os, pair<E, E> &t) { os << t.first << ' ' << t.second; return os; } //"map" pair output template <typename E> ostream &operator<<(ostream &os, pair<const E, E> &t) { os << t.first << ' ' << t.second; return os; } // vector output template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) { for (T i : vec) { os << i << ' '; } return os; } // 2 dimensional vector output template <typename T> ostream &operator<<(ostream &os, vector<vector<T>> &vec) { for (vector<T> i : vec) { os << i << '\n'; } return os; } int n, k; vector<int> a; bool can(int len) { int amount = 0; for (int i = 0; i < n; ++i) { int el = a[i]; amount += (el + len - 1) / len - 1; if (amount > k) { return false; } } return amount <= k; } int32_t main() { start; cin >> n >> k; a.resize(n); int sum = 0; int mx = 0; for (int i = 0; i < n; ++i) { cin >> a[i]; sum += a[i]; if (mx < a[i]) { mx = a[i]; } } // sort(a.rbegin(), a.rend()); int l = max(0ll, sum / (n + k) - 1); int r = mx; while (r != l + 1) { int m = (l + r) / 2; if (can(m)) { r = m; } else { l = m; } } cout << r << '\n'; finish; }
replace
113
114
113
114
0
p02598
C++
Runtime Error
#include <algorithm> #include <cassert> #include <cmath> #include <cstring> #include <deque> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <utility> #include <vector> using namespace std; typedef long long ll; ll mod = 1e9 + 7; #define rep(i, n) for (int i = 0; i < (n); ++i) int main() { ll n, k; cin >> n >> k; vector<ll> a(n); rep(i, n) cin >> a[i]; ll l = -1; ll r = 1e9 + 1; while (r - l > 1) { ll m = (l + r) / 2; ll num = 0; rep(i, n) { num += (a[i] - 1LL) / m; } if (num > k) { l = m; } else { r = m; } } cout << r << endl; return 0; }
#include <algorithm> #include <cassert> #include <cmath> #include <cstring> #include <deque> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <utility> #include <vector> using namespace std; typedef long long ll; ll mod = 1e9 + 7; #define rep(i, n) for (int i = 0; i < (n); ++i) int main() { ll n, k; cin >> n >> k; vector<ll> a(n); rep(i, n) cin >> a[i]; ll l = 0; ll r = 1e9; while (r - l > 1) { ll m = (l + r) / 2; ll num = 0; rep(i, n) { num += (a[i] - 1LL) / m; } if (num > k) { l = m; } else { r = m; } } cout << r << endl; return 0; }
replace
24
26
24
26
0
p02598
C++
Runtime Error
// Abhinav ---IIIT_A #include <bits/stdc++.h> using namespace std; #define int long long #define ld long double #define pb push_back #define ff first #define ss second #define f(i, x, n) for (int i = x; i < (int)n; ++i) #define vpii vector<pair<int, int>> #define vi vector<int> #define mpii map<pair<int, int>, int> #define mpivpii map<int, vector<pair<int, int>>> #define pii pair<int, int> #define all(x) x.begin(), x.end() #define sz(x) x.size() #define mpi map<int, int> #define vvi vector<vector<int>> #define vvvi vector<vvi> ld pie = 3.141592653589; int mod = 1e9 + 7; bool Compare(pair<int, int> a, pair<int, int> b) { int l1 = a.ss - a.ff + 1; int l2 = b.ss - b.ff + 1; if (l1 != l2) return l1 > l2; return a.ff > b.ff; } std::priority_queue<pii, std::vector<pii>, std::function<bool(pii, pii)>> pq(Compare); int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int ans = -1; int n, k; cin >> n >> k; int a[n]; f(i, 0, n) cin >> a[i]; int l = 0, h = 1e10; while (l <= h) { int mid = (l + h) / 2; int copy[n]; f(i, 0, n) copy[i] = a[i]; int cuts = 0; f(i, 0, n) { if (copy[i] > mid) { cuts += (((copy[i] + mid - 1) / mid) - 1); } } if (cuts <= k) { ans = mid; h = mid - 1; } else l = mid + 1; } cout << ans; return 0; } // check for overflows dummy !!!
// Abhinav ---IIIT_A #include <bits/stdc++.h> using namespace std; #define int long long #define ld long double #define pb push_back #define ff first #define ss second #define f(i, x, n) for (int i = x; i < (int)n; ++i) #define vpii vector<pair<int, int>> #define vi vector<int> #define mpii map<pair<int, int>, int> #define mpivpii map<int, vector<pair<int, int>>> #define pii pair<int, int> #define all(x) x.begin(), x.end() #define sz(x) x.size() #define mpi map<int, int> #define vvi vector<vector<int>> #define vvvi vector<vvi> ld pie = 3.141592653589; int mod = 1e9 + 7; bool Compare(pair<int, int> a, pair<int, int> b) { int l1 = a.ss - a.ff + 1; int l2 = b.ss - b.ff + 1; if (l1 != l2) return l1 > l2; return a.ff > b.ff; } std::priority_queue<pii, std::vector<pii>, std::function<bool(pii, pii)>> pq(Compare); int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int ans = -1; int n, k; cin >> n >> k; int a[n]; f(i, 0, n) cin >> a[i]; int l = 1, h = 1e10; while (l <= h) { int mid = (l + h) / 2; int copy[n]; f(i, 0, n) copy[i] = a[i]; int cuts = 0; f(i, 0, n) { if (copy[i] > mid) { cuts += (((copy[i] + mid - 1) / mid) - 1); } } if (cuts <= k) { ans = mid; h = mid - 1; } else l = mid + 1; } cout << ans; return 0; } // check for overflows dummy !!!
replace
44
45
44
45
-11
p02598
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; typedef long long ll; typedef pair<int, int> ii; typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; // *st.find_by_order(index), 0-based // order_of_key(e) ll eval(ll x, vector<ll> &A) { ll ret = 0; for (auto a : A) ret += (a + x - 1) / x - 1; return ret; } int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); int N, K; cin >> N >> K; vector<ll> A(N); for (int i = 0; i < N; i++) cin >> A[i]; ll low = 0, high = 1e9 + 7; while (low < high) { int mid = (low + high) / 2; if (eval(mid, A) <= K) high = mid; else low = mid + 1; } cout << min(*max_element(A.begin(), A.end()), high) << "\n"; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; typedef long long ll; typedef pair<int, int> ii; typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; // *st.find_by_order(index), 0-based // order_of_key(e) ll eval(ll x, vector<ll> &A) { ll ret = 0; for (auto a : A) ret += (a + x - 1) / x - 1; return ret; } int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); int N, K; cin >> N >> K; vector<ll> A(N); for (int i = 0; i < N; i++) cin >> A[i]; ll low = 1, high = 1e9 + 7; while (low < high) { int mid = (low + high) / 2; if (eval(mid, A) <= K) high = mid; else low = mid + 1; } cout << min(*max_element(A.begin(), A.end()), high) << "\n"; return 0; }
replace
29
30
29
30
0
p02598
C++
Runtime Error
#include <iostream> #include <vector> using namespace std; using ll = int64_t; bool ok(const vector<ll> &A, ll k, ll allowed) { ll cost = 0; for (ll i = 0; i < A.size(); i++) { // smallest K s.t. allowed*K >= A[i] // cost += K-1 // 1..allowed -> 0 // allowed+1..2*allowed -> 1 cost += (A[i] - 1) / allowed; } return cost <= k; } int main() { ll n, k; cin >> n >> k; vector<ll> A(n, 0); for (ll i = 0; i < n; i++) { cin >> A[i]; } ll lo = 0; ll hi = 1e9; while (lo < hi) { ll mid = (lo + hi) / 2; // cerr << " mid=" << mid << " ok=" << ok(A, k, mid) << endl; if (ok(A, k, mid)) { hi = mid; } else { lo = mid + 1; } } cout << lo << endl; }
#include <iostream> #include <vector> using namespace std; using ll = int64_t; bool ok(const vector<ll> &A, ll k, ll allowed) { ll cost = 0; for (ll i = 0; i < A.size(); i++) { // smallest K s.t. allowed*K >= A[i] // cost += K-1 // 1..allowed -> 0 // allowed+1..2*allowed -> 1 cost += (A[i] - 1) / allowed; } return cost <= k; } int main() { ll n, k; cin >> n >> k; vector<ll> A(n, 0); for (ll i = 0; i < n; i++) { cin >> A[i]; } ll lo = 1; ll hi = 1e9; while (lo < hi) { ll mid = (lo + hi) / 2; // cerr << " mid=" << mid << " ok=" << ok(A, k, mid) << endl; if (ok(A, k, mid)) { hi = mid; } else { lo = mid + 1; } } cout << lo << endl; }
replace
25
26
25
26
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define pb push_back #define mp make_pair #define all(a) (a).begin(), (a).end() #define debug_array(a, n) \ for (ll bccc = (0); bccc < (n); bccc++) \ cout << a[bccc] << " " \ << "\n" #define debug_vector(a) \ for (ll bccc = (0); bccc < (a.size()); bccc++) \ cout << a[bccc] << " " \ << "\n" #define F first #define S second #define debug_set(s) \ for (auto p : s) \ cout << p << " " #define debug_map(m) \ for (auto p : m) \ cout << p.F << " " << p.S << "\n" #define trace(x) cerr << #x << ": " << x << " " << endl; typedef long long ll; using namespace __gnu_pbds; typedef tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset; /* ll t = 0; ordered_multiset me; ... me.insert({x, t++}); me.erase(me.lower_bound({x, 0})); cout << me.order_of_key({x, 0}) << "\n"; /////////// t is insertion time */ // #pragma GCC optimize("Ofast") // works very well #define ordered_set \ tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); typedef long double lld; lld pi = 3.14159265358; ll powr(ll a, ll b) { ll c = 1; ll kjk; for (kjk = 0; kjk < b; kjk++) c *= a; return c; } ll hell = 1000000007; // ll hell=998244353 ; ll power(ll x, ll y, ll p) { ll res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // to generate random number , use rng() ... eg cout<<rng(); bool check(ll a[], ll n, ll mid, ll k) { ll ans = 0; for (int i = 0; i < n; i++) ans += max(0LL, ((a[i] + mid - 1) / mid - 1)); return ans <= k; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll n, k, i; cin >> n >> k; ll a[n]; for (i = 0; i < n; i++) cin >> a[i]; ll lo = 0; ll hi = hell; ll mid, ans; while (lo <= hi) { mid = ((hi + lo) / 2); if (check(a, n, mid, k)) { ans = mid; hi = mid - 1; } else lo = mid + 1; } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define pb push_back #define mp make_pair #define all(a) (a).begin(), (a).end() #define debug_array(a, n) \ for (ll bccc = (0); bccc < (n); bccc++) \ cout << a[bccc] << " " \ << "\n" #define debug_vector(a) \ for (ll bccc = (0); bccc < (a.size()); bccc++) \ cout << a[bccc] << " " \ << "\n" #define F first #define S second #define debug_set(s) \ for (auto p : s) \ cout << p << " " #define debug_map(m) \ for (auto p : m) \ cout << p.F << " " << p.S << "\n" #define trace(x) cerr << #x << ": " << x << " " << endl; typedef long long ll; using namespace __gnu_pbds; typedef tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset; /* ll t = 0; ordered_multiset me; ... me.insert({x, t++}); me.erase(me.lower_bound({x, 0})); cout << me.order_of_key({x, 0}) << "\n"; /////////// t is insertion time */ // #pragma GCC optimize("Ofast") // works very well #define ordered_set \ tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); typedef long double lld; lld pi = 3.14159265358; ll powr(ll a, ll b) { ll c = 1; ll kjk; for (kjk = 0; kjk < b; kjk++) c *= a; return c; } ll hell = 1000000007; // ll hell=998244353 ; ll power(ll x, ll y, ll p) { ll res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // to generate random number , use rng() ... eg cout<<rng(); bool check(ll a[], ll n, ll mid, ll k) { ll ans = 0; for (int i = 0; i < n; i++) ans += max(0LL, ((a[i] + mid - 1) / mid - 1)); return ans <= k; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll n, k, i; cin >> n >> k; ll a[n]; for (i = 0; i < n; i++) cin >> a[i]; ll lo = 1; ll hi = hell; ll mid, ans; while (lo <= hi) { mid = ((hi + lo) / 2); if (check(a, n, mid, k)) { ans = mid; hi = mid - 1; } else lo = mid + 1; } cout << ans; return 0; }
replace
83
84
83
84
0
p02598
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <iostream> #include <vector> #define NMAX 200002 using namespace std; vector<int> v; int N, K, M = 0, m = 0, ans = 0; bool able(int a) { int cou = 0; for (auto &&i : v) { int b = i; if (b <= a) break; while (true) { if (b > a) { b = b - a; cou++; } else { break; } } } // cout << a << ":" << cou << endl; if (cou > K) return false; else return true; } int main() { cin >> N >> K; for (int i = 0; i < N; ++i) { int a; cin >> a; v.push_back(a); M = max(M, a); } sort(v.begin(), v.end(), greater<int>()); while (M - m > 1) { int k = (M + m) / 2; if (able(k)) M = k; else m = k; } cout << M << endl; }
#include <algorithm> #include <cmath> #include <iostream> #include <vector> #define NMAX 200002 using namespace std; vector<int> v; int N, K, M = 0, m = 0, ans = 0; bool able(int a) { int cou = 0; for (auto &&i : v) { int b = i; if (b <= a) break; if (b > a) { cou = cou + b / a - (b % a == 0); } } // cout << a << ":" << cou << endl; if (cou > K) return false; else return true; } int main() { cin >> N >> K; for (int i = 0; i < N; ++i) { int a; cin >> a; v.push_back(a); M = max(M, a); } sort(v.begin(), v.end(), greater<int>()); while (M - m > 1) { int k = (M + m) / 2; if (able(k)) M = k; else m = k; } cout << M << endl; }
replace
14
21
14
16
TLE
p02598
C++
Runtime Error
/* _ __ _ _____ _____ _____ ___ _ _| |__ ___ / _|_ __ ___ __ _| | __ |___ |___ |___ | / __| | | | '_ \ / _ \ |_| '__/ _ \/ _` | |/ / / / / / / / | (__| |_| | |_) | __/ _| | | __/ (_| | < / / / / / / \___|\__,_|_.__/ \___|_| |_| \___|\__,_|_|\_\ /_/ /_/ /_/ */ #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define CS custom_hash #define vi vector #define loop(i, a, b) for (ll i = a; i < b; i++) #define For(i, n) for (int i = 0; i < (ll)n; i++) #define Rev(i, n) for (int i = n - 1; i >= 0; i--) #define Rep(i, n) for (int i = 1; i <= n; ++i) #define F first #define S second #define pb push_back #define em emplace_back #define all(v) (v).begin(), (v).end() #define mems(x, y) memset(x, y, sizeof(x)) #define sz(x) (int)(x).size() #define mp(a, b) make_pair(a, b) #define po(n) cout << n << "\n " #define ar array #define endl "\n" #define PI acos(-1) #define umap unordered_map #define gmap gp_hash_table 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...); } template <typename T, typename V> void mdebug(map<T, vi<V>> m) { for (auto x : m) { cerr << x.F << " : [ "; for (auto c : x.S) cerr << c << " "; cerr << "]" << endl; } } #define debug(x...) \ cerr << "[" << #x << "] = ["; \ _print(x) // #ifndef ONLINE_JUDGE // #ifndef LOCAL #define debug(x...) \ cerr << "[" << #x << "] = ["; \ _print(x) // #else // #define debug(x...) // #endif // #pragma GCC optimize "trapv" template <class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // credits for below template:William Lin(tmwilliamlin168) #define F_OR(i, a, b, s) \ for (int i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s)) #define F_OR1(e) F_OR(i, 0, e, 1) #define F_OR2(i, e) F_OR(i, 0, e, 1) #define F_OR3(i, b, e) F_OR(i, b, e, 1) #define F_OR4(i, b, e, s) F_OR(i, b, e, s) #define GET5(a, b, c, d, e, ...) e #define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1) #define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__) #define EACH(x, a) for (auto &x : a) template <class A> void read(vi<A> &v); template <class A, size_t S> void read(ar<A, S> &a); template <class T> void read(T &x) { cin >> x; } void read(double &d) { string t; read(t); d = stod(t); } void read(long double &d) { string t; read(t); d = stold(t); } template <class H, class... T> void read(H &h, T &...t) { read(h); read(t...); } template <class A> void read(vi<A> &x) { EACH(a, x) read(a); } template <class A, size_t S> void read(array<A, S> &x) { EACH(a, x) read(a); } string to_string(char c) { return string(1, c); } string to_string(bool b) { return b ? "true" : "false"; } string to_string(const char *s) { return string(s); } string to_string(string s) { return s; } string to_string(vi<bool> v) { string res; FOR(sz(v)) res += char('0' + v[i]); return res; } template <size_t S> string to_string(bitset<S> b) { string res; FOR(S) res += char('0' + b[i]); return res; } template <class T> string to_string(T v) { bool f = 1; string res; EACH(x, v) { if (!f) res += ' '; f = 0; res += to_string(x); } return res; } template <class A> void pff(A x) { cout << to_string(x); } template <class H, class... T> void pff(const H &h, const T &...t) { pff(h); pff(t...); } void print() { pff("\n"); } template <class H, class... T> void print(const H &h, const T &...t) { pff(h); if (sizeof...(t)) pff(' '); print(t...); } struct PH { size_t operator()(const pair<int, int> &x) const { size_t ans = 0; for (int i = 0; i < x.first; i++) ans += x.second; return ans; } }; 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); } }; // void DBG() { // cerr << "]" << endl; // } // template<class H, class... T> void DBG(H h, T... t) { // cerr << to_string(h); // if(sizeof...(t)) // cerr << ", "; // DBG(t...); // } // // #ifdef _DEBUG // #define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << // "]: [", DBG(__VA_ARGS__) // // #else // // #define dbg(...) 0 // // #endif template <class T> void offset(ll o, T &x) { x += o; } template <class T> void offset(ll o, vi<T> &x) { EACH(a, x) offset(o, a); } template <class T, size_t S> void offset(ll o, ar<T, S> &x) { EACH(a, x) offset(o, a); } #define pf(n) return print(n) #define int ll long const M = 1e9 + 7; const ll INF = 1e18; // order_of_key (k) : Number of items strictly smaller than k . // find_by_order(k) : K-th element in a set (counting from zero). // Syntax to create a min heap for priority queue // priority_queue <T, vector<T>, greater<T>>pq ; // make sure to clear the adjacency list for every test case // check mxN size const long mxN = 1e5 + 2; vi<int> a; int n, k; bool ok(int x) { int ans = 0; EACH(c, a) ans += (c - 1) / x; return ans <= k ? 1 : 0; } void solve() { read(n, k); a = vi<int>(n); read(a); int lb = 0, rb = 1e9; while (lb < rb) { int mb = (lb + rb) / 2; if (!ok(mb)) lb = mb + 1; else rb = mb; } print(lb); } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); // cout << setprecision(20) << fixed ; int T = 1; // read(T); FOR(_, T) { // pff("Case #", _+1, ": "); solve(); } return 0; }
/* _ __ _ _____ _____ _____ ___ _ _| |__ ___ / _|_ __ ___ __ _| | __ |___ |___ |___ | / __| | | | '_ \ / _ \ |_| '__/ _ \/ _` | |/ / / / / / / / | (__| |_| | |_) | __/ _| | | __/ (_| | < / / / / / / \___|\__,_|_.__/ \___|_| |_| \___|\__,_|_|\_\ /_/ /_/ /_/ */ #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define CS custom_hash #define vi vector #define loop(i, a, b) for (ll i = a; i < b; i++) #define For(i, n) for (int i = 0; i < (ll)n; i++) #define Rev(i, n) for (int i = n - 1; i >= 0; i--) #define Rep(i, n) for (int i = 1; i <= n; ++i) #define F first #define S second #define pb push_back #define em emplace_back #define all(v) (v).begin(), (v).end() #define mems(x, y) memset(x, y, sizeof(x)) #define sz(x) (int)(x).size() #define mp(a, b) make_pair(a, b) #define po(n) cout << n << "\n " #define ar array #define endl "\n" #define PI acos(-1) #define umap unordered_map #define gmap gp_hash_table 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...); } template <typename T, typename V> void mdebug(map<T, vi<V>> m) { for (auto x : m) { cerr << x.F << " : [ "; for (auto c : x.S) cerr << c << " "; cerr << "]" << endl; } } #define debug(x...) \ cerr << "[" << #x << "] = ["; \ _print(x) // #ifndef ONLINE_JUDGE // #ifndef LOCAL #define debug(x...) \ cerr << "[" << #x << "] = ["; \ _print(x) // #else // #define debug(x...) // #endif // #pragma GCC optimize "trapv" template <class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // credits for below template:William Lin(tmwilliamlin168) #define F_OR(i, a, b, s) \ for (int i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s)) #define F_OR1(e) F_OR(i, 0, e, 1) #define F_OR2(i, e) F_OR(i, 0, e, 1) #define F_OR3(i, b, e) F_OR(i, b, e, 1) #define F_OR4(i, b, e, s) F_OR(i, b, e, s) #define GET5(a, b, c, d, e, ...) e #define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1) #define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__) #define EACH(x, a) for (auto &x : a) template <class A> void read(vi<A> &v); template <class A, size_t S> void read(ar<A, S> &a); template <class T> void read(T &x) { cin >> x; } void read(double &d) { string t; read(t); d = stod(t); } void read(long double &d) { string t; read(t); d = stold(t); } template <class H, class... T> void read(H &h, T &...t) { read(h); read(t...); } template <class A> void read(vi<A> &x) { EACH(a, x) read(a); } template <class A, size_t S> void read(array<A, S> &x) { EACH(a, x) read(a); } string to_string(char c) { return string(1, c); } string to_string(bool b) { return b ? "true" : "false"; } string to_string(const char *s) { return string(s); } string to_string(string s) { return s; } string to_string(vi<bool> v) { string res; FOR(sz(v)) res += char('0' + v[i]); return res; } template <size_t S> string to_string(bitset<S> b) { string res; FOR(S) res += char('0' + b[i]); return res; } template <class T> string to_string(T v) { bool f = 1; string res; EACH(x, v) { if (!f) res += ' '; f = 0; res += to_string(x); } return res; } template <class A> void pff(A x) { cout << to_string(x); } template <class H, class... T> void pff(const H &h, const T &...t) { pff(h); pff(t...); } void print() { pff("\n"); } template <class H, class... T> void print(const H &h, const T &...t) { pff(h); if (sizeof...(t)) pff(' '); print(t...); } struct PH { size_t operator()(const pair<int, int> &x) const { size_t ans = 0; for (int i = 0; i < x.first; i++) ans += x.second; return ans; } }; 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); } }; // void DBG() { // cerr << "]" << endl; // } // template<class H, class... T> void DBG(H h, T... t) { // cerr << to_string(h); // if(sizeof...(t)) // cerr << ", "; // DBG(t...); // } // // #ifdef _DEBUG // #define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << // "]: [", DBG(__VA_ARGS__) // // #else // // #define dbg(...) 0 // // #endif template <class T> void offset(ll o, T &x) { x += o; } template <class T> void offset(ll o, vi<T> &x) { EACH(a, x) offset(o, a); } template <class T, size_t S> void offset(ll o, ar<T, S> &x) { EACH(a, x) offset(o, a); } #define pf(n) return print(n) #define int ll long const M = 1e9 + 7; const ll INF = 1e18; // order_of_key (k) : Number of items strictly smaller than k . // find_by_order(k) : K-th element in a set (counting from zero). // Syntax to create a min heap for priority queue // priority_queue <T, vector<T>, greater<T>>pq ; // make sure to clear the adjacency list for every test case // check mxN size const long mxN = 1e5 + 2; vi<int> a; int n, k; bool ok(int x) { int ans = 0; EACH(c, a) ans += (c - 1) / x; return ans <= k ? 1 : 0; } void solve() { read(n, k); a = vi<int>(n); read(a); int lb = 1, rb = 1e9; while (lb < rb) { int mb = (lb + rb) / 2; if (!ok(mb)) lb = mb + 1; else rb = mb; } print(lb); } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); // cout << setprecision(20) << fixed ; int T = 1; // read(T); FOR(_, T) { // pff("Case #", _+1, ": "); solve(); } return 0; }
replace
241
242
241
242
0
p02598
C++
Runtime Error
// include //------------------------------------------ #include <algorithm> #include <bitset> #include <deque> #include <functional> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #include <complex> #include <numeric> #include <utility> #include <iomanip> #include <iostream> #include <sstream> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> // namespace using namespace std; // type alias using ll = long long; using ull = unsigned long long; using comp = complex<double>; // constant static const ll MOD = 1000000007LL; static const double PI = 3.14159265358979323846; // conversion inline ll toint(string s) { ll v; istringstream sin(s); sin >> v; return v; } template <class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); } // print #define RET(x) return cout << x << endl, 0; // for loop #define REP(i, a, b) for ((i) = (ll)(a); (i) < (ll)(b); (i)++) #define REPD(i, a, b) for (ll i = (ll)(a); (i) < (ll)(b); (i)++) #define REPI(v, vs) for (auto &v : vs) // debug #define DUMP(x) cerr << #x << " = " << (x) << endl #define DEBUG(x) \ cerr << #x << " = " << (x) << " (l" << __LINE__ << ")" \ << " " << __FILE__ << endl #define MAX_VALUE 9223372036854775807 int solve() { ll n, k; cin >> n >> k; vector<ll> as(n); REPD(i, 0, n) cin >> as[i]; ll low = 0, high = 1000000000, mid = (low + high) / 2; while (high - low >= 2) { ll curr_k = 0; REPD(i, 0, n) { curr_k += (as[i] - 1) / mid; } if (curr_k <= k) { high = mid; } else { low = mid; } mid = (low + high) / 2; } { ll curr_k = 0; REPD(i, 0, n) { curr_k += (as[i] - 1) / low; } if (curr_k <= k) { RET(low); } } RET(high); return 0; } // main function int main() { cin.tie(0); ios::sync_with_stdio(false); solve(); return 0; }
// include //------------------------------------------ #include <algorithm> #include <bitset> #include <deque> #include <functional> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #include <complex> #include <numeric> #include <utility> #include <iomanip> #include <iostream> #include <sstream> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> // namespace using namespace std; // type alias using ll = long long; using ull = unsigned long long; using comp = complex<double>; // constant static const ll MOD = 1000000007LL; static const double PI = 3.14159265358979323846; // conversion inline ll toint(string s) { ll v; istringstream sin(s); sin >> v; return v; } template <class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); } // print #define RET(x) return cout << x << endl, 0; // for loop #define REP(i, a, b) for ((i) = (ll)(a); (i) < (ll)(b); (i)++) #define REPD(i, a, b) for (ll i = (ll)(a); (i) < (ll)(b); (i)++) #define REPI(v, vs) for (auto &v : vs) // debug #define DUMP(x) cerr << #x << " = " << (x) << endl #define DEBUG(x) \ cerr << #x << " = " << (x) << " (l" << __LINE__ << ")" \ << " " << __FILE__ << endl #define MAX_VALUE 9223372036854775807 int solve() { ll n, k; cin >> n >> k; vector<ll> as(n); REPD(i, 0, n) cin >> as[i]; ll low = 1, high = 1000000000, mid = (low + high) / 2; while (high - low >= 2) { ll curr_k = 0; REPD(i, 0, n) { curr_k += (as[i] - 1) / mid; } if (curr_k <= k) { high = mid; } else { low = mid; } mid = (low + high) / 2; } { ll curr_k = 0; REPD(i, 0, n) { curr_k += (as[i] - 1) / low; } if (curr_k <= k) { RET(low); } } RET(high); return 0; } // main function int main() { cin.tie(0); ios::sync_with_stdio(false); solve(); return 0; }
replace
77
78
77
78
0
p02598
C++
Runtime Error
#include <algorithm> #include <iostream> #include <map> #include <stdio.h> #include <string.h> #include <vector> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; 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; } bool f(vector<int> &a, int target, int k) { int t = 0, i = 0; while (t <= k && i != a.size()) { t += (a[i] - 1) / target; ++i; } if (t > k) return false; else return true; } int main() { int n, k; cin >> n >> k; vector<int> a(n); rep(i, n) cin >> a[i]; sort(a.rbegin(), a.rend()); int maxi = a[0]; int mini = 0; while (1) { int now = (maxi + mini) / 2; bool ret = f(a, now, k); if (ret) maxi = now; else mini = now; if (maxi == mini + 1) break; } cout << maxi << endl; return 0; }
#include <algorithm> #include <iostream> #include <map> #include <stdio.h> #include <string.h> #include <vector> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; 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; } bool f(vector<int> &a, int target, int k) { int t = 0, i = 0; while (t <= k && i != a.size()) { t += (a[i] - 1) / target; ++i; } if (t > k) return false; else return true; } int main() { int n, k; cin >> n >> k; vector<int> a(n); rep(i, n) cin >> a[i]; sort(a.rbegin(), a.rend()); int maxi = a[0]; int mini = 0; while (1) { int now = (maxi + mini) / 2; if (now == 0) break; bool ret = f(a, now, k); if (ret) maxi = now; else mini = now; if (maxi == mini + 1) break; } cout << maxi << endl; return 0; }
insert
48
48
48
50
0
p02598
C++
Runtime Error
#ifndef INCLUDEHEADER_MY_TEMPLATE #define INCLUDEHEADER_MY_TEMPLATE #ifndef _GLIBCXX_NO_ASSERT #include <cassert> #endif #include <cctype> #include <cerrno> #include <cfloat> #include <ciso646> #include <climits> #include <clocale> #include <cmath> #include <csetjmp> #include <csignal> #include <cstdarg> #include <cstddef> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #if __cplusplus >= 201103L #include <ccomplex> #include <cfenv> #include <cinttypes> #include <cstdalign> #include <cstdbool> #include <cstdint> #include <ctgmath> #include <cwchar> #include <cwctype> #endif #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #if __cplusplus >= 201103L #include <array> #include <atomic> #include <chrono> #include <condition_variable> #include <forward_list> #include <future> #include <initializer_list> #include <mutex> #include <random> #include <ratio> #include <regex> #include <scoped_allocator> #include <system_error> #include <thread> #include <tuple> #include <type_traits> #include <typeindex> #include <unordered_map> #include <unordered_set> #endif #define y0 qvya13579 #define y1 qvyb24680 #define j0 qvja13579 #define j1 qvjb24680 #define next qvne13579xt #define prev qvpr13579ev #define INF 1000000007 #define MOD 1000000007 #define endl "\n" #define PI acos(-1.0) #if __cplusplus < 201103L #define stoi(argument_string) atoi((argument_string).c_str()) #define stoll(argument_string) atoll((argument_string).c_str()) #endif #define REP(i, n) for (int i = 0; i < (int)(n); ++i) #define REP_R(i, n) for (int i = ((int)(n)-1); i >= 0; --i) #define FOR(i, m, n) for (int i = ((int)(m)); i < (int)(n); ++i) #define FOR_R(i, m, n) for (int i = ((int)(m)-1); i >= (int)(n); --i) #define ALL(v) (v).begin(), (v).end() #define RALL(v) (v).rbegin(), (v).rend() #define SIZ(x) ((int)(x).size()) #define CIN(x) cin >> (x) #define CIN2(x, y) cin >> (x) >> (y) #define CIN3(x, y, z) cin >> (x) >> (y) >> (z) #define CIN4(x, y, z, w) cin >> (x) >> (y) >> (z) >> (w) #define CIN5(x, y, z, w, u) cin >> (x) >> (y) >> (z) >> (w) >> (u) #define SCAND(x) scanf("%d", &(x)) #define SCAND2(x, y) scanf("%d%d", &(x), &(y)) #define SCAND3(x, y, z) scanf("%d%d%d", &(x), &(y), &(z)) #define SCAND4(x, y, z, w) scanf("%d%d%d%d", &(x), &(y), &(z), &(w)) #define SCAND5(x, y, z, w, u) scanf("%d%d%d%d%d", &(x), &(y), &(z), &(w), &(u)) #define SCANLLD(x) scanf("%lld", &(x)) #define SCANLLD2(x, y) scanf("%lld%lld", &(x), &(y)) #define SCANLLD3(x, y, z) scanf("%lld%lld%lld", &(x), &(y), &(z)) #define SCANLLD4(x, y, z, w) scanf("%lld%lld%lld%lld", &(x), &(y), &(z), &(w)) #define SCANLLD5(x, y, z, w, u) \ scanf("%lld%lld%lld%lld%lld", &(x), &(y), &(z), &(w), &(u)) #define PRINTD(x) printf("%d\n", (x)) #define PRINTLLD(x) printf("%lld\n", (x)) #define DEBUG(argument) cerr << (#argument) << " : " << (argument) << "\n" typedef long long lli; typedef unsigned long long ulli; using namespace std; #endif // header int ctoi(char c) { if (c >= '0' and c <= '9') { return (int)(c - '0'); } return -1; } int alphabet_pos(char c) { if (c >= 'a' and c <= 'z') { return (int)(c - 'a'); } return -1; } int alphabet_pos_capital(char c) { if (c >= 'A' and c <= 'Z') { return (int)(c - 'A'); } return -1; } vector<string> split(string str, char ch) { int first = 0; int last = str.find_first_of(ch); if (last == ((int)string::npos)) { last = SIZ(str); } vector<string> result; while (first < SIZ(str)) { string Ssubstr(str, first, last - first); result.push_back(Ssubstr); first = last + 1; last = str.find_first_of(ch, first); if (last == ((int)string::npos)) { last = SIZ(str); } } return result; } int gcd(int a, int b) // assuming a,b >= 1 { if (a < b) { swap(a, b); } if (b == 0) { return a; } if (a % b == 0) { return b; } return gcd(b, a % b); } long long gcd(long long a, long long b) // assuming a,b >= 1 { if (a < b) { swap(a, b); } if (b == 0LL) { return a; } if (a % b == 0) { return b; } return gcd(b, a % b); } int lcm(int a, int b) // assuming a,b >= 1 { return a * b / gcd(a, b); } long long lcm(long long a, long long b) // assuming a,b >= 1 { return a * b / gcd(a, b); } long long pow_fast(long long x, long long n_power, long long modulus) { if (n_power == 0) { return 1; } if (n_power % 2 == 0) { return pow_fast(x * x % modulus, n_power / 2, modulus); } return x * pow_fast(x, n_power - 1, modulus) % modulus; } struct CombinationTable { vector<vector<long long>> val; CombinationTable(int size) : val(size + 1, vector<long long>(size + 1)) // constructor { for (int i = 0; i <= size; ++i) // note that 0 <= i <= size { for (int j = 0; j <= i; ++j) { if (j == 0 or j == i) { val[i][j] = 1LL; } else { val[i][j] = val[i - 1][j - 1] + val[i - 1][j]; } } } } }; void print_vector(vector<int> h, bool verbose = true) { int L = h.size(); for (int i = 0; i < L; ++i) { if (verbose) { printf("%d", h[i]); } else { cerr << h[i]; } if (i != L - 1) { if (verbose) { printf(" "); } else { cerr << " "; } } else { if (verbose) { printf("\n"); } else { cerr << "\n"; } } } } void print_vector(vector<long long> h, bool verbose = true) { int L = h.size(); for (int i = 0; i < L; ++i) { if (verbose) { printf("%lld", h[i]); } else { cerr << h[i]; } if (i != L - 1) { if (verbose) { printf(" "); } else { cerr << " "; } } else { if (verbose) { printf("\n"); } else { cerr << "\n"; } } } } void print_matrix2D(vector<vector<int>> h, bool verbose = true) { int Ly = h.size(); for (int i = 0; i < Ly; ++i) { int Lx = h[i].size(); for (int j = 0; j < Lx; ++j) { if (verbose) { printf("%d", h[i][j]); } else { cerr << h[i][j]; } if (j != Lx - 1) { if (verbose) { printf(" "); } else { cerr << " "; } } else { if (verbose) { printf("\n"); } else { cerr << "\n"; } } } } } void print_matrix2D(vector<vector<long long>> h, bool verbose = true) { int Ly = h.size(); for (int i = 0; i < Ly; ++i) { int Lx = h[i].size(); for (int j = 0; j < Lx; ++j) { if (verbose) { printf("%lld", h[i][j]); } else { cerr << h[i][j]; } if (j != Lx - 1) { if (verbose) { printf(" "); } else { cerr << " "; } } else { if (verbose) { printf("\n"); } else { cerr << "\n"; } } } } } void print_matrix2D(vector<string> h, bool verbose = true) { int Ly = h.size(); for (int i = 0; i < Ly; ++i) { int Lx = h[i].size(); for (int j = 0; j < Lx; ++j) { if (verbose) { printf("%c", h[i][j]); } else { cerr << h[i][j]; } } if (verbose) { printf("\n"); } else { cerr << "\n"; } } } void print_binary(int val, int num_digit = 31, bool verbose = false) { for (int k = num_digit - 1; k >= 0; --k) { if (verbose) { printf("%d", (val >> k) & 1); } else { cerr << ((val >> k) & 1); } } if (verbose) { printf("\n"); } else { cerr << "\n"; } } void print_binary(long long val, int num_digit = 63, bool verbose = false) { for (int k = num_digit - 1; k >= 0; --k) { if (verbose) { printf("%lld", ((val >> k) & 1)); } else { cerr << ((val >> k) & 1); } } if (verbose) { printf("\n"); } else { cerr << "\n"; } } void print_all() { cout << endl; } void print_all_nobreak() { return; } template <class Head, class... Tail> void print_all_nobreak(Head head, Tail... tail) { cout << head; if (sizeof...(tail) != 0) { cout << " "; } print_all_nobreak(forward<Tail>(tail)...); } template <class Head, class... Tail> void print_all(Head head, Tail... tail) { cout << head; if (sizeof...(tail) != 0) { cout << " "; } print_all(forward<Tail>(tail)...); } template <class T> void print_all_nobreak(vector<T> vec) { cout << "["; for (int i = 0; i < vec.size(); i++) { cout << vec[i]; if (i != ((int)vec.size() - 1)) { cout << ", "; } } cout << "]"; } template <class T> void print_all(vector<T> vec) { cout << "["; for (int i = 0; i < vec.size(); i++) { cout << vec[i]; if (i != ((int)vec.size() - 1)) { cout << ", "; } } cout << "]"; cout << endl; } template <class T> void print_all(vector<vector<T>> df) { cout << "["; for (int i = 0; i < df.size(); i++) { print_all_nobreak(df[i]); if (i != ((int)df.size() - 1)) { cout << ", "; } } cout << "]"; cout << endl; } template <class T> void print_all_nobreak(vector<vector<T>> df) { cout << "["; for (int i = 0; i < df.size(); i++) { print_all_nobreak(df[i]); if (i != ((int)df.size() - 1)) { cout << ", "; } } cout << "]"; } template <class T1, class T2> void print_all_nobreak(pair<T1, T2> p) { cout << "("; print_all_nobreak(p.first); cout << ", "; print_all_nobreak(p.second); cout << ")"; } template <class T1, class T2> void print_all(pair<T1, T2> p) { cout << "("; print_all_nobreak(p.first); cout << ", "; print_all_nobreak(p.second); cout << ")"; cout << endl; } struct UnionFind // size-based { vector<int> parent, treesize; UnionFind(int size) : parent(size), treesize(size, 1) // constructor { for (int i = 0; i < size; ++i) { parent[i] = i; } } int root(int x) { if (parent[x] == x) { return x; } return parent[x] = root(parent[x]); } void unite(int x, int y) { x = root(x); y = root(y); if (x == y) { return; } if (treesize[x] < treesize[y]) { parent[x] = y; treesize[y] += treesize[x]; } else { parent[y] = x; treesize[x] += treesize[y]; } } bool sametree(int x, int y) { return root(x) == root(y); } int gettreesize(int x) { return treesize[root(x)]; } }; template <typename Type_value> struct SegmentTree // Range Minimum Query (RMQ) { private: int n; vector<Type_value> node; Type_value identity_element_segmenttree; public: SegmentTree(vector<Type_value> v, Type_value identity_element_st) // constructor { int sz = v.size(); identity_element_segmenttree = identity_element_st; n = 1; while (n < sz) { n <<= 1; } node.resize(2 * n - 1, identity_element_segmenttree); for (int i = 0; i < sz; ++i) { node[i + n - 1] = v[i]; } for (int i = n - 2; i >= 0; --i) { node[i] = min(node[2 * i + 1], node[2 * i + 2]); } } void update(int x, Type_value val) { x += (n - 1); node[x] = val; while (x > 0) { x = (x - 1) / 2; node[x] = min(node[2 * x + 1], node[2 * x + 2]); } } Type_value getmin(int a, int b, int k = 0, int l = 0, int r = -1) // getting minimum value in [a,b) { // k : index of the referred node // [l,r) : range covered by the k-th node if (r < 0) { r = n; } if (r <= a or b <= l) { return identity_element_segmenttree; } if (a <= l and r <= b) { return node[k]; } Type_value vl = getmin(a, b, 2 * k + 1, l, (l + r) / 2); Type_value vr = getmin(a, b, 2 * k + 2, (l + r) / 2, r); return min(vl, vr); } }; template <typename Type_value> struct BinaryIndexedTree // Range Sum Query (RSQ), 0-indexed { private: int size_; vector<Type_value> data; public: BinaryIndexedTree(int sz, Type_value identity_element_binaryindexedtree = 0.0) // constructor { size_ = sz; data.resize(sz + 1, identity_element_binaryindexedtree); } Type_value sum(int i) // sum within [0,i) { if (i <= 0) { return (Type_value)0.0; } if (i > size_) { i = size_; } Type_value sm = 0.0; while (i > 0) { sm += data[i]; i -= i & -i; } return sm; } void add(int i, Type_value x) { if (i < 0 or i >= size_) { return; } ++i; while (i <= size_) { data[i] += x; i += i & -i; } } }; struct RollingHash { /* 10 primes near 1e9(for other mod(s)): { 1000000007, 1000000009, 1000000021, 1000000033, 1000000087, 1000000093, 1000000097, 1000000103, 1000000123, 1000000181 } 10 primes near 1e5(for other base(s)): {100003, 100019, 100043, 100049, 100057, 100069, 100103, 100109, 100129, 100151} */ private: vector<unsigned long long> hash; vector<unsigned long long> base_pow; unsigned long long base, modulus; const unsigned long long MODULUS_DEFAULT = (1ULL << 61) - 1; const unsigned long long MASK30 = (1ULL << 30) - 1; const unsigned long long MASK31 = (1ULL << 31) - 1; const unsigned long long BASE_MIN = 1e7; unsigned long long Modulus_2pow61m1(unsigned long long val) { val = (val & MODULUS_DEFAULT) + (val >> 61); if (MODULUS_DEFAULT < val) { val -= MODULUS_DEFAULT; } return val; } unsigned long long Multiple_2pow61m1(unsigned long long a, unsigned long long b) { unsigned long long au = a >> 31; unsigned long long ad = a & MASK31; unsigned long long bu = b >> 31; unsigned long long bd = b & MASK31; unsigned long long mid = ad * bu + au * bd; unsigned long long midu = mid >> 30; unsigned long long midd = mid & MASK30; return Modulus_2pow61m1(((au * bu) << 1) + midu + (midd << 31) + ad * bd); } void initialize(string &S) { int N = S.size(); vector<int> s(N); for (int i = 0; i < N; ++i) { s[i] = S[i]; } initialize(s); } void initialize(vector<int> &S) { hash.resize(S.size() + 1); base_pow.resize(S.size() + 1); hash[0] = 0; base_pow[0] = 1; if (modulus == MODULUS_DEFAULT) { for (int i = 1; i <= ((int)S.size()); ++i) { hash[i] = Modulus_2pow61m1(Multiple_2pow61m1(hash[i - 1], base) + S[i - 1]); base_pow[i] = Multiple_2pow61m1(base_pow[i - 1], base); } } else { for (int i = 1; i <= ((int)S.size()); ++i) { hash[i] = (hash[i - 1] * base + S[i - 1]) % modulus; base_pow[i] = (base_pow[i - 1] * base) % modulus; } } } public: RollingHash(string S = "", unsigned long long base_ = 0, unsigned long long modulus_ = 0) { if (0 < modulus_) { modulus = modulus_; } else { modulus = MODULUS_DEFAULT; } if (0 < base_) { base = base_; } else { mt19937_64 mt64(static_cast<unsigned int>(time(nullptr))); uniform_int_distribution<unsigned long long> rand_uniform( BASE_MIN, modulus - BASE_MIN); base = rand_uniform(mt64); } if (S.size() > 0) { initialize(S); } } // 0-indexed, [a, b) unsigned long long between(int a, int b) { if (modulus == MODULUS_DEFAULT) { return Modulus_2pow61m1(modulus + hash[b] - Multiple_2pow61m1(hash[a], base_pow[b - a])); } return (modulus + hash[b] - (hash[a] * base_pow[b - a]) % modulus) % modulus; } }; struct TrieTree { private: char chara_origin; int numtypes_ch; struct TrieNode { public: TrieNode **children; bool isLeaf; }; TrieNode *newNode() { TrieNode *pNode = new TrieNode; pNode->children = new TrieNode *[numtypes_ch]; pNode->isLeaf = false; for (int i = 0; i < numtypes_ch; i++) { pNode->children[i] = nullptr; } return pNode; } TrieNode *treeroot; public: TrieTree(int number_of_types_of_character = 26, char character_origin = 'a') { numtypes_ch = number_of_types_of_character; chara_origin = character_origin; treeroot = newNode(); } void insert(string key) { TrieNode *pCrawl = treeroot; for (int i = 0; i < ((int)key.size()); i++) { int index = key[i] - chara_origin; if (pCrawl->children[index] == nullptr) { pCrawl->children[index] = newNode(); } pCrawl = pCrawl->children[index]; } // mark last node as leaf pCrawl->isLeaf = true; } bool search(string key) { TrieNode *pCrawl = treeroot; for (int i = 0; i < ((int)key.size()); i++) { int index = key[i] - chara_origin; if (pCrawl->children[index] == nullptr) { return false; } pCrawl = pCrawl->children[index]; } return (pCrawl != nullptr and pCrawl->isLeaf); } }; /*------------------ the end of the template -----------------------*/ signed main(signed argc, char *argv[]) { int N, K; SCAND2(N, K); vector<int> a(N); lli left = -1; lli right = 0; REP(i, N) { SCAND(a[i]); right += a[i]; } while (left < right - 1) { lli mid = ((left + right) >> 1); lli cnt = 0; REP(i, N) { cnt += ((a[i] + mid - 1) / mid) - 1; } if (K < cnt) { left = mid; } else { right = mid; } } PRINTLLD(right); }
#ifndef INCLUDEHEADER_MY_TEMPLATE #define INCLUDEHEADER_MY_TEMPLATE #ifndef _GLIBCXX_NO_ASSERT #include <cassert> #endif #include <cctype> #include <cerrno> #include <cfloat> #include <ciso646> #include <climits> #include <clocale> #include <cmath> #include <csetjmp> #include <csignal> #include <cstdarg> #include <cstddef> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #if __cplusplus >= 201103L #include <ccomplex> #include <cfenv> #include <cinttypes> #include <cstdalign> #include <cstdbool> #include <cstdint> #include <ctgmath> #include <cwchar> #include <cwctype> #endif #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #if __cplusplus >= 201103L #include <array> #include <atomic> #include <chrono> #include <condition_variable> #include <forward_list> #include <future> #include <initializer_list> #include <mutex> #include <random> #include <ratio> #include <regex> #include <scoped_allocator> #include <system_error> #include <thread> #include <tuple> #include <type_traits> #include <typeindex> #include <unordered_map> #include <unordered_set> #endif #define y0 qvya13579 #define y1 qvyb24680 #define j0 qvja13579 #define j1 qvjb24680 #define next qvne13579xt #define prev qvpr13579ev #define INF 1000000007 #define MOD 1000000007 #define endl "\n" #define PI acos(-1.0) #if __cplusplus < 201103L #define stoi(argument_string) atoi((argument_string).c_str()) #define stoll(argument_string) atoll((argument_string).c_str()) #endif #define REP(i, n) for (int i = 0; i < (int)(n); ++i) #define REP_R(i, n) for (int i = ((int)(n)-1); i >= 0; --i) #define FOR(i, m, n) for (int i = ((int)(m)); i < (int)(n); ++i) #define FOR_R(i, m, n) for (int i = ((int)(m)-1); i >= (int)(n); --i) #define ALL(v) (v).begin(), (v).end() #define RALL(v) (v).rbegin(), (v).rend() #define SIZ(x) ((int)(x).size()) #define CIN(x) cin >> (x) #define CIN2(x, y) cin >> (x) >> (y) #define CIN3(x, y, z) cin >> (x) >> (y) >> (z) #define CIN4(x, y, z, w) cin >> (x) >> (y) >> (z) >> (w) #define CIN5(x, y, z, w, u) cin >> (x) >> (y) >> (z) >> (w) >> (u) #define SCAND(x) scanf("%d", &(x)) #define SCAND2(x, y) scanf("%d%d", &(x), &(y)) #define SCAND3(x, y, z) scanf("%d%d%d", &(x), &(y), &(z)) #define SCAND4(x, y, z, w) scanf("%d%d%d%d", &(x), &(y), &(z), &(w)) #define SCAND5(x, y, z, w, u) scanf("%d%d%d%d%d", &(x), &(y), &(z), &(w), &(u)) #define SCANLLD(x) scanf("%lld", &(x)) #define SCANLLD2(x, y) scanf("%lld%lld", &(x), &(y)) #define SCANLLD3(x, y, z) scanf("%lld%lld%lld", &(x), &(y), &(z)) #define SCANLLD4(x, y, z, w) scanf("%lld%lld%lld%lld", &(x), &(y), &(z), &(w)) #define SCANLLD5(x, y, z, w, u) \ scanf("%lld%lld%lld%lld%lld", &(x), &(y), &(z), &(w), &(u)) #define PRINTD(x) printf("%d\n", (x)) #define PRINTLLD(x) printf("%lld\n", (x)) #define DEBUG(argument) cerr << (#argument) << " : " << (argument) << "\n" typedef long long lli; typedef unsigned long long ulli; using namespace std; #endif // header int ctoi(char c) { if (c >= '0' and c <= '9') { return (int)(c - '0'); } return -1; } int alphabet_pos(char c) { if (c >= 'a' and c <= 'z') { return (int)(c - 'a'); } return -1; } int alphabet_pos_capital(char c) { if (c >= 'A' and c <= 'Z') { return (int)(c - 'A'); } return -1; } vector<string> split(string str, char ch) { int first = 0; int last = str.find_first_of(ch); if (last == ((int)string::npos)) { last = SIZ(str); } vector<string> result; while (first < SIZ(str)) { string Ssubstr(str, first, last - first); result.push_back(Ssubstr); first = last + 1; last = str.find_first_of(ch, first); if (last == ((int)string::npos)) { last = SIZ(str); } } return result; } int gcd(int a, int b) // assuming a,b >= 1 { if (a < b) { swap(a, b); } if (b == 0) { return a; } if (a % b == 0) { return b; } return gcd(b, a % b); } long long gcd(long long a, long long b) // assuming a,b >= 1 { if (a < b) { swap(a, b); } if (b == 0LL) { return a; } if (a % b == 0) { return b; } return gcd(b, a % b); } int lcm(int a, int b) // assuming a,b >= 1 { return a * b / gcd(a, b); } long long lcm(long long a, long long b) // assuming a,b >= 1 { return a * b / gcd(a, b); } long long pow_fast(long long x, long long n_power, long long modulus) { if (n_power == 0) { return 1; } if (n_power % 2 == 0) { return pow_fast(x * x % modulus, n_power / 2, modulus); } return x * pow_fast(x, n_power - 1, modulus) % modulus; } struct CombinationTable { vector<vector<long long>> val; CombinationTable(int size) : val(size + 1, vector<long long>(size + 1)) // constructor { for (int i = 0; i <= size; ++i) // note that 0 <= i <= size { for (int j = 0; j <= i; ++j) { if (j == 0 or j == i) { val[i][j] = 1LL; } else { val[i][j] = val[i - 1][j - 1] + val[i - 1][j]; } } } } }; void print_vector(vector<int> h, bool verbose = true) { int L = h.size(); for (int i = 0; i < L; ++i) { if (verbose) { printf("%d", h[i]); } else { cerr << h[i]; } if (i != L - 1) { if (verbose) { printf(" "); } else { cerr << " "; } } else { if (verbose) { printf("\n"); } else { cerr << "\n"; } } } } void print_vector(vector<long long> h, bool verbose = true) { int L = h.size(); for (int i = 0; i < L; ++i) { if (verbose) { printf("%lld", h[i]); } else { cerr << h[i]; } if (i != L - 1) { if (verbose) { printf(" "); } else { cerr << " "; } } else { if (verbose) { printf("\n"); } else { cerr << "\n"; } } } } void print_matrix2D(vector<vector<int>> h, bool verbose = true) { int Ly = h.size(); for (int i = 0; i < Ly; ++i) { int Lx = h[i].size(); for (int j = 0; j < Lx; ++j) { if (verbose) { printf("%d", h[i][j]); } else { cerr << h[i][j]; } if (j != Lx - 1) { if (verbose) { printf(" "); } else { cerr << " "; } } else { if (verbose) { printf("\n"); } else { cerr << "\n"; } } } } } void print_matrix2D(vector<vector<long long>> h, bool verbose = true) { int Ly = h.size(); for (int i = 0; i < Ly; ++i) { int Lx = h[i].size(); for (int j = 0; j < Lx; ++j) { if (verbose) { printf("%lld", h[i][j]); } else { cerr << h[i][j]; } if (j != Lx - 1) { if (verbose) { printf(" "); } else { cerr << " "; } } else { if (verbose) { printf("\n"); } else { cerr << "\n"; } } } } } void print_matrix2D(vector<string> h, bool verbose = true) { int Ly = h.size(); for (int i = 0; i < Ly; ++i) { int Lx = h[i].size(); for (int j = 0; j < Lx; ++j) { if (verbose) { printf("%c", h[i][j]); } else { cerr << h[i][j]; } } if (verbose) { printf("\n"); } else { cerr << "\n"; } } } void print_binary(int val, int num_digit = 31, bool verbose = false) { for (int k = num_digit - 1; k >= 0; --k) { if (verbose) { printf("%d", (val >> k) & 1); } else { cerr << ((val >> k) & 1); } } if (verbose) { printf("\n"); } else { cerr << "\n"; } } void print_binary(long long val, int num_digit = 63, bool verbose = false) { for (int k = num_digit - 1; k >= 0; --k) { if (verbose) { printf("%lld", ((val >> k) & 1)); } else { cerr << ((val >> k) & 1); } } if (verbose) { printf("\n"); } else { cerr << "\n"; } } void print_all() { cout << endl; } void print_all_nobreak() { return; } template <class Head, class... Tail> void print_all_nobreak(Head head, Tail... tail) { cout << head; if (sizeof...(tail) != 0) { cout << " "; } print_all_nobreak(forward<Tail>(tail)...); } template <class Head, class... Tail> void print_all(Head head, Tail... tail) { cout << head; if (sizeof...(tail) != 0) { cout << " "; } print_all(forward<Tail>(tail)...); } template <class T> void print_all_nobreak(vector<T> vec) { cout << "["; for (int i = 0; i < vec.size(); i++) { cout << vec[i]; if (i != ((int)vec.size() - 1)) { cout << ", "; } } cout << "]"; } template <class T> void print_all(vector<T> vec) { cout << "["; for (int i = 0; i < vec.size(); i++) { cout << vec[i]; if (i != ((int)vec.size() - 1)) { cout << ", "; } } cout << "]"; cout << endl; } template <class T> void print_all(vector<vector<T>> df) { cout << "["; for (int i = 0; i < df.size(); i++) { print_all_nobreak(df[i]); if (i != ((int)df.size() - 1)) { cout << ", "; } } cout << "]"; cout << endl; } template <class T> void print_all_nobreak(vector<vector<T>> df) { cout << "["; for (int i = 0; i < df.size(); i++) { print_all_nobreak(df[i]); if (i != ((int)df.size() - 1)) { cout << ", "; } } cout << "]"; } template <class T1, class T2> void print_all_nobreak(pair<T1, T2> p) { cout << "("; print_all_nobreak(p.first); cout << ", "; print_all_nobreak(p.second); cout << ")"; } template <class T1, class T2> void print_all(pair<T1, T2> p) { cout << "("; print_all_nobreak(p.first); cout << ", "; print_all_nobreak(p.second); cout << ")"; cout << endl; } struct UnionFind // size-based { vector<int> parent, treesize; UnionFind(int size) : parent(size), treesize(size, 1) // constructor { for (int i = 0; i < size; ++i) { parent[i] = i; } } int root(int x) { if (parent[x] == x) { return x; } return parent[x] = root(parent[x]); } void unite(int x, int y) { x = root(x); y = root(y); if (x == y) { return; } if (treesize[x] < treesize[y]) { parent[x] = y; treesize[y] += treesize[x]; } else { parent[y] = x; treesize[x] += treesize[y]; } } bool sametree(int x, int y) { return root(x) == root(y); } int gettreesize(int x) { return treesize[root(x)]; } }; template <typename Type_value> struct SegmentTree // Range Minimum Query (RMQ) { private: int n; vector<Type_value> node; Type_value identity_element_segmenttree; public: SegmentTree(vector<Type_value> v, Type_value identity_element_st) // constructor { int sz = v.size(); identity_element_segmenttree = identity_element_st; n = 1; while (n < sz) { n <<= 1; } node.resize(2 * n - 1, identity_element_segmenttree); for (int i = 0; i < sz; ++i) { node[i + n - 1] = v[i]; } for (int i = n - 2; i >= 0; --i) { node[i] = min(node[2 * i + 1], node[2 * i + 2]); } } void update(int x, Type_value val) { x += (n - 1); node[x] = val; while (x > 0) { x = (x - 1) / 2; node[x] = min(node[2 * x + 1], node[2 * x + 2]); } } Type_value getmin(int a, int b, int k = 0, int l = 0, int r = -1) // getting minimum value in [a,b) { // k : index of the referred node // [l,r) : range covered by the k-th node if (r < 0) { r = n; } if (r <= a or b <= l) { return identity_element_segmenttree; } if (a <= l and r <= b) { return node[k]; } Type_value vl = getmin(a, b, 2 * k + 1, l, (l + r) / 2); Type_value vr = getmin(a, b, 2 * k + 2, (l + r) / 2, r); return min(vl, vr); } }; template <typename Type_value> struct BinaryIndexedTree // Range Sum Query (RSQ), 0-indexed { private: int size_; vector<Type_value> data; public: BinaryIndexedTree(int sz, Type_value identity_element_binaryindexedtree = 0.0) // constructor { size_ = sz; data.resize(sz + 1, identity_element_binaryindexedtree); } Type_value sum(int i) // sum within [0,i) { if (i <= 0) { return (Type_value)0.0; } if (i > size_) { i = size_; } Type_value sm = 0.0; while (i > 0) { sm += data[i]; i -= i & -i; } return sm; } void add(int i, Type_value x) { if (i < 0 or i >= size_) { return; } ++i; while (i <= size_) { data[i] += x; i += i & -i; } } }; struct RollingHash { /* 10 primes near 1e9(for other mod(s)): { 1000000007, 1000000009, 1000000021, 1000000033, 1000000087, 1000000093, 1000000097, 1000000103, 1000000123, 1000000181 } 10 primes near 1e5(for other base(s)): {100003, 100019, 100043, 100049, 100057, 100069, 100103, 100109, 100129, 100151} */ private: vector<unsigned long long> hash; vector<unsigned long long> base_pow; unsigned long long base, modulus; const unsigned long long MODULUS_DEFAULT = (1ULL << 61) - 1; const unsigned long long MASK30 = (1ULL << 30) - 1; const unsigned long long MASK31 = (1ULL << 31) - 1; const unsigned long long BASE_MIN = 1e7; unsigned long long Modulus_2pow61m1(unsigned long long val) { val = (val & MODULUS_DEFAULT) + (val >> 61); if (MODULUS_DEFAULT < val) { val -= MODULUS_DEFAULT; } return val; } unsigned long long Multiple_2pow61m1(unsigned long long a, unsigned long long b) { unsigned long long au = a >> 31; unsigned long long ad = a & MASK31; unsigned long long bu = b >> 31; unsigned long long bd = b & MASK31; unsigned long long mid = ad * bu + au * bd; unsigned long long midu = mid >> 30; unsigned long long midd = mid & MASK30; return Modulus_2pow61m1(((au * bu) << 1) + midu + (midd << 31) + ad * bd); } void initialize(string &S) { int N = S.size(); vector<int> s(N); for (int i = 0; i < N; ++i) { s[i] = S[i]; } initialize(s); } void initialize(vector<int> &S) { hash.resize(S.size() + 1); base_pow.resize(S.size() + 1); hash[0] = 0; base_pow[0] = 1; if (modulus == MODULUS_DEFAULT) { for (int i = 1; i <= ((int)S.size()); ++i) { hash[i] = Modulus_2pow61m1(Multiple_2pow61m1(hash[i - 1], base) + S[i - 1]); base_pow[i] = Multiple_2pow61m1(base_pow[i - 1], base); } } else { for (int i = 1; i <= ((int)S.size()); ++i) { hash[i] = (hash[i - 1] * base + S[i - 1]) % modulus; base_pow[i] = (base_pow[i - 1] * base) % modulus; } } } public: RollingHash(string S = "", unsigned long long base_ = 0, unsigned long long modulus_ = 0) { if (0 < modulus_) { modulus = modulus_; } else { modulus = MODULUS_DEFAULT; } if (0 < base_) { base = base_; } else { mt19937_64 mt64(static_cast<unsigned int>(time(nullptr))); uniform_int_distribution<unsigned long long> rand_uniform( BASE_MIN, modulus - BASE_MIN); base = rand_uniform(mt64); } if (S.size() > 0) { initialize(S); } } // 0-indexed, [a, b) unsigned long long between(int a, int b) { if (modulus == MODULUS_DEFAULT) { return Modulus_2pow61m1(modulus + hash[b] - Multiple_2pow61m1(hash[a], base_pow[b - a])); } return (modulus + hash[b] - (hash[a] * base_pow[b - a]) % modulus) % modulus; } }; struct TrieTree { private: char chara_origin; int numtypes_ch; struct TrieNode { public: TrieNode **children; bool isLeaf; }; TrieNode *newNode() { TrieNode *pNode = new TrieNode; pNode->children = new TrieNode *[numtypes_ch]; pNode->isLeaf = false; for (int i = 0; i < numtypes_ch; i++) { pNode->children[i] = nullptr; } return pNode; } TrieNode *treeroot; public: TrieTree(int number_of_types_of_character = 26, char character_origin = 'a') { numtypes_ch = number_of_types_of_character; chara_origin = character_origin; treeroot = newNode(); } void insert(string key) { TrieNode *pCrawl = treeroot; for (int i = 0; i < ((int)key.size()); i++) { int index = key[i] - chara_origin; if (pCrawl->children[index] == nullptr) { pCrawl->children[index] = newNode(); } pCrawl = pCrawl->children[index]; } // mark last node as leaf pCrawl->isLeaf = true; } bool search(string key) { TrieNode *pCrawl = treeroot; for (int i = 0; i < ((int)key.size()); i++) { int index = key[i] - chara_origin; if (pCrawl->children[index] == nullptr) { return false; } pCrawl = pCrawl->children[index]; } return (pCrawl != nullptr and pCrawl->isLeaf); } }; /*------------------ the end of the template -----------------------*/ signed main(signed argc, char *argv[]) { int N, K; SCAND2(N, K); vector<int> a(N); lli left = 0; lli right = 0; REP(i, N) { SCAND(a[i]); right += a[i]; } while (left < right - 1) { lli mid = ((left + right) >> 1); lli cnt = 0; REP(i, N) { cnt += ((a[i] + mid - 1) / mid) - 1; } if (K < cnt) { left = mid; } else { right = mid; } } PRINTLLD(right); }
replace
857
858
857
858
0
p02598
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; bool possible(long long longestLog, const vector<long long> &A, long long K) { long long N = A.size(); long long numOfLongestLogs = 0; for (long long i = 0; i < N; ++i) { numOfLongestLogs += A[i] / longestLog; if (A[i] % longestLog == 0) { --numOfLongestLogs; } } return (numOfLongestLogs <= K); } void Main() { long long N, K; cin >> N >> K; vector<long long> A(N, 0LL); for (long long i = 0; i < N; ++i) { cin >> A[i]; } sort(A.begin(), A.end(), greater<long long>()); long long ub = A.front(); long long lb = 0LL; while (ub - lb > 1LL) { long long mid = (ub + lb) / 2LL; if (possible(mid, A, K)) { ub = mid; } else { lb = mid; } } if (ub == lb) { cout << ub << endl; } else { if (possible(lb, A, K)) { cout << lb << endl; } else { cout << ub << endl; } } } int main() { std::cout << std::fixed << std::setprecision(15); Main(); return 0; }
#include "bits/stdc++.h" using namespace std; bool possible(long long longestLog, const vector<long long> &A, long long K) { long long N = A.size(); long long numOfLongestLogs = 0; for (long long i = 0; i < N; ++i) { numOfLongestLogs += A[i] / longestLog; if (A[i] % longestLog == 0) { --numOfLongestLogs; } } return (numOfLongestLogs <= K); } void Main() { long long N, K; cin >> N >> K; vector<long long> A(N, 0LL); for (long long i = 0; i < N; ++i) { cin >> A[i]; } sort(A.begin(), A.end(), greater<long long>()); long long ub = A.front(); long long lb = 0LL; while (ub - lb > 1LL) { long long mid = (ub + lb) / 2LL; if (possible(mid, A, K)) { ub = mid; } else { lb = mid; } } cout << ub << endl; // if (ub == lb) { // cout << ub << endl; // } // else { // if (possible(lb, A, K)) { // cout << lb << endl; // } // else { // cout << ub << endl; // } // } } int main() { std::cout << std::fixed << std::setprecision(15); Main(); return 0; }
replace
35
44
35
47
0
p02598
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; int main() { int N, K; cin >> N >> K; vector<int> A(N); int maxsize = 0; for (int i = 0; i < N; ++i) { cin >> A[i]; maxsize = max(A[i], maxsize); } int l = 0; int r = maxsize; for (int n = 0; n < 100; ++n) { int x = (l + r) / 2; int count = 0; for (int i = 0; i < N; ++i) { count += A[i] / x; if (0 != A[i] % x) { count++; } } if (count > N + K) { l = x; } else { r = x; } } cout << r << endl; return 0; }
#include "bits/stdc++.h" using namespace std; int main() { int N, K; cin >> N >> K; vector<int> A(N); int maxsize = 0; for (int i = 0; i < N; ++i) { cin >> A[i]; maxsize = max(A[i], maxsize); } int l = 1; int r = maxsize; for (int n = 0; n < 100; ++n) { int x = (l + r) / 2; int count = 0; for (int i = 0; i < N; ++i) { count += A[i] / x; if (0 != A[i] % x) { count++; } } if (count > N + K) { l = x; } else { r = x; } } cout << r << endl; return 0; }
replace
13
14
13
14
0
p02598
C++
Runtime Error
// #define _CRT_SECURE_NO_WARNINGS // #include <bits/stdc++.h> #include "bits/stdc++.h" #define rep(i, n) for (long long(i) = 0; (i) < (long long)(n); (i)++) #define all(x) (x).begin(), (x).end() #define int long long #define PI (3.14159265358979323) #define MOD (1000000007LL) #define INF (1LL << 60LL) #define MAX_N (10000001) #define MAX (1000000000000000000LL) using namespace std; signed main() { int l = 0, r = 1000000000; int n; int k; cin >> n >> k; vector<int> a(n); rep(i, n) cin >> a[i]; while (l != r) { int m = (l + r) / 2; int k2 = 0; rep(i, n) { int b = a[i]; k2 += (b / m) - 1; if (b % m != 0) k2++; } if (k2 <= k) { r = m; } else { l = m + 1; } } cout << l << endl; }
// #define _CRT_SECURE_NO_WARNINGS // #include <bits/stdc++.h> #include "bits/stdc++.h" #define rep(i, n) for (long long(i) = 0; (i) < (long long)(n); (i)++) #define all(x) (x).begin(), (x).end() #define int long long #define PI (3.14159265358979323) #define MOD (1000000007LL) #define INF (1LL << 60LL) #define MAX_N (10000001) #define MAX (1000000000000000000LL) using namespace std; signed main() { int l = 1, r = 1000000000; int n; int k; cin >> n >> k; vector<int> a(n); rep(i, n) cin >> a[i]; while (l != r) { int m = (l + r) / 2; int k2 = 0; rep(i, n) { int b = a[i]; k2 += (b / m) - 1; if (b % m != 0) k2++; } if (k2 <= k) { r = m; } else { l = m + 1; } } cout << l << endl; }
replace
16
17
16
17
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; long long int Exp(long long int exp_n, long long int exp_e, long long exp_mod); int main() { long long int N, K, Max_A = 0, O; priority_queue<long long int> q; cin >> N >> K; long long int A[N]; for (int i = 0; i < N; i++) { cin >> A[i]; Max_A = max(Max_A, A[i]); } long long int X, top = Max_A, btm = 0; X = (top + btm) / 2; while (top != X) { O = 0; for (int i = 0; i < N; i++) { O = O + (A[i] - 1) / X; } if (O > K) { btm = X; X = (top + btm + 1) / 2; } else { top = X; X = (top + btm + 1) / 2; } } cout << X << endl; return 0; } long long int Exp(long long int exp_n, long long int exp_e, long long int exp_mod) { long long int exp_o = 1; long long int exp_x = exp_n; long long int exp_tmp; while (0 < exp_e) { exp_tmp = exp_e / 2; if (exp_e - exp_tmp * 2 == 1) { exp_o = exp_o * exp_x; if (exp_o > exp_mod) { exp_o = exp_o % exp_mod; } } exp_x = exp_x * exp_x; if (exp_x > exp_mod) { exp_x = exp_x % exp_mod; } exp_e = exp_tmp; } return exp_o; }
#include <bits/stdc++.h> using namespace std; long long int Exp(long long int exp_n, long long int exp_e, long long exp_mod); int main() { long long int N, K, Max_A = 0, O; priority_queue<long long int> q; cin >> N >> K; long long int A[N]; for (int i = 0; i < N; i++) { cin >> A[i]; Max_A = max(Max_A, A[i]); } long long int X, top = Max_A, btm = 0; X = (top + btm + 1) / 2; while (top != X) { O = 0; for (int i = 0; i < N; i++) { O = O + (A[i] - 1) / X; } if (O > K) { btm = X; X = (top + btm + 1) / 2; } else { top = X; X = (top + btm + 1) / 2; } } cout << X << endl; return 0; } long long int Exp(long long int exp_n, long long int exp_e, long long int exp_mod) { long long int exp_o = 1; long long int exp_x = exp_n; long long int exp_tmp; while (0 < exp_e) { exp_tmp = exp_e / 2; if (exp_e - exp_tmp * 2 == 1) { exp_o = exp_o * exp_x; if (exp_o > exp_mod) { exp_o = exp_o % exp_mod; } } exp_x = exp_x * exp_x; if (exp_x > exp_mod) { exp_x = exp_x % exp_mod; } exp_e = exp_tmp; } return exp_o; }
replace
15
16
15
16
0
p02598
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; #ifdef _DEBUG #define dlog(str) cout << "====" << str << endl; #else #define dlog(str) #endif #define INF 999999999 #define MOD 1000000007 #define REP(i, n) for (int i = 0, i##_l = (n); i < i##_l; i++) #define FOR(i, s, e) for (int i = s, i##_l = (e); i < i##_l; i++) #define LLI long long int #define _min(a, b) ((a < b) ? a : b) #define _max(a, b) ((a < b) ? b : a) #define chmax(a, b) a = _max(a, b) #define chmin(a, b) a = _min(a, b) #define bit(a, shift) ((a>>shift)&1)) #define pm(a) ((a) ? 1 : -1) #define SORT(v) sort(v.begin(), v.end()) #define RSORT(v) sort((v).rbegin(), (v).rend()) // int 2.14E±9 lli 9.2E±18 double 1.7E±380 int main() { cout << fixed << setprecision(10); int n, k; cin >> n >> k; vector<int> a(n); REP(i, n) { cin >> a[i]; } RSORT(a); LLI l = 0, r = 1e9; while (l < r) { LLI m = (l + r) / 2; int c = 0; REP(i, n) { c += (a[i] - 1) / m; } if (c <= k) { r = m; } else { l = m + 1; } } cout << l << endl; return 0; }
#include "bits/stdc++.h" using namespace std; #ifdef _DEBUG #define dlog(str) cout << "====" << str << endl; #else #define dlog(str) #endif #define INF 999999999 #define MOD 1000000007 #define REP(i, n) for (int i = 0, i##_l = (n); i < i##_l; i++) #define FOR(i, s, e) for (int i = s, i##_l = (e); i < i##_l; i++) #define LLI long long int #define _min(a, b) ((a < b) ? a : b) #define _max(a, b) ((a < b) ? b : a) #define chmax(a, b) a = _max(a, b) #define chmin(a, b) a = _min(a, b) #define bit(a, shift) ((a>>shift)&1)) #define pm(a) ((a) ? 1 : -1) #define SORT(v) sort(v.begin(), v.end()) #define RSORT(v) sort((v).rbegin(), (v).rend()) // int 2.14E±9 lli 9.2E±18 double 1.7E±380 int main() { cout << fixed << setprecision(10); int n, k; cin >> n >> k; vector<int> a(n); REP(i, n) { cin >> a[i]; } RSORT(a); LLI l = 1, r = 1e9; while (l < r) { LLI m = (l + r) / 2; int c = 0; REP(i, n) { c += (a[i] - 1) / m; } if (c <= k) { r = m; } else { l = m + 1; } } cout << l << endl; return 0; }
replace
31
32
31
32
0
p02598
C++
Runtime Error
#include <iostream> #include <vector> using namespace std; #define rep(i, j, n) for (int i = j; i < (int)n; ++i) int main() { int n, k; cin >> n >> k; vector<int> a(n); int l = 0, r = 0; rep(i, 0, n) { cin >> a[i]; r = max(r, a[i]); } // upper bound while (l != r) { int mid = (r + l) >> 1; bool ok = [&] { int res = 0; rep(i, 0, n) { res += (a[i] - 1) / mid; } return res <= k; }(); if (ok) r = mid; else l = mid + 1; } cout << l; return 0; }
#include <iostream> #include <vector> using namespace std; #define rep(i, j, n) for (int i = j; i < (int)n; ++i) int main() { int n, k; cin >> n >> k; vector<int> a(n); int l = 1, r = 0; rep(i, 0, n) { cin >> a[i]; r = max(r, a[i]); } // upper bound while (l != r) { int mid = (r + l) >> 1; bool ok = [&] { int res = 0; rep(i, 0, n) { res += (a[i] - 1) / mid; } return res <= k; }(); if (ok) r = mid; else l = mid + 1; } cout << l; return 0; }
replace
10
11
10
11
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) #define dup(x, y) (((x) + (y)-1) / (y)) #define ALL(x) (x).begin(), (x).end() typedef long long ll; typedef pair<int, int> pii; const double EPS = 1e-10; const int INF = 1e9; const ll LINF = 1e15; const int MOD = 1e9 + 7; const double PI = acos(-1); int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; typedef pair<ll, ll> pll; long long n, k; long long a[200005]; bool check(int x) { int cnt = 0; for (int i = 0; i < n; i++) { cnt += (a[i] - 1) / x; } if (cnt <= k) return true; else return false; } int main() { cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; long long left = -1; long long right = INF; while (right - left > 1) { long long mid = (left + right) / 2; if (check(mid)) right = mid; else left = mid; // cout << left << " " << right << endl; } cout << right << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) #define dup(x, y) (((x) + (y)-1) / (y)) #define ALL(x) (x).begin(), (x).end() typedef long long ll; typedef pair<int, int> pii; const double EPS = 1e-10; const int INF = 1e9; const ll LINF = 1e15; const int MOD = 1e9 + 7; const double PI = acos(-1); int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; typedef pair<ll, ll> pll; long long n, k; long long a[200005]; bool check(int x) { int cnt = 0; for (int i = 0; i < n; i++) { cnt += (a[i] - 1) / x; } if (cnt <= k) return true; else return false; } int main() { cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; long long left = 0; long long right = INF; while (right - left > 1) { long long mid = (left + right) / 2; if (check(mid)) right = mid; else left = mid; // cout << left << " " << right << endl; } cout << right << endl; }
replace
35
36
35
36
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> #define del(a, i) memset(a, i, sizeof(a)) #define ll long long #define inl inline #define il inl void #define it inl int #define ill inl ll #define re register #define ri re int #define rl re ll #define mid ((l + r) >> 1) #define lowbit(x) (x & (-x)) #define INF 0x3f3f3f3f using namespace std; template <class T> inl T read() { T x = 0; int f = 1; char k = getchar(); for (; k > '9' || k < '0'; k = getchar()) if (k == '-') f = -1; for (; k >= '0' && k <= '9'; k = getchar()) x = x * 10 + k - '0'; return x * f; } template <class T> inl T read(T &x) { return x = read<T>(); } int _num, _buf[20]; template <class T> il print(T x) { if (x == 0) return putchar('0'), void(); if (x < 0) putchar('-'), x = -x; while (x) _buf[++_num] = x % 10, x /= 10; while (_num) putchar(_buf[_num--] + '0'); } ll mul(ll a, ll b, ll mod) { long double c = 1.; return (a * b - (ll)(c * a * b / mod) * mod) % mod; } it qpow(int x, int m, int mod) { int res = 1, bas = x; while (m) { if (m & 1) res = (1ll * res * bas) % mod; bas = (1ll * bas * bas) % mod, m >>= 1; } return res; } const int N = 2e5 + 5; int n, k, val[N]; inl bool chk(int len) { int rest = k + n; for (ri i = 1; i <= n; ++i) rest -= (val[i] + len - 1) / len; return rest >= 0; } int main() { // freopen( ".in", "r", stdin ) ; // freopen( ".out", "w", stdout ) ; n = read<int>(), k = read<int>(); int l = 0, r = 0; for (ri i = 1; i <= n; ++i) { val[i] = read<int>(); r = std::max(r, val[i]); } while (l < r) { if (chk(mid)) r = mid; else l = mid + 1; } print(mid), puts(""); cerr << 1. * clock() / CLOCKS_PER_SEC << "\n"; return 0; }
#include <bits/stdc++.h> #define del(a, i) memset(a, i, sizeof(a)) #define ll long long #define inl inline #define il inl void #define it inl int #define ill inl ll #define re register #define ri re int #define rl re ll #define mid ((l + r) >> 1) #define lowbit(x) (x & (-x)) #define INF 0x3f3f3f3f using namespace std; template <class T> inl T read() { T x = 0; int f = 1; char k = getchar(); for (; k > '9' || k < '0'; k = getchar()) if (k == '-') f = -1; for (; k >= '0' && k <= '9'; k = getchar()) x = x * 10 + k - '0'; return x * f; } template <class T> inl T read(T &x) { return x = read<T>(); } int _num, _buf[20]; template <class T> il print(T x) { if (x == 0) return putchar('0'), void(); if (x < 0) putchar('-'), x = -x; while (x) _buf[++_num] = x % 10, x /= 10; while (_num) putchar(_buf[_num--] + '0'); } ll mul(ll a, ll b, ll mod) { long double c = 1.; return (a * b - (ll)(c * a * b / mod) * mod) % mod; } it qpow(int x, int m, int mod) { int res = 1, bas = x; while (m) { if (m & 1) res = (1ll * res * bas) % mod; bas = (1ll * bas * bas) % mod, m >>= 1; } return res; } const int N = 2e5 + 5; int n, k, val[N]; inl bool chk(int len) { int rest = k + n; for (ri i = 1; i <= n; ++i) rest -= (val[i] + len - 1) / len; return rest >= 0; } int main() { // freopen( ".in", "r", stdin ) ; // freopen( ".out", "w", stdout ) ; n = read<int>(), k = read<int>(); int l = 1, r = 0; for (ri i = 1; i <= n; ++i) { val[i] = read<int>(); r = std::max(r, val[i]); } while (l < r) { if (chk(mid)) r = mid; else l = mid + 1; } print(mid), puts(""); cerr << 1. * clock() / CLOCKS_PER_SEC << "\n"; return 0; }
replace
62
63
62
63
0
0.025796
p02598
C++
Runtime Error
//@sakshjha #include <bits/stdc++.h> using namespace std; // #include <ext/pb_ds/assoc_container.hpp> // Common file // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; #define ll long long int #define ld long double #define FAST \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define pb push_back #define pi 3.14159265358979 #define pa pair<ll, ll> // #define goodset tree<pa, null_type, less<pa>, rb_tree_tag, // tree_order_statistics_node_update> #define FRE freopen("acm.in","r",stdin); // freopen("acm.out","w",stdout); const ll mod = 1e9 + 7; const ll N = 1e7 + 5; int main() { FAST ll tc, i, j, k; // cin>>tc; tc = 1; while (tc--) { ll n, k; cin >> n >> k; ll a[n]; for (i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); ll lo = 0; ll hi = a[n - 1]; ll ans = a[n - 1]; while (lo <= hi) { ll mi = (lo + hi) / 2; ll cnt = 0; for (i = 0; i < n; i++) { ll val = a[i] / mi; if (a[i] % mi != 0) val++; if (val > 0) cnt += (val - 1); } if (cnt <= k) { ans = min(ans, mi); hi = mi - 1; } else lo = mi + 1; } cout << ans; } return 0; }
//@sakshjha #include <bits/stdc++.h> using namespace std; // #include <ext/pb_ds/assoc_container.hpp> // Common file // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; #define ll long long int #define ld long double #define FAST \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define pb push_back #define pi 3.14159265358979 #define pa pair<ll, ll> // #define goodset tree<pa, null_type, less<pa>, rb_tree_tag, // tree_order_statistics_node_update> #define FRE freopen("acm.in","r",stdin); // freopen("acm.out","w",stdout); const ll mod = 1e9 + 7; const ll N = 1e7 + 5; int main() { FAST ll tc, i, j, k; // cin>>tc; tc = 1; while (tc--) { ll n, k; cin >> n >> k; ll a[n]; for (i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); ll lo = 0; ll hi = a[n - 1]; ll ans = a[n - 1]; while (lo <= hi) { ll mi = (lo + hi) / 2; if (mi == 0) { ans = 1; break; } ll cnt = 0; for (i = 0; i < n; i++) { ll val = a[i] / mi; if (a[i] % mi != 0) val++; if (val > 0) cnt += (val - 1); } if (cnt <= k) { ans = min(ans, mi); hi = mi - 1; } else lo = mi + 1; } cout << ans; } return 0; }
insert
43
43
43
47
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> #define int long long using namespace std; int n, k, a[200010]; signed main() { ios::sync_with_stdio(false); cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; int l = 0, r = 1000000000, ans = -1; while (l <= r) { int mid = (l + r) / 2; int cnt = 0ll; for (int i = 1; i <= n; i++) cnt += (a[i] - 1) / mid; if (cnt <= k) { ans = mid; r = mid - 1; } else l = mid + 1; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define int long long using namespace std; int n, k, a[200010]; signed main() { ios::sync_with_stdio(false); cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; int l = 1, r = 1000000000, ans = -1; while (l <= r) { int mid = (l + r) / 2; int cnt = 0ll; for (int i = 1; i <= n; i++) cnt += (a[i] - 1) / mid; if (cnt <= k) { ans = mid; r = mid - 1; } else l = mid + 1; } cout << ans << endl; return 0; }
replace
11
12
11
12
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using llong = long long int; #define rep(i, n) for (int i = 0; i < n; ++i) #define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr) #define all(x) x.begin(), x.end() #define allr(x) x.rbegin(), x.rend() const static int MOD = 1000000007; const static int INF = 1000000000; const static int dx[4] = {1, 0, -1, 0}; const static int dy[4] = {0, 1, 0, -1}; int main(int argc, char *argv[]) { cin.tie(0); ios::sync_with_stdio(false); int n, k; cin >> n >> k; vector<int> logs(n); rep(i, n) cin >> logs[i]; int left = -1, right = INF, mid; while (right - left > 1) { mid = left + (right - left) / 2; int cut = 0; rep(i, n) { if (cut > k) break; cut += (logs[i] + mid - 1) / mid - 1; } if (cut <= k) right = mid; else left = mid; } cout << right << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using llong = long long int; #define rep(i, n) for (int i = 0; i < n; ++i) #define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr) #define all(x) x.begin(), x.end() #define allr(x) x.rbegin(), x.rend() const static int MOD = 1000000007; const static int INF = 1000000000; const static int dx[4] = {1, 0, -1, 0}; const static int dy[4] = {0, 1, 0, -1}; int main(int argc, char *argv[]) { cin.tie(0); ios::sync_with_stdio(false); int n, k; cin >> n >> k; vector<int> logs(n); rep(i, n) cin >> logs[i]; int left = 0, right = INF, mid; while (right - left > 1) { mid = left + (right - left) / 2; int cut = 0; rep(i, n) { if (cut > k) break; cut += (logs[i] + mid - 1) / mid - 1; } if (cut <= k) right = mid; else left = mid; } cout << right << endl; return 0; }
replace
25
26
25
26
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long #define str string #define pii pair<int, int> #define pll pair<ll, ll> #define fi first #define se second #define vc vector<char> #define vvc vector<vc> #define vi vector<int> #define vll vector<ll> #define vvi vector<vi> #define vvll vector<vll> #define vvvll vector<vvll> #define vs vector<str> #define vvs vector<vs> #define vpii vector<pii> #define vvpii vector<vpii> #define vpll vector<pll> #define vvpll vector<vpll> #define vb vector<bool> #define vvb vector<vb> #define rep(i, a, b) for (int i = (a); i < int(b); i++) #define repi(i, a, b) for (int i = (a); i <= int(b); i++) using namespace std; ll INF = LONG_LONG_MAX; ll mod = 1000000000 + 7; template <typename T, typename L> void read(vector<T> &_data, L &_size, bool _shift) { _data.resize(_size + (ll)_shift); for (ll i = (ll)_shift; i < _size + (ll)_shift; i++) cin >> _data[i]; } template <typename T, typename L> void read(vector<vector<T>> &_data, L &_rows, L &_cols, bool _shiftRows, bool _shiftCols) { _data.resize(_rows + (ll)_shiftRows); for (ll i = 0; i < _rows + (ll)_shiftRows; i++) _data[i].resize(_cols + (ll)_shiftCols); for (ll i = (ll)_shiftRows; i < _rows + (ll)_shiftRows; i++) for (ll j = (ll)_shiftCols; j < _cols + (ll)_shiftCols; j++) cin >> _data[i][j]; } template <typename T> void write(vector<T> &_data, bool _shift) { for (ll i = (ll)_shift; i < _data.size(); i++) cout << _data[i] << " "; cout << endl; } // TODO: SOLUTION ll n, k; vll a; void solve() { cin >> n >> k; read(a, n, 0); sort(a.begin(), a.end(), greater<>()); ll lo = 0; ll hi = *max_element(a.begin(), a.end()); ll best = hi; while (lo <= hi) { ll mid = (lo + hi) / 2; ll touse = k; ll i = 0; while (i < n && touse >= 0) { ll cuts; if (a[i] % mid == 0) cuts = a[i] / mid - 1; else cuts = a[i] / mid; touse -= cuts; i++; } if (i == n && touse >= 0) { best = mid; hi = mid - 1; } else { lo = mid + 1; } } cout << best << endl; } int main() { // TODO: Set value of this variable manually bool _multipleTestCases = false; if (_multipleTestCases) { ll t; cin >> t; while (t--) solve(); } else { solve(); } return 0; }
#include <bits/stdc++.h> #define ll long long #define str string #define pii pair<int, int> #define pll pair<ll, ll> #define fi first #define se second #define vc vector<char> #define vvc vector<vc> #define vi vector<int> #define vll vector<ll> #define vvi vector<vi> #define vvll vector<vll> #define vvvll vector<vvll> #define vs vector<str> #define vvs vector<vs> #define vpii vector<pii> #define vvpii vector<vpii> #define vpll vector<pll> #define vvpll vector<vpll> #define vb vector<bool> #define vvb vector<vb> #define rep(i, a, b) for (int i = (a); i < int(b); i++) #define repi(i, a, b) for (int i = (a); i <= int(b); i++) using namespace std; ll INF = LONG_LONG_MAX; ll mod = 1000000000 + 7; template <typename T, typename L> void read(vector<T> &_data, L &_size, bool _shift) { _data.resize(_size + (ll)_shift); for (ll i = (ll)_shift; i < _size + (ll)_shift; i++) cin >> _data[i]; } template <typename T, typename L> void read(vector<vector<T>> &_data, L &_rows, L &_cols, bool _shiftRows, bool _shiftCols) { _data.resize(_rows + (ll)_shiftRows); for (ll i = 0; i < _rows + (ll)_shiftRows; i++) _data[i].resize(_cols + (ll)_shiftCols); for (ll i = (ll)_shiftRows; i < _rows + (ll)_shiftRows; i++) for (ll j = (ll)_shiftCols; j < _cols + (ll)_shiftCols; j++) cin >> _data[i][j]; } template <typename T> void write(vector<T> &_data, bool _shift) { for (ll i = (ll)_shift; i < _data.size(); i++) cout << _data[i] << " "; cout << endl; } // TODO: SOLUTION ll n, k; vll a; void solve() { cin >> n >> k; read(a, n, 0); sort(a.begin(), a.end(), greater<>()); ll lo = 1; ll hi = *max_element(a.begin(), a.end()); ll best = hi; while (lo <= hi) { ll mid = (lo + hi) / 2; ll touse = k; ll i = 0; while (i < n && touse >= 0) { ll cuts; if (a[i] % mid == 0) cuts = a[i] / mid - 1; else cuts = a[i] / mid; touse -= cuts; i++; } if (i == n && touse >= 0) { best = mid; hi = mid - 1; } else { lo = mid + 1; } } cout << best << endl; } int main() { // TODO: Set value of this variable manually bool _multipleTestCases = false; if (_multipleTestCases) { ll t; cin >> t; while (t--) solve(); } else { solve(); } return 0; }
replace
66
67
66
67
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using vi = vector<int>; using vll = vector<ll>; #define MOD 1000000007 int main() { int n, k; cin >> n >> k; vll a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } ll ng = -1, ok = 1e10, mid; ll cnt; while (abs(ok - ng) > 1) { mid = (ok + ng) / 2; cnt = 0; for (int i = 0; i < n; i++) { cnt += (a[i] + mid - 1) / mid; cnt--; } if (cnt <= k) ok = mid; else ng = mid; } cout << ok << 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 vi = vector<int>; using vll = vector<ll>; #define MOD 1000000007 int main() { int n, k; cin >> n >> k; vll a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } ll ng = 0, ok = 1e10, mid; ll cnt; while (abs(ok - ng) > 1) { mid = (ok + ng) / 2; cnt = 0; for (int i = 0; i < n; i++) { cnt += (a[i] + mid - 1) / mid; cnt--; } if (cnt <= k) ok = mid; else ng = mid; } cout << ok << endl; return 0; }
replace
16
17
16
17
0
p02598
C++
Runtime Error
#define _USE_MATH_DEFINES #include <bits/stdc++.h> #define REP(i, start, end) for (int i = start, i##Len = (end); i < i##Len; ++i) #define REPR(i, start, end) for (int i = start, i##Len = (end); i > i##Len; --i) using ll = long long; using namespace std; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); ll n, k; cin >> n >> k; vector<ll> a(n); REP(i, 0, n) cin >> a[i]; auto solve = [&](ll x) { ll cnt = 0; for (auto &l : a) cnt += l / x; return cnt > k; }; ll ok = 0, ng = 1e9 + 1; while (abs(ok - ng) > 1) { ll mid = (ok + ng) / 2; if (solve(mid)) ok = mid; else ng = mid; } ll cnt = 0; for (auto &l : a) { cnt += (l % ok > 0 ? l / ok : l / ok - 1); } cout << (cnt > k ? ok + 1 : ok) << endl; }
#define _USE_MATH_DEFINES #include <bits/stdc++.h> #define REP(i, start, end) for (int i = start, i##Len = (end); i < i##Len; ++i) #define REPR(i, start, end) for (int i = start, i##Len = (end); i > i##Len; --i) using ll = long long; using namespace std; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); ll n, k; cin >> n >> k; vector<ll> a(n); REP(i, 0, n) cin >> a[i]; auto solve = [&](ll x) { ll cnt = 0; for (auto &l : a) cnt += l / x; return cnt > k; }; ll ok = 0, ng = 1e9 + 1; while (abs(ok - ng) > 1) { ll mid = (ok + ng) / 2; if (solve(mid)) ok = mid; else ng = mid; } ll cnt = 0; if (ok == 0) { cout << 1 << endl; return 0; } for (auto &l : a) { cnt += (l % ok > 0 ? l / ok : l / ok - 1); } cout << (cnt > k ? ok + 1 : ok) << endl; }
insert
35
35
35
39
0
p02598
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vll; typedef vector<vll> vvll; typedef vector<bool> vb; typedef vector<vb> vvb; void printVP(vector<pair<long long int, long long int>> vec_of_pairs); void printV(vector<int> vec); void printVVI(vector<vector<int>> vec); void printMapSP(map<string, pair<int, int>> mp); void printVC(vector<char> vec); void printCurrMap(map<char, set<char>> mp); int K, ans; vi all_a; bool can_get_height_with_less_cuts_than_k(int height) { int tot_num_cuts = 0; for (int i = 0; i < all_a.size(); i++) { int num_curr_cuts = ceil((all_a[i] * 1.0) / height - 1); tot_num_cuts += num_curr_cuts; // cout<<num_curr_cuts<<" "<<height<<" "<<all_a[i]<<endl; } // cout<<"Total: "<<tot_num_cuts<<" "<<height<<endl; if (tot_num_cuts > K) return false; else return true; } // Inclusive of heights void binary_search(int lower_height, int upper_height) { // cout<<lower_height<<" "<<upper_height<<endl; if (upper_height - lower_height == 1) { if (can_get_height_with_less_cuts_than_k(lower_height)) ans = lower_height; else ans = upper_height; return; } int mid = (upper_height + lower_height) / 2; if (can_get_height_with_less_cuts_than_k(mid)) // Then try do more cuts upper_height = mid; else lower_height = mid; binary_search(lower_height, upper_height); } void solve() { int N, Ai, max_Ai; cin >> N >> K; max_Ai = -1; for (int i = 0; i < N; i++) { cin >> Ai; all_a.push_back(Ai); if (Ai > max_Ai) max_Ai = Ai; } binary_search(1, max_Ai); cout << ans << endl; } int main() { int t; // cin>>t; t = 1; for (int i = 0; i < t; i++) { // cout<<"Case #"<<i+1<<": "; solve(); } return 0; }
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vll; typedef vector<vll> vvll; typedef vector<bool> vb; typedef vector<vb> vvb; void printVP(vector<pair<long long int, long long int>> vec_of_pairs); void printV(vector<int> vec); void printVVI(vector<vector<int>> vec); void printMapSP(map<string, pair<int, int>> mp); void printVC(vector<char> vec); void printCurrMap(map<char, set<char>> mp); int K, ans; vi all_a; bool can_get_height_with_less_cuts_than_k(int height) { int tot_num_cuts = 0; for (int i = 0; i < all_a.size(); i++) { int num_curr_cuts = ceil((all_a[i] * 1.0) / height - 1); tot_num_cuts += num_curr_cuts; // cout<<num_curr_cuts<<" "<<height<<" "<<all_a[i]<<endl; } // cout<<"Total: "<<tot_num_cuts<<" "<<height<<endl; if (tot_num_cuts > K) return false; else return true; } // Inclusive of heights void binary_search(int lower_height, int upper_height) { // cout<<lower_height<<" "<<upper_height<<endl; if (upper_height - lower_height == 1) { if (can_get_height_with_less_cuts_than_k(lower_height)) ans = lower_height; else ans = upper_height; return; } int mid = (upper_height + lower_height) / 2; if (can_get_height_with_less_cuts_than_k(mid)) // Then try do more cuts upper_height = mid; else lower_height = mid; binary_search(lower_height, upper_height); } void solve() { int N, Ai, max_Ai; cin >> N >> K; max_Ai = -1; for (int i = 0; i < N; i++) { cin >> Ai; all_a.push_back(Ai); if (Ai > max_Ai) max_Ai = Ai; } if (max_Ai == 1) { cout << 1 << endl; return; } binary_search(1, max_Ai); cout << ans << endl; } int main() { int t; // cin>>t; t = 1; for (int i = 0; i < t; i++) { // cout<<"Case #"<<i+1<<": "; solve(); } return 0; }
insert
82
82
82
87
TLE
p02598
C++
Runtime Error
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> #define ll long long #define ull unsigned long long using namespace std; const ll INF = 10010010010010; int main() { ll N, K; cin >> N >> K; vector<ll> A(N); for (int ii = 0; ii < N; ++ii) { cin >> A[ii]; } ll l = -1; ll r = INF; while (l + 1 < r) { ll mid = (l + r) / 2; ll sum = 0; for (int ii = 0; ii < N; ++ii) { sum += (A[ii] + mid - 1) / mid - 1; } bool ok = (sum <= K) ? true : false; if (ok) { r = mid; } else { l = mid; } } cout << r << "\n"; return 0; }
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> #define ll long long #define ull unsigned long long using namespace std; const ll INF = 10010010010010; int main() { ll N, K; cin >> N >> K; vector<ll> A(N); for (int ii = 0; ii < N; ++ii) { cin >> A[ii]; } ll l = 0; ll r = INF; while (l + 1 < r) { ll mid = (l + r) / 2; ll sum = 0; for (int ii = 0; ii < N; ++ii) { sum += (A[ii] + mid - 1) / mid - 1; } bool ok = (sum <= K) ? true : false; if (ok) { r = mid; } else { l = mid; } } cout << r << "\n"; return 0; }
replace
19
20
19
20
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> #define pb push_back #define F first #define S second using ll = long long; #define ull unsigned ll #define endl "\n" #define vi vector<int> #define vl vector<ll> #define all(v) (v).begin(), (v).end() #define mst(a, b) memset(a, b, sizeof(a)) #define pi pair<int, int> #define pl pair<ll, ll> #define ppi pair<int, pii> #define mt make_tuple #define eb emplace_back using namespace std; const ll N = 2e5 + 5, mod = 1e9 + 7; const int inf = 1e9 + 5; bool cmp(const pair<ll, ll> &a, const pair<ll, ll> &b) { if (a.F == b.F) return a.S < b.S; return a.F > b.F; } ll power(ll x, ll p) { ll r = 1ll; x = x % mod; while (p > 0) { if (p & 1) r = (r * x) % mod; p = p >> 1; x = (x * x) % mod; } return r; } void solve() { int n, k; cin >> n >> k; vi a(n); int ans = 0; for (int i = 0; i < n; i++) { cin >> a[i]; ans = max(ans, a[i]); } int l = 0, r = inf; while (l <= r) { int mid = (l + r) / 2; int cnt = 0; for (int i = 0; i < n; i++) { cnt += (a[i] - 1) / mid; if (cnt > k) break; } if (cnt > k) { l = mid + 1; } else { r = mid - 1; ans = mid; } } cout << ans << endl; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); // cout.tie(0); /*#ifndef ONLINE_JUDGE freopen("Input.txt", "r", stdin); #endif*/ // freopen("running_on_fumes_chapter_1_input (1).txt", "r", stdin); // freopen("Output.txt", "w", stdout); int t = 1, p; // cin >> t; for (p = 1; p <= t; p++) { // cout << "Case #" << p << ": "; solve(); } return 0; }
#include <bits/stdc++.h> #define pb push_back #define F first #define S second using ll = long long; #define ull unsigned ll #define endl "\n" #define vi vector<int> #define vl vector<ll> #define all(v) (v).begin(), (v).end() #define mst(a, b) memset(a, b, sizeof(a)) #define pi pair<int, int> #define pl pair<ll, ll> #define ppi pair<int, pii> #define mt make_tuple #define eb emplace_back using namespace std; const ll N = 2e5 + 5, mod = 1e9 + 7; const int inf = 1e9 + 5; bool cmp(const pair<ll, ll> &a, const pair<ll, ll> &b) { if (a.F == b.F) return a.S < b.S; return a.F > b.F; } ll power(ll x, ll p) { ll r = 1ll; x = x % mod; while (p > 0) { if (p & 1) r = (r * x) % mod; p = p >> 1; x = (x * x) % mod; } return r; } void solve() { int n, k; cin >> n >> k; vi a(n); int ans = 0; for (int i = 0; i < n; i++) { cin >> a[i]; ans = max(ans, a[i]); } int l = 0, r = inf; while (l <= r) { int mid = (l + r) / 2; int cnt = 0; if (mid == 0) { cout << 1 << endl; return; } for (int i = 0; i < n; i++) { cnt += (a[i] - 1) / mid; if (cnt > k) break; } if (cnt > k) { l = mid + 1; } else { r = mid - 1; ans = mid; } } cout << ans << endl; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); // cout.tie(0); /*#ifndef ONLINE_JUDGE freopen("Input.txt", "r", stdin); #endif*/ // freopen("running_on_fumes_chapter_1_input (1).txt", "r", stdin); // freopen("Output.txt", "w", stdout); int t = 1, p; // cin >> t; for (p = 1; p <= t; p++) { // cout << "Case #" << p << ": "; solve(); } return 0; }
insert
51
51
51
55
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 __gnu_pdbs; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 1. order_of_key(k) : number of elements strictly lesser than k 2. find_by_order(k) : k-th element in the set */ // #define int long long using namespace std; #define f(i, k, n) for (i = k; i < n; i++) #define fd(i, k, n) for (i = k; i > n; i--) #define pb push_back #define mp make_pair #define ll long long #define ld long double #define ull unsigned long long #define vi vector<int> #define vll vector<ll> #define vvi vector<vi> #define vvll vector<vll> #define pii pair<int, int> #define pll pair<ll, ll> #define mii map<int, int> #define mll map<ll, ll> #define umap unordered_map #define all(c) c.begin(), c.end() #define sz(c) (int)c.size() #define si(c) (int)c.size() #define lb lower_bound #define ub upper_bound #define gi greater<int> #define rev reverse #define ff first #define ss second #define yes cout << "YES" << endl #define no cout << "NO" << endl #define imp cout << "IMPOSSIBLE" << endl #define nl cout << endl #define hello cout << "hello" << endl #define sp(x) fixed << setprecision(x) #define re return #define p_q priority_queue #define FAST \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); // debugging void dbg_out() { cerr << endl; } template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); } #define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__) /* const double pi = 3.14159265359; const ll mod = 1000000007; const ll modc = 998244353; ll inline power(ll a, ll b, ll p){ a %= p; ll ans = 1; while(b>0){ if(b & 1) ans = (ans*a)%p; a = (a*a)%p; b >>= 1; } return ans; } ll mod_inv(ll n, ll p){ return power(n,p-2, p); } bool inline isPrime(ll n) { if (n <= 1) return false; if (n <= 3) return true; if (n%2 == 0 || n%3 == 0) return false; for (ll i=5; i*i<=n; i=i+6) if (n%i == 0 || n%(i+2) == 0) return false; return true; } template<typename... T> void W(T&&... args) { ((cout << sp(9) << args << " "), ...); nl; } template<typename... T> void R(T&&... args) { ((cin >> args), ...); } ll ston(string s) { ll a = 0; reverse(s.begin(),s.end()); ll pow = 1; for(int i=0;i<s.size();i++) { a += pow*(s[i]-'0'); pow*=10; } return a; } template <class T> string to_binary(T n) { string binaryNum; int i = 0; while (n > 0) { binaryNum.pb((n % 2)+'0'); n = n / 2; i++; } reverse(binaryNum.begin(),binaryNum.end()); return binaryNum; } template<class T> void wv(T &v) { for(auto x : v) cout << x << " " ; nl; } template<class T> void rv(T &v) { for(int i=0;i<sz(v);i++) cin >> v[i]; } //to safe_guard unordered_map<> in STL //now declare something as unordered_map<int,int,custom_hash>mp :) 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); } }; */ /* * USING WITH STRUCT Define a structure . Initialize variables in structure. Define another structure of type compare.(don't use bool operator < for stl containers (since it is there in std namespace); Overload the variables of structure in compare structure.(bool operator()(arguments){} ) Use container with compare structure. (priority queue me ulta) */ /* FUNCTIONS YOU ARE USING * ll inline power(ll a, ll b, ll p) * ll mod_inv(ll n, ll p) * bool inline isPrime(ll n) * ll ston(string s) * string to_binary(T n) */ /* *int overflow (ll vs int) *array out of bounds(runtime errors) *special cases (n=1)? *don't store large numbers in double(use long double instead) *BINARY SEARCH ?? *BRUTE FORCE with some optimization ?? *in compare return true if you want to place first argument before second *argument(p_q me ulta)(bool operator<)(bool operator()) Use custom_hash with *unordered_map to avoid collisions Think of your approach for one more minute *if it will work or not , otherwise you will end up implementing shit as always *:( use factor cmd to get prime factorization of something instead of writing *another code for it :) DO SOMETHING INSTEAD OF NOTHING */ const int M = 2e5; // for graph ll cost(ll val, vll &a) { ll sum = 0; for (auto x : a) { if (x % val == 0) sum += x / val - 1; else sum += x / val; } return sum; } void solve() { int i, j; ll sum = 0, prod = 1; ll maxl = LLONG_MIN, minl = LLONG_MAX; int maxi = INT_MIN, mini = INT_MAX; ll n, k; cin >> n >> k; vll a(n); for (auto &x : a) cin >> x; if (k == 0) { cout << *max_element(all(a)) << endl; re; } ll l, r; l = 0; r = 1e9; ll ans; while (l <= r) { ll mid = (l + r) / 2; if (cost(mid, a) <= k) { ans = mid; r = mid - 1; } else { l = mid + 1; } } cout << ans << endl; } int32_t main() { FAST; int t = 1; while (t--) { solve(); } }
/*╔═══╗──╔╗╔╗───────────────────╔╗────────╔═══╦═══╗ ║║─║╠╗╠╗╔╣╚═╦══╦═╗╔╦╗╔═╗╔══╦══╣╚═╦╦══╦══╣║─║║║─╚╝ ║╔═╗║╚╝║╚╣║║║╚╝║║─╔╦╗║║║║╚╝║╚╝║╚╝║║║═╬══║╔═╗║╚╩═║ ╚╝─╚╩══╩═╩╝╚╩══╩╝─╚╩╝╚╝╚╩══╩══╩══╩╩══╩══╩╝─╚╩═══╝*/ #include <bits/stdc++.h> /* #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pdbs; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 1. order_of_key(k) : number of elements strictly lesser than k 2. find_by_order(k) : k-th element in the set */ // #define int long long using namespace std; #define f(i, k, n) for (i = k; i < n; i++) #define fd(i, k, n) for (i = k; i > n; i--) #define pb push_back #define mp make_pair #define ll long long #define ld long double #define ull unsigned long long #define vi vector<int> #define vll vector<ll> #define vvi vector<vi> #define vvll vector<vll> #define pii pair<int, int> #define pll pair<ll, ll> #define mii map<int, int> #define mll map<ll, ll> #define umap unordered_map #define all(c) c.begin(), c.end() #define sz(c) (int)c.size() #define si(c) (int)c.size() #define lb lower_bound #define ub upper_bound #define gi greater<int> #define rev reverse #define ff first #define ss second #define yes cout << "YES" << endl #define no cout << "NO" << endl #define imp cout << "IMPOSSIBLE" << endl #define nl cout << endl #define hello cout << "hello" << endl #define sp(x) fixed << setprecision(x) #define re return #define p_q priority_queue #define FAST \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); // debugging void dbg_out() { cerr << endl; } template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); } #define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__) /* const double pi = 3.14159265359; const ll mod = 1000000007; const ll modc = 998244353; ll inline power(ll a, ll b, ll p){ a %= p; ll ans = 1; while(b>0){ if(b & 1) ans = (ans*a)%p; a = (a*a)%p; b >>= 1; } return ans; } ll mod_inv(ll n, ll p){ return power(n,p-2, p); } bool inline isPrime(ll n) { if (n <= 1) return false; if (n <= 3) return true; if (n%2 == 0 || n%3 == 0) return false; for (ll i=5; i*i<=n; i=i+6) if (n%i == 0 || n%(i+2) == 0) return false; return true; } template<typename... T> void W(T&&... args) { ((cout << sp(9) << args << " "), ...); nl; } template<typename... T> void R(T&&... args) { ((cin >> args), ...); } ll ston(string s) { ll a = 0; reverse(s.begin(),s.end()); ll pow = 1; for(int i=0;i<s.size();i++) { a += pow*(s[i]-'0'); pow*=10; } return a; } template <class T> string to_binary(T n) { string binaryNum; int i = 0; while (n > 0) { binaryNum.pb((n % 2)+'0'); n = n / 2; i++; } reverse(binaryNum.begin(),binaryNum.end()); return binaryNum; } template<class T> void wv(T &v) { for(auto x : v) cout << x << " " ; nl; } template<class T> void rv(T &v) { for(int i=0;i<sz(v);i++) cin >> v[i]; } //to safe_guard unordered_map<> in STL //now declare something as unordered_map<int,int,custom_hash>mp :) 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); } }; */ /* * USING WITH STRUCT Define a structure . Initialize variables in structure. Define another structure of type compare.(don't use bool operator < for stl containers (since it is there in std namespace); Overload the variables of structure in compare structure.(bool operator()(arguments){} ) Use container with compare structure. (priority queue me ulta) */ /* FUNCTIONS YOU ARE USING * ll inline power(ll a, ll b, ll p) * ll mod_inv(ll n, ll p) * bool inline isPrime(ll n) * ll ston(string s) * string to_binary(T n) */ /* *int overflow (ll vs int) *array out of bounds(runtime errors) *special cases (n=1)? *don't store large numbers in double(use long double instead) *BINARY SEARCH ?? *BRUTE FORCE with some optimization ?? *in compare return true if you want to place first argument before second *argument(p_q me ulta)(bool operator<)(bool operator()) Use custom_hash with *unordered_map to avoid collisions Think of your approach for one more minute *if it will work or not , otherwise you will end up implementing shit as always *:( use factor cmd to get prime factorization of something instead of writing *another code for it :) DO SOMETHING INSTEAD OF NOTHING */ const int M = 2e5; // for graph ll cost(ll val, vll &a) { ll sum = 0; for (auto x : a) { if (x % val == 0) sum += x / val - 1; else sum += x / val; } return sum; } void solve() { int i, j; ll sum = 0, prod = 1; ll maxl = LLONG_MIN, minl = LLONG_MAX; int maxi = INT_MIN, mini = INT_MAX; ll n, k; cin >> n >> k; vll a(n); for (auto &x : a) cin >> x; if (k == 0) { cout << *max_element(all(a)) << endl; re; } ll l, r; l = 1; r = 1e9; ll ans; while (l <= r) { ll mid = (l + r) / 2; if (cost(mid, a) <= k) { ans = mid; r = mid - 1; } else { l = mid + 1; } } cout << ans << endl; } int32_t main() { FAST; int t = 1; while (t--) { solve(); } }
replace
221
222
221
222
0
p02598
C++
Runtime Error
/*COMPETITIVE PROGRAMMING C++ TEMPLATE */ #include <algorithm> #include <climits> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> #define all(x) x.begin(), x.end() #define debug(x) cout << #x << " = " << x << "\n" #define MOD 998244353 const long double PI = 3.141592653589793236L; typedef long long int ll; typedef long double ld; using namespace std; bool check(ll ans, vector<ll> &a, ll k) { ll count = 0; int n = a.size(); for (int i = 0; i < n; i++) { count += a[i] / ans - 1; if (a[i] % ans) { count++; } } if (count <= k) { return true; } return false; } void solve() { ll n, k; cin >> n >> k; vector<ll> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } ll lo = 0; ll high = 1e9; ll ans = high; while (lo <= high) { ll mid = lo + (high - lo) / 2; bool is_valid = check(mid, a, k); if (is_valid) { ans = mid; high = mid - 1; } else { lo = mid + 1; } } cout << ans << "\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int T = 1; // cin >> T; while (T--) { solve(); } return 0; }
/*COMPETITIVE PROGRAMMING C++ TEMPLATE */ #include <algorithm> #include <climits> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> #define all(x) x.begin(), x.end() #define debug(x) cout << #x << " = " << x << "\n" #define MOD 998244353 const long double PI = 3.141592653589793236L; typedef long long int ll; typedef long double ld; using namespace std; bool check(ll ans, vector<ll> &a, ll k) { if (ans == 0) { return false; } ll count = 0; int n = a.size(); for (int i = 0; i < n; i++) { count += a[i] / ans - 1; if (a[i] % ans) { count++; } } if (count <= k) { return true; } return false; } void solve() { ll n, k; cin >> n >> k; vector<ll> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } ll lo = 0; ll high = 1e9; ll ans = high; while (lo <= high) { ll mid = lo + (high - lo) / 2; bool is_valid = check(mid, a, k); if (is_valid) { ans = mid; high = mid - 1; } else { lo = mid + 1; } } cout << ans << "\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int T = 1; // cin >> T; while (T--) { solve(); } return 0; }
insert
28
28
28
33
0
p02598
C++
Runtime Error
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <bitset> // bitset #include <cctype> // isupper, islower, isdigit, toupper, tolower #include <cmath> #include <cstdint> // int64_t, int*_t #include <cstdio> // printf #include <deque> // deque #include <iomanip> #include <iostream> #include <limits> #include <map> // map #include <numeric> #include <queue> // queue, priority_queue #include <set> // set #include <stack> // stack #include <stdio.h> #include <string> // string, to_string, stoi #include <tuple> // tuple, make_tuple #include <unordered_map> // unordered_map #include <unordered_set> // unordered_set #include <utility> // pair, make_pair #include <vector> // vector using namespace std; using ll = long long; #define rep(i, n) for (long long i = 0; i < (long long)(n); i++) ll Max(ll(a), ll(b), ll(c)) { return max(max(a, b), c); } ll Min(ll(a), ll(b), ll(c)) { return min(min(a, b), c); } vector<int> a = {1, 14, 32, 51, 51, 51, 243, 419, 750, 910}; ll kai(vector<ll> A, ll key) { ll an = 0; rep(i, A.size()) { an += (A.at(i) - 1) / key; } return an; } // index が条件を満たすかどうか bool isOK(int index, vector<ll> A, int K) { if (kai(A, index) <= K) return true; else return false; } // 汎用的な二分探索のテンプレ int binary_search(ll MA, vector<ll> A, ll K) { int left = -1; // 「index = 0」が条件を満たすこともあるので、初期値は -1 int right = MA; // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は // a.size() /* どんな二分探索でもここの書き方を変えずにできる! */ while (right - left > 1) { int mid = left + (right - left) / 2; if (isOK(mid, A, K)) right = mid; else left = mid; } /* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */ return right; } int main() { ll N, MA = 0, K; cin >> N >> K; vector<ll> A(N); rep(i, N) { cin >> A.at(i); MA = max(MA, A.at(i)); } int key = 0; int AN = binary_search(MA, A, K); cout << AN << endl; }
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <bitset> // bitset #include <cctype> // isupper, islower, isdigit, toupper, tolower #include <cmath> #include <cstdint> // int64_t, int*_t #include <cstdio> // printf #include <deque> // deque #include <iomanip> #include <iostream> #include <limits> #include <map> // map #include <numeric> #include <queue> // queue, priority_queue #include <set> // set #include <stack> // stack #include <stdio.h> #include <string> // string, to_string, stoi #include <tuple> // tuple, make_tuple #include <unordered_map> // unordered_map #include <unordered_set> // unordered_set #include <utility> // pair, make_pair #include <vector> // vector using namespace std; using ll = long long; #define rep(i, n) for (long long i = 0; i < (long long)(n); i++) ll Max(ll(a), ll(b), ll(c)) { return max(max(a, b), c); } ll Min(ll(a), ll(b), ll(c)) { return min(min(a, b), c); } vector<int> a = {1, 14, 32, 51, 51, 51, 243, 419, 750, 910}; ll kai(vector<ll> A, ll key) { ll an = 0; rep(i, A.size()) { an += (A.at(i) - 1) / key; } return an; } // index が条件を満たすかどうか bool isOK(int index, vector<ll> A, int K) { if (kai(A, index) <= K) return true; else return false; } // 汎用的な二分探索のテンプレ int binary_search(ll MA, vector<ll> A, ll K) { int left = 0; // 「index = 0」が条件を満たすこともあるので、初期値は -1 int right = MA; // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は // a.size() /* どんな二分探索でもここの書き方を変えずにできる! */ while (right - left > 1) { int mid = left + (right - left) / 2; if (isOK(mid, A, K)) right = mid; else left = mid; } /* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */ return right; } int main() { ll N, MA = 0, K; cin >> N >> K; vector<ll> A(N); rep(i, N) { cin >> A.at(i); MA = max(MA, A.at(i)); } int key = 0; int AN = binary_search(MA, A, K); cout << AN << endl; }
replace
44
45
44
45
0
p02598
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cmath> #include <complex> #include <ctime> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef int itn; const ll LINF = 1e18; const int INF = 1e9; // マクロ定義 #define vvint(vec, n, m, l) \ vector<vector<int>> vec(n, vector<int>(m, l)); // lで初期化 #define vvll(vec, n, m, l) vector<vector<ll>> vec(n, vector<ll>(m, l)); #define vint vector<int> #define pint pair<int, int> #define rep(i, a) for (ll i = 0; i < (a); i++) #define all(x) (x).begin(), (x).end() #define debug system("pause") // デバッグ用 #define ret return 0 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; } using Graph = vector<vector<ll>>; #define ketasitei setprecision(15) // 15桁表示 const ll MOD = 1000000007; const double PI = 3.1415926535897932; bool isOK(ll x, ll k, vector<ll> a) { ll sum = 0; rep(i, a.size()) { sum += (a[i] + x - 1) / x - 1; } if (sum <= k) return true; return false; } int main(void) { cin.tie(0); ios::sync_with_stdio(false); ll n, k; cin >> n >> k; vector<ll> a(n); rep(i, n) { cin >> a[i]; } ll ok = 1000000001; ll ng = -1; while (abs(ok - ng) > 1) { ll mid = (ok + ng) / 2; if (isOK(mid, k, a)) { ok = mid; } else { ng = mid; } } cout << ok << endl; // ll n; // ll bits = (1 << n) - 1; ////全部0の場合も調べたいのなら条件を変更するか、別途その分だけプログラムを書く // while (bits) //{ // ll tmp = bits; // for (int i = 0; i < n; i++) // { // if ((tmp >> i) & 1) // { // func(); // } // else // { // } // } // bits--; //} return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <complex> #include <ctime> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef int itn; const ll LINF = 1e18; const int INF = 1e9; // マクロ定義 #define vvint(vec, n, m, l) \ vector<vector<int>> vec(n, vector<int>(m, l)); // lで初期化 #define vvll(vec, n, m, l) vector<vector<ll>> vec(n, vector<ll>(m, l)); #define vint vector<int> #define pint pair<int, int> #define rep(i, a) for (ll i = 0; i < (a); i++) #define all(x) (x).begin(), (x).end() #define debug system("pause") // デバッグ用 #define ret return 0 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; } using Graph = vector<vector<ll>>; #define ketasitei setprecision(15) // 15桁表示 const ll MOD = 1000000007; const double PI = 3.1415926535897932; bool isOK(ll x, ll k, vector<ll> a) { ll sum = 0; rep(i, a.size()) { sum += (a[i] + x - 1) / x - 1; } if (sum <= k) return true; return false; } int main(void) { cin.tie(0); ios::sync_with_stdio(false); ll n, k; cin >> n >> k; vector<ll> a(n); rep(i, n) { cin >> a[i]; } ll ok = 1000000001; ll ng = 0; while (abs(ok - ng) > 1) { ll mid = (ok + ng) / 2; if (isOK(mid, k, a)) { ok = mid; } else { ng = mid; } } cout << ok << endl; // ll n; // ll bits = (1 << n) - 1; ////全部0の場合も調べたいのなら条件を変更するか、別途その分だけプログラムを書く // while (bits) //{ // ll tmp = bits; // for (int i = 0; i < n; i++) // { // if ((tmp >> i) & 1) // { // func(); // } // else // { // } // } // bits--; //} return 0; }
replace
75
76
75
76
0
p02598
C++
Runtime Error
#pragma region RegionDefs #include <bits/stdc++.h> #define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define reps(i, l, r) for (int i = (l), i##_len = (r); i < i##_len; ++i) #define repr(i, l, r) for (int i = (r)-1, i##_left = (l); i >= i##_left; --i) #define all(x) begin(x), end(x) using namespace std; typedef long long ll; const ll INF = 1e9; template <class T = ll> using V = vector<T>; template <class T = ll> using PQ = priority_queue<T>; template <class T = ll> using PQG = priority_queue<T, V<T>, greater<T>>; const ll MOD = 1000000007LL; void in() {} template <class Head, class... Tail> void in(Head &&head, Tail &&...tail) { cin >> head; in(move(tail)...); } #define IN(...) \ ll __VA_ARGS__; \ in(__VA_ARGS__) #define INS(T, ...) \ T __VA_ARGS__; \ in(__VA_ARGS__) #define VIN(T, v, n) \ V<T> v(n); \ for (auto &_elem : v) \ cin >> _elem 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 (a > b) { a = b; return 1; } return 0; } template <class T> string join(vector<T> &v, string delim = "") { ostringstream os; rep(i, v.size()) i ? os << delim << v[i] : os << v[0]; return os.str(); } #pragma endregion RegionDefs // index が条件を満たすかどうか bool f(vector<ll> &a, int len, int k) { rep(i, a.size()) { k -= (a[i] + len - 1) / len - 1; } return k >= 0; } // 汎用的な二分探索のテンプレ。[s, t)からf(x)=trueとなる最小のxを探す int meguru_search(vector<ll> &a, int s, int t, int k) { int ng = s - 1; int ok = t; while (abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if (f(a, mid, k)) ok = mid; else ng = mid; } // okがtなら全ての要素でfalse // okがsなら全ての要素でtrue return ok; } void solve() { IN(n, k); VIN(ll, a, n); ll res = meguru_search(a, 0, 1000000009LL, k); cout << res << endl; } int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); cout << setprecision(numeric_limits<double>::max_digits10); solve(); return 0; }
#pragma region RegionDefs #include <bits/stdc++.h> #define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define reps(i, l, r) for (int i = (l), i##_len = (r); i < i##_len; ++i) #define repr(i, l, r) for (int i = (r)-1, i##_left = (l); i >= i##_left; --i) #define all(x) begin(x), end(x) using namespace std; typedef long long ll; const ll INF = 1e9; template <class T = ll> using V = vector<T>; template <class T = ll> using PQ = priority_queue<T>; template <class T = ll> using PQG = priority_queue<T, V<T>, greater<T>>; const ll MOD = 1000000007LL; void in() {} template <class Head, class... Tail> void in(Head &&head, Tail &&...tail) { cin >> head; in(move(tail)...); } #define IN(...) \ ll __VA_ARGS__; \ in(__VA_ARGS__) #define INS(T, ...) \ T __VA_ARGS__; \ in(__VA_ARGS__) #define VIN(T, v, n) \ V<T> v(n); \ for (auto &_elem : v) \ cin >> _elem 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 (a > b) { a = b; return 1; } return 0; } template <class T> string join(vector<T> &v, string delim = "") { ostringstream os; rep(i, v.size()) i ? os << delim << v[i] : os << v[0]; return os.str(); } #pragma endregion RegionDefs // index が条件を満たすかどうか bool f(vector<ll> &a, int len, int k) { rep(i, a.size()) { k -= (a[i] + len - 1) / len - 1; } return k >= 0; } // 汎用的な二分探索のテンプレ。[s, t)からf(x)=trueとなる最小のxを探す int meguru_search(vector<ll> &a, int s, int t, int k) { int ng = s - 1; int ok = t; while (abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if (f(a, mid, k)) ok = mid; else ng = mid; } // okがtなら全ての要素でfalse // okがsなら全ての要素でtrue return ok; } void solve() { IN(n, k); VIN(ll, a, n); ll res = meguru_search(a, 1, 1000000009LL, k); cout << res << endl; } int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); cout << setprecision(numeric_limits<double>::max_digits10); solve(); return 0; }
replace
74
75
74
75
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define eb emplace_back #define ii pair<int, int> #define OK (cerr << "OK" << endl) #define debug(x) cerr << #x " = " << (x) << endl #define ff first #define ss second #define int long long #define tt tuple<int, int, int> #define all(x) x.begin(), x.end() #define vvi vector<vector<int>> #define vvii vector<vector<pair<int, int>>> #define Mat(n, m, v) vector<vector<int>>(n, vector<int>(m, v)) #define endl '\n' constexpr int INF = 2e18; constexpr int MOD = 1e9 + 7; constexpr int MAXN = 2e5 + 3; bool check(int g, vector<int> &arr, int k) { int c = 0; for (int x : arr) { c += (x - 1) / g; } return (c <= k); } // #define MULTIPLE_TEST_CASES void solve() { int n; cin >> n; int k; cin >> k; vector<int> arr(n); for (int &x : arr) cin >> x; int l = 0, r = 2e9; int ans = -1; while (l <= r) { int mid = (l + r) / 2; if (check(mid, arr, k)) { ans = mid; r = mid - 1; } else { l = mid + 1; } } cout << ans << endl; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; #ifdef MULTIPLE_TEST_CASES cin >> t; #endif while (t--) solve(); }
#include <bits/stdc++.h> using namespace std; #define eb emplace_back #define ii pair<int, int> #define OK (cerr << "OK" << endl) #define debug(x) cerr << #x " = " << (x) << endl #define ff first #define ss second #define int long long #define tt tuple<int, int, int> #define all(x) x.begin(), x.end() #define vvi vector<vector<int>> #define vvii vector<vector<pair<int, int>>> #define Mat(n, m, v) vector<vector<int>>(n, vector<int>(m, v)) #define endl '\n' constexpr int INF = 2e18; constexpr int MOD = 1e9 + 7; constexpr int MAXN = 2e5 + 3; bool check(int g, vector<int> &arr, int k) { int c = 0; for (int x : arr) { c += (x - 1) / g; } return (c <= k); } // #define MULTIPLE_TEST_CASES void solve() { int n; cin >> n; int k; cin >> k; vector<int> arr(n); for (int &x : arr) cin >> x; int l = 1, r = 2e9; int ans = 0; while (l <= r) { int mid = (l + r) / 2; if (check(mid, arr, k)) { ans = mid; r = mid - 1; } else { l = mid + 1; } } cout << ans << endl; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; #ifdef MULTIPLE_TEST_CASES cin >> t; #endif while (t--) solve(); }
replace
42
44
42
44
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> // #include <boost/multiprecision/cpp_int.hpp> #define int long long #define inf 1000000007 // #define inf 998244353 #define pa pair<int, int> #define ll long long #define pal pair<double, double> #define ppap pair<pa, int> #define PI 3.14159265358979323846 #define paa pair<int, char> #define mp make_pair #define pb push_back #define EPS (1e-8) int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1}; int dy[8] = {1, 0, -1, 0, -1, 1, 1, -1}; using namespace std; class pa3 { public: int x; int y, z; pa3(int x = 0, int y = 0, int z = 0) : x(x), y(y), z(z) {} bool operator<(const pa3 &p) const { if (x != p.x) return x < p.x; if (y != p.y) return y < p.y; return z < p.z; // return x != p.x ? x<p.x: y<p.y; } bool operator>(const pa3 &p) const { if (x != p.x) return x > p.x; if (y != p.y) return y > p.y; return z > p.z; // return x != p.x ? x<p.x: y<p.y; } bool operator==(const pa3 &p) const { return x == p.x && y == p.y && z == p.z; } bool operator!=(const pa3 &p) const { return !(x == p.x && y == p.y && z == p.z); } }; class pa4 { public: int x; int y, z, w; pa4(int x = 0, int y = 0, int z = 0, int w = 0) : x(x), y(y), z(z), w(w) {} bool operator<(const pa4 &p) const { if (x != p.x) return x < p.x; if (y != p.y) return y < p.y; if (z != p.z) return z < p.z; return w < p.w; // return x != p.x ? x<p.x: y<p.y; } bool operator>(const pa4 &p) const { if (x != p.x) return x > p.x; if (y != p.y) return y > p.y; if (z != p.z) return z > p.z; return w > p.w; // return x != p.x ? x<p.x: y<p.y; } bool operator==(const pa4 &p) const { return x == p.x && y == p.y && z == p.z && w == p.w; } }; class pa2 { public: int x, y; pa2(int x = 0, int y = 0) : x(x), y(y) {} pa2 operator+(pa2 p) { return pa2(x + p.x, y + p.y); } pa2 operator-(pa2 p) { return pa2(x - p.x, y - p.y); } bool operator<(const pa2 &p) const { return y != p.y ? y < p.y : x < p.x; } bool operator>(const pa2 &p) const { return x != p.x ? x < p.x : y < p.y; } bool operator==(const pa2 &p) const { return abs(x - p.x) == 0 && abs(y - p.y) == 0; } bool operator!=(const pa2 &p) const { return !(abs(x - p.x) == 0 && abs(y - p.y) == 0); } }; string itos(int i) { ostringstream s; s << i; return s.str(); } int Gcd(int v, int b) { if (v == 0) return b; if (b == 0) return v; if (v > b) return Gcd(b, v); if (v == b) return b; if (b % v == 0) return v; return Gcd(v, b % v); } int mod; int extgcd(int a, int b, int &x, int &y) { if (b == 0) { x = 1; y = 0; return a; } int d = extgcd(b, a % b, y, x); y -= a / b * x; return d; } pa operator+(const pa &l, const pa &r) { return {l.first + r.first, l.second + r.second}; } pa operator-(const pa &l, const pa &r) { return {l.first - r.first, l.second - r.second}; } int beki(int wa, int rr, int warukazu) { if (rr == 0) return 1 % warukazu; if (rr == 1) return wa % warukazu; wa %= warukazu; if (rr % 2 == 1) return ((ll)beki(wa, rr - 1, warukazu) * (ll)wa) % warukazu; ll zx = beki(wa, rr / 2, warukazu); return (zx * zx) % warukazu; } int pr[100000]; int inv[100000]; int comb(int nn, int rr) { if (rr < 0 || rr > nn || nn < 0) return 0; int r = pr[nn] * inv[rr]; r %= mod; r *= inv[nn - rr]; r %= mod; return r; } void gya(int ert) { pr[0] = 1; for (int i = 1; i <= ert; i++) { pr[i] = ((ll)pr[i - 1] * i) % mod; } inv[ert] = beki(pr[ert], mod - 2, mod); for (int i = ert - 1; i >= 0; i--) { inv[i] = (ll)inv[i + 1] * (i + 1) % mod; } } // cin.tie(0); // ios::sync_with_stdio(false); // priority_queue<pa3,vector<pa3>,greater<pa3>> pq; // sort(ve.begin(),ve.end(),greater<int>()); // mt19937(clock_per_sec); // mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()) ; int a[200020] = {}; int n, k; bool ch(int r) { int ans = 0; for (int i = 0; i < n; i++) { int g = (a[i]) / r + !!(a[i] % r) - 1; ans += g; } return ans <= k; } void solve() { cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; int ue = inf; int si = 0; for (int i = 0; i < 100; i++) { int me = (ue + si) / 2.0; if (ch(me)) ue = me; else si = me; } cout << ue << endl; } signed main() { cin.tie(0); ios::sync_with_stdio(false); int n = 1; // cin>>n; for (int i = 0; i < n; i++) solve(); return 0; }
#include <bits/stdc++.h> // #include <boost/multiprecision/cpp_int.hpp> #define int long long #define inf 1000000007 // #define inf 998244353 #define pa pair<int, int> #define ll long long #define pal pair<double, double> #define ppap pair<pa, int> #define PI 3.14159265358979323846 #define paa pair<int, char> #define mp make_pair #define pb push_back #define EPS (1e-8) int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1}; int dy[8] = {1, 0, -1, 0, -1, 1, 1, -1}; using namespace std; class pa3 { public: int x; int y, z; pa3(int x = 0, int y = 0, int z = 0) : x(x), y(y), z(z) {} bool operator<(const pa3 &p) const { if (x != p.x) return x < p.x; if (y != p.y) return y < p.y; return z < p.z; // return x != p.x ? x<p.x: y<p.y; } bool operator>(const pa3 &p) const { if (x != p.x) return x > p.x; if (y != p.y) return y > p.y; return z > p.z; // return x != p.x ? x<p.x: y<p.y; } bool operator==(const pa3 &p) const { return x == p.x && y == p.y && z == p.z; } bool operator!=(const pa3 &p) const { return !(x == p.x && y == p.y && z == p.z); } }; class pa4 { public: int x; int y, z, w; pa4(int x = 0, int y = 0, int z = 0, int w = 0) : x(x), y(y), z(z), w(w) {} bool operator<(const pa4 &p) const { if (x != p.x) return x < p.x; if (y != p.y) return y < p.y; if (z != p.z) return z < p.z; return w < p.w; // return x != p.x ? x<p.x: y<p.y; } bool operator>(const pa4 &p) const { if (x != p.x) return x > p.x; if (y != p.y) return y > p.y; if (z != p.z) return z > p.z; return w > p.w; // return x != p.x ? x<p.x: y<p.y; } bool operator==(const pa4 &p) const { return x == p.x && y == p.y && z == p.z && w == p.w; } }; class pa2 { public: int x, y; pa2(int x = 0, int y = 0) : x(x), y(y) {} pa2 operator+(pa2 p) { return pa2(x + p.x, y + p.y); } pa2 operator-(pa2 p) { return pa2(x - p.x, y - p.y); } bool operator<(const pa2 &p) const { return y != p.y ? y < p.y : x < p.x; } bool operator>(const pa2 &p) const { return x != p.x ? x < p.x : y < p.y; } bool operator==(const pa2 &p) const { return abs(x - p.x) == 0 && abs(y - p.y) == 0; } bool operator!=(const pa2 &p) const { return !(abs(x - p.x) == 0 && abs(y - p.y) == 0); } }; string itos(int i) { ostringstream s; s << i; return s.str(); } int Gcd(int v, int b) { if (v == 0) return b; if (b == 0) return v; if (v > b) return Gcd(b, v); if (v == b) return b; if (b % v == 0) return v; return Gcd(v, b % v); } int mod; int extgcd(int a, int b, int &x, int &y) { if (b == 0) { x = 1; y = 0; return a; } int d = extgcd(b, a % b, y, x); y -= a / b * x; return d; } pa operator+(const pa &l, const pa &r) { return {l.first + r.first, l.second + r.second}; } pa operator-(const pa &l, const pa &r) { return {l.first - r.first, l.second - r.second}; } int beki(int wa, int rr, int warukazu) { if (rr == 0) return 1 % warukazu; if (rr == 1) return wa % warukazu; wa %= warukazu; if (rr % 2 == 1) return ((ll)beki(wa, rr - 1, warukazu) * (ll)wa) % warukazu; ll zx = beki(wa, rr / 2, warukazu); return (zx * zx) % warukazu; } int pr[100000]; int inv[100000]; int comb(int nn, int rr) { if (rr < 0 || rr > nn || nn < 0) return 0; int r = pr[nn] * inv[rr]; r %= mod; r *= inv[nn - rr]; r %= mod; return r; } void gya(int ert) { pr[0] = 1; for (int i = 1; i <= ert; i++) { pr[i] = ((ll)pr[i - 1] * i) % mod; } inv[ert] = beki(pr[ert], mod - 2, mod); for (int i = ert - 1; i >= 0; i--) { inv[i] = (ll)inv[i + 1] * (i + 1) % mod; } } // cin.tie(0); // ios::sync_with_stdio(false); // priority_queue<pa3,vector<pa3>,greater<pa3>> pq; // sort(ve.begin(),ve.end(),greater<int>()); // mt19937(clock_per_sec); // mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()) ; int a[200020] = {}; int n, k; bool ch(int r) { int ans = 0; for (int i = 0; i < n; i++) { int g = (a[i]) / r + !!(a[i] % r) - 1; ans += g; } return ans <= k; } void solve() { cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; int ue = inf; int si = 0; while (ue - si > 1) { int me = (ue + si) / 2; if (ch(me)) ue = me; else si = me; } cout << ue << endl; } signed main() { cin.tie(0); ios::sync_with_stdio(false); int n = 1; // cin>>n; for (int i = 0; i < n; i++) solve(); return 0; }
replace
195
197
195
197
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef vector<int> vi; typedef long long ll; #define F first #define S second #define PB push_back #define MP make_pair #define REP(i, a, b) for (int i = a; i <= b; i++) #define pmod 1000000007 #define INF 1000000000000000000 #define pi atan(1) * 4 #define modi 1000000 void solve() { ll n, k; cin >> n >> k; ll a[n]; ll sum = 0; for (ll i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } ll mini = sum; ll ini = 0, fin = sum; bool can; while (ini <= fin) { ll med = (fin + ini) / 2; ll counter = 0; for (ll i = 0; i < n; i++) { counter += (((a[i] + med - 1) / med) - 1); } if (counter <= k) { mini = min(mini, med); fin = med - 1; } else { ini = med + 1; } } cout << mini << endl; } int main() { ifstream fin("text.in"); ofstream fout("text.out"); ll t = 1; while (t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef vector<int> vi; typedef long long ll; #define F first #define S second #define PB push_back #define MP make_pair #define REP(i, a, b) for (int i = a; i <= b; i++) #define pmod 1000000007 #define INF 1000000000000000000 #define pi atan(1) * 4 #define modi 1000000 void solve() { ll n, k; cin >> n >> k; ll a[n]; ll sum = 0; for (ll i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } ll mini = sum; ll ini = 1, fin = sum; bool can; while (ini <= fin) { ll med = (fin + ini) / 2; ll counter = 0; for (ll i = 0; i < n; i++) { counter += (((a[i] + med - 1) / med) - 1); } if (counter <= k) { mini = min(mini, med); fin = med - 1; } else { ini = med + 1; } } cout << mini << endl; } int main() { ifstream fin("text.in"); ofstream fout("text.out"); ll t = 1; while (t--) solve(); return 0; }
replace
32
33
32
33
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i <= (int)(n); i++) int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; vector<int> a(n); rep(i, n) cin >> a[i]; ll ub = 2e9; ll lb = 0; rep(i, 100) { ll mid = (ub + lb) / 2; ll tans = 0; rep(j, n) { if (a[j] > mid) { tans += (a[j] + mid - 1) / mid - 1; } } if (tans > k) lb = mid; else ub = mid; } cout << ub << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i <= (int)(n); i++) int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; vector<int> a(n); rep(i, n) cin >> a[i]; ll ub = 2e9; ll lb = 0; rep(i, 100) { ll mid = (ub + lb) / 2; if (mid == 0) break; ll tans = 0; rep(j, n) { if (a[j] > mid) { tans += (a[j] + mid - 1) / mid - 1; } } if (tans > k) lb = mid; else ub = mid; } cout << ub << endl; return 0; }
insert
18
18
18
20
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long int ll; #define mod 1000000007 #define all(v) v.begin(), v.end() #define pb push_back #define size(v) (int)v.size() #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) ll power_mod(ll a, ll x) { if (x == 0) return 1; ll y = power_mod(a, x / 2); ll ans = (y * y) % mod; if (x % 2) ans = (ans * a) % mod; return ans; } ll inv(ll a) { return power_mod(a, mod - 2); } ll power(ll a, ll x) { if (x == 0) return 1; ll y = power(a, x / 2); ll ans = (y * y); if (x % 2) ans *= a; return ans; } int main() { fast; ll n, k; cin >> n >> k; vector<ll> a(n, 0); for (ll i = 0; i < n; i++) { cin >> a[i]; } ll lo = 0, hi = 1000000000; ll ans = hi; while (lo <= hi) { ll mid = (lo + hi) / 2; if (mid == 0) { if (lo == hi) { break; } lo = 1; } ll cut_req = 0; for (auto i : a) { ll curr = i; if (curr < mid) continue; cut_req += ((curr - 1) / mid); } // printf("%0.9lf ",mid); // cout << cut_req << endl; if (cut_req > k) { lo = mid + 1; } else { ans = min(ans, mid); hi = mid - 1; } } ll res = ans; // printf("%0.9lf\n",ans); cout << res << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; #define mod 1000000007 #define all(v) v.begin(), v.end() #define pb push_back #define size(v) (int)v.size() #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) ll power_mod(ll a, ll x) { if (x == 0) return 1; ll y = power_mod(a, x / 2); ll ans = (y * y) % mod; if (x % 2) ans = (ans * a) % mod; return ans; } ll inv(ll a) { return power_mod(a, mod - 2); } ll power(ll a, ll x) { if (x == 0) return 1; ll y = power(a, x / 2); ll ans = (y * y); if (x % 2) ans *= a; return ans; } int main() { fast; ll n, k; cin >> n >> k; vector<ll> a(n, 0); for (ll i = 0; i < n; i++) { cin >> a[i]; } ll lo = 0, hi = 1000000000; ll ans = hi; while (lo <= hi) { ll mid = (lo + hi) / 2; if (mid == 0) { if (lo == hi) { break; } mid = 1; } ll cut_req = 0; for (auto i : a) { ll curr = i; if (curr < mid) continue; cut_req += ((curr - 1) / mid); } // printf("%0.9lf ",mid); // cout << cut_req << endl; if (cut_req > k) { lo = mid + 1; } else { ans = min(ans, mid); hi = mid - 1; } } ll res = ans; // printf("%0.9lf\n",ans); cout << res << endl; }
replace
52
53
52
53
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int INF = 1e9; int main() { int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } int left = -1; int right = INF; while (right - left > 1) { int mid = (right + left) / 2; ll num = 0; for (int i = 0; i < n; ++i) { if (a[i] % mid == 0) num += a[i] / mid - 1; else num += a[i] / mid; } if (num <= k) right = mid; else left = mid; } cout << right << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int INF = 1e9; int main() { int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } int left = 0; int right = INF; while (right - left > 1) { int mid = (right + left) / 2; ll num = 0; for (int i = 0; i < n; ++i) { if (a[i] % mid == 0) num += a[i] / mid - 1; else num += a[i] / mid; } if (num <= k) right = mid; else left = mid; } cout << right << endl; }
replace
16
17
16
17
0
p02598
C++
Runtime Error
#include <algorithm> #include <bitset> #include <functional> #include <iostream> #include <map> #include <math.h> #include <queue> #include <random> #include <set> #include <stack> #include <stdio.h> #include <string> #include <utility> #include <vector> using namespace std; #define N (1000000000 + 7) // #define N 998244353 #define INF 1e16 typedef long long ll; typedef pair<int, int> P; typedef pair<int, P> Q; const int inf = (int)1e9; ll gcd(ll a, ll b) { if (b > a) { ll tmp = b; b = a; a = tmp; } if (a % b == 0) return b; else return gcd(b, a % b); } ll n, k; vector<ll> a(n); bool check(ll x) { ll t = 0; for (int i = 0; i < n; i++) { if (a[i] % x == 0) t += a[i] / x - 1; else t += a[i] / x; } return (t <= k); } int main(void) { n, k; cin >> n >> k; a.resize(n); ll ng = -1, ok = 0; for (int i = 0; i < n; i++) { cin >> a[i]; ok = max(ok, a[i]); } while (ok - ng > 1) { ll mid = (ok + ng) / 2; if (check(mid)) ok = mid; else ng = mid; } cout << ok << endl; return 0; }
#include <algorithm> #include <bitset> #include <functional> #include <iostream> #include <map> #include <math.h> #include <queue> #include <random> #include <set> #include <stack> #include <stdio.h> #include <string> #include <utility> #include <vector> using namespace std; #define N (1000000000 + 7) // #define N 998244353 #define INF 1e16 typedef long long ll; typedef pair<int, int> P; typedef pair<int, P> Q; const int inf = (int)1e9; ll gcd(ll a, ll b) { if (b > a) { ll tmp = b; b = a; a = tmp; } if (a % b == 0) return b; else return gcd(b, a % b); } ll n, k; vector<ll> a(n); bool check(ll x) { ll t = 0; if (x == 0) { return false; } for (int i = 0; i < n; i++) { if (a[i] % x == 0) t += a[i] / x - 1; else t += a[i] / x; } return (t <= k); } int main(void) { n, k; cin >> n >> k; a.resize(n); ll ng = -1, ok = 0; for (int i = 0; i < n; i++) { cin >> a[i]; ok = max(ok, a[i]); } while (ok - ng > 1) { ll mid = (ok + ng) / 2; if (check(mid)) ok = mid; else ng = mid; } cout << ok << endl; return 0; }
insert
41
41
41
44
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int n, k, i, mini, maxi = 1e9; vector<int> A; bool check(int tar) { int j, cur = 0; for (j = 0; j < n; j++) { cur += (A[j] - 1) / tar; } if (cur > k) return false; else return true; } int main() { cin >> n >> k; for (i = 0; i < n; i++) { int a; cin >> a; A.push_back(a); } while (mini < maxi) { int mid = mini + maxi >> 1; if (mini == mid) { if (!check(mini)) mini = maxi; else maxi = mini; } else { if (check(mid)) maxi = mid; else mini = mid + 1; } } cout << mini; return 0; }
#include <bits/stdc++.h> using namespace std; int n, k, i, mini = 1, maxi = 1e9; vector<int> A; bool check(int tar) { int j, cur = 0; for (j = 0; j < n; j++) { cur += (A[j] - 1) / tar; } if (cur > k) return false; else return true; } int main() { cin >> n >> k; for (i = 0; i < n; i++) { int a; cin >> a; A.push_back(a); } while (mini < maxi) { int mid = mini + maxi >> 1; if (mini == mid) { if (!check(mini)) mini = maxi; else maxi = mini; } else { if (check(mid)) maxi = mid; else mini = mid + 1; } } cout << mini; return 0; }
replace
2
3
2
3
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <functional> using namespace std; using namespace __gnu_pbds; #define ll long long #define mk make_pair template <class key, class cmp = std::less<key>> using ordered_set = tree<key, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>; const ll mod = 1e9 + 7; /* if you have any question about any part of my code, please don't shy to ask anytime :) */ ll n, k; ll x[200005]; bool get(ll mid) { ll cnt = 0; for (int i = 0; i < n; i++) { cnt += (x[i] - 1) / mid; } return cnt <= k; } void solve() { cin >> n >> k; for (int i = 0; i < n; i++) { cin >> x[i]; } ll st = 0, en = 1e9; ll ans = 0; while (st <= en) { ll mid = (st + en) >> 1; if (get(mid)) { ans = mid; en = mid - 1; } else { st = mid + 1; } } cout << ans << endl; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); // ll t; // cin >> t; // while (t--) // { // solve(); // } solve(); return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <functional> using namespace std; using namespace __gnu_pbds; #define ll long long #define mk make_pair template <class key, class cmp = std::less<key>> using ordered_set = tree<key, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>; const ll mod = 1e9 + 7; /* if you have any question about any part of my code, please don't shy to ask anytime :) */ ll n, k; ll x[200005]; bool get(ll mid) { ll cnt = 0; for (int i = 0; i < n; i++) { cnt += (x[i] - 1) / mid; } return cnt <= k; } void solve() { cin >> n >> k; for (int i = 0; i < n; i++) { cin >> x[i]; } ll st = 1, en = 1e9; ll ans = 0; while (st <= en) { ll mid = (st + en) >> 1; if (get(mid)) { ans = mid; en = mid - 1; } else { st = mid + 1; } } cout << ans << endl; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); // ll t; // cin >> t; // while (t--) // { // solve(); // } solve(); return 0; }
replace
38
39
38
39
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 &e : A) cin >> e; auto OK = [&](int x) -> bool { int cnt = 0; for (auto &a : A) { if (a == x) continue; cnt += (a / x); } return cnt <= K; }; int l = -1, r = 1e9; while (r - l > 1) { int c = (l + r) / 2; if (OK(c)) r = c; else l = c; } cout << r << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; vector<int> A(N); for (auto &e : A) cin >> e; auto OK = [&](int x) -> bool { int cnt = 0; for (auto &a : A) { if (a == x) continue; cnt += (a / x); } return cnt <= K; }; int l = 0, r = 1e9; while (r - l > 1) { int c = (l + r) / 2; if (OK(c)) r = c; else l = c; } cout << r << '\n'; return 0; }
replace
18
19
18
19
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> #define f first #define s second #define fore(i, a, b) for (int i = (a), ThxMK = (b); i < ThxMK; ++i) #define pb push_back #define all(s) begin(s), end(s) #define _ \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define sz(s) int(s.size()) #define ENDL '\n' using namespace std; typedef long double ld; typedef long long lli; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<lli> vl; typedef vector<ii> vii; typedef vector<vi> vvi; typedef vector<vl> vvl; #define deb(x) cout << #x ": " << (x) << endl; const int N = 1e3; const lli INF = 1e18; const lli MOD = 1e9 + 7; vi m; vi primes(1, 2); vector<vector<ld>> nk; void sieve() { m = vi(N + 1, 0); for (int i = 4; i < N; i += 2) m[i] = 1; for (int i = 3; i * i <= N; i += 2) if (!m[i]) for (int j = i * i; j < N; j += i) m[j] = 1; for (int i = 3; i < N; i += 2) if (!m[i]) primes.pb(i); } void pascal() { nk = vector<vector<ld>>(N, vector<ld>(N, 0.0)); fore(i, 0, N) nk[i][0] = nk[i][i] = 1.0; fore(i, 1, N) fore(j, 1, i) nk[i][j] = nk[i - 1][j - 1] + nk[i - 1][j]; } lli gcd(lli a, lli b) { return (b ? gcd(b, a % b) : a); } lli lcm(lli a, lli b) { if (a < b) swap(a, b); lli c = gcd(a, b); a /= c; return a * b; } int popcount(lli x) { return __builtin_popcountll(x); } lli poww(lli a, lli b) { lli res = 1; while (b) { if (b & 1) res = res * a; a = a * a; b /= 2; } return res; } lli powm(lli a, lli b, lli mod = MOD) { lli res = 1; while (b) { if (b & 1) res = (res * a) % mod; a = (a * a) % mod; b /= 2; } return res; } bool isPrime(lli x) { if (x == 1) return 0; for (auto i : primes) { if (i * i > x) return 1; if (x % i == 0) return 0; } return 1; } // ---- コーディングはここから! ('-')7 int main() { _ lli n, k; cin >> n >> k; vl v(n); fore(i, 0, n) cin >> v[i]; sort(all(v), greater<lli>()); lli L = 0, R = v[0], last = R; auto f = [&](lli mid) { lli r = 0; fore(i, 0, n) { if (v[i] <= mid) break; r += (v[i] / mid); if (v[i] % mid == 0) r--; } return r <= k; }; while (L <= R) { lli mid = (L + R) / 2; if (f(mid)) R = mid - 1, last = mid; else L = mid + 1; } cout << last << ENDL; }
#include <bits/stdc++.h> #define f first #define s second #define fore(i, a, b) for (int i = (a), ThxMK = (b); i < ThxMK; ++i) #define pb push_back #define all(s) begin(s), end(s) #define _ \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define sz(s) int(s.size()) #define ENDL '\n' using namespace std; typedef long double ld; typedef long long lli; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<lli> vl; typedef vector<ii> vii; typedef vector<vi> vvi; typedef vector<vl> vvl; #define deb(x) cout << #x ": " << (x) << endl; const int N = 1e3; const lli INF = 1e18; const lli MOD = 1e9 + 7; vi m; vi primes(1, 2); vector<vector<ld>> nk; void sieve() { m = vi(N + 1, 0); for (int i = 4; i < N; i += 2) m[i] = 1; for (int i = 3; i * i <= N; i += 2) if (!m[i]) for (int j = i * i; j < N; j += i) m[j] = 1; for (int i = 3; i < N; i += 2) if (!m[i]) primes.pb(i); } void pascal() { nk = vector<vector<ld>>(N, vector<ld>(N, 0.0)); fore(i, 0, N) nk[i][0] = nk[i][i] = 1.0; fore(i, 1, N) fore(j, 1, i) nk[i][j] = nk[i - 1][j - 1] + nk[i - 1][j]; } lli gcd(lli a, lli b) { return (b ? gcd(b, a % b) : a); } lli lcm(lli a, lli b) { if (a < b) swap(a, b); lli c = gcd(a, b); a /= c; return a * b; } int popcount(lli x) { return __builtin_popcountll(x); } lli poww(lli a, lli b) { lli res = 1; while (b) { if (b & 1) res = res * a; a = a * a; b /= 2; } return res; } lli powm(lli a, lli b, lli mod = MOD) { lli res = 1; while (b) { if (b & 1) res = (res * a) % mod; a = (a * a) % mod; b /= 2; } return res; } bool isPrime(lli x) { if (x == 1) return 0; for (auto i : primes) { if (i * i > x) return 1; if (x % i == 0) return 0; } return 1; } // ---- コーディングはここから! ('-')7 int main() { _ lli n, k; cin >> n >> k; vl v(n); fore(i, 0, n) cin >> v[i]; sort(all(v), greater<lli>()); lli L = 1, R = v[0], last = R; auto f = [&](lli mid) { lli r = 0; fore(i, 0, n) { if (v[i] <= mid) break; r += (v[i] / mid); if (v[i] % mid == 0) r--; } return r <= k; }; while (L <= R) { lli mid = (L + R) / 2; if (f(mid)) R = mid - 1, last = mid; else L = mid + 1; } cout << last << ENDL; }
replace
103
104
103
104
0
p02598
Python
Runtime Error
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10**9) INF = 1 << 60 MOD = 1000000007 def main(): N, K, *A = map(int, read().split()) ng = -1 ok = 10**9 while ok - ng > 1: mid = (ok + ng) // 2 res = 0 for a in A: res += (a + mid - 1) // mid - 1 if res <= K: ok = mid else: ng = mid print(ok) return if __name__ == "__main__": main()
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10**9) INF = 1 << 60 MOD = 1000000007 def main(): N, K, *A = map(int, read().split()) ng = 0 ok = 10**9 while ok - ng > 1: mid = (ok + ng) // 2 res = 0 for a in A: res += (a + mid - 1) // mid - 1 if res <= K: ok = mid else: ng = mid print(ok) return if __name__ == "__main__": main()
replace
13
14
13
14
0
p02598
Python
Time Limit Exceeded
def is_good(mid, key): return sum(count_cuts(a, mid) for a in A) <= key def binary_search(key): bad, good = 0, 10**16 while good - bad > 1: mid = (bad + good) // 2 if is_good(mid, key): good = mid else: bad = mid return good def count_cuts(a, unit): return (a + unit - 1) // unit - 1 N, K, *A = map(int, open(0).read().split()) print(binary_search(K))
def is_good(mid, key): return sum(count_cuts(a, mid) for a in A) <= key def binary_search(key): bad, good = 0, 2 * 10**14 + 1 while good - bad > 1: mid = (bad + good) // 2 if is_good(mid, key): good = mid else: bad = mid return good def count_cuts(a, unit): return (a + unit - 1) // unit - 1 N, K, *A = map(int, open(0).read().split()) print(binary_search(K))
replace
5
6
5
6
TLE
p02598
Python
Time Limit Exceeded
from sys import stdin import numpy as np n, k = map(int, stdin.readline().split()) a = np.array(stdin.readline().split(), dtype=np.int64) ng = 0 ok = 10**9 + 1 while ok - ng > 1: mid = (ok + ng) >> 1 if sum(0 - -b // mid - 1 for b in a) <= k: ok = mid else: ng = mid print(ok)
from sys import stdin import numpy as np n, k = map(int, stdin.readline().split()) a = np.array(stdin.readline().split(), dtype=np.int64) ng = 0 ok = 10**9 + 1 while ok - ng > 1: mid = (ok + ng) >> 1 if np.sum(0 - -a // mid - 1) <= k: ok = mid else: ng = mid print(ok)
replace
10
11
10
11
TLE
p02598
C++
Runtime Error
#include <iostream> using namespace std; bool able_check(long L, long *A, long N, long K); int main(void) { long N, K; cin >> N >> K; long *A = (long *)malloc(sizeof(long) * N); for (int i = 0; i < N; i++) { cin >> A[i]; } long min = 0; long max = 1000000010; while (max - min > 5) { long mid = (min + max) / 2; if (able_check(mid, A, N, K)) { max = mid; } else { min = mid; } } for (long i = min; i <= max; i++) { if (able_check(i, A, N, K)) { cout << i << endl; break; } } return 0; } bool able_check(long L, long *A, long N, long K) { long retval = 0; for (int i = 0; i < N; i++) { if (A[i] % L == 0) { retval += A[i] / L - 1; } else { retval += A[i] / L; } } return retval <= K; }
#include <iostream> using namespace std; bool able_check(long L, long *A, long N, long K); int main(void) { long N, K; cin >> N >> K; long *A = (long *)malloc(sizeof(long) * N); for (int i = 0; i < N; i++) { cin >> A[i]; } long min = 1; long max = 1000000010; while (max - min > 5) { long mid = (min + max) / 2; if (able_check(mid, A, N, K)) { max = mid; } else { min = mid; } } for (long i = min; i <= max; i++) { if (able_check(i, A, N, K)) { cout << i << endl; break; } } return 0; } bool able_check(long L, long *A, long N, long K) { long retval = 0; for (int i = 0; i < N; i++) { if (A[i] % L == 0) { retval += A[i] / L - 1; } else { retval += A[i] / L; } } return retval <= K; }
replace
12
13
12
13
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int N = 200003; int n, k; int a[N]; inline bool check(int x) { long long tot = 0; for (int i = 1; i <= n; i += 1) tot += a[i] / x + (a[i] % x != 0) - 1; return tot <= k; } int main() { cin >> n >> k; for (int i = 1; i <= n; i += 1) cin >> a[i]; int l = 0, r = 1000000001, ans = 0; while (l <= r) { int mid = (l + r) >> 1; if (check(mid)) ans = mid, r = mid - 1; else l = mid + 1; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; const int N = 200003; int n, k; int a[N]; inline bool check(int x) { long long tot = 0; for (int i = 1; i <= n; i += 1) tot += a[i] / x + (a[i] % x != 0) - 1; return tot <= k; } int main() { cin >> n >> k; for (int i = 1; i <= n; i += 1) cin >> a[i]; int l = 1, r = 1000000001, ans = 0; while (l <= r) { int mid = (l + r) >> 1; if (check(mid)) ans = mid, r = mid - 1; else l = mid + 1; } cout << ans << endl; }
replace
15
16
15
16
0
p02598
C++
Runtime Error
#include <cassert> #include <cctype> #include <cerrno> #include <cfloat> #include <ciso646> #include <climits> #include <clocale> #include <cmath> #include <csetjmp> #include <csignal> #include <cstdarg> #include <cstddef> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <ccomplex> #include <cfenv> #include <cinttypes> #include <cstdbool> #include <cstdint> #include <ctgmath> #include <cwchar> #include <cwctype> // C++ #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #include <array> #include <atomic> #include <chrono> #include <condition_variable> #include <forward_list> #include <future> #include <initializer_list> #include <mutex> #include <random> #include <ratio> #include <regex> #include <scoped_allocator> #include <system_error> #include <thread> #include <tuple> #include <type_traits> #include <typeindex> #include <unordered_map> #include <unordered_set> using namespace std; #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define endl "\n" #define f(i, n) for (int i = 0; i < n; ++i) #define pb push_back #define eb emplace_back #define m_p make_pair #define T \ int t = 0; \ cin >> t; \ while (t--) #define pr(a) \ for (int i = 0; i < (int)a.size(); ++i) \ cout << a[i] << " "; \ cout << endl; #define b_e(a) a.begin(), a.end() typedef long long ll; typedef long double lld; const ll mod = 1e15; const ll mx = 2e6; const ll inf = 1e9; const int sz = 26; typedef long long ll; void input() { IOS; ll n, k; cin >> n >> k; vector<ll> a(n); f(i, n) cin >> a[i]; ll low = 0, high = 1e9; ll ans = 0; auto possible = [&](ll x) { ll cnt = 0; f(i, n) { cnt += (a[i] - 1) / x; } return cnt <= k; }; while (low <= high) { ll mid = (low + high) / 2LL; // cout << high << " "<< low << endl; if (possible(mid)) { ans = mid; high = mid - 1; } else low = mid + 1; } cout << ans << endl; } int main() { input(); return 0; } /* freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); */
#include <cassert> #include <cctype> #include <cerrno> #include <cfloat> #include <ciso646> #include <climits> #include <clocale> #include <cmath> #include <csetjmp> #include <csignal> #include <cstdarg> #include <cstddef> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <ccomplex> #include <cfenv> #include <cinttypes> #include <cstdbool> #include <cstdint> #include <ctgmath> #include <cwchar> #include <cwctype> // C++ #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #include <array> #include <atomic> #include <chrono> #include <condition_variable> #include <forward_list> #include <future> #include <initializer_list> #include <mutex> #include <random> #include <ratio> #include <regex> #include <scoped_allocator> #include <system_error> #include <thread> #include <tuple> #include <type_traits> #include <typeindex> #include <unordered_map> #include <unordered_set> using namespace std; #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define endl "\n" #define f(i, n) for (int i = 0; i < n; ++i) #define pb push_back #define eb emplace_back #define m_p make_pair #define T \ int t = 0; \ cin >> t; \ while (t--) #define pr(a) \ for (int i = 0; i < (int)a.size(); ++i) \ cout << a[i] << " "; \ cout << endl; #define b_e(a) a.begin(), a.end() typedef long long ll; typedef long double lld; const ll mod = 1e15; const ll mx = 2e6; const ll inf = 1e9; const int sz = 26; typedef long long ll; void input() { IOS; ll n, k; cin >> n >> k; vector<ll> a(n); f(i, n) cin >> a[i]; ll low = 0, high = 1e9; ll ans = 0; auto possible = [&](ll x) { if (x == 0) return false; ll cnt = 0; f(i, n) { cnt += (a[i] - 1) / x; } return cnt <= k; }; while (low <= high) { ll mid = (low + high) / 2LL; // cout << high << " "<< low << endl; if (possible(mid)) { ans = mid; high = mid - 1; } else low = mid + 1; } cout << ans << endl; } int main() { input(); return 0; } /* freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); */
insert
115
115
115
117
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> 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; #define fr(i, a, b) for (ll i = a; i < b; i++) int main() { ios::sync_with_stdio(false); #ifdef CODE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ll n, k; cin >> n >> k; vl arr(n); fr(i, 0, n) { cin >> arr[i]; } ll low = 0, high = *max_element(arr.begin(), arr.end()); ll ans = high; auto func = [&](ll x) { ll total = 0; fr(i, 0, n) { int temp = arr[i] / x; if (x * temp == arr[i]) temp--; total += temp; } return (total <= k); }; while (low <= high) { ll mid = low + (high - low) / 2; if (func(mid)) { ans = mid; high = mid - 1; } else { low = mid + 1; } } cout << ans; return 0; }
#include <bits/stdc++.h> 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; #define fr(i, a, b) for (ll i = a; i < b; i++) int main() { ios::sync_with_stdio(false); #ifdef CODE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ll n, k; cin >> n >> k; vl arr(n); fr(i, 0, n) { cin >> arr[i]; } ll low = 1, high = 1e+10; ll ans = high; auto func = [&](ll x) { ll total = 0; fr(i, 0, n) { int temp = arr[i] / x; if (x * temp == arr[i]) temp--; total += temp; } return (total <= k); }; while (low <= high) { ll mid = low + (high - low) / 2; if (func(mid)) { ans = mid; high = mid - 1; } else { low = mid + 1; } } cout << ans; return 0; }
replace
21
22
21
22
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> #define endl "\n" using namespace std; typedef long long ll; typedef pair<ll, ll> l_l; typedef pair<int, int> i_i; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } const long long INF = 1e18; // const ll mod = 1000000007; ll N, K; ll A[201000]; int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N >> K; for (int i = 0; i < N; i++) cin >> A[i]; ll ok = 1e9; ll ng = 0; for (int _ = 0; _ <= 100; _++) { ll mid = (ok + ng) / 2; ll timer = 0; for (int i = 0; i < N; i++) { timer += (A[i] - 1) / mid; } if (timer <= K) ok = mid; else ng = mid; } cout << ok << endl; return 0; }
#include <bits/stdc++.h> #define endl "\n" using namespace std; typedef long long ll; typedef pair<ll, ll> l_l; typedef pair<int, int> i_i; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } const long long INF = 1e18; // const ll mod = 1000000007; ll N, K; ll A[201000]; int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N >> K; for (int i = 0; i < N; i++) cin >> A[i]; ll ok = 1e9; ll ng = 0; while (abs(ok - ng) > 1) { ll mid = (ok + ng) / 2; ll timer = 0; for (int i = 0; i < N; i++) { timer += (A[i] - 1) / mid; } if (timer <= K) ok = mid; else ng = mid; } cout << ok << endl; return 0; }
replace
36
37
36
37
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long int #define endl '\n' bool check(int x, vector<int> &v, int k) { int cuts = 0; for (int i = 0; i < v.size(); i++) { cuts += v[i] / x; if (v[i] % x == 0) cuts--; } if (cuts <= k) return true; else return false; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, k; cin >> n >> k; vector<int> v(n); int low = 0; int high = 1000000000; for (int i = 0; i < n; ++i) { cin >> v[i]; } int ans; while (low <= high) { int mid = (low + high) / 2; if (check(mid, v, k)) { ans = mid; high = mid - 1; } else { low = mid + 1; } } cout << ans; }
#include <bits/stdc++.h> using namespace std; #define int long long int #define endl '\n' bool check(int x, vector<int> &v, int k) { int cuts = 0; for (int i = 0; i < v.size(); i++) { cuts += v[i] / x; if (v[i] % x == 0) cuts--; } if (cuts <= k) return true; else return false; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, k; cin >> n >> k; vector<int> v(n); int low = 1; int high = 1000000000; for (int i = 0; i < n; ++i) { cin >> v[i]; } int ans; while (low <= high) { int mid = (low + high) / 2; if (check(mid, v, k)) { ans = mid; high = mid - 1; } else { low = mid + 1; } } cout << ans; }
replace
23
24
23
24
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define PI acos(-1) #define pb push_back #define mp make_pair #define int long long int #define pi pair<int, int> #define pii pair<int, pi> #define fir first #define sec second #define MAXN 500001 #define MAXL 20 #define INF 200001 #define mod 1000000007 bool possible(int x, vector<int> v, int k) { int ans = 0; for (int i = 0; i < v.size(); i++) { if (v[i] > x) { int inc = v[i] / x; ans += inc; } } return ans <= k; } int bb(vector<int> v, int k) { int l = 0, r = 1e9, m; while (l < r) { m = (l + r) >> 1; if (possible(m, v, k)) r = m; else l = m + 1; } return l; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin >> n >> k; vector<int> v(n); for (int i = 0; i < n; i++) cin >> v[i]; cout << bb(v, k) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define PI acos(-1) #define pb push_back #define mp make_pair #define int long long int #define pi pair<int, int> #define pii pair<int, pi> #define fir first #define sec second #define MAXN 500001 #define MAXL 20 #define INF 200001 #define mod 1000000007 bool possible(int x, vector<int> v, int k) { int ans = 0; for (int i = 0; i < v.size(); i++) { if (v[i] > x) { int inc = v[i] / x; ans += inc; } } return ans <= k; } int bb(vector<int> v, int k) { int l = 1, r = 1e9, m; while (l < r) { m = (l + r) >> 1; if (possible(m, v, k)) r = m; else l = m + 1; } return l; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin >> n >> k; vector<int> v(n); for (int i = 0; i < n; i++) cin >> v[i]; cout << bb(v, k) << endl; return 0; }
replace
27
28
27
28
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define all(v) (v).begin(), (v).end() #define lp(i, n) for (int i = 0; i < (n); ++i) #define pr1(x) cout << "[" << #x << ": " << x << "] \n"; #define pr2(x, y) \ cout << "[" << #x << ": " << x << ", " << #y << ": " << y << "] \n"; #define mod 1000000007 #define int long long #define sz(v) (int)(v).size() int n, k; vector<int> v; bool can(int md) { int cnt = 0; for (int i = 0; i < n; i++) { cnt += ((v[i] + md - 1) / md) - 1; } return cnt <= k; } void solve() { cin >> n >> k; v.resize(n); lp(i, n) cin >> v[i]; int lo = 0, hi = 1e12, md, ans = 0; while (hi >= lo) { md = (lo + hi) / 2; if (can(md)) { ans = md; hi = md - 1; } else lo = md + 1; } cout << ans << "\n"; } int32_t main() { ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL); int t = 1; // cin >> t; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define all(v) (v).begin(), (v).end() #define lp(i, n) for (int i = 0; i < (n); ++i) #define pr1(x) cout << "[" << #x << ": " << x << "] \n"; #define pr2(x, y) \ cout << "[" << #x << ": " << x << ", " << #y << ": " << y << "] \n"; #define mod 1000000007 #define int long long #define sz(v) (int)(v).size() int n, k; vector<int> v; bool can(int md) { int cnt = 0; for (int i = 0; i < n; i++) { cnt += ((v[i] + md - 1) / md) - 1; } return cnt <= k; } void solve() { cin >> n >> k; v.resize(n); lp(i, n) cin >> v[i]; int lo = 1, hi = 1e12, md, ans = 0; while (hi >= lo) { md = (lo + hi) / 2; if (can(md)) { ans = md; hi = md - 1; } else lo = md + 1; } cout << ans << "\n"; } int32_t main() { ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL); int t = 1; // cin >> t; while (t--) { solve(); } return 0; }
replace
27
28
27
28
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; bool solve(vector<int> &a, int k, int l) { ll r = 0; for (int i : a) r += (i - 1) / l; return r <= k; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; int x = 0, y = 1 << 30; while (x < y) { int sr = (x + y) / 2; if (solve(a, k, sr)) y = sr; else x = sr + 1; } cout << x << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; bool solve(vector<int> &a, int k, int l) { ll r = 0; for (int i : a) r += (i - 1) / l; return r <= k; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; int x = 1, y = 1 << 30; while (x < y) { int sr = (x + y) / 2; if (solve(a, k, sr)) y = sr; else x = sr + 1; } cout << x << endl; }
replace
17
18
17
18
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long const ll MAXN = 1e9; ll n, k; vector<ll> a; bool check(ll x) { ll operations = 0; for (int i = 0; i < n; i++) { operations += ((a[i] - 1) / x); } if (operations > k) { return false; } return true; } void search() { ll left = 0, right = MAXN, ans = -1; while (left < right) { ll mid = (left + right) / 2; if (!check(mid)) { left = mid + 1; } else { right = mid; } } cout << right << endl; } int main() { cin >> n >> k; for (int i = 0; i < n; i++) { ll nums; cin >> nums; a.push_back(nums); } sort(a.begin(), a.end()); search(); return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long const ll MAXN = 1e9; ll n, k; vector<ll> a; bool check(ll x) { ll operations = 0; for (int i = 0; i < n; i++) { operations += ((a[i] - 1) / x); } if (operations > k) { return false; } return true; } void search() { ll left = 1, right = MAXN; while (left < right) { ll mid = (left + right) / 2; if (!check(mid)) { left = mid + 1; } else { right = mid; } } cout << right << endl; } int main() { cin >> n >> k; for (int i = 0; i < n; i++) { ll nums; cin >> nums; a.push_back(nums); } sort(a.begin(), a.end()); search(); return 0; }
replace
20
21
20
21
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> typedef long long ll; using namespace std; const ll mod = 1000000007; bool judge(ll x, ll *A, ll N, ll K) { ll p = 0; for (int i = 0; i < N; ++i) { p += (A[i] - 1) / x; } // cout<<"x: "<<x<<" p:"<<p<<endl; return p <= K; } ll binarysearch(ll *A, ll N, ll K) { ll ok = 1e9; ll ng = -1; while (abs(ok - ng) > 1) { ll mid = (ok + ng) / 2; if (judge(mid, A, N, K)) { ok = mid; } else { ng = mid; } } return ok; } int main() { ll N, K; cin >> N >> K; ll A[N]; ll end; for (int i = 0; i != N; i++) { cin >> A[i]; } ll ans = binarysearch(A, N, K); cout << ans << endl; }
#include <bits/stdc++.h> typedef long long ll; using namespace std; const ll mod = 1000000007; bool judge(ll x, ll *A, ll N, ll K) { ll p = 0; for (int i = 0; i < N; ++i) { p += (A[i] - 1) / x; } // cout<<"x: "<<x<<" p:"<<p<<endl; return p <= K; } ll binarysearch(ll *A, ll N, ll K) { ll ok = 1e9; ll ng = 0; while (abs(ok - ng) > 1) { ll mid = (ok + ng) / 2; if (judge(mid, A, N, K)) { ok = mid; } else { ng = mid; } } return ok; } int main() { ll N, K; cin >> N >> K; ll A[N]; ll end; for (int i = 0; i != N; i++) { cin >> A[i]; } ll ans = binarysearch(A, N, K); cout << ans << endl; }
replace
22
23
22
23
0
p02598
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define err(args...) \ {} #ifdef DEBUG #include "_debug.cpp" #endif using namespace std; using ll = long long; using ld = long double; template <typename T> using lim = numeric_limits<T>; template <typename T> istream &operator>>(istream &is, vector<T> &a) { for (T &x : a) { is >> x; } return is; } template <typename X, typename Y> istream &operator>>(istream &is, pair<X, Y> &p) { return is >> p.first >> p.second; } template <typename T, typename Can> T bsearch(T L, T R, const Can &can, bool left_feasible = true) { static_assert(is_convertible<decltype(can), function<bool(T)>>::value, "can must be bool(T)"); T &feasible = left_feasible ? L : R; T &infeasible = left_feasible ? R : L; while (R - L > 1) { T M = L + (R - L) / 2; (can(M) ? feasible : infeasible) = M; } return feasible; } ll ceildiv(ll x, ll y) { return (x + y - 1) / y; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; vector<int> a(n); cin >> a; cout << bsearch( 0, *max_element(a.begin(), a.end()), [&](int max_piece) { ll needed_cuts = 0; for (int ai : a) { needed_cuts += bsearch( -1, ai - 1, [&](int cuts) { return ceildiv(ai, cuts + 1) <= max_piece; }, false); } return needed_cuts <= k; }, false) << endl; return 0; }
#include <bits/stdc++.h> #define err(args...) \ {} #ifdef DEBUG #include "_debug.cpp" #endif using namespace std; using ll = long long; using ld = long double; template <typename T> using lim = numeric_limits<T>; template <typename T> istream &operator>>(istream &is, vector<T> &a) { for (T &x : a) { is >> x; } return is; } template <typename X, typename Y> istream &operator>>(istream &is, pair<X, Y> &p) { return is >> p.first >> p.second; } template <typename T, typename Can> T bsearch(T L, T R, const Can &can, bool left_feasible = true) { static_assert(is_convertible<decltype(can), function<bool(T)>>::value, "can must be bool(T)"); T &feasible = left_feasible ? L : R; T &infeasible = left_feasible ? R : L; while (R - L > 1) { T M = L + (R - L) / 2; (can(M) ? feasible : infeasible) = M; } return feasible; } ll ceildiv(ll x, ll y) { return (x + y - 1) / y; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; vector<int> a(n); cin >> a; cout << bsearch( 0, *max_element(a.begin(), a.end()), [&](int max_piece) { ll needed_cuts = 0; for (int ai : a) { needed_cuts += ceildiv(ai, max_piece) - 1; } return needed_cuts <= k; }, false) << endl; return 0; }
replace
45
51
45
46
TLE
p02598
C++
Runtime Error
#ifndef __OPTIMIZE_H__ #define __OPTIMIZE_H__ /* updated: 2020-07-22 */ #include <cmath> #include <cstdint> #include <stack> #include <vector> /* std::not_fn などに相当するものを自作するほうがいいか? */ /* findAllBoundaries の戻り値 */ template <class Value> struct BoundariesResult { std::vector<int64_t> args; // func の引数の列 std::vector<Value> vals; // func の戻り値の列 }; template <class Function> int64_t findBoundary(Function func, int64_t lower, int64_t upper, bool greater = false); template <class Function> double findBoundaryFloat(Function func, double lower, double upper, bool greater = false); template <class Function> double findOptimumFloat(Function func, double lower, double upper, bool maximize = false); template <class Function> auto findAllBoundaries(Function func, int64_t lower, int64_t upper) -> BoundariesResult<decltype(func(lower))>; /* // 関数 func : int64_t -> bool に対して // 二分探索で true と false の境界を(1つ)見つける O(log(upper - lower)) // 探索範囲は [lower, upper) // デフォルトでは func(i - 1) == true かつ func(i) == false となる i を返す (lower <= i <= upper) // greater を指定すると真偽を逆にする */ template <class Function> int64_t findBoundary(Function func, int64_t lower, int64_t upper, bool greater) { int64_t lo = lower - 1; int64_t hi = upper; while (hi - lo > 1) { int64_t mid = (lo + hi) / 2; if (func(mid) == greater) { hi = mid; } else { lo = mid; } } return hi; } /* // 関数 func : double -> bool に対して // 二分探索で true から false に変化する境界を(1つ)見つける // greater を指定すると真偽を逆にする */ template <class Function> double findBoundaryFloat(Function func, double lower, double upper, bool greater) { constexpr double precision = 1e-9; const int iterations = (int)(std::log2(upper - lower) - std::log2(precision)) + 1; double lo = lower; double hi = upper; for (int i = 0; i < iterations; ++i) { double mid = (lo + hi) / 2; if (func(mid) == greater) { hi = mid; } else { lo = mid; } } return hi; } /* // 関数 func : double -> double に対して // 三分探索で極小値をとる点を見つける(maximize を指定すると極大値を探索する) */ template <class Function> double findOptimumFloat(Function func, double lower, double upper, bool maximize) { constexpr double precision = 1e-9; constexpr double ratio = 1.5; const int iterations = (int)((std::log(upper - lower) - std::log(precision)) / std::log(ratio)) + 1; double lo = lower; double hi = upper; for (int i = 0; i < iterations; ++i) { double mid_lo = (ratio * lo + hi) / (1 + ratio); double mid_hi = (lo + ratio * hi) / (1 + ratio); double val_lo = func(mid_lo); double val_hi = func(mid_hi); if ((val_lo > val_hi) == maximize) { hi = mid_hi; } else { lo = mid_lo; } } return hi; } /* // 関数 func : int64_t -> Value(任意) に対して // 二分探索で値が変化する点をすべて見つける O(min(range, 変化する点数 * log(range))) // 探索区間 [lower, upper) 内で同じ値を返す区間が複数登場してはならない // 戻り値は func(x) が等しい区間の左端の列 (args) とそれに対応する func の値の列 (vals) // (ただし lower を含み upper を含まない) // 例えば区間 [0, 6) に対する func の値が { 4, 4, 4, 2, 2, 5 } なら // (args, vals) = ( { 0, 3, 5 }, { 4, 2, 5 } ) を返す */ template <class Function> auto findAllBoundaries(Function func, int64_t lower, int64_t upper) -> BoundariesResult<decltype(func(lower))> { using Value = decltype(func(lower)); // 値の型を推論 struct Mapping { int64_t arg; Value val; Mapping(int64_t arg, Value val) : arg(arg), val(val) {} }; using Range = std::pair<Mapping, Mapping>; /* 区間として正当かどうかチェック */ if (upper <= lower) return BoundariesResult<Value>(); /* 区間 [lower, upper - 1] の両端の値を計算し、戻り値用配列に追加 */ int64_t lower_arg = lower; int64_t upper_arg = upper - 1; Value lower_val = func(lower_arg); Value upper_val = func(upper_arg); std::vector<int64_t> ret_args; std::vector<Value> ret_vals; ret_args.push_back(lower_arg); ret_vals.push_back(lower_val); /* 区間全体が同じ値を返すなら終了 */ if (lower_val == upper_val) { BoundariesResult<Value> ret; ret.args = std::move(ret_args); ret.vals = std::move(ret_vals); return ret; } /* 区間 [lower, upper - 1] の両端の値が異なるなら stack に追加 */ std::stack<Range> stack; stack.push( Range(Mapping(lower_arg, lower_val), Mapping(upper_arg, upper_val))); /* 両端の値が異なる限り二分探索で境界を探索 */ while (!stack.empty()) { /* 区間 [l_arg, r_arg] に注目 */ auto pair = stack.top(); stack.pop(); Mapping l = pair.first; Mapping r = pair.second; int64_t l_arg = l.arg; int64_t r_arg = r.arg; Value l_val = l.val; Value r_val = r.val; /* 区間幅が 1 なら終了 (r_arg が境界) */ if (r_arg - l_arg == 1) { ret_args.push_back(r_arg); ret_vals.push_back(r.val); continue; } /* 区間 [l_arg, m_arg] と [m_arg, r_arg] に分割 */ int64_t m_arg = (l_arg + r_arg) / 2; Value m_val = func(m_arg); /* 各区間について、両端の値が異なるなら stack に追加 */ /* stack から取り出す順序の都合上、区間 [m, r] -> 区間 [l, m] の順で追加 */ if (m_val != r_val) { stack.push(Range(Mapping(m_arg, m_val), Mapping(r_arg, r_val))); } if (m_val != l_val) { stack.push(Range(Mapping(l_arg, l_val), Mapping(m_arg, m_val))); } } BoundariesResult<Value> ret; ret.args = std::move(ret_args); ret.vals = std::move(ret_vals); return ret; } #endif #define _CRT_SECURE_NO_WARNINGS #define _SCL_SECURE_NO_WARNINGS #include <algorithm> #include <array> #include <bitset> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <valarray> #include <vector> using namespace std; using uint = uint32_t; using LL = int64_t; using ULL = uint64_t; using PP = pair<LL, LL>; template <typename T> using PriorityQ = priority_queue<T, vector<T>, greater<T>>; #define REP(i, a, n) for (LL i = (a), i##_max_ = (n); i < i##_max_; ++i) #define REM(i, a, n) for (LL i = (LL)(n)-1, i##_min_ = (a); i >= i##_min_; --i) #define FLOAT fixed << setprecision(16) #define SPEEDUP \ { \ cin.tie(NULL); \ ios::sync_with_stdio(false); \ } const int INF = 0x3FFFFFFF; const LL INFLL = 0x3FFFFFFF3FFFFFFF; const double INFD = 1.0e+308; const double EPS = 1.0e-9; void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; } void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; } template <class T, class U> istream &operator>>(istream &ist, pair<T, U> &right) { return ist >> right.first >> right.second; } template <class T, class U> ostream &operator<<(ostream &ost, const pair<T, U> &right) { return ost << right.first << ' ' << right.second; } template <class T, class TCompatible, size_t N> void Fill(T (&dest)[N], const TCompatible &val) { fill(dest, dest + N, val); } template <class T, class TCompatible, size_t M, size_t N> void Fill(T (&dest)[M][N], const TCompatible &val) { for (int i = 0; i < M; ++i) Fill(dest[i], val); } template <class T> T Next() { T buf; cin >> buf; return buf; } istream &Ignore(istream &ist) { string s; ist >> s; return ist; } bool Inside(int i, int j, int h, int w) { return i >= 0 && i < h && j >= 0 && j < w; } #ifdef ONLY_MY_ENVIR #include "Accumulator.h" #include "Algebraic.h" #include "BIT.h" #include "BinaryMatrix.h" #include "BinaryTree.h" #include "Bipartite.h" #include "Compressor.h" #include "Decompositions.h" #include "DiscreteLog.h" #include "DynamicMod.h" #include "Exponential.h" #include "FFT.h" #include "Factorization.h" #include "FlowSolver.h" #include "Geometric2D.h" #include "Geometric2DFloat.h" #include "Geometric3D.h" #include "Geometric3DFloat.h" #include "Graph.h" #include "GraphUtil.h" #include "IntMod.h" #include "Interpolation.h" #include "KDTree.h" #include "LIS.h" #include "LazySegmentTree.h" #include "List.h" #include "Math.h" #include "MathUtil.h" #include "Matrix.h" #include "MinCostFlowSolver.h" #include "MinMax.h" #include "Numbers.h" #include "Optimize.h" #include "Permutation.h" #include "Polynomial.h" #include "Position.h" #include "Random.h" #include "Range.h" #include "Rational.h" #include "RuntimeMod.h" #include "SegmentTree.h" #include "SegmentTree2D.h" #include "Sets.h" #include "Shortest.h" #include "SlidingWindow.h" #include "SpanningTree.h" #include "StringSearching.h" #include "SuffixArray.h" #include "SwitchList.h" #include "Timer.h" #include "Tree.h" #include "TreeUtil.h" #include "UnionFind.h" #include "Util.h" #include "VectorUtil.h" #endif #ifdef __GNUC__ typedef __int128 LLL; istream &operator>>(istream &ist, __int128 &val) { LL tmp; ist >> tmp; val = tmp; return ist; } ostream &operator<<(ostream &ost, __int128 val) { LL tmp = val; ost << tmp; return ost; } #endif LL n, k; LL a[200000]; bool ok(LL x) { int cnt = 0; REP(i, 0, n) { cnt += (a[i] + x - 1) / x - 1; } return cnt <= k; } int main() { cin >> n >> k; REP(i, 0, n) cin >> a[i]; cout << findBoundary(ok, 0, INF, true) << endl; return 0; }
#ifndef __OPTIMIZE_H__ #define __OPTIMIZE_H__ /* updated: 2020-07-22 */ #include <cmath> #include <cstdint> #include <stack> #include <vector> /* std::not_fn などに相当するものを自作するほうがいいか? */ /* findAllBoundaries の戻り値 */ template <class Value> struct BoundariesResult { std::vector<int64_t> args; // func の引数の列 std::vector<Value> vals; // func の戻り値の列 }; template <class Function> int64_t findBoundary(Function func, int64_t lower, int64_t upper, bool greater = false); template <class Function> double findBoundaryFloat(Function func, double lower, double upper, bool greater = false); template <class Function> double findOptimumFloat(Function func, double lower, double upper, bool maximize = false); template <class Function> auto findAllBoundaries(Function func, int64_t lower, int64_t upper) -> BoundariesResult<decltype(func(lower))>; /* // 関数 func : int64_t -> bool に対して // 二分探索で true と false の境界を(1つ)見つける O(log(upper - lower)) // 探索範囲は [lower, upper) // デフォルトでは func(i - 1) == true かつ func(i) == false となる i を返す (lower <= i <= upper) // greater を指定すると真偽を逆にする */ template <class Function> int64_t findBoundary(Function func, int64_t lower, int64_t upper, bool greater) { int64_t lo = lower - 1; int64_t hi = upper; while (hi - lo > 1) { int64_t mid = (lo + hi) / 2; if (func(mid) == greater) { hi = mid; } else { lo = mid; } } return hi; } /* // 関数 func : double -> bool に対して // 二分探索で true から false に変化する境界を(1つ)見つける // greater を指定すると真偽を逆にする */ template <class Function> double findBoundaryFloat(Function func, double lower, double upper, bool greater) { constexpr double precision = 1e-9; const int iterations = (int)(std::log2(upper - lower) - std::log2(precision)) + 1; double lo = lower; double hi = upper; for (int i = 0; i < iterations; ++i) { double mid = (lo + hi) / 2; if (func(mid) == greater) { hi = mid; } else { lo = mid; } } return hi; } /* // 関数 func : double -> double に対して // 三分探索で極小値をとる点を見つける(maximize を指定すると極大値を探索する) */ template <class Function> double findOptimumFloat(Function func, double lower, double upper, bool maximize) { constexpr double precision = 1e-9; constexpr double ratio = 1.5; const int iterations = (int)((std::log(upper - lower) - std::log(precision)) / std::log(ratio)) + 1; double lo = lower; double hi = upper; for (int i = 0; i < iterations; ++i) { double mid_lo = (ratio * lo + hi) / (1 + ratio); double mid_hi = (lo + ratio * hi) / (1 + ratio); double val_lo = func(mid_lo); double val_hi = func(mid_hi); if ((val_lo > val_hi) == maximize) { hi = mid_hi; } else { lo = mid_lo; } } return hi; } /* // 関数 func : int64_t -> Value(任意) に対して // 二分探索で値が変化する点をすべて見つける O(min(range, 変化する点数 * log(range))) // 探索区間 [lower, upper) 内で同じ値を返す区間が複数登場してはならない // 戻り値は func(x) が等しい区間の左端の列 (args) とそれに対応する func の値の列 (vals) // (ただし lower を含み upper を含まない) // 例えば区間 [0, 6) に対する func の値が { 4, 4, 4, 2, 2, 5 } なら // (args, vals) = ( { 0, 3, 5 }, { 4, 2, 5 } ) を返す */ template <class Function> auto findAllBoundaries(Function func, int64_t lower, int64_t upper) -> BoundariesResult<decltype(func(lower))> { using Value = decltype(func(lower)); // 値の型を推論 struct Mapping { int64_t arg; Value val; Mapping(int64_t arg, Value val) : arg(arg), val(val) {} }; using Range = std::pair<Mapping, Mapping>; /* 区間として正当かどうかチェック */ if (upper <= lower) return BoundariesResult<Value>(); /* 区間 [lower, upper - 1] の両端の値を計算し、戻り値用配列に追加 */ int64_t lower_arg = lower; int64_t upper_arg = upper - 1; Value lower_val = func(lower_arg); Value upper_val = func(upper_arg); std::vector<int64_t> ret_args; std::vector<Value> ret_vals; ret_args.push_back(lower_arg); ret_vals.push_back(lower_val); /* 区間全体が同じ値を返すなら終了 */ if (lower_val == upper_val) { BoundariesResult<Value> ret; ret.args = std::move(ret_args); ret.vals = std::move(ret_vals); return ret; } /* 区間 [lower, upper - 1] の両端の値が異なるなら stack に追加 */ std::stack<Range> stack; stack.push( Range(Mapping(lower_arg, lower_val), Mapping(upper_arg, upper_val))); /* 両端の値が異なる限り二分探索で境界を探索 */ while (!stack.empty()) { /* 区間 [l_arg, r_arg] に注目 */ auto pair = stack.top(); stack.pop(); Mapping l = pair.first; Mapping r = pair.second; int64_t l_arg = l.arg; int64_t r_arg = r.arg; Value l_val = l.val; Value r_val = r.val; /* 区間幅が 1 なら終了 (r_arg が境界) */ if (r_arg - l_arg == 1) { ret_args.push_back(r_arg); ret_vals.push_back(r.val); continue; } /* 区間 [l_arg, m_arg] と [m_arg, r_arg] に分割 */ int64_t m_arg = (l_arg + r_arg) / 2; Value m_val = func(m_arg); /* 各区間について、両端の値が異なるなら stack に追加 */ /* stack から取り出す順序の都合上、区間 [m, r] -> 区間 [l, m] の順で追加 */ if (m_val != r_val) { stack.push(Range(Mapping(m_arg, m_val), Mapping(r_arg, r_val))); } if (m_val != l_val) { stack.push(Range(Mapping(l_arg, l_val), Mapping(m_arg, m_val))); } } BoundariesResult<Value> ret; ret.args = std::move(ret_args); ret.vals = std::move(ret_vals); return ret; } #endif #define _CRT_SECURE_NO_WARNINGS #define _SCL_SECURE_NO_WARNINGS #include <algorithm> #include <array> #include <bitset> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <valarray> #include <vector> using namespace std; using uint = uint32_t; using LL = int64_t; using ULL = uint64_t; using PP = pair<LL, LL>; template <typename T> using PriorityQ = priority_queue<T, vector<T>, greater<T>>; #define REP(i, a, n) for (LL i = (a), i##_max_ = (n); i < i##_max_; ++i) #define REM(i, a, n) for (LL i = (LL)(n)-1, i##_min_ = (a); i >= i##_min_; --i) #define FLOAT fixed << setprecision(16) #define SPEEDUP \ { \ cin.tie(NULL); \ ios::sync_with_stdio(false); \ } const int INF = 0x3FFFFFFF; const LL INFLL = 0x3FFFFFFF3FFFFFFF; const double INFD = 1.0e+308; const double EPS = 1.0e-9; void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; } void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; } template <class T, class U> istream &operator>>(istream &ist, pair<T, U> &right) { return ist >> right.first >> right.second; } template <class T, class U> ostream &operator<<(ostream &ost, const pair<T, U> &right) { return ost << right.first << ' ' << right.second; } template <class T, class TCompatible, size_t N> void Fill(T (&dest)[N], const TCompatible &val) { fill(dest, dest + N, val); } template <class T, class TCompatible, size_t M, size_t N> void Fill(T (&dest)[M][N], const TCompatible &val) { for (int i = 0; i < M; ++i) Fill(dest[i], val); } template <class T> T Next() { T buf; cin >> buf; return buf; } istream &Ignore(istream &ist) { string s; ist >> s; return ist; } bool Inside(int i, int j, int h, int w) { return i >= 0 && i < h && j >= 0 && j < w; } #ifdef ONLY_MY_ENVIR #include "Accumulator.h" #include "Algebraic.h" #include "BIT.h" #include "BinaryMatrix.h" #include "BinaryTree.h" #include "Bipartite.h" #include "Compressor.h" #include "Decompositions.h" #include "DiscreteLog.h" #include "DynamicMod.h" #include "Exponential.h" #include "FFT.h" #include "Factorization.h" #include "FlowSolver.h" #include "Geometric2D.h" #include "Geometric2DFloat.h" #include "Geometric3D.h" #include "Geometric3DFloat.h" #include "Graph.h" #include "GraphUtil.h" #include "IntMod.h" #include "Interpolation.h" #include "KDTree.h" #include "LIS.h" #include "LazySegmentTree.h" #include "List.h" #include "Math.h" #include "MathUtil.h" #include "Matrix.h" #include "MinCostFlowSolver.h" #include "MinMax.h" #include "Numbers.h" #include "Optimize.h" #include "Permutation.h" #include "Polynomial.h" #include "Position.h" #include "Random.h" #include "Range.h" #include "Rational.h" #include "RuntimeMod.h" #include "SegmentTree.h" #include "SegmentTree2D.h" #include "Sets.h" #include "Shortest.h" #include "SlidingWindow.h" #include "SpanningTree.h" #include "StringSearching.h" #include "SuffixArray.h" #include "SwitchList.h" #include "Timer.h" #include "Tree.h" #include "TreeUtil.h" #include "UnionFind.h" #include "Util.h" #include "VectorUtil.h" #endif #ifdef __GNUC__ typedef __int128 LLL; istream &operator>>(istream &ist, __int128 &val) { LL tmp; ist >> tmp; val = tmp; return ist; } ostream &operator<<(ostream &ost, __int128 val) { LL tmp = val; ost << tmp; return ost; } #endif LL n, k; LL a[200000]; bool ok(LL x) { int cnt = 0; REP(i, 0, n) { cnt += (a[i] + x - 1) / x - 1; } return cnt <= k; } int main() { cin >> n >> k; REP(i, 0, n) cin >> a[i]; cout << findBoundary(ok, 1, INF, true) << endl; return 0; }
replace
366
367
366
367
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> #define int long long #define ld long double #define fi first #define se second #define vll vector<int> #define pii pair<int, int> #define vvll vector<vector<int>> #define pb push_back #define sz(v) (int)(v).size() #define inf 1e10 #define md 1000000007 #define all(v) (v).begin(), (v).end() #define rep(i, a, b) for (int i = a; i < b; ++i) #define tel(a) \ { cout << a << "\n"; } #define tell(a, b) \ { cout << a << " | " << b << "\n"; } #define telll(a, b, c) \ { cout << a << " | " << b << " | " << c << "\n"; } #define teln(v, n) \ { \ cout << "v- "; \ rep(o, 0, n) cout << v[o] << " "; \ cout << "\n"; \ } #define IOS \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); using namespace std; #define M 2010 int32_t main() { IOS; int n, k; cin >> n >> k; int a[n]; rep(i, 0, n) cin >> a[i]; int lo = 0, hi = inf, mid, ans; while (lo <= hi) { mid = (lo + hi) >> 1; int cnt = 0; rep(i, 0, n) cnt += (a[i] - 1) / mid; if (cnt <= k) hi = mid - 1, ans = mid; else lo = mid + 1; } cout << ans; return 0; }
#include <bits/stdc++.h> #define int long long #define ld long double #define fi first #define se second #define vll vector<int> #define pii pair<int, int> #define vvll vector<vector<int>> #define pb push_back #define sz(v) (int)(v).size() #define inf 1e10 #define md 1000000007 #define all(v) (v).begin(), (v).end() #define rep(i, a, b) for (int i = a; i < b; ++i) #define tel(a) \ { cout << a << "\n"; } #define tell(a, b) \ { cout << a << " | " << b << "\n"; } #define telll(a, b, c) \ { cout << a << " | " << b << " | " << c << "\n"; } #define teln(v, n) \ { \ cout << "v- "; \ rep(o, 0, n) cout << v[o] << " "; \ cout << "\n"; \ } #define IOS \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); using namespace std; #define M 2010 int32_t main() { IOS; int n, k; cin >> n >> k; int a[n]; rep(i, 0, n) cin >> a[i]; int lo = 1, hi = inf, mid, ans; while (lo <= hi) { mid = (lo + hi) >> 1; int cnt = 0; rep(i, 0, n) cnt += (a[i] - 1) / mid; if (cnt <= k) hi = mid - 1, ans = mid; else lo = mid + 1; } cout << ans; return 0; }
replace
41
42
41
42
0
p02598
C++
Runtime Error
// 問題の URL を書いておく // #include <algorithm> #include <array> #include <bitset> #include <cmath> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <vector> using namespace std; // #define ENABLE_PRINT #if defined(ENABLE_PRINT) #define Print(v) \ do { \ cout << #v << ": " << v << endl; \ } while (0) #define PrintVec(v) \ do { \ for (int __i = 0; __i < v.size(); ++__i) { \ cout << #v << "[" << __i << "]: " << v[__i] << endl; \ } \ } while (0) #else #define Print(v) ((void)0) #define PrintVec(v) ((void)0) #endif #define rep(i, n) for (int i = 0; i < (int)(n); ++i) using ll = int64_t; bool isValid(int x, const vector<int> &a, int k) { ll count = 0; for (auto av : a) { auto m = av % x; count += (m == 0 ? av / x - 1 : av / x); if (count > k) { return false; } } return true; } int main(int, const char **) { int n, k; cin >> n >> k; vector<int> a(n); int maxLen = 0; rep(i, n) { cin >> a[i]; maxLen = max(maxLen, a[i]); } ll l = 0, h = maxLen; while (h != l) { auto t = (l + h) / 2; if (isValid(t, a, k)) { h = t; } else { if (l == t) { l = h; break; } l = t; } } cout << l << endl; return 0; }
// 問題の URL を書いておく // #include <algorithm> #include <array> #include <bitset> #include <cmath> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <vector> using namespace std; // #define ENABLE_PRINT #if defined(ENABLE_PRINT) #define Print(v) \ do { \ cout << #v << ": " << v << endl; \ } while (0) #define PrintVec(v) \ do { \ for (int __i = 0; __i < v.size(); ++__i) { \ cout << #v << "[" << __i << "]: " << v[__i] << endl; \ } \ } while (0) #else #define Print(v) ((void)0) #define PrintVec(v) ((void)0) #endif #define rep(i, n) for (int i = 0; i < (int)(n); ++i) using ll = int64_t; bool isValid(int x, const vector<int> &a, int k) { ll count = 0; if (x == 0) { return false; } for (auto av : a) { auto m = av % x; count += (m == 0 ? av / x - 1 : av / x); if (count > k) { return false; } } return true; } int main(int, const char **) { int n, k; cin >> n >> k; vector<int> a(n); int maxLen = 0; rep(i, n) { cin >> a[i]; maxLen = max(maxLen, a[i]); } ll l = 0, h = maxLen; while (h != l) { auto t = (l + h) / 2; if (isValid(t, a, k)) { h = t; } else { if (l == t) { l = h; break; } l = t; } } cout << l << endl; return 0; }
insert
46
46
46
49
0
p02598
C++
Runtime Error
#include <algorithm> #include <iostream> using namespace std; int N_MAX = 200000; typedef long long ll; int main() { ll n, i, l, r, c, k, t, s = 0; ll a[N_MAX]; cin >> n >> k; for (i = 0; i < n; i++) { cin >> a[i]; s += a[i]; } sort(a, a + n, greater<ll>()); l = s / (n + k); r = a[0]; while (l < r) { c = (l + r) / 2; t = 0; for (i = 0; i < n; i++) { t += (a[i] + c - 1) / c - 1; if (t > k) break; } if (t > k) { l = c + 1; } else { r = c; } } cout << l << endl; return 0; }
#include <algorithm> #include <iostream> using namespace std; int N_MAX = 200000; typedef long long ll; int main() { ll n, i, l, r, c, k, t, s = 0; ll a[N_MAX]; cin >> n >> k; for (i = 0; i < n; i++) { cin >> a[i]; s += a[i]; } sort(a, a + n, greater<ll>()); l = max(s / (n + k), (ll)1); r = a[0]; while (l < r) { c = (l + r) / 2; t = 0; for (i = 0; i < n; i++) { t += (a[i] + c - 1) / c - 1; if (t > k) break; } if (t > k) { l = c + 1; } else { r = c; } } cout << l << endl; return 0; }
replace
14
15
14
15
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> #pragma GCC optimize(2) #define ll long long #define rep(i, a, n) for (int i = a; i <= n; i++) #define per(i, n, a) for (int i = n; i >= a; i--) #define endl '\n' #define eps 0.000000001 #define pb push_back #define mem(a, b) memset(a, b, sizeof(a)) #define IO \ ios::sync_with_stdio(false); \ cin.tie(0); using namespace std; const int INF = 0x3f3f3f3f; const ll inf = 0x3f3f3f3f3f3f3f3f; const int mod = 1e9 + 7; const int maxn = 2e5 + 5; int n, k, a[maxn]; bool check(int x) { int ok = 0; rep(i, 1, n) { ok += (a[i] - 1) / x; } return ok <= k; } int main() { cin >> n >> k; rep(i, 1, n) cin >> a[i]; int l = 0, r = 1000000000; while (l < r) { int mid = (l + r) >> 1; if (check(mid)) r = mid; else l = mid + 1; } cout << l << endl; }
#include <bits/stdc++.h> #pragma GCC optimize(2) #define ll long long #define rep(i, a, n) for (int i = a; i <= n; i++) #define per(i, n, a) for (int i = n; i >= a; i--) #define endl '\n' #define eps 0.000000001 #define pb push_back #define mem(a, b) memset(a, b, sizeof(a)) #define IO \ ios::sync_with_stdio(false); \ cin.tie(0); using namespace std; const int INF = 0x3f3f3f3f; const ll inf = 0x3f3f3f3f3f3f3f3f; const int mod = 1e9 + 7; const int maxn = 2e5 + 5; int n, k, a[maxn]; bool check(int x) { int ok = 0; rep(i, 1, n) { ok += (a[i] - 1) / x; } return ok <= k; } int main() { cin >> n >> k; rep(i, 1, n) cin >> a[i]; int l = 1, r = 1e9; while (l < r) { int mid = (l + r) >> 1; if (check(mid)) r = mid; else l = mid + 1; } cout << l << endl; }
replace
26
27
26
27
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define X first; #define Y second; typedef pair<int, int> pii; typedef pair<ll, int> pli; typedef pair<ll, ll> pll; const ll INF = 2e18; const int inf = 1e9 + 10; const int maxN = 2e5 + 10; const int maxK = 1e4 + 10; const int maxD = 15; const int maxH = 100; const int MOD = 1e9 + 7; ll n, k; ll a[maxN]; bool check(ll x) { ll cnt = 0; for (int i = 1; i <= n; i++) { if (a[i] >= x) { cnt += ((a[i] / x) - (a[i] % x == 0)); } } if (cnt <= k) { return true; } else { return false; } } int main() { cin >> n >> k; for (int i = 1; i <= n; i++) { scanf("%lld", &a[i]); } ll L = 0, R = 1e9; ll ans = R; while (L <= R) { ll mid = (L + R) / 2; if (check(mid)) { ans = mid; R = mid - 1; } else { L = mid + 1; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define X first; #define Y second; typedef pair<int, int> pii; typedef pair<ll, int> pli; typedef pair<ll, ll> pll; const ll INF = 2e18; const int inf = 1e9 + 10; const int maxN = 2e5 + 10; const int maxK = 1e4 + 10; const int maxD = 15; const int maxH = 100; const int MOD = 1e9 + 7; ll n, k; ll a[maxN]; bool check(ll x) { ll cnt = 0; for (int i = 1; i <= n; i++) { if (a[i] >= x) { cnt += ((a[i] / x) - (a[i] % x == 0)); } } if (cnt <= k) { return true; } else { return false; } } int main() { cin >> n >> k; for (int i = 1; i <= n; i++) { scanf("%lld", &a[i]); } ll L = 1, R = 1e9; ll ans = R; while (L <= R) { ll mid = (L + R) / 2; if (check(mid)) { ans = mid; R = mid - 1; } else { L = mid + 1; } } cout << ans << endl; return 0; }
replace
38
39
38
39
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long int ll; using ii = pair<ll, ll>; #define all(o) (o).begin(), (o).end() #define F first #define S second #define MP make_pair #define PB push_back #define ld long double #define eps 0.00000000001 class prioritize { public: bool operator()(ii &p1, ii &p2) { return p1.F < p2.F; } }; int main() { #ifndef ONLINE_JUDGE freopen("input1.txt", "r", stdin); freopen("output1.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n, k; cin >> n >> k; ll arr[n]; for (ll i = 0; i < n; i++) { cin >> arr[i]; } sort(arr, arr + n); ll left = 0; ll right = 1e9; ll mid = 0; ll ans = 1e9; while (left <= right) { mid = left + (right - left) / 2; ll count = 0; for (ll i = 0; i < n; i++) { ll x = floor((arr[i] - 1) / mid); count += x; } if (count <= k) { right = mid - 1; ans = min(ans, mid); } else left = mid + 1; } if (k == 0 || ans == 1e9) cout << arr[n - 1] << "\n"; else cout << ans << "\n"; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; using ii = pair<ll, ll>; #define all(o) (o).begin(), (o).end() #define F first #define S second #define MP make_pair #define PB push_back #define ld long double #define eps 0.00000000001 class prioritize { public: bool operator()(ii &p1, ii &p2) { return p1.F < p2.F; } }; int main() { #ifndef ONLINE_JUDGE freopen("input1.txt", "r", stdin); freopen("output1.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n, k; cin >> n >> k; ll arr[n]; for (ll i = 0; i < n; i++) { cin >> arr[i]; } sort(arr, arr + n); ll left = 1; ll right = 1e9; ll mid = 0; ll ans = 1e9; while (left <= right) { mid = left + (right - left) / 2; ll count = 0; for (ll i = 0; i < n; i++) { ll x = floor((arr[i] - 1) / mid); count += x; } if (count <= k) { right = mid - 1; ans = min(ans, mid); } else left = mid + 1; } if (k == 0 || ans == 1e9) cout << arr[n - 1] << "\n"; else cout << ans << "\n"; }
replace
38
39
38
39
-11