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
// om namah shivaay // faith over fear // no one wants to die,yet death is the destination we all share // don't think you are,know you are!! #include <bits/stdc++.h> using namespace std; #define mp make_pair #define mt make_tuple #define fi first #define se second #define pb push_back #define ll long long #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define rep(i, n) for (i = 0; i < n; i++) #define forn(i, n) for (ll i = 0; i < (ll)(n); ++i) #define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i) #define ford(i, n) for (ll i = (ll)(n)-1; i >= 0; --i) #define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i) #define fora(it, x) for (auto it : x) #define PI 3.14159265 #define sync \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define endl "\n" typedef pair<ll, ll> pii; typedef vector<ll> vi; typedef vector<pii> vpi; typedef vector<vi> vvi; typedef long long i64; typedef vector<i64> vi64; typedef vector<vi64> vvi64; typedef pair<i64, i64> pi64; typedef long double ld; template <class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; } template <class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; } ll a[2 * 100002]; ll fun(ll m, ll n) { ll s = 0; forn(i, n) { s += (a[i] - 1) / m; } return (s); } int main() { ll n, k; cin >> n >> k; forn(i, n) cin >> a[i]; ll f = 0, l = 1e18; while (f < l) { ll m = (f + l) / 2; ll val = fun(m, n); if (val <= k) l = m; else f = m + 1; } cout << f; }
// om namah shivaay // faith over fear // no one wants to die,yet death is the destination we all share // don't think you are,know you are!! #include <bits/stdc++.h> using namespace std; #define mp make_pair #define mt make_tuple #define fi first #define se second #define pb push_back #define ll long long #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define rep(i, n) for (i = 0; i < n; i++) #define forn(i, n) for (ll i = 0; i < (ll)(n); ++i) #define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i) #define ford(i, n) for (ll i = (ll)(n)-1; i >= 0; --i) #define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i) #define fora(it, x) for (auto it : x) #define PI 3.14159265 #define sync \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define endl "\n" typedef pair<ll, ll> pii; typedef vector<ll> vi; typedef vector<pii> vpi; typedef vector<vi> vvi; typedef long long i64; typedef vector<i64> vi64; typedef vector<vi64> vvi64; typedef pair<i64, i64> pi64; typedef long double ld; template <class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; } template <class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; } ll a[2 * 100002]; ll fun(ll m, ll n) { ll s = 0; forn(i, n) { s += (a[i] - 1) / m; } return (s); } int main() { ll n, k; cin >> n >> k; forn(i, n) cin >> a[i]; ll f = 1, l = 1e18; while (f < l) { ll m = (f + l) / 2; ll val = fun(m, n); if (val <= k) l = m; else f = m + 1; } cout << f; }
replace
54
55
54
55
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; #define MOD 1000000007LL #define rep(i, n) for (ll(i) = 0LL; (i) < (ll)(n); (i)++) #define rep2(i, s, e) for (ll(i) = (ll)(s); (i) < (ll)(e); (i)++) #define repi(i, n) for (ll(i) = 0LL; (i) <= (ll)(n); (i)++) #define repi2(i, s, e) for (ll(i) = (ll)(s); (i) <= (ll)(e); (i)++) #define per(i, n) for (ll(i) = (ll)(n)-1LL; (i) >= 0LL; (i)--) #define per2(i, s, e) for (ll(i) = (ll)(s)-1LL; (i) >= (ll)(e); (i)--) #define peri(i, n) for (ll(i) = (ll)(n); (i) >= 0LL; (i)--) #define peri2(i, s, e) for (ll(i) = (ll)(s); (i) >= (ll)(e); (i)--) #define iter(i, it) for (auto &(i) : (it)) template <typename T, typename U> ostream &operator<<(ostream &s, const pair<T, U> m) { cout << "(" << m.first << ", " << m.second << ")"; return s; } template <typename T, typename U> ostream &operator<<(ostream &s, const map<T, U> m) { ll c = 0; cout << "{ "; iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", "); cout << "}"; return s; } template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) { cout << "{ "; rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", "); cout << "}"; return s; } template <typename T> ostream &operator<<(ostream &s, const list<T> &v) { ll c = 0; cout << "{ "; iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", "); cout << "}"; return s; } int main(void) { ll N, K; cin >> N >> K; vector<ll> A(N); ll maxi = 0; rep(i, N) { cin >> A[i]; maxi = max(maxi, A[i]); } ll l = 1, r = maxi; do { ll key = (l + r) / 2; ll temp = 0; iter(i, A) temp += i / key + !!(i % key) - 1; if (temp <= K) r = key - 1; else l = key + 1; } while (l != r); cout << l << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; #define MOD 1000000007LL #define rep(i, n) for (ll(i) = 0LL; (i) < (ll)(n); (i)++) #define rep2(i, s, e) for (ll(i) = (ll)(s); (i) < (ll)(e); (i)++) #define repi(i, n) for (ll(i) = 0LL; (i) <= (ll)(n); (i)++) #define repi2(i, s, e) for (ll(i) = (ll)(s); (i) <= (ll)(e); (i)++) #define per(i, n) for (ll(i) = (ll)(n)-1LL; (i) >= 0LL; (i)--) #define per2(i, s, e) for (ll(i) = (ll)(s)-1LL; (i) >= (ll)(e); (i)--) #define peri(i, n) for (ll(i) = (ll)(n); (i) >= 0LL; (i)--) #define peri2(i, s, e) for (ll(i) = (ll)(s); (i) >= (ll)(e); (i)--) #define iter(i, it) for (auto &(i) : (it)) template <typename T, typename U> ostream &operator<<(ostream &s, const pair<T, U> m) { cout << "(" << m.first << ", " << m.second << ")"; return s; } template <typename T, typename U> ostream &operator<<(ostream &s, const map<T, U> m) { ll c = 0; cout << "{ "; iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", "); cout << "}"; return s; } template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) { cout << "{ "; rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", "); cout << "}"; return s; } template <typename T> ostream &operator<<(ostream &s, const list<T> &v) { ll c = 0; cout << "{ "; iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", "); cout << "}"; return s; } int main(void) { ll N, K; cin >> N >> K; vector<ll> A(N); ll maxi = 0; rep(i, N) { cin >> A[i]; maxi = max(maxi, A[i]); } ll l = 1, r = maxi; do { ll key = (l + r) / 2; ll temp = 0; iter(i, A) temp += i / key + !!(i % key) - 1; if (temp <= K) r = key - 1; else l = key + 1; } while (l <= r); cout << l << endl; return 0; }
replace
64
65
64
65
0
p02598
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; using ll = long long; int main() { int n, k; cin >> n >> k; vector<ll> a(n); ll maxi = 0; for (int i = 0; i < n; i++) { cin >> a[i]; maxi = max(maxi, a[i]); } ll l = -1, r = (ll)1e9 + 10; ll mid = (l + r) / 2; ll cnt = 0; while (r - l > 1) { mid = l + (r - l) / 2; cnt = 0; for (int i = 0; i < n; i++) { cnt += (a[i] + mid - 1) / mid - 1; } if (cnt <= k) { r = mid; } else { l = mid; } } cout << r << endl; return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; using ll = long long; int main() { int n, k; cin >> n >> k; vector<ll> a(n); ll maxi = 0; for (int i = 0; i < n; i++) { cin >> a[i]; maxi = max(maxi, a[i]); } ll l = 0, r = (ll)1e9 + 10; ll mid = (l + r) / 2; ll cnt = 0; while (r - l > 1) { mid = l + (r - l) / 2; cnt = 0; for (int i = 0; i < n; i++) { cnt += (a[i] + mid - 1) / mid - 1; } if (cnt <= k) { r = mid; } else { l = mid; } } cout << r << endl; return 0; }
replace
23
24
23
24
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long #define rep(i, n) for (int i = 0; i < n; i++) int N, K; int A[200010]; signed main() { cin >> N >> K; rep(i, N) cin >> A[i]; sort(A, A + N); if (K == 0) { cout << A[N - 1] << endl; return 0; } int l = 0, r = 1001001001001001001; rep(i, 70) { int mid = (l + r) / 2; int cnt = 0; rep(j, N) cnt += (A[j] + mid - 1) / mid - 1; if (cnt <= K) r = mid; else l = mid; } cout << r << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define rep(i, n) for (int i = 0; i < n; i++) int N, K; int A[200010]; signed main() { cin >> N >> K; rep(i, N) cin >> A[i]; sort(A, A + N); if (K == 0) { cout << A[N - 1] << endl; return 0; } int l = 1, r = 1001001001001001001; rep(i, 70) { int mid = (l + r) / 2; int cnt = 0; rep(j, N) cnt += (A[j] + mid - 1) / mid - 1; if (cnt <= K) r = mid; else l = mid; } cout << r << endl; return 0; }
replace
20
21
20
21
0
p02598
C++
Runtime Error
#include <algorithm> #include <bits/stdc++.h> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> #define forn(i, a, b) for (int i = (a), _b = (b); i <= _b; i++) #define fore(i, b, a) for (int i = (b), _a = (a); i >= _a; i--) #define rep(i, n) for (int i = 0, _n = n; i < n; i++) #define ll long long #define pii pair<int, int> #define vi vector<int> #define vpii vector<pii> #define m_p make_pair #define re return #define pb push_back #define si set<int> #define ld long double #define X first #define Y second #define st string #define ull unsigned long long #define mod 1000000007 #define INF 1000000007 #define x1 XZVJDFADSPFOE #define y1 GASDIJSLDAEJF #define x2 DFDAJKVOHKWIW #define y2 PSFSAODSXVNMQ #define LLINF 0x3f3f3f3f3f3f3f3fLL using namespace std; inline void read(int &x) { short negative = 1; x = 0; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') negative = -1; c = getchar(); } while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + (c ^ 48), c = getchar(); x *= negative; } ll quickpower(ll n, ll k) { ll ans = 1; while (k) { if (k % 2) { ans *= n; ans %= mod; } n *= n; n %= mod; k /= 2; } return ans; } string int_to_string(int n) { string s = ""; while (n) { int now = n % 10; s += now + '0'; n /= 10; } reverse(s.begin(), s.end()); return s; } int string_to_int(string s) { int n = 0; rep(i, s.size()) { n *= 10; n += s[i] - '0'; } return n; } ll low, high; int n; ll k; ll a[200100]; bool check(int l) { ll res = 0; rep(i, n) { if (a[i] % l == 0) { res += a[i] / l - 1; } else res += a[i] / l; } if (res <= k) return 1; return 0; } int main() { ios::sync_with_stdio(0); // think twice,code once cin >> n >> k; rep(i, n) cin >> a[i]; low = 0; high = 1e9; while (low < high) { int mid = (low + high) >> 1; if (check(mid)) high = mid; else low = mid + 1; } cout << low << endl; return 0; }
#include <algorithm> #include <bits/stdc++.h> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> #define forn(i, a, b) for (int i = (a), _b = (b); i <= _b; i++) #define fore(i, b, a) for (int i = (b), _a = (a); i >= _a; i--) #define rep(i, n) for (int i = 0, _n = n; i < n; i++) #define ll long long #define pii pair<int, int> #define vi vector<int> #define vpii vector<pii> #define m_p make_pair #define re return #define pb push_back #define si set<int> #define ld long double #define X first #define Y second #define st string #define ull unsigned long long #define mod 1000000007 #define INF 1000000007 #define x1 XZVJDFADSPFOE #define y1 GASDIJSLDAEJF #define x2 DFDAJKVOHKWIW #define y2 PSFSAODSXVNMQ #define LLINF 0x3f3f3f3f3f3f3f3fLL using namespace std; inline void read(int &x) { short negative = 1; x = 0; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') negative = -1; c = getchar(); } while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + (c ^ 48), c = getchar(); x *= negative; } ll quickpower(ll n, ll k) { ll ans = 1; while (k) { if (k % 2) { ans *= n; ans %= mod; } n *= n; n %= mod; k /= 2; } return ans; } string int_to_string(int n) { string s = ""; while (n) { int now = n % 10; s += now + '0'; n /= 10; } reverse(s.begin(), s.end()); return s; } int string_to_int(string s) { int n = 0; rep(i, s.size()) { n *= 10; n += s[i] - '0'; } return n; } ll low, high; int n; ll k; ll a[200100]; bool check(int l) { ll res = 0; rep(i, n) { if (a[i] % l == 0) { res += a[i] / l - 1; } else res += a[i] / l; } if (res <= k) return 1; return 0; } int main() { ios::sync_with_stdio(0); // think twice,code once cin >> n >> k; rep(i, n) cin >> a[i]; low = 1; high = 1e9; while (low < high) { int mid = (low + high) >> 1; if (check(mid)) high = mid; else low = mid + 1; } cout << low << endl; return 0; }
replace
107
108
107
108
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_pbds; using namespace std; #define ll long long #define PI acos(-1) #define pb push_back #define ins insert #define INF 5000000000000000007 // 1e18+7 #define mk make_pair #define lb(v, x) lower_bound(all(v), x) #define ub(v, x) upper_bound(all(v), x) #define ff first #define ss second #define rev reverse #define endl "\n" #define max3(x, y, z) max(x, max(y, z)) #define min3(x, y, z) min(x, min(y, z)) #define sz(a) (ll) a.size() #define double long double #define coud(a, b) cout << fixed << setprecision((b)) << (a) #define mset(x, y) memset(x, y, sizeof(x)) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define bp(n) __builtin_popcountll(n) #define mxt(a) *(max_element(a.begin(), a.end())) #define mnt(a) *(min_element(a.begin(), a.end())) #define unique_sort(c) \ (sort(all(c)), c.resize(distance(c.begin(), unique(c.begin(), c.end())))) #define rep(i, a, b) for (ll i = (a); i <= (b); ++i) #define trav(a, x) for (auto &a : x) #define re(i, n) for (ll i = 0; i < n; ++i) #define int2Bin(x, y) \ bitset<y> z = x; \ cout << z.to_string() << endl; const double eps = 1e-7; const string alpha = "abcdefghijklmnopqrstuvwxyz"; // int dx[8]={+1, +1, +1, 0, 0, -1, -1, -1}; // int dy[8]={+1, 0, -1, +1, -1, +1, 0, -1}; int dx[4] = {1, 0, 0, -1}; int dy[4] = {0, -1, 1, 0}; ll power(ll x, ll y) { ll ans = 1; x = x; while (y > 0) { if (y & 1) ans = (ans * x); y = y >> 1; x = (x * x); } return ans; } ll sqr(ll x) { return x * x; } template <typename T> T gcd(T a, T b) { if (a == 0) return b; return gcd(b % a, a); } template <class T> inline void chmax(T &x, T y) { x = max((x), (y)); } template <class T> inline void chmin(T &x, T y) { x = min((x), (y)); } template <class T> T abs(T x) { return x > 0 ? x : -x; } template <typename T> T powm(T a, T b, ll m) { T cnt = 1; while (b > 0) { if (b % 2 == 1) cnt = (cnt * a) % m; b /= 2; a = (a * a) % m; } return cnt % m; } typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<pll> vpll; typedef vector<pii> vpii; typedef vector<ll> vll; typedef vector<int> vii; #define minpq priority_queue<T, vector<T>, greater<T>>; // #define T int // #define ordered_set tree<T, null_type, less<T>, rb_tree_tag, // tree_order_statistics_node_update> //*X.find_by_order(k) returns the kth largest element (0-based). // X.order_of_key(val) returns the no. of values less than val. ll ncr(ll n, ll r) { ll ans = 1; if (r > n) return 0; if (r > n - r) r = n - r; for (ll i = 0; i < r; i++) { ans *= (n - i); ans /= (i + 1); } return ans; } const int MOD = 1000000007; const int N = 100000; struct compare { bool operator()(const int &a, const int &b) const { return a > b; } }; void prec() {} ll n, k, ans; ll a[N]; bool ok(ll x) { ll cnt = 0; for (int i = 1; i <= n; ++i) { cnt += (a[i] + x - 1) / x - 1; } return cnt <= k; } void run() { cin >> n >> k; rep(i, 1, n) cin >> a[i]; ll l = 1, r = 1e9; while (l <= r) { ll mid = (l + r) >> 1; if (ok(mid)) ans = mid, r = mid - 1; else l = mid + 1; } cout << ans; } int32_t main() { cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit); int tc = 1; // cin>>tc; prec(); re(i, tc) run(); return 0; } /* stuff you should look for * int overflow,array bounds. * special cases (n=1?). * N,MOD value. */
#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; #define ll long long #define PI acos(-1) #define pb push_back #define ins insert #define INF 5000000000000000007 // 1e18+7 #define mk make_pair #define lb(v, x) lower_bound(all(v), x) #define ub(v, x) upper_bound(all(v), x) #define ff first #define ss second #define rev reverse #define endl "\n" #define max3(x, y, z) max(x, max(y, z)) #define min3(x, y, z) min(x, min(y, z)) #define sz(a) (ll) a.size() #define double long double #define coud(a, b) cout << fixed << setprecision((b)) << (a) #define mset(x, y) memset(x, y, sizeof(x)) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define bp(n) __builtin_popcountll(n) #define mxt(a) *(max_element(a.begin(), a.end())) #define mnt(a) *(min_element(a.begin(), a.end())) #define unique_sort(c) \ (sort(all(c)), c.resize(distance(c.begin(), unique(c.begin(), c.end())))) #define rep(i, a, b) for (ll i = (a); i <= (b); ++i) #define trav(a, x) for (auto &a : x) #define re(i, n) for (ll i = 0; i < n; ++i) #define int2Bin(x, y) \ bitset<y> z = x; \ cout << z.to_string() << endl; const double eps = 1e-7; const string alpha = "abcdefghijklmnopqrstuvwxyz"; // int dx[8]={+1, +1, +1, 0, 0, -1, -1, -1}; // int dy[8]={+1, 0, -1, +1, -1, +1, 0, -1}; int dx[4] = {1, 0, 0, -1}; int dy[4] = {0, -1, 1, 0}; ll power(ll x, ll y) { ll ans = 1; x = x; while (y > 0) { if (y & 1) ans = (ans * x); y = y >> 1; x = (x * x); } return ans; } ll sqr(ll x) { return x * x; } template <typename T> T gcd(T a, T b) { if (a == 0) return b; return gcd(b % a, a); } template <class T> inline void chmax(T &x, T y) { x = max((x), (y)); } template <class T> inline void chmin(T &x, T y) { x = min((x), (y)); } template <class T> T abs(T x) { return x > 0 ? x : -x; } template <typename T> T powm(T a, T b, ll m) { T cnt = 1; while (b > 0) { if (b % 2 == 1) cnt = (cnt * a) % m; b /= 2; a = (a * a) % m; } return cnt % m; } typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<pll> vpll; typedef vector<pii> vpii; typedef vector<ll> vll; typedef vector<int> vii; #define minpq priority_queue<T, vector<T>, greater<T>>; // #define T int // #define ordered_set tree<T, null_type, less<T>, rb_tree_tag, // tree_order_statistics_node_update> //*X.find_by_order(k) returns the kth largest element (0-based). // X.order_of_key(val) returns the no. of values less than val. ll ncr(ll n, ll r) { ll ans = 1; if (r > n) return 0; if (r > n - r) r = n - r; for (ll i = 0; i < r; i++) { ans *= (n - i); ans /= (i + 1); } return ans; } const int MOD = 1000000007; const int N = 200010; struct compare { bool operator()(const int &a, const int &b) const { return a > b; } }; void prec() {} ll n, k, ans; ll a[N]; bool ok(ll x) { ll cnt = 0; for (int i = 1; i <= n; ++i) { cnt += (a[i] + x - 1) / x - 1; } return cnt <= k; } void run() { cin >> n >> k; rep(i, 1, n) cin >> a[i]; ll l = 1, r = 1e9; while (l <= r) { ll mid = (l + r) >> 1; if (ok(mid)) ans = mid, r = mid - 1; else l = mid + 1; } cout << ans; } int32_t main() { cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit); int tc = 1; // cin>>tc; prec(); re(i, tc) run(); return 0; } /* stuff you should look for * int overflow,array bounds. * special cases (n=1?). * N,MOD value. */
replace
97
98
97
98
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> #define mp make_pair #define mt make_tuple #define fi first #define se second #define pb push_back #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define forn(i, n) for (int i = 0; i < (int)(n); ++i) #define for1(i, n) for (int i = 1; i <= (int)(n); ++i) #define ford(i, n) for (int i = (int)(n)-1; i >= 0; --i) #define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i) using namespace std; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pii> vpi; typedef vector<vi> vvi; typedef long long i64; typedef vector<i64> vi64; typedef vector<vi64> vvi64; typedef pair<i64, i64> pi64; typedef double ld; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; vi vec(n); forn(i, n) { cin >> vec[i]; } sort(all(vec)); reverse(all(vec)); int l = 0; int r = vec[0] + 1; int ans = INT_MAX; while (l <= r) { int mid = (l + r) / 2; bool ok = true; int cnt = 0; forn(i, n) { if (vec[i] <= mid) { break; } cnt += vec[i] / mid; if (cnt > k) { ok = false; break; } } if (ok) { ans = min(mid, ans); r = mid - 1; } else { l = mid + 1; } } if (ans == INT_MAX) { ans = vec[0]; } cout << ans; return 0; }
#include <bits/stdc++.h> #define mp make_pair #define mt make_tuple #define fi first #define se second #define pb push_back #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define forn(i, n) for (int i = 0; i < (int)(n); ++i) #define for1(i, n) for (int i = 1; i <= (int)(n); ++i) #define ford(i, n) for (int i = (int)(n)-1; i >= 0; --i) #define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i) using namespace std; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pii> vpi; typedef vector<vi> vvi; typedef long long i64; typedef vector<i64> vi64; typedef vector<vi64> vvi64; typedef pair<i64, i64> pi64; typedef double ld; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; vi vec(n); forn(i, n) { cin >> vec[i]; } sort(all(vec)); reverse(all(vec)); int l = 1; int r = vec[0] + 1; int ans = INT_MAX; while (l <= r) { int mid = (l + r) / 2; bool ok = true; int cnt = 0; forn(i, n) { if (vec[i] <= mid) { break; } cnt += vec[i] / mid; if (cnt > k) { ok = false; break; } } if (ok) { ans = min(mid, ans); r = mid - 1; } else { l = mid + 1; } } if (ans == INT_MAX) { ans = vec[0]; } cout << ans; return 0; }
replace
36
37
36
37
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long int ll; // const double pi=acos(-1.0); #define mod 1000000007 #define forn(i, k, n) for (ll i = k; i < n; i++) #define fornr(i, k, k1) for (ll i = k; i >= k1; i--) #define v(ll) vector<ll> #define vl(a, n, ll, k) vector<ll> a(n, k) #define vli(a, n) vector<ll> a(n) #define init(a, n) \ vector<ll> a(n); \ forn(i, 0, n) cin >> a[i] #define vll(a, n, m, ll, k) vector<vector<ll>> a(n, vector<ll>(m, k)) #define mp(a, ll, ll1) map<ll, ll1> a #define st(a, ll) set<ll> a #define mpa make_pair #define pr pair<ll, ll> #define pb push_back #define MAX 1000000 #define ed '\n' #define fileTake \ ifstream cin("input.txt"); \ ofstream cout("output.txt"); #define sortv(a) sort(a.begin(), a.end()) #define sorta(a, n) sort(a, a + n) #define yeah "YES" #define nil "NO" #define All(x) x.begin(), x.end() #define remDup(a) a.erase(unique(All(a)), a.end()) #define N 100 void swap(ll &x, ll &y) { x = x ^ y; y = x ^ y; x = x ^ y; } template <typename T> void print(T a) { for (auto i = a.begin(); i != a.end(); i++) cout << *i << " "; cout << endl; } bool isVowel(char c) { if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') return true; return false; } void sync() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } int main() { sync(); ll n, k; cin >> n >> k; init(a, n); ll ans = -1; ll lo = 0, hi = 1000000000; while (lo <= hi) { ll mid = (lo + hi) / 2; ll cnt = 0; forn(i, 0, n) { cnt += a[i] / mid; if (a[i] % mid == 0) cnt--; } if (cnt <= k) { ans = mid; hi = mid - 1; } else lo = mid + 1; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; // const double pi=acos(-1.0); #define mod 1000000007 #define forn(i, k, n) for (ll i = k; i < n; i++) #define fornr(i, k, k1) for (ll i = k; i >= k1; i--) #define v(ll) vector<ll> #define vl(a, n, ll, k) vector<ll> a(n, k) #define vli(a, n) vector<ll> a(n) #define init(a, n) \ vector<ll> a(n); \ forn(i, 0, n) cin >> a[i] #define vll(a, n, m, ll, k) vector<vector<ll>> a(n, vector<ll>(m, k)) #define mp(a, ll, ll1) map<ll, ll1> a #define st(a, ll) set<ll> a #define mpa make_pair #define pr pair<ll, ll> #define pb push_back #define MAX 1000000 #define ed '\n' #define fileTake \ ifstream cin("input.txt"); \ ofstream cout("output.txt"); #define sortv(a) sort(a.begin(), a.end()) #define sorta(a, n) sort(a, a + n) #define yeah "YES" #define nil "NO" #define All(x) x.begin(), x.end() #define remDup(a) a.erase(unique(All(a)), a.end()) #define N 100 void swap(ll &x, ll &y) { x = x ^ y; y = x ^ y; x = x ^ y; } template <typename T> void print(T a) { for (auto i = a.begin(); i != a.end(); i++) cout << *i << " "; cout << endl; } bool isVowel(char c) { if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') return true; return false; } void sync() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } int main() { sync(); ll n, k; cin >> n >> k; init(a, n); ll ans = -1; ll lo = 1, hi = 1000000000; while (lo <= hi) { ll mid = (lo + hi) / 2; ll cnt = 0; forn(i, 0, n) { cnt += a[i] / mid; if (a[i] % mid == 0) cnt--; } if (cnt <= k) { ans = mid; hi = mid - 1; } else lo = mid + 1; } cout << ans << endl; }
replace
62
63
62
63
0
p02598
C++
Runtime Error
#include "bits/stdc++.h" #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i, n) for (int i = 1; i <= (int)(n); i++) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() using namespace std; using ll = long long; using pi = pair<int, int>; const ll INF = 1LL << 60; int main() { int n, k; cin >> n >> k; vector<int> arr(n); rep(i, n) cin >> arr[i]; int l = 0, r = 1e9; while (r - l > 1) { int m = (l + r) / 2; auto cut = [&](int m) { ll cnt = 0; rep(i, n) cnt += (arr[i] - 1) / k; return cnt <= k; }; if (cut(m)) r = m; else l = m; } cout << r << endl; return 0; }
#include "bits/stdc++.h" #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i, n) for (int i = 1; i <= (int)(n); i++) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() using namespace std; using ll = long long; using pi = pair<int, int>; const ll INF = 1LL << 60; int main() { int n, k; cin >> n >> k; vector<int> arr(n); rep(i, n) cin >> arr[i]; int l = 0, r = 1e9; while (r - l > 1) { int m = (l + r) / 2; auto cut = [&](int m) { ll cnt = 0; rep(i, n) cnt += (arr[i] - 1) / m; return cnt <= k; }; if (cut(m)) r = m; else l = m; } cout << r << endl; return 0; }
replace
21
22
21
22
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> P; const ll mod = 1000000007; const ll INF = 1e+14; #define rep(i, n) for (int i = 0; i < n; i++) #define per(i, n) for (int i = n - 1; i >= 0; i--) #define Rep(i, sta, n) for (int i = sta; i < n; i++) #define rep1(i, n) for (int i = 1; i <= n; i++) #define per1(i, n) for (int i = n; i >= 1; i--) #define Rep1(i, sta, n) for (int i = sta; i <= n; i++) #define _GLIBCXX_DEBUG int main() { ll n, k; cin >> n >> k; ll a[n]; rep(i, n) { cin >> a[i]; } ll ng = -1; ll ok = 10000000001; while (abs(ok - ng) > 1) { ll mid = (ok + ng) / 2; ll count = 0; rep(i, n) { if (count > k) break; count += (a[i] + mid - 1) / mid - 1; } if (count <= k) ok = mid; else ng = mid; } cout << ok << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> P; const ll mod = 1000000007; const ll INF = 1e+14; #define rep(i, n) for (int i = 0; i < n; i++) #define per(i, n) for (int i = n - 1; i >= 0; i--) #define Rep(i, sta, n) for (int i = sta; i < n; i++) #define rep1(i, n) for (int i = 1; i <= n; i++) #define per1(i, n) for (int i = n; i >= 1; i--) #define Rep1(i, sta, n) for (int i = sta; i <= n; i++) #define _GLIBCXX_DEBUG int main() { ll n, k; cin >> n >> k; ll a[n]; rep(i, n) { cin >> a[i]; } ll ng = 0; ll ok = 10000000001; while (abs(ok - ng) > 1) { ll mid = (ok + ng) / 2; ll count = 0; rep(i, n) { if (count > k) break; count += (a[i] + mid - 1) / mid - 1; } if (count <= k) ok = mid; else ng = mid; } cout << ok << endl; }
replace
21
22
21
22
0
p02598
C++
Runtime Error
// Code by Mukul Totla #include <bits/stdc++.h> using namespace std; #define ll long long bool check(ll mid, ll k, ll *arr, ll n) { for (ll i = 0; i < n; i++) { if (arr[i] > mid) { ll val = ((arr[i] + mid - 1) / mid) - 1; if (k - val >= 0) k -= val; else return false; } } return true; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n, k, i, lo = 0, hi = 0; cin >> n >> k; ll arr[n]; for (i = 0; i < n; i++) { cin >> arr[i]; hi = max(arr[i], hi); } ll ans = hi; hi = 1e9 + 100; while (lo <= hi) { ll mid = (lo + hi) / 2; bool chk = check(mid, k, arr, n); if (chk == true) { hi = mid - 1; ans = min(ans, mid); } else lo = mid + 1; } cout << ans; return 0; }
// Code by Mukul Totla #include <bits/stdc++.h> using namespace std; #define ll long long bool check(ll mid, ll k, ll *arr, ll n) { for (ll i = 0; i < n; i++) { if (arr[i] > mid) { ll val = ((arr[i] + mid - 1) / mid) - 1; if (k - val >= 0) k -= val; else return false; } } return true; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n, k, i, lo = 0, hi = 0; cin >> n >> k; ll arr[n]; for (i = 0; i < n; i++) { cin >> arr[i]; hi = max(arr[i], hi); } ll ans = hi; hi = 1e9 + 100; while (lo <= hi) { ll mid = (lo + hi) / 2; bool chk; if (mid > 0) chk = check(mid, k, arr, n); else chk = false; if (chk == true) { hi = mid - 1; ans = min(ans, mid); } else lo = mid + 1; } cout << ans; return 0; }
replace
33
36
33
38
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, ll> pa; const int N = 2e5 + 100; const int mod = 1e9 + 7; const int inf = 0x3f3f3f3f; ll a[N]; ll n, k; bool check(int x) { ll sum = 0; for (int i = 1; i <= n; i++) { sum += a[i] / x; if (a[i] % x == 0) sum--; } if (sum <= k) return true; else return false; } int main() { ll ans = 1e9; cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; ll l = 0, r = 1e9; while (r >= l) { ll mid = l + r >> 1; if (check(mid)) ans = min(ans, mid), r = mid - 1; else l = mid + 1; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, ll> pa; const int N = 2e5 + 100; const int mod = 1e9 + 7; const int inf = 0x3f3f3f3f; ll a[N]; ll n, k; bool check(int x) { ll sum = 0; for (int i = 1; i <= n; i++) { sum += a[i] / x; if (a[i] % x == 0) sum--; } if (sum <= k) return true; else return false; } int main() { ll ans = 1e9; cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; ll l = 1, r = 1e9; while (r >= l) { ll mid = l + r >> 1; if (check(mid)) ans = min(ans, mid), r = mid - 1; else l = mid + 1; } cout << ans << endl; }
replace
29
30
29
30
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long bool check(int n, int k, vector<int> a, int m) { int cuts_need = 0; for (int i : a) { cuts_need += (i - 1) / m; } return cuts_need <= k; } signed main() { ios::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 lo = 0, hi = 1000000000; while (lo < hi) { int mid = (lo + hi) / 2; if (check(n, k, a, mid)) { hi = mid; } else { lo = mid + 1; } } cout << lo << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long bool check(int n, int k, vector<int> a, int m) { int cuts_need = 0; for (int i : a) { cuts_need += (i - 1) / m; } return cuts_need <= k; } signed main() { ios::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 lo = 1, hi = 1000000000; while (lo < hi) { int mid = (lo + hi) / 2; if (check(n, k, a, mid)) { hi = mid; } else { lo = mid + 1; } } cout << lo << '\n'; return 0; }
replace
23
24
23
24
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define fs first #define fst first #define sc second #define snd second #define sz(X) (int)(X).size() #define forn(i, n) for (int i = 0; i < int(n); i++) #define fornr(i, n) for (int i = int(n) - 1; i >= 0; i--) #define forab(i, a, b) for (int i = int(a); i < int(b); i++) #define all(X) X.begin(), X.end() typedef long long ll; typedef vector<pair<ll, ll>> vpll; typedef pair<int, int> pii; typedef unsigned int uint; typedef unsigned long long ull; typedef double dbl; typedef long double ld; typedef vector<int> vi; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; vi a(n); forn(i, n) cin >> a[i]; int l = 0, r = 1e9 + 1; while (l != r) { int m = (l + r) / 2; int cnt = 0; forn(i, n) cnt += (a[i] - 1) / m; if (cnt <= k) r = m; else l = m + 1; } cout << l << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define fs first #define fst first #define sc second #define snd second #define sz(X) (int)(X).size() #define forn(i, n) for (int i = 0; i < int(n); i++) #define fornr(i, n) for (int i = int(n) - 1; i >= 0; i--) #define forab(i, a, b) for (int i = int(a); i < int(b); i++) #define all(X) X.begin(), X.end() typedef long long ll; typedef vector<pair<ll, ll>> vpll; typedef pair<int, int> pii; typedef unsigned int uint; typedef unsigned long long ull; typedef double dbl; typedef long double ld; typedef vector<int> vi; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; vi a(n); forn(i, n) cin >> a[i]; int l = 1, r = 1e9 + 1; while (l != r) { int m = (l + r) / 2; int cnt = 0; forn(i, n) cnt += (a[i] - 1) / m; if (cnt <= k) r = m; else l = m + 1; } cout << l << "\n"; return 0; }
replace
33
34
33
34
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<bool> vb; typedef vector<string> vs; typedef vector<vector<int>> vvi; typedef pair<int, int> pi; // #define int ll #define forl(i, a, b) for (int i = a; i < b; i++) #define rfor(i, b, a) for (int i = b; i >= a; i--) #define f first #define s second #define pb push_back #define mp make_pair #define srt(x) sort(x.begin(), x.end()) #define sumup(x) accumulate(x.begin(), x.end(), 0) #define PI 3.141592653589793238 #define MOD 1000000007 #define loop(n) for (int i = 0; i < n; i++) #define rloop(n) for (int i = n - 1; i >= 0; i--) void io() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int steps_needed(int len, vi &a) { int steps = 0; int n = a.size(); for (int i = 0; i < n; i++) { steps += (a[i] + len - 1) / len - 1; } return steps; } int32_t main() { io(); int t = 1; // cin>>t; while (t--) { int n, k; cin >> n >> k; vi a(n); int maxl = -1; loop(n) { cin >> a[i]; if (maxl < a[i]) maxl = a[i]; } // left will be 0 and right will be maxl // binary search on longest length left..start it with maxl/2..and count the // steps.. if steps>k, then increase the length, if steps<k then decrease // length int l = 0, r = maxl; int mid; if (k == 0) { cout << maxl << "\n"; return 0; } while (l < r) { mid = l + (r - l) / 2; int steps = steps_needed(mid, a); if (steps > k) l = mid + 1; else if (steps <= k) r = mid; } cout << l << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<bool> vb; typedef vector<string> vs; typedef vector<vector<int>> vvi; typedef pair<int, int> pi; // #define int ll #define forl(i, a, b) for (int i = a; i < b; i++) #define rfor(i, b, a) for (int i = b; i >= a; i--) #define f first #define s second #define pb push_back #define mp make_pair #define srt(x) sort(x.begin(), x.end()) #define sumup(x) accumulate(x.begin(), x.end(), 0) #define PI 3.141592653589793238 #define MOD 1000000007 #define loop(n) for (int i = 0; i < n; i++) #define rloop(n) for (int i = n - 1; i >= 0; i--) void io() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int steps_needed(int len, vi &a) { int steps = 0; int n = a.size(); for (int i = 0; i < n; i++) { steps += (a[i] + len - 1) / len - 1; } return steps; } int32_t main() { io(); int t = 1; // cin>>t; while (t--) { int n, k; cin >> n >> k; vi a(n); int maxl = -1; loop(n) { cin >> a[i]; if (maxl < a[i]) maxl = a[i]; } // left will be 0 and right will be maxl // binary search on longest length left..start it with maxl/2..and count the // steps.. if steps>k, then increase the length, if steps<k then decrease // length int l = 1, r = maxl; int mid; if (k == 0) { cout << maxl << "\n"; return 0; } while (l < r) { mid = l + (r - l) / 2; int steps = steps_needed(mid, a); if (steps > k) l = mid + 1; else if (steps <= k) r = mid; } cout << l << "\n"; } return 0; }
replace
63
64
63
64
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 1e5 + 50; ll n, k; ll a[maxn]; inline int log_number(int x, int mid) { if (x % mid == 0) return x / mid; else return x / mid + 1; } bool check(int x) { int ans = 0; for (int i = 1; i <= n; ++i) { ans += log_number(a[i], x) - 1; } if (ans <= k) return true; else return false; } int main() { cin >> n >> k; for (int i = 1; i <= n; ++i) cin >> a[i]; int l = 1, r = 1e9; int ans = 0; while (l <= r) { int mid = (l + r) / 2; if (check(mid)) r = mid - 1, ans = mid; else l = mid + 1; } /*if(check(l)) cout<<l<<endl; else cout<<r<<endl;*/ cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 1e6 + 50; ll n, k; ll a[maxn]; inline int log_number(int x, int mid) { if (x % mid == 0) return x / mid; else return x / mid + 1; } bool check(int x) { int ans = 0; for (int i = 1; i <= n; ++i) { ans += log_number(a[i], x) - 1; } if (ans <= k) return true; else return false; } int main() { cin >> n >> k; for (int i = 1; i <= n; ++i) cin >> a[i]; int l = 1, r = 1e9; int ans = 0; while (l <= r) { int mid = (l + r) / 2; if (check(mid)) r = mid - 1, ans = mid; else l = mid + 1; } /*if(check(l)) cout<<l<<endl; else cout<<r<<endl;*/ cout << ans << endl; return 0; }
replace
3
4
3
4
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, a, b) for (i = a; i < b; i++) #define rep2(i, a, b) for (i = a; i >= b; i--) #define mod 1000000007 #define mod2 998244353 #define FIO \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) #define INF 1e9 + 5 #define f first #define s second #define endl '\n' #define ll long long #define ii pair<int, int> #define pll pair<ll, ll> #define vi vector<int> #define vl vector<ll> #define vvi vector<vi> #define vii vector<ii> #define vpl vector<pll> #define vvii vector<vii> #define vll vector<ll> #define vb vector<bool> #define pb push_back #define mk make_pair #define eb emplace_back #define pg priority_queue<ll, vector<ll>, greater<ll>> #define sz(a) a.size() #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define cset(a) __builtin_popcountll(a) #define FILL(a, b, T) fill_n((T *)a, sizeof(a) / sizeof(T), b) #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") // #define debug(x) cerr << #x << " is " << x << endl; using namespace std; #define error(args...) \ { \ string _s = #args; \ replace(_s.begin(), _s.end(), ',', ' '); \ stringstream _ss(_s); \ istream_iterator<string> _it(_ss); \ err(_it, args); \ } #define pis pair<ll, pll> void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; err(++it, args...); } const auto start_time = std::chrono::high_resolution_clock::now(); void timecalculater() { #ifndef ONLINE_JUDGE auto end_time = std::chrono::high_resolution_clock::now(); std::chrono::duration<double> diff = end_time - start_time; cerr << "Time Taken : " << diff.count() << " s\n"; #endif } template <typename A, typename B> string to_string(pair<A, B> p); string to_string(const string &s) { return '"' + s + '"'; } string to_string(const char *s) { return to_string((string)s); } string to_string(bool b) { return (b ? "true" : "false"); } string to_string(vector<bool> v) { bool first = true; string res = "{"; for (int i = 0; i < static_cast<int>(v.size()); i++) { if (!first) { res += ", "; } first = false; res += to_string(v[i]); } res += "}"; return res; } template <size_t N> string to_string(bitset<N> v) { string res = ""; for (size_t i = 0; i < N; i++) { res += static_cast<char>('0' + v[i]); } return res; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #ifndef ONLINE_JUDGE #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) #endif 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); } }; // unordered_map<long long, int, custom_hash> safe_map; // FOR VIEWERS, CODE STARTS HERE vll v; ll N, K; bool check(ll x) { ll i, res = 0; // to get max x-length wood. how many cuts ? rep(i, 0, N) { res += (v[i] + x - 1) / x; res -= 1; } return res <= K; } ll binary_search(ll l, ll r) { ll mid, res = 1e9; while (l <= r) { mid = l + (r - l) / 2; if (check(mid)) { res = mid; r = mid - 1; } else { l = mid + 1; } } return res; } int main() { // get the logic, then code ! // if code is long, dry run on samples // think in a generalised way FIO; ll n, m, t, q, maxx, i, j, k1, k2, k3, k, x, y, flag, sum, cnt, ans, minn, cur; cin >> N >> K; rep(i, 0, N) { cin >> x; v.pb(x); } // binary search the length cout << binary_search(0, 1e9) << endl; // debug(v); return 0; }
#include <bits/stdc++.h> #define rep(i, a, b) for (i = a; i < b; i++) #define rep2(i, a, b) for (i = a; i >= b; i--) #define mod 1000000007 #define mod2 998244353 #define FIO \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) #define INF 1e9 + 5 #define f first #define s second #define endl '\n' #define ll long long #define ii pair<int, int> #define pll pair<ll, ll> #define vi vector<int> #define vl vector<ll> #define vvi vector<vi> #define vii vector<ii> #define vpl vector<pll> #define vvii vector<vii> #define vll vector<ll> #define vb vector<bool> #define pb push_back #define mk make_pair #define eb emplace_back #define pg priority_queue<ll, vector<ll>, greater<ll>> #define sz(a) a.size() #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define cset(a) __builtin_popcountll(a) #define FILL(a, b, T) fill_n((T *)a, sizeof(a) / sizeof(T), b) #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") // #define debug(x) cerr << #x << " is " << x << endl; using namespace std; #define error(args...) \ { \ string _s = #args; \ replace(_s.begin(), _s.end(), ',', ' '); \ stringstream _ss(_s); \ istream_iterator<string> _it(_ss); \ err(_it, args); \ } #define pis pair<ll, pll> void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; err(++it, args...); } const auto start_time = std::chrono::high_resolution_clock::now(); void timecalculater() { #ifndef ONLINE_JUDGE auto end_time = std::chrono::high_resolution_clock::now(); std::chrono::duration<double> diff = end_time - start_time; cerr << "Time Taken : " << diff.count() << " s\n"; #endif } template <typename A, typename B> string to_string(pair<A, B> p); string to_string(const string &s) { return '"' + s + '"'; } string to_string(const char *s) { return to_string((string)s); } string to_string(bool b) { return (b ? "true" : "false"); } string to_string(vector<bool> v) { bool first = true; string res = "{"; for (int i = 0; i < static_cast<int>(v.size()); i++) { if (!first) { res += ", "; } first = false; res += to_string(v[i]); } res += "}"; return res; } template <size_t N> string to_string(bitset<N> v) { string res = ""; for (size_t i = 0; i < N; i++) { res += static_cast<char>('0' + v[i]); } return res; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #ifndef ONLINE_JUDGE #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) #endif 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); } }; // unordered_map<long long, int, custom_hash> safe_map; // FOR VIEWERS, CODE STARTS HERE vll v; ll N, K; bool check(ll x) { ll i, res = 0; // to get max x-length wood. how many cuts ? rep(i, 0, N) { res += (v[i] + x - 1) / x; res -= 1; } return res <= K; } ll binary_search(ll l, ll r) { ll mid, res = 1e9; while (l <= r) { mid = l + (r - l) / 2; if (check(mid)) { res = mid; r = mid - 1; } else { l = mid + 1; } } return res; } int main() { // get the logic, then code ! // if code is long, dry run on samples // think in a generalised way FIO; ll n, m, t, q, maxx, i, j, k1, k2, k3, k, x, y, flag, sum, cnt, ans, minn, cur; cin >> N >> K; rep(i, 0, N) { cin >> x; v.pb(x); } // binary search the length cout << binary_search(1, 1e9) << endl; // debug(v); return 0; }
replace
175
176
175
176
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define fs first #define sc second #define pb push_back #define mp make_pair #define eb emplace_back #define ALL(A) A.begin(), A.end() #define RALL(A) A.rbegin(), A.rend() typedef long long ll; typedef pair<ll, ll> P; const ll mod = 1000000007; const ll LINF = 1LL << 60; const int INF = 1 << 30; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } ll copy(ll x) { return x; } int main() { ll n, k; cin >> n >> k; vector<ll> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } ll r = INF; ll l = -1LL; while (r - l > 1) { ll m = (r + l) / 2; ll ans = 0; for (int i = 0; i < n; i++) { ll x = copy(a[i]); ans += ((x + m - 1) / m - 1); if (ans > k) { break; } } if (ans <= k) { // out = min(out,res); r = m; } else { l = m; } } cout << r << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define fs first #define sc second #define pb push_back #define mp make_pair #define eb emplace_back #define ALL(A) A.begin(), A.end() #define RALL(A) A.rbegin(), A.rend() typedef long long ll; typedef pair<ll, ll> P; const ll mod = 1000000007; const ll LINF = 1LL << 60; const int INF = 1 << 30; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } ll copy(ll x) { return x; } int main() { ll n, k; cin >> n >> k; vector<ll> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } ll r = LINF; ll l = 0LL; while (r - l > 1) { ll m = (r + l) / 2; ll ans = 0; for (int i = 0; i < n; i++) { ll x = copy(a[i]); ans += ((x + m - 1) / m - 1); if (ans > k) { break; } } if (ans <= k) { // out = min(out,res); r = m; } else { l = m; } } cout << r << endl; return 0; }
replace
36
38
36
38
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> #define LL long long const int N = 2e5 + 5; int n, k, a[N], l, r, ans; bool check(int cur) { int cur_ans = 0; for (int i = 1; i <= n; ++i) { int cnt = 0; cnt = (a[i] - 1) / cur + 1; cur_ans += cnt - 1; } return cur_ans <= k; } int32_t main() { std::cin >> n >> k; for (int i = 1; i <= n; ++i) { std::cin >> a[i]; r = std::max(r, a[i]); } while (l <= r) { int mid = l + r + 1 >> 1; if (check(mid)) { ans = mid; r = mid - 1; } else l = mid + 1; } printf("%d", ans); return 0; }
#include <bits/stdc++.h> #define LL long long const int N = 2e5 + 5; int n, k, a[N], l = 1, r, ans; bool check(int cur) { int cur_ans = 0; for (int i = 1; i <= n; ++i) { int cnt = 0; cnt = (a[i] - 1) / cur + 1; cur_ans += cnt - 1; } return cur_ans <= k; } int32_t main() { std::cin >> n >> k; for (int i = 1; i <= n; ++i) { std::cin >> a[i]; r = std::max(r, a[i]); } while (l <= r) { int mid = l + r + 1 >> 1; if (check(mid)) { ans = mid; r = mid - 1; } else l = mid + 1; } printf("%d", ans); return 0; }
replace
5
6
5
6
0
p02598
C++
Runtime Error
#include <algorithm> #include <bits/stdc++.h> #include <vector> using namespace std; using UL = unsigned int; using ULL = unsigned long long; using LL = long long; #define rep(i, n) for (int i = 0; i < (n); i++) LL floor_usr(LL a, int b) { return (a + (b - 1)) / b; } const int maxN = 20; // 当分割するのが最適なメソッド。 // 各丸太についてn[i]回切るとすると、最大n[i]+1で割った値になる。 // n[i](sum(n[i])=K)を最適に分配するという問題に帰着する。 // O(nlog(K))かO(Klog(n))ぐらいならいけそう。後者はソートか? // 基本、数値に比例した(n+1)を当てれば全ての丸太は均一な大きさになる。 // その和をKに合わせればそもそも計算がいらないか。A[i]=min*(n[i]+1) int main() { int N, K; scanf("%d %d", &N, &K); LL A[maxN]; LL sumA = 0; vector<vector<LL>> dn; rep(i, N) scanf("%ld", &A[i]); sort(A, A + N); rep(i, N) sumA += A[i]; int n; int sumn = 0; rep(i, N) { if (sumA != 0) n = K * A[i] / sumA; else n = 0; sumn += n; dn.push_back({floor_usr(A[i], (n + 1)), A[i], n}); } vector<LL> B; sort(dn.begin(), dn.begin() + N, greater<vector<LL>>()); rep(i, K - sumn) { dn[i % N][2]++; dn[i % N][0] = floor_usr(dn[i % N][1], dn[i % N][2] + 1); } sort(dn.begin(), dn.begin() + N, greater<vector<LL>>()); printf("%ld", dn[0][0]); // 真の値より一回小さいnが得られているので、追加するiを選んで最小値を求める return 0; }
#include <algorithm> #include <bits/stdc++.h> #include <vector> using namespace std; using UL = unsigned int; using ULL = unsigned long long; using LL = long long; #define rep(i, n) for (int i = 0; i < (n); i++) LL floor_usr(LL a, int b) { return (a + (b - 1)) / b; } const int maxN = 200001; // 当分割するのが最適なメソッド。 // 各丸太についてn[i]回切るとすると、最大n[i]+1で割った値になる。 // n[i](sum(n[i])=K)を最適に分配するという問題に帰着する。 // O(nlog(K))かO(Klog(n))ぐらいならいけそう。後者はソートか? // 基本、数値に比例した(n+1)を当てれば全ての丸太は均一な大きさになる。 // その和をKに合わせればそもそも計算がいらないか。A[i]=min*(n[i]+1) int main() { int N, K; scanf("%d %d", &N, &K); LL A[maxN]; LL sumA = 0; vector<vector<LL>> dn; rep(i, N) scanf("%ld", &A[i]); sort(A, A + N); rep(i, N) sumA += A[i]; int n; int sumn = 0; rep(i, N) { if (sumA != 0) n = K * A[i] / sumA; else n = 0; sumn += n; dn.push_back({floor_usr(A[i], (n + 1)), A[i], n}); } vector<LL> B; sort(dn.begin(), dn.begin() + N, greater<vector<LL>>()); rep(i, K - sumn) { dn[i % N][2]++; dn[i % N][0] = floor_usr(dn[i % N][1], dn[i % N][2] + 1); } sort(dn.begin(), dn.begin() + N, greater<vector<LL>>()); printf("%ld", dn[0][0]); // 真の値より一回小さいnが得られているので、追加するiを選んで最小値を求める return 0; }
replace
10
11
10
11
0
p02598
C++
Runtime Error
#include <algorithm> #include <cassert> #include <chrono> #include <climits> #include <cmath> #include <complex> #include <cstring> #include <functional> #include <iostream> #include <map> #include <queue> #include <random> #include <regex> #include <set> #include <stack> #include <vector> using namespace std; #pragma region #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repr(i, s, n) for (int i = (s); i < (int)(n); i++) #define revrep(i, n) for (int i = (n)-1; i >= 0; i--) #define revrepr(i, s, n) for (int i = (n)-1; i >= s; i--) #define debug(x) cerr << #x << ": " << x << "\n" #define popcnt(x) __builtin_popcount(x) const double PI = acos(-1.0); using ll = long long; using P = pair<int, int>; 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; } template <class T> istream &operator>>(istream &is, vector<T> &v) { for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i); return is; } template <class T, class U> ostream &operator<<(ostream &os, pair<T, U> p) { cout << '(' << p.first << ", " << p.second << ')'; return os; } template <class T> void print(const vector<T> &v, const string &delimiter = " ") { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; } template <class T> void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v : vv) print(v, delimiter); } #pragma endregion int main() { int n, k; cin >> n >> k; vector<int> a(n); cin >> a; ll ng = -1; ll ok = 1000000000; auto is_ok = [&](int x) { ll cnt = 0; rep(i, n) { cnt += (a[i] + x - 1) / x - 1; } return cnt <= k; }; while (abs(ok - ng) > 1) { ll mid = (ok + ng) / 2; if (is_ok(mid)) ok = mid; else ng = mid; } cout << ok << endl; }
#include <algorithm> #include <cassert> #include <chrono> #include <climits> #include <cmath> #include <complex> #include <cstring> #include <functional> #include <iostream> #include <map> #include <queue> #include <random> #include <regex> #include <set> #include <stack> #include <vector> using namespace std; #pragma region #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repr(i, s, n) for (int i = (s); i < (int)(n); i++) #define revrep(i, n) for (int i = (n)-1; i >= 0; i--) #define revrepr(i, s, n) for (int i = (n)-1; i >= s; i--) #define debug(x) cerr << #x << ": " << x << "\n" #define popcnt(x) __builtin_popcount(x) const double PI = acos(-1.0); using ll = long long; using P = pair<int, int>; 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; } template <class T> istream &operator>>(istream &is, vector<T> &v) { for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i); return is; } template <class T, class U> ostream &operator<<(ostream &os, pair<T, U> p) { cout << '(' << p.first << ", " << p.second << ')'; return os; } template <class T> void print(const vector<T> &v, const string &delimiter = " ") { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; } template <class T> void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v : vv) print(v, delimiter); } #pragma endregion int main() { int n, k; cin >> n >> k; vector<int> a(n); cin >> a; ll ng = 0; ll ok = 1000000000; auto is_ok = [&](int x) { ll cnt = 0; rep(i, n) { cnt += (a[i] + x - 1) / x - 1; } return cnt <= k; }; while (abs(ok - ng) > 1) { ll mid = (ok + ng) / 2; if (is_ok(mid)) ok = mid; else ng = mid; } cout << ok << endl; }
replace
78
79
78
79
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define scan(n) scanf("%d", &n) #define ls(n) scanf("%lld", &n) #define print(n) printf("%d ", n) #define pln(n) printf("%d\n", n) #define lpln(n) printf("%lld\n", n) #define rep(i, a, n) for (int i = a; i < n; i++) #define rev(i, a, n) for (int i = n - 1; i >= a; i--) #define pb push_back #define mp make_pair #define F first #define S second #define gcd __gcd #define tc \ ll t1; \ cin >> t1; \ while (t1--) #define inp \ ll n; \ cin >> n; \ ll arr[n]; \ rep(i, 0, n) cin >> arr[i]; #define vect vector<ll> #define sortv(v) sort(v.begin(), v.end()) #define lower(v, n) lower_bound(v.begin(), v.end(), n) - v.begin() #define upper(v, n) upper_bound(v.begin(), v.end(), n) - v.begin() #define bitcount(n) __builtin_popcount(n) #define ln << endl #define inf 1e12 #define ninf LONG_MIN #define fast() \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) const ll mod = 1e9 + 7; const ll N = 1e5 + 5; int main() { fast(); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ll n, k; cin >> n >> k; ll arr[n]; rep(i, 0, n) cin >> arr[i]; ll low = 0, high = 1000000000; ll ans = -1; ll count = 0; while (low <= high) { count = 0; ll mid = (low + high) / 2; rep(i, 0, n) { ll temp1 = arr[i] / mid; ll rem = arr[i] - temp1 * (ll)mid; if (rem > 0) temp1++; // cout<<temp1<<endl; count += (temp1 - 1); } // cout<<mid<<" "<<count<<endl; if (count <= k) { ans = (mid); high = mid - 1; } else low = mid + 1; // cout<<low<<" "<<high<<endl; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define scan(n) scanf("%d", &n) #define ls(n) scanf("%lld", &n) #define print(n) printf("%d ", n) #define pln(n) printf("%d\n", n) #define lpln(n) printf("%lld\n", n) #define rep(i, a, n) for (int i = a; i < n; i++) #define rev(i, a, n) for (int i = n - 1; i >= a; i--) #define pb push_back #define mp make_pair #define F first #define S second #define gcd __gcd #define tc \ ll t1; \ cin >> t1; \ while (t1--) #define inp \ ll n; \ cin >> n; \ ll arr[n]; \ rep(i, 0, n) cin >> arr[i]; #define vect vector<ll> #define sortv(v) sort(v.begin(), v.end()) #define lower(v, n) lower_bound(v.begin(), v.end(), n) - v.begin() #define upper(v, n) upper_bound(v.begin(), v.end(), n) - v.begin() #define bitcount(n) __builtin_popcount(n) #define ln << endl #define inf 1e12 #define ninf LONG_MIN #define fast() \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) const ll mod = 1e9 + 7; const ll N = 1e5 + 5; int main() { fast(); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ll n, k; cin >> n >> k; ll arr[n]; rep(i, 0, n) cin >> arr[i]; ll low = 1, high = 1000000000; ll ans = -1; ll count = 0; while (low <= high) { count = 0; ll mid = (low + high) / 2; rep(i, 0, n) { ll temp1 = arr[i] / mid; ll rem = arr[i] - temp1 * (ll)mid; if (rem > 0) temp1++; // cout<<temp1<<endl; count += (temp1 - 1); } // cout<<mid<<" "<<count<<endl; if (count <= k) { ans = (mid); high = mid - 1; } else low = mid + 1; // cout<<low<<" "<<high<<endl; } cout << ans << endl; return 0; }
replace
49
50
49
50
-11
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; int n; ll k; vector<ll> a; bool check(ll x) { ll cnt = 0; for (int i = 0; i < n; ++i) { if (a[i] > x) { if (a[i] % x == 0) cnt += (a[i] / x) - 1; else cnt += a[i] / x; } } return cnt <= k; } int main() { cin >> n >> k; // a=vector<ll>(n); for (int i = 0; i < n; ++i) { ll aa; cin >> aa; a.push_back(aa); } sort(a.rbegin(), a.rend()); ll high = a[0] + 10; ll row = 0; while (high - row > 0) { ll mid = (high + row) / 2; if (check(mid)) high = mid; else row = mid + 1; } cout << row << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int n; ll k; vector<ll> a; bool check(ll x) { ll cnt = 0; for (int i = 0; i < n; ++i) { if (a[i] > x) { if (a[i] % x == 0) cnt += (a[i] / x) - 1; else cnt += a[i] / x; } } return cnt <= k; } int main() { cin >> n >> k; // a=vector<ll>(n); for (int i = 0; i < n; ++i) { ll aa; cin >> aa; a.push_back(aa); } sort(a.rbegin(), a.rend()); ll high = a[0]; ll row = 1; while (high - row > 0) { ll mid = (high + row) / 2; if (check(mid)) high = mid; else row = mid + 1; } cout << row << endl; return 0; }
replace
31
33
31
33
0
p02598
C++
Runtime Error
#include <iostream> #include <vector> using namespace std; using ll = long long; ll di(vector<ll> &A, int len) { ll ret{}; for (ll &a : A) ret += (a - 1) / len + 1; return ret; } int main() { ll N, K; cin >> N >> K; vector<ll> A(N); for (ll &a : A) cin >> a; int lower{-1}, upper{1000000001}; while (upper - lower > 1) { auto mid = lower + (upper - lower) / 2; if (di(A, mid) <= N + K) { upper = mid; } else { lower = mid; } } cout << upper << endl; }
#include <iostream> #include <vector> using namespace std; using ll = long long; ll di(vector<ll> &A, int len) { ll ret{}; for (ll &a : A) ret += (a - 1) / len + 1; return ret; } int main() { ll N, K; cin >> N >> K; vector<ll> A(N); for (ll &a : A) cin >> a; int lower{0}, upper{1000000001}; while (upper - lower > 1) { auto mid = lower + (upper - lower) / 2; if (di(A, mid) <= N + K) { upper = mid; } else { lower = mid; } } cout << upper << endl; }
replace
19
20
19
20
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define ll long long #define ld long double #define ull unsigned long long #define ff first #define ss second #define Mod 1000000007 // #define Mod 998244353 #define nl "\n" #define all(v) (v).begin(), (v).end() #define pb push_back #define f(i, a, b) for (ll i = a; i < b; ++i) #define rf(i, a, b) for (ll i = a; i >= b; --i) #define vll vector<ll> #define pll pair<ll, ll> #define mem(a, b) memset(a, b, sizeof(a)) #define printv(v) \ for (int i = 0; i < v.size(); i++) { \ cout << v[i] << " "; \ } \ cout << nl; using namespace std; inline bool kthbit(ll n, int k) { return (n >> k) & 1; } ll pw(ll a, ll b) { ll c = 1, m = a; while (b) { if (b & 1) c = (c * m); m = (m * m); b /= 2; } return c; } //------------------------------------------------------------------------------------------------ int main() { fast; ll T = 1; // cin>>T; //comment for single test while (T--) { // code... ll N, K; cin >> N >> K; vll A; ll mx = -10e17; f(i, 0, N) { ll x; cin >> x; A.pb(x); mx = max(mx, x); } ll low = 0, high = mx, ans = mx; while (low <= high) { ll mid = low + (high - low) / 2; ll cnt = 0; f(i, 0, N) { if (A[i] > mid) { if (A[i] % mid == 0) cnt += A[i] / mid - 1; else cnt += A[i] / mid; } } if (cnt <= K) { ans = min(ans, mid); high = mid - 1; } else { low = mid + 1; } } cout << ans << nl; } return 0; }
#include <bits/stdc++.h> #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define ll long long #define ld long double #define ull unsigned long long #define ff first #define ss second #define Mod 1000000007 // #define Mod 998244353 #define nl "\n" #define all(v) (v).begin(), (v).end() #define pb push_back #define f(i, a, b) for (ll i = a; i < b; ++i) #define rf(i, a, b) for (ll i = a; i >= b; --i) #define vll vector<ll> #define pll pair<ll, ll> #define mem(a, b) memset(a, b, sizeof(a)) #define printv(v) \ for (int i = 0; i < v.size(); i++) { \ cout << v[i] << " "; \ } \ cout << nl; using namespace std; inline bool kthbit(ll n, int k) { return (n >> k) & 1; } ll pw(ll a, ll b) { ll c = 1, m = a; while (b) { if (b & 1) c = (c * m); m = (m * m); b /= 2; } return c; } //------------------------------------------------------------------------------------------------ int main() { fast; ll T = 1; // cin>>T; //comment for single test while (T--) { // code... ll N, K; cin >> N >> K; vll A; ll mx = -10e17; f(i, 0, N) { ll x; cin >> x; A.pb(x); mx = max(mx, x); } ll low = 1, high = mx, ans = mx; while (low <= high) { ll mid = low + (high - low) / 2; ll cnt = 0; f(i, 0, N) { if (A[i] > mid) { if (A[i] % mid == 0) cnt += A[i] / mid - 1; else cnt += A[i] / mid; } } if (cnt <= K) { ans = min(ans, mid); high = mid - 1; } else { low = mid + 1; } } cout << ans << nl; } return 0; }
replace
56
57
56
57
0
p02598
C++
Time Limit Exceeded
// #pragma warning(disable:4996) #include <algorithm> #include <bitset> #include <cassert> #include <functional> #include <iomanip> #include <iostream> #include <limits.h> #include <map> #include <math.h> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <vector> // #include <boost/multiprecision/cpp_int.hpp> #include <bitset> #include <complex> #include <cstdio> #include <list> // #include <stdio.h> //< in.txt > out.txt using namespace std; // std::ios::sync_with_stdio(false); // std::cin.tie(0); const long long MOD = 10000; /// 1e9 + 7; const long long INF = 1e9; typedef long long LL; typedef long double LD; // typedef boost::multiprecision::cpp_int bigint; typedef pair<LL, LL> PLL; typedef pair<int, int> PI; typedef pair<LD, LL> pdl; typedef pair<LD, LD> pdd; typedef vector<LL> VLL; typedef vector<VLL> VVLL; typedef vector<int> VI; typedef vector<vector<int>> VVI; typedef unsigned long long ULL; VI A; int N, K; int count(LD x) { int ans = 0; for (int n = 0; n < N; n++) { int t = ceil((LD)A[n] / x); ans += t - 1; } return ans; } int main() { std::cin.tie(0); std::ios::sync_with_stdio(false); cin >> N >> K; A.resize(N); for (int n = 0; n < N; n++) cin >> A[n]; // sなら<=K回、eなら>K回 LD s = 1e9, e = 0; for (int t = 0; t < 200; t++) { LD m = (e + s) / 2; if (count(m) <= K) s = m; else e = m; } cout << (int)ceil(s) << "\n"; return 0; }
// #pragma warning(disable:4996) #include <algorithm> #include <bitset> #include <cassert> #include <functional> #include <iomanip> #include <iostream> #include <limits.h> #include <map> #include <math.h> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <vector> // #include <boost/multiprecision/cpp_int.hpp> #include <bitset> #include <complex> #include <cstdio> #include <list> // #include <stdio.h> //< in.txt > out.txt using namespace std; // std::ios::sync_with_stdio(false); // std::cin.tie(0); const long long MOD = 10000; /// 1e9 + 7; const long long INF = 1e9; typedef long long LL; typedef long double LD; // typedef boost::multiprecision::cpp_int bigint; typedef pair<LL, LL> PLL; typedef pair<int, int> PI; typedef pair<LD, LL> pdl; typedef pair<LD, LD> pdd; typedef vector<LL> VLL; typedef vector<VLL> VVLL; typedef vector<int> VI; typedef vector<vector<int>> VVI; typedef unsigned long long ULL; VI A; int N, K; int count(LD x) { int ans = 0; for (int n = 0; n < N; n++) { int t = ceil((LD)A[n] / x); ans += t - 1; } return ans; } int main() { std::cin.tie(0); std::ios::sync_with_stdio(false); cin >> N >> K; A.resize(N); for (int n = 0; n < N; n++) cin >> A[n]; // sなら<=K回、eなら>K回 LD s = 1e9, e = 0; for (int t = 0; t < 100; t++) { LD m = (e + s) / 2; if (count(m) <= K) s = m; else e = m; } cout << (int)ceil(s) << "\n"; return 0; }
replace
63
64
63
64
TLE
p02598
C++
Runtime Error
#include <bits/stdc++.h> #define IO_OP \ std::ios::sync_with_stdio(0); \ std::cin.tie(0); #define F first #define S second #define V vector #define PB push_back #define MP make_pair #define EB emplace_back #define ALL(v) (v).begin(), (v).end() #define debug(x) cerr << #x << " is " << x << endl using namespace std; typedef long long ll; typedef pair<int, int> pi; typedef V<int> vi; const int INF = 1e9 + 7, N = 2e5 + 7; int a[N]; int n, k; bool ok(int m) { ll cnt = 0; for (int i = 0; i < n; i++) cnt += (a[i] + m - 1) / m - 1; return cnt <= k; } signed main() { IO_OP; cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; int l = 0, r = INF; while (l <= r) { int m = (l + r) / 2; if (ok(m)) r = m - 1; else l = m + 1; } cout << l << endl; }
#include <bits/stdc++.h> #define IO_OP \ std::ios::sync_with_stdio(0); \ std::cin.tie(0); #define F first #define S second #define V vector #define PB push_back #define MP make_pair #define EB emplace_back #define ALL(v) (v).begin(), (v).end() #define debug(x) cerr << #x << " is " << x << endl using namespace std; typedef long long ll; typedef pair<int, int> pi; typedef V<int> vi; const int INF = 1e9 + 7, N = 2e5 + 7; int a[N]; int n, k; bool ok(int m) { ll cnt = 0; for (int i = 0; i < n; i++) cnt += (a[i] + m - 1) / m - 1; return cnt <= k; } signed main() { IO_OP; cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; int l = 1, r = INF; while (l <= r) { int m = (l + r) / 2; if (ok(m)) r = m - 1; else l = m + 1; } cout << l << endl; }
replace
37
38
37
38
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x, to) for (x = 0; x < (to); x++) #define FORR(x, arr) for (auto &x : arr) #define ITR(x, c) for (__typeof(c.begin()) x = c.begin(); x != c.end(); x++) #define ALL(a) (a.begin()), (a.end()) #define ZERO(a) memset(a, 0, sizeof(a)) #define MINUS(a) memset(a, 0xff, sizeof(a)) //------------------------------------------------------- int N; ll K; ll A[202020]; ll cut(ll v) { ll num = 0; int i; FOR(i, N) { num += (A[i] - 1) / v; if (num > K) return num; } return num; } void solve() { int i, j, k, l, r, x, y; string s; cin >> N >> K; FOR(i, N) cin >> A[i]; ll L = (1 << 30) - 1; for (i = 29; i >= 0; i--) { if (cut(L - (1 << i)) <= K) L -= 1 << i; } cout << L << endl; } int main(int argc, char **argv) { string s; int i; if (argc == 1) ios::sync_with_stdio(false), cin.tie(0); FOR(i, argc - 1) s += argv[i + 1], s += '\n'; FOR(i, s.size()) ungetc(s[s.size() - 1 - i], stdin); cout.tie(0); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x, to) for (x = 0; x < (to); x++) #define FORR(x, arr) for (auto &x : arr) #define ITR(x, c) for (__typeof(c.begin()) x = c.begin(); x != c.end(); x++) #define ALL(a) (a.begin()), (a.end()) #define ZERO(a) memset(a, 0, sizeof(a)) #define MINUS(a) memset(a, 0xff, sizeof(a)) //------------------------------------------------------- int N; ll K; ll A[202020]; ll cut(ll v) { ll num = 0; int i; FOR(i, N) { num += (A[i] - 1) / v; if (num > K) return num; } return num; } void solve() { int i, j, k, l, r, x, y; string s; cin >> N >> K; FOR(i, N) cin >> A[i]; ll L = (1 << 30); for (i = 29; i >= 0; i--) { if (cut(L - (1 << i)) <= K) L -= 1 << i; } cout << L << endl; } int main(int argc, char **argv) { string s; int i; if (argc == 1) ios::sync_with_stdio(false), cin.tie(0); FOR(i, argc - 1) s += argv[i + 1], s += '\n'; FOR(i, s.size()) ungetc(s[s.size() - 1 - i], stdin); cout.tie(0); solve(); return 0; }
replace
36
37
36
37
0
p02598
C++
Runtime Error
#include <algorithm> #include <iostream> #include <numeric> #include <string> #include <tuple> #include <utility> #include <vector> #define REP(i, a, b) for (int i = int(a); i < int(b); i++) using namespace std; using ll = long long int; using P = pair<ll, ll>; // clang-format off #ifdef _DEBUG_ #define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false) template<typename T> void PPPPP(T t) { cerr << t; } template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); } #else #define dump(...) do{ } while(false) #endif template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); } template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); } template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; } template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; } template<typename T> void print(T a) { cout << a << endl; } template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); } template<typename T> istream &operator,(istream &in, T &t) { return in >> t; } // clang-format on int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n, k; cin, n, k; vector<ll> a(n); REP(i, 0, n) { cin, a[i]; } ll l = 0, r = 1000000010; ll ans = r; while (l <= r) { ll mid = (l + r) / 2; ll cnt = 0; auto vv = a; REP(i, 0, n) { vv[i] -= mid; chmax(vv[i], 0LL); } REP(i, 0, n) { cnt += (vv[i] + mid - 1) / mid; } if (k >= cnt) { r = mid - 1; chmin(ans, mid); } else { l = mid + 1; } } print(ans); return 0; }
#include <algorithm> #include <iostream> #include <numeric> #include <string> #include <tuple> #include <utility> #include <vector> #define REP(i, a, b) for (int i = int(a); i < int(b); i++) using namespace std; using ll = long long int; using P = pair<ll, ll>; // clang-format off #ifdef _DEBUG_ #define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false) template<typename T> void PPPPP(T t) { cerr << t; } template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); } #else #define dump(...) do{ } while(false) #endif template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); } template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); } template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; } template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; } template<typename T> void print(T a) { cout << a << endl; } template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); } template<typename T> istream &operator,(istream &in, T &t) { return in >> t; } // clang-format on int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n, k; cin, n, k; vector<ll> a(n); REP(i, 0, n) { cin, a[i]; } ll l = 1, r = 1000000010; ll ans = r; while (l <= r) { ll mid = (l + r) / 2; ll cnt = 0; auto vv = a; REP(i, 0, n) { vv[i] -= mid; chmax(vv[i], 0LL); } REP(i, 0, n) { cnt += (vv[i] + mid - 1) / mid; } if (k >= cnt) { r = mid - 1; chmin(ans, mid); } else { l = mid + 1; } } print(ans); return 0; }
replace
37
38
37
38
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long void A() { int x; cin >> x; if (x >= 30) cout << "Yes" << endl; else cout << "No" << endl; } void B() { ll n, d; cin >> n >> d; int res = 0; for (int i = 0; i < n; i++) { ll x, y; cin >> x >> y; if (x * x + y * y <= d * d) res++; } cout << res << endl; } void C() {} void D() { int n; string s; cin >> n; cin >> s; stack<int> st; for (int i = 0; i < n; i++) { if (s[i] == 'R') st.push(i); } int l = 0, r = n - 1; int res = 0; for (int i = 0; i < n && !st.empty(); i++) { if (i >= st.top()) break; if (s[i] == 'W') { st.pop(); res++; } } cout << res << endl; } void E() { ll n, k; cin >> n >> k; vector<ll> a(n, 0); ll ma = 0; for (int i = 0; i < n; i++) { cin >> a[i]; ma = max(ma, a[i]); } if (k == 0) { cout << ma << endl; return; } ll l = 0, r = ma; //*1.0; ll ans = 0; while (l < r) { // cout<<l<<" "<<r<<endl; ll mid = l + (r - l) / 2; ll cnt = 0; for (ll i : a) { cnt += (i - 1) / mid; } if (cnt <= k) { ans = mid; r = mid; } else l = mid + 1; } cout << l << endl; } void F() {} void helper() { ll r = 1; while (r < LONG_LONG_MAX / 100) { vector<ll> res; for (ll i = 1; i * i <= r; i++) { if (r % i == 0) { res.push_back(i); if (r / i != i) res.push_back(r / i); } } sort(res.begin(), res.end()); for (ll i : res) cout << i << " "; cout << endl; r = r * 10 + 1; } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); // helper(); E(); return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long void A() { int x; cin >> x; if (x >= 30) cout << "Yes" << endl; else cout << "No" << endl; } void B() { ll n, d; cin >> n >> d; int res = 0; for (int i = 0; i < n; i++) { ll x, y; cin >> x >> y; if (x * x + y * y <= d * d) res++; } cout << res << endl; } void C() {} void D() { int n; string s; cin >> n; cin >> s; stack<int> st; for (int i = 0; i < n; i++) { if (s[i] == 'R') st.push(i); } int l = 0, r = n - 1; int res = 0; for (int i = 0; i < n && !st.empty(); i++) { if (i >= st.top()) break; if (s[i] == 'W') { st.pop(); res++; } } cout << res << endl; } void E() { ll n, k; cin >> n >> k; vector<ll> a(n, 0); ll ma = 0; for (int i = 0; i < n; i++) { cin >> a[i]; ma = max(ma, a[i]); } if (k == 0) { cout << ma << endl; return; } ll l = 0, r = ma; //*1.0; ll ans = 0; while (l < r) { // cout<<l<<" "<<r<<endl; ll mid = l + (r - l) / 2; if (mid == 0) { l = 1; break; } ll cnt = 0; for (ll i : a) { cnt += (i - 1) / mid; } if (cnt <= k) { ans = mid; r = mid; } else l = mid + 1; } cout << l << endl; } void F() {} void helper() { ll r = 1; while (r < LONG_LONG_MAX / 100) { vector<ll> res; for (ll i = 1; i * i <= r; i++) { if (r % i == 0) { res.push_back(i); if (r / i != i) res.push_back(r / i); } } sort(res.begin(), res.end()); for (ll i : res) cout << i << " "; cout << endl; r = r * 10 + 1; } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); // helper(); E(); return 0; }
insert
64
64
64
68
0
p02598
C++
Runtime Error
#include "list" #include <algorithm> #include <bitset> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <unordered_set> #include <vector> using namespace std; using ll = long long; using ull = unsigned long long; const ll mod = 998244353; // const ll mod = 1000000007; const int inf = 1e9; const ll linf = 1e18; const int DX[] = {1, -1, 0, 0}; const int DY[] = {0, 0, 1, -1}; #define rep(i, n) for (ll i = 0; i < (n); ++i) #define rep_from(i, j, n) for (ll i = (j); i < (n); ++i) #define rep_rev(i, n) for (ll i = n - 1; i >= 0; --i) #define rep_from_rev(i, j, n) for (ll i = n - 1; i >= j; --i) #define all(x) (x).begin(), (x).end() #define sz(x) ll(x.size()) template <typename T> inline T chmax(T &a, const T b) { return a = (a < b) ? b : a; } template <typename T> inline T chmin(T &a, const T b) { return a = (a > b) ? b : a; } ll power(ll base, ll exponent) { if (exponent % 2) { return power(base, exponent - 1) * base % mod; } else if (exponent) { ll root_ans = power(base, exponent / 2); return root_ans * root_ans % mod; } else { return 1; } } ll inverse(ll x) { return power(x, mod - 2); } ll gcd(ll a, ll b) { if (a < b) gcd(b, a); ll r; while (r = a % b) { a = b; b = r; } return b; } template <typename T> ll sum(T begin, T end) { return accumulate(begin, end, 0ll); } template <typename T> struct combination { vector<ll> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1) { fact[0] = 1; for (int i = 1; i <= sz; i++) { fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2); for (int i = sz - 1; i >= 0; i--) { inv[i] = inv[i + 1] * (i + 1) % mod; } } T C(int p, int q) const { if (q < 0 || p < q) return 0; return T(fact[p] * inv[q] % mod * inv[p - q] % mod); } T P(int p, int q) const { if (p < 0 || p < q) return 0; return T(fact[p] * inv[p - q] % mod); } }; using Pair = pair<int, int>; using LPair = pair<ll, ll>; template <ll Modulus> struct ModInt { ll a; constexpr ModInt(const ll x = 0) noexcept : a((x % mod + mod) % mod) {} constexpr ll &value() noexcept { return a; } constexpr const ll &value() const noexcept { return a; } constexpr ModInt operator+(const ModInt x) const noexcept { return ModInt(*this) += x; } constexpr ModInt operator-(const ModInt x) const noexcept { return ModInt(*this) -= x; } constexpr ModInt operator*(const ModInt x) const noexcept { return ModInt(*this) *= x; } constexpr ModInt operator/(const ModInt x) const noexcept { return ModInt(*this) /= x; } constexpr ModInt &operator+=(const ModInt x) noexcept { a += x.a; if (a >= Modulus) { a -= Modulus; } return *this; } constexpr ModInt &operator-=(const ModInt x) noexcept { if (a < x.a) { a += Modulus; } a -= x.a; return *this; } constexpr ModInt &operator*=(const ModInt x) noexcept { a = a * x.a % Modulus; return *this; } constexpr ModInt &operator/=(ModInt x) noexcept { ll exp = Modulus - 2; while (exp) { if (exp % 2) { *this *= x; } x *= x; exp /= 2; } return *this; } constexpr ModInt operator-() noexcept { return ModInt(-a); } friend ostream &operator<<(ostream &os, const ModInt &m) { os << m.a; return os; } }; using mint = ModInt<mod>; int main() { ios::sync_with_stdio(false); cout << fixed << setprecision(15); int n, k; cin >> n >> k; vector<int> a(n); rep(i, n) cin >> a[i]; int lft = 0; int rgt = 1e9 + 1; rep(_, 200) { int mid = (lft + rgt) / 2; int cnt = 0; rep(i, n) { cnt += ((a[i] - 1) / mid); } if (cnt <= k) { rgt = mid; } else { lft = mid; } } cout << rgt << endl; }
#include "list" #include <algorithm> #include <bitset> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <unordered_set> #include <vector> using namespace std; using ll = long long; using ull = unsigned long long; const ll mod = 998244353; // const ll mod = 1000000007; const int inf = 1e9; const ll linf = 1e18; const int DX[] = {1, -1, 0, 0}; const int DY[] = {0, 0, 1, -1}; #define rep(i, n) for (ll i = 0; i < (n); ++i) #define rep_from(i, j, n) for (ll i = (j); i < (n); ++i) #define rep_rev(i, n) for (ll i = n - 1; i >= 0; --i) #define rep_from_rev(i, j, n) for (ll i = n - 1; i >= j; --i) #define all(x) (x).begin(), (x).end() #define sz(x) ll(x.size()) template <typename T> inline T chmax(T &a, const T b) { return a = (a < b) ? b : a; } template <typename T> inline T chmin(T &a, const T b) { return a = (a > b) ? b : a; } ll power(ll base, ll exponent) { if (exponent % 2) { return power(base, exponent - 1) * base % mod; } else if (exponent) { ll root_ans = power(base, exponent / 2); return root_ans * root_ans % mod; } else { return 1; } } ll inverse(ll x) { return power(x, mod - 2); } ll gcd(ll a, ll b) { if (a < b) gcd(b, a); ll r; while (r = a % b) { a = b; b = r; } return b; } template <typename T> ll sum(T begin, T end) { return accumulate(begin, end, 0ll); } template <typename T> struct combination { vector<ll> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1) { fact[0] = 1; for (int i = 1; i <= sz; i++) { fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2); for (int i = sz - 1; i >= 0; i--) { inv[i] = inv[i + 1] * (i + 1) % mod; } } T C(int p, int q) const { if (q < 0 || p < q) return 0; return T(fact[p] * inv[q] % mod * inv[p - q] % mod); } T P(int p, int q) const { if (p < 0 || p < q) return 0; return T(fact[p] * inv[p - q] % mod); } }; using Pair = pair<int, int>; using LPair = pair<ll, ll>; template <ll Modulus> struct ModInt { ll a; constexpr ModInt(const ll x = 0) noexcept : a((x % mod + mod) % mod) {} constexpr ll &value() noexcept { return a; } constexpr const ll &value() const noexcept { return a; } constexpr ModInt operator+(const ModInt x) const noexcept { return ModInt(*this) += x; } constexpr ModInt operator-(const ModInt x) const noexcept { return ModInt(*this) -= x; } constexpr ModInt operator*(const ModInt x) const noexcept { return ModInt(*this) *= x; } constexpr ModInt operator/(const ModInt x) const noexcept { return ModInt(*this) /= x; } constexpr ModInt &operator+=(const ModInt x) noexcept { a += x.a; if (a >= Modulus) { a -= Modulus; } return *this; } constexpr ModInt &operator-=(const ModInt x) noexcept { if (a < x.a) { a += Modulus; } a -= x.a; return *this; } constexpr ModInt &operator*=(const ModInt x) noexcept { a = a * x.a % Modulus; return *this; } constexpr ModInt &operator/=(ModInt x) noexcept { ll exp = Modulus - 2; while (exp) { if (exp % 2) { *this *= x; } x *= x; exp /= 2; } return *this; } constexpr ModInt operator-() noexcept { return ModInt(-a); } friend ostream &operator<<(ostream &os, const ModInt &m) { os << m.a; return os; } }; using mint = ModInt<mod>; int main() { ios::sync_with_stdio(false); cout << fixed << setprecision(15); int n, k; cin >> n >> k; vector<int> a(n); rep(i, n) cin >> a[i]; int lft = 0; int rgt = 1e9 + 1; while (rgt - lft > 1) { int mid = (lft + rgt) / 2; int cnt = 0; rep(i, n) { cnt += ((a[i] - 1) / mid); } if (cnt <= k) { rgt = mid; } else { lft = mid; } } cout << rgt << endl; }
replace
174
175
174
175
0
p02598
C++
Time Limit Exceeded
#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; double X[200100]; int N; long long Count(double len) { long long Ans = 0; for (int i = 0; i < N; i++) { // Ans+=(long long)(X[i]/len);//解答引っ張ってきた人の条件。なぜか通る Ans += ceil(X[i] / len) - 1; // 多少遅くなるがこっちが正解 } return Ans; } int main() { long long K; cin >> N >> K; for (int i = 0; i < N; i++) { cin >> X[i]; } // long double l=1,r=1e9; double l = 1, r = 1e9; // while(l<r-0.1)//解答を引っ張ってきた人の条件。なぜかOKだったが、lとrの整数部が異なる状態でループを出ると問題になるはず // for(int i=0;i<35;i++)//OK // log2(10^9)=30.二分探索だとこのやり方安定する。ただし、浮動小数のせいか34以上でないと通らず。 // while(!((ceil(r)-ceil(l)) == // 0))//NG:左端が初期値0のままだと、右端のceilは0にならず、無限ループ // while(!((floor(r)-floor(l)) == // 0))//OK:右端がぴったり整数にならなければ成立.(あまりよくない) while ((floor(r) - floor(l)) > 0) // OK:右端がぴったり整数にならなければ成立.(あまりよくない) { // long double mid=(l+r)/2; double mid = (l + r) / 2; if (Count(mid) <= K) r = mid; else l = mid; } cout << (long long)(l + 0.999) << endl; return 0; }
#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; double X[200100]; int N; long long Count(double len) { long long Ans = 0; for (int i = 0; i < N; i++) { Ans += (long long)(X[i] / len); // 解答引っ張ってきた人の条件。なぜか通る // Ans+= ceil(X[i]/len)-1;//多少遅くなるがこっちが正解 } return Ans; } int main() { long long K; cin >> N >> K; for (int i = 0; i < N; i++) { cin >> X[i]; } // long double l=1,r=1e9; double l = 1, r = 1e9; // while(l<r-0.1)//解答を引っ張ってきた人の条件。なぜかOKだったが、lとrの整数部が異なる状態でループを出ると問題になるはず // for(int i=0;i<35;i++)//OK // log2(10^9)=30.二分探索だとこのやり方安定する。ただし、浮動小数のせいか34以上でないと通らず。 // while(!((ceil(r)-ceil(l)) == // 0))//NG:左端が初期値0のままだと、右端のceilは0にならず、無限ループ // while(!((floor(r)-floor(l)) == // 0))//OK:右端がぴったり整数にならなければ成立.(あまりよくない) while ((floor(r) - floor(l)) > 0) // OK:右端がぴったり整数にならなければ成立.(あまりよくない) { // long double mid=(l+r)/2; double mid = (l + r) / 2; if (Count(mid) <= K) r = mid; else l = mid; } cout << (long long)(l + 0.999) << endl; return 0; }
replace
11
13
11
13
TLE
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 lli long long int #define tc \ int t; \ cin >> t; \ while (t--) #define all(x) x.begin(), x.end() #define f first #define s second #define pb push_back #define vi vector<int> #define vll vector<lli> #define maxn 1771562 #define mod 1000000007 #define inf 10000000 int main() { fastio; int n, k; cin >> n >> k; lli a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } lli l = 0, h = 1e9, ans; while (l <= h) { lli mid = (l + h) / 2; lli ca = 0; for (int i = 0; i < n; i++) { ca += a[i] / mid - 1; if (a[i] % mid) ca++; } // cout<<mid<<" "<<ca<<"\n"; if (ca <= k) ans = mid, h = mid - 1; else l = mid + 1; } cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) #define lli long long int #define tc \ int t; \ cin >> t; \ while (t--) #define all(x) x.begin(), x.end() #define f first #define s second #define pb push_back #define vi vector<int> #define vll vector<lli> #define maxn 1771562 #define mod 1000000007 #define inf 10000000 int main() { fastio; int n, k; cin >> n >> k; lli a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } lli l = 1, h = 1e9, ans; while (l <= h) { lli mid = (l + h) / 2; lli ca = 0; for (int i = 0; i < n; i++) { ca += a[i] / mid - 1; if (a[i] % mid) ca++; } // cout<<mid<<" "<<ca<<"\n"; if (ca <= k) ans = mid, h = mid - 1; else l = mid + 1; } cout << ans << "\n"; return 0; }
replace
29
30
29
30
0
p02598
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> using namespace std; #define mid ((l + r) >> 1) #define MAXN (int)(1e5 + 2333) int a[MAXN]; inline int f(int x, int y) { if (x % y) return (int)(x / y) + 1; return x / y; } int main() { int n, k; scanf("%d%d", &n, &k); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); int l = 1, r = 1e9 + 1, sum, ans = 1e9; while (l < r) { sum = 0; // printf(";%d %d %d\n",l,mid,r); for (int i = 1; i <= n; i++) sum += (f(a[i], mid) - 1); // printf("--- %d\n",sum); if (sum > k) l = mid + 1; else { ans = mid; r = mid; } } printf("%d\n", ans); return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> using namespace std; #define mid ((l + r) >> 1) #define MAXN (int)(2e5 + 2333) int a[MAXN]; inline int f(int x, int y) { if (x % y) return (int)(x / y) + 1; return x / y; } int main() { int n, k; scanf("%d%d", &n, &k); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); int l = 1, r = 1e9 + 1, sum, ans = 1e9; while (l < r) { sum = 0; // printf(";%d %d %d\n",l,mid,r); for (int i = 1; i <= n; i++) sum += (f(a[i], mid) - 1); // printf("--- %d\n",sum); if (sum > k) l = mid + 1; else { ans = mid; r = mid; } } printf("%d\n", ans); return 0; }
replace
7
8
7
8
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define endl '\n' #define rep(i, n) \ ; \ for (long long i = 0; i < (n); i++) using ll = long long; using P = pair<long long, long long>; template <class T> using vec = vector<T>; ll n, k; vec<ll> a; bool cut(ll x) { ll p = 0; rep(i, n) p += (a[i] - 1) / x; return p <= k; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> k; a.resize(n); rep(i, n) cin >> a[i]; sort(a.rbegin(), a.rend()); ll left = 0, right = a[0], mid; while (left + 1 < right) { mid = (left + right) / 2; cut(mid) ? right = mid : left = mid; } cout << (cut(left) ? left : right) << endl; }
#include <bits/stdc++.h> using namespace std; #define endl '\n' #define rep(i, n) \ ; \ for (long long i = 0; i < (n); i++) using ll = long long; using P = pair<long long, long long>; template <class T> using vec = vector<T>; ll n, k; vec<ll> a; bool cut(ll x) { if (x == 0) return false; ll p = 0; rep(i, n) p += (a[i] - 1) / x; return p <= k; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> k; a.resize(n); rep(i, n) cin >> a[i]; sort(a.rbegin(), a.rend()); ll left = 0, right = a[0], mid; while (left + 1 < right) { mid = (left + right) / 2; cut(mid) ? right = mid : left = mid; } cout << (cut(left) ? left : right) << endl; }
insert
13
13
13
15
0
p02598
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; long double X[200100]; int N; long long Count(long double len) { long long Ans = 0; for (int i = 0; i < N; i++) { // Ans+=(long long)(X[i]/len);//解答引っ張ってきた人の条件。なぜか通る Ans += ceil(X[i] / len) - 1; // 多少遅くなるがこっちが正解 } return Ans; } int main() { long long K; cin >> N >> K; for (int i = 0; i < N; i++) { cin >> X[i]; // X[i]-=0.1; } long double l = 1, r = 1e9; // while(l<r-0.1)//解答を引っ張ってきた人の条件。なぜかOKだったが、lとrの整数部が異なる状態でループを出ると問題になるはず // for(int i=0;i<35;i++)//OK // log2(10^9)=30.二分探索だとこのやり方安定する。ただし、浮動小数のせいか34以上でないと通らず。 // while(!((ceil(r)-ceil(l)) == // 0))//NG:左端が初期値0のままだと、右端のceilは0にならず、無限ループ while (!((floor(r) - floor(l)) == 0)) // OK:右端がぴったり整数にならなければ成立.(あまりよくない) { long double mid = (l + r) / 2; if (Count(mid) <= K) r = mid; else l = mid; } cout << (long long)(l + 0.999) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; long double X[200100]; int N; long long Count(long double len) { long long Ans = 0; for (int i = 0; i < N; i++) { Ans += (long long)(X[i] / len); // 解答引っ張ってきた人の条件。なぜか通る // Ans+= ceil(X[i]/len)-1;//多少遅くなるがこっちが正解 } return Ans; } int main() { long long K; cin >> N >> K; for (int i = 0; i < N; i++) { cin >> X[i]; // X[i]-=0.1; } long double l = 1, r = 1e9; // while(l<r-0.1)//解答を引っ張ってきた人の条件。なぜかOKだったが、lとrの整数部が異なる状態でループを出ると問題になるはず // for(int i=0;i<35;i++)//OK // log2(10^9)=30.二分探索だとこのやり方安定する。ただし、浮動小数のせいか34以上でないと通らず。 // while(!((ceil(r)-ceil(l)) == // 0))//NG:左端が初期値0のままだと、右端のceilは0にならず、無限ループ while (!((floor(r) - floor(l)) == 0)) // OK:右端がぴったり整数にならなければ成立.(あまりよくない) { long double mid = (l + r) / 2; if (Count(mid) <= K) r = mid; else l = mid; } cout << (long long)(l + 0.999) << endl; return 0; }
replace
7
9
7
9
TLE
p02598
C++
Runtime Error
#include <algorithm> #include <bits/stdc++.h> #include <cstdio> #include <iostream> using namespace std; int a[200005] = {0}; int n, k; int solve(int fun) { int num = 0; for (int i = 0; i < n; i++) { num += (a[i] - 1) / fun; } if (num <= k) return 1; return 0; } int main() { cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; int l = 0, r = 1000000007; int ans = 0; while (l < r) { int m = (l + r) / 2; if (solve(m)) { r = m; ans = m; } else l = m + 1; // cout << l << " " << r << endl; } cout << ans << endl; return 0; }
#include <algorithm> #include <bits/stdc++.h> #include <cstdio> #include <iostream> using namespace std; int a[200005] = {0}; int n, k; int solve(int fun) { int num = 0; for (int i = 0; i < n; i++) { num += (a[i] - 1) / fun; } if (num <= k) return 1; return 0; } int main() { cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; int l = 1, r = 1000000007; int ans = 0; while (l < r) { int m = (l + r) / 2; if (solve(m)) { r = m; ans = m; } else l = m + 1; // cout << l << " " << r << endl; } cout << ans << endl; return 0; }
replace
20
21
20
21
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; (i) < ((int)(n)); ++(i)) int main() { ll N, K; cin >> N >> K; vector<ll> A(N); rep(i, N) cin >> A[i]; sort(A.begin(), A.end(), greater<ll>()); ll l = 0, r = 1000000000; ll m = (l + r) / 2; while (r - l > 0) { ll Count = 0; rep(i, N) { if (A[i] > m) { Count += A[i] / m; } } if (Count <= K) { r = m; m = (l + r) / 2; } else { l = m + 1; m = (l + r) / 2; } } cout << m << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; (i) < ((int)(n)); ++(i)) int main() { ll N, K; cin >> N >> K; vector<ll> A(N); rep(i, N) cin >> A[i]; sort(A.begin(), A.end(), greater<ll>()); ll l = 1, r = 1000000000; ll m = (l + r) / 2; while (r - l > 0) { ll Count = 0; rep(i, N) { if (A[i] > m) { Count += A[i] / m; } } if (Count <= K) { r = m; m = (l + r) / 2; } else { l = m + 1; m = (l + r) / 2; } } cout << m << endl; }
replace
11
12
11
12
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define CPP_STR(x) CPP_STR_I(x) #define CPP_CAT(x, y) CPP_CAT_I(x, y) #define CPP_STR_I(args...) #args #define CPP_CAT_I(x, y) x##y using i8 = int8_t; using u8 = uint8_t; using i16 = int16_t; using u16 = uint16_t; using i32 = int32_t; using u32 = uint32_t; using i64 = int64_t; using u64 = uint64_t; using f32 = float; using f64 = double; #define FOR(i, start, end) \ for (i64 i = (start), CPP_CAT(i, xxxx_end) = (end); \ i < CPP_CAT(i, xxxx_end); ++i) #define REP(i, n) FOR(i, 0, n) #define REPS(i, n) for (i64 i = 1; i <= n; ++i) #define RREP(i, n) for (i64 i = n - 1; i >= 0; --i) #define RREPS(i, n) for (i64 i = n; i >= 1; --i) #define ALL(f, c, ...) \ (([&](decltype((c)) cccc) { \ return (f)(std::begin(cccc), std::end(cccc), ##__VA_ARGS__); \ })(c)) #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()); #define pb push_back #define mp make_pair 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; } template <typename C> i64 SIZE(const C &c) { return static_cast<i64>(c.size()); } template <typename T, size_t N> i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); } #define YES(n) cout << ((n) ? "YES" : "NO") << endl #define Yes(n) cout << ((n) ? "Yes" : "No") << endl #define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE") << endl #define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl #define VIN(x) \ for (auto &youso_ : (x)) \ cin >> youso_ #define VOUT(x, delim) \ for (auto &youso_ : (x)) \ cout << youso_ << delim; \ cout << endl #define COUT(x) cout << (x) << endl void CINT() {} template <class Head, class... Tail> void CINT(Head &&head, Tail &&...tail) { cin >> head; CINT(move(tail)...); } #define CIN(...) \ i64 __VA_ARGS__; \ CINT(__VA_ARGS__) #define SCIN(...) \ string __VA_ARGS__; \ CINT(__VA_ARGS__) struct ProconInit { static constexpr int IOS_PREC = 15; static constexpr bool AUTOFLUSH = false; ProconInit() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(IOS_PREC); if (AUTOFLUSH) cout << unitbuf; } } PROCON_INIT; int main() { CIN(N, K); vector<i64> A(N); VIN(A); ALL(sort, A, greater<i64>()); auto ok = [&](i64 x) { i64 cnt = 0; REP(i, N) { if (A[i] <= x) break; cnt += A[i] / x; } return cnt <= K; }; i64 ub = A[0] + 1; i64 lb = 0; REP(i, 100) { i64 mid = (ub + lb) / 2; if (ok(mid)) ub = mid; else lb = mid; } COUT(ub); return 0; }
#include <bits/stdc++.h> using namespace std; #define CPP_STR(x) CPP_STR_I(x) #define CPP_CAT(x, y) CPP_CAT_I(x, y) #define CPP_STR_I(args...) #args #define CPP_CAT_I(x, y) x##y using i8 = int8_t; using u8 = uint8_t; using i16 = int16_t; using u16 = uint16_t; using i32 = int32_t; using u32 = uint32_t; using i64 = int64_t; using u64 = uint64_t; using f32 = float; using f64 = double; #define FOR(i, start, end) \ for (i64 i = (start), CPP_CAT(i, xxxx_end) = (end); \ i < CPP_CAT(i, xxxx_end); ++i) #define REP(i, n) FOR(i, 0, n) #define REPS(i, n) for (i64 i = 1; i <= n; ++i) #define RREP(i, n) for (i64 i = n - 1; i >= 0; --i) #define RREPS(i, n) for (i64 i = n; i >= 1; --i) #define ALL(f, c, ...) \ (([&](decltype((c)) cccc) { \ return (f)(std::begin(cccc), std::end(cccc), ##__VA_ARGS__); \ })(c)) #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()); #define pb push_back #define mp make_pair 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; } template <typename C> i64 SIZE(const C &c) { return static_cast<i64>(c.size()); } template <typename T, size_t N> i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); } #define YES(n) cout << ((n) ? "YES" : "NO") << endl #define Yes(n) cout << ((n) ? "Yes" : "No") << endl #define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE") << endl #define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl #define VIN(x) \ for (auto &youso_ : (x)) \ cin >> youso_ #define VOUT(x, delim) \ for (auto &youso_ : (x)) \ cout << youso_ << delim; \ cout << endl #define COUT(x) cout << (x) << endl void CINT() {} template <class Head, class... Tail> void CINT(Head &&head, Tail &&...tail) { cin >> head; CINT(move(tail)...); } #define CIN(...) \ i64 __VA_ARGS__; \ CINT(__VA_ARGS__) #define SCIN(...) \ string __VA_ARGS__; \ CINT(__VA_ARGS__) struct ProconInit { static constexpr int IOS_PREC = 15; static constexpr bool AUTOFLUSH = false; ProconInit() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(IOS_PREC); if (AUTOFLUSH) cout << unitbuf; } } PROCON_INIT; int main() { CIN(N, K); vector<i64> A(N); VIN(A); ALL(sort, A, greater<i64>()); auto ok = [&](i64 x) { i64 cnt = 0; REP(i, N) { if (A[i] <= x) break; cnt += A[i] / x; } return cnt <= K; }; i64 ub = A[0] + 1; i64 lb = 0; while (ub - lb > 1) { i64 mid = (ub + lb) / 2; if (ok(mid)) ub = mid; else lb = mid; } COUT(ub); return 0; }
replace
118
119
118
119
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> #define pb push_back #define fi first #define se second #define io std::ios::sync_with_stdio(false) using namespace std; typedef long long ll; typedef pair<int, int> pii; const int P = 1e9 + 7, INF = 0x3f3f3f3f; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int qpow(int a, int n) { int r = 1 % P; for (a %= P; n; a = a * a % P, n >>= 1) if (n & 1) r = r * a % P; return r; } const int maxn = 1e5 + 10; int a[maxn]; int n, k; int check(int x) { int kk = 0; for (int i = 1; i <= n; i++) { kk += (a[i] - 1) / x; } if (kk > k) return 0; else return 1; } int main() { cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; } int l = 1, r = 1e9; int ans = 0; while (l <= r) { int mid = (l + r) / 2; if (check(mid)) { r = mid - 1; ans = mid; } else { l = mid + 1; } } cout << ans << endl; }
#include <bits/stdc++.h> #define pb push_back #define fi first #define se second #define io std::ios::sync_with_stdio(false) using namespace std; typedef long long ll; typedef pair<int, int> pii; const int P = 1e9 + 7, INF = 0x3f3f3f3f; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int qpow(int a, int n) { int r = 1 % P; for (a %= P; n; a = a * a % P, n >>= 1) if (n & 1) r = r * a % P; return r; } const int maxn = 2e5 + 50; int a[maxn]; int n, k; int check(int x) { int kk = 0; for (int i = 1; i <= n; i++) { kk += (a[i] - 1) / x; } if (kk > k) return 0; else return 1; } int main() { cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; } int l = 1, r = 1e9; int ans = 0; while (l <= r) { int mid = (l + r) / 2; if (check(mid)) { r = mid - 1; ans = mid; } else { l = mid + 1; } } cout << ans << endl; }
replace
17
18
17
18
0
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 long double ld; // typedef tree<int,null_type,less<int // >,rb_tree_tag,tree_order_statistics_node_update>indexed_set; template <class T1, class T2> ostream &operator<<(ostream &os, pair<T1, T2> &p); template <class T> ostream &operator<<(ostream &os, vector<T> &v); template <class T> ostream &operator<<(ostream &os, set<T> &v); template <class T1, class T2> ostream &operator<<(ostream &os, map<T1, T2> &v); #ifdef APURBA #define debug(a) cout << #a << " --> " << (a) << "\n"; #define debug2(a) cout << #a << " --> " << (a) << " "; #define HERE cout << "here - " << __LINE__ << "\n"; #else #define debug(a) #define debug2(a) #define HERE #endif const ll mod = 1e9 + 7; const int N = 5e5 + 5; typedef pair<int, int> pii; ll n, k; vector<ll> a; bool check(ll val) { ll cnt = 0; for (ll i = 0; i < n; i++) { ll now = a[i]; if (now <= val) continue; ll tmp = now / val; if (now % val) { tmp++; } cnt += tmp - 1; } return cnt <= k; } void TEST_CASES(int cas) { scanf("%lld %lld", &n, &k); a.resize(n); for (ll &i : a) { scanf("%lld", &i); } ll ans = -1; ll low = 0, high = *max_element(a.begin(), a.end()); while (low <= high) { ll mid = (low + high) / 2; if (check(mid)) { ans = mid; high = mid - 1; } else { low = mid + 1; } } printf("%lld\n", ans); } /* */ int main() { // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); int t = 1, cas = 0; // scanf("%d",&t); while (t--) { TEST_CASES(++cas); } return 0; } template <class T1, class T2> ostream &operator<<(ostream &os, pair<T1, T2> &p) { os << "{" << p.first << ", " << p.second << "} "; return os; } template <class T> ostream &operator<<(ostream &os, vector<T> &v) { os << "[ "; for (int i = 0; i < v.size(); i++) { os << v[i] << " "; } os << " ]"; return os; } template <class T> ostream &operator<<(ostream &os, set<T> &v) { os << "[ "; for (T i : v) { os << i << " "; } os << " ]"; return os; } template <class T1, class T2> ostream &operator<<(ostream &os, map<T1, T2> &v) { for (auto i : v) { os << "Key : " << i.first << " , Value : " << i.second << endl; } return os; }
#include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // using namespace __gnu_pbds; using namespace std; typedef long long ll; typedef long double ld; // typedef tree<int,null_type,less<int // >,rb_tree_tag,tree_order_statistics_node_update>indexed_set; template <class T1, class T2> ostream &operator<<(ostream &os, pair<T1, T2> &p); template <class T> ostream &operator<<(ostream &os, vector<T> &v); template <class T> ostream &operator<<(ostream &os, set<T> &v); template <class T1, class T2> ostream &operator<<(ostream &os, map<T1, T2> &v); #ifdef APURBA #define debug(a) cout << #a << " --> " << (a) << "\n"; #define debug2(a) cout << #a << " --> " << (a) << " "; #define HERE cout << "here - " << __LINE__ << "\n"; #else #define debug(a) #define debug2(a) #define HERE #endif const ll mod = 1e9 + 7; const int N = 5e5 + 5; typedef pair<int, int> pii; ll n, k; vector<ll> a; bool check(ll val) { ll cnt = 0; for (ll i = 0; i < n; i++) { ll now = a[i]; if (now <= val) continue; ll tmp = now / val; if (now % val) { tmp++; } cnt += tmp - 1; } return cnt <= k; } void TEST_CASES(int cas) { scanf("%lld %lld", &n, &k); a.resize(n); for (ll &i : a) { scanf("%lld", &i); } ll ans = -1; ll low = 1, high = *max_element(a.begin(), a.end()); while (low <= high) { ll mid = (low + high) / 2; if (check(mid)) { ans = mid; high = mid - 1; } else { low = mid + 1; } } printf("%lld\n", ans); } /* */ int main() { // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); int t = 1, cas = 0; // scanf("%d",&t); while (t--) { TEST_CASES(++cas); } return 0; } template <class T1, class T2> ostream &operator<<(ostream &os, pair<T1, T2> &p) { os << "{" << p.first << ", " << p.second << "} "; return os; } template <class T> ostream &operator<<(ostream &os, vector<T> &v) { os << "[ "; for (int i = 0; i < v.size(); i++) { os << v[i] << " "; } os << " ]"; return os; } template <class T> ostream &operator<<(ostream &os, set<T> &v) { os << "[ "; for (T i : v) { os << i << " "; } os << " ]"; return os; } template <class T1, class T2> ostream &operator<<(ostream &os, map<T1, T2> &v) { for (auto i : v) { os << "Key : " << i.first << " , Value : " << i.second << endl; } return os; }
replace
49
50
49
50
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pll; #define rep(i, n) for (int i = 0; i < (n); ++i) const int MAXN = 2e5 + 1; ll N, K; ll A[MAXN]; bool chk(ll l) { ll totalCut = 0; rep(i, N) { totalCut += (A[i] + l - 1) / l - 1; } return totalCut <= K; } int main() { cin >> N >> K; rep(i, N) cin >> A[i]; ll ans = -1; ll lo = 0, hi = 1e9; while (lo <= hi) { ll mid = (lo + hi) / 2; if (chk(mid)) { ans = mid; hi = mid - 1; } else { lo = mid + 1; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pll; #define rep(i, n) for (int i = 0; i < (n); ++i) const int MAXN = 2e5 + 1; ll N, K; ll A[MAXN]; bool chk(ll l) { ll totalCut = 0; rep(i, N) { totalCut += (A[i] + l - 1) / l - 1; } return totalCut <= K; } int main() { cin >> N >> K; rep(i, N) cin >> A[i]; ll ans = -1; ll lo = 1, hi = 1e9; while (lo <= hi) { ll mid = (lo + hi) / 2; if (chk(mid)) { ans = mid; hi = mid - 1; } else { lo = mid + 1; } } cout << ans << endl; }
replace
21
22
21
22
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; /******* All Required define Pre-Processors and typedef Constants *******/ #define all(cont) cont.begin(), cont.end() #define rall(cont) cont.rbegin(), cont.rend() #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep1(i, n) for (int i = 1; i <= (n); ++i) #define Dcout(a) cout << setprecision(20) << a << endl #define MP make_pair #define PB push_back #define EPS 1e-9 #define PI 3.1415926535897932384626433832795 #define MOD 1000000007 using ll = long long; using PAIR = pair<int, int>; using Graph = vector<vector<int>>; const ll INF = (1LL << 60); const double pi = acos(-1.0); #define debug cout << "line : " << __LINE__ << " debug" << endl /****** Template of some basic operations *****/ template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } /**************************************/ /******** User-defined Function *******/ /**************************************/ /********** Main() function **********/ int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, k; cin >> n >> k; vector<ll> a(n); rep(i, n) cin >> a[i]; sort(all(a)); int ng = -1; int ok = 1e9; while (abs(ok - ng) > 1) { int mid = (ok + ng) / 2; // 答えをxとして全てのlogsはx以下にk回以内で切れるのか auto f = [&](int x) { ll now = 0; rep(i, n) { now += (a[i] - 1) / x; } // 切れる場合はtrueを返す return now <= k; }; if (f(mid)) ok = mid; else ng = mid; } cout << ok << endl; return 0; } /******** Main() Ends Here *************/
#include <bits/stdc++.h> using namespace std; /******* All Required define Pre-Processors and typedef Constants *******/ #define all(cont) cont.begin(), cont.end() #define rall(cont) cont.rbegin(), cont.rend() #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep1(i, n) for (int i = 1; i <= (n); ++i) #define Dcout(a) cout << setprecision(20) << a << endl #define MP make_pair #define PB push_back #define EPS 1e-9 #define PI 3.1415926535897932384626433832795 #define MOD 1000000007 using ll = long long; using PAIR = pair<int, int>; using Graph = vector<vector<int>>; const ll INF = (1LL << 60); const double pi = acos(-1.0); #define debug cout << "line : " << __LINE__ << " debug" << endl /****** Template of some basic operations *****/ template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } /**************************************/ /******** User-defined Function *******/ /**************************************/ /********** Main() function **********/ int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, k; cin >> n >> k; vector<ll> a(n); rep(i, n) cin >> a[i]; sort(all(a)); int ng = 0; int ok = 1e9; while (abs(ok - ng) > 1) { int mid = (ok + ng) / 2; // 答えをxとして全てのlogsはx以下にk回以内で切れるのか auto f = [&](int x) { ll now = 0; rep(i, n) { now += (a[i] - 1) / x; } // 切れる場合はtrueを返す return now <= k; }; if (f(mid)) ok = mid; else ng = mid; } cout << ok << endl; return 0; } /******** Main() Ends Here *************/
replace
49
50
49
50
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define ff first #define ss second #define pb push_back #define rep(i, a, b) for (i = a; i < b; i++) #define pii pair<ll, ll> #define all(x) x.begin(), x.end() #define nl "\n" #define ump unordered_map #define mtv(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__) 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) { cout << endl; } template <typename Head, typename... Tail> void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) { stringstream ss; ss << H; cout << args[idx] << "- " << ss.str() << ", "; debug_out(args, idx + 1, LINE_NUM, T...); } bool isvalid(ll k, ll n, vector<ll> &v, ll cur) { ll i, cou = 0; rep(i, 0, n) { if (v[i] > cur) { cou += (v[i] / cur - 1); if (v[i] % cur) cou++; } } return cou <= k; } void doit() { ll n, k, i, x; cin >> n >> k; vector<ll> v(n); for (i = 0; i < n; i++) cin >> v[i]; ll low = 0LL, high = *max_element(all(v)), mid, ans = 1e18; while (low <= high) { mid = low + (high - low) / 2; if (isvalid(k, n, v, mid)) { ans = mid; high = mid - 1; } else { low = mid + 1; } } // mtv(isvalid(k,n,v,292638192)); cout << ans << nl; } 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); ll t = 1; // cin >> t; for (ll i = 1; i <= t; i++) { doit(); } }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ff first #define ss second #define pb push_back #define rep(i, a, b) for (i = a; i < b; i++) #define pii pair<ll, ll> #define all(x) x.begin(), x.end() #define nl "\n" #define ump unordered_map #define mtv(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__) 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) { cout << endl; } template <typename Head, typename... Tail> void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) { stringstream ss; ss << H; cout << args[idx] << "- " << ss.str() << ", "; debug_out(args, idx + 1, LINE_NUM, T...); } bool isvalid(ll k, ll n, vector<ll> &v, ll cur) { ll i, cou = 0; if (cur == 0) { return false; } rep(i, 0, n) { if (v[i] > cur) { cou += (v[i] / cur - 1); if (v[i] % cur) cou++; } } return cou <= k; } void doit() { ll n, k, i, x; cin >> n >> k; vector<ll> v(n); for (i = 0; i < n; i++) cin >> v[i]; ll low = 0LL, high = *max_element(all(v)), mid, ans = 1e18; while (low <= high) { mid = low + (high - low) / 2; if (isvalid(k, n, v, mid)) { ans = mid; high = mid - 1; } else { low = mid + 1; } } // mtv(isvalid(k,n,v,292638192)); cout << ans << nl; } 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); ll t = 1; // cin >> t; for (ll i = 1; i <= t; i++) { doit(); } }
insert
38
38
38
41
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define VI vector<int> #define VLL vector<ll> #define PII pair<int, int> #define mp make_pair #define pb push_back #define PI acos(-1) #define ld long double const int MxN = 200001; #define FOR(i, a, b) for (int i = a; i < b; ++i) #define RFOR(i, a, b) for (int i = a; i >= b; --i) const int MOD = 1e9 + 7; /* VARIABLES */ int n, k; VI logs(MxN); /* END OF VARIABLES */ ll fun(int v) { ll cnt = 0; FOR(i, 0, n) { if (logs[i] <= v) continue; int rem = (logs[i] + v - 1) / v; // cout << rem << " " ; cnt += rem - 1; } return cnt; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> k; FOR(i, 0, n) cin >> logs[i]; ll l = 0; ll r = 1e9; ll ans = 1e9; while (l <= r) { ll m = l + (r - l) / 2; // cout << m << " " << fun(m) << endl ; if (fun(m) > k) l = m + 1; else { ans = min(ans, m); r = m - 1; } } cout << ans; cout << endl; // cout << fun(5) ; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define VI vector<int> #define VLL vector<ll> #define PII pair<int, int> #define mp make_pair #define pb push_back #define PI acos(-1) #define ld long double const int MxN = 200001; #define FOR(i, a, b) for (int i = a; i < b; ++i) #define RFOR(i, a, b) for (int i = a; i >= b; --i) const int MOD = 1e9 + 7; /* VARIABLES */ int n, k; VI logs(MxN); /* END OF VARIABLES */ ll fun(int v) { ll cnt = 0; FOR(i, 0, n) { if (logs[i] <= v) continue; int rem = (logs[i] + v - 1) / v; // cout << rem << " " ; cnt += rem - 1; } return cnt; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> k; FOR(i, 0, n) cin >> logs[i]; ll l = 1; ll r = 1e9; ll ans = 1e9; while (l <= r) { ll m = l + (r - l) / 2; // cout << m << " " << fun(m) << endl ; if (fun(m) > k) l = m + 1; else { ans = min(ans, m); r = m - 1; } } cout << ans; cout << endl; // cout << fun(5) ; return 0; }
replace
40
41
40
41
0
p02598
C++
Runtime Error
/** * author: otera **/ #include <algorithm> #include <bitset> #include <cassert> #include <ciso646> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <utility> #include <vector> using namespace std; #define int long long typedef long long ll; typedef unsigned long long ul; typedef unsigned int ui; typedef long double ld; const int inf = 1e9 + 7; const ll INF = 1LL << 60; const ll mod = 1e9 + 7; #define rep(i, n) for (int i = 0; i < n; i++) #define per(i, n) for (int i = n - 1; i >= 0; i--) #define Rep(i, sta, n) for (int i = sta; i < n; i++) #define rep1(i, n) for (int i = 1; i <= n; i++) #define per1(i, n) for (int i = n; i >= 1; i--) #define Rep1(i, sta, n) for (int i = sta; i <= n; i++) typedef complex<ld> Point; const ld eps = 1e-8; const ld pi = acos(-1.0); typedef pair<int, int> P; typedef pair<ld, ld> LDP; typedef pair<ll, ll> LP; #define fr first #define sc second #define all(c) c.begin(), c.end() #define pb push_back #define debug(x) cerr << #x << " = " << (x) << endl; 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; } int n, k; vector<int> a; bool check(int x) { int cnt = 0; rep(i, n) { if (a[i] <= x) continue; cnt += (a[i] - 1) / x; } return (cnt <= k); } void solve() { cin >> n >> k; a.resize(n); rep(i, n) { cin >> a[i]; } int ok = inf, ng = -1; while (ok - ng > 1) { int mid = (ok + ng) / 2; if (check(mid)) ok = mid; else ng = mid; } cout << ok << endl; } signed main() { ios::sync_with_stdio(false); cin.tie(0); // cout << fixed << setprecision(10); // int t; cin >> t; rep(i, t)solve(); solve(); return 0; }
/** * author: otera **/ #include <algorithm> #include <bitset> #include <cassert> #include <ciso646> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <utility> #include <vector> using namespace std; #define int long long typedef long long ll; typedef unsigned long long ul; typedef unsigned int ui; typedef long double ld; const int inf = 1e9 + 7; const ll INF = 1LL << 60; const ll mod = 1e9 + 7; #define rep(i, n) for (int i = 0; i < n; i++) #define per(i, n) for (int i = n - 1; i >= 0; i--) #define Rep(i, sta, n) for (int i = sta; i < n; i++) #define rep1(i, n) for (int i = 1; i <= n; i++) #define per1(i, n) for (int i = n; i >= 1; i--) #define Rep1(i, sta, n) for (int i = sta; i <= n; i++) typedef complex<ld> Point; const ld eps = 1e-8; const ld pi = acos(-1.0); typedef pair<int, int> P; typedef pair<ld, ld> LDP; typedef pair<ll, ll> LP; #define fr first #define sc second #define all(c) c.begin(), c.end() #define pb push_back #define debug(x) cerr << #x << " = " << (x) << endl; 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; } int n, k; vector<int> a; bool check(int x) { int cnt = 0; rep(i, n) { if (a[i] <= x) continue; cnt += (a[i] - 1) / x; } return (cnt <= k); } void solve() { cin >> n >> k; a.resize(n); rep(i, n) { cin >> a[i]; } int ok = inf, ng = 0; while (ok - ng > 1) { int mid = (ok + ng) / 2; if (check(mid)) ok = mid; else ng = mid; } cout << ok << endl; } signed main() { ios::sync_with_stdio(false); cin.tie(0); // cout << fixed << setprecision(10); // int t; cin >> t; rep(i, t)solve(); solve(); return 0; }
replace
83
84
83
84
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef bool boool; typedef long long ll; #define vl vector<ll> #define vb vector<boool> #define vs vector<string> #define vp vector<pair<ll, ll>> #define vvl vector<vector<ll>> #define vvp vector<vector<pair<ll, ll>>> #define mod 1000000007 #define all(x) x.begin(), x.end() #define rep1(i, n) for (long long i = 0; i < (long long)(n); i++) #define rep2(i, s, e) for (long long i = (s); i < (long long)(e); i++) #define GET_MACRO(_1, _2, _3, NAME, ...) NAME #define rep(...) GET_MACRO(__VA_ARGS__, rep2, rep1)(__VA_ARGS__) int main() { ll n, k; cin >> n >> k; vl vec(n); rep(i, n) cin >> vec[i]; sort(all(vec)); if (k == 0) { cout << vec.back() << endl; return 0; } ll ng = -1; ll ok = 1000000001; while (abs(ok - ng) > 1) { ll mid = (ok + ng) / 2; ll sum = 0; rep(i, n) { sum += (vec[i] + (mid - 1)) / mid - 1; } if (sum <= k) ok = mid; else ng = mid; } cout << ok << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef bool boool; typedef long long ll; #define vl vector<ll> #define vb vector<boool> #define vs vector<string> #define vp vector<pair<ll, ll>> #define vvl vector<vector<ll>> #define vvp vector<vector<pair<ll, ll>>> #define mod 1000000007 #define all(x) x.begin(), x.end() #define rep1(i, n) for (long long i = 0; i < (long long)(n); i++) #define rep2(i, s, e) for (long long i = (s); i < (long long)(e); i++) #define GET_MACRO(_1, _2, _3, NAME, ...) NAME #define rep(...) GET_MACRO(__VA_ARGS__, rep2, rep1)(__VA_ARGS__) int main() { ll n, k; cin >> n >> k; vl vec(n); rep(i, n) cin >> vec[i]; sort(all(vec)); ll ng = 0; ll ok = 1000000001; while (abs(ok - ng) > 1) { ll mid = (ok + ng) / 2; ll sum = 0; rep(i, n) { sum += (vec[i] + (mid - 1)) / mid - 1; } if (sum <= k) ok = mid; else ng = mid; } cout << ok << endl; return 0; }
replace
23
28
23
24
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int n, k; vector<int> a(20000); bool good(int x) { int cut = 0; for (int i = 0; i < n; i++) { cut += a[i] / x; if (a[i] % x == 0) cut--; if (cut > k) return false; } return true; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> k; for (int i = 0; i < n; i++) { cin >> a[i]; } int upper = *max_element(a.begin(), a.end()); int lower = 0; int mid = 1; while (upper - lower > 1) { mid = (upper + lower) / 2; if (good(mid)) { upper = mid; } else { lower = mid; } } cout << upper << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; int n, k; vector<int> a(200000); bool good(int x) { int cut = 0; for (int i = 0; i < n; i++) { cut += a[i] / x; if (a[i] % x == 0) cut--; if (cut > k) return false; } return true; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> k; for (int i = 0; i < n; i++) { cin >> a[i]; } int upper = *max_element(a.begin(), a.end()); int lower = 0; int mid = 1; while (upper - lower > 1) { mid = (upper + lower) / 2; if (good(mid)) { upper = mid; } else { lower = mid; } } cout << upper << '\n'; return 0; }
replace
5
6
5
6
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; vector<int> a(n); for (auto &&e : a) { cin >> e; } int upper = *max_element(a.begin(), a.end()) + 1; int lower = -1; while (upper - lower > 1) { int mid = lower + (upper - lower) / 2; auto ok = [&](int x) { int cnt = 0; for (auto &&e : a) { cnt += (e - 1) / x; } return (cnt <= k); }; if (ok(mid)) { upper = mid; } else { lower = mid; } } cout << upper << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; vector<int> a(n); for (auto &&e : a) { cin >> e; } int upper = *max_element(a.begin(), a.end()); int lower = 0; while (upper - lower > 1) { int mid = lower + (upper - lower) / 2; auto ok = [&](int x) { int cnt = 0; for (auto &&e : a) { cnt += (e - 1) / x; } return (cnt <= k); }; if (ok(mid)) { upper = mid; } else { lower = mid; } } cout << upper << '\n'; return 0; }
replace
15
17
15
17
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> #define INFLL 1e18 using namespace std; #define REPR(i, n) for (int i = (n); i >= 0; --i) #define FOR(i, m, n) for (int i = (m); i < (n); ++i) #define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define ALL(a) (a).begin(), (a).end() #define endl "\n" template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } typedef long long ll; void solve() { // 解xに対して K回以内の切断で達成かのうか調べる O(Nlogmax(Ai)) ll N, K; cin >> N >> K; vector<ll> A(N); REP(i, N) cin >> A[i]; auto isOk = [&](ll key) { ll need_cut = 0; for (const auto &a : A) { // debug ll cut = ((a + key - 1) / key) - 1; need_cut += cut; } bool res = need_cut <= K; return res; }; // binary search ll l = -1; ll r = INFLL; while ((r - l) > 1) { ll mid = (l + r) / 2; if (isOk(mid)) r = mid; else l = mid; } cout << r << endl; } int main() { solve(); return 0; }
#include <bits/stdc++.h> #define INFLL 1e18 using namespace std; #define REPR(i, n) for (int i = (n); i >= 0; --i) #define FOR(i, m, n) for (int i = (m); i < (n); ++i) #define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define ALL(a) (a).begin(), (a).end() #define endl "\n" template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } typedef long long ll; void solve() { // 解xに対して K回以内の切断で達成かのうか調べる O(Nlogmax(Ai)) ll N, K; cin >> N >> K; vector<ll> A(N); REP(i, N) cin >> A[i]; auto isOk = [&](ll key) { ll need_cut = 0; for (const auto &a : A) { // debug ll cut = ((a + key - 1) / key) - 1; need_cut += cut; } bool res = need_cut <= K; return res; }; // binary search ll l = 0; ll r = INFLL; while ((r - l) > 1) { ll mid = (l + r) / 2; if (isOk(mid)) r = mid; else l = mid; } cout << r << endl; } int main() { solve(); return 0; }
replace
45
46
45
46
0
p02598
C++
Runtime Error
#pragma GCC optimize("O3") #include <algorithm> #include <iostream> #include <list> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unordered_map> #include <unordered_set> using namespace std; using QWORD = uint64_t; using SQWORD = int64_t; using DWORD = uint32_t; using SDWORD = int32_t; using WORD = uint16_t; using SWORD = int16_t; using BYTE = uint8_t; using SBYTE = int8_t; using DOUBLE = double; using LDOUBLE = long double; using FLOAT = float; #define MIN_SDWORD (-2147483648) #define MAX_SDWORD (2147483647) #define MIN_SBYTE (-128) #define MAX_SBYTE (127) #define MIN_SQWORD (0x8000000000000000) #define MAX_SQWORD (0x7FFFFFFFFFFFFFFF) #define MAX_QWORD (0xFFFFFFFFFFFFFFFF) #define MAX_DWORD (0xFFFFFFFF) #define MAX_WORD (0xFFFF) #define MAX_BYTE (0xFF) #define MAX_DOUBLE (1.0e+308) #define DOUBLE_EPS (1.0e-12) #define MIN_DOUBLE_N (-1.0e+308) #define ArrayLength(a) (sizeof(a) / sizeof(a[0])) static inline DOUBLE MAX(DOUBLE a, DOUBLE b) { return a > b ? a : b; } static inline QWORD MAX(QWORD a, QWORD b) { return a > b ? a : b; } static inline DWORD MAX(DWORD a, DWORD b) { return a > b ? a : b; } static inline SDWORD MAX(SDWORD a, SDWORD b) { return a > b ? a : b; } static inline DOUBLE MIN(DOUBLE a, DOUBLE b) { return a < b ? a : b; } static inline QWORD MIN(QWORD a, QWORD b) { return a < b ? a : b; } static inline DWORD MIN(DWORD a, DWORD b) { return a < b ? a : b; } static inline SDWORD MIN(SDWORD a, SDWORD b) { return a < b ? a : b; } #define BYTE_BITS (8) #define WORD_BITS (16) #define DWORD_BITS (32) #define QWORD_BITS (64) static inline void inputStringSpSeparated(char *pcStr) { char *pcCur = pcStr; for (;;) { char c = getchar(); if (('\n' == c) || (EOF == c) || (' ' == c)) { break; } *pcCur = c; pcCur++; } *pcCur = '\0'; } static inline void inputString(char *pcStr) { char *pcCur = pcStr; for (;;) { char c = getchar(); if (('\n' == c) || (EOF == c)) { break; } *pcCur = c; pcCur++; } *pcCur = '\0'; } static inline SQWORD inputSQWORD(void) { SQWORD sqNumber = 0; SQWORD sqMultiplier = 1; bool bRead = false; for (;;) { char c = getchar(); if (!bRead) { if ('-' == c) { sqMultiplier = -1; } } if (('0' <= c) && (c <= '9')) { sqNumber *= 10LL; sqNumber += (SQWORD)(c - '0'); bRead = true; } else { if (bRead) { return sqNumber * sqMultiplier; } } } } static inline SDWORD inputSDWORD(void) { SDWORD lNumber = 0; SDWORD lMultiplier = 1; bool bRead = false; for (;;) { char c = getchar(); if (!bRead) { if ('-' == c) { lMultiplier = -1; } } if (('0' <= c) && (c <= '9')) { lNumber *= 10; lNumber += (c - '0'); bRead = true; } else { if (bRead) { return lNumber * lMultiplier; } } } } static inline DOUBLE inputFP(void) { DOUBLE dInt = 0.0; DOUBLE dFrac = 0.0; DOUBLE dMultiplier = 1.0; DWORD dwFpCnt = 0; DOUBLE *pdCur = &dInt; bool bRead = false; for (;;) { char c = getchar(); if (!bRead) { if ('-' == c) { dMultiplier = -1; } } if ('.' == c) { pdCur = &dFrac; } else if (('0' <= c) && (c <= '9')) { (*pdCur) *= 10; (*pdCur) += (DOUBLE)(c - '0'); bRead = true; if (pdCur == &dFrac) { dwFpCnt++; } } else { if (bRead) { return dMultiplier * (dInt + dFrac / (pow((DOUBLE)10.0, (DOUBLE)dwFpCnt))); } } } } /*----------------------------------------------*/ /** * mod による操作ライブラリ */ #define ANS_MOD (1000000007) class MODINT { static SQWORD MOD; SQWORD m_x; public: MODINT(SQWORD val) { m_x = (val % MOD + MOD) % MOD; }; MODINT() { m_x = 0; } static void Init(SQWORD sqMod) { MOD = sqMod; } MODINT &operator+=(const MODINT a) { m_x = (m_x + a.m_x) % MOD; return *this; }; MODINT &operator-=(const MODINT a) { m_x = (m_x - a.m_x + MOD) % MOD; return *this; }; MODINT &operator*=(const MODINT a) { m_x = (m_x * a.m_x) % MOD; return *this; }; MODINT pow(SQWORD t) const { if (!t) return 1; MODINT a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } MODINT operator+(const MODINT a) const { MODINT res(*this); return (res += a); } MODINT operator-(const MODINT a) const { MODINT res(*this); return (res -= a); } MODINT operator*(const MODINT a) const { MODINT res(*this); return (res *= a); } MODINT operator/(const MODINT a) const { MODINT res(*this); return (res /= a); } /* 逆元 */ MODINT inv() const { return pow(MOD - 2); } /* 除算 */ MODINT &operator/=(const MODINT a) { return (*this) *= a.inv(); } /* 整数版 */ MODINT &operator+=(const SQWORD a) { *this += MODINT(a); return *this; }; MODINT &operator-=(const SQWORD a) { *this -= MODINT(a); return *this; }; MODINT &operator*=(const SQWORD a) { *this *= MODINT(a); return *this; }; MODINT &operator/=(const SQWORD a) { *this /= MODINT(a); return *this; }; SQWORD getVal() { return m_x; }; }; SQWORD MODINT::MOD = ANS_MOD; /*----------------------------------------------*/ static bool isDivisible(SQWORD sqLength, const vector<SQWORD> &vsqA, SQWORD sqCnt) { SQWORD sqNeedCnt = 0; for (auto a : vsqA) { sqNeedCnt += ((a + (sqLength - 1)) / sqLength - 1); if (sqCnt < sqNeedCnt) { return false; } } return true; } static SQWORD binarySearch(bool (*pfJudge)(SQWORD, const vector<SQWORD> &, SQWORD), SQWORD sqInitLower, SQWORD sqInitUpper, const vector<SQWORD> &vsqA, SQWORD sqCnt) { SQWORD sqOk = sqInitUpper; SQWORD sqNg = sqInitLower; while (1LL < sqOk - sqNg) { SQWORD sqMid = (sqNg + sqOk) / 2LL; // printf("%lld\n", sqMid); if (pfJudge(sqMid, vsqA, sqCnt)) { sqOk = sqMid; } else { sqNg = sqMid; } } return sqOk; } #define MAX_ANS (100100100100100100) int main(void) { SQWORD sqN = inputSQWORD(); SQWORD sqK = inputSQWORD(); vector<SQWORD> vsqA; for (SQWORD sqIdx = 0; sqIdx < sqN; sqIdx++) { SQWORD sqA = inputSQWORD(); vsqA.emplace_back(sqA); } SQWORD sqAns = binarySearch(isDivisible, -1, MAX_ANS, vsqA, sqK); printf("%lld\n", sqAns); return 0; }
#pragma GCC optimize("O3") #include <algorithm> #include <iostream> #include <list> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unordered_map> #include <unordered_set> using namespace std; using QWORD = uint64_t; using SQWORD = int64_t; using DWORD = uint32_t; using SDWORD = int32_t; using WORD = uint16_t; using SWORD = int16_t; using BYTE = uint8_t; using SBYTE = int8_t; using DOUBLE = double; using LDOUBLE = long double; using FLOAT = float; #define MIN_SDWORD (-2147483648) #define MAX_SDWORD (2147483647) #define MIN_SBYTE (-128) #define MAX_SBYTE (127) #define MIN_SQWORD (0x8000000000000000) #define MAX_SQWORD (0x7FFFFFFFFFFFFFFF) #define MAX_QWORD (0xFFFFFFFFFFFFFFFF) #define MAX_DWORD (0xFFFFFFFF) #define MAX_WORD (0xFFFF) #define MAX_BYTE (0xFF) #define MAX_DOUBLE (1.0e+308) #define DOUBLE_EPS (1.0e-12) #define MIN_DOUBLE_N (-1.0e+308) #define ArrayLength(a) (sizeof(a) / sizeof(a[0])) static inline DOUBLE MAX(DOUBLE a, DOUBLE b) { return a > b ? a : b; } static inline QWORD MAX(QWORD a, QWORD b) { return a > b ? a : b; } static inline DWORD MAX(DWORD a, DWORD b) { return a > b ? a : b; } static inline SDWORD MAX(SDWORD a, SDWORD b) { return a > b ? a : b; } static inline DOUBLE MIN(DOUBLE a, DOUBLE b) { return a < b ? a : b; } static inline QWORD MIN(QWORD a, QWORD b) { return a < b ? a : b; } static inline DWORD MIN(DWORD a, DWORD b) { return a < b ? a : b; } static inline SDWORD MIN(SDWORD a, SDWORD b) { return a < b ? a : b; } #define BYTE_BITS (8) #define WORD_BITS (16) #define DWORD_BITS (32) #define QWORD_BITS (64) static inline void inputStringSpSeparated(char *pcStr) { char *pcCur = pcStr; for (;;) { char c = getchar(); if (('\n' == c) || (EOF == c) || (' ' == c)) { break; } *pcCur = c; pcCur++; } *pcCur = '\0'; } static inline void inputString(char *pcStr) { char *pcCur = pcStr; for (;;) { char c = getchar(); if (('\n' == c) || (EOF == c)) { break; } *pcCur = c; pcCur++; } *pcCur = '\0'; } static inline SQWORD inputSQWORD(void) { SQWORD sqNumber = 0; SQWORD sqMultiplier = 1; bool bRead = false; for (;;) { char c = getchar(); if (!bRead) { if ('-' == c) { sqMultiplier = -1; } } if (('0' <= c) && (c <= '9')) { sqNumber *= 10LL; sqNumber += (SQWORD)(c - '0'); bRead = true; } else { if (bRead) { return sqNumber * sqMultiplier; } } } } static inline SDWORD inputSDWORD(void) { SDWORD lNumber = 0; SDWORD lMultiplier = 1; bool bRead = false; for (;;) { char c = getchar(); if (!bRead) { if ('-' == c) { lMultiplier = -1; } } if (('0' <= c) && (c <= '9')) { lNumber *= 10; lNumber += (c - '0'); bRead = true; } else { if (bRead) { return lNumber * lMultiplier; } } } } static inline DOUBLE inputFP(void) { DOUBLE dInt = 0.0; DOUBLE dFrac = 0.0; DOUBLE dMultiplier = 1.0; DWORD dwFpCnt = 0; DOUBLE *pdCur = &dInt; bool bRead = false; for (;;) { char c = getchar(); if (!bRead) { if ('-' == c) { dMultiplier = -1; } } if ('.' == c) { pdCur = &dFrac; } else if (('0' <= c) && (c <= '9')) { (*pdCur) *= 10; (*pdCur) += (DOUBLE)(c - '0'); bRead = true; if (pdCur == &dFrac) { dwFpCnt++; } } else { if (bRead) { return dMultiplier * (dInt + dFrac / (pow((DOUBLE)10.0, (DOUBLE)dwFpCnt))); } } } } /*----------------------------------------------*/ /** * mod による操作ライブラリ */ #define ANS_MOD (1000000007) class MODINT { static SQWORD MOD; SQWORD m_x; public: MODINT(SQWORD val) { m_x = (val % MOD + MOD) % MOD; }; MODINT() { m_x = 0; } static void Init(SQWORD sqMod) { MOD = sqMod; } MODINT &operator+=(const MODINT a) { m_x = (m_x + a.m_x) % MOD; return *this; }; MODINT &operator-=(const MODINT a) { m_x = (m_x - a.m_x + MOD) % MOD; return *this; }; MODINT &operator*=(const MODINT a) { m_x = (m_x * a.m_x) % MOD; return *this; }; MODINT pow(SQWORD t) const { if (!t) return 1; MODINT a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } MODINT operator+(const MODINT a) const { MODINT res(*this); return (res += a); } MODINT operator-(const MODINT a) const { MODINT res(*this); return (res -= a); } MODINT operator*(const MODINT a) const { MODINT res(*this); return (res *= a); } MODINT operator/(const MODINT a) const { MODINT res(*this); return (res /= a); } /* 逆元 */ MODINT inv() const { return pow(MOD - 2); } /* 除算 */ MODINT &operator/=(const MODINT a) { return (*this) *= a.inv(); } /* 整数版 */ MODINT &operator+=(const SQWORD a) { *this += MODINT(a); return *this; }; MODINT &operator-=(const SQWORD a) { *this -= MODINT(a); return *this; }; MODINT &operator*=(const SQWORD a) { *this *= MODINT(a); return *this; }; MODINT &operator/=(const SQWORD a) { *this /= MODINT(a); return *this; }; SQWORD getVal() { return m_x; }; }; SQWORD MODINT::MOD = ANS_MOD; /*----------------------------------------------*/ static bool isDivisible(SQWORD sqLength, const vector<SQWORD> &vsqA, SQWORD sqCnt) { SQWORD sqNeedCnt = 0; if (0 == sqLength) { return false; } for (auto a : vsqA) { sqNeedCnt += ((a + (sqLength - 1)) / sqLength - 1); if (sqCnt < sqNeedCnt) { return false; } } return true; } static SQWORD binarySearch(bool (*pfJudge)(SQWORD, const vector<SQWORD> &, SQWORD), SQWORD sqInitLower, SQWORD sqInitUpper, const vector<SQWORD> &vsqA, SQWORD sqCnt) { SQWORD sqOk = sqInitUpper; SQWORD sqNg = sqInitLower; while (1LL < sqOk - sqNg) { SQWORD sqMid = (sqNg + sqOk) / 2LL; // printf("%lld\n", sqMid); if (pfJudge(sqMid, vsqA, sqCnt)) { sqOk = sqMid; } else { sqNg = sqMid; } } return sqOk; } #define MAX_ANS (100100100100100100) int main(void) { SQWORD sqN = inputSQWORD(); SQWORD sqK = inputSQWORD(); vector<SQWORD> vsqA; for (SQWORD sqIdx = 0; sqIdx < sqN; sqIdx++) { SQWORD sqA = inputSQWORD(); vsqA.emplace_back(sqA); } SQWORD sqAns = binarySearch(isDivisible, -1, MAX_ANS, vsqA, sqK); printf("%lld\n", sqAns); return 0; }
insert
253
253
253
257
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define rep2(i, x, n) for (int i = x; i < (n); i++) #define ALL(n) begin(n), end(n) #define INF ((1 << 30) - 1) #define LINF (1LL << 60) #define EPS (1e-10) typedef long long Int; typedef pair<Int, Int> P; typedef pair<int, int> pint; struct cww { cww() { ios::sync_with_stdio(false); cin.tie(0); } } star; bool judge(Int cut, vector<Int> logs, Int k) { Int ans = 0; for (int i = 0; i < logs.size(); i++) { if (logs[i] % cut != 0) ans += (logs[i] / cut); else ans += (logs[i] / cut - 1); if (ans > k) return false; } if (ans > k) return false; return true; } int main() { cin.tie(0); ios::sync_with_stdio(false); Int n, k; cin >> n >> k; vector<Int> a(n, 0); rep(i, n) cin >> a[i]; Int ok = 1000000100; Int ng = -1; while (abs(ok - ng) > 1) { Int mid = (ok + ng) / 2; if (judge(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 < (n); i++) #define rep2(i, x, n) for (int i = x; i < (n); i++) #define ALL(n) begin(n), end(n) #define INF ((1 << 30) - 1) #define LINF (1LL << 60) #define EPS (1e-10) typedef long long Int; typedef pair<Int, Int> P; typedef pair<int, int> pint; struct cww { cww() { ios::sync_with_stdio(false); cin.tie(0); } } star; bool judge(Int cut, vector<Int> logs, Int k) { Int ans = 0; if (cut == 0) return false; for (int i = 0; i < logs.size(); i++) { if (logs[i] % cut != 0) ans += (logs[i] / cut); else ans += (logs[i] / cut - 1); if (ans > k) return false; } if (ans > k) return false; return true; } int main() { cin.tie(0); ios::sync_with_stdio(false); Int n, k; cin >> n >> k; vector<Int> a(n, 0); rep(i, n) cin >> a[i]; Int ok = 1000000100; Int ng = -1; while (abs(ok - ng) > 1) { Int mid = (ok + ng) / 2; if (judge(mid, a, k)) { ok = mid; } else { ng = mid; } } cout << ok << endl; return 0; }
insert
21
21
21
23
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define REP(i, x, n) for (int i = x; i < (int)n; i++) #define rep(i, n) REP(i, 0, n) #define sp(p) cout << setprecision(16) << fixed << p << endl; #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define SORT(a) sort(all(a)) #define RSORT(a) sort(rall(a)) #define UNIQ(a) unique(all(a)) #define UNIQNUM(a) UNIQ(a) - a.begin() #define UNIQIT(a) a.erase(UNIQ(a), a.end()); #define VOUT(v, i) \ rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? "\n" : " "); #define vout(v) VOUT(v, z); #define vdbg(v, i) \ cout << #v << ": "; \ for (int i = 0; i < (int)v.size(); i++) { \ cout << v[i] << " "; \ } \ cout << "\n"; #define vmin(v) *min_element(all(v)) #define vmax(v) *max_element(all(v)) #define vsum(v) accumulate(all(v), 0LL) #define MOUT(m, r, c) \ rep(i, r) { \ rep(j, c) { cout << m[i][j] << " "; } \ cout << endl; \ } #define mout(m) MOUT(m, m.size(), m[0].size()) #define debg(a) cout << #a << ": " << a << endl; #define show(a) \ for (cont & y : a) { \ for (cont & x : y) { \ cout << x << " "; \ } \ cout << endl; \ } #define digit(a) to_string(a).length(); template <class T> inline int out(const T &t) { print(t); putchar('\n'); return 0; } // template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));} // template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;} bool is_palindrome(string s) { return s == string(s.rbegin(), s.rend()); } #define popcount __builtin_popcount typedef long long ll; typedef long double ld; typedef pair<ll, ll> P; typedef vector<ll> V; typedef vector<vector<ll>> VV; // const long long MOD=1000000007; const long long INF = 1e18; #define EPS (1e-7) #define PI (acos(-1)) 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; } ll N; ll K; std::vector<long long> A; bool check(ll mid) { ll cnt = 0; for (long long i = 0; i < N; i++) { if (A[i] <= mid) continue; cnt += A[i] / mid; } return cnt <= K; } int main() { // long long N; scanf("%lld", &N); // long long K; scanf("%lld", &K); // std::vector<long long> A(N); A.resize(N); for (int i = 0; i < N; i++) { scanf("%lld", &A[i]); } long long ng = -1, ok = INF; while (abs(ok - ng) > 1) { long long mid = (ok + ng) / 2; if (check(mid)) { ok = mid; } else { ng = mid; } } cout << ok << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, x, n) for (int i = x; i < (int)n; i++) #define rep(i, n) REP(i, 0, n) #define sp(p) cout << setprecision(16) << fixed << p << endl; #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define SORT(a) sort(all(a)) #define RSORT(a) sort(rall(a)) #define UNIQ(a) unique(all(a)) #define UNIQNUM(a) UNIQ(a) - a.begin() #define UNIQIT(a) a.erase(UNIQ(a), a.end()); #define VOUT(v, i) \ rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? "\n" : " "); #define vout(v) VOUT(v, z); #define vdbg(v, i) \ cout << #v << ": "; \ for (int i = 0; i < (int)v.size(); i++) { \ cout << v[i] << " "; \ } \ cout << "\n"; #define vmin(v) *min_element(all(v)) #define vmax(v) *max_element(all(v)) #define vsum(v) accumulate(all(v), 0LL) #define MOUT(m, r, c) \ rep(i, r) { \ rep(j, c) { cout << m[i][j] << " "; } \ cout << endl; \ } #define mout(m) MOUT(m, m.size(), m[0].size()) #define debg(a) cout << #a << ": " << a << endl; #define show(a) \ for (cont & y : a) { \ for (cont & x : y) { \ cout << x << " "; \ } \ cout << endl; \ } #define digit(a) to_string(a).length(); template <class T> inline int out(const T &t) { print(t); putchar('\n'); return 0; } // template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));} // template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;} bool is_palindrome(string s) { return s == string(s.rbegin(), s.rend()); } #define popcount __builtin_popcount typedef long long ll; typedef long double ld; typedef pair<ll, ll> P; typedef vector<ll> V; typedef vector<vector<ll>> VV; // const long long MOD=1000000007; const long long INF = 1e18; #define EPS (1e-7) #define PI (acos(-1)) 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; } ll N; ll K; std::vector<long long> A; bool check(ll mid) { ll cnt = 0; for (long long i = 0; i < N; i++) { if (A[i] <= mid) continue; cnt += A[i] / mid; } return cnt <= K; } int main() { // long long N; scanf("%lld", &N); // long long K; scanf("%lld", &K); // std::vector<long long> A(N); A.resize(N); for (int i = 0; i < N; i++) { scanf("%lld", &A[i]); } long long ng = 0, ok = INF; while (abs(ok - ng) > 1) { long long mid = (ok + ng) / 2; if (check(mid)) { ok = mid; } else { ng = mid; } } cout << ok << endl; return 0; }
replace
97
98
97
98
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; template <typename T> void print(T t) { cout << t << endl; } template <typename T, typename... Args> void print(T t, Args... args) { cout << t << " "; print(args...); } typedef complex<double> base; #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define endl '\n' #define int long long #define double long double int n, k; int arr[200005]; bool check(int req) { int moves = 0; for (int i = 0; i < n; i++) { if (arr[i] <= req) continue; int ans = 0; ans += arr[i] / req; if (arr[i] % req == 0) ans--; moves += ans; if (moves > k) return 0; } return 1; } int32_t main() { IOS cin >> n >> k; for (int i = 0; i < n; i++) cin >> arr[i]; int low = 0; int high = 2e9; while (low < high) { int mid = (low + high) / 2; if (!check(mid)) low = mid + 1; else high = mid; } print(low); }
#include <bits/stdc++.h> using namespace std; template <typename T> void print(T t) { cout << t << endl; } template <typename T, typename... Args> void print(T t, Args... args) { cout << t << " "; print(args...); } typedef complex<double> base; #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define endl '\n' #define int long long #define double long double int n, k; int arr[200005]; bool check(int req) { int moves = 0; for (int i = 0; i < n; i++) { if (arr[i] <= req) continue; int ans = 0; ans += arr[i] / req; if (arr[i] % req == 0) ans--; moves += ans; if (moves > k) return 0; } return 1; } int32_t main() { IOS cin >> n >> k; for (int i = 0; i < n; i++) cin >> arr[i]; int low = 1; int high = 2e9; while (low < high) { int mid = (low + high) / 2; if (!check(mid)) low = mid + 1; else high = mid; } print(low); }
replace
40
41
40
41
0
p02598
C++
Runtime Error
#include "algorithm" #include "bitset" #include "chrono" #include "cstring" #include "ctime" #include "iomanip" #include "iostream" #include "map" #include "math.h" #include "numeric" #include "queue" #include "random" #include "set" #include "stack" #include "string" #include "vector" #include "ext/pb_ds/assoc_container.hpp" // Common file #include "ext/pb_ds/detail/standard_policies.hpp" #include "ext/pb_ds/tree_policy.hpp" // Including tree_order_statistics_node_update using namespace std; using namespace __gnu_pbds; #define f first #define lgn 25 #define endl '\n' #define sc second #define pb push_back #define N (int)5e5 + 5 #define PI acos(-1.0) #define int long long #define vi vector<int> #define mod 1000000007 #define ld long double #define eb emplace_back #define mii map<int, int> #define vpii vector<pii> #define pii pair<int, int> #define pq priority_queue #define BLOCK (int)sqrt(N) #define test(x) while (x--) #define all(x) begin(x), end(x) #define allr(x) x.rbegin(), x.rend() #define fo(i, a, n) for (int i = a; i < n; i++) #define rfo(i, n, a) for (int i = n; i >= a; i--) #define FAST \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define time() \ cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n" #define bug(...) __f(#__VA_ARGS__, __VA_ARGS__) typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> OS; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cout << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } const int inf = 0x3f3f3f3f; const int INF = 0x3f3f3f3f3f3f3f3f; int n, m, k, q; string s; vi adj[N]; int vis[N], par[N], a[N]; bool check(int mid) { int cn = 0; fo(i, 0, n) { if (a[i] < mid) continue; cn += ((a[i] + mid - 1) / mid) - 1; } return (cn <= k); } void go() { cin >> n >> k; int mx = 0; fo(i, 0, n) cin >> a[i], mx = max(mx, a[i]); int l = 0, r = 1e11; int ans = mx; while (l <= r) { int mid = l + (r - l) / 2; if (check(mid)) { ans = mid; r = mid - 1; } else l = mid + 1; } cout << ans << endl; } int32_t main() { FAST; int t = 1; // cin>>t; test(t) go(); }
#include "algorithm" #include "bitset" #include "chrono" #include "cstring" #include "ctime" #include "iomanip" #include "iostream" #include "map" #include "math.h" #include "numeric" #include "queue" #include "random" #include "set" #include "stack" #include "string" #include "vector" #include "ext/pb_ds/assoc_container.hpp" // Common file #include "ext/pb_ds/detail/standard_policies.hpp" #include "ext/pb_ds/tree_policy.hpp" // Including tree_order_statistics_node_update using namespace std; using namespace __gnu_pbds; #define f first #define lgn 25 #define endl '\n' #define sc second #define pb push_back #define N (int)5e5 + 5 #define PI acos(-1.0) #define int long long #define vi vector<int> #define mod 1000000007 #define ld long double #define eb emplace_back #define mii map<int, int> #define vpii vector<pii> #define pii pair<int, int> #define pq priority_queue #define BLOCK (int)sqrt(N) #define test(x) while (x--) #define all(x) begin(x), end(x) #define allr(x) x.rbegin(), x.rend() #define fo(i, a, n) for (int i = a; i < n; i++) #define rfo(i, n, a) for (int i = n; i >= a; i--) #define FAST \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define time() \ cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n" #define bug(...) __f(#__VA_ARGS__, __VA_ARGS__) typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> OS; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cout << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } const int inf = 0x3f3f3f3f; const int INF = 0x3f3f3f3f3f3f3f3f; int n, m, k, q; string s; vi adj[N]; int vis[N], par[N], a[N]; bool check(int mid) { int cn = 0; fo(i, 0, n) { if (a[i] < mid) continue; cn += ((a[i] + mid - 1) / mid) - 1; } return (cn <= k); } void go() { cin >> n >> k; int mx = 0; fo(i, 0, n) cin >> a[i], mx = max(mx, a[i]); int l = 1, r = 1e11; int ans = mx; while (l <= r) { int mid = l + (r - l) / 2; if (check(mid)) { ans = mid; r = mid - 1; } else l = mid + 1; } cout << ans << endl; } int32_t main() { FAST; int t = 1; // cin>>t; test(t) go(); }
replace
94
95
94
95
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long int #define ld long double #define vii vector<ll> #define pb push_back #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); using namespace std; const int MOD = 1e9 + 7, N = 1e4 + 3; int main() { fast; ll n, k; cin >> n >> k; ll a[n]; for (int i = 0; i < n; ++i) cin >> a[i]; ll low = 0, high = 1e9 + 5, ans; while (low <= high) { ll mid = (low + high) / 2, sum = 0; for (int i = 0; i < n; ++i) { ll g; if (a[i] < mid) continue; if (a[i] % mid == 0) g = a[i] / mid - 1; else g = a[i] / mid; sum += g; } if (sum > k) low = mid + 1; else if (sum <= k) { ans = mid; high = mid - 1; } } cout << ans; cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n"; return 0; }
#include <bits/stdc++.h> #define ll long long int #define ld long double #define vii vector<ll> #define pb push_back #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); using namespace std; const int MOD = 1e9 + 7, N = 1e4 + 3; int main() { fast; ll n, k; cin >> n >> k; ll a[n]; for (int i = 0; i < n; ++i) cin >> a[i]; ll low = 1, high = 1e9 + 5, ans; while (low <= high) { ll mid = (low + high) / 2, sum = 0; for (int i = 0; i < n; ++i) { ll g; if (a[i] < mid) continue; if (a[i] % mid == 0) g = a[i] / mid - 1; else g = a[i] / mid; sum += g; } if (sum > k) low = mid + 1; else if (sum <= k) { ans = mid; high = mid - 1; } } cout << ans; cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n"; return 0; }
replace
19
20
19
20
0
Time elapsed : 0.022698 sec
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define all(a) a.begin(), a.end() using ll = long long; const int INF = 1 << 30; const ll INFll = 1LL << 62; const int mod = int(1e9) + 7; using P = pair<ll, ll>; using ld = long double; vector<ll> a; ll n; ll k; bool ch(ll x) { ll now = 0; for (int i = 0; i < n; ++i) { now += (a[i] - 1) / x; } if (now <= k) return true; return false; } int main() { cin >> n >> k; a.resize(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } ll ok = 1e9; ll ng = 0; ll cnt = 0; while (cnt < 1000) { ll m = (ok + ng) / 2; if (ch(m)) ok = m; else ng = m; cnt++; } cout << ok << endl; }
#include <bits/stdc++.h> using namespace std; #define all(a) a.begin(), a.end() using ll = long long; const int INF = 1 << 30; const ll INFll = 1LL << 62; const int mod = int(1e9) + 7; using P = pair<ll, ll>; using ld = long double; vector<ll> a; ll n; ll k; bool ch(ll x) { ll now = 0; if (x == 0) return false; for (int i = 0; i < n; ++i) { now += (a[i] - 1) / x; } if (now <= k) return true; return false; } int main() { cin >> n >> k; a.resize(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } ll ok = 1e9; ll ng = 0; ll cnt = 0; while (cnt < 1000) { ll m = (ok + ng) / 2; if (ch(m)) ok = m; else ng = m; cnt++; } cout << ok << endl; }
insert
16
16
16
18
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long int #define pb push_back // g++ -std=c++17 -Wshadow -Wall -g -fsanitize=address -fsanitize=undefined // -D_GLIBCXX_DEBUG -o int main() { ll n, k; cin >> n >> k; ll a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } ll r = *max_element(a, a + n); ll l = 0; while (l < r) { ll mid = l + (r - l) / 2; ll cuts = 0; for (int i = 0; i < n; i++) { if (a[i] % mid) cuts += (a[i] / mid); else cuts += ((a[i] - 1) / mid); } if (cuts > k) l = mid + 1; else { r = mid; } // cout<<l<<" "<<r<<"\n"; } cout << l << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define pb push_back // g++ -std=c++17 -Wshadow -Wall -g -fsanitize=address -fsanitize=undefined // -D_GLIBCXX_DEBUG -o int main() { ll n, k; cin >> n >> k; ll a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } ll r = *max_element(a, a + n); ll l = 1; while (l < r) { ll mid = l + (r - l) / 2; ll cuts = 0; for (int i = 0; i < n; i++) { if (a[i] % mid) cuts += (a[i] / mid); else cuts += ((a[i] - 1) / mid); } if (cuts > k) l = mid + 1; else { r = mid; } // cout<<l<<" "<<r<<"\n"; } cout << l << "\n"; return 0; }
replace
16
17
16
17
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> #include <string> #define rep(i, n) for (int i = 0; i < (n); i++) #define rrep(i, n) for (int i = n - 1; i >= 0; i--) #define fi first #define se second #define pb push_back #define ALL(a) (a).begin(), (a).end() typedef long long ll; const ll MOD = 1000000007ll; const int MAX = 5100000; using namespace std; int inputValue() { int a; cin >> a; return a; }; void inputArray(int *p, int a) { for (int i = 0; i < a; i++) { cin >> p[i]; } }; void inputVector(vector<int> *p, int a) { for (int i = 0; i < a; i++) { int input; cin >> input; p->push_back(input); } } ll fact[MAX], fact_inv[MAX]; ll power(ll a, ll b) { ll res = 1; while (b > 0) { if (b & 1) res = res * a % MOD; a = a * a % MOD; b >>= 1; } return res; } // nCr ll comb(ll n, ll r) { ll t = 1000000; fact[0] = 1; for (int i = 0; i < t; i++) { fact[i + 1] = fact[i] * (i + 1) % MOD; } fact_inv[t] = power(fact[t], MOD - 2); for (int i = 0; i < t; i++) { fact_inv[i] = fact_inv[i + 1] * (i + 1) % MOD; } return (fact[n] * fact_inv[r]) % MOD * fact_inv[n - r] % MOD; } int i, j, k, tmp; ll ans = 0; ll A[200000]; bool solve(int N, ll K, ll ans) { ll tmp = 0; for (i = 0; i < N; i++) { if (A[i] <= ans) { continue; } tmp += (A[i] + ans - 1) / ans - 1; if (tmp > K) { return false; } } return true; } int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; ll K; cin >> K; ll max = 0; for (i = 0; i < N; i++) { cin >> A[i]; if (A[i] > max) { max = A[i]; } } if (K == 0) { cout << max << endl; return 0; } ll left = -1, right = max; while (right - left > 1) { ll mid = left + (right - left) / 2; if (solve(N, K, mid)) { right = mid; } else { left = mid; } } cout << right << endl; return 0; }
#include <bits/stdc++.h> #include <string> #define rep(i, n) for (int i = 0; i < (n); i++) #define rrep(i, n) for (int i = n - 1; i >= 0; i--) #define fi first #define se second #define pb push_back #define ALL(a) (a).begin(), (a).end() typedef long long ll; const ll MOD = 1000000007ll; const int MAX = 5100000; using namespace std; int inputValue() { int a; cin >> a; return a; }; void inputArray(int *p, int a) { for (int i = 0; i < a; i++) { cin >> p[i]; } }; void inputVector(vector<int> *p, int a) { for (int i = 0; i < a; i++) { int input; cin >> input; p->push_back(input); } } ll fact[MAX], fact_inv[MAX]; ll power(ll a, ll b) { ll res = 1; while (b > 0) { if (b & 1) res = res * a % MOD; a = a * a % MOD; b >>= 1; } return res; } // nCr ll comb(ll n, ll r) { ll t = 1000000; fact[0] = 1; for (int i = 0; i < t; i++) { fact[i + 1] = fact[i] * (i + 1) % MOD; } fact_inv[t] = power(fact[t], MOD - 2); for (int i = 0; i < t; i++) { fact_inv[i] = fact_inv[i + 1] * (i + 1) % MOD; } return (fact[n] * fact_inv[r]) % MOD * fact_inv[n - r] % MOD; } int i, j, k, tmp; ll ans = 0; ll A[200000]; bool solve(int N, ll K, ll ans) { ll tmp = 0; for (i = 0; i < N; i++) { if (A[i] <= ans) { continue; } tmp += (A[i] + ans - 1) / ans - 1; if (tmp > K) { return false; } } return true; } int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; ll K; cin >> K; ll max = 0; for (i = 0; i < N; i++) { cin >> A[i]; if (A[i] > max) { max = A[i]; } } if (K == 0) { cout << max << endl; return 0; } ll left = 0, right = max; while (right - left > 1) { ll mid = left + (right - left) / 2; if (solve(N, K, mid)) { right = mid; } else { left = mid; } } cout << right << endl; return 0; }
replace
101
102
101
102
0
p02598
C++
Runtime Error
#include <algorithm> #include <cinttypes> #include <cmath> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define FSCNd64 "%" SCNd64 #define FPRId64 "%" PRId64 using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using pii = pair<int, int>; using vll = vector<ll>; using vvll = vector<vll>; using vpii = vector<pii>; #define PI 3.1415926535897932384626433832795 template <typename X> bool max_u(X &m, X v) { if (m < v) { m = v; return true; } return false; } template <typename X> bool min_u(X &m, X v) { if (m > v) { m = v; return true; } return false; } template <typename X> X ceil(X v, X d) { return (v + d - 1) / d; } struct l_t { int id; ll a; ll l; ll d; }; struct solve { solve() {} ll operator()(int n, ll k, vll &a) { ll a_sum = 0, a_max = 0; for (auto &m : a) { a_sum += m; max_u(a_max, m); } ll a_min = a_sum / (n + k); ll s = a_min; ll e = a_max; ll ans = e; while (s <= e) { ll c = (s + e) / 2; ll cut_sum = 0; for (auto m : a) { ll cut = (m - 1) / c; cut_sum += cut; } // cout << "s=" << s << " e=" << e << " c=" << c << " cut_sum=" << cut_sum // << "\n"; if (cut_sum <= k) { e = c - 1; min_u(ans, c); } else { s = c + 1; } } return ans; } }; int main(void) { ios::sync_with_stdio(false); cin.tie(nullptr); for (;;) { int n; ll k; cin >> n >> k; if (cin.fail()) break; vll a(n); for (auto &m : a) cin >> m; cout << solve()(n, k, a) << "\n"; cout.flush(); } return 0; }
#include <algorithm> #include <cinttypes> #include <cmath> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define FSCNd64 "%" SCNd64 #define FPRId64 "%" PRId64 using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using pii = pair<int, int>; using vll = vector<ll>; using vvll = vector<vll>; using vpii = vector<pii>; #define PI 3.1415926535897932384626433832795 template <typename X> bool max_u(X &m, X v) { if (m < v) { m = v; return true; } return false; } template <typename X> bool min_u(X &m, X v) { if (m > v) { m = v; return true; } return false; } template <typename X> X ceil(X v, X d) { return (v + d - 1) / d; } struct l_t { int id; ll a; ll l; ll d; }; struct solve { solve() {} ll operator()(int n, ll k, vll &a) { ll a_sum = 0, a_max = 0; for (auto &m : a) { a_sum += m; max_u(a_max, m); } ll a_min = a_sum / (n + k); ll s = max(1LL, a_min); ll e = a_max; ll ans = e; while (s <= e) { ll c = (s + e) / 2; ll cut_sum = 0; for (auto m : a) { ll cut = (m - 1) / c; cut_sum += cut; } // cout << "s=" << s << " e=" << e << " c=" << c << " cut_sum=" << cut_sum // << "\n"; if (cut_sum <= k) { e = c - 1; min_u(ans, c); } else { s = c + 1; } } return ans; } }; int main(void) { ios::sync_with_stdio(false); cin.tie(nullptr); for (;;) { int n; ll k; cin >> n >> k; if (cin.fail()) break; vll a(n); for (auto &m : a) cin >> m; cout << solve()(n, k, a) << "\n"; cout.flush(); } return 0; }
replace
64
65
64
65
0
p02598
C++
Runtime Error
// #pragma GCC optimize("Ofast") // #pragma GCC optimize ("unroll-loops") // #pragma GCC target("avx,avx2,fma") #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; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // #include<boost/multiprecision/cpp_int.hpp> // #include <boost/math/common_factor.hpp> // namespace mp=boost::multiprecision; #define ll long long #define mod 1000000007 #define fi first #define se second #define inf 4e18 #define lim 1000000000000 #define pll pair<ll, ll> #define pb push_back #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define el "\n" #define vll vector<ll> #define vpll vector<pll> #define vppll vector<pair<ll, pll>> #define vvpll vector<vector<pair<ll, ll>>> #define vvll vector<vector<ll>> #define vvc vector<vector<char>> #define vc vector<char> // #define mod 998244353 ll gcd(ll a, ll b) { if (b == 0) return a; else return gcd(b, a % b); } ll xpow(ll a, ll b, ll m) { if (!b) return 1 % m; if (b == 1) return a % m; if (b & 1) { return (((a % m) * xpow(a, b - 1, m)) % m); } else { ll p = xpow(a, b / 2, m); return ((p * p) % m); } } /*double xpow(double a,ll b) { if(!b) return 1; if(b==1) return a; if(b&1) { return((a*xpow(a,b-1))); } else { p=xpow(a,b/2); return((p*p)); } } void dfs(ll v,vector<vector<ll> > &edge,vector<bool> &vis) { vis[v]=1; for(ll i=0;i<edge[v].size();i++) { ll v1=edge[v][i]; if(!vis[v1]) { dfs(v1,edge,vis; } } } ll parent(ll x,vector<ll> &par) { if(par[x]==x) return(x); par[x]=parent(par[x],par); return(par[x]); } bool uni(ll a,ll b,vector<ll> &par) { ll pa=parent(a,par); ll pb=parent(b,par); if(pa==pb) return 0; else { par[pa]=pb; return 1; } } void seive(vector<bool> &v) { ll n=v.size(); for(ll i=2;i*i<n;i++) { if(v[i]) { for(ll j=i*i;j<n;j+=i) v[j]=0; } } } void bfs(ll v,vector<vector<ll> > &edge,vector<bool> &vis,vector<ll> &level) { queue<ll> q; q.push(v); vis[v]=1; level[v]=0; while(!q.empty()) { ll ve=q.front();q.pop(); for(ll i=0;i<edge[ve].size();i++) { ll vee=edge[ve][i]; if(!vis[vee]) { vis[vee]=1; level[vee]=level[ve]+1; q.push(vee); } } } } ll solve(ll x,ll n) { ll low=0,high=2e9,mid; ll ans=x; while(low<high) { mid=low+(high-low)/2; ll val=(mid*(mid+1))/2; if(val>=x) { ans=mid; high=mid; } else { low=mid+1; } } return(ans); } bool chk(ll vv,vector<ll> &v) { for(auto p:v) { if(p==vv) return 0; } return 1; } ll phi(ll n) { ll ans=n; for(ll i=2;i*i<=n;i++) { if(n%i) continue; while(n%i==0) { n/=i; } ans=ans-ans/i; } if(n>1) ans-=ans/n; return(ans); } ll tr[800005]; void build(ll node,ll l,ll r,vector<ll> &v) { if(l==r) { tr[node]=v[l]; return; } ll mid=(l+r)/2; build(2*node+1,l,mid,v); build(2*node+2,mid+1,r,v); tr[node]=max(tr[2*node+1],tr[2*node+2]); } ll query(ll node,ll s,ll e,ll l,ll r) { if(e<l || s>r) return 0; if(s>=l&&e<=r) return(tr[node]); ll mid=(s+e)/2; ll m1=query(2*node+1,s,mid,l,r); ll m2=query(2*node+2,mid+1,e,l,r); return(max(m1,m2)); } ll nCr(ll n,ll r) { ll ans=1; for(ll i=1;i<=n-r;i++) { ans=(ans*((r+i))); ans/=i; ans%=mod; //ans/=i; } ans%=mod; return(ans); } void djks(ll v,vvll &edge,vvll &dist) { ll n=edge.size()-1; vll dis(n+1,inf); priority_queue<pll> pq; dis[v]=0; pq.push({0,v}); while(!pq.empty()) { pll p=pq.top();pq.pop(); p.fi*=-1; for(ll i=1;i<=n;i++) { if(edge[p.se][i]) { if(dis[i]>(dis[p.se]+edge[p.se][i])) { dis[i]=dis[p.se]+edge[p.se][i]; pq.push({-dis[i],i}); } } } } for(ll i=1;i<=n;i++) { dist[v][i]=dis[i]; } } ll kmp(string &s) { string t=s; reverse(all(t)); string a=s+"#"+t; ll n=a.size(); vll nxt(n); nxt[0]=0; ll i=0,j=1; while(j<n) { if(a[i]==a[j]) { nxt[j]=i+1; i++;j++; } else { if(i) i=nxt[i-1]; else { nxt[j]=0; j++; } } } return(nxt[n-1]); } string sadd(string a,string b) { string t; ll la=a.length(),lb=b.length(); ll d=0; ll i=la-1,j=lb-1; while(i>=0 && j>=0) { ll x=a[i]-'0',y=b[j]-'0'; t.pb((x+y+d)%10+'0'); d=(x+y+d)/10; i--;j--; } while(i>=0) { ll x=a[i]-'0'; t.pb((x+d)%10+'0'); d=(x+d)/10;i--; } while(j>=0) { ll y=b[j]-'0'; t.pb((y+d)%10+'0'); d=(y+d)/10;j--; } while(d) { t.pb(d%10+'0'); d/=10; } //cout<<a<<" "<<b<<el; reverse(all(t)); return(t); }*/ const ll zzz = 1e3 + 5; ll nCr[zzz][zzz]; void cal() { nCr[0][0] = 1; for (ll i = 1; i < zzz; i++) { nCr[i][0] = 1; for (ll j = 1; j < zzz; j++) { nCr[i][j] = (nCr[i - 1][j] + nCr[i - 1][j - 1]) % mod; } } } const ll N = 1e5 + 5; bool check_prime(ll n) { for (ll i = 2; i * i <= n; i++) { if (n % i == 0) return 0; } return 1; } bool chk(ll &l, vll &v, ll &k) { ll c = 0; for (auto p : v) { c += (p - 1) / l; } if (c <= k) return 1; else return 0; } void doit() { ll n, k; cin >> n >> k; vll v(n); for (ll i = 0; i < n; i++) cin >> v[i]; ll low = 0, high = 2e9, mid; ll ans = 0; while (low <= high) { mid = low + (high - low) / 2; // cout<<mid<<" "<<chk(mid,v,k)<<el; if (chk(mid, v, k)) { ans = mid; high = mid - 1; } else low = mid + 1; } cout << ans; cout << el; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cal(); // For nCr; // Array of length 5e6 can be made...and I think questions are also within // range 2^17>10^5 and 2^16<10^5 ll t; t = 1; // cin>>t; while (t--) { doit(); } return 0; }
// #pragma GCC optimize("Ofast") // #pragma GCC optimize ("unroll-loops") // #pragma GCC target("avx,avx2,fma") #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; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // #include<boost/multiprecision/cpp_int.hpp> // #include <boost/math/common_factor.hpp> // namespace mp=boost::multiprecision; #define ll long long #define mod 1000000007 #define fi first #define se second #define inf 4e18 #define lim 1000000000000 #define pll pair<ll, ll> #define pb push_back #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define el "\n" #define vll vector<ll> #define vpll vector<pll> #define vppll vector<pair<ll, pll>> #define vvpll vector<vector<pair<ll, ll>>> #define vvll vector<vector<ll>> #define vvc vector<vector<char>> #define vc vector<char> // #define mod 998244353 ll gcd(ll a, ll b) { if (b == 0) return a; else return gcd(b, a % b); } ll xpow(ll a, ll b, ll m) { if (!b) return 1 % m; if (b == 1) return a % m; if (b & 1) { return (((a % m) * xpow(a, b - 1, m)) % m); } else { ll p = xpow(a, b / 2, m); return ((p * p) % m); } } /*double xpow(double a,ll b) { if(!b) return 1; if(b==1) return a; if(b&1) { return((a*xpow(a,b-1))); } else { p=xpow(a,b/2); return((p*p)); } } void dfs(ll v,vector<vector<ll> > &edge,vector<bool> &vis) { vis[v]=1; for(ll i=0;i<edge[v].size();i++) { ll v1=edge[v][i]; if(!vis[v1]) { dfs(v1,edge,vis; } } } ll parent(ll x,vector<ll> &par) { if(par[x]==x) return(x); par[x]=parent(par[x],par); return(par[x]); } bool uni(ll a,ll b,vector<ll> &par) { ll pa=parent(a,par); ll pb=parent(b,par); if(pa==pb) return 0; else { par[pa]=pb; return 1; } } void seive(vector<bool> &v) { ll n=v.size(); for(ll i=2;i*i<n;i++) { if(v[i]) { for(ll j=i*i;j<n;j+=i) v[j]=0; } } } void bfs(ll v,vector<vector<ll> > &edge,vector<bool> &vis,vector<ll> &level) { queue<ll> q; q.push(v); vis[v]=1; level[v]=0; while(!q.empty()) { ll ve=q.front();q.pop(); for(ll i=0;i<edge[ve].size();i++) { ll vee=edge[ve][i]; if(!vis[vee]) { vis[vee]=1; level[vee]=level[ve]+1; q.push(vee); } } } } ll solve(ll x,ll n) { ll low=0,high=2e9,mid; ll ans=x; while(low<high) { mid=low+(high-low)/2; ll val=(mid*(mid+1))/2; if(val>=x) { ans=mid; high=mid; } else { low=mid+1; } } return(ans); } bool chk(ll vv,vector<ll> &v) { for(auto p:v) { if(p==vv) return 0; } return 1; } ll phi(ll n) { ll ans=n; for(ll i=2;i*i<=n;i++) { if(n%i) continue; while(n%i==0) { n/=i; } ans=ans-ans/i; } if(n>1) ans-=ans/n; return(ans); } ll tr[800005]; void build(ll node,ll l,ll r,vector<ll> &v) { if(l==r) { tr[node]=v[l]; return; } ll mid=(l+r)/2; build(2*node+1,l,mid,v); build(2*node+2,mid+1,r,v); tr[node]=max(tr[2*node+1],tr[2*node+2]); } ll query(ll node,ll s,ll e,ll l,ll r) { if(e<l || s>r) return 0; if(s>=l&&e<=r) return(tr[node]); ll mid=(s+e)/2; ll m1=query(2*node+1,s,mid,l,r); ll m2=query(2*node+2,mid+1,e,l,r); return(max(m1,m2)); } ll nCr(ll n,ll r) { ll ans=1; for(ll i=1;i<=n-r;i++) { ans=(ans*((r+i))); ans/=i; ans%=mod; //ans/=i; } ans%=mod; return(ans); } void djks(ll v,vvll &edge,vvll &dist) { ll n=edge.size()-1; vll dis(n+1,inf); priority_queue<pll> pq; dis[v]=0; pq.push({0,v}); while(!pq.empty()) { pll p=pq.top();pq.pop(); p.fi*=-1; for(ll i=1;i<=n;i++) { if(edge[p.se][i]) { if(dis[i]>(dis[p.se]+edge[p.se][i])) { dis[i]=dis[p.se]+edge[p.se][i]; pq.push({-dis[i],i}); } } } } for(ll i=1;i<=n;i++) { dist[v][i]=dis[i]; } } ll kmp(string &s) { string t=s; reverse(all(t)); string a=s+"#"+t; ll n=a.size(); vll nxt(n); nxt[0]=0; ll i=0,j=1; while(j<n) { if(a[i]==a[j]) { nxt[j]=i+1; i++;j++; } else { if(i) i=nxt[i-1]; else { nxt[j]=0; j++; } } } return(nxt[n-1]); } string sadd(string a,string b) { string t; ll la=a.length(),lb=b.length(); ll d=0; ll i=la-1,j=lb-1; while(i>=0 && j>=0) { ll x=a[i]-'0',y=b[j]-'0'; t.pb((x+y+d)%10+'0'); d=(x+y+d)/10; i--;j--; } while(i>=0) { ll x=a[i]-'0'; t.pb((x+d)%10+'0'); d=(x+d)/10;i--; } while(j>=0) { ll y=b[j]-'0'; t.pb((y+d)%10+'0'); d=(y+d)/10;j--; } while(d) { t.pb(d%10+'0'); d/=10; } //cout<<a<<" "<<b<<el; reverse(all(t)); return(t); }*/ const ll zzz = 1e3 + 5; ll nCr[zzz][zzz]; void cal() { nCr[0][0] = 1; for (ll i = 1; i < zzz; i++) { nCr[i][0] = 1; for (ll j = 1; j < zzz; j++) { nCr[i][j] = (nCr[i - 1][j] + nCr[i - 1][j - 1]) % mod; } } } const ll N = 1e5 + 5; bool check_prime(ll n) { for (ll i = 2; i * i <= n; i++) { if (n % i == 0) return 0; } return 1; } bool chk(ll &l, vll &v, ll &k) { ll c = 0; for (auto p : v) { c += (p - 1) / l; } if (c <= k) return 1; else return 0; } void doit() { ll n, k; cin >> n >> k; vll v(n); for (ll i = 0; i < n; i++) cin >> v[i]; ll low = 1, high = 2e9, mid; ll ans = 0; while (low <= high) { mid = low + (high - low) / 2; // cout<<mid<<" "<<chk(mid,v,k)<<el; if (chk(mid, v, k)) { ans = mid; high = mid - 1; } else low = mid + 1; } cout << ans; cout << el; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cal(); // For nCr; // Array of length 5e6 can be made...and I think questions are also within // range 2^17>10^5 and 2^16<10^5 ll t; t = 1; // cin>>t; while (t--) { doit(); } return 0; }
replace
343
344
343
344
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> // Common file #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update using namespace std; using namespace __gnu_pbds; #define TRACE #ifdef TRACE #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cerr << name << " : " << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } #else #define trace(...) #endif #define lsc(x) scanf("%lld", &x) #define sc(x) scanf("%d", &x) #define lpr(x) printf("%lld ", (long long)x) #define pr(x) printf("%d ", x) #define n_l printf("\n") #define VI vector<int> #define VII vector<long long int> #define m_p make_pair #define pb push_back #define fi first #define se second #define mset(x, y) memset(x, y, sizeof(x)) #define sz(v) (int)v.size() #define all(v) v.begin(), v.end() #define fr(i, a, n) for (int i = a; i <= n; i++) #define FIO \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count()); const int N = (int)1e6 + 5; const int mod = 1000000007; typedef long long ll; // order_of_key (val): returns the no. of values strictly less than val // find_by_order (k): returns the kth largest element iterator.(0-based) // vector<int>::iterator itr=lower_bound(v.begin(),v.end(),x); // s.substr(pos[0-indexed], len(default=till end)) typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; ll fmod(ll x) { if (x < mod) return x; return x % mod; } ll mul(ll a, ll b, ll c) { ll ret = 0; while (b) { if (b % 2) ret = (ret + a) % c; a = (a * 2) % c; b >>= 1; } return ret; } int modpow(ll a, ll b) { ll ret = 1; while (b) { if (b % 2) ret = (ret * a) % mod; a = (a * a) % mod; b >>= 1; } return (int)ret; } inline int inv(int x) { return modpow(x, mod - 2); } int isprime[N]; void calc_prime() { isprime[1] = 1; for (ll i = 2; i < N; i++) if (!isprime[i]) for (ll j = i * i; j < N; j += i) isprime[j] = 1; } int a[N]; int main() { int n, k; sc(n); sc(k); fr(i, 1, n) sc(a[i]); int lo = 0; int hi = mod; while (lo <= hi) { ll cuts = 0; int mid = (lo + hi) / 2; fr(i, 1, n) { cuts += (a[i] - 1) / mid; } if (cuts <= k) hi = mid - 1; else lo = mid + 1; } lpr(hi + 1); n_l; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> // Common file #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update using namespace std; using namespace __gnu_pbds; #define TRACE #ifdef TRACE #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cerr << name << " : " << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } #else #define trace(...) #endif #define lsc(x) scanf("%lld", &x) #define sc(x) scanf("%d", &x) #define lpr(x) printf("%lld ", (long long)x) #define pr(x) printf("%d ", x) #define n_l printf("\n") #define VI vector<int> #define VII vector<long long int> #define m_p make_pair #define pb push_back #define fi first #define se second #define mset(x, y) memset(x, y, sizeof(x)) #define sz(v) (int)v.size() #define all(v) v.begin(), v.end() #define fr(i, a, n) for (int i = a; i <= n; i++) #define FIO \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count()); const int N = (int)1e6 + 5; const int mod = 1000000007; typedef long long ll; // order_of_key (val): returns the no. of values strictly less than val // find_by_order (k): returns the kth largest element iterator.(0-based) // vector<int>::iterator itr=lower_bound(v.begin(),v.end(),x); // s.substr(pos[0-indexed], len(default=till end)) typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; ll fmod(ll x) { if (x < mod) return x; return x % mod; } ll mul(ll a, ll b, ll c) { ll ret = 0; while (b) { if (b % 2) ret = (ret + a) % c; a = (a * 2) % c; b >>= 1; } return ret; } int modpow(ll a, ll b) { ll ret = 1; while (b) { if (b % 2) ret = (ret * a) % mod; a = (a * a) % mod; b >>= 1; } return (int)ret; } inline int inv(int x) { return modpow(x, mod - 2); } int isprime[N]; void calc_prime() { isprime[1] = 1; for (ll i = 2; i < N; i++) if (!isprime[i]) for (ll j = i * i; j < N; j += i) isprime[j] = 1; } int a[N]; int main() { int n, k; sc(n); sc(k); fr(i, 1, n) sc(a[i]); int lo = 1; int hi = mod; while (lo <= hi) { ll cuts = 0; int mid = (lo + hi) / 2; fr(i, 1, n) { cuts += (a[i] - 1) / mid; } if (cuts <= k) hi = mid - 1; else lo = mid + 1; } lpr(hi + 1); n_l; return 0; }
replace
94
95
94
95
0
p02598
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<double, double> pdd; typedef unsigned long long ull; typedef set<int>::iterator sit; #define st first #define sd second #define mkp make_pair #define pb push_back void tempwj() { freopen("hash.in", "r", stdin); freopen("hash.out", "w", stdout); } ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } ll qpow(ll a, ll b, ll mod) { a %= mod; ll ans = 1; while (b) { if (b & 1) ans = ans * a % mod; a = a * a % mod; b >>= 1; } return ans; } struct cmp { bool operator()(const pii &a, const pii &b) { return a.second < b.second; } }; int lb(int x) { return x & -x; } // friend bool operator < (Node a,Node b) 重载 const int inf = 0x3f3f3f3f; const ll INF = 0x3f3f3f3f3f3f3f3f; const ll mod = 1e9 + 7; const int maxn = 2e6 + 10; int a[maxn]; int n, m; bool pd(int x) { ll s = 0; for (int i = 1; i <= n; i++) { s += (a[i] + x - 1) / x - 1; } return s <= m; } int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); int l = 0, r = 1e9; while (l < r) { int mid = l + r >> 1; if (pd(mid)) r = mid; else l = mid + 1; } printf("%d\n", r); }
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<double, double> pdd; typedef unsigned long long ull; typedef set<int>::iterator sit; #define st first #define sd second #define mkp make_pair #define pb push_back void tempwj() { freopen("hash.in", "r", stdin); freopen("hash.out", "w", stdout); } ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } ll qpow(ll a, ll b, ll mod) { a %= mod; ll ans = 1; while (b) { if (b & 1) ans = ans * a % mod; a = a * a % mod; b >>= 1; } return ans; } struct cmp { bool operator()(const pii &a, const pii &b) { return a.second < b.second; } }; int lb(int x) { return x & -x; } // friend bool operator < (Node a,Node b) 重载 const int inf = 0x3f3f3f3f; const ll INF = 0x3f3f3f3f3f3f3f3f; const ll mod = 1e9 + 7; const int maxn = 2e6 + 10; int a[maxn]; int n, m; bool pd(int x) { ll s = 0; for (int i = 1; i <= n; i++) { s += (a[i] + x - 1) / x - 1; } return s <= m; } int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); int l = 1, r = 1e9; while (l < r) { int mid = l + r >> 1; if (pd(mid)) r = mid; else l = mid + 1; } printf("%d\n", r); }
replace
56
57
56
57
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define all(n) (n).begin(), (n).end() #define fi first #define se second typedef pair<int, int> PII; typedef long long ll; const int MOD = 1e9 + 7; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; int a[200000], ans = 0; for (int i = 0; i < n; i++) cin >> a[i]; ll lo = 0, hi = 1e9; while (lo <= hi) { int mid = (lo + hi) / 2; int cuts = 0; for (int i = 0; i < n; i++) { cuts += (a[i] - 1) / mid; if (cuts > k) break; } if (cuts <= k) ans = mid, hi = mid - 1; else lo = mid + 1; } cout << ans << "\n"; }
#include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define all(n) (n).begin(), (n).end() #define fi first #define se second typedef pair<int, int> PII; typedef long long ll; const int MOD = 1e9 + 7; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; int a[200000], ans = 0; for (int i = 0; i < n; i++) cin >> a[i]; ll lo = 0, hi = 1e9; while (lo <= hi) { int mid = (lo + hi) / 2; int cuts = 0; if (mid == 0) { cout << 1 << "\n"; return 0; } for (int i = 0; i < n; i++) { cuts += (a[i] - 1) / mid; if (cuts > k) break; } if (cuts <= k) ans = mid, hi = mid - 1; else lo = mid + 1; } cout << ans << "\n"; }
insert
28
28
28
32
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> const int N = 2e5 + 5, INF = 2e9; using namespace std; template <typename tp> inline void r(tp &n) { n = 0; char c = getchar(); while (!isdigit(c)) c = getchar(); while (isdigit(c)) n = n * 10 + c - 48, c = getchar(); } int n, k; int a[N]; bool OK(int cur) { int ret = 0; for (int i = 1; i <= n; ++i) ret += ((a[i] - 1) / cur); return ret <= k; } int main() { int L = 0, R = 0; r(n), r(k); for (int i = 1; i <= n; ++i) r(a[i]), R = max(R, a[i]); while (L <= R) { int mid = L + R >> 1; if (OK(mid)) R = mid - 1; else L = mid + 1; } printf("%d\n", R + 1); return 0; }
#include <bits/stdc++.h> const int N = 2e5 + 5, INF = 2e9; using namespace std; template <typename tp> inline void r(tp &n) { n = 0; char c = getchar(); while (!isdigit(c)) c = getchar(); while (isdigit(c)) n = n * 10 + c - 48, c = getchar(); } int n, k; int a[N]; bool OK(int cur) { int ret = 0; for (int i = 1; i <= n; ++i) ret += ((a[i] - 1) / cur); return ret <= k; } int main() { int L = 1, R = 0; r(n), r(k); for (int i = 1; i <= n; ++i) r(a[i]), R = max(R, a[i]); while (L <= R) { int mid = L + R >> 1; if (OK(mid)) R = mid - 1; else L = mid + 1; } printf("%d\n", R + 1); return 0; }
replace
21
22
21
22
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> #define mod 1000000007 #define ll long long int #define pb push_back #define mk make_pair #define pii pair<int, int> #define pll pair<ll, ll> #define fr(j, i, n) for (int i = j; i < n; ++i) #define frr(j, i, n) for (int i = j; i <= n; ++i) using namespace std; void solve() { ll n, k; cin >> n >> k; ll a[n + 1]; frr(1, i, n) cin >> a[i]; ll left = 0, right = 1e9; ll ans = 1e10; while (left <= right) { ll moves = 0; ll mid = (left + right) / 2ll; frr(1, i, n) { if (a[i] % mid == 0) moves += ((a[i] / mid) - 1ll); else moves += (a[i] / mid); } if (moves > k) left = mid + 1ll; else ans = min(mid, ans), right = mid - 1ll; } cout << ans << "\n"; } int main() { // #ifndef ONLINE_JUDGE // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); // #endif ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; // t=1; // cin>>t; while (t--) solve(); return 0; }
#include <bits/stdc++.h> #define mod 1000000007 #define ll long long int #define pb push_back #define mk make_pair #define pii pair<int, int> #define pll pair<ll, ll> #define fr(j, i, n) for (int i = j; i < n; ++i) #define frr(j, i, n) for (int i = j; i <= n; ++i) using namespace std; void solve() { ll n, k; cin >> n >> k; ll a[n + 1]; frr(1, i, n) cin >> a[i]; ll left = 1, right = 1e9; ll ans = 1e10; while (left <= right) { ll moves = 0; ll mid = (left + right) / 2ll; frr(1, i, n) { if (a[i] % mid == 0) moves += ((a[i] / mid) - 1ll); else moves += (a[i] / mid); } if (moves > k) left = mid + 1ll; else ans = min(mid, ans), right = mid - 1ll; } cout << ans << "\n"; } int main() { // #ifndef ONLINE_JUDGE // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); // #endif ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; // t=1; // cin>>t; while (t--) solve(); return 0; }
replace
15
16
15
16
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define pii pair<ll, ll> #define SZ(x) ((int)(x).size()) // #define endl "\n" #define vvi vector<vector<int>> #define vvl vector<vector<long long>> ll mod = 1e9 + 7; // const double pi = acos(-1.0); /* ll kmp(string x) { ll n= x.length(); //cout<<x<<endl; vector<ll> lcp(x.length(), 0); for(ll i=1;i<n;i++) { ll j=lcp[i-1]; while(j>0 && x[j]!=x[i]) j=lcp[j-1]; if(x[i]==x[j]) j++; lcp[i]=j; } return lcp[n-1]; } int N = 1000002; int ar[100002]; void sieve() { for(int i=1;i<=N;i++) ar[i] = 1; ar[0] = 0; for(int i=2;i*i<=N;i++) { if(ar[i] && i*i<=N) { for(int j = i*i; j<=N;j+=i) ar[j] = 0; } } } ll modex(ll a,ll b){ if(b<=0){ return 1; } if(b%2==0) { ll x = modex(a, b/2); return ((x*x)%mod); } else return ((a%mod * modex(a, b-1))%mod); } ll c[1010][1010]; ll combina(ll i, ll j){ for (int i=0;i<=1005;i++) for (int j=0;j<=i;j++) { if (j==i||j==0) c[i][j]=1; else c[i][j]=c[i-1][j-1]+c[i-1][j]; c[i][j]%=mod; } return c[i][j]; } void find_fac(int x){ vector<ll> di; for(ll i = 2; i*i <= x; i++) { if(x%i==0){ di.push_back(i); while(x%i==0) x/=i; } } if(x > 1) di.push_back(x); } */ ll n, k; vector<ll> a; ll fun(ll m) { ll c = 0; for (ll i = 0; i < n; i++) { if (a[i] <= m) continue; ll x = (a[i] + m - 1) / m; c += (x - 1); } return c; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout << fixed; cout.precision(12); cin >> n >> k; a.resize(n); for (ll i = 0; i < n; i++) cin >> a[i]; ll l = 0, r = 1e9, an = 1e9; while (l <= r) { ll m = (l + r) / 2; if (fun(m) > k) l = m + 1; else { an = min(an, m); r = m - 1; } } cout << an << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define pii pair<ll, ll> #define SZ(x) ((int)(x).size()) // #define endl "\n" #define vvi vector<vector<int>> #define vvl vector<vector<long long>> ll mod = 1e9 + 7; // const double pi = acos(-1.0); /* ll kmp(string x) { ll n= x.length(); //cout<<x<<endl; vector<ll> lcp(x.length(), 0); for(ll i=1;i<n;i++) { ll j=lcp[i-1]; while(j>0 && x[j]!=x[i]) j=lcp[j-1]; if(x[i]==x[j]) j++; lcp[i]=j; } return lcp[n-1]; } int N = 1000002; int ar[100002]; void sieve() { for(int i=1;i<=N;i++) ar[i] = 1; ar[0] = 0; for(int i=2;i*i<=N;i++) { if(ar[i] && i*i<=N) { for(int j = i*i; j<=N;j+=i) ar[j] = 0; } } } ll modex(ll a,ll b){ if(b<=0){ return 1; } if(b%2==0) { ll x = modex(a, b/2); return ((x*x)%mod); } else return ((a%mod * modex(a, b-1))%mod); } ll c[1010][1010]; ll combina(ll i, ll j){ for (int i=0;i<=1005;i++) for (int j=0;j<=i;j++) { if (j==i||j==0) c[i][j]=1; else c[i][j]=c[i-1][j-1]+c[i-1][j]; c[i][j]%=mod; } return c[i][j]; } void find_fac(int x){ vector<ll> di; for(ll i = 2; i*i <= x; i++) { if(x%i==0){ di.push_back(i); while(x%i==0) x/=i; } } if(x > 1) di.push_back(x); } */ ll n, k; vector<ll> a; ll fun(ll m) { ll c = 0; for (ll i = 0; i < n; i++) { if (a[i] <= m) continue; ll x = (a[i] + m - 1) / m; c += (x - 1); } return c; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout << fixed; cout.precision(12); cin >> n >> k; a.resize(n); for (ll i = 0; i < n; i++) cin >> a[i]; ll l = 1, r = 1e9, an = 1e9; while (l <= r) { ll m = (l + r) / 2; if (fun(m) > k) l = m + 1; else { an = min(an, m); r = m - 1; } } cout << an << endl; return 0; }
replace
109
110
109
110
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define all(x) (x).begin(), (x).end() using ll = long long; using P = pair<int, int>; using mp = map<int, int>; const int MOD = 1e9 + 7; const int INF = 1001001001; int main(void) { int n, k; cin >> n >> k; vector<int> a(n); int amax = 0; for (int i = 0; i < n; ++i) { cin >> a[i]; amax = max(a[i], amax); } int left = -1, right = amax + 1, mid = 0; while (left + 1 < right) { mid = (left + right) / 2; int cnt = 0; for (int i = 0; i < n; ++i) { cnt += (a[i] - 1) / mid; } if (cnt <= k) { right = mid; } else { left = mid; } } cout << right << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #define all(x) (x).begin(), (x).end() using ll = long long; using P = pair<int, int>; using mp = map<int, int>; const int MOD = 1e9 + 7; const int INF = 1001001001; int main(void) { int n, k; cin >> n >> k; vector<int> a(n); int amax = 0; for (int i = 0; i < n; ++i) { cin >> a[i]; amax = max(a[i], amax); } int left = 0, right = amax + 1, mid = 0; while (left + 1 < right) { mid = (left + right) / 2; int cnt = 0; for (int i = 0; i < n; ++i) { cnt += (a[i] - 1) / mid; } if (cnt <= k) { right = mid; } else { left = mid; } } cout << right << "\n"; return 0; }
replace
25
26
25
26
0
p02598
C++
Runtime Error
/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author */ #include <fstream> #include <iostream> #include "bits/stdc++.h" #include <iostream> using namespace std; typedef unsigned long long ull; typedef long long ll; typedef int integer; #define int long long typedef pair<int, int> pii; #define vii vector<pair<int, int>> #define vi vector<int> #define vvi vector<vector<int>> #define rep(i, a, b) for (int i = a; i < (b); i++) #define s(x) in >> x #define s2(x, y) in >> x >> y #define s3(x, y, z) in >> x >> y >> z #define s4(x, y, z, w) in >> x >> y >> z >> w #define p(x) out << (x) << endl #define p2(x, y) out << (x) << ' ' << (y) << endl #define p3(x, y, z) out << (x) << ' ' << (y) << ' ' << (z) << endl #define p4(x, y, z, w) \ out << (x) << ' ' << (y) << ' ' << (z) << ' ' << (w) << endl #define p1d(a, n) \ for (int ix = 0; ix < n - 1; ix++) \ out << a[ix] << ' '; \ out << a[n - 1] << '\n'; #define p2d(a, n, m) \ for (int ix = 0; ix < n; ix++) { \ for (int jx = 0; jx < m; jx++) \ out << a[ix][jx] << " "; \ out << endl; \ } #define pl(x) out << (x) #define pll(x) out << (x) << ' ' #define range(v) v.begin(), v.end() #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() #define rst(x) memset(x, -1, sizeof(x)) #define UNVISITED -1 #define VISITED 0 #define EXPLORED 2 #define EACH(x, a) for (auto &x : a) template <class T> void read_v(T &x, std::istream &in) { in >> (x); } template <class A> void read_vec(vector<A> &x, std::istream &in) { EACH(a, x) read_v(a, in); } ll iceildiv(const ll a, const ll b) { if (a == 0) { return 0; } return (1 + ((a - 1) / b)); } bool sortpairbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); } template <typename T> T factmod(T a, T modulus) { int res = 1, i; for (i = 2; i <= a; i++) { res *= i; res %= modulus; } return res; } template <typename T> int powmod(T a, T b, const int m) { int ans = 1; while (b > 0) { if (b & 1) { ans *= a; ans %= m; } a *= a; a %= m; b >>= 1; } return ans; } template <typename T> int power(T a, T b) { int ans = 1; while (b > 0) { if (b & 1) { ans *= a; } a *= a; b >>= 1; } return ans; } bool check(const int target, const vector<int> &a, const int cuts) { int required = 0; for (const int log : a) { required += (iceildiv(log, target) - 1); } return (cuts >= required); } void ssolve(std::istream &in, std::ostream &out) { int n, k; s2(n, k); vi a(n); read_vec(a, in); int l = 0, r = (int)1e9 + 5; while (l < r) { int mid = (l + r) / 2; if (check(mid, a, k)) { r = mid; } else { l = mid + 1; } } p(r); return; } class ELogs { public: void solve(std::istream &in, std::ostream &out) { ios_base::sync_with_stdio(false); in.tie(nullptr); out.tie(nullptr); int t; int READ = 0; if (READ) s(t); else t = 1; while (t--) { ssolve(in, out); } } }; integer main() { ELogs solver; std::istream &in(std::cin); std::ostream &out(std::cout); solver.solve(in, out); }
/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author */ #include <fstream> #include <iostream> #include "bits/stdc++.h" #include <iostream> using namespace std; typedef unsigned long long ull; typedef long long ll; typedef int integer; #define int long long typedef pair<int, int> pii; #define vii vector<pair<int, int>> #define vi vector<int> #define vvi vector<vector<int>> #define rep(i, a, b) for (int i = a; i < (b); i++) #define s(x) in >> x #define s2(x, y) in >> x >> y #define s3(x, y, z) in >> x >> y >> z #define s4(x, y, z, w) in >> x >> y >> z >> w #define p(x) out << (x) << endl #define p2(x, y) out << (x) << ' ' << (y) << endl #define p3(x, y, z) out << (x) << ' ' << (y) << ' ' << (z) << endl #define p4(x, y, z, w) \ out << (x) << ' ' << (y) << ' ' << (z) << ' ' << (w) << endl #define p1d(a, n) \ for (int ix = 0; ix < n - 1; ix++) \ out << a[ix] << ' '; \ out << a[n - 1] << '\n'; #define p2d(a, n, m) \ for (int ix = 0; ix < n; ix++) { \ for (int jx = 0; jx < m; jx++) \ out << a[ix][jx] << " "; \ out << endl; \ } #define pl(x) out << (x) #define pll(x) out << (x) << ' ' #define range(v) v.begin(), v.end() #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() #define rst(x) memset(x, -1, sizeof(x)) #define UNVISITED -1 #define VISITED 0 #define EXPLORED 2 #define EACH(x, a) for (auto &x : a) template <class T> void read_v(T &x, std::istream &in) { in >> (x); } template <class A> void read_vec(vector<A> &x, std::istream &in) { EACH(a, x) read_v(a, in); } ll iceildiv(const ll a, const ll b) { if (a == 0) { return 0; } return (1 + ((a - 1) / b)); } bool sortpairbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); } template <typename T> T factmod(T a, T modulus) { int res = 1, i; for (i = 2; i <= a; i++) { res *= i; res %= modulus; } return res; } template <typename T> int powmod(T a, T b, const int m) { int ans = 1; while (b > 0) { if (b & 1) { ans *= a; ans %= m; } a *= a; a %= m; b >>= 1; } return ans; } template <typename T> int power(T a, T b) { int ans = 1; while (b > 0) { if (b & 1) { ans *= a; } a *= a; b >>= 1; } return ans; } bool check(const int target, const vector<int> &a, const int cuts) { int required = 0; for (const int log : a) { required += (iceildiv(log, target) - 1); } return (cuts >= required); } void ssolve(std::istream &in, std::ostream &out) { int n, k; s2(n, k); vi a(n); read_vec(a, in); int l = 1, r = (int)1e9 + 5; while (l < r) { int mid = (l + r) / 2; if (check(mid, a, k)) { r = mid; } else { l = mid + 1; } } p(r); return; } class ELogs { public: void solve(std::istream &in, std::ostream &out) { ios_base::sync_with_stdio(false); in.tie(nullptr); out.tie(nullptr); int t; int READ = 0; if (READ) s(t); else t = 1; while (t--) { ssolve(in, out); } } }; integer main() { ELogs solver; std::istream &in(std::cin); std::ostream &out(std::cout); solver.solve(in, out); }
replace
113
114
113
114
0
p02598
C++
Runtime Error
// NEVER GIVE UP I AM GOING TO IMPROVE ONE DAY. // PRACTICE,PRACTICE,PRACTICE!!! #include <bits/stdc++.h> #define int long long int // #define ull unsigned long long int #define pb push_back #define mp make_pair #define mem(a, b) memset(a, b, sizeof(a)) #define inf 1e18 #define endl "\n" #define all(v) v.begin(), v.end() #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define dbg(x) cerr << #x << " = " << x << endl; const int M = 100005; const int mod = 1000000007; const double pi = acos(-1.0); using namespace std; bool possible(int mid, int k, int a[], int n) { int cut = 0; for (int i = 0; i < n; i++) { cut += ((a[i] - 1) / mid); } if (cut <= k) { return true; } return false; } int32_t main() { // #ifndef ONLINE_JUDGE // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); // #endif fast; int t; t = 1; // cin>>t; // int test=t; while (t--) { int n, k; cin >> n >> k; int a[n], maxi = -1; for (int i = 0; i < n; i++) { cin >> a[i]; maxi = max(maxi, a[i]); } int low = 0, high = maxi, mid, ans = maxi; while (high >= low) { mid = low + ((high - low) / 2); if (possible(mid, k, a, n)) { ans = min(ans, mid); high = mid - 1; } else { low = mid + 1; } } cout << ans << endl; } }
// NEVER GIVE UP I AM GOING TO IMPROVE ONE DAY. // PRACTICE,PRACTICE,PRACTICE!!! #include <bits/stdc++.h> #define int long long int // #define ull unsigned long long int #define pb push_back #define mp make_pair #define mem(a, b) memset(a, b, sizeof(a)) #define inf 1e18 #define endl "\n" #define all(v) v.begin(), v.end() #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define dbg(x) cerr << #x << " = " << x << endl; const int M = 100005; const int mod = 1000000007; const double pi = acos(-1.0); using namespace std; bool possible(int mid, int k, int a[], int n) { int cut = 0; if (mid == 0) { return false; } for (int i = 0; i < n; i++) { cut += ((a[i] - 1) / mid); } if (cut <= k) { return true; } return false; } int32_t main() { // #ifndef ONLINE_JUDGE // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); // #endif fast; int t; t = 1; // cin>>t; // int test=t; while (t--) { int n, k; cin >> n >> k; int a[n], maxi = -1; for (int i = 0; i < n; i++) { cin >> a[i]; maxi = max(maxi, a[i]); } int low = 0, high = maxi, mid, ans = maxi; while (high >= low) { mid = low + ((high - low) / 2); if (possible(mid, k, a, n)) { ans = min(ans, mid); high = mid - 1; } else { low = mid + 1; } } cout << ans << endl; } }
insert
22
22
22
25
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define ff first #define ss second #define ll int64_t #define ld long double #define nl cout << "\n" #define dbg(x) cerr << #x << " = " << x << "\n" #define dbg2(x, y) cerr << #x << " = " << x << " " << #y << " = " << y << "\n" #define all(v) v.begin(), v.end() #define mset(a, v) memset((a), (v), sizeof(a)) #define forn(i, a, b) for (int64_t i = int64_t(a); i < int64_t(b); ++i) #define forb(i, a, b) for (int64_t i = int64_t(a); i >= int64_t(b); --i) #define fastio() \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define ordered_set \ tree<int, null_type, less<int>, rb_tree_tag, \ tree_order_statistics_node_update> #define mod 1000000007 #define mod2 998244353 #define inf 1000000000000007 #define pi 3.14159265358979323846 template <typename T, typename U> static inline void amin(T &x, U y) { if (y < x) x = y; } template <typename T, typename U> static inline void amax(T &x, U y) { if (x < y) x = y; } template <class L, class R> ostream &operator<<(ostream &out, pair<L, R> &p) { return out << "(" << p.ff << ", " << p.ss << ")"; } template <class T> ostream &operator<<(ostream &out, vector<T> &v) { out << "["; for (auto it = v.begin(); it != v.end(); ++it) { if (it != v.begin()) out << ", "; out << *it; } return out << "]"; } template <class T> ostream &operator<<(ostream &out, deque<T> &v) { out << "["; for (auto it = v.begin(); it != v.end(); ++it) { if (it != v.begin()) out << ", "; out << *it; } return out << "]"; } template <class T> ostream &operator<<(ostream &out, set<T> &s) { out << "{"; for (auto it = s.begin(); it != s.end(); ++it) { if (it != s.begin()) out << ", "; out << *it; } return out << "}"; } template <class L, class R> ostream &operator<<(ostream &out, map<L, R> &m) { out << "{"; for (auto it = m.begin(); it != m.end(); ++it) { if (it != m.begin()) out << ", "; out << *it; } return out << "}"; } ll count_digits(ll n) { ll dig = floor(log10(n) + 1); return dig; } ll mpow(ll x, ll y, ll p) { ll r = 1; x = x % p; while (y > 0) { if (y & 1) r = (r * x) % p; y = y >> 1; x = (x * x) % p; } return r; } string dec_bin_32(ll n) { string s; for (ll i = 31; i >= 0; i--) { ll k = n >> i; s += (k & 1) ? '1' : '0'; } return s; } string dec_bin_64(ll n) { string s; for (ll i = 63; i >= 0; i--) { ll k = n >> i; s += (k & 1) ? '1' : '0'; } return s; } ll mod_inv(ll a, ll m) { ll m0 = m, y = 0, x = 1; if (m == 1) return 0; while (a > 1) { ll q = a / m, t = m; m = a % m, a = t; t = y; y = x - q * y; x = t; } if (x < 0) x += m0; return x; } /* const ll MAXN=10000007;ll spf[MAXN+5];vector<ll> prime; */ /* void sieve(ll n) {forn(i,2,MAXN+1)spf[i]=i;for(ll * i=2;i*i<=n;i++)if(spf[i]==i)for(ll * j=i*i;j<=n;j+=i)if(spf[j]==j)spf[j]=i;forn(i,2,MAXN+1)if(spf[i]==i)prime.push_back(i);} */ //-------------------------------L_I_Erq34------------------------------- ll cuts; vector<ll> a; bool chk(ll val) { ll res = 0; for (ll i : a) res += (i + val - 1) / val - 1; return res <= cuts; } ll bin_search(ll st, ll end) { ll res = inf; while (end - st > 1) { ll mid = (st + end) >> 1; if (chk(mid)) { res = mid; end = mid - 1; } else st = mid + 1; } forb(i, end, st) if (chk(i)) res = i; return res; } int main() { fastio(); ll z, n, m, t, k, i, j, l, d, h, r; cin >> n >> cuts; a.resize(n); for (ll &i : a) cin >> i; cout << bin_search(0, inf) << "\n"; cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define ff first #define ss second #define ll int64_t #define ld long double #define nl cout << "\n" #define dbg(x) cerr << #x << " = " << x << "\n" #define dbg2(x, y) cerr << #x << " = " << x << " " << #y << " = " << y << "\n" #define all(v) v.begin(), v.end() #define mset(a, v) memset((a), (v), sizeof(a)) #define forn(i, a, b) for (int64_t i = int64_t(a); i < int64_t(b); ++i) #define forb(i, a, b) for (int64_t i = int64_t(a); i >= int64_t(b); --i) #define fastio() \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define ordered_set \ tree<int, null_type, less<int>, rb_tree_tag, \ tree_order_statistics_node_update> #define mod 1000000007 #define mod2 998244353 #define inf 1000000000000007 #define pi 3.14159265358979323846 template <typename T, typename U> static inline void amin(T &x, U y) { if (y < x) x = y; } template <typename T, typename U> static inline void amax(T &x, U y) { if (x < y) x = y; } template <class L, class R> ostream &operator<<(ostream &out, pair<L, R> &p) { return out << "(" << p.ff << ", " << p.ss << ")"; } template <class T> ostream &operator<<(ostream &out, vector<T> &v) { out << "["; for (auto it = v.begin(); it != v.end(); ++it) { if (it != v.begin()) out << ", "; out << *it; } return out << "]"; } template <class T> ostream &operator<<(ostream &out, deque<T> &v) { out << "["; for (auto it = v.begin(); it != v.end(); ++it) { if (it != v.begin()) out << ", "; out << *it; } return out << "]"; } template <class T> ostream &operator<<(ostream &out, set<T> &s) { out << "{"; for (auto it = s.begin(); it != s.end(); ++it) { if (it != s.begin()) out << ", "; out << *it; } return out << "}"; } template <class L, class R> ostream &operator<<(ostream &out, map<L, R> &m) { out << "{"; for (auto it = m.begin(); it != m.end(); ++it) { if (it != m.begin()) out << ", "; out << *it; } return out << "}"; } ll count_digits(ll n) { ll dig = floor(log10(n) + 1); return dig; } ll mpow(ll x, ll y, ll p) { ll r = 1; x = x % p; while (y > 0) { if (y & 1) r = (r * x) % p; y = y >> 1; x = (x * x) % p; } return r; } string dec_bin_32(ll n) { string s; for (ll i = 31; i >= 0; i--) { ll k = n >> i; s += (k & 1) ? '1' : '0'; } return s; } string dec_bin_64(ll n) { string s; for (ll i = 63; i >= 0; i--) { ll k = n >> i; s += (k & 1) ? '1' : '0'; } return s; } ll mod_inv(ll a, ll m) { ll m0 = m, y = 0, x = 1; if (m == 1) return 0; while (a > 1) { ll q = a / m, t = m; m = a % m, a = t; t = y; y = x - q * y; x = t; } if (x < 0) x += m0; return x; } /* const ll MAXN=10000007;ll spf[MAXN+5];vector<ll> prime; */ /* void sieve(ll n) {forn(i,2,MAXN+1)spf[i]=i;for(ll * i=2;i*i<=n;i++)if(spf[i]==i)for(ll * j=i*i;j<=n;j+=i)if(spf[j]==j)spf[j]=i;forn(i,2,MAXN+1)if(spf[i]==i)prime.push_back(i);} */ //-------------------------------L_I_Erq34------------------------------- ll cuts; vector<ll> a; bool chk(ll val) { ll res = 0; for (ll i : a) res += (i + val - 1) / val - 1; return res <= cuts; } ll bin_search(ll st, ll end) { ll res = inf; while (end - st > 1) { ll mid = (st + end) >> 1; if (chk(mid)) { res = mid; end = mid - 1; } else st = mid + 1; } forb(i, end, st) if (chk(i)) res = i; return res; } int main() { fastio(); ll z, n, m, t, k, i, j, l, d, h, r; cin >> n >> cuts; a.resize(n); for (ll &i : a) cin >> i; cout << bin_search(1, inf) << "\n"; cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; return 0; }
replace
164
165
164
165
0
Time elapsed: 22ms
p02598
C++
Runtime Error
#include <algorithm> #include <cassert> #include <cmath> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <vector> using namespace std; using lint = long long; constexpr int MOD = 1000000007, INF = 1010101010; constexpr lint LINF = 1LL << 60; #ifdef _DEBUG #include "../../library/library/debug_template.cpp" #define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__) #else #define DMP(...) ((void)0) #endif struct init { init() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } init_; int main() { int N, K; cin >> N >> K; vector<int> A(N); for (int i = 0; i < N; i++) cin >> A[i]; auto judge = [&](auto idx) { lint sum = 0; for (int i = 0; i < N; i++) sum += (A[i] - 1) / idx; return sum <= K; }; auto binary_search = [&](auto f) { auto ng = -1; auto ok = INF; while (abs(ok - ng) > 1) { auto mid = (ok + ng) / 2; if (f(mid)) ok = mid; else ng = mid; } return ok; }; cout << binary_search(judge) << "\n"; return 0; }
#include <algorithm> #include <cassert> #include <cmath> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <vector> using namespace std; using lint = long long; constexpr int MOD = 1000000007, INF = 1010101010; constexpr lint LINF = 1LL << 60; #ifdef _DEBUG #include "../../library/library/debug_template.cpp" #define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__) #else #define DMP(...) ((void)0) #endif struct init { init() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } init_; int main() { int N, K; cin >> N >> K; vector<int> A(N); for (int i = 0; i < N; i++) cin >> A[i]; auto judge = [&](auto idx) { lint sum = 0; for (int i = 0; i < N; i++) sum += (A[i] - 1) / idx; return sum <= K; }; auto binary_search = [&](auto f) { auto ng = 0; auto ok = INF; while (abs(ok - ng) > 1) { auto mid = (ok + ng) / 2; if (f(mid)) ok = mid; else ng = mid; } return ok; }; cout << binary_search(judge) << "\n"; return 0; }
replace
50
51
50
51
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define SPEED \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define FOR(i, a, b) for (ll i = a; i < b; ++i) #define RFOR(i, b, a) for (ll i = b; i >= a; --i) #define ALL(x) x.begin(), x.end() #define DEBUG(args...) \ { \ string _s = #args; \ replace(ALL(_s), ' ', '\0'); \ replace(ALL(_s), ',', ' '); \ stringstream _ss(_s); \ istream_iterator<string> _it(_ss); \ _debug(_it, args); \ } #define endl "\n" #define F first #define S second #define pb(x) push_back(x) a #define mp(x, y) make_pair(x, y) using namespace std; using namespace __gnu_pbds; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; void _debug(istream_iterator<string>) {} template <typename T, typename... Args> void _debug(istream_iterator<string> it, T first, Args... args) { cerr << ">> " << *it << " : " << first << endl; _debug(++it, args...); } template <typename T1, typename T2> inline ostream &operator<<(ostream &out, const pair<T1, T2> &p) { return out << "(" << p.F << ", " << p.S << ")"; } template <typename T> inline ostream &operator<<(ostream &out, const vector<T> &v) { if (v.empty()) return out << "[]"; else { out << '['; for (auto &e : v) { out << e << ", "; } return out << "\b\b]"; } } template <typename T> inline ostream &operator<<(ostream &out, const set<T> &s) { if (s.empty()) return out << "{}"; else { out << '{'; for (auto &e : s) { out << e << ", "; } return out << "\b\b}"; } } template <typename T> inline ostream &operator<<(ostream &out, const unordered_set<T> &s) { return out << set<T>(ALL(s)); } template <typename T1, typename T2> inline ostream &operator<<(ostream &out, const map<T1, T2> &m) { if (m.empty()) return out << "{}"; out << '{'; for (auto &p : m) { out << p << ", "; } return out << "\b\b}"; } template <typename T1, typename T2> inline ostream &operator<<(ostream &out, const unordered_map<T1, T2> &m) { return out << map<T1, T2>(ALL(m)); } template <typename T> inline ostream &operator<<(ostream &out, const ordered_set<T> &s) { return out << set<T>(ALL(s)); } typedef long long ll; typedef long double ld; typedef vector<long long> vll; typedef pair<ll, ll> pll; typedef vector<pair<ll, ll>> vpll; typedef unordered_map<ll, ll> STll; /************************************** MAIN PROGRAM * ********************************************/ int main() { // freopen("input.txt", "r", stdin); SPEED int n; cin >> n; int k; cin >> k; vector<int> a(n); for (auto &e : a) cin >> e; auto can = [&](int x) { int req = 0; for (auto e : a) { int parts = (e + x - 1) / x; req += parts - 1; } return req <= k; }; int lo = 0, hi = 1e9, mid; while (lo < hi) { mid = lo + (hi - lo) / 2; if (can(mid)) { hi = mid; } else { lo = mid + 1; } } cout << lo; } /************************************** END OF PROGRAM * ******************************************/ /** Stuff you should look for: * int overflow, array bounds, over-counting * special cases (n=1?), set/unordered_set TLE, multi-set/set error * do something instead of nothing and stay organized */
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define SPEED \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define FOR(i, a, b) for (ll i = a; i < b; ++i) #define RFOR(i, b, a) for (ll i = b; i >= a; --i) #define ALL(x) x.begin(), x.end() #define DEBUG(args...) \ { \ string _s = #args; \ replace(ALL(_s), ' ', '\0'); \ replace(ALL(_s), ',', ' '); \ stringstream _ss(_s); \ istream_iterator<string> _it(_ss); \ _debug(_it, args); \ } #define endl "\n" #define F first #define S second #define pb(x) push_back(x) a #define mp(x, y) make_pair(x, y) using namespace std; using namespace __gnu_pbds; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; void _debug(istream_iterator<string>) {} template <typename T, typename... Args> void _debug(istream_iterator<string> it, T first, Args... args) { cerr << ">> " << *it << " : " << first << endl; _debug(++it, args...); } template <typename T1, typename T2> inline ostream &operator<<(ostream &out, const pair<T1, T2> &p) { return out << "(" << p.F << ", " << p.S << ")"; } template <typename T> inline ostream &operator<<(ostream &out, const vector<T> &v) { if (v.empty()) return out << "[]"; else { out << '['; for (auto &e : v) { out << e << ", "; } return out << "\b\b]"; } } template <typename T> inline ostream &operator<<(ostream &out, const set<T> &s) { if (s.empty()) return out << "{}"; else { out << '{'; for (auto &e : s) { out << e << ", "; } return out << "\b\b}"; } } template <typename T> inline ostream &operator<<(ostream &out, const unordered_set<T> &s) { return out << set<T>(ALL(s)); } template <typename T1, typename T2> inline ostream &operator<<(ostream &out, const map<T1, T2> &m) { if (m.empty()) return out << "{}"; out << '{'; for (auto &p : m) { out << p << ", "; } return out << "\b\b}"; } template <typename T1, typename T2> inline ostream &operator<<(ostream &out, const unordered_map<T1, T2> &m) { return out << map<T1, T2>(ALL(m)); } template <typename T> inline ostream &operator<<(ostream &out, const ordered_set<T> &s) { return out << set<T>(ALL(s)); } typedef long long ll; typedef long double ld; typedef vector<long long> vll; typedef pair<ll, ll> pll; typedef vector<pair<ll, ll>> vpll; typedef unordered_map<ll, ll> STll; /************************************** MAIN PROGRAM * ********************************************/ int main() { // freopen("input.txt", "r", stdin); SPEED int n; cin >> n; int k; cin >> k; vector<int> a(n); for (auto &e : a) cin >> e; auto can = [&](int x) { int req = 0; for (auto e : a) { int parts = (e + x - 1) / x; req += parts - 1; } return req <= k; }; int lo = 1, hi = 1e9, mid; while (lo < hi) { mid = lo + (hi - lo) / 2; if (can(mid)) { hi = mid; } else { lo = mid + 1; } } cout << lo; } /************************************** END OF PROGRAM * ******************************************/ /** Stuff you should look for: * int overflow, array bounds, over-counting * special cases (n=1?), set/unordered_set TLE, multi-set/set error * do something instead of nothing and stay organized */
replace
117
118
117
118
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; const int inf = 0x3f3f3f3f; int n, k; int a[maxn]; bool check(int x) { int sum = 0; for (int i = 1; i <= n; i++) { sum += a[i] / x; if (a[i] % x == 0) sum--; } if (sum > k) return 0; else return 1; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); // freopen(".in","r",stdin); // freopen(".out","w",stdout); cin >> n >> k; int maxv = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; maxv = max(maxv, a[i]); } int l = 0, r = maxv + 1, ans; while (l < r) { int mid = (l + r) / 2; if (check(mid)) r = mid; else l = mid + 1; } cout << l << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; const int inf = 0x3f3f3f3f; int n, k; int a[maxn]; bool check(int x) { int sum = 0; for (int i = 1; i <= n; i++) { sum += a[i] / x; if (a[i] % x == 0) sum--; } if (sum > k) return 0; else return 1; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); // freopen(".in","r",stdin); // freopen(".out","w",stdout); cin >> n >> k; int maxv = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; maxv = max(maxv, a[i]); } int l = 1, r = 1000000000, ans; while (l < r) { int mid = (l + r) / 2; if (check(mid)) r = mid; else l = mid + 1; } cout << l << endl; return 0; }
replace
30
31
30
31
0
p02598
C++
Runtime Error
#pragma GCC optimize("O3") #include <bits/stdc++.h> typedef long long ll; using namespace std; template <class TH> void _dbg(const char *sdbg, TH h) { cerr << sdbg << '=' << h << endl; } template <class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) { while (*sdbg != ',') cerr << *sdbg++; cerr << '=' << h << ','; _dbg(sdbg + 1, a...); } #ifdef LOCAL #define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__) #else #define debug(...) 42 #endif typedef long long ll; string s; const int maxn = 2e5 + 100; int a[maxn]; int main() { int n, k; cin >> n >> k; int maxx = 0; for (int i = 0; i < n; ++i) { cin >> a[i]; if (a[i] > maxx) maxx = a[i]; } int l = 0, r = maxx; while (l < r) { int mid = (l + r) >> 1; int res = k; for (int i = 0; i < n; ++i) { if (a[i] % mid == 0) res -= a[i] / mid - 1; else res -= a[i] / mid; } debug(l, r, mid, res); if (res < 0) l = mid + 1; else r = mid; } cout << l << endl; return 0; }
#pragma GCC optimize("O3") #include <bits/stdc++.h> typedef long long ll; using namespace std; template <class TH> void _dbg(const char *sdbg, TH h) { cerr << sdbg << '=' << h << endl; } template <class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) { while (*sdbg != ',') cerr << *sdbg++; cerr << '=' << h << ','; _dbg(sdbg + 1, a...); } #ifdef LOCAL #define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__) #else #define debug(...) 42 #endif typedef long long ll; string s; const int maxn = 2e5 + 100; int a[maxn]; int main() { int n, k; cin >> n >> k; int maxx = 0; for (int i = 0; i < n; ++i) { cin >> a[i]; if (a[i] > maxx) maxx = a[i]; } int l = 1, r = maxx; while (l < r) { int mid = (l + r) >> 1; int res = k; for (int i = 0; i < n; ++i) { if (a[i] % mid == 0) res -= a[i] / mid - 1; else res -= a[i] / mid; } debug(l, r, mid, res); if (res < 0) l = mid + 1; else r = mid; } cout << l << endl; return 0; }
replace
34
35
34
35
0
p02598
C++
Runtime Error
/* / \ (Hello)//JSM//*/ /* /*****\ */ /* Jai Shree Mataji / \ |\| |_| $ |-| K */ #include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <cstring> #include <iostream> #include <map> #include <set> #include <string.h> #include <vector> using namespace std; #define ll long long int #define ld long double #define MOD 1000000007 #define PI 3.1415926535897932384626433832795 #define YY cout << "YES" #define NN cout << "NO" #define EE cout << "\n" #define ee cout << "\n" #define ne cout << "-1" #define pb push_back #define fi first #define se second #define mkp make_pair #define mkt make_tuple #define sall(v) sort(v.begin(), v.end()) #define all(v) v.begin(), v.end() #define fo(i, n) for (ll i = 0; i < n; i++) #define vl vector<ll> #define vc vector<char> #define vll vector<pair<ll, ll>> #define mps map<string, ll> #define mpc map<char, ll> #define mpl map<ll, ll> #define pr pair<ll, ll> #define tpl tuple<ll, ll, ll> bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); } ll containsDigit(ll number, ll digit) { while (number != 0) { int curr_digit = number % 10; if (curr_digit == digit) return 1; number /= 10; } return 0; } ll soltn(ll x, ll n) { if (x >= 0) return x % n; else return n + x % n; } ll bin_srch(ll L[], ll N, ll item) { ll flag = -2; int l = 0, u = N - 1, m; while (l <= u) { m = (l + u) / 2; if (item == L[m]) { flag = m - 1; break; } else if (item > L[m]) l = m - 1; else u = m + 1; } return flag; } ll pd(ll x, ll y) { if (x % y == 0) return x / y; else return x / y + 1; } ll coda(ll n, ll d) { ll count = 0; while (n != 0) { if (n % 10 == d) count++; n /= 10; } return count; } ll minDissame(ll a[], ll n) { map<ll, ll> hmap; ll minDistance = INT_MAX; ll previousIndex = 0, currentIndex = 0; for (ll i = 0; i < n; i++) { if (hmap.find(a[i]) != hmap.end()) { currentIndex = i; previousIndex = hmap[a[i]]; minDistance = min((currentIndex - previousIndex), minDistance); } hmap[a[i]] = i; } return (minDistance == INT_MAX ? -1 : minDistance); } ll minDistanytwo(ll arr[], ll n, ll x, ll y) { ll p = -1, min_dist = INT_MAX; for (ll i = 0; i < n; i++) { if (arr[i] == x || arr[i] == y) { if (p != -1 && arr[i] != arr[p]) min_dist = min(min_dist, i - p); p = i; } } if (min_dist == INT_MAX) return -1; return min_dist; } ll mdls(ll x) { return max(x, -x); } ll pow1(ll n, ll p) { if (p == 0) return 1; ll x = pow1(n, p / 2); x = (x * x); if (p % 2 == 0) return x; else return (x * n); } string fumn(string s) { string p; for (ll i = 0; i < s.length(); i++) if (isalpha(s[i])) p += toupper(s[i]); return p; } ll turns(string S, string SS) { ll i, cc = 0, l = S.length(); fo(i, l) { if (S[i] != SS[i]) cc++; } return cc / 2; } ll isSubstr(string s1, string s2) { ll M = s1.length(); ll N = s2.length(); for (ll i = 0; i <= N - M; i++) { ll j; for (j = 0; j < M; j++) if (s2[i + j] != s1[j]) break; if (j == M) return i; } return -1; } // s2>s1;if(not) rtrn -1; ll hhh2(unsigned ll n) { if (n < 1) return 0; ll res = 1; ll u = 0; for (ll i = 0; i < 8 * sizeof(unsigned ll); i++) { ll curr = 1 << i; if (curr > n) break; u++; res = curr; } return u; } ld ldgcd(ld a, ld b) { return a < 0.0001 ? b : ldgcd(fmod(b, a), a); } void onesol(ll a, ll b, ll &x, ll &y, ll &g) { if (!b) { g = a; x = 1; y = 0; } else { onesol(b, a % b, y, x, g); y -= a / b * x; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); ll tt = 1; // cin>>tt; while (tt--) { /* 10 10 158260522 877914575 602436426 24979445 861648772 623690081 433933447 476190629 262703497 211047202*/ ll i, n, m, j, k, l; cin >> n >> k; ll a[n]; fo(i, n) cin >> a[i]; sort(a, a + n); ll H = a[n - 1], L = 1; ll ans = a[n - 1]; while (H >= L) { ll mid = (H + L) / 2; ll c = 0; fo(j, n) { ll p = (a[j] + k - 1) / k - 1; c += p; } /* cout<<mid<<" "<<c; ee;*/ if (c <= k) { ans = mid; H = mid - 1; } else { L = mid + 1; } } cout << ans; ee; } return 0; }
/* / \ (Hello)//JSM//*/ /* /*****\ */ /* Jai Shree Mataji / \ |\| |_| $ |-| K */ #include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <cstring> #include <iostream> #include <map> #include <set> #include <string.h> #include <vector> using namespace std; #define ll long long int #define ld long double #define MOD 1000000007 #define PI 3.1415926535897932384626433832795 #define YY cout << "YES" #define NN cout << "NO" #define EE cout << "\n" #define ee cout << "\n" #define ne cout << "-1" #define pb push_back #define fi first #define se second #define mkp make_pair #define mkt make_tuple #define sall(v) sort(v.begin(), v.end()) #define all(v) v.begin(), v.end() #define fo(i, n) for (ll i = 0; i < n; i++) #define vl vector<ll> #define vc vector<char> #define vll vector<pair<ll, ll>> #define mps map<string, ll> #define mpc map<char, ll> #define mpl map<ll, ll> #define pr pair<ll, ll> #define tpl tuple<ll, ll, ll> bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); } ll containsDigit(ll number, ll digit) { while (number != 0) { int curr_digit = number % 10; if (curr_digit == digit) return 1; number /= 10; } return 0; } ll soltn(ll x, ll n) { if (x >= 0) return x % n; else return n + x % n; } ll bin_srch(ll L[], ll N, ll item) { ll flag = -2; int l = 0, u = N - 1, m; while (l <= u) { m = (l + u) / 2; if (item == L[m]) { flag = m - 1; break; } else if (item > L[m]) l = m - 1; else u = m + 1; } return flag; } ll pd(ll x, ll y) { if (x % y == 0) return x / y; else return x / y + 1; } ll coda(ll n, ll d) { ll count = 0; while (n != 0) { if (n % 10 == d) count++; n /= 10; } return count; } ll minDissame(ll a[], ll n) { map<ll, ll> hmap; ll minDistance = INT_MAX; ll previousIndex = 0, currentIndex = 0; for (ll i = 0; i < n; i++) { if (hmap.find(a[i]) != hmap.end()) { currentIndex = i; previousIndex = hmap[a[i]]; minDistance = min((currentIndex - previousIndex), minDistance); } hmap[a[i]] = i; } return (minDistance == INT_MAX ? -1 : minDistance); } ll minDistanytwo(ll arr[], ll n, ll x, ll y) { ll p = -1, min_dist = INT_MAX; for (ll i = 0; i < n; i++) { if (arr[i] == x || arr[i] == y) { if (p != -1 && arr[i] != arr[p]) min_dist = min(min_dist, i - p); p = i; } } if (min_dist == INT_MAX) return -1; return min_dist; } ll mdls(ll x) { return max(x, -x); } ll pow1(ll n, ll p) { if (p == 0) return 1; ll x = pow1(n, p / 2); x = (x * x); if (p % 2 == 0) return x; else return (x * n); } string fumn(string s) { string p; for (ll i = 0; i < s.length(); i++) if (isalpha(s[i])) p += toupper(s[i]); return p; } ll turns(string S, string SS) { ll i, cc = 0, l = S.length(); fo(i, l) { if (S[i] != SS[i]) cc++; } return cc / 2; } ll isSubstr(string s1, string s2) { ll M = s1.length(); ll N = s2.length(); for (ll i = 0; i <= N - M; i++) { ll j; for (j = 0; j < M; j++) if (s2[i + j] != s1[j]) break; if (j == M) return i; } return -1; } // s2>s1;if(not) rtrn -1; ll hhh2(unsigned ll n) { if (n < 1) return 0; ll res = 1; ll u = 0; for (ll i = 0; i < 8 * sizeof(unsigned ll); i++) { ll curr = 1 << i; if (curr > n) break; u++; res = curr; } return u; } ld ldgcd(ld a, ld b) { return a < 0.0001 ? b : ldgcd(fmod(b, a), a); } void onesol(ll a, ll b, ll &x, ll &y, ll &g) { if (!b) { g = a; x = 1; y = 0; } else { onesol(b, a % b, y, x, g); y -= a / b * x; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); ll tt = 1; // cin>>tt; while (tt--) { /* 10 10 158260522 877914575 602436426 24979445 861648772 623690081 433933447 476190629 262703497 211047202*/ ll i, n, m, j, k, l; cin >> n >> k; ll a[n]; fo(i, n) cin >> a[i]; sort(a, a + n); ll H = a[n - 1], L = 1; ll ans = a[n - 1]; while (H >= L) { ll mid = (H + L) / 2; ll c = 0; fo(j, n) { ll p = (a[j] + mid - 1) / mid - 1; c += p; } /* cout<<mid<<" "<<c; ee;*/ if (c <= k) { ans = mid; H = mid - 1; } else { L = mid + 1; } } cout << ans; ee; } return 0; }
replace
200
201
200
201
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long // #define endl '\n' void max_self(int &a, int b) { a = max(a, b); } void min_self(int &a, int b) { a = min(a, b); } int n, k; vector<int> v; bool good(int x) { int cnt = k; for (int i = 0; i < n; i++) { cnt -= (v[i] - 1) / x; } return cnt >= 0; } void solve() { cin >> n >> k; v.resize(n); for (int &i : v) cin >> i; int l = -1; // bad int r = 1e9; // good while (r > l + 1) { int mid = (l + r) / 2; if (good(mid)) { r = mid; } else { l = mid; } } cout << r << endl; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; // cin>>t; for (int i = 1; i <= t; i++) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long // #define endl '\n' void max_self(int &a, int b) { a = max(a, b); } void min_self(int &a, int b) { a = min(a, b); } int n, k; vector<int> v; bool good(int x) { int cnt = k; for (int i = 0; i < n; i++) { cnt -= (v[i] - 1) / x; } return cnt >= 0; } void solve() { cin >> n >> k; v.resize(n); for (int &i : v) cin >> i; int l = 0; // bad int r = 1e9; // good while (r > l + 1) { int mid = (l + r) / 2; if (good(mid)) { r = mid; } else { l = mid; } } cout << r << endl; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; // cin>>t; for (int i = 1; i <= t; i++) { solve(); } return 0; }
replace
25
26
25
26
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") using namespace std; typedef long long ll; typedef long double ld; const double E = 1e-7; const ll INF = 1e17; #define forn(i, s, f) for (int i = s; i < f; ++i) #define ft first #define sec second #define fora(i, n) for (auto i : n) #define sz(a) (int)(a).size() #define sort_(a) sort(a.begin(), a.end()) #define pb push_back #define mp make_pair #define rsort_(a) \ sort(a.begin(), a.end()); \ reverse(a.begin(), a.end()) #define fast_ cin.tie(0), ios_base::sync_with_stdio(false) // ____________________________________________________________ #define cina(a) forn(i, 0, sz(a)) cin >> a[i] #define cinpr(a) cin >> a.ft >> a.sec //-------------------------------------------------------------- #define int long long bool f(int m, const vector<int> &a, int k) { int ans = 0; forn(i, 0, a.size()) { int cp = a[i]; int deep = 0; if (a[i] > m) ans += (a[i] / m); /*while (cp > m) { ans += (1<<deep); deep++; cp = cp / 2 + (cp % 2 != 0); }*/ } if (ans <= k) return true; return false; } signed main() { fast_; ll n, k; cin >> n >> k; vector<int> a(n); forn(i, 0, n) cin >> a[i]; int l = 0, r = 1e9; while (l + 1 < r) { int m = (l + r) / 2; if (f(m, a, k)) { r = m; } else { l = m; } } // cout << l << '\n'; if (f(l, a, k)) cout << l; else cout << r << '\n'; }
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") using namespace std; typedef long long ll; typedef long double ld; const double E = 1e-7; const ll INF = 1e17; #define forn(i, s, f) for (int i = s; i < f; ++i) #define ft first #define sec second #define fora(i, n) for (auto i : n) #define sz(a) (int)(a).size() #define sort_(a) sort(a.begin(), a.end()) #define pb push_back #define mp make_pair #define rsort_(a) \ sort(a.begin(), a.end()); \ reverse(a.begin(), a.end()) #define fast_ cin.tie(0), ios_base::sync_with_stdio(false) // ____________________________________________________________ #define cina(a) forn(i, 0, sz(a)) cin >> a[i] #define cinpr(a) cin >> a.ft >> a.sec //-------------------------------------------------------------- #define int long long bool f(int m, const vector<int> &a, int k) { int ans = 0; forn(i, 0, a.size()) { int cp = a[i]; int deep = 0; if (a[i] > m) ans += (a[i] / m); /*while (cp > m) { ans += (1<<deep); deep++; cp = cp / 2 + (cp % 2 != 0); }*/ } if (ans <= k) return true; return false; } signed main() { fast_; ll n, k; cin >> n >> k; vector<int> a(n); forn(i, 0, n) cin >> a[i]; int l = 1, r = 1e10; while (l + 1 < r) { int m = (l + r) / 2; if (f(m, a, k)) { r = m; } else { l = m; } } // cout << l << '\n'; if (f(l, a, k)) cout << l; else cout << r << '\n'; }
replace
51
52
51
52
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/hash_map> #include <ext/numeric> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; using namespace __gnu_cxx; #define REP(i, n) for ((i) = 0; (i) < (n); (i)++) #define rep(i, x, n) for ((i) = (x); (i) < (n); (i)++) #define REV(i, n) for ((i) = (n); (i) >= 0; (i)--) #define FORIT(it, x) for ((it) = (x).begin(); (it) != (x).end(); (it)++) #define foreach(it, c) \ for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it) #define rforeach(it, c) \ for (__typeof((c).rbegin()) it = (c).rbegin(); it != (c).rend(); ++it) #define foreach2d(i, j, v) \ foreach (i, v) \ foreach (j, *i) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define SZ(x) ((int)(x).size()) #define MMS(x, n) memset(x, n, sizeof(x)) #define mms(x, n, s) memset(x, n, sizeof(x) * s) #define pb push_back #define mp make_pair #define NX next_permutation #define UN(x) sort(all(x)), x.erase(unique(all(x)), x.end()) #define CV(x, n) count(all(x), (n)) #define FIND(x, n) find(all(x), (n)) - (x).begin() #define ACC(x) accumulate(all(x), 0) #define PPC(x) __builtin_popcountll(x) #define LZ(x) __builtin_clz(x) #define TZ(x) __builtin_ctz(x) #define mxe(x) *max_element(all(x)) #define mne(x) *min_element(all(x)) #define low(x, i) lower_bound(all(x), i) #define upp(x, i) upper_bound(all(x), i) #define NXPOW2(x) (1ll << ((int)log2(x) + 1)) #define PR(x) cout << #x << " = " << (x) << endl; typedef unsigned long long ull; typedef long long ll; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef pair<int, int> pii; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; const int OO = (int)2e9; const double eps = 1e-9; const int N = 2e5 + 5; int n, k; int a[N]; bool valid(int x) { ll need = 0; for (int i = 0; i < n; i++) { need += a[i] / x - !bool(a[i] % x); } return need <= k; } int main() { std::ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE // freopen("in.txt", "rt", stdin); // freopen("out.txt", "wt", stdout); #endif cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; int st = 0, en = 1e9; while (st < en) { int mid = st + (en - st) / 2; if (!valid(mid)) st = mid + 1; else en = mid; } cout << st << endl; return 0; }
#include <bits/stdc++.h> #include <ext/hash_map> #include <ext/numeric> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; using namespace __gnu_cxx; #define REP(i, n) for ((i) = 0; (i) < (n); (i)++) #define rep(i, x, n) for ((i) = (x); (i) < (n); (i)++) #define REV(i, n) for ((i) = (n); (i) >= 0; (i)--) #define FORIT(it, x) for ((it) = (x).begin(); (it) != (x).end(); (it)++) #define foreach(it, c) \ for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it) #define rforeach(it, c) \ for (__typeof((c).rbegin()) it = (c).rbegin(); it != (c).rend(); ++it) #define foreach2d(i, j, v) \ foreach (i, v) \ foreach (j, *i) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define SZ(x) ((int)(x).size()) #define MMS(x, n) memset(x, n, sizeof(x)) #define mms(x, n, s) memset(x, n, sizeof(x) * s) #define pb push_back #define mp make_pair #define NX next_permutation #define UN(x) sort(all(x)), x.erase(unique(all(x)), x.end()) #define CV(x, n) count(all(x), (n)) #define FIND(x, n) find(all(x), (n)) - (x).begin() #define ACC(x) accumulate(all(x), 0) #define PPC(x) __builtin_popcountll(x) #define LZ(x) __builtin_clz(x) #define TZ(x) __builtin_ctz(x) #define mxe(x) *max_element(all(x)) #define mne(x) *min_element(all(x)) #define low(x, i) lower_bound(all(x), i) #define upp(x, i) upper_bound(all(x), i) #define NXPOW2(x) (1ll << ((int)log2(x) + 1)) #define PR(x) cout << #x << " = " << (x) << endl; typedef unsigned long long ull; typedef long long ll; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef pair<int, int> pii; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; const int OO = (int)2e9; const double eps = 1e-9; const int N = 2e5 + 5; int n, k; int a[N]; bool valid(int x) { ll need = 0; for (int i = 0; i < n; i++) { need += a[i] / x - !bool(a[i] % x); } return need <= k; } int main() { std::ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE // freopen("in.txt", "rt", stdin); // freopen("out.txt", "wt", stdout); #endif cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; int st = 1, en = 1e9; while (st < en) { int mid = st + (en - st) / 2; if (!valid(mid)) st = mid + 1; else en = mid; } cout << st << endl; return 0; }
replace
80
81
80
81
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long #define db double #define pb push_back #define rep(i, a, b) for (ll i = a; i <= b; i++) #define all(a) a.begin(), a.end() using namespace std; ll mod = 1e9 + 7; const ll M = 500006; ll f[M], inv[M]; ll expo(ll base, ll exponent) { ll ans = 1; while (exponent != 0) { if (exponent & 1) ans = (1LL * ans * base) % mod; base = (1LL * base * base) % mod; exponent >>= 1; } return ans % mod; } void compute() { f[0] = 1; rep(i, 1, M - 1) { f[i] = (1LL * i * f[i - 1]) % mod; } inv[M - 1] = expo(f[M - 1], mod - 2); for (ll i = M - 2; i >= 0; i--) { inv[i] = (1LL * (i + 1) * inv[i + 1]) % mod; } } ll C(ll n, ll r) { return (1LL * ((1LL * f[n] * inv[r]) % mod) * inv[n - r]) % mod; } vector<bool> prime(1000002, true); void Sieve() { for (int p = 2; p * p <= 1000001; p++) { // If prime[p] is not changed, then it is a prime if (prime[p] == true) { for (int i = p * p; i <= 1000001; i += p) prime[i] = false; } } } vector<ll> a(2000000); ll func(ll val, ll n) { ll cnt = 0; for (ll i = 0; i < n; i++) { ll tmp = a[i] / val; if (a[i] % val == 0) tmp--; cnt += tmp; } return cnt; } int main() { // #ifndef ONLINE_JUDGE // // for getting input from input.txt // freopen("alchemy_input.txt", "r", stdin); // // for writing output to output.txt // freopen("output.txt", "w", stdout); // #endif ios_base::sync_with_stdio(false); cin.tie(NULL); // compute(); ll tests = 1, t = 1; // cin>>tests; while (tests--) { ll i, j, n, k; cin >> n >> k; ll mx = 0; rep(i, 0, n - 1) { cin >> a[i]; mx = max(mx, a[i]); } if (k == 0) { cout << mx; return 0; } ll lo = 0, hi = 1e9; while (hi >= lo) { ll mid = (lo + hi) / 2; ll tmp = func(mid, n); // cout<<tmp<<"\n"; if (tmp > k) lo = mid + 1; else hi = mid - 1; } cout << lo; } return 0; }
#include <bits/stdc++.h> #define ll long long #define db double #define pb push_back #define rep(i, a, b) for (ll i = a; i <= b; i++) #define all(a) a.begin(), a.end() using namespace std; ll mod = 1e9 + 7; const ll M = 500006; ll f[M], inv[M]; ll expo(ll base, ll exponent) { ll ans = 1; while (exponent != 0) { if (exponent & 1) ans = (1LL * ans * base) % mod; base = (1LL * base * base) % mod; exponent >>= 1; } return ans % mod; } void compute() { f[0] = 1; rep(i, 1, M - 1) { f[i] = (1LL * i * f[i - 1]) % mod; } inv[M - 1] = expo(f[M - 1], mod - 2); for (ll i = M - 2; i >= 0; i--) { inv[i] = (1LL * (i + 1) * inv[i + 1]) % mod; } } ll C(ll n, ll r) { return (1LL * ((1LL * f[n] * inv[r]) % mod) * inv[n - r]) % mod; } vector<bool> prime(1000002, true); void Sieve() { for (int p = 2; p * p <= 1000001; p++) { // If prime[p] is not changed, then it is a prime if (prime[p] == true) { for (int i = p * p; i <= 1000001; i += p) prime[i] = false; } } } vector<ll> a(2000000); ll func(ll val, ll n) { ll cnt = 0; for (ll i = 0; i < n; i++) { ll tmp = a[i] / val; if (a[i] % val == 0) tmp--; cnt += tmp; } return cnt; } int main() { // #ifndef ONLINE_JUDGE // // for getting input from input.txt // freopen("alchemy_input.txt", "r", stdin); // // for writing output to output.txt // freopen("output.txt", "w", stdout); // #endif ios_base::sync_with_stdio(false); cin.tie(NULL); // compute(); ll tests = 1, t = 1; // cin>>tests; while (tests--) { ll i, j, n, k; cin >> n >> k; ll mx = 0; rep(i, 0, n - 1) { cin >> a[i]; mx = max(mx, a[i]); } if (k == 0) { cout << mx; return 0; } ll lo = 1, hi = 1e9; while (hi >= lo) { ll mid = (lo + hi) / 2; ll tmp = func(mid, n); // cout<<tmp<<"\n"; if (tmp > k) lo = mid + 1; else hi = mid - 1; } cout << lo; } return 0; }
replace
81
82
81
82
0
p02598
C++
Runtime Error
// Template Headers {{{ #include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; using vpii = vector<pii>; using vi = vector<int>; using vvi = vector<vi>; using ll = long long; using pll = pair<ll, ll>; using vpll = vector<pll>; using vll = vector<long long>; using vvll = vector<vll>; template <class T> using min_queue = priority_queue<T, vector<T>, greater<T>>; template <class T> istream &operator>>(istream &, vector<T> &); template <class T> ostream &operator<<(ostream &, const vector<T> &); template <class T, class U> istream &operator>>(istream &, pair<T, U> &); template <class T, class U> ostream &operator<<(ostream &, const pair<T, U> &); template <class T> struct Inf { static constexpr T inf() { return std::numeric_limits<T>::has_infinity ? std::numeric_limits<T>::infinity() : std::numeric_limits<T>::max(); } }; template <> struct Inf<int> { static constexpr int inf() { return 0x3f3f3f3f; } }; template <> struct Inf<long long> { static constexpr long long inf() { return 0x3f3f3f3f3f3f3f3fLL; } }; constexpr int INF = Inf<int>::inf(); constexpr ll BINF = Inf<ll>::inf(); // mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // }}} // Preprocessing & "Global" variables {{{ struct Solver { Solver() {} int solve(); }; // }}} int Solver::solve() { int n, k; cin >> n >> k; vi a(n); cin >> a; int lo = 0, hi = 1'000'000'000; while (lo < hi) { int mi = lo + (hi - lo) / 2; ll cuts = 0; for (int x : a) cuts += (x + mi - 1) / mi - 1; if (cuts <= k) hi = mi; else lo = mi + 1; } cout << lo << endl; return 0; } // Template Main {{{ int main() { ios::sync_with_stdio(0); cin.tie(0); Solver solver; #ifdef JUDGE_MULTI_CASE int t; cin >> t; for (int i = 1; i <= t; i++) #endif solver.solve(); // cout << "Case #" << i << ": ", solver.solve(); return 0; } template <class T> istream &operator>>(istream &is, vector<T> &v) { for (auto it = v.begin(); it != v.end(); ++it) is >> *it; return is; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto it = v.begin(); it != v.end();) os << *it, os << " \n"[++it == v.end()]; return os; } template <class T, class U> istream &operator>>(istream &is, pair<T, U> &p) { return is >> p.first >> p.second; } template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { return os << p.first << ' ' << p.second; } // }}} // vim: fdm=marker
// Template Headers {{{ #include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; using vpii = vector<pii>; using vi = vector<int>; using vvi = vector<vi>; using ll = long long; using pll = pair<ll, ll>; using vpll = vector<pll>; using vll = vector<long long>; using vvll = vector<vll>; template <class T> using min_queue = priority_queue<T, vector<T>, greater<T>>; template <class T> istream &operator>>(istream &, vector<T> &); template <class T> ostream &operator<<(ostream &, const vector<T> &); template <class T, class U> istream &operator>>(istream &, pair<T, U> &); template <class T, class U> ostream &operator<<(ostream &, const pair<T, U> &); template <class T> struct Inf { static constexpr T inf() { return std::numeric_limits<T>::has_infinity ? std::numeric_limits<T>::infinity() : std::numeric_limits<T>::max(); } }; template <> struct Inf<int> { static constexpr int inf() { return 0x3f3f3f3f; } }; template <> struct Inf<long long> { static constexpr long long inf() { return 0x3f3f3f3f3f3f3f3fLL; } }; constexpr int INF = Inf<int>::inf(); constexpr ll BINF = Inf<ll>::inf(); // mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // }}} // Preprocessing & "Global" variables {{{ struct Solver { Solver() {} int solve(); }; // }}} int Solver::solve() { int n, k; cin >> n >> k; vi a(n); cin >> a; int lo = 1, hi = 1'000'000'000; while (lo < hi) { int mi = lo + (hi - lo) / 2; ll cuts = 0; for (int x : a) cuts += (x + mi - 1) / mi - 1; if (cuts <= k) hi = mi; else lo = mi + 1; } cout << lo << endl; return 0; } // Template Main {{{ int main() { ios::sync_with_stdio(0); cin.tie(0); Solver solver; #ifdef JUDGE_MULTI_CASE int t; cin >> t; for (int i = 1; i <= t; i++) #endif solver.solve(); // cout << "Case #" << i << ": ", solver.solve(); return 0; } template <class T> istream &operator>>(istream &is, vector<T> &v) { for (auto it = v.begin(); it != v.end(); ++it) is >> *it; return is; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto it = v.begin(); it != v.end();) os << *it, os << " \n"[++it == v.end()]; return os; } template <class T, class U> istream &operator>>(istream &is, pair<T, U> &p) { return is >> p.first >> p.second; } template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { return os << p.first << ' ' << p.second; } // }}} // vim: fdm=marker
replace
47
48
47
48
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> #include <iostream> using namespace std; int main() { // your code goes long long int n, k; cin >> n >> k; long long int a[n]; for (long int i = 0; i < n; i++) { cin >> a[i]; } long long int l = 0, r = 1e9; long long int ans = 1e9; while (l <= r) { long long int mid = (l + r) / 2; long long int ss = 0; for (long int i = 0; i < n; i++) { ss += a[i] / mid; if (a[i] % mid == 0) ss--; } if (ss > k) { l = mid + 1; } else { ans = min(ans, mid); r = mid - 1; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #include <iostream> using namespace std; int main() { // your code goes long long int n, k; cin >> n >> k; long long int a[n]; for (long int i = 0; i < n; i++) { cin >> a[i]; } long long int l = 1, r = 1e9; long long int ans = 1e9; while (l <= r) { long long int mid = (l + r) / 2; long long int ss = 0; for (long int i = 0; i < n; i++) { ss += a[i] / mid; if (a[i] % mid == 0) ss--; } if (ss > k) { l = mid + 1; } else { ans = min(ans, mid); r = mid - 1; } } cout << ans << endl; return 0; }
replace
12
13
12
13
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vii; typedef vector<vi> vvi; typedef vector<pll> vll; typedef vector<vl> vvl; #define fori(i, n) for (int i = 0; i < n; i++) #define ford(i, n) for (int i = n - 1; i >= 0; i--) #define rep(i, a, b) for (int i = a; i <= b; i++) #define repd(i, a, b) for (int i = a; i >= b; i--) #define trav(x, a) for (auto &x : a) #define all(x) (x).begin(), (x).end() #define pb push_back #define eb emplace_back #define endl '\n' #define sz(a) (int)(a).size() #define fi first #define se second clock_t time_p = clock(); void time_taken() { time_p = clock() - time_p; cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n"; } const ll mod = 1e9 + 7; const ll INF = 1e18; const ld EPS = 1e-8; #define TRACE #ifdef TRACE #define trace(...) \ { \ cerr << "[ "; \ __trace__(#__VA_ARGS__, __VA_ARGS__); \ } #undef endl template <typename Arg1, typename Arg2> ostream &operator<<(ostream &out, const pair<Arg1, Arg2> &x) { return out << "(" << x.first << "," << x.second << ")"; } template <typename Arg1> ostream &operator<<(ostream &out, const vector<Arg1> &a) { out << "["; for (const auto &x : a) out << x << ","; return out << "]"; } template <typename Arg1> ostream &operator<<(ostream &out, const set<Arg1> &a) { out << "["; for (const auto &x : a) out << x << ","; return out << "]"; } template <typename Arg1, typename Arg2> ostream &operator<<(ostream &out, const map<Arg1, Arg2> &a) { out << "["; for (const auto &x : a) out << x << ","; return out << "]"; } template <typename Arg1> void __trace__(const string name, Arg1 &&arg1) { cerr << name << " : " << arg1 << " ] " << endl; } template <typename Arg1, typename... Args> void __trace__(const string names, Arg1 &&arg1, Args &&...args) { const string name = names.substr(0, names.find(',')); cerr << name << " : " << arg1 << " | "; __trace__(names.substr(1 + (int)name.size()), args...); } #else #define trace(args...) #endif int main() { ios_base::sync_with_stdio(false), cin.tie(nullptr); int n, k; cin >> n >> k; vi a(n); fori(i, n) cin >> a[i]; ll lo = 0, hi = 1e9; ll ans = 1e9; while (lo <= hi) { ll mid = (lo + hi) / 2; ll req = 0; fori(i, n) { req += (a[i] + mid - 1) / mid - 1; } // trace(mid,req); if (req <= k) { ans = mid; hi = mid - 1; } else { lo = mid + 1; } } cout << ans << endl; time_taken(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vii; typedef vector<vi> vvi; typedef vector<pll> vll; typedef vector<vl> vvl; #define fori(i, n) for (int i = 0; i < n; i++) #define ford(i, n) for (int i = n - 1; i >= 0; i--) #define rep(i, a, b) for (int i = a; i <= b; i++) #define repd(i, a, b) for (int i = a; i >= b; i--) #define trav(x, a) for (auto &x : a) #define all(x) (x).begin(), (x).end() #define pb push_back #define eb emplace_back #define endl '\n' #define sz(a) (int)(a).size() #define fi first #define se second clock_t time_p = clock(); void time_taken() { time_p = clock() - time_p; cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n"; } const ll mod = 1e9 + 7; const ll INF = 1e18; const ld EPS = 1e-8; #define TRACE #ifdef TRACE #define trace(...) \ { \ cerr << "[ "; \ __trace__(#__VA_ARGS__, __VA_ARGS__); \ } #undef endl template <typename Arg1, typename Arg2> ostream &operator<<(ostream &out, const pair<Arg1, Arg2> &x) { return out << "(" << x.first << "," << x.second << ")"; } template <typename Arg1> ostream &operator<<(ostream &out, const vector<Arg1> &a) { out << "["; for (const auto &x : a) out << x << ","; return out << "]"; } template <typename Arg1> ostream &operator<<(ostream &out, const set<Arg1> &a) { out << "["; for (const auto &x : a) out << x << ","; return out << "]"; } template <typename Arg1, typename Arg2> ostream &operator<<(ostream &out, const map<Arg1, Arg2> &a) { out << "["; for (const auto &x : a) out << x << ","; return out << "]"; } template <typename Arg1> void __trace__(const string name, Arg1 &&arg1) { cerr << name << " : " << arg1 << " ] " << endl; } template <typename Arg1, typename... Args> void __trace__(const string names, Arg1 &&arg1, Args &&...args) { const string name = names.substr(0, names.find(',')); cerr << name << " : " << arg1 << " | "; __trace__(names.substr(1 + (int)name.size()), args...); } #else #define trace(args...) #endif int main() { ios_base::sync_with_stdio(false), cin.tie(nullptr); int n, k; cin >> n >> k; vi a(n); fori(i, n) cin >> a[i]; ll lo = 1, hi = 1e9; ll ans = 1e9; while (lo <= hi) { ll mid = (lo + hi) / 2; ll req = 0; fori(i, n) { req += (a[i] + mid - 1) / mid - 1; } // trace(mid,req); if (req <= k) { ans = mid; hi = mid - 1; } else { lo = mid + 1; } } cout << ans << endl; time_taken(); return 0; }
replace
96
97
96
97
0
Time Taken : 0.000138
p02598
C++
Runtime Error
#include <bits/stdc++.h> #define repz(i, z, n) for (decltype(n) i = (z); i < (n); i++) #define rep(i, n) for (decltype(n) i = 0; i < (n); i++) #define REPZ(i, z, n) for (decltype(n) i = (z); i <= (n); i++) #define REP(i, n) for (decltype(n) i = 0; i <= (n); i++) #define ALL(v) v.begin(), v.end() #define len(v) ((ll)(v).size()) #define MAX(v) (*max_element(ALL(v))) #define MIN(v) (*min_element(ALL(v))) #define INF 1000000000000 // 1E+12 // 略 #define PB push_back #define F first #define S second #define MP make_pair #define READ cin >> #define PRINT cout << #define PYES cout << "YES" << endl #define pyes cout << "Yes" << endl #define POK cout << "OK" << endl #define PNO cout << "NO" << endl #define pno cout << "No" << endl #define PNG cout << "NG" << endl #define ret return 0 using namespace std; // デバッグ用 void debug_out() { cout << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); } template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } #ifdef _DEBUG #define debug(...) debug_out(__VA_ARGS__) #else #define debug(...) #endif // typedef typedef long long ll; typedef unsigned long long ul; typedef long double ld; typedef pair<ll, ll> pl; // const // 円周率 const ld pi = acos(-1); // mod用 // 1E+9 +7 const ll mod = (ll)1e+9 + 7; // 1s間で可能なループ回数2E+8回 // ll 最大値2147483647 〜2E+9 // long long 最大値9223372036854775807〜9E+18 // 総和accumulate // 単純リストvector<type> push_back // 連想配列map<key,value> insert, // 集合set<type> // pair キーとバリューを格納 firstとsecondでアクセス // 小数点指定 cout << fixed << setprecision(15) << endl; // to_string<->stoi // stoll(longlong) // stod(double) // deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) ); // 大文字65-90(-32) // 小文字97-122(+32) // priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> ll n, k; vector<ll> a; bool solve(ll mid) { ll res = 0; rep(i, n) { res += (a[i] + mid - 1) / mid - 1; } return res <= k; } signed main() { // faster // C言語流の入出力は使用できない ios::sync_with_stdio(false); std::cin.tie(nullptr); cin >> n >> k; a = vector<ll>(n); rep(i, n) cin >> a[i]; ll ok = INF; // 解が存在する値 [ok,ng) or (ng,ok] ll ng = -1; // 解が存在しない値 while (abs(ok - ng) > 1) { ll mid = (ok + ng) / 2; if (solve(mid)) ok = mid; else ng = mid; } cout << ok << endl; ret; }
#include <bits/stdc++.h> #define repz(i, z, n) for (decltype(n) i = (z); i < (n); i++) #define rep(i, n) for (decltype(n) i = 0; i < (n); i++) #define REPZ(i, z, n) for (decltype(n) i = (z); i <= (n); i++) #define REP(i, n) for (decltype(n) i = 0; i <= (n); i++) #define ALL(v) v.begin(), v.end() #define len(v) ((ll)(v).size()) #define MAX(v) (*max_element(ALL(v))) #define MIN(v) (*min_element(ALL(v))) #define INF 1000000000000 // 1E+12 // 略 #define PB push_back #define F first #define S second #define MP make_pair #define READ cin >> #define PRINT cout << #define PYES cout << "YES" << endl #define pyes cout << "Yes" << endl #define POK cout << "OK" << endl #define PNO cout << "NO" << endl #define pno cout << "No" << endl #define PNG cout << "NG" << endl #define ret return 0 using namespace std; // デバッグ用 void debug_out() { cout << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); } template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } #ifdef _DEBUG #define debug(...) debug_out(__VA_ARGS__) #else #define debug(...) #endif // typedef typedef long long ll; typedef unsigned long long ul; typedef long double ld; typedef pair<ll, ll> pl; // const // 円周率 const ld pi = acos(-1); // mod用 // 1E+9 +7 const ll mod = (ll)1e+9 + 7; // 1s間で可能なループ回数2E+8回 // ll 最大値2147483647 〜2E+9 // long long 最大値9223372036854775807〜9E+18 // 総和accumulate // 単純リストvector<type> push_back // 連想配列map<key,value> insert, // 集合set<type> // pair キーとバリューを格納 firstとsecondでアクセス // 小数点指定 cout << fixed << setprecision(15) << endl; // to_string<->stoi // stoll(longlong) // stod(double) // deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) ); // 大文字65-90(-32) // 小文字97-122(+32) // priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> ll n, k; vector<ll> a; bool solve(ll mid) { ll res = 0; rep(i, n) { res += (a[i] + mid - 1) / mid - 1; } return res <= k; } signed main() { // faster // C言語流の入出力は使用できない ios::sync_with_stdio(false); std::cin.tie(nullptr); cin >> n >> k; a = vector<ll>(n); rep(i, n) cin >> a[i]; ll ok = INF; // 解が存在する値 [ok,ng) or (ng,ok] ll ng = 0; // 解が存在しない値 while (abs(ok - ng) > 1) { ll mid = (ok + ng) / 2; if (solve(mid)) ok = mid; else ng = mid; } cout << ok << endl; ret; }
replace
102
103
102
103
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> // using namespace std; #pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define rep(i, j, n) for (ll i = (ll)(j); i < (ll)(n); i++) #define REP(i, j, n) for (ll i = (ll)(j); i <= (ll)(n); i++) #define per(i, j, n) for (ll i = (ll)(j); (ll)(n) <= i; i--) #define ll long long #define ALL(a) (a).begin(), (a).end() #define disup(A, key) distance(A.begin(), upper_bound(ALL(A), (ll)(key))) #define dislow(A, key) distance(A.begin(), lower_bound(ALL(A), (ll)(key))) #define pb emplace_back #define mp std::make_pair // #define endl "\n" // using std::cin; using std::cout; using std::endl; using std::lower_bound; using std::string; using std::upper_bound; using std::vector; using vi = vector<ll>; using vii = vector<vi>; using pii = std::pair<ll, ll>; // constexpr ll MOD = 1e9 + 7; // constexpr ll MOD=998244353; // constexpr ll MOD=10000000; // constexpr ll MOD=1e4; constexpr ll MAX = 3e6; constexpr ll inf = (1ll << 60); template <class T> class prique : public std::priority_queue<T, std::vector<T>, std::greater<T>> { }; template <typename T> struct Segment_tree { ll N; T mem; vector<T> node; Segment_tree(vector<T> &X, T m) : mem(m) { ll sz = X.size(); N = 1; while (N < sz) N *= 2; node.resize(2 * N - 1, mem); rep(i, 0, sz) node[N - 1 + i] = X[i]; per(i, N - 2, 0) { node[i] = Compare(node[i * 2 + 1], node[i * 2 + 2]); } } T Compare(T &A, T &B) { return std::max(A, B); } void update(ll X, T val) { X += N - 1; node[X] = val; while (X > 0) { X = (X - 1) / 2; node[X] = Compare(node[X * 2 + 1], node[X * 2 + 2]); } } T Query(ll a, ll b, ll now, ll l, ll r) { //[a,b),[l,r) if (r < 0) r = N; if (r <= a || b <= l) return mem; if (a <= l && r <= b) return node[now]; auto vl = Query(a, b, now * 2 + 1, l, (l + r) / 2), vr = Query(a, b, now * 2 + 2, (l + r) / 2, r); return Compare(vl, vr); } }; struct Tree { int N; vector<vector<int>> dp; vector<int> dist; Tree(vector<vector<int>> edge) { N = edge.size(); dp.resize(N); dist.resize(N, -1); for (int i = 0; i < N; i++) dp[i].resize(30); dist[0] = dp[0][0] = 0; std::queue<int> que; que.push(0); while (!que.empty()) { int now = que.front(); que.pop(); for (int i = 0; i < edge[now].size(); i++) { int next = edge[now][i]; if (dist[next] == -1) { dist[next] = dist[now] + 1; que.push(next); dp[next][0] = now; } } } for (int i = 1; i < 30; i++) { for (int j = 0; j < N; j++) dp[j][i] = dp[dp[j][i - 1]][i - 1]; } } int LCA(int X, int Y) { if (dist[X] < dist[Y]) std::swap(X, Y); { int Z = dist[X] - dist[Y]; for (int i = 0; i < 30; i++) { if (Z & (1 << i)) { X = dp[X][i]; } } } if (X == Y) return X; for (int i = 29; i >= 0; i--) { if (dp[X][i] != dp[Y][i]) { X = dp[X][i]; Y = dp[Y][i]; } } return dp[X][0]; } }; struct Binary_indexed_tree { int N; vi bit; Binary_indexed_tree(int n) : N(n) { bit.resize(N + 1, 0); } void add(int x, ll a) { for (x; x <= N; x += (x & -x)) bit[x] += a; } ll sum(int x) { ll ret = 0; for (x; x > 0; x -= (x & -x)) ret += bit[x]; return ret; } ll lower_bound(ll X) { if (sum(N) < X) return -1; ll ret = 0, memo = 1, sum = 0; while (memo * 2 <= N) memo *= 2; while (memo > 0) { if (memo + ret <= N && sum + bit[memo + ret] < X) { sum += bit[memo + ret]; ret += memo; } memo /= 2; } return ret + 1; } }; struct Union_Find { ll N; vi par; vi siz; Union_Find(int n) : N(n) { par.resize(N); siz.resize(N, 1); rep(i, 0, N) par[i] = i; } ll root(ll X) { if (par[X] == X) return X; return par[X] = root(par[X]); } bool same(ll X, ll Y) { return root(X) == root(Y); } void unite(ll X, ll Y) { X = root(X); Y = root(Y); if (X == Y) return; par[X] = Y; siz[Y] += siz[X]; siz[X] = 0; } ll size(ll X) { return siz[root(X)]; } }; long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } vi fac, finv, inv; void COMinit() { fac.resize(MAX); finv.resize(MAX); inv.resize(MAX); fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } ll COM(ll n, ll r) { if (n < r || n < 0 || r < 0) return 0; return fac[n] * finv[r] % MOD * finv[n - r] % MOD; } void comp(vi &A) { std::map<ll, ll> memo; rep(i, 0, A.size()) memo[A[i]] = 0; ll cnt = 1; for (auto &p : memo) p.second = cnt++; rep(i, 0, A.size()) A[i] = memo[A[i]]; } ll judge(ll N, vi A, ll X) { ll cnt = 0; rep(i, 0, N) { cnt += std::max(0ll, (A[i] + X - 1) / X - 1); } return cnt; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); ll N, K; cin >> N >> K; ll left = 0, right = 1e16; vi A(N); rep(i, 0, N) cin >> A[i]; while (left + 1 < right) { ll mid = (left + right) / 2; if (judge(N, A, mid) > K) left = mid; else right = mid; } ll ans = inf; REP(i, left, right) { if (judge(N, A, i) <= K) { ans = i; break; } } cout << ans << endl; }
#include <bits/stdc++.h> // using namespace std; #pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define rep(i, j, n) for (ll i = (ll)(j); i < (ll)(n); i++) #define REP(i, j, n) for (ll i = (ll)(j); i <= (ll)(n); i++) #define per(i, j, n) for (ll i = (ll)(j); (ll)(n) <= i; i--) #define ll long long #define ALL(a) (a).begin(), (a).end() #define disup(A, key) distance(A.begin(), upper_bound(ALL(A), (ll)(key))) #define dislow(A, key) distance(A.begin(), lower_bound(ALL(A), (ll)(key))) #define pb emplace_back #define mp std::make_pair // #define endl "\n" // using std::cin; using std::cout; using std::endl; using std::lower_bound; using std::string; using std::upper_bound; using std::vector; using vi = vector<ll>; using vii = vector<vi>; using pii = std::pair<ll, ll>; // constexpr ll MOD = 1e9 + 7; // constexpr ll MOD=998244353; // constexpr ll MOD=10000000; // constexpr ll MOD=1e4; constexpr ll MAX = 3e6; constexpr ll inf = (1ll << 60); template <class T> class prique : public std::priority_queue<T, std::vector<T>, std::greater<T>> { }; template <typename T> struct Segment_tree { ll N; T mem; vector<T> node; Segment_tree(vector<T> &X, T m) : mem(m) { ll sz = X.size(); N = 1; while (N < sz) N *= 2; node.resize(2 * N - 1, mem); rep(i, 0, sz) node[N - 1 + i] = X[i]; per(i, N - 2, 0) { node[i] = Compare(node[i * 2 + 1], node[i * 2 + 2]); } } T Compare(T &A, T &B) { return std::max(A, B); } void update(ll X, T val) { X += N - 1; node[X] = val; while (X > 0) { X = (X - 1) / 2; node[X] = Compare(node[X * 2 + 1], node[X * 2 + 2]); } } T Query(ll a, ll b, ll now, ll l, ll r) { //[a,b),[l,r) if (r < 0) r = N; if (r <= a || b <= l) return mem; if (a <= l && r <= b) return node[now]; auto vl = Query(a, b, now * 2 + 1, l, (l + r) / 2), vr = Query(a, b, now * 2 + 2, (l + r) / 2, r); return Compare(vl, vr); } }; struct Tree { int N; vector<vector<int>> dp; vector<int> dist; Tree(vector<vector<int>> edge) { N = edge.size(); dp.resize(N); dist.resize(N, -1); for (int i = 0; i < N; i++) dp[i].resize(30); dist[0] = dp[0][0] = 0; std::queue<int> que; que.push(0); while (!que.empty()) { int now = que.front(); que.pop(); for (int i = 0; i < edge[now].size(); i++) { int next = edge[now][i]; if (dist[next] == -1) { dist[next] = dist[now] + 1; que.push(next); dp[next][0] = now; } } } for (int i = 1; i < 30; i++) { for (int j = 0; j < N; j++) dp[j][i] = dp[dp[j][i - 1]][i - 1]; } } int LCA(int X, int Y) { if (dist[X] < dist[Y]) std::swap(X, Y); { int Z = dist[X] - dist[Y]; for (int i = 0; i < 30; i++) { if (Z & (1 << i)) { X = dp[X][i]; } } } if (X == Y) return X; for (int i = 29; i >= 0; i--) { if (dp[X][i] != dp[Y][i]) { X = dp[X][i]; Y = dp[Y][i]; } } return dp[X][0]; } }; struct Binary_indexed_tree { int N; vi bit; Binary_indexed_tree(int n) : N(n) { bit.resize(N + 1, 0); } void add(int x, ll a) { for (x; x <= N; x += (x & -x)) bit[x] += a; } ll sum(int x) { ll ret = 0; for (x; x > 0; x -= (x & -x)) ret += bit[x]; return ret; } ll lower_bound(ll X) { if (sum(N) < X) return -1; ll ret = 0, memo = 1, sum = 0; while (memo * 2 <= N) memo *= 2; while (memo > 0) { if (memo + ret <= N && sum + bit[memo + ret] < X) { sum += bit[memo + ret]; ret += memo; } memo /= 2; } return ret + 1; } }; struct Union_Find { ll N; vi par; vi siz; Union_Find(int n) : N(n) { par.resize(N); siz.resize(N, 1); rep(i, 0, N) par[i] = i; } ll root(ll X) { if (par[X] == X) return X; return par[X] = root(par[X]); } bool same(ll X, ll Y) { return root(X) == root(Y); } void unite(ll X, ll Y) { X = root(X); Y = root(Y); if (X == Y) return; par[X] = Y; siz[Y] += siz[X]; siz[X] = 0; } ll size(ll X) { return siz[root(X)]; } }; long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } vi fac, finv, inv; void COMinit() { fac.resize(MAX); finv.resize(MAX); inv.resize(MAX); fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } ll COM(ll n, ll r) { if (n < r || n < 0 || r < 0) return 0; return fac[n] * finv[r] % MOD * finv[n - r] % MOD; } void comp(vi &A) { std::map<ll, ll> memo; rep(i, 0, A.size()) memo[A[i]] = 0; ll cnt = 1; for (auto &p : memo) p.second = cnt++; rep(i, 0, A.size()) A[i] = memo[A[i]]; } ll judge(ll N, vi A, ll X) { ll cnt = 0; rep(i, 0, N) { cnt += std::max(0ll, (A[i] + X - 1) / X - 1); } return cnt; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); ll N, K; cin >> N >> K; ll left = 1, right = 1e16; vi A(N); rep(i, 0, N) cin >> A[i]; while (left + 1 < right) { ll mid = (left + right) / 2; if (judge(N, A, mid) > K) left = mid; else right = mid; } ll ans = inf; REP(i, left, right) { if (judge(N, A, i) <= K) { ans = i; break; } } cout << ans << endl; }
replace
226
227
226
227
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define floop(i, a, n) for (int i = a; i < n; i++) #define rfloop(i, a, n) for (int i = n - 1; i >= a; i--) #define mloop(it, x) for (it = x.begin(); it != x.end(); it++) #define pb push_back #define mp make_pair #define all(x) (x).begin(), (x).end() #define fi first #define se second #define sz(x) ((ll)(x).size()) #define cases \ ll t; \ cin >> t; \ while (t--) #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); typedef long long ll; typedef unsigned long long int ull; typedef vector<ll> vec; typedef pair<ll, ll> pll; typedef double db; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; const ll mod = 1000000007; ll pm(ll x, ll n) { ll result = 1; while (n > 0) { if (n % 2 == 1) result = ((result % mod) * (x % mod)) % mod; x = ((x % mod) * (x % mod)) % mod; n /= 2; } return result; } ll p(ll x, ll n) { ll result = 1; while (n > 0) { if (n % 2 == 1) result = result * x; x = x * x; n /= 2; } return result; } ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll ncr(ll n, ll r) { ll p = 1, k = 1; if (n - r < r) r = n - r; if (r != 0) { while (r != 0) { p *= n; k *= r; ll temp = gcd(p, k); p /= temp; k /= temp; n--; r--; } } else p = 1; return p; } ll factorial[300000 + 1]; void fact(ll n) { factorial[0] = 1; factorial[1] = 1; floop(i, 2, n + 1) factorial[i] = (i * factorial[i - 1] % mod) % mod; } ll d, coeff1, coeff2; void euclid(ll a, ll b) { if (b == 0) { d = a; coeff1 = 1; coeff2 = 0; } else { euclid(b, a % b); ll temp = coeff1; coeff1 = coeff2; coeff2 = temp - (a / b) * (coeff2); } } ll modinv(ll a) { euclid(a, mod); return (coeff1 % mod + mod) % mod; } int prime[1000001] = {}; int spf[1000001] = {}; void sieve(ll n) { prime[0] = 1; prime[1] = 1; for (ll i = 2; i * i <= n; i++) { if (prime[i] == 0) { for (ll j = i * i; j <= n; j += i) { prime[j] = 1; if (spf[j] == j) spf[j] = i; } } } } /* vec s(300000,0); vec si(300000,1); ll root(ll a) { while(s[a]!=a) a=s[a]; return a; } void uni(ll a,ll b) { ll r1=root(a); ll r2=root(b); if(si[r1]<si[r2]) { s[r1]=s[r2]; si[r2]+=si[r1]; } else { s[r2]=s[r1]; si[r1]+=si[r2]; } } vector<vec > adj(300000); vec vis(300000,0); vec dist(300000,0); void dfs(ll t,ll n) { vis[t]=1; floop(i,0,sz(adj[t])) { if(vis[adj[t][i]]==0) { dist[adj[t][i]]=dist[t]+1; vis[adj[t][i]]=1; // sum[adj[t][i]]=sum[t]+c[t][adj[t][i]]; dfs(adj[t][i],n); } } }*/ struct my_comp { bool operator()(pair<ll, pll> p1, pair<ll, pll> p2) { if (p1.fi != p2.fi) return p1.fi > p2.fi; return p1.se.fi < p2.se.fi; } }; // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); ll tot(ll v, ll n, vec &a) { ll ans = 0; floop(i, 0, n) ans += max((a[i] - 1) / v, 0ll); return ans; } ll bs(vec &a, ll mx, ll k) { ll low = 0, high = mx, mid; while (low < high) { mid = low + (high - low) / 2; if (tot(mid, sz(a), a) <= k) high = mid; else low = mid + 1; // cout<<low<<" "; } return high; } int main() { ll n, k; cin >> n >> k; vec a(n); floop(i, 0, n) cin >> a[i]; sort(all(a), greater<ll>()); ll mx = a[0]; cout << bs(a, mx, k) << "\n"; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define floop(i, a, n) for (int i = a; i < n; i++) #define rfloop(i, a, n) for (int i = n - 1; i >= a; i--) #define mloop(it, x) for (it = x.begin(); it != x.end(); it++) #define pb push_back #define mp make_pair #define all(x) (x).begin(), (x).end() #define fi first #define se second #define sz(x) ((ll)(x).size()) #define cases \ ll t; \ cin >> t; \ while (t--) #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); typedef long long ll; typedef unsigned long long int ull; typedef vector<ll> vec; typedef pair<ll, ll> pll; typedef double db; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; const ll mod = 1000000007; ll pm(ll x, ll n) { ll result = 1; while (n > 0) { if (n % 2 == 1) result = ((result % mod) * (x % mod)) % mod; x = ((x % mod) * (x % mod)) % mod; n /= 2; } return result; } ll p(ll x, ll n) { ll result = 1; while (n > 0) { if (n % 2 == 1) result = result * x; x = x * x; n /= 2; } return result; } ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll ncr(ll n, ll r) { ll p = 1, k = 1; if (n - r < r) r = n - r; if (r != 0) { while (r != 0) { p *= n; k *= r; ll temp = gcd(p, k); p /= temp; k /= temp; n--; r--; } } else p = 1; return p; } ll factorial[300000 + 1]; void fact(ll n) { factorial[0] = 1; factorial[1] = 1; floop(i, 2, n + 1) factorial[i] = (i * factorial[i - 1] % mod) % mod; } ll d, coeff1, coeff2; void euclid(ll a, ll b) { if (b == 0) { d = a; coeff1 = 1; coeff2 = 0; } else { euclid(b, a % b); ll temp = coeff1; coeff1 = coeff2; coeff2 = temp - (a / b) * (coeff2); } } ll modinv(ll a) { euclid(a, mod); return (coeff1 % mod + mod) % mod; } int prime[1000001] = {}; int spf[1000001] = {}; void sieve(ll n) { prime[0] = 1; prime[1] = 1; for (ll i = 2; i * i <= n; i++) { if (prime[i] == 0) { for (ll j = i * i; j <= n; j += i) { prime[j] = 1; if (spf[j] == j) spf[j] = i; } } } } /* vec s(300000,0); vec si(300000,1); ll root(ll a) { while(s[a]!=a) a=s[a]; return a; } void uni(ll a,ll b) { ll r1=root(a); ll r2=root(b); if(si[r1]<si[r2]) { s[r1]=s[r2]; si[r2]+=si[r1]; } else { s[r2]=s[r1]; si[r1]+=si[r2]; } } vector<vec > adj(300000); vec vis(300000,0); vec dist(300000,0); void dfs(ll t,ll n) { vis[t]=1; floop(i,0,sz(adj[t])) { if(vis[adj[t][i]]==0) { dist[adj[t][i]]=dist[t]+1; vis[adj[t][i]]=1; // sum[adj[t][i]]=sum[t]+c[t][adj[t][i]]; dfs(adj[t][i],n); } } }*/ struct my_comp { bool operator()(pair<ll, pll> p1, pair<ll, pll> p2) { if (p1.fi != p2.fi) return p1.fi > p2.fi; return p1.se.fi < p2.se.fi; } }; // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); ll tot(ll v, ll n, vec &a) { ll ans = 0; floop(i, 0, n) ans += max((a[i] - 1) / v, 0ll); return ans; } ll bs(vec &a, ll mx, ll k) { ll low = 1, high = mx, mid; while (low < high) { mid = low + (high - low) / 2; if (tot(mid, sz(a), a) <= k) high = mid; else low = mid + 1; // cout<<low<<" "; } return high; } int main() { ll n, k; cin >> n >> k; vec a(n); floop(i, 0, n) cin >> a[i]; sort(all(a), greater<ll>()); ll mx = a[0]; cout << bs(a, mx, k) << "\n"; return 0; }
replace
164
165
164
165
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> #define _GLIBCXX_DEBUG using namespace std; using ll = long long; using vec = vector<ll>; using vect = vector<double>; using Graph = vector<vector<ll>>; #define loop(i, n) for (ll i = 0; i < n; i++) #define Loop(i, m, n) for (ll i = m; i < n; i++) #define pool(i, n) for (ll i = n; i >= 0; i--) #define Pool(i, m, n) for (ll i = n; i >= m; i--) #define mod 1000000007ll // #define mod 998244353ll #define flagcount __builtin_popcount #define flag(x) (1ll << x) #define flagadd(bit, x) bit |= flag(x) #define flagpop(bit, x) bit &= ~flag(x) #define flagon(bit, i) bit &flag(i) #define flagoff(bit, i) !(bit & (1ll << i)) #define all(v) v.begin(), v.end() #define low2way(v, x) lower_bound(all(v), x) #define high2way(v, x) upper_bound(all(v), x) #define idx_lower(v, x) \ (distance(v.begin(), low2way(v, x))) // 配列vでx未満の要素数を返す #define idx_upper(v, x) \ (distance(v.begin(), high2way(v, x))) // 配列vでx以下の要素数を返す #define idx_lower2(v, x) \ (v.size() - idx_lower(v, x)) // 配列vでx以上の要素数を返す #define idx_upper2(v, x) \ (v.size() - idx_upper(v, x)) // 配列vでxより大きい要素の数を返す #define putout(a) cout << a << endl #define Sum(v) accumulate(all(v), 0ll) #define gcd(x, y) __gcd(x, y) ll ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return -1; } template <typename T> T lcm(T x, T y) { T z = gcd(x, y); return x * y / z; } template <typename T> bool primejudge(T n) { if (n < 2) return false; else if (n == 2) return true; else if (n % 2 == 0) return false; double sqrtn = sqrt(n); for (T i = 3; i < sqrtn + 1; i++) { if (n % i == 0) { return false; } i++; } return true; } template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; // aをbで更新 return true; } return false; } template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; // aをbで更新 return true; } return false; } // 場合によって使い分ける // const ll dx[4]={1,0,-1,0}; // const ll dy[4]={0,1,0,-1}; const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1}; const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1}; // 2次元配列の宣言 // vector<vector<ll>> field(h, vector<ll>(w)); bool check(ll N, ll K, vector<ll> A, ll X) { ll count = 0; loop(i, N) { count += ((A[i] + X - 1) / X) - 1; } if (count <= K) return true; else return false; } int main() { cout << fixed << setprecision(30); ll N, K; cin >> N >> K; vector<ll> A(N); loop(i, N) cin >> A[i]; ll ok = 2000000010, ng = 0; loop(i, 1000) { ll mid = (ok + ng) / 2; if (check(N, K, A, mid)) ok = mid; else ng = mid; } putout(ok); return 0; }
#include <bits/stdc++.h> #define _GLIBCXX_DEBUG using namespace std; using ll = long long; using vec = vector<ll>; using vect = vector<double>; using Graph = vector<vector<ll>>; #define loop(i, n) for (ll i = 0; i < n; i++) #define Loop(i, m, n) for (ll i = m; i < n; i++) #define pool(i, n) for (ll i = n; i >= 0; i--) #define Pool(i, m, n) for (ll i = n; i >= m; i--) #define mod 1000000007ll // #define mod 998244353ll #define flagcount __builtin_popcount #define flag(x) (1ll << x) #define flagadd(bit, x) bit |= flag(x) #define flagpop(bit, x) bit &= ~flag(x) #define flagon(bit, i) bit &flag(i) #define flagoff(bit, i) !(bit & (1ll << i)) #define all(v) v.begin(), v.end() #define low2way(v, x) lower_bound(all(v), x) #define high2way(v, x) upper_bound(all(v), x) #define idx_lower(v, x) \ (distance(v.begin(), low2way(v, x))) // 配列vでx未満の要素数を返す #define idx_upper(v, x) \ (distance(v.begin(), high2way(v, x))) // 配列vでx以下の要素数を返す #define idx_lower2(v, x) \ (v.size() - idx_lower(v, x)) // 配列vでx以上の要素数を返す #define idx_upper2(v, x) \ (v.size() - idx_upper(v, x)) // 配列vでxより大きい要素の数を返す #define putout(a) cout << a << endl #define Sum(v) accumulate(all(v), 0ll) #define gcd(x, y) __gcd(x, y) ll ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return -1; } template <typename T> T lcm(T x, T y) { T z = gcd(x, y); return x * y / z; } template <typename T> bool primejudge(T n) { if (n < 2) return false; else if (n == 2) return true; else if (n % 2 == 0) return false; double sqrtn = sqrt(n); for (T i = 3; i < sqrtn + 1; i++) { if (n % i == 0) { return false; } i++; } return true; } template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; // aをbで更新 return true; } return false; } template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; // aをbで更新 return true; } return false; } // 場合によって使い分ける // const ll dx[4]={1,0,-1,0}; // const ll dy[4]={0,1,0,-1}; const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1}; const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1}; // 2次元配列の宣言 // vector<vector<ll>> field(h, vector<ll>(w)); bool check(ll N, ll K, vector<ll> A, ll X) { ll count = 0; loop(i, N) { count += ((A[i] + X - 1) / X) - 1; } if (count <= K) return true; else return false; } int main() { cout << fixed << setprecision(30); ll N, K; cin >> N >> K; vector<ll> A(N); loop(i, N) cin >> A[i]; ll ok = 2000000010, ng = 0; loop(i, 1000) { ll mid = (ok + ng + 1) / 2; if (check(N, K, A, mid)) ok = mid; else ng = mid; } putout(ok); return 0; }
replace
96
97
96
98
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> #define INF 2000000000 #define MOD 1000000007 #define MAXN 200005 #define REP(temp, init_val, end_val) \ for (int temp = init_val; temp <= end_val; ++temp) #define REPR(temp, init_val, end_val) \ for (int temp = init_val; temp >= end_val; --temp) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> intpair; int read() { int f = 1, x = 0; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -f; c = getchar(); } while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return f * x; } inline int lowbit(int x) { return x & (-x); } inline int modadd(int x, int y) { return (x + y >= MOD ? x + y - MOD : x + y); } inline int sgn(int x) { return (x < 0 ? -1 : (x > 0 ? 1 : 0)); } template <typename T> T gcd(T a, T b) { return (!b) ? a : gcd(b, a % b); } int poww(int a, int b) { int res = 1; while (b > 0) { if (b & 1) res = 1ll * res * a % MOD; a = 1ll * a * a % MOD, b >>= 1; } return res; } const int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1}; const int ddx[] = {-1, -1, -1, 0, 0, 1, 1, 1}, ddy[] = {-1, 0, 1, -1, 1, -1, 0, 1}; /*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/ int n, k, a[200005]; void init() { n = read(), k = read(); REP(i, 1, n) a[i] = read(); } void solve() { int l = 0, r = 1000000000; while (r > l) { int mid = (l + r) >> 1; ll cnt = 0; REP(i, 1, n) { cnt += (1ll * a[i] - 1) / mid; } if (cnt <= k) r = mid; else l = mid + 1; } printf("%d\n", l); } int main() { init(); solve(); return 0; }
#include <bits/stdc++.h> #define INF 2000000000 #define MOD 1000000007 #define MAXN 200005 #define REP(temp, init_val, end_val) \ for (int temp = init_val; temp <= end_val; ++temp) #define REPR(temp, init_val, end_val) \ for (int temp = init_val; temp >= end_val; --temp) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> intpair; int read() { int f = 1, x = 0; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -f; c = getchar(); } while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return f * x; } inline int lowbit(int x) { return x & (-x); } inline int modadd(int x, int y) { return (x + y >= MOD ? x + y - MOD : x + y); } inline int sgn(int x) { return (x < 0 ? -1 : (x > 0 ? 1 : 0)); } template <typename T> T gcd(T a, T b) { return (!b) ? a : gcd(b, a % b); } int poww(int a, int b) { int res = 1; while (b > 0) { if (b & 1) res = 1ll * res * a % MOD; a = 1ll * a * a % MOD, b >>= 1; } return res; } const int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1}; const int ddx[] = {-1, -1, -1, 0, 0, 1, 1, 1}, ddy[] = {-1, 0, 1, -1, 1, -1, 0, 1}; /*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/ int n, k, a[200005]; void init() { n = read(), k = read(); REP(i, 1, n) a[i] = read(); } void solve() { int l = 1, r = 1000000000; while (r > l) { int mid = (l + r) >> 1; ll cnt = 0; REP(i, 1, n) { cnt += (1ll * a[i] - 1) / mid; } if (cnt <= k) r = mid; else l = mid + 1; } printf("%d\n", l); } int main() { init(); solve(); return 0; }
replace
51
52
51
52
0
p02598
C++
Runtime Error
// Bismillahir Rahmanir Rahim .Ya Allah... #include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<int, int> PII; const int mod = 1e9 + 7, INF = 1e9; const int mx = 2e5 + 5; vector<ll> v(mx); int main() { ios::sync_with_stdio(0); cin.tie(0); ll n, k; cin >> n >> k; for (int i = 0; i < n; i++) cin >> v[i]; ll lb = 0, rb = 1e9 + 7; while (lb < rb) { ll mid = (lb + rb) / 2; ll ans = 0; for (int i = 0; i < n; i++) ans = ans + (v[i] + mid - 1) / mid - 1; if (ans <= k) rb = mid; else lb = mid + 1; } cout << rb << endl; return 0; }
// Bismillahir Rahmanir Rahim .Ya Allah... #include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<int, int> PII; const int mod = 1e9 + 7, INF = 1e9; const int mx = 2e5 + 5; vector<ll> v(mx); int main() { ios::sync_with_stdio(0); cin.tie(0); ll n, k; cin >> n >> k; for (int i = 0; i < n; i++) cin >> v[i]; ll lb = 1, rb = 1e9 + 7; while (lb < rb) { ll mid = (lb + rb) / 2; ll ans = 0; for (int i = 0; i < n; i++) ans = ans + (v[i] + mid - 1) / mid - 1; if (ans <= k) rb = mid; else lb = mid + 1; } cout << rb << endl; return 0; }
replace
15
16
15
16
0
p02598
C++
Time Limit Exceeded
// abc174_e #include <bits/stdc++.h> #ifdef LOCAL #include "../cxx-prettyprint/prettyprint.hpp" #endif using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> P; #define REP(i, n) for (int(i) = 0; (i) < (int)(n); ++(i)) #define REPN(i, m, n) for (int(i) = m; (i) < (int)(n); ++(i)) #define REP_REV(i, n) for (int(i) = (int)(n)-1; (i) >= 0; --(i)) #define REPN_REV(i, m, n) for (int(i) = (int)(n)-1; (i) >= m; --(i)) #define ALL(x) x.begin(), x.end() #define INF (ll)(1e9) #define MOD (1000000007) #define print2D(h, w, arr) \ REP(i, h) { \ REP(j, w) cout << arr[i][j] << " "; \ cout << endl; \ } #define print_line(vec, n) \ { \ for (int idx = 0; idx < (n - 1); idx++) \ cout << (vec)[idx] << " "; \ cout << (vec)[(n)-1] << endl; \ } template <class T> void print(const T &x) { cout << x << endl; } template <class T, class... A> void print(const T &first, const A &...rest) { cout << first << " "; print(rest...); } struct PreMain { PreMain() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); } } premain; int N, K; vector<int> A; bool check(double x) { ll k = 0; REP(i, N) { k += ll(A[i] / x); if (floor(x) == x) { int x_ = int(x); if (A[i] % x_ == 0) { k--; } } } return k <= K; } int main() { #ifdef LOCAL ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf()); #endif cin >> N >> K; A.assign(N, 0); REP(i, N) cin >> A[i]; if (K == 0) { int ans = *max_element(ALL(A)); print(ans); return 0; } double ng = 0; double ok = 1e9 + 1; while (ok - ng > 1e-7) { double mid = (ok + ng) / 2; if (check(mid)) { ok = mid; } else { ng = mid; } } int ans = ceil(ok); if (ok - (ans - 1) < 1e-6) ans--; print(ans); return 0; }
// abc174_e #include <bits/stdc++.h> #ifdef LOCAL #include "../cxx-prettyprint/prettyprint.hpp" #endif using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> P; #define REP(i, n) for (int(i) = 0; (i) < (int)(n); ++(i)) #define REPN(i, m, n) for (int(i) = m; (i) < (int)(n); ++(i)) #define REP_REV(i, n) for (int(i) = (int)(n)-1; (i) >= 0; --(i)) #define REPN_REV(i, m, n) for (int(i) = (int)(n)-1; (i) >= m; --(i)) #define ALL(x) x.begin(), x.end() #define INF (ll)(1e9) #define MOD (1000000007) #define print2D(h, w, arr) \ REP(i, h) { \ REP(j, w) cout << arr[i][j] << " "; \ cout << endl; \ } #define print_line(vec, n) \ { \ for (int idx = 0; idx < (n - 1); idx++) \ cout << (vec)[idx] << " "; \ cout << (vec)[(n)-1] << endl; \ } template <class T> void print(const T &x) { cout << x << endl; } template <class T, class... A> void print(const T &first, const A &...rest) { cout << first << " "; print(rest...); } struct PreMain { PreMain() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); } } premain; int N, K; vector<int> A; bool check(double x) { ll k = 0; REP(i, N) { k += ll(A[i] / x); if (floor(x) == x) { int x_ = int(x); if (A[i] % x_ == 0) { k--; } } } return k <= K; } int main() { #ifdef LOCAL ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf()); #endif cin >> N >> K; A.assign(N, 0); REP(i, N) cin >> A[i]; if (K == 0) { int ans = *max_element(ALL(A)); print(ans); return 0; } double ng = 0; double ok = 1e9 + 1; while (ok - ng > 1e-6) { double mid = (ok + ng) / 2; if (check(mid)) { ok = mid; } else { ng = mid; } } int ans = ceil(ok); if (ok - (ans - 1) < 1e-6) ans--; print(ans); return 0; }
replace
81
82
81
82
TLE
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long lint; typedef long long llint; typedef pair<int, int> pint; typedef pair<long long, long long> pllint; typedef tuple<long long, long long, long long> tllint; // static const int MAX = 1e6; // static const int NIL = -1; // static const llint INF = 1<<21; // static const llint MOD = 1e9 + 7; bool compPair(const pint &arg1, const pint &arg2) { return arg1.first > arg2.first; } bool compTuple(const tllint &arg1, const tllint &arg2) { return get<2>(arg1) > get<2>(arg2); } template <class T> void chmax(T &a, T b) { if (a < b) { a = b; } } template <class T> void chmin(T &a, T b) { if (a > b) { a = b; } } int main(void) { int n, k; cin >> n >> k; vector<int> a(n); int max = 0; for (int in = 0; in < n; in++) { cin >> a[in]; if (max < a[in]) max = a[in]; } int l = 0, r = max, mid, ans = max, ktmp, times; while (l < r) { mid = l + (r - l) / 2; ktmp = 0; for (int in = 0; in < n; in++) { times = a[in] / mid; if (a[in] % mid != 0) times++; times--; ktmp += times; } if (ktmp <= k) { ans = min(ans, mid); r = mid; } else l = mid + 1; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long lint; typedef long long llint; typedef pair<int, int> pint; typedef pair<long long, long long> pllint; typedef tuple<long long, long long, long long> tllint; // static const int MAX = 1e6; // static const int NIL = -1; // static const llint INF = 1<<21; // static const llint MOD = 1e9 + 7; bool compPair(const pint &arg1, const pint &arg2) { return arg1.first > arg2.first; } bool compTuple(const tllint &arg1, const tllint &arg2) { return get<2>(arg1) > get<2>(arg2); } template <class T> void chmax(T &a, T b) { if (a < b) { a = b; } } template <class T> void chmin(T &a, T b) { if (a > b) { a = b; } } int main(void) { int n, k; cin >> n >> k; vector<int> a(n); int max = 0; for (int in = 0; in < n; in++) { cin >> a[in]; if (max < a[in]) max = a[in]; } int l = 1, r = max, mid, ans = max, ktmp, times; while (l < r) { mid = l + (r - l) / 2; ktmp = 0; for (int in = 0; in < n; in++) { times = a[in] / mid; if (a[in] % mid != 0) times++; times--; ktmp += times; } if (ktmp <= k) { ans = min(ans, mid); r = mid; } else l = mid + 1; } cout << ans << endl; return 0; }
replace
43
44
43
44
0
p02598
C++
Runtime Error
// #include<i_am_noob_orz> #include <bits/stdc++.h> using namespace std; #define ll long long #define int ll #define ull unsigned long long #define pii pair<int, int> #define X first #define Y second #define mod ((ll)1e9 + 7) #define pb push_back #define mp make_pair #define abs(x) ((x) > 0 ? (x) : (-(x))) #define F(n) Fi(i, n) #define Fi(i, n) Fl(i, 0, n) #define Fl(i, l, n) for (int i = l; i < n; i++) #define memres(a) memset(a, 0, sizeof(a)) #define all(a) a.begin(), a.end() #define sz(a) ((int)a.size()) #define ceiling(a, b) (((a) + (b)-1) / (b)) #define endl '\n' #define bit_count(x) __builtin_popcount((x)) #define ykh mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // #define LOCAL #ifdef LOCAL #define debug(a) cerr << #a << " " << a << endl; #else #define debug(a) #endif int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int a[200010]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; F(n) cin >> a[i]; int l = 0, r = 1e9; while (l < r) { int mi = ((l + r) / 2); int s = 0; // cout<<l<<" "<<r<<endl; // cout<<mi<<endl; F(n) if (a[i] > mi) s += (ceiling(a[i], mi) - 1); // cout<<s<<" "<<m<<endl; if (s <= m) r = mi; else l = mi + 1; } cout << l << endl; return 0; }
// #include<i_am_noob_orz> #include <bits/stdc++.h> using namespace std; #define ll long long #define int ll #define ull unsigned long long #define pii pair<int, int> #define X first #define Y second #define mod ((ll)1e9 + 7) #define pb push_back #define mp make_pair #define abs(x) ((x) > 0 ? (x) : (-(x))) #define F(n) Fi(i, n) #define Fi(i, n) Fl(i, 0, n) #define Fl(i, l, n) for (int i = l; i < n; i++) #define memres(a) memset(a, 0, sizeof(a)) #define all(a) a.begin(), a.end() #define sz(a) ((int)a.size()) #define ceiling(a, b) (((a) + (b)-1) / (b)) #define endl '\n' #define bit_count(x) __builtin_popcount((x)) #define ykh mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // #define LOCAL #ifdef LOCAL #define debug(a) cerr << #a << " " << a << endl; #else #define debug(a) #endif int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int a[200010]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; F(n) cin >> a[i]; int l = 1, r = 1e9; while (l < r) { int mi = ((l + r) / 2); int s = 0; // cout<<l<<" "<<r<<endl; // cout<<mi<<endl; F(n) if (a[i] > mi) s += (ceiling(a[i], mi) - 1); // cout<<s<<" "<<m<<endl; if (s <= m) r = mi; else l = mi + 1; } cout << l << endl; return 0; }
replace
41
42
41
42
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define M 1000000000 #define f(i, a, b) for (long long i = a; i < b; i++) #define tc \ long long t; \ cin >> t; \ while (t--) #define pb push_back #define mp make_pair #define gcd __gcd #define F first #define S second #define input(a, n) \ for (ll i = 0; i < n; i++) \ cin >> a[i]; #define output(a, n) \ for (ll i = 0; i < n; i++) \ cout << a[i] << " "; #define up upper_bound #define lo lower_bound #define endl "\n" #define mem(a) memset(a, -1, sizeof(a)) #define ll long long #define umap unordered_map ll a[100005]; ll n, k; bool solve(ll x) { ll sum = 0; f(i, 0, n) { sum += (a[i] - 1) / x; } return sum <= k; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif cin >> n >> k; input(a, n); ll l = 1, r = 1e9 + 10, mid; while (l < r) { mid = (l + r) / 2; if (solve(mid)) r = mid; else l = mid + 1; } cout << r; return 0; }
#include <bits/stdc++.h> using namespace std; #define M 1000000000 #define f(i, a, b) for (long long i = a; i < b; i++) #define tc \ long long t; \ cin >> t; \ while (t--) #define pb push_back #define mp make_pair #define gcd __gcd #define F first #define S second #define input(a, n) \ for (ll i = 0; i < n; i++) \ cin >> a[i]; #define output(a, n) \ for (ll i = 0; i < n; i++) \ cout << a[i] << " "; #define up upper_bound #define lo lower_bound #define endl "\n" #define mem(a) memset(a, -1, sizeof(a)) #define ll long long #define umap unordered_map ll a[200010]; ll n, k; bool solve(ll x) { ll sum = 0; f(i, 0, n) { sum += (a[i] - 1) / x; } return sum <= k; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif cin >> n >> k; input(a, n); ll l = 1, r = 1e9 + 10, mid; while (l < r) { mid = (l + r) / 2; if (solve(mid)) r = mid; else l = mid + 1; } cout << r; return 0; }
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; typedef pair<int, int> pii; typedef pair<ll, ll> pll; ll n, k, v[200001], minim = 1e10; bool ok(ll val) { ll x = val; ll nrop = 0; for (int i = 1; i <= n; i++) { ll bc = v[i] / x; if (v[i] % x) bc++; nrop += bc - 1; } return nrop <= k; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> k; for (int i = 1; i <= n; i++) cin >> v[i]; ll st = 0; ll dr = 1e9; while (st <= dr) { ll mij = (st + dr) / 2; if (ok(mij)) { minim = min(mij, minim); dr = mij - 1; } else st = mij + 1; } cout << minim; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; ll n, k, v[200001], minim = 1e10; bool ok(ll val) { ll x = val; ll nrop = 0; for (int i = 1; i <= n; i++) { ll bc = v[i] / x; if (v[i] % x) bc++; nrop += bc - 1; } return nrop <= k; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> k; for (int i = 1; i <= n; i++) cin >> v[i]; ll st = 1; ll dr = 1e9; while (st <= dr) { ll mij = (st + dr) / 2; if (ok(mij)) { minim = min(mij, minim); dr = mij - 1; } else st = mij + 1; } cout << minim; return 0; }
replace
26
27
26
27
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define pi 3.14159265358979 #define mod 1000000007 #define ll long long int #define rep(i, a, b) for (ll i = a; i < b; i++) #define repn(i, a, b) for (ll i = a; i > b; i--) #define mod1 1000003 #define mod2 998244353 #define inf 2e18 #define hi "hello" #define nl "\n" #define ws " " #define sz size() #define len length() #define ff first #define ss second #define pb push_back #define MP make_pair #define B begin() #define RB rbegin() #define E end() #define UB upper_bound #define LB lower_bound #define present(k, m) (m.find(k) != m.end()) ? 1 : 0 #define all(v) v.begin(), v.end() #define reset(a, val) memset(a, val, sizeof(a)) #define pll pair<ll, ll> #define vll vector<ll> #define vpll vector<pll> #define vs vector<string> #define vc vector<char> #define sqr(a) ((a) * (a)) #define print1(a) \ for (auto i : a) \ cout << i << " "; \ cout << "\n" #define print2(a) \ for (auto i : a) \ cout << i; \ cout << "\n" #define print3(a) \ for (auto i : a) \ cout << i << nl; #define boost \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) // ostringstream str1; // str1 << n; // string tmp = str1.str(); bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); } bool compare(const pair<string, int> &a, const pair<string, int> &b) { return a.second < b.second; } double logn(double n, double r) { return (n > r - 1) ? 1 + logn(n / r, r) : 0; } // vll pwx(32); // void cal(ll x){ pwx[0] = 1; rep(i, 1, 32)pwx[i] = x*pwx[i-1]; } /* ################################################################ */ #define space 200005 bool check(vector<ll> &a, ll x, ll k) { ll req = 0; for (ll i = 0; i < a.size(); i++) { if (a[i] > x) req += a[i] / x; } if (req > k) return false; return true; } void solve() { ll n, k; cin >> n >> k; vector<ll> a(n); rep(i, 0, n) cin >> a[i]; ll ans = 0; ll low = 0, high = 1e18, mid; while (low <= high) { mid = (low + high) / 2; // cout << low << ws << mid << ws << high << nl;; if (check(a, mid, k)) { ans = mid; high = mid - 1; } else { low = mid + 1; } } cout << ans << nl; } int main() { // boost; // cal(2); int t = 1, k = 1; // cin>>t; while (t--) { // cout<<"Case #"<<k<<": "; solve(); k++; } }
#include <bits/stdc++.h> using namespace std; #define pi 3.14159265358979 #define mod 1000000007 #define ll long long int #define rep(i, a, b) for (ll i = a; i < b; i++) #define repn(i, a, b) for (ll i = a; i > b; i--) #define mod1 1000003 #define mod2 998244353 #define inf 2e18 #define hi "hello" #define nl "\n" #define ws " " #define sz size() #define len length() #define ff first #define ss second #define pb push_back #define MP make_pair #define B begin() #define RB rbegin() #define E end() #define UB upper_bound #define LB lower_bound #define present(k, m) (m.find(k) != m.end()) ? 1 : 0 #define all(v) v.begin(), v.end() #define reset(a, val) memset(a, val, sizeof(a)) #define pll pair<ll, ll> #define vll vector<ll> #define vpll vector<pll> #define vs vector<string> #define vc vector<char> #define sqr(a) ((a) * (a)) #define print1(a) \ for (auto i : a) \ cout << i << " "; \ cout << "\n" #define print2(a) \ for (auto i : a) \ cout << i; \ cout << "\n" #define print3(a) \ for (auto i : a) \ cout << i << nl; #define boost \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) // ostringstream str1; // str1 << n; // string tmp = str1.str(); bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); } bool compare(const pair<string, int> &a, const pair<string, int> &b) { return a.second < b.second; } double logn(double n, double r) { return (n > r - 1) ? 1 + logn(n / r, r) : 0; } // vll pwx(32); // void cal(ll x){ pwx[0] = 1; rep(i, 1, 32)pwx[i] = x*pwx[i-1]; } /* ################################################################ */ #define space 200005 bool check(vector<ll> &a, ll x, ll k) { ll req = 0; for (ll i = 0; i < a.size(); i++) { if (a[i] > x) req += a[i] / x; } if (req > k) return false; return true; } void solve() { ll n, k; cin >> n >> k; vector<ll> a(n); rep(i, 0, n) cin >> a[i]; ll ans = 0; ll low = 1, high = 1e18, mid; while (low <= high) { mid = (low + high) / 2; // cout << low << ws << mid << ws << high << nl;; if (check(a, mid, k)) { ans = mid; high = mid - 1; } else { low = mid + 1; } } cout << ans << nl; } int main() { // boost; // cal(2); int t = 1, k = 1; // cin>>t; while (t--) { // cout<<"Case #"<<k<<": "; solve(); k++; } }
replace
93
94
93
94
0
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define rep(i, n) REP(i, 0, n) #define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--) #define sz(x) int(x.size()) #define bitsz(x) int(__builtin_popcount(x)) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define pb(x) push_back(x) #define INF 1e9 #define LINF 1e18 #define mod 1000000007 template <class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; } template <typename T> inline string toString(const T &a) { ostringstream oss; oss << a; return oss.str(); }; typedef long long ll; typedef pair<int, int> P; typedef pair<ll, ll> LP; const int di[4] = {1, 0, -1, 0}; const int dj[4] = {0, 1, 0, -1}; int main() { int n; cin >> n; int k; cin >> k; vector<int> a(n); rep(i, n) cin >> a[i]; int lb = -1, ub = INF; auto C = [&](int x) { int num = 0; rep(i, n) { int tmp = a[i] / x; if (a[i] % x == 0) tmp--; num += tmp; } if (num <= k) return true; else return false; }; while (ub - lb > 1) { int mid = (lb + ub) / 2; if (C(mid)) ub = mid; else lb = mid; } cout << ub << endl; }
#include <bits/stdc++.h> using namespace std; #define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define rep(i, n) REP(i, 0, n) #define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--) #define sz(x) int(x.size()) #define bitsz(x) int(__builtin_popcount(x)) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define pb(x) push_back(x) #define INF 1e9 #define LINF 1e18 #define mod 1000000007 template <class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; } template <typename T> inline string toString(const T &a) { ostringstream oss; oss << a; return oss.str(); }; typedef long long ll; typedef pair<int, int> P; typedef pair<ll, ll> LP; const int di[4] = {1, 0, -1, 0}; const int dj[4] = {0, 1, 0, -1}; int main() { int n; cin >> n; int k; cin >> k; vector<int> a(n); rep(i, n) cin >> a[i]; int lb = 0, ub = INF; auto C = [&](int x) { int num = 0; rep(i, n) { int tmp = a[i] / x; if (a[i] % x == 0) tmp--; num += tmp; } if (num <= k) return true; else return false; }; while (ub - lb > 1) { int mid = (lb + ub) / 2; if (C(mid)) ub = mid; else lb = mid; } cout << ub << endl; }
replace
45
46
45
46
0
p02598
C++
Time Limit Exceeded
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < n; i++) #define rep2(i, a, b) for (int i = (a); i < (b); ++i) template <class T> inline void chmin(T &a, T b) { if (a > b) a = b; } template <class T> inline void chmax(T &a, T b) { if (a < b) a = b; } // vector出力 template <class T> ostream &operator<<(ostream &o, const vector<T> &v) { o << "{"; for (int i = 0; i < (int)v.size(); i++) o << (i > 0 ? ", " : "") << v[i]; o << "}" << endl; return o; } // 逆元 a/b の modをとるとき -> a*modinv(b)%mod long long modinv(long long a, long long m = 1e9 + 7) { long long b = m, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } ll const mod = 1e9 + 7; // combination const int MAX = 510000; const ll MOD = 1000000007; long long fac[MAX], finv[MAX], inv[MAX]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } // べき乗 ll modpow(ll x, ll n) { x = x % MOD; if (n == 0) return 1; // 再帰の終了条件 else if (n % 2 == 1) { return (x * modpow(x, n - 1)) % MOD; // nが奇数ならnを1ずらす } else return modpow((x * x) % MOD, n / 2) % MOD; // nが偶数ならnが半分になる } int main() { int N; ll K; cin >> N >> K; vector<ll> A(N); rep(i, N) { cin >> A[i]; } sort(A.begin(), A.end()); ll ok = 1e9 + 1, ng = 0, now; while (ok - ng > 1) { ll cnt = 0; now = (ok + ng) / 2; for (ll i = 1; i < 1e9; i++) { if (upper_bound(A.begin(), A.end(), now * i) == A.end()) break; cnt += i * (upper_bound(A.begin(), A.end(), now * (i + 1)) - upper_bound(A.begin(), A.end(), now * i)); } if (cnt > K) { ng = now; // cout << now << ' ' << cnt << ';' << "ng" << endl; } else { ok = now; // cout << now << ' ' << cnt << ';' << "ok" << endl; } } cout << ok << endl; }
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < n; i++) #define rep2(i, a, b) for (int i = (a); i < (b); ++i) template <class T> inline void chmin(T &a, T b) { if (a > b) a = b; } template <class T> inline void chmax(T &a, T b) { if (a < b) a = b; } // vector出力 template <class T> ostream &operator<<(ostream &o, const vector<T> &v) { o << "{"; for (int i = 0; i < (int)v.size(); i++) o << (i > 0 ? ", " : "") << v[i]; o << "}" << endl; return o; } // 逆元 a/b の modをとるとき -> a*modinv(b)%mod long long modinv(long long a, long long m = 1e9 + 7) { long long b = m, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } ll const mod = 1e9 + 7; // combination const int MAX = 510000; const ll MOD = 1000000007; long long fac[MAX], finv[MAX], inv[MAX]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } // べき乗 ll modpow(ll x, ll n) { x = x % MOD; if (n == 0) return 1; // 再帰の終了条件 else if (n % 2 == 1) { return (x * modpow(x, n - 1)) % MOD; // nが奇数ならnを1ずらす } else return modpow((x * x) % MOD, n / 2) % MOD; // nが偶数ならnが半分になる } int main() { int N; ll K; cin >> N >> K; vector<ll> A(N); rep(i, N) { cin >> A[i]; } sort(A.begin(), A.end()); ll ok = 1e9 + 1, ng = 0, now; while (ok - ng > 1) { ll cnt = 0; now = (ok + ng) / 2; // for (ll i=1;i<1e9;i++) { // if (upper_bound(A.begin(),A.end(),now*i)==A.end()) break; // cnt += i*(upper_bound(A.begin(),A.end(),now*(i+1)) - // upper_bound(A.begin(),A.end(),now*i)); // } rep(i, N) cnt += (A[i] - 1) / now; if (cnt > K) { ng = now; // cout << now << ' ' << cnt << ';' << "ng" << endl; } else { ok = now; // cout << now << ' ' << cnt << ';' << "ok" << endl; } } cout << ok << endl; }
replace
89
95
89
96
TLE
p02598
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<int> a(n); int l = 0; // int r = -1; int r = 1000000000; for (int i = 0; i < n; i++) { cin >> a[i]; // r = max(a[i],r); } while (l < r) { int m = l + (r - l) / 2; int cnt = 0; for (int i = 0; i < n; i++) { cnt += (a[i] - 1) / m; } if (cnt > k) l = m + 1; else r = m; // cout << l << " " << r << endl; } cout << r << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<int> a(n); int l = 1; // int r = -1; int r = 1000000000; for (int i = 0; i < n; i++) { cin >> a[i]; // r = max(a[i],r); } while (l < r) { int m = l + (r - l) / 2; int cnt = 0; for (int i = 0; i < n; i++) { cnt += (a[i] - 1) / m; } if (cnt > k) l = m + 1; else r = m; // cout << l << " " << r << endl; } cout << r << endl; }
replace
7
8
7
8
0
p02598
C++
Runtime Error
/* Dont BLUNDER */ #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 d long double #define int long long #define pii pair<int, int> #define pb push_back #define endl '\n' #define pi acos(-1) #define init(x, a) memset(x, a, sizeof(x)) #define all(c) c.begin(), c.end() int const mod1 = 998244353; int const mod = 1000000007; #define l first #define r second int toint(const string &s) { stringstream ss; ss << s; int x; ss >> x; return x; } string tostring(int number) { stringstream ss; ss << number; return ss.str(); } #define out(x) \ cout << #x << " = " \ << " " << x << "\n"; #define trace1(x) cerr << #x << ": " << x << endl #define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl #define trace3(x, y, z) \ cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl #define haha \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); // * Using PBDS * /*typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> os; */ int modexp(int x, int n) { if (n == 0) { return 1; } else if (n & 1) { return (modexp((x * x) % mod, n / 2) % mod * x % mod) % mod; } else { return (modexp((x * x) % mod, n / 2) % mod); } } int modinv(int n) { return modexp(n, mod - 2); } int gcd(int a, int b) { if (b == 0) { return a; } return gcd(b, a % b); } int n, k; int arr[200001]; bool con(int x) { // cout << x << " "; int s = 0; for (int i = 0; i < n; i++) { int v = arr[i]; if (v % x != 0) s += v / x; else s += max(0ll, (v / x) - 1); } // cout << s << endl; if (s <= k) return true; return false; } signed main() { haha #ifndef ONLINE_JUDGE freopen("inp.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif cin >> n >> k; for (int i = 0; i < n; i++) { cin >> arr[i]; } int l = 0; int r = 1e10; while (l + 1 < r) { int m = (l + r) / 2; // cout << m << endl; if (con(m)) { r = m; } else l = m + 1; } if (con(l)) cout << l; else cout << r; }
/* Dont BLUNDER */ #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 d long double #define int long long #define pii pair<int, int> #define pb push_back #define endl '\n' #define pi acos(-1) #define init(x, a) memset(x, a, sizeof(x)) #define all(c) c.begin(), c.end() int const mod1 = 998244353; int const mod = 1000000007; #define l first #define r second int toint(const string &s) { stringstream ss; ss << s; int x; ss >> x; return x; } string tostring(int number) { stringstream ss; ss << number; return ss.str(); } #define out(x) \ cout << #x << " = " \ << " " << x << "\n"; #define trace1(x) cerr << #x << ": " << x << endl #define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl #define trace3(x, y, z) \ cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl #define haha \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); // * Using PBDS * /*typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> os; */ int modexp(int x, int n) { if (n == 0) { return 1; } else if (n & 1) { return (modexp((x * x) % mod, n / 2) % mod * x % mod) % mod; } else { return (modexp((x * x) % mod, n / 2) % mod); } } int modinv(int n) { return modexp(n, mod - 2); } int gcd(int a, int b) { if (b == 0) { return a; } return gcd(b, a % b); } int n, k; int arr[200001]; bool con(int x) { // cout << x << " "; int s = 0; for (int i = 0; i < n; i++) { int v = arr[i]; if (v % x != 0) s += v / x; else s += max(0ll, (v / x) - 1); } // cout << s << endl; if (s <= k) return true; return false; } signed main() { haha #ifndef ONLINE_JUDGE freopen("inp.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif cin >> n >> k; for (int i = 0; i < n; i++) { cin >> arr[i]; } int l = 1; int r = 1e10; while (l + 1 < r) { int m = (l + r) / 2; // cout << m << endl; if (con(m)) { r = m; } else l = m + 1; } if (con(l)) cout << l; else cout << r; }
replace
103
104
103
104
0
p02598
C++
Runtime Error
/* :: :: ': : :. : ;' :: :: ' .' '; ;' '. :: :; ;: :: ; :;. ,;: :: :; :;: ,;" :: ::. ':; ..,.; ;:' ,.;: "'"... '::,::::: ;: .;.;""' '"""....;:::::;,;.;""" .:::.....'"':::::::'",...;::::;. ;:' '""'"";.,;:::::;.'"""""" ':; ::' ;::;:::;::.. :; :: ,;:::::::::::;:.. :: ;' ,;;:;::::::::::::::;";.. ':. :: ;:" ::::::"""':::::: ": :: :. :: ::::::; ::::::: : ; ; :: ::::::: ::::::: : ; ' :: ::::::....:::::' ,: ' ' :: :::::::::::::" :: :: ':::::::::"' :: ': """""""' :: :: ;: ':; ;:" P_r_A_d_Y */ #include <bits/stdc++.h> using namespace std; #define int long long int #define endl "\n" #define mod 1000000007 #define inf 1e18 const int N = 300005; #define fastIO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); void cs(int &x) { cout << "Case #" << x << ": "; } bool cmp(int a, int b) { return a > b; } int32_t main() { fastIO; // int t;cin>>t; // int x=1; // while(t--) // { int n, k; cin >> n >> k; vector<int> v(n); for (int i = 0; i < n; i++) cin >> v[i]; int l = 0, h = *max_element(v.begin(), v.end()); while (l < h) { int mid = l + (h - l) / 2; int p = 0; for (auto i : v) p += (i - 1) / mid; if (p <= k) h = mid; else l = mid + 1; } cout << l << endl; //} return 0; }
/* :: :: ': : :. : ;' :: :: ' .' '; ;' '. :: :; ;: :: ; :;. ,;: :: :; :;: ,;" :: ::. ':; ..,.; ;:' ,.;: "'"... '::,::::: ;: .;.;""' '"""....;:::::;,;.;""" .:::.....'"':::::::'",...;::::;. ;:' '""'"";.,;:::::;.'"""""" ':; ::' ;::;:::;::.. :; :: ,;:::::::::::;:.. :: ;' ,;;:;::::::::::::::;";.. ':. :: ;:" ::::::"""':::::: ": :: :. :: ::::::; ::::::: : ; ; :: ::::::: ::::::: : ; ' :: ::::::....:::::' ,: ' ' :: :::::::::::::" :: :: ':::::::::"' :: ': """""""' :: :: ;: ':; ;:" P_r_A_d_Y */ #include <bits/stdc++.h> using namespace std; #define int long long int #define endl "\n" #define mod 1000000007 #define inf 1e18 const int N = 300005; #define fastIO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); void cs(int &x) { cout << "Case #" << x << ": "; } bool cmp(int a, int b) { return a > b; } int32_t main() { fastIO; // int t;cin>>t; // int x=1; // while(t--) // { int n, k; cin >> n >> k; vector<int> v(n); for (int i = 0; i < n; i++) cin >> v[i]; int l = 1, h = *max_element(v.begin(), v.end()); while (l < h) { int mid = l + (h - l) / 2; int p = 0; for (auto i : v) p += (i - 1) / mid; if (p <= k) h = mid; else l = mid + 1; } cout << l << endl; //} return 0; }
replace
53
54
53
54
0