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++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <vector>
#define SPBR(w, n) std::cout << (w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define RFOR(i, a, n) for (int i = (n)-1; i >= (a); --i)
#define REP(i, n) for (int i = 0; i < int(n); ++i)
#define RREP(i, n) for (int i = int(n) - 1; i >= 0; --i)
#define IN(a, x, b) (a <= x && x < b)
#define OUT(a, x, b) (x < a || b <= x)
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);
using namespace std;
struct INIT {
INIT() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
}
} INIT;
signed main() {
int N, K;
cin >> N >> K;
int MAX = 0;
vector<int> A(N);
REP(i, N) {
cin >> A[i];
chmax(MAX, A[i]);
}
auto check = [&](int x) {
int cnt = 0;
REP(i, N) {
int ok = A[i];
int ng = 0;
while (abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if ((A[i] + mid - 1) / mid <= x)
ok = mid;
else
ng = mid;
}
cnt += ok - 1;
}
return (cnt <= K);
};
int ok = MAX;
int ng = 0;
while (abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
(check(mid) ? ok : ng) = mid;
}
cout << ok << "\n";
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <vector>
#define SPBR(w, n) std::cout << (w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define RFOR(i, a, n) for (int i = (n)-1; i >= (a); --i)
#define REP(i, n) for (int i = 0; i < int(n); ++i)
#define RREP(i, n) for (int i = int(n) - 1; i >= 0; --i)
#define IN(a, x, b) (a <= x && x < b)
#define OUT(a, x, b) (x < a || b <= x)
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);
using namespace std;
struct INIT {
INIT() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
}
} INIT;
signed main() {
int N, K;
cin >> N >> K;
int MAX = 0;
vector<int> A(N);
REP(i, N) {
cin >> A[i];
chmax(MAX, A[i]);
}
auto check = [&](int x) {
int cnt = 0;
REP(i, N) { cnt += (A[i] + x - 1) / x - 1; }
return (cnt <= K);
};
int ok = MAX;
int ng = 0;
while (abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
(check(mid) ? ok : ng) = mid;
}
cout << ok << "\n";
return 0;
}
| replace | 74 | 87 | 74 | 75 | TLE | |
p02598 | C++ | Runtime Error | #include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5 + 10;
int n, k, a[N];
int check(int x) {
int ans = 0;
for (int i = 1; i <= n; i++)
ans += (a[i] + x - 1) / x - 1;
return ans <= k;
}
signed main() {
scanf("%lld%lld", &n, &k);
for (int i = 1; i <= n; i++)
scanf("%lld", &a[i]);
int l = 0, r = 2e9;
while (l < r) {
int mid = (l + r) >> 1;
if (check(mid))
r = mid;
else
l = mid + 1;
}
cout << l << endl;
return 0;
} | #include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5 + 10;
int n, k, a[N];
int check(int x) {
int ans = 0;
for (int i = 1; i <= n; i++)
ans += (a[i] + x - 1) / x - 1;
return ans <= k;
}
signed main() {
scanf("%lld%lld", &n, &k);
for (int i = 1; i <= n; i++)
scanf("%lld", &a[i]);
int l = 1, r = 2e9;
while (l < r) {
int mid = (l + r) >> 1;
if (check(mid))
r = mid;
else
l = mid + 1;
}
cout << l << endl;
return 0;
} | replace | 15 | 16 | 15 | 16 | 0 | |
p02598 | C++ | Runtime Error | #include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream &operator<<(ostream &out, const pair<A, B> &a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream &operator<<(ostream &out, const array<T, N> &a) {
out << "[";
bool first = true;
for (auto &v : a) {
out << (first ? "" : ", ");
out << v;
first = 0;
}
out << "]";
return out;
}
template <typename T> ostream &operator<<(ostream &out, const vector<T> &a) {
out << "[";
bool first = true;
for (auto &v : a) {
out << (first ? "" : ", ");
out << v;
first = 0;
}
out << "]";
return out;
}
template <typename T, class Cmp>
ostream &operator<<(ostream &out, const set<T, Cmp> &a) {
out << "{";
bool first = true;
for (auto &v : a) {
out << (first ? "" : ", ");
out << v;
first = 0;
}
out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream &operator<<(ostream &out, const map<U, T, Cmp> &a) {
out << "{";
bool first = true;
for (auto &p : a) {
out << (first ? "" : ", ");
out << p.first << ":" << p.second;
first = 0;
}
out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << ": " << arg1 << 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...);
}
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
#define int long long
using P = pair<int, int>;
// #########################################
signed main() {
int n, k;
cin >> n >> k;
vector<int> a(n);
rep(i, n) cin >> a[i];
auto ok = [&](int x) {
// 最大値xをk階以内でできるか
int ret = 0;
rep(i, n) {
if (a[i] > x) {
ret += a[i] / x;
}
}
return ret <= k;
};
int bot = 0, top = 1e9;
rep(i, 500) {
double mid = (top + bot) / 2;
if (ok(mid)) {
top = mid;
} else
bot = mid;
}
cout << top << endl;
return 0;
} | #include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream &operator<<(ostream &out, const pair<A, B> &a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream &operator<<(ostream &out, const array<T, N> &a) {
out << "[";
bool first = true;
for (auto &v : a) {
out << (first ? "" : ", ");
out << v;
first = 0;
}
out << "]";
return out;
}
template <typename T> ostream &operator<<(ostream &out, const vector<T> &a) {
out << "[";
bool first = true;
for (auto &v : a) {
out << (first ? "" : ", ");
out << v;
first = 0;
}
out << "]";
return out;
}
template <typename T, class Cmp>
ostream &operator<<(ostream &out, const set<T, Cmp> &a) {
out << "{";
bool first = true;
for (auto &v : a) {
out << (first ? "" : ", ");
out << v;
first = 0;
}
out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream &operator<<(ostream &out, const map<U, T, Cmp> &a) {
out << "{";
bool first = true;
for (auto &p : a) {
out << (first ? "" : ", ");
out << p.first << ":" << p.second;
first = 0;
}
out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << ": " << arg1 << 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...);
}
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
#define int long long
using P = pair<int, int>;
// #########################################
signed main() {
int n, k;
cin >> n >> k;
vector<int> a(n);
rep(i, n) cin >> a[i];
auto ok = [&](int x) {
// 最大値xをk階以内でできるか
int ret = 0;
rep(i, n) {
if (a[i] > x) {
ret += a[i] / x;
}
}
return ret <= k;
};
int bot = 0, top = 1e9;
while (top - bot > 1) {
int mid = (top + bot) / 2;
if (ok(mid)) {
top = mid;
} else
bot = mid;
}
cout << top << endl;
return 0;
} | replace | 91 | 93 | 91 | 93 | 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 ll long long
#define uint unsigned int
#define ull unsigned long long
#define pb push_back
#define mk make_pair
#define ins insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define X first
#define Y second
#define umap unordered_map
#define speed() \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define setvalue(d, s, e, n) \
for (int qwe = s; qwe < e; ++qwe) \
d[qwe] = n
#define mset multiset
#define pqueue priority_queue
template <class T>
using oset =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int N = 2e5 + 314;
const int INF = 1e9;
const double PI = acos(-1);
const int MOD = 1e9 + 7;
const double eps = 1e-9;
const long long LINF = 1e18 + 3141;
ll a[N];
ll n, k;
ll get(ll a, ll nd) {
if (a == nd)
return 0;
return a / nd;
}
void solve() {
cin >> n >> k;
ll f = -1;
for (int i = 1; i <= n; ++i)
cin >> a[i], f = max(f, a[i]);
ll l = 0, r = INF;
while (l <= r) {
ll md = l + r >> 1;
ll t = 0;
for (int i = 1; i <= n; ++i) {
t += get(a[i], md);
}
if (t <= k) {
r = md - 1;
f = md;
} else {
l = md + 1;
}
}
cout << f << '\n';
}
int main() {
speed();
int t = 1;
// cin >> t;
while (t--)
solve();
} | #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 ll long long
#define uint unsigned int
#define ull unsigned long long
#define pb push_back
#define mk make_pair
#define ins insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define X first
#define Y second
#define umap unordered_map
#define speed() \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define setvalue(d, s, e, n) \
for (int qwe = s; qwe < e; ++qwe) \
d[qwe] = n
#define mset multiset
#define pqueue priority_queue
template <class T>
using oset =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int N = 2e5 + 314;
const int INF = 1e9;
const double PI = acos(-1);
const int MOD = 1e9 + 7;
const double eps = 1e-9;
const long long LINF = 1e18 + 3141;
ll a[N];
ll n, k;
ll get(ll a, ll nd) {
if (a == nd)
return 0;
return a / nd;
}
void solve() {
cin >> n >> k;
ll f = -1;
for (int i = 1; i <= n; ++i)
cin >> a[i], f = max(f, a[i]);
ll l = 1, r = INF;
while (l <= r) {
ll md = l + r >> 1;
ll t = 0;
for (int i = 1; i <= n; ++i) {
t += get(a[i], md);
}
if (t <= k) {
r = md - 1;
f = md;
} else {
l = md + 1;
}
}
cout << f << '\n';
}
int main() {
speed();
int t = 1;
// cin >> t;
while (t--)
solve();
} | replace | 51 | 52 | 51 | 52 | 0 | |
p02598 | C++ | Runtime Error |
#include <bits/stdc++.h>
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
using namespace std;
#define M 1000000001
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define repb(i, a, b) for (int i = a; i >= b; --i)
#define repv(arr) for (auto it = arr[i].begin(); it != arr[i].end(); ++it)
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define vl vector<long long int>
#define vc vector<char>
#define sz(a) (int)a.size()
#define ssortA(arr) stable_sort(arr.begin(), arr.end())
#define ssortB(arr) stable_sort(arr.begin(), arr.end(), greater<int>());
#define pii pair<int, int>
#define pli pair<long long, int>
#define pll pair<long long, long long>
#define fi first
#define se second
#define search(arr, c) binary_search(arr.begin(), arr.end(), c)
#define pb push_back
#define ll long long
#define mp make_pair
#define endl "\n"
#define LCM(a, b) boost::math::lcm(a, b)
#define cl_bf cin.ignore(numeric_limits<streamsize>::max(), '\n');
#define check(ds, x) (int)(ds.find(x) != ds.end() ? 1 : 0)
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll n, k;
cin >> n >> k;
vl arr(n);
rep(i, 0, n) { cin >> arr[i]; }
ll high = M;
ll low = 0, mark = M;
ll mid;
while (high >= low) {
mid = (high + low) / 2;
// if(high<=13)
// cout<<low<<" "<<high<<endl;
int flag = 0;
ll count = 0;
rep(i, 0, n) {
if (arr[i] <= mid) {
continue;
}
if (arr[i] % mid == 0) {
count += arr[i] / mid - 1;
} else {
ll x = ceil((double(arr[i])) / mid) - 1;
/*if(mid==3){
cout<<x<<" ";
}*/
count += x;
}
}
/*if(mid==3){
cout<<count<<endl;
}*/
if (count <= k) {
mark = mid;
high = mid - 1;
} else {
low = mid + 1;
}
}
cout << mark << endl;
}
|
#include <bits/stdc++.h>
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
using namespace std;
#define M 1000000001
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define repb(i, a, b) for (int i = a; i >= b; --i)
#define repv(arr) for (auto it = arr[i].begin(); it != arr[i].end(); ++it)
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define vl vector<long long int>
#define vc vector<char>
#define sz(a) (int)a.size()
#define ssortA(arr) stable_sort(arr.begin(), arr.end())
#define ssortB(arr) stable_sort(arr.begin(), arr.end(), greater<int>());
#define pii pair<int, int>
#define pli pair<long long, int>
#define pll pair<long long, long long>
#define fi first
#define se second
#define search(arr, c) binary_search(arr.begin(), arr.end(), c)
#define pb push_back
#define ll long long
#define mp make_pair
#define endl "\n"
#define LCM(a, b) boost::math::lcm(a, b)
#define cl_bf cin.ignore(numeric_limits<streamsize>::max(), '\n');
#define check(ds, x) (int)(ds.find(x) != ds.end() ? 1 : 0)
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll n, k;
cin >> n >> k;
vl arr(n);
rep(i, 0, n) { cin >> arr[i]; }
ll high = M;
ll low = 1, mark = M;
ll mid;
while (high >= low) {
mid = (high + low) / 2;
// if(high<=13)
// cout<<low<<" "<<high<<endl;
int flag = 0;
ll count = 0;
rep(i, 0, n) {
if (arr[i] <= mid) {
continue;
}
if (arr[i] % mid == 0) {
count += arr[i] / mid - 1;
} else {
ll x = ceil((double(arr[i])) / mid) - 1;
/*if(mid==3){
cout<<x<<" ";
}*/
count += x;
}
}
/*if(mid==3){
cout<<count<<endl;
}*/
if (count <= k) {
mark = mid;
high = mid - 1;
} else {
low = mid + 1;
}
}
cout << mark << endl;
}
| replace | 41 | 42 | 41 | 42 | 0 | |
p02598 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define ff first
#define ss second
using namespace std;
using pii = pair<int, int>;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll n, k;
cin >> n >> k;
vector<ll> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
ll maxa = *max_element(a.begin(), a.end());
ll lo = 0, hi = maxa + 1;
while (lo < hi) {
ll mid = (lo + hi) / 2;
ll m = maxa - mid;
ll cnt = 0;
for (int i = 0; i < n; i++) {
cnt += a[i] / m;
if (a[i] % m == 0)
cnt -= 1;
}
if (cnt <= k)
lo = mid + 1;
else
hi = mid;
}
cout << maxa - lo + 1;
return 0;
}
| #include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define ff first
#define ss second
using namespace std;
using pii = pair<int, int>;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll n, k;
cin >> n >> k;
vector<ll> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
ll maxa = *max_element(a.begin(), a.end());
ll lo = 0, hi = maxa;
while (lo < hi) {
ll mid = (lo + hi) / 2;
ll m = maxa - mid;
ll cnt = 0;
for (int i = 0; i < n; i++) {
cnt += a[i] / m;
if (a[i] % m == 0)
cnt -= 1;
}
if (cnt <= k)
lo = mid + 1;
else
hi = mid;
}
cout << maxa - lo + 1;
return 0;
}
| replace | 34 | 35 | 34 | 35 | 0 | |
p02598 | C++ | Runtime Error | // Created by ...
#include <bits/stdc++.h>
#define db1(x) cout << #x << "=" << x << '\n'
#define db2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << '\n'
#define db3(x, y, z) \
cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \
<< '\n'
#define vll vector<ll>
#define M 100000
#define MD 1000000007
#define pb push_back
#define rep(i, a, b) for (ll i = a; i <= b; ++i)
#define fo(i, a, b) for (int i = a; i <= b; ++i)
#define pii pair<ll, ll>
#define vec(a) vector<a>
#define all(a) a.begin(), a.end()
#define se second
#define fi first
#define inf 0xffffffff
#define inchar getchar_unlocked
#define outchar(x) putchar_unlocked(x)
#define int long long
#define endl '\n'
#define IOS \
ios::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
using namespace std;
using ll = long long;
ll md = MD;
ll exp(ll a, ll b) {
ll r = 1ll;
while (b > 0) {
if (b & 1) {
r = r * (a % md);
r = (r + md) % md;
}
b >>= 1;
a = (a % md) * (a % md);
a = (a + md) % md;
}
return (r + md) % md;
}
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll Min(ll a, ll b) {
if (a < b)
return a;
return b;
}
ll Max(ll a, ll b) {
if (a > b)
return a;
return b;
}
bool check(int x, int k, vll &v) {
int ans = 0;
for (auto &z : v)
ans += ((z - 1) / x);
return ans <= k;
}
int32_t main() {
IOS;
ll n, k;
cin >> n >> k;
vll v(n);
rep(i, 0, n - 1) cin >> v[i];
int low = 0, high = 2e9, mid, ans = -1;
while (low <= high) {
mid = (low + high) / 2;
if (check(mid, k, v)) {
ans = mid;
high = mid - 1;
} else
low = mid + 1;
}
cout << ans;
cout << '\n';
return 0;
} | // Created by ...
#include <bits/stdc++.h>
#define db1(x) cout << #x << "=" << x << '\n'
#define db2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << '\n'
#define db3(x, y, z) \
cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \
<< '\n'
#define vll vector<ll>
#define M 100000
#define MD 1000000007
#define pb push_back
#define rep(i, a, b) for (ll i = a; i <= b; ++i)
#define fo(i, a, b) for (int i = a; i <= b; ++i)
#define pii pair<ll, ll>
#define vec(a) vector<a>
#define all(a) a.begin(), a.end()
#define se second
#define fi first
#define inf 0xffffffff
#define inchar getchar_unlocked
#define outchar(x) putchar_unlocked(x)
#define int long long
#define endl '\n'
#define IOS \
ios::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
using namespace std;
using ll = long long;
ll md = MD;
ll exp(ll a, ll b) {
ll r = 1ll;
while (b > 0) {
if (b & 1) {
r = r * (a % md);
r = (r + md) % md;
}
b >>= 1;
a = (a % md) * (a % md);
a = (a + md) % md;
}
return (r + md) % md;
}
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll Min(ll a, ll b) {
if (a < b)
return a;
return b;
}
ll Max(ll a, ll b) {
if (a > b)
return a;
return b;
}
bool check(int x, int k, vll &v) {
int ans = 0;
for (auto &z : v)
ans += ((z - 1) / x);
return ans <= k;
}
int32_t main() {
IOS;
ll n, k;
cin >> n >> k;
vll v(n);
rep(i, 0, n - 1) cin >> v[i];
int low = 1, high = 2e9, mid, ans = -1;
while (low <= high) {
mid = (low + high) / 2;
if (check(mid, k, v)) {
ans = mid;
high = mid - 1;
} else
low = mid + 1;
}
cout << ans;
cout << '\n';
return 0;
} | replace | 76 | 77 | 76 | 77 | 0 | |
p02598 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int mod = (1 ? 1e9 + 7 : 998244353);
const int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
ll a, b, c, d, e, f, n, T;
double z[200005];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> a >> b;
double maxx = 0;
for (int i = 0; i < a; i++)
cin >> z[i], maxx = max(maxx, z[i]);
double minn = 0;
double mid;
while (maxx - minn > 1e-7) {
mid = (maxx + minn) / 2;
c = 0;
for (int i = 0; i < a; i++)
c += ceil(z[i] / mid - 1);
if (c > b)
minn = mid;
else
maxx = mid;
}
cout << (ll)ceil(maxx) << endl;
}
| #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int mod = (1 ? 1e9 + 7 : 998244353);
const int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
ll a, b, c, d, e, f, n, T;
double z[200005];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> a >> b;
double maxx = 0;
for (int i = 0; i < a; i++)
cin >> z[i], maxx = max(maxx, z[i]);
double minn = 0;
double mid;
while (maxx - minn > 1e-6) {
mid = (maxx + minn) / 2;
c = 0;
for (int i = 0; i < a; i++)
c += ceil(z[i] / mid - 1);
if (c > b)
minn = mid;
else
maxx = mid;
}
cout << (ll)ceil(maxx) << endl;
}
| replace | 23 | 24 | 23 | 24 | TLE | |
p02598 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<ll> a;
ll n, k;
bool ok(ll x) {
ll res = 0;
for (ll i = 0; i < n; i++)
if (a[i] > x) {
res += a[i] / x;
if (a[i] % x == 0)
res--;
}
return res <= k;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> k;
a.resize(n);
for (ll i = 0; i < n; i++)
cin >> a[i];
ll x = 0;
for (ll b = 300000; b; b /= 2)
while (!ok(x + b))
x += b;
cout << x + 1 << '\n';
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<ll> a;
ll n, k;
bool ok(ll x) {
ll res = 0;
for (ll i = 0; i < n; i++)
if (a[i] > x) {
res += a[i] / x;
if (a[i] % x == 0)
res--;
}
return res <= k;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> k;
a.resize(n);
for (ll i = 0; i < n; i++)
cin >> a[i];
ll x = 0;
for (ll b = 2000000000; b; b /= 2)
while (!ok(x + b))
x += b;
cout << x + 1 << '\n';
}
| replace | 27 | 28 | 27 | 28 | TLE | |
p02598 | C++ | Runtime Error | #include <cstring>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
int n, k;
cin >> n >> k;
vector<int> a(n);
int hmax = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] > hmax)
hmax = a[i];
}
int l = 0, h = hmax;
while (l != h && h != 0) {
int m = l + (h - l) / 2;
ll cnt = 0;
for (int i = 0; i < n; i++) {
if (a[i] % m == 0) {
cnt += (a[i] / m - 1);
} else {
cnt += a[i] / m;
}
}
if (cnt <= k) {
h = m;
} else {
l = m + 1;
}
}
cout << l;
return 0;
} | #include <cstring>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
int n, k;
cin >> n >> k;
vector<int> a(n);
int hmax = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] > hmax)
hmax = a[i];
}
int l = 1, h = hmax;
while (l != h) {
int m = l + (h - l) / 2;
ll cnt = 0;
for (int i = 0; i < n; i++) {
if (a[i] % m == 0) {
cnt += (a[i] / m - 1);
} else {
cnt += a[i] / m;
}
}
if (cnt <= k) {
h = m;
} else {
l = m + 1;
}
}
cout << l;
return 0;
} | replace | 15 | 17 | 15 | 17 | 0 | |
p02598 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
int main() {
int n, k;
cin >> n >> k;
int a[n], ng = -1, ok = 1e9 + 1, mid, tk;
for (int i = 0; i < n; i++)
cin >> a[i];
while (ok - ng > 1) {
mid = ng + (ok - ng) / 2;
tk = 0;
for (int i = 0; i < n; i++)
tk += max(0, a[i] / mid - (a[i] % mid == 0 ? 1 : 0));
(tk <= k ? ok : ng) = mid;
}
cout << ok << endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
int main() {
int n, k;
cin >> n >> k;
int a[n], ng = 0, ok = 1e9 + 1, mid, tk;
for (int i = 0; i < n; i++)
cin >> a[i];
while (ok - ng > 1) {
mid = ng + (ok - ng) / 2;
tk = 0;
for (int i = 0; i < n; i++)
tk += max(0, a[i] / mid - (a[i] % mid == 0 ? 1 : 0));
(tk <= k ? ok : ng) = mid;
}
cout << ok << endl;
}
| replace | 7 | 8 | 7 | 8 | 0 | |
p02598 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define repr1(i, n) for (int i = n; i >= 1; i--)
#define all(v) v.begin(), v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1);
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 main() {
int n;
cin >> n;
ll k;
cin >> k;
vector<ll> a(n);
rep(i, n) cin >> a[i];
if (k == 0) {
ll m = -1;
rep(i, n) chmax(m, a[i]);
cout << m << endl;
return 0;
}
ll ng = -1, ok = 2e18;
while (ok - ng > 1) {
ll mid = (ok + ng) / 2;
ll sum = 0;
rep(i, n) {
if (a[i] <= mid)
continue;
sum += a[i] / mid;
}
if (sum > k)
ng = mid; // 短く切りすぎ
else
ok = mid;
}
cout << ok << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define repr1(i, n) for (int i = n; i >= 1; i--)
#define all(v) v.begin(), v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1);
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 main() {
int n;
cin >> n;
ll k;
cin >> k;
vector<ll> a(n);
rep(i, n) cin >> a[i];
if (k == 0) {
ll m = -1;
rep(i, n) chmax(m, a[i]);
cout << m << endl;
return 0;
}
ll ng = 0, ok = 2e18;
while (ok - ng > 1) {
ll mid = (ok + ng) / 2;
ll sum = 0;
rep(i, n) {
if (a[i] <= mid)
continue;
sum += a[i] / mid;
}
if (sum > k)
ng = mid; // 短く切りすぎ
else
ok = mid;
}
cout << ok << endl;
}
| replace | 47 | 48 | 47 | 48 | 0 | |
p02598 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;
#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i, k, N) for (int i = k; i < N; i++)
#define MP make_pair
#define MT make_tuple // tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(), (x).end()
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
struct wood {
double L;
ll N;
double M;
bool operator<(const wood &a) const { return L < a.L; }
};
int main() {
ll N, K;
cin >> N >> K;
v A(N);
rep(i, 0, N) cin >> A[i];
ll l = 0;
ll r = 1000000000;
while (l != r) {
ll sum = 0;
ll now = (l + r) / 2;
rep(i, 0, N) { sum += ((A[i] - 1) / now); }
if (sum > K) {
l = now + 1;
} else {
r = now;
}
}
cout << r;
return 0;
} | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;
#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i, k, N) for (int i = k; i < N; i++)
#define MP make_pair
#define MT make_tuple // tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(), (x).end()
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
struct wood {
double L;
ll N;
double M;
bool operator<(const wood &a) const { return L < a.L; }
};
int main() {
ll N, K;
cin >> N >> K;
v A(N);
rep(i, 0, N) cin >> A[i];
ll l = 0;
ll r = 1000000000;
while (l != r) {
ll sum = 0;
ll now = (l + r) / 2;
if (now == 0) {
cout << 1;
return 0;
}
rep(i, 0, N) { sum += ((A[i] - 1) / now); }
if (sum > K) {
l = now + 1;
} else {
r = now;
}
}
cout << r;
return 0;
} | insert | 48 | 48 | 48 | 52 | 0 | |
p02598 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ll N, K;
cin >> N >> K;
ll ok = 1e9;
ll ng = 0;
vector<ll> A(N);
for (int i = 0; i < N; i++)
cin >> A[i];
int t = 40;
while (t--) {
ll mid = (ok + ng) / 2;
ll count = 0;
for (int i = 0; i < N; i++) {
count += A[i] / mid;
if (A[i] % mid == 0)
count--;
}
if (count > K)
ng = mid;
else
ok = mid;
}
cout << ok << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ll N, K;
cin >> N >> K;
ll ok = 1e9;
ll ng = 1;
vector<ll> A(N);
for (int i = 0; i < N; i++)
cin >> A[i];
int t = 40;
while (t--) {
ll mid = (ok + ng) / 2;
ll count = 0;
for (int i = 0; i < N; i++) {
count += A[i] / mid;
if (A[i] % mid == 0)
count--;
}
if (count > K)
ng = mid;
else
ok = mid;
}
cout << ok << endl;
} | replace | 8 | 9 | 8 | 9 | 0 | |
p02598 | C++ | Runtime Error |
#include <bits/stdc++.h>
using namespace std;
/**
******************* Author:Bisnu sarkar ****************************
**/
/*
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
*/
#define fRead(x) freopen(x, "r", stdin)
#define fWrite(x) freopen(x, "w", stdout)
#define ull unsigned long long
#define ll long long
#define pii pair<int, int>
#define sit set<int>::iterator
#define vrit vector<int>::reverse iterator
#define ff first
#define ss second
#define endl '\n';
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()
#define IO ios_base::sync_with_stdio(false), cin.tie(NULL);
#define what_is(x) cerr << #x << " is " << x << endl;
///*....Debugger....*///
#define error(args...) \
{ \
string _s = #args; \
replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); \
istream_iterator<string> _it(_ss); \
err(_it, args); \
}
void err(istream_iterator<string> it) { cout << endl; }
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << ", ";
err(++it, args...);
}
///*....Input....*///
template <typename T> inline void Int(T &n) {
n = 0;
int f = 1;
register int ch = getchar();
for (; !isdigit(ch); ch = getchar())
if (ch == '-')
f = -1;
for (; isdigit(ch); ch = getchar())
n = (n << 3) + (n << 1) + ch - '0';
n = n * f;
}
template <typename T, typename TT> inline void Int(T &n, TT &m) {
Int(n);
Int(m);
}
template <typename T, typename TT, typename TTT>
inline void Int(T &n, TT &m, TTT &l) {
Int(n, m);
Int(l);
}
double ind() {
double x;
scanf("%lf", &x);
return x;
}
///*....Bitmask....*///
int set_1(int n, int pos) { return n = (n | (1 << pos)); }
int reset_0(int n, int pos) { return n = n & ~(1 << pos); }
bool check_bit(int n, int pos) { return n = n & (1 << pos); }
int dx[8] = {1, 0, -1, 0, -1, -1, 1, 1};
int dy[8] = {0, 1, 0, -1, -1, 1, -1, 1};
///*....Constraints....*///
const int N = (int)1e6 + 5;
const int M = (int)1e9 + 7;
const double pi = 2 * acos(0.0);
const double eps = 1e-9;
ll a[N];
ll n, k;
bool valid(ll x) {
ll op = 0ll;
for (int i = 1; i <= n; ++i) {
ll p = a[i] / x;
if (a[i] % x == 0)
p -= 1;
op += p;
// error(a[i],x,p)
}
return op <= k;
}
int main() {
Int(n, k);
ll ma = 0ll;
for (int i = 1; i <= n; ++i) {
Int(a[i]);
ma = max(a[i], ma);
}
ll l = 0, r = ma, ans;
while (l <= r) {
ll mid = (l + r) / 2;
if (valid(mid)) {
ans = mid;
r = mid - 1;
} else {
l = mid + 1;
}
}
printf("%lld\n", ans);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
/**
******************* Author:Bisnu sarkar ****************************
**/
/*
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
*/
#define fRead(x) freopen(x, "r", stdin)
#define fWrite(x) freopen(x, "w", stdout)
#define ull unsigned long long
#define ll long long
#define pii pair<int, int>
#define sit set<int>::iterator
#define vrit vector<int>::reverse iterator
#define ff first
#define ss second
#define endl '\n';
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()
#define IO ios_base::sync_with_stdio(false), cin.tie(NULL);
#define what_is(x) cerr << #x << " is " << x << endl;
///*....Debugger....*///
#define error(args...) \
{ \
string _s = #args; \
replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); \
istream_iterator<string> _it(_ss); \
err(_it, args); \
}
void err(istream_iterator<string> it) { cout << endl; }
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << ", ";
err(++it, args...);
}
///*....Input....*///
template <typename T> inline void Int(T &n) {
n = 0;
int f = 1;
register int ch = getchar();
for (; !isdigit(ch); ch = getchar())
if (ch == '-')
f = -1;
for (; isdigit(ch); ch = getchar())
n = (n << 3) + (n << 1) + ch - '0';
n = n * f;
}
template <typename T, typename TT> inline void Int(T &n, TT &m) {
Int(n);
Int(m);
}
template <typename T, typename TT, typename TTT>
inline void Int(T &n, TT &m, TTT &l) {
Int(n, m);
Int(l);
}
double ind() {
double x;
scanf("%lf", &x);
return x;
}
///*....Bitmask....*///
int set_1(int n, int pos) { return n = (n | (1 << pos)); }
int reset_0(int n, int pos) { return n = n & ~(1 << pos); }
bool check_bit(int n, int pos) { return n = n & (1 << pos); }
int dx[8] = {1, 0, -1, 0, -1, -1, 1, 1};
int dy[8] = {0, 1, 0, -1, -1, 1, -1, 1};
///*....Constraints....*///
const int N = (int)1e6 + 5;
const int M = (int)1e9 + 7;
const double pi = 2 * acos(0.0);
const double eps = 1e-9;
ll a[N];
ll n, k;
bool valid(ll x) {
ll op = 0ll;
for (int i = 1; i <= n; ++i) {
ll p = a[i] / x;
if (a[i] % x == 0)
p -= 1;
op += p;
// error(a[i],x,p)
}
return op <= k;
}
int main() {
Int(n, k);
ll ma = 0ll;
for (int i = 1; i <= n; ++i) {
Int(a[i]);
ma = max(a[i], ma);
}
ll l = 1, r = ma, ans;
while (l <= r) {
ll mid = (l + r) / 2;
if (valid(mid)) {
ans = mid;
r = mid - 1;
} else {
l = mid + 1;
}
}
printf("%lld\n", ans);
return 0;
}
| replace | 106 | 107 | 106 | 107 | 0 | |
p02598 | C++ | Runtime Error | #include <cmath>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
ll A[100006];
int N, K;
bool f(ll x) {
int cnt = 0;
for (int i = 0; i < N; i++) {
if (A[i] <= x)
continue;
cnt += (int)ceil(1.0 * A[i] / x) - 1;
}
return cnt <= K;
}
int main() {
cin >> N >> K;
for (int i = 0; i < N; i++)
cin >> A[i];
ll ub = 1LL << 60;
ll lb = 0;
while (ub - lb > 1) {
ll mid = (ub + lb) / 2;
if (f(mid))
ub = mid;
else
lb = mid;
}
cout << ub << endl;
} | #include <cmath>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
ll A[200006];
int N, K;
bool f(ll x) {
int cnt = 0;
for (int i = 0; i < N; i++) {
if (A[i] <= x)
continue;
cnt += (int)ceil(1.0 * A[i] / x) - 1;
}
return cnt <= K;
}
int main() {
cin >> N >> K;
for (int i = 0; i < N; i++)
cin >> A[i];
ll ub = 1LL << 60;
ll lb = 0;
while (ub - lb > 1) {
ll mid = (ub + lb) / 2;
if (f(mid))
ub = mid;
else
lb = mid;
}
cout << ub << endl;
} | replace | 7 | 8 | 7 | 8 | 0 | |
p02598 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = (0); i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x, y) \
cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x, y, z) \
cout << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z \
<< " = " << (z) << endl
#define showv(v) \
rep(i, v.size()) printf("%d%c", v[i], i == v.size() - 1 ? '\n' : ' ')
#define showv2(v) rep(j, v.size()) showv(v[j])
#define showt(t, n) rep(i, n) printf("%d%c", t[i], i == n - 1 ? '\n' : ' ')
#define showt2(t, r, c) rep(j, r) showt(t[j], c)
#define showvp(p) rep(i, p.size()) printf("%d %d\n", p[i].first, p[i].second)
#define printv(v) rep(i, v.size()) printf("%d\n", v[i])
#define printt(t, n) rep(i, n) printf("%d\n", t[i])
#define incl(v, x) (find(all(v), x) != v.end())
#define incls(s, c) (s.find(c) != string::npos)
#define lb(a, x) distance((a).begin(), lower_bound(all(a), (x)))
#define ub(a, x) distance((a).begin(), upper_bound(all(a), (x)))
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n, k) ((n >> k) & 1) // nのk bit目
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define uni(x) x.erase(unique(all(x)), x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
// const long double EPS = 1e-14;
const int INF = (1 << 30) - 1;
const ll LINF = (1LL << 62) - 1;
#define dame \
{ \
puts("No"); \
return 0; \
}
#define yn \
{ puts("Yes"); } \
else { \
puts("No"); \
}
#define YN \
{ puts("YES"); } \
else { \
puts("NO"); \
}
inline int in() {
int x;
cin >> x;
return x;
}
inline ll lin() {
ll x;
cin >> x;
return x;
}
inline char chin() {
char x;
cin >> x;
return x;
}
inline string stin() {
string x;
cin >> x;
return x;
}
inline double din() {
double x;
cin >> x;
return x;
}
// template<class T = int> inline T in() { T x; cin >> x; return (x);}
template <typename T> inline ll suma(const vector<T> &a) {
ll res(0);
for (auto &&x : a)
res += x;
return res;
}
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;
}
char itoa(int n) { return n + '0'; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const int dy[4] = {0, -1, 0, 1};
const int dx[4] = {1, 0, -1, 0};
ll n, k;
vl a;
bool isOK(ll x) {
ll tot = 0;
rep(i, n) { tot += dup(a[i], x) - 1; }
return tot <= k;
}
int main() {
cin >> n >> k;
a = vl(n);
rep(i, n) cin >> a[i];
ll ng = -1;
ll ok = LINF;
// (ng, ok]
// xxxxxooooo
// |
while (abs(ok - ng) > 1) {
ll mid = (ok + ng) / 2;
if (isOK(mid))
ok = mid;
else
ng = mid;
}
cout << ok << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = (0); i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x, y) \
cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x, y, z) \
cout << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z \
<< " = " << (z) << endl
#define showv(v) \
rep(i, v.size()) printf("%d%c", v[i], i == v.size() - 1 ? '\n' : ' ')
#define showv2(v) rep(j, v.size()) showv(v[j])
#define showt(t, n) rep(i, n) printf("%d%c", t[i], i == n - 1 ? '\n' : ' ')
#define showt2(t, r, c) rep(j, r) showt(t[j], c)
#define showvp(p) rep(i, p.size()) printf("%d %d\n", p[i].first, p[i].second)
#define printv(v) rep(i, v.size()) printf("%d\n", v[i])
#define printt(t, n) rep(i, n) printf("%d\n", t[i])
#define incl(v, x) (find(all(v), x) != v.end())
#define incls(s, c) (s.find(c) != string::npos)
#define lb(a, x) distance((a).begin(), lower_bound(all(a), (x)))
#define ub(a, x) distance((a).begin(), upper_bound(all(a), (x)))
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n, k) ((n >> k) & 1) // nのk bit目
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define uni(x) x.erase(unique(all(x)), x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
// const long double EPS = 1e-14;
const int INF = (1 << 30) - 1;
const ll LINF = (1LL << 62) - 1;
#define dame \
{ \
puts("No"); \
return 0; \
}
#define yn \
{ puts("Yes"); } \
else { \
puts("No"); \
}
#define YN \
{ puts("YES"); } \
else { \
puts("NO"); \
}
inline int in() {
int x;
cin >> x;
return x;
}
inline ll lin() {
ll x;
cin >> x;
return x;
}
inline char chin() {
char x;
cin >> x;
return x;
}
inline string stin() {
string x;
cin >> x;
return x;
}
inline double din() {
double x;
cin >> x;
return x;
}
// template<class T = int> inline T in() { T x; cin >> x; return (x);}
template <typename T> inline ll suma(const vector<T> &a) {
ll res(0);
for (auto &&x : a)
res += x;
return res;
}
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;
}
char itoa(int n) { return n + '0'; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const int dy[4] = {0, -1, 0, 1};
const int dx[4] = {1, 0, -1, 0};
ll n, k;
vl a;
bool isOK(ll x) {
ll tot = 0;
rep(i, n) { tot += dup(a[i], x) - 1; }
return tot <= k;
}
int main() {
cin >> n >> k;
a = vl(n);
rep(i, n) cin >> a[i];
ll ng = 0;
ll ok = LINF;
// (ng, ok]
// xxxxxooooo
// |
while (abs(ok - ng) > 1) {
ll mid = (ok + ng) / 2;
if (isOK(mid))
ok = mid;
else
ng = mid;
}
cout << ok << endl;
return 0;
} | replace | 142 | 143 | 142 | 143 | 0 | |
p02598 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
// #define MODE 1
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define DEB2(X) cout << X << " ";
#define END cout << endl;
#else
#define DEB(X) \
{}
#define DEB2(X) \
{}
#define END \
{}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
// typedef std::pair<int,int> P;
struct edge {
int to, cost;
};
const int INF = 100000000000000000;
const int INF2 = 9223372036854775807;
const int MOD = 1000000007;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define min(X, Y) (((int)(X) < (int)(Y)) ? (X) : (Y))
#define max(X, Y) (((int)(X) > (int)(Y)) ? (X) : (Y))
#define NP(X, Y) next_permutation(X, Y)
#define setdouble(X, Y) cout << fixed << setprecision(X) << Y
int ceil2(int a, int b) {
if (a % b == 0) {
return a / b;
} else {
return a / b + 1;
}
}
int pow2(int a, int b) {
int r = 1;
for (int i = 1; i <= b; i++) {
r *= a;
}
return r;
}
int Log2(int a) {
int t = 0;
while (1) {
if (a == 0 || a == 1) {
break;
}
a /= 2;
t++;
}
return t;
}
int N, K;
int A[200010];
int M = 0;
bool check(int m) {
int sum = 0;
REP(i, N) {
int c = ceil2(A[i], m);
sum += c;
}
if (sum <= K + N) {
return true;
}
return false;
}
signed main() {
cin >> N >> K;
REP(i, N) {
cin >> A[i];
M = max(M, A[i]);
}
int ok = M, ng = -1;
while (abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (check(mid)) {
ok = mid;
} else {
ng = mid;
}
}
cout << ok << endl;
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
// #define MODE 1
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define DEB2(X) cout << X << " ";
#define END cout << endl;
#else
#define DEB(X) \
{}
#define DEB2(X) \
{}
#define END \
{}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
// typedef std::pair<int,int> P;
struct edge {
int to, cost;
};
const int INF = 100000000000000000;
const int INF2 = 9223372036854775807;
const int MOD = 1000000007;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define min(X, Y) (((int)(X) < (int)(Y)) ? (X) : (Y))
#define max(X, Y) (((int)(X) > (int)(Y)) ? (X) : (Y))
#define NP(X, Y) next_permutation(X, Y)
#define setdouble(X, Y) cout << fixed << setprecision(X) << Y
int ceil2(int a, int b) {
if (a % b == 0) {
return a / b;
} else {
return a / b + 1;
}
}
int pow2(int a, int b) {
int r = 1;
for (int i = 1; i <= b; i++) {
r *= a;
}
return r;
}
int Log2(int a) {
int t = 0;
while (1) {
if (a == 0 || a == 1) {
break;
}
a /= 2;
t++;
}
return t;
}
int N, K;
int A[200010];
int M = 0;
bool check(int m) {
int sum = 0;
REP(i, N) {
int c = ceil2(A[i], m);
sum += c;
}
if (sum <= K + N) {
return true;
}
return false;
}
signed main() {
cin >> N >> K;
REP(i, N) {
cin >> A[i];
M = max(M, A[i]);
}
int ok = M, ng = 0;
while (abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (check(mid)) {
ok = mid;
} else {
ng = mid;
}
}
cout << ok << endl;
return 0;
}
| replace | 94 | 95 | 94 | 95 | 0 | |
p02598 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mod(n, k) ((((n) % (k)) + (k)) % (k))
#define forn(i, a, b) for (int i = a; i < b; i++)
#define forr(i, a, b) for (int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
const int maxn = 200000 + 10;
int N, K, A[maxn];
int get(int act, int x) {
if (act <= x)
return 0;
return 1 + get(act - x, x);
}
int can(int x) {
int cnt = 0;
forn(i, 0, N) {
if (A[i] <= x)
continue;
cnt += get(A[i], x);
}
if (cnt > K)
return 0;
return 1;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> N >> K;
forn(i, 0, N) cin >> A[i];
int ini = 1, fin = 1e9 + 1;
while (ini < fin) {
int mit = (ini + fin) >> 1;
if (can(mit))
fin = mit;
else
ini = mit + 1;
}
cout << ini << '\n';
return 0;
}
/*
__builtin_mul_overflow(x,y,&x)
-fsplit-stack
*/
| #include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mod(n, k) ((((n) % (k)) + (k)) % (k))
#define forn(i, a, b) for (int i = a; i < b; i++)
#define forr(i, a, b) for (int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
const int maxn = 200000 + 10;
int N, K, A[maxn];
int get(int act, int x) {
// if(act <= x)return 0;
// return 1+get(act-x,x);
return act / x;
}
int can(int x) {
int cnt = 0;
forn(i, 0, N) {
if (A[i] <= x)
continue;
cnt += get(A[i], x);
}
if (cnt > K)
return 0;
return 1;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> N >> K;
forn(i, 0, N) cin >> A[i];
int ini = 1, fin = 1e9 + 1;
while (ini < fin) {
int mit = (ini + fin) >> 1;
if (can(mit))
fin = mit;
else
ini = mit + 1;
}
cout << ini << '\n';
return 0;
}
/*
__builtin_mul_overflow(x,y,&x)
-fsplit-stack
*/
| replace | 21 | 24 | 21 | 24 | TLE | |
p02598 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define REP(i, n) for (ll i = 0LL; i < (ll)(n); i++)
#define REPR(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, n, m) for (ll i = (ll)n; i < (ll)(m); i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define INF (1LL << 62)
#define PI (acos(-1))
#define PRINT(x) std::cout << x << endl
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll countDigit(ll n) { return floor(log10(n) + 1); }
typedef pair<ll, ll> P;
static const ll dx[8] = {0, 1, 0, -1, 1, -1, 1, -1},
dy[8] = {1, 0, -1, 0, 1, 1, -1, -1};
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
for (int i = 0; i < (int)v.size(); ++i)
os << v[i] << " ";
return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const map<T1, T2> &m) {
for (auto p : m)
os << "<" << p.first << ", " << p.second << "> ";
return os;
}
int main() {
ll N, K;
cin >> N >> K;
vector<ll> A(N);
REP(i, N) { cin >> A[i]; }
ll left = 0.;
ll right = 1e9;
while (right >= left) {
ll mid = (left + right) / 2;
ll tK = K + N;
bool flag = false;
REP(i, N) {
ll n = (A[i] + mid - 1) / mid;
if (n <= tK) {
tK -= n;
} else {
i = N;
flag = true;
}
}
if (flag) {
left = mid + 1;
} else {
right = mid - 1;
}
}
cout << left << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define REP(i, n) for (ll i = 0LL; i < (ll)(n); i++)
#define REPR(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, n, m) for (ll i = (ll)n; i < (ll)(m); i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define INF (1LL << 62)
#define PI (acos(-1))
#define PRINT(x) std::cout << x << endl
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll countDigit(ll n) { return floor(log10(n) + 1); }
typedef pair<ll, ll> P;
static const ll dx[8] = {0, 1, 0, -1, 1, -1, 1, -1},
dy[8] = {1, 0, -1, 0, 1, 1, -1, -1};
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
for (int i = 0; i < (int)v.size(); ++i)
os << v[i] << " ";
return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const map<T1, T2> &m) {
for (auto p : m)
os << "<" << p.first << ", " << p.second << "> ";
return os;
}
int main() {
ll N, K;
cin >> N >> K;
vector<ll> A(N);
REP(i, N) { cin >> A[i]; }
ll left = 1;
ll right = 1e9;
while (right >= left) {
ll mid = (left + right) / 2;
ll tK = K + N;
bool flag = false;
REP(i, N) {
ll n = (A[i] + mid - 1) / mid;
if (n <= tK) {
tK -= n;
} else {
i = N;
flag = true;
}
}
if (flag) {
left = mid + 1;
} else {
right = mid - 1;
}
}
cout << left << endl;
return 0;
}
| replace | 42 | 43 | 42 | 43 | 0 | |
p02598 | C++ | Runtime Error | /*
Created by Rahul Goel.
*/
#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;
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
/*******************************************************************************/
using ll = long long;
using ld = long double;
const ll MOD = 1000000007;
// const ll MOD = 998244353;
const int INF = 1e9;
const ll LINF = 1e18;
/*******************************************************************************/
ll mod_sum() { return 0LL; }
template <typename T, typename... Args> T mod_sum(T a, Args... args) {
return ((a + MOD_sum(args...)) % MOD + MOD) % MOD;
}
/*******************************************************************************/
ll mod_prod() { return 1LL; }
template <typename T, typename... Args> T mod_prod(T a, Args... args) {
return (a * MOD_prod(args...)) % MOD;
}
/*******************************************************************************/
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif
#define fastio \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define all(c) (c).begin(), (c).end()
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define uniq(c) (c).resize(distance((c).begin(), unique(all(c))))
#define min_pq(t) priority_queue<t, vector<t>, greater<t>>
#define max_pq(t) priority_queue<t>
#define pb push_back
#define ff first
#define ss second
/*******************************************************************************/
using pii = pair<ll, ll>;
using vi = vector<ll>;
using vb = vector<bool>;
using vvi = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vpii = vector<pii>;
using vvpii = vector<vector<pii>>;
/*******************************************************************************/
//.-.. . -. -.- .- .. ... .-.. --- ...- .
/*
Code begins after this.
*/
ll solve() {
ll n, k;
cin >> n >> k;
vi vec(n);
for (ll &x : vec) {
cin >> x;
}
ll start = 0, end = INF, mid, ans = -1;
while (start <= end) {
mid = (start + end) >> 1;
ll op = 0;
for (ll &x : vec) {
if (x > mid) {
op += x / mid;
}
}
if (op <= k) {
ans = mid;
end = mid - 1;
} else {
start = mid + 1;
}
}
cout << ans << endl;
return 0;
}
signed main() {
fastio;
ll t = 1;
while (t--) {
solve();
}
return 0;
}
| /*
Created by Rahul Goel.
*/
#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;
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
/*******************************************************************************/
using ll = long long;
using ld = long double;
const ll MOD = 1000000007;
// const ll MOD = 998244353;
const int INF = 1e9;
const ll LINF = 1e18;
/*******************************************************************************/
ll mod_sum() { return 0LL; }
template <typename T, typename... Args> T mod_sum(T a, Args... args) {
return ((a + MOD_sum(args...)) % MOD + MOD) % MOD;
}
/*******************************************************************************/
ll mod_prod() { return 1LL; }
template <typename T, typename... Args> T mod_prod(T a, Args... args) {
return (a * MOD_prod(args...)) % MOD;
}
/*******************************************************************************/
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif
#define fastio \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define all(c) (c).begin(), (c).end()
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define uniq(c) (c).resize(distance((c).begin(), unique(all(c))))
#define min_pq(t) priority_queue<t, vector<t>, greater<t>>
#define max_pq(t) priority_queue<t>
#define pb push_back
#define ff first
#define ss second
/*******************************************************************************/
using pii = pair<ll, ll>;
using vi = vector<ll>;
using vb = vector<bool>;
using vvi = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vpii = vector<pii>;
using vvpii = vector<vector<pii>>;
/*******************************************************************************/
//.-.. . -. -.- .- .. ... .-.. --- ...- .
/*
Code begins after this.
*/
ll solve() {
ll n, k;
cin >> n >> k;
vi vec(n);
for (ll &x : vec) {
cin >> x;
}
if (k == 0) {
cout << *max_element(all(vec)) << endl;
return 0;
}
ll start = 1, end = INF, mid, ans = -1;
while (start <= end) {
mid = (start + end) >> 1;
ll op = 0;
for (ll &x : vec) {
if (x > mid) {
op += x / mid;
}
}
if (op <= k) {
ans = mid;
end = mid - 1;
} else {
start = mid + 1;
}
}
cout << ans << endl;
return 0;
}
signed main() {
fastio;
ll t = 1;
while (t--) {
solve();
}
return 0;
}
| replace | 69 | 70 | 69 | 75 | 0 | |
p02598 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define maxn 200010
const int MOD = 1000000007;
int v[maxn];
int n;
int k;
bool check(int m) {
int times = 0;
for (int i = 0; i < n; i++) {
times += v[i] / m + (v[i] % m > 0) - 1;
}
return times <= k;
}
void solve() {
cin >> n >> k;
for (int i = 0; i < n; ++i)
cin >> v[i];
int lo = 0, hi = 1e12, mid, ans = 0;
while (lo <= hi) {
mid = lo + hi >> 1;
if (check(mid)) {
ans = mid;
hi = mid - 1;
} else
lo = mid + 1;
}
cout << ans << endl;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
// cin >> t;
while (t--)
solve();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define maxn 200010
const int MOD = 1000000007;
int v[maxn];
int n;
int k;
bool check(int m) {
int times = 0;
for (int i = 0; i < n; i++) {
times += v[i] / m + (v[i] % m > 0) - 1;
}
return times <= k;
}
void solve() {
cin >> n >> k;
for (int i = 0; i < n; ++i)
cin >> v[i];
int lo = 1, hi = 1e12, mid, ans = 0;
while (lo <= hi) {
mid = lo + hi >> 1;
if (check(mid)) {
ans = mid;
hi = mid - 1;
} else
lo = mid + 1;
}
cout << ans << endl;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
// cin >> t;
while (t--)
solve();
return 0;
} | replace | 26 | 27 | 26 | 27 | 0 | |
p02598 | C++ | Runtime Error | #include <algorithm>
#include <climits>
#include <cmath>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
ll N, K;
ll A[200200];
bool IsCuttable(ll len) {
ll count = 0;
for (int i = 0; i < N; i++) {
ll count_ = A[i] / len;
if (A[i] % len != 0 && A[i] > len) {
count_++;
}
if (count_ > 0) {
count_--;
}
count += count_;
}
if (count <= K) {
return true;
} else {
return false;
}
}
int main() {
cin >> N >> K;
for (int i = 0; i < N; i++) {
cin >> A[i];
}
ll min = 0;
ll max = 1000000000;
while (max - min > 0) {
ll mid = min + (max - min) / 2;
// cout << mid << endl;
if (IsCuttable(mid)) {
max = mid;
} else {
min = mid + 1;
}
}
cout << min << endl;
return 0;
}
| #include <algorithm>
#include <climits>
#include <cmath>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
ll N, K;
ll A[200200];
bool IsCuttable(ll len) {
ll count = 0;
for (int i = 0; i < N; i++) {
ll count_ = A[i] / len;
if (A[i] % len != 0 && A[i] > len) {
count_++;
}
if (count_ > 0) {
count_--;
}
count += count_;
}
if (count <= K) {
return true;
} else {
return false;
}
}
int main() {
cin >> N >> K;
for (int i = 0; i < N; i++) {
cin >> A[i];
}
ll min = 1;
ll max = 1000000000;
while (max - min > 0) {
ll mid = min + (max - min) / 2;
// cout << mid << endl;
if (IsCuttable(mid)) {
max = mid;
} else {
min = mid + 1;
}
}
cout << min << endl;
return 0;
}
| replace | 48 | 49 | 48 | 49 | 0 | |
p02598 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n, k;
cin >> n >> k;
int A[n];
for (int i = 0; i < n; i++)
cin >> A[i];
int a = 0, b = 1e9;
while (a < b) {
// cout<<a<<" "<<b<<endl;
int mid = (a + b) / 2;
int times = 0;
for (int i = 0; i < n; i++) {
int y = A[i] / mid;
if (A[i] % mid == 0)
y--;
times += y;
}
if (times > k)
a = mid + 1;
else
b = mid;
}
cout << a;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n, k;
cin >> n >> k;
int A[n];
for (int i = 0; i < n; i++)
cin >> A[i];
int a = 1, b = 1e9;
while (a < b) {
// cout<<a<<" "<<b<<endl;
int mid = (a + b) / 2;
int times = 0;
for (int i = 0; i < n; i++) {
int y = A[i] / mid;
if (A[i] % mid == 0)
y--;
times += y;
}
if (times > k)
a = mid + 1;
else
b = mid;
}
cout << a;
} | replace | 21 | 22 | 21 | 22 | -8 | |
p02598 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 100000000;
#define rep1(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, k, n) for (ll i = k; i < (n); i++)
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 n, k;
vector<ll> a;
bool check(ll x) {
ll count = 0;
rep1(i, n) count += (a[i] - 1) / x;
if (count <= k)
return true;
else
return false;
}
int main() {
cin >> n >> k;
a.resize(n);
rep1(i, n) cin >> a[i];
ll ans = 0;
ll left = -1, right = 1e9 + 1;
while (right > left) {
ll mid = (right + left) / 2;
if (check(mid))
right = mid;
else
left = mid + 1;
}
cout << left << endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 100000000;
#define rep1(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, k, n) for (ll i = k; i < (n); i++)
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 n, k;
vector<ll> a;
bool check(ll x) {
ll count = 0;
rep1(i, n) count += (a[i] - 1) / x;
if (count <= k)
return true;
else
return false;
}
int main() {
cin >> n >> k;
a.resize(n);
rep1(i, n) cin >> a[i];
ll ans = 0;
ll left = 1, right = 1e9;
while (right > left) {
ll mid = (right + left) / 2;
if (check(mid))
right = mid;
else
left = mid + 1;
}
cout << left << endl;
} | replace | 38 | 39 | 38 | 39 | 0 | |
p02598 | C++ | Time Limit Exceeded | #pragma region cp -helper
#include <bits/stdc++.h>
using namespace std;
#define AC \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
#define int long long
#define ll long long
#define ull unsigned long long
#define ii pair<int, int>
#define lll pair<ll, ll>
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define vll vector<lll>
#define vvl vector<vl>
#define vii vector<ii>
#define all(a) a.begin(), a.end()
#define qsort(a) sort(all(a))
#define qsortd(a) sort(all(a), greater<>())
#define qsortf(a, f) sort(all(a), f)
#define pb(n) push_back(n)
#define eb(n) emplace_back(n)
#define pp(a, b) emplace_back(a, b)
#define umap unordered_map
#define uset unordered_set
#define nl '\n'
#define fileio(in, out) \
freopen(in, "r", stdin); \
freopen(out, "w", stdout)
#define qmod % mod
#define pls signed
#define give main()
const int mod = 1000000007;
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);
}
};
#pragma endregion
const int N = 200005;
int n, arr[N], k;
bool verify(int g) {
int count = 0;
for (int i = 0; i < n; i++) {
int gg = arr[i];
while (gg > g) {
gg -= g;
count++;
if (count > k) {
return false;
}
}
}
return true;
}
pls give {
AC;
cin >> n >> k;
for (int i = 0; i < n; i++)
cin >> arr[i];
int l = 1, r = INT_MAX;
while (l < r) {
int m = (l + r) / 2;
if (verify(m))
r = m;
else
l = m + 1;
}
cout << l << nl;
} | #pragma region cp -helper
#include <bits/stdc++.h>
using namespace std;
#define AC \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
#define int long long
#define ll long long
#define ull unsigned long long
#define ii pair<int, int>
#define lll pair<ll, ll>
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define vll vector<lll>
#define vvl vector<vl>
#define vii vector<ii>
#define all(a) a.begin(), a.end()
#define qsort(a) sort(all(a))
#define qsortd(a) sort(all(a), greater<>())
#define qsortf(a, f) sort(all(a), f)
#define pb(n) push_back(n)
#define eb(n) emplace_back(n)
#define pp(a, b) emplace_back(a, b)
#define umap unordered_map
#define uset unordered_set
#define nl '\n'
#define fileio(in, out) \
freopen(in, "r", stdin); \
freopen(out, "w", stdout)
#define qmod % mod
#define pls signed
#define give main()
const int mod = 1000000007;
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);
}
};
#pragma endregion
const int N = 200005;
int n, arr[N], k;
bool verify(int g) {
int count = 0;
for (int i = 0; i < n; i++) {
int gg = arr[i];
count += ceil(double(gg) / g) - 1;
if (count > k)
return false;
}
return true;
}
pls give {
AC;
cin >> n >> k;
for (int i = 0; i < n; i++)
cin >> arr[i];
int l = 1, r = INT_MAX;
while (l < r) {
int m = (l + r) / 2;
if (verify(m))
r = m;
else
l = m + 1;
}
cout << l << nl;
} | replace | 62 | 69 | 62 | 65 | TLE | |
p02598 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define sint(a) scanf("%d", &a)
#define sint2(a, b) scanf("%d %d", &a, &b)
#define sll(a) scanf("%lld", &a)
#define sll2(a, b) scanf("%lld %lld", &a, &b)
#define mem(a, i) memset(a, i, sizeof(a))
#define pb push_back
#define int long long
#define ll long long
#define lson node << 1
#define rson (node << 1) + 1
#define endl "\n"
const int maxn = 2e6 + 10;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
ll qpow(ll a, ll n) {
ll b = 1;
while (n) {
if (n & 1)
b = b * a % mod;
a = a * a % mod;
n >>= 1;
}
return b;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
// int prime[maxn],s,v[maxn];
// void prime_init()
//{
// for(int i=2; i<=maxn; i++)
// {
// if(!v[i])
// {
// prime[s++]=i;
// for(int j=1; j*i<=maxn; j++)
// v[i*j]=1;
// }
// }
// }
int n, k;
int a[maxn];
int check(int x) {
int sum = 0;
for (int i = 0; i < n; i++) {
sum += a[i] / x;
if (a[i] % x == 0)
sum--;
if (sum > k)
return 0;
}
return 1;
}
signed main() {
sll2(n, k);
int l = 0, r = 0;
for (int i = 0; i < n; i++) {
sll(a[i]);
r = max(r, a[i]);
}
r++;
while (l < r) {
int mid = (l + r) >> 1;
if (check(mid))
r = mid;
else
l = mid + 1;
}
printf("%lld", r);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define sint(a) scanf("%d", &a)
#define sint2(a, b) scanf("%d %d", &a, &b)
#define sll(a) scanf("%lld", &a)
#define sll2(a, b) scanf("%lld %lld", &a, &b)
#define mem(a, i) memset(a, i, sizeof(a))
#define pb push_back
#define int long long
#define ll long long
#define lson node << 1
#define rson (node << 1) + 1
#define endl "\n"
const int maxn = 2e6 + 10;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
ll qpow(ll a, ll n) {
ll b = 1;
while (n) {
if (n & 1)
b = b * a % mod;
a = a * a % mod;
n >>= 1;
}
return b;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
// int prime[maxn],s,v[maxn];
// void prime_init()
//{
// for(int i=2; i<=maxn; i++)
// {
// if(!v[i])
// {
// prime[s++]=i;
// for(int j=1; j*i<=maxn; j++)
// v[i*j]=1;
// }
// }
// }
int n, k;
int a[maxn];
int check(int x) {
int sum = 0;
for (int i = 0; i < n; i++) {
sum += a[i] / x;
if (a[i] % x == 0)
sum--;
if (sum > k)
return 0;
}
return 1;
}
signed main() {
sll2(n, k);
int l = 1, r = 0;
for (int i = 0; i < n; i++) {
sll(a[i]);
r = max(r, a[i]);
}
r++;
while (l < r) {
int mid = (l + r) >> 1;
if (check(mid))
r = mid;
else
l = mid + 1;
}
printf("%lld", r);
return 0;
}
| replace | 59 | 60 | 59 | 60 | 0 | |
p02598 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define init(a, i) \
for (int k = 0; k < (i); k++) \
(a)[k] = 0
#define in(a, i) \
for (int k = 0; k < (i); k++) \
cin >> (a)[k]
#define all(a) (a).begin(), (a).end()
#define el(a) (a).end() - (a).begin()
#define mod 1000000007
#define inf 2147483647
#define range(x, a, b) (a) <= x &&x <= (b)
int n, k;
int a[200000];
bool can(int length) {
ll WorkCount = 0;
rep(i, n) { WorkCount += (a[i] + (length - 1)) / length - 1; }
if (WorkCount > k)
return 0;
else
return 1;
}
int main() {
cin >> n >> k;
in(a, n);
int left = -1, right = 1000000000; // 2分探索(left<anser<=right)
int middle;
while (right - left != 1) {
middle = (left + right) / 2;
if (can(middle)) {
right = middle;
} else {
left = middle;
}
}
cout << right;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define init(a, i) \
for (int k = 0; k < (i); k++) \
(a)[k] = 0
#define in(a, i) \
for (int k = 0; k < (i); k++) \
cin >> (a)[k]
#define all(a) (a).begin(), (a).end()
#define el(a) (a).end() - (a).begin()
#define mod 1000000007
#define inf 2147483647
#define range(x, a, b) (a) <= x &&x <= (b)
int n, k;
int a[200000];
bool can(int length) {
ll WorkCount = 0;
rep(i, n) { WorkCount += (a[i] + (length - 1)) / length - 1; }
if (WorkCount > k)
return 0;
else
return 1;
}
int main() {
cin >> n >> k;
in(a, n);
int left = 0, right = 1000000000; // 2分探索(left<anser<=right)
int middle;
while (right - left != 1) {
middle = (left + right) / 2;
if (can(middle)) {
right = middle;
} else {
left = middle;
}
}
cout << right;
return 0;
} | replace | 30 | 31 | 30 | 31 | 0 | |
p02598 | C++ | Runtime Error | #ifndef TEMPLATE_HPP
#define TEMPLATE_HPP
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int)v.size())
using namespace std;
using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;
template <typename T>
class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T>
class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> void amax(T &x, T y) { x = max(x, y); }
template <typename T> void amin(T &x, T y) { x = min(x, y); }
template <typename T> T power(T x, i64 n, T e = 1) {
T r = e;
while (n > 0) {
if (n & 1)
r *= x;
x *= x;
n >>= 1;
}
return r;
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
for (auto &x : v)
is >> x;
return is;
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) {
rep(i, v.size()) {
if (i)
os << ' ';
os << v[i];
}
return os;
}
template <typename T, typename U> vector<U> make_vector(T &&n, U &&val) {
return vector<U>(forward<T>(n), forward<U>(val));
}
template <typename T, typename... Args>
decltype(auto) make_vector(T &&n, Args &&...args) {
return vector<decltype(make_vector(forward<Args>(args)...))>(
forward<T>(n), make_vector(forward<Args>(args)...));
}
const int INF = 1001001001;
const i64 LINF = 1001001001001001001ll;
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
#endif
void solve() {
int n, k;
cin >> n >> k;
k += n;
vi32 a(n);
cin >> a;
i64 ok = 1e18, ng = 0;
rep(_, 100) {
i64 x = (ok + ng) / 2;
i64 cnt = 0;
rep(i, n) {
i64 c = (a[i] + x - 1) / x;
cnt += c;
}
(cnt <= k ? ok : ng) = x;
}
cout << ok << endl;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout << fixed << setprecision(16);
cerr << fixed << setprecision(16);
solve();
return 0;
}
| #ifndef TEMPLATE_HPP
#define TEMPLATE_HPP
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int)v.size())
using namespace std;
using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;
template <typename T>
class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T>
class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> void amax(T &x, T y) { x = max(x, y); }
template <typename T> void amin(T &x, T y) { x = min(x, y); }
template <typename T> T power(T x, i64 n, T e = 1) {
T r = e;
while (n > 0) {
if (n & 1)
r *= x;
x *= x;
n >>= 1;
}
return r;
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
for (auto &x : v)
is >> x;
return is;
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) {
rep(i, v.size()) {
if (i)
os << ' ';
os << v[i];
}
return os;
}
template <typename T, typename U> vector<U> make_vector(T &&n, U &&val) {
return vector<U>(forward<T>(n), forward<U>(val));
}
template <typename T, typename... Args>
decltype(auto) make_vector(T &&n, Args &&...args) {
return vector<decltype(make_vector(forward<Args>(args)...))>(
forward<T>(n), make_vector(forward<Args>(args)...));
}
const int INF = 1001001001;
const i64 LINF = 1001001001001001001ll;
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
#endif
void solve() {
int n, k;
cin >> n >> k;
k += n;
vi32 a(n);
cin >> a;
i64 ok = 1e18, ng = 0;
while (abs(ok - ng) != 1) {
i64 x = (ok + ng) >> 1;
i64 cnt = 0;
rep(i, n) {
i64 c = (a[i] + x - 1) / x;
cnt += c;
}
(cnt <= k ? ok : ng) = x;
}
cout << ok << endl;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout << fixed << setprecision(16);
cerr << fixed << setprecision(16);
solve();
return 0;
}
| replace | 72 | 74 | 72 | 74 | 0 | |
p02598 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int n, k;
int a[200010];
char check(const int &n);
int main() {
scanf("%d%d", &n, &k);
int maxv = 0;
long long sum = 0;
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
sum += a[i], maxv = max(maxv, a[i]);
}
int l = sum / (n + k), r = maxv;
while (l <= r) {
int m = l + r >> 1;
if (check(m))
r = m - 1;
else
l = m + 1;
}
printf("%d\n", l);
return 0;
}
char check(const int &m) {
int sum = 0;
for (int i = 0; i < n; ++i)
sum += (a[i] - 1) / m;
return sum <= k;
}
| #include <bits/stdc++.h>
using namespace std;
int n, k;
int a[200010];
char check(const int &n);
int main() {
scanf("%d%d", &n, &k);
int maxv = 0;
long long sum = 0;
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
sum += a[i], maxv = max(maxv, a[i]);
}
int l = (sum + n + k - 1) / (n + k), r = maxv;
while (l <= r) {
int m = l + r >> 1;
if (check(m))
r = m - 1;
else
l = m + 1;
}
printf("%d\n", l);
return 0;
}
char check(const int &m) {
int sum = 0;
for (int i = 0; i < n; ++i)
sum += (a[i] - 1) / m;
return sum <= k;
}
| replace | 16 | 17 | 16 | 17 | 0 | |
p02598 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set \
tree<int, null_type, less<int>, rb_tree_tag, \
tree_order_statistics_node_update>
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
long long int k;
cin >> n >> k;
long long int a[n];
for (int i = 0; i < n; i++)
cin >> a[i];
long long int l = 0;
long long int r = 1e9;
while (l < r) {
long long int m = (l + r) / 2;
long long int cnt = 0;
for (int i = 0; i < n; i++) {
if (a[i] > m) {
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;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set \
tree<int, null_type, less<int>, rb_tree_tag, \
tree_order_statistics_node_update>
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
long long int k;
cin >> n >> k;
long long int a[n];
for (int i = 0; i < n; i++)
cin >> a[i];
long long int l = 1;
long long int r = 1e9;
while (l < r) {
long long int m = (l + r) / 2;
long long int cnt = 0;
for (int i = 0; i < n; i++) {
if (a[i] > m) {
cnt += (a[i] - 1) / m;
}
}
if (cnt <= k)
r = m;
else
l = m + 1;
}
cout << l << "\n";
return 0;
} | replace | 21 | 22 | 21 | 22 | 0 | |
p02598 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
int n, k;
int a[maxn];
bool check(int mid) {
int num = 0;
for (int i = 1; i <= n; i++) {
num += a[i] / mid + (a[i] % mid != 0) - 1;
if (num > k)
return false;
}
return true;
}
int main() {
int l = 0, r, mid;
r = 0;
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
r = max(r, a[i]);
}
while (l < r) {
mid = l + r >> 1;
if (check(mid))
r = mid;
else
l = mid + 1;
}
printf("%d\n", l);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
int n, k;
int a[maxn];
bool check(int mid) {
int num = 0;
for (int i = 1; i <= n; i++) {
num += a[i] / mid + (a[i] % mid != 0) - 1;
if (num > k)
return false;
}
return true;
}
int main() {
int l = 1, r, mid;
r = 0;
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
r = max(r, a[i]);
}
while (l < r) {
mid = l + r >> 1;
if (check(mid))
r = mid;
else
l = mid + 1;
}
printf("%d\n", l);
return 0;
}
| replace | 19 | 20 | 19 | 20 | 0 | |
p02598 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main() {
ll n, k;
cin >> n >> k;
vector<ll> a(n);
rep(i, n) cin >> a[i];
auto solve = [&](int x) {
int cnt = 0;
rep(i, n) {
double now = a[i];
int div = 1;
while (x < now / div) {
cnt++;
div++;
}
}
if (cnt <= k)
return true;
else
return false;
};
int ok = 1e9; // 解が存在する値
int ng = 0; // 解が存在しない値
while (abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (solve(mid)) {
ok = mid;
} else {
ng = mid;
}
}
cout << ok << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main() {
ll n, k;
cin >> n >> k;
vector<ll> a(n);
rep(i, n) cin >> a[i];
auto solve = [&](int x) {
int cnt = 0;
rep(i, n) {
// x = 3
// a: 1, 2, 3, 4, 5, 6, 7...
// b: 0, 0, 0, 1, 1, 1, 2...
cnt += (a[i] - 1) / x;
}
if (cnt <= k)
return true;
else
return false;
};
int ok = 1e9; // 解が存在する値
int ng = 0; // 解が存在しない値
while (abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (solve(mid)) {
ok = mid;
} else {
ng = mid;
}
}
cout << ok << endl;
return 0;
} | replace | 15 | 21 | 15 | 19 | TLE | |
p02598 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
using ll = long long int;
using dd = long double;
int main() {
ll N, K;
cin >> N >> K;
vector<ll> log(N);
for (ll i = 0; i < N; i++) {
cin >> log[i];
}
ll l = 0;
ll r = 1e9;
while ((r - l) > 1) {
ll mid = (l + r) / 2;
ll sum = 0;
for (ll i = 0; i < N; i++) {
if (log[i] <= mid) {
continue;
}
sum += (log[i] / mid) + (log[i] % mid == 0 ? -1 : 0);
}
if (sum > K) {
l = mid + 1;
} else {
r = mid;
}
}
ll l_sum = 0;
for (ll i = 0; i < N; i++) {
if (log[i] <= l) {
continue;
}
l_sum += (log[i] / l) + (log[i] % l == 0 ? -1 : 0);
}
if (l_sum <= K) {
cout << l << endl;
} else {
cout << r << endl;
}
} | #include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
using ll = long long int;
using dd = long double;
int main() {
ll N, K;
cin >> N >> K;
vector<ll> log(N);
for (ll i = 0; i < N; i++) {
cin >> log[i];
}
ll l = 1;
ll r = 1e9;
while ((r - l) > 1) {
ll mid = (l + r) / 2;
ll sum = 0;
for (ll i = 0; i < N; i++) {
if (log[i] <= mid) {
continue;
}
sum += (log[i] / mid) + (log[i] % mid == 0 ? -1 : 0);
}
if (sum > K) {
l = mid + 1;
} else {
r = mid;
}
}
ll l_sum = 0;
for (ll i = 0; i < N; i++) {
if (log[i] <= l) {
continue;
}
l_sum += (log[i] / l) + (log[i] % l == 0 ? -1 : 0);
}
if (l_sum <= K) {
cout << l << endl;
} else {
cout << r << endl;
}
} | replace | 20 | 21 | 20 | 21 | 0 | |
p02598 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)
/* REPmacro */
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORR(i, a, b) for (int i = (a); i > (b); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
/* exchange */
#define chmin(a, b) (a) = min((ll)(a), (ll)(b))
#define chmax(a, b) (a) = max((ll)(a), (ll)(b))
/* output */
#define IN(x) cin >> x
#define DE(x) cerr << (x) << " "
#define BR cerr << "\n"
#define OUT(x) cout << (x) << endl
#define FIX cout << fixed << setprecision(10)
/* const */
const int ARRAY = 100005;
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;
ll N = 0;
ll K;
ll ret = 0;
int main(void) {
IN(N);
IN(K);
vl A(N);
REP(i, N) { IN(A[i]); }
ll left = 0;
ll right = 1000000000;
while (right - left > 1) {
ll mid = (left + right) / 2;
ll k = 0;
REP(i, N) { k += (A[i] + mid - 1) / mid - 1; }
if (k < K) {
right = mid;
} else if (k > K) {
left = mid;
} else {
right = mid;
}
// DE(k);
// DE(left);
// DE(right);
// BR;
}
ll left_k = 0;
REP(i, N) { left_k += (A[i] + left - 1) / left - 1; }
// ll right_k = 0;
// REP(i, N) {
// right_k += (A[i] + right - 1) / right - 1;
// }
if (left_k > K) {
OUT(right);
} else {
OUT(left);
}
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)
/* REPmacro */
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORR(i, a, b) for (int i = (a); i > (b); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
/* exchange */
#define chmin(a, b) (a) = min((ll)(a), (ll)(b))
#define chmax(a, b) (a) = max((ll)(a), (ll)(b))
/* output */
#define IN(x) cin >> x
#define DE(x) cerr << (x) << " "
#define BR cerr << "\n"
#define OUT(x) cout << (x) << endl
#define FIX cout << fixed << setprecision(10)
/* const */
const int ARRAY = 100005;
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;
ll N = 0;
ll K;
ll ret = 0;
int main(void) {
IN(N);
IN(K);
vl A(N);
REP(i, N) { IN(A[i]); }
ll left = 1;
ll right = 1000000000;
while (right - left > 1) {
ll mid = (left + right) / 2;
ll k = 0;
REP(i, N) { k += (A[i] + mid - 1) / mid - 1; }
if (k < K) {
right = mid;
} else if (k > K) {
left = mid;
} else {
right = mid;
}
// DE(k);
// DE(left);
// DE(right);
// BR;
}
ll left_k = 0;
REP(i, N) { left_k += (A[i] + left - 1) / left - 1; }
// ll right_k = 0;
// REP(i, N) {
// right_k += (A[i] + right - 1) / right - 1;
// }
if (left_k > K) {
OUT(right);
} else {
OUT(left);
}
}
| replace | 49 | 50 | 49 | 50 | 0 | |
p02598 | C++ | Runtime Error |
// E - Logs
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;
int N, K;
ll A[200000];
// 長さt以下にできるかどうか
bool is_ok(ll t) {
ll cnt = 0;
for (int i = 0; i < N; i++) {
cnt += (A[i] - 1) / t; // 切る回数
}
return cnt <= K;
}
ll find_min_ok(ll lower, ll upper) {
if (!is_ok(upper - 1))
return -1; // 存在しない
ll ok = upper - 1;
ll ng = lower - 1;
while (ok - ng > 1) {
ll trying = (ng + ok) / 2;
if (is_ok(trying)) {
ok = trying;
} else {
ng = trying;
}
}
return ok;
}
int main() {
cin >> N >> K;
for (int i = 0; i < N; i++) {
cin >> A[i];
}
ll ans = find_min_ok(0, 1e9 + 1);
cout << ans << endl;
return 0;
} |
// E - Logs
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;
int N, K;
ll A[200000];
// 長さt以下にできるかどうか
bool is_ok(ll t) {
if (t == 0)
return false;
ll cnt = 0;
for (int i = 0; i < N; i++) {
cnt += (A[i] - 1) / t; // 切る回数
}
return cnt <= K;
}
ll find_min_ok(ll lower, ll upper) {
if (!is_ok(upper - 1))
return -1; // 存在しない
ll ok = upper - 1;
ll ng = lower - 1;
while (ok - ng > 1) {
ll trying = (ng + ok) / 2;
if (is_ok(trying)) {
ok = trying;
} else {
ng = trying;
}
}
return ok;
}
int main() {
cin >> N >> K;
for (int i = 0; i < N; i++) {
cin >> A[i];
}
ll ans = find_min_ok(0, 1e9 + 1);
cout << ans << endl;
return 0;
} | insert | 15 | 15 | 15 | 18 | 0 | |
p02598 | C++ | Runtime Error | // g++ 7.4.0
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, k;
cin >> n >> k;
vector<int> ar(n);
for (int &i : ar)
cin >> i;
int l = -1;
int h = *max_element(ar.begin(), ar.end());
auto fun = [&](int x) { // want the largest length to be x , minimize x
int cuts = 0;
for (const int i : ar) {
if (x >= i)
continue;
int rem = i - x;
cuts++;
if (rem > x)
cuts += ((rem + x - 1) / x - 1);
}
return cuts <= k;
};
while (l + 1 < h) {
int mid = (l + h) >> 1;
if (fun(mid))
h = mid;
else
l = mid;
}
cout << h << '\n';
return 0;
} | // g++ 7.4.0
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, k;
cin >> n >> k;
vector<int> ar(n);
for (int &i : ar)
cin >> i;
int l = 0;
int h = *max_element(ar.begin(), ar.end());
auto fun = [&](int x) { // want the largest length to be x , minimize x
int cuts = 0;
for (const int i : ar) {
if (x >= i)
continue;
int rem = i - x;
cuts++;
if (rem > x)
cuts += ((rem + x - 1) / x - 1);
}
return cuts <= k;
};
while (l + 1 < h) {
int mid = (l + h) >> 1;
if (fun(mid))
h = mid;
else
l = mid;
}
cout << h << '\n';
return 0;
}
| replace | 15 | 16 | 15 | 16 | 0 | |
p02598 | C++ | Runtime Error |
#define INF 10000000000
#define MOD 1000000007
#if 1 // use_templates
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define rep(i, up) for (ll i = 0; i < (up); ++i)
#define repp(i, up) for (ll i = 0; i <= (up); ++i)
#define rrep(i, lo, up) for (ll i = (lo); i < (up); ++i)
#define rrepp(i, lo, up) for (ll i = (lo); i <= (up); ++i)
#define eep(i, lo, up) for ((i) = (lo); (i) < (up); ++(i))
#define eepp(i, lo, up) for ((i) = (lo); (i) <= (up); ++(i))
#define feach(it, vec) for (auto it = (vec).begin(); it != (vec).end(); ++it)
ll gcd(ll a, ll b);
ll gcd(ll a, ll b) {
if (a < b) {
return gcd(b, a);
}
ll r;
while (r = a % b) {
a = b;
b = r;
}
return b;
}
#endif // end of use_templates
ll sum(ll mid2, const vector<ll> &vec) {
ll r = 0;
rep(i, vec.size()) { r += (vec[i] * 2 + mid2 - 1) / mid2; }
return r;
}
int main() {
ll n, k;
cin >> n >> k;
k += n;
vector<ll> a(n);
rep(i, n) { cin >> a[i]; }
ll left2 = 0 * 2, right2 = 1000000001 * 2;
while (right2 - left2 > 1) {
ll mid2 = (left2 + right2) / 2;
ll s = sum(mid2, a);
if (s > k) {
left2 = mid2;
} else {
right2 = mid2;
}
}
if (sum(left2, a) <= k) {
cout << (left2 + 1) / 2 << endl;
} else {
cout << (right2 + 1) / 2 << endl;
}
return 0;
}
|
#define INF 10000000000
#define MOD 1000000007
#if 1 // use_templates
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define rep(i, up) for (ll i = 0; i < (up); ++i)
#define repp(i, up) for (ll i = 0; i <= (up); ++i)
#define rrep(i, lo, up) for (ll i = (lo); i < (up); ++i)
#define rrepp(i, lo, up) for (ll i = (lo); i <= (up); ++i)
#define eep(i, lo, up) for ((i) = (lo); (i) < (up); ++(i))
#define eepp(i, lo, up) for ((i) = (lo); (i) <= (up); ++(i))
#define feach(it, vec) for (auto it = (vec).begin(); it != (vec).end(); ++it)
ll gcd(ll a, ll b);
ll gcd(ll a, ll b) {
if (a < b) {
return gcd(b, a);
}
ll r;
while (r = a % b) {
a = b;
b = r;
}
return b;
}
#endif // end of use_templates
ll sum(ll mid2, const vector<ll> &vec) {
ll r = 0;
rep(i, vec.size()) { r += (vec[i] * 2 + mid2 - 1) / mid2; }
return r;
}
int main() {
ll n, k;
cin >> n >> k;
k += n;
vector<ll> a(n);
rep(i, n) { cin >> a[i]; }
ll left2 = 0 * 2, right2 = 1000000001 * 2;
while (right2 - left2 > 1) {
ll mid2 = (left2 + right2) / 2;
ll s = sum(mid2, a);
if (s > k) {
left2 = mid2;
} else {
right2 = mid2;
}
}
if (left2 == 0) {
cout << "1" << endl;
} else if (sum(left2, a) <= k) {
cout << (left2 + 1) / 2 << endl;
} else {
cout << (right2 + 1) / 2 << endl;
}
return 0;
}
| replace | 72 | 73 | 72 | 75 | 0 | |
p02598 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i, n) for (int i = 0; i < n; i++)
#define rev(i, n) for (int i = n; i >= 0; i--)
#define rep_a(i, a, n) for (int i = a; i < n; i++)
#define tr(ds, it) for (auto it = ds.begin(); it != ds.end(); it++)
#define rtr(ds, it) for (auto it = ds.rbegin(); it != ds.rend(); it--)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef priority_queue<int> pq;
typedef vector<long long> vi;
typedef pair<long long, long long> ii;
#define o_set \
tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update>
#define graph vector<vi>
#define Mod 1000000007
#define fastio \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define T \
int t; \
cin >> t; \
rep(i, t)
int binarysearch(int arr[], int n, int mid) {
int ans = 0;
rep(i, n) {
ans += arr[i] / mid;
if (arr[i] % mid == 0)
ans--;
}
return ans;
}
void solve() {
int n, k;
cin >> n >> k;
int arr[n];
int front = 0, end = 0;
rep(i, n) {
cin >> arr[i];
end = max(end, arr[i]);
}
while (front < end) {
int mid = front + (end - front) / 2;
int temp = binarysearch(arr, n, mid);
if (temp <= k)
end = mid;
else
front = mid + 1;
}
cout << end << "\n";
}
int main() {
fastio;
// T
solve();
// code
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i, n) for (int i = 0; i < n; i++)
#define rev(i, n) for (int i = n; i >= 0; i--)
#define rep_a(i, a, n) for (int i = a; i < n; i++)
#define tr(ds, it) for (auto it = ds.begin(); it != ds.end(); it++)
#define rtr(ds, it) for (auto it = ds.rbegin(); it != ds.rend(); it--)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef priority_queue<int> pq;
typedef vector<long long> vi;
typedef pair<long long, long long> ii;
#define o_set \
tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update>
#define graph vector<vi>
#define Mod 1000000007
#define fastio \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define T \
int t; \
cin >> t; \
rep(i, t)
int binarysearch(int arr[], int n, int mid) {
int ans = 0;
rep(i, n) {
ans += arr[i] / mid;
if (arr[i] % mid == 0)
ans--;
}
return ans;
}
void solve() {
int n, k;
cin >> n >> k;
int arr[n];
int front = 0, end = 0;
rep(i, n) {
cin >> arr[i];
end = max(end, arr[i]);
}
while (front < end) {
int mid = front + (end - front) / 2;
if (mid == 0)
break;
int temp = binarysearch(arr, n, mid);
if (temp <= k)
end = mid;
else
front = mid + 1;
}
cout << end << "\n";
}
int main() {
fastio;
// T
solve();
// code
return 0;
}
| insert | 63 | 63 | 63 | 66 | 0 | |
p02598 | C++ | Runtime Error | // #include <fsociety>
#include <algorithm>
#include <cmath>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// end of libraries ;
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// ll lmax(ll o , ll w) {if(o>w)return o; return w;}
// ll lmin(ll o , ll w) {if(o<w)return o; return w;}
#define LNF 3999999999999999999
#define INF 999999999
#define N 3000003
#define PI 3.14159265359
#define endl "\n"
#define F first
#define S second
#define pb push_back
#define ll long long
#define all(c) (c).begin(), (c).end()
#define sz(c) (c).size()
#define fcin ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
using namespace std;
ll n, k, a[N], ans;
int main() {
fcin;
cin >> n >> k;
for (ll i = 0; i < n; i++)
cin >> a[i];
ll l = 0, r = 10e10;
while (l <= r) {
ll mid = (l + r) / 2, c = 0;
for (ll i = 0; i < n; i++) {
if (a[i] < mid)
continue;
c += ((a[i] / mid + (a[i] % mid != 0)) - 1);
}
if (c > k) {
l = mid + 1;
} else {
ans = mid;
r = mid - 1;
}
}
cout << ans << "\n";
} | // #include <fsociety>
#include <algorithm>
#include <cmath>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// end of libraries ;
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// ll lmax(ll o , ll w) {if(o>w)return o; return w;}
// ll lmin(ll o , ll w) {if(o<w)return o; return w;}
#define LNF 3999999999999999999
#define INF 999999999
#define N 3000003
#define PI 3.14159265359
#define endl "\n"
#define F first
#define S second
#define pb push_back
#define ll long long
#define all(c) (c).begin(), (c).end()
#define sz(c) (c).size()
#define fcin ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
using namespace std;
ll n, k, a[N], ans;
int main() {
fcin;
cin >> n >> k;
for (ll i = 0; i < n; i++)
cin >> a[i];
ll l = 1, r = 10e8;
while (l <= r) {
ll mid = (l + r) / 2, c = 0;
for (ll i = 0; i < n; i++) {
if (a[i] < mid)
continue;
c += ((a[i] / mid + (a[i] % mid != 0)) - 1);
}
if (c > k) {
l = mid + 1;
} else {
ans = mid;
r = mid - 1;
}
}
cout << ans << "\n";
} | replace | 42 | 43 | 42 | 43 | 0 | |
p02598 | C++ | Runtime Error | #include <algorithm>
#include <climits>
#include <cmath>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define loopi(x, y) for (int i = x; i < (y); i++)
#define loopj(x, y) for (int j = x; j < (y); j++)
#define rloopi(x, y) for (int i = x; i >= (y); i--)
#define rloopj(x, y) for (int j = x; j >= (y); j--)
#define nl cout << "\n";
#define ll long long int
#define mod 1000000007
using namespace std;
int main() {
ios ::sync_with_stdio(false);
cin.tie(nullptr);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n, k;
cin >> n >> k;
vector<ll> a(n);
ll q = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] > q)
q = a[i];
}
ll p = 0;
while (p < q) {
ll mid = (p + q) / 2;
ll count = 0;
for (int i = 0; i < n; i++) {
count += (a[i] - 1) / mid;
}
if (count <= k) {
q = mid;
} else {
p = mid + 1;
}
}
cout << p;
return 0;
} | #include <algorithm>
#include <climits>
#include <cmath>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define loopi(x, y) for (int i = x; i < (y); i++)
#define loopj(x, y) for (int j = x; j < (y); j++)
#define rloopi(x, y) for (int i = x; i >= (y); i--)
#define rloopj(x, y) for (int j = x; j >= (y); j--)
#define nl cout << "\n";
#define ll long long int
#define mod 1000000007
using namespace std;
int main() {
ios ::sync_with_stdio(false);
cin.tie(nullptr);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n, k;
cin >> n >> k;
vector<ll> a(n);
ll q = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] > q)
q = a[i];
}
ll p = 1;
while (p < q) {
ll mid = (p + q) / 2;
ll count = 0;
for (int i = 0; i < n; i++) {
count += (a[i] - 1) / mid;
}
if (count <= k) {
q = mid;
} else {
p = mid + 1;
}
}
cout << p;
return 0;
} | replace | 45 | 46 | 45 | 46 | 0 | |
p02598 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n - 1); i >= 0; i--)
#define all(x) x.begin(), x.end()
#define br cout << "\n";
using namespace std;
const long long INF = 1e10;
const long long MOD = 1e9 + 7;
using Graph = vector<vector<ll>>;
using pll = pair<ll, ll>;
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;
}
// 0 false, 1 true
// string number to int : -48
// a to A : -32
// ceil(a) 1.2->2.0
// c++17 g++ -std=c++17 a.cpp
ll n, k;
vector<ll> vec(n);
// return the number of ng
// left always ng. right always ok
long long nibun_search(ll val) {
long long left = -1;
long long right = val;
while (right - left > 1) {
long long mid = (left + right) / 2;
if (mid == 0) {
mid = 1;
}
ll count = 0;
rep(i, n) {
if (vec[i] % mid == 0) {
count += ((vec[i] / mid) - 1);
} else {
count += (vec[i] / mid);
}
}
if (count <= k) {
right = mid;
} else {
left = mid;
}
}
return right;
}
int main() {
std::cout << std::fixed << std::setprecision(15);
cin >> n >> k;
vec.resize(n);
for (long long i = 0; i < n; i++) {
cin >> vec[i];
}
cout << nibun_search(1000000000) << endl;
} | #include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n - 1); i >= 0; i--)
#define all(x) x.begin(), x.end()
#define br cout << "\n";
using namespace std;
const long long INF = 1e10;
const long long MOD = 1e9 + 7;
using Graph = vector<vector<ll>>;
using pll = pair<ll, ll>;
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;
}
// 0 false, 1 true
// string number to int : -48
// a to A : -32
// ceil(a) 1.2->2.0
// c++17 g++ -std=c++17 a.cpp
ll n, k;
vector<ll> vec(n);
// return the number of ng
// left always ng. right always ok
long long nibun_search(ll val) {
long long left = -1;
long long right = val;
while (right - left > 1) {
long long mid = (left + right) / 2;
if (mid == 0) {
return 1;
}
ll count = 0;
rep(i, n) {
if (vec[i] % mid == 0) {
count += ((vec[i] / mid) - 1);
} else {
count += (vec[i] / mid);
}
}
if (count <= k) {
right = mid;
} else {
left = mid;
}
}
return right;
}
int main() {
std::cout << std::fixed << std::setprecision(15);
cin >> n >> k;
vec.resize(n);
for (long long i = 0; i < n; i++) {
cin >> vec[i];
}
cout << nibun_search(1000000000) << endl;
} | replace | 44 | 45 | 44 | 45 | TLE | |
p02598 | C++ | Runtime Error | /* [Template].cpp
Example code to use when starting new code. This particular problem was problem
977A_Wrong_Subtraction from CodeForces
Compile: g++ -o E.exe E.cpp
Execute: ./E
*/
/* Solution sketch
E: Use (integer) binary search on the answer. Suppose the answer is X
(0≤X≤10^9). Then go through all logs Ai and count how many splits Ki you need to
get the length of each of them under X, using the equation Ai/(Ki+1)=X. There's
some funky arithmetic with the rounding, which I'm unsure of, but it works.
Code.
Code: https://atcoder.jp/contests/abc174/submissions/15619338
*/
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <limits>
#include <queue>
#include <string>
using namespace std;
// Global variables for convenience
int n, k, a[200000];
int find_k(int x) {
int result = 0;
int k0;
for (int i = 0; i < n; i++) {
// Compute using integer arithmetic: ceil(Ai/X) - 1
if (a[i] % x == 0) {
k0 = a[i] / x - 1;
} else {
k0 = a[i] / x;
}
result += k0;
}
return result;
}
/* Integer binary search for this problem.
Precondition: f(a) > target & f(b) <= target.
*/
int binary_search(int a, int b, int target) {
int m = a + (b - a) / 2, fm = find_k(m);
// Base case: end of search
if (b == a || b == a + 1)
return b;
// Recursive cases
if (fm > target)
return binary_search(m, b, target);
else
return binary_search(a, m, target);
}
int main() {
// Input
cin >> n >> k;
for (int i = 0; i < n; i++)
cin >> a[i];
// Binary search
int a = 0, b = 1000000001;
cout << binary_search(a, b, k) << endl;
return 0;
}
| /* [Template].cpp
Example code to use when starting new code. This particular problem was problem
977A_Wrong_Subtraction from CodeForces
Compile: g++ -o E.exe E.cpp
Execute: ./E
*/
/* Solution sketch
E: Use (integer) binary search on the answer. Suppose the answer is X
(0≤X≤10^9). Then go through all logs Ai and count how many splits Ki you need to
get the length of each of them under X, using the equation Ai/(Ki+1)=X. There's
some funky arithmetic with the rounding, which I'm unsure of, but it works.
Code.
Code: https://atcoder.jp/contests/abc174/submissions/15619338
*/
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <limits>
#include <queue>
#include <string>
using namespace std;
// Global variables for convenience
int n, k, a[200000];
int find_k(int x) {
int result = 0;
int k0;
for (int i = 0; i < n; i++) {
// Compute using integer arithmetic: ceil(Ai/X) - 1
if (a[i] % x == 0) {
k0 = a[i] / x - 1;
} else {
k0 = a[i] / x;
}
result += k0;
}
return result;
}
/* Integer binary search for this problem.
Precondition: f(a) > target & f(b) <= target.
*/
int binary_search(int a, int b, int target) {
int m = a + (b - a) / 2;
if (m == 0)
return 1;
int fm = find_k(m);
// Base case: end of search
if (b == a || b == a + 1)
return b;
// Recursive cases
if (fm > target)
return binary_search(m, b, target);
else
return binary_search(a, m, target);
}
int main() {
// Input
cin >> n >> k;
for (int i = 0; i < n; i++)
cin >> a[i];
// Binary search
int a = 0, b = 1000000001;
cout << binary_search(a, b, k) << endl;
return 0;
}
| replace | 53 | 54 | 53 | 59 | 0 | |
p02598 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#define N 1000000007
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
int n;
ll k;
cin >> n >> k;
vector<ll> a(n);
ll sum = 0;
ll max_a = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
max_a = max(max_a, a[i]);
}
ll bound_max = max_a;
ll bound_min = sum / (n + k);
ll cur = (bound_max + bound_min) / 2;
while (true) {
if (bound_max - bound_min == 1)
break;
ll ncut = 0;
for (int i = 0; i < n; i++) {
if (a[i] <= cur)
continue;
ll m = a[i] / cur + (a[i] % cur ? 1 : 0);
ncut += m - 1;
}
if (ncut <= k) {
bound_max = cur;
} else {
bound_min = cur;
}
cur = (bound_max + bound_min) / 2;
}
cout << bound_max << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#define N 1000000007
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
int n;
ll k;
cin >> n >> k;
vector<ll> a(n);
ll sum = 0;
ll max_a = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
max_a = max(max_a, a[i]);
}
ll bound_max = max_a;
ll bound_min = sum / (n + k);
ll cur = (bound_max + bound_min) / 2;
while (true) {
if (bound_min + 1 >= bound_max)
break;
ll ncut = 0;
for (int i = 0; i < n; i++) {
if (a[i] <= cur)
continue;
ll m = a[i] / cur + (a[i] % cur ? 1 : 0);
ncut += m - 1;
}
if (ncut <= k) {
bound_max = cur;
} else {
bound_min = cur;
}
cur = (bound_max + bound_min) / 2;
}
cout << bound_max << endl;
return 0;
} | replace | 29 | 30 | 29 | 30 | TLE | |
p02598 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mem(a, b) memset(a, b, sizeof(a))
#define all(x) (x).begin(), (x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
inline void normal(ll &a) {
a %= MOD;
(a < 0) && (a += MOD);
}
inline ll modMul(ll a, ll b) {
a %= MOD, b %= MOD;
normal(a), normal(b);
return (a * b) % MOD;
}
inline ll modAdd(ll a, ll b) {
a %= MOD, b %= MOD;
normal(a), normal(b);
return (a + b) % MOD;
}
inline ll modSub(ll a, ll b) {
a %= MOD, b %= MOD;
normal(a), normal(b);
a -= b;
normal(a);
return a;
}
inline ll modPow(ll b, ll p) {
ll r = 1;
while (p) {
if (p & 1)
r = modMul(r, b);
b = modMul(b, b);
p >>= 1;
}
return r;
}
inline ll modInverse(ll a) { return modPow(a, MOD - 2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main() {
ll n, k;
cin >> n >> k;
vl a(n);
rep(i, n) cin >> a[i];
ll r = 1e18, l = 0;
while (r - l > 1) {
ll m = (r + l) / 2;
ll cnt = 0;
rep(i, n) {
cnt += a[i] / m;
if (a[i] % m == 0 && a[i] >= m)
cnt--;
}
if (cnt > k)
l = m;
else
r = m;
}
ll cnt = 0;
rep(i, n) {
cnt += a[i] / l;
if (a[i] % l == 0 && a[i] >= l)
cnt--;
}
if (cnt > k)
cout << r << endl;
else
cout << l << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mem(a, b) memset(a, b, sizeof(a))
#define all(x) (x).begin(), (x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
inline void normal(ll &a) {
a %= MOD;
(a < 0) && (a += MOD);
}
inline ll modMul(ll a, ll b) {
a %= MOD, b %= MOD;
normal(a), normal(b);
return (a * b) % MOD;
}
inline ll modAdd(ll a, ll b) {
a %= MOD, b %= MOD;
normal(a), normal(b);
return (a + b) % MOD;
}
inline ll modSub(ll a, ll b) {
a %= MOD, b %= MOD;
normal(a), normal(b);
a -= b;
normal(a);
return a;
}
inline ll modPow(ll b, ll p) {
ll r = 1;
while (p) {
if (p & 1)
r = modMul(r, b);
b = modMul(b, b);
p >>= 1;
}
return r;
}
inline ll modInverse(ll a) { return modPow(a, MOD - 2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main() {
ll n, k;
cin >> n >> k;
vl a(n);
rep(i, n) cin >> a[i];
ll r = 1e18, l = 0;
while (r - l > 1) {
ll m = (r + l) / 2;
ll cnt = 0;
rep(i, n) {
cnt += a[i] / m;
if (a[i] % m == 0 && a[i] >= m)
cnt--;
}
if (cnt > k)
l = m;
else
r = m;
}
if (l != 0) {
ll cnt = 0;
rep(i, n) {
cnt += a[i] / l;
if (a[i] % l == 0 && a[i] >= l)
cnt--;
}
if (cnt > k)
cout << r << endl;
else
cout << l << endl;
} else
cout << 1 << endl;
}
| replace | 83 | 93 | 83 | 96 | 0 | |
p02598 | C++ | Runtime Error | // #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
//----------------------- Print Function ----------------------//
inline void print() { cout << endl; }
template <typename First, typename... Rest>
void print(const First &first, const Rest &...rest) {
cout << first << ' ';
print(rest...);
}
template <typename T> void print(const vector<T> &v) {
for (auto e : v)
cout << e << ' ';
cout << endl;
}
//------------------------- Libraries -------------------------//
//--------------------------- Solve ---------------------------//
long long N, K;
vector<long long> A;
bool isOK(long long mid) {
long long k = 0;
for (int i = 0; i < N; i++) {
k += (A[i] - 1) / mid;
}
if (k <= K)
return true;
else
return false;
}
void solve() {
cin >> N >> K;
A.resize(N);
long long ma = 0;
for (int i = 0; i < N; i++) {
cin >> A[i];
ma = max(ma, A[i]);
}
long long ok = ma;
long long ng = -1;
while (abs(ok - ng) > 1) {
long long mid = (ok + ng) / 2;
if (isOK(mid))
ok = mid;
else
ng = mid;
}
cout << ok << '\n';
}
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
solve();
return 0;
} | // #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
//----------------------- Print Function ----------------------//
inline void print() { cout << endl; }
template <typename First, typename... Rest>
void print(const First &first, const Rest &...rest) {
cout << first << ' ';
print(rest...);
}
template <typename T> void print(const vector<T> &v) {
for (auto e : v)
cout << e << ' ';
cout << endl;
}
//------------------------- Libraries -------------------------//
//--------------------------- Solve ---------------------------//
long long N, K;
vector<long long> A;
bool isOK(long long mid) {
long long k = 0;
for (int i = 0; i < N; i++) {
k += (A[i] - 1) / mid;
}
if (k <= K)
return true;
else
return false;
}
void solve() {
cin >> N >> K;
A.resize(N);
long long ma = 0;
for (int i = 0; i < N; i++) {
cin >> A[i];
ma = max(ma, A[i]);
}
long long ok = ma;
long long ng = 0;
while (abs(ok - ng) > 1) {
long long mid = (ok + ng) / 2;
if (isOK(mid))
ok = mid;
else
ng = mid;
}
cout << ok << '\n';
}
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
solve();
return 0;
} | replace | 48 | 49 | 48 | 49 | 0 | |
p02598 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;
template <typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <typename T> map<T, T> getPrimeFactor(T n) {
map<T, T> res;
for (T i = 2; i * i <= n; ++i) {
while (n % i == 0) {
res[i]++;
n /= i;
}
}
if (n != 1)
res[n] = 1;
return res;
}
template <typename T> bool IsPrimeNumber(T num) {
if (num <= 2)
return true;
else if (num % 2 == 0)
return false;
double sqrtNum = sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0) {
return false;
}
}
return true;
}
long long modinv(long long a, long long m) {
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 pow2(ll n, ll p, ll mod) {
if (p == 0 || n == 1) {
return 1;
} else {
ll ret = pow2(n * n % mod, p / 2, mod);
if (p % 2 == 1) {
ret *= n;
}
return ret % mod;
}
}
#define rep(i, s, e) for (ll i = s; i < e; i++)
#define repeq(i, s, e) for (ll i = s; i <= e; i++)
int main() {
ll N, K;
cin >> N >> K;
priority_queue<ll> pq;
rep(i, 0, N) {
ll a;
cin >> a;
pq.push(a);
}
ll l_min = 0;
ll l_max = pq.top();
ll ans;
while (l_min != l_max) {
ans = (l_max - l_min) / 2 + l_min;
priority_queue<ll> pq2 = pq;
ll cnt = 0;
while (cnt <= K && !pq2.empty() && ans < pq2.top()) {
cnt += (pq2.top() - 1) / ans;
pq2.pop();
}
if (cnt > K) {
l_min = ans + 1;
} else {
l_max = ans;
}
}
ans = l_min;
cout << ans << endl;
}
| #include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;
template <typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <typename T> map<T, T> getPrimeFactor(T n) {
map<T, T> res;
for (T i = 2; i * i <= n; ++i) {
while (n % i == 0) {
res[i]++;
n /= i;
}
}
if (n != 1)
res[n] = 1;
return res;
}
template <typename T> bool IsPrimeNumber(T num) {
if (num <= 2)
return true;
else if (num % 2 == 0)
return false;
double sqrtNum = sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0) {
return false;
}
}
return true;
}
long long modinv(long long a, long long m) {
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 pow2(ll n, ll p, ll mod) {
if (p == 0 || n == 1) {
return 1;
} else {
ll ret = pow2(n * n % mod, p / 2, mod);
if (p % 2 == 1) {
ret *= n;
}
return ret % mod;
}
}
#define rep(i, s, e) for (ll i = s; i < e; i++)
#define repeq(i, s, e) for (ll i = s; i <= e; i++)
int main() {
ll N, K;
cin >> N >> K;
priority_queue<ll> pq;
rep(i, 0, N) {
ll a;
cin >> a;
pq.push(a);
}
ll l_min = 1;
ll l_max = pq.top();
ll ans;
while (l_min != l_max) {
ans = (l_max - l_min) / 2 + l_min;
priority_queue<ll> pq2 = pq;
ll cnt = 0;
while (cnt <= K && !pq2.empty() && ans < pq2.top()) {
cnt += (pq2.top() - 1) / ans;
pq2.pop();
}
if (cnt > K) {
l_min = ans + 1;
} else {
l_max = ans;
}
}
ans = l_min;
cout << ans << endl;
}
| replace | 94 | 95 | 94 | 95 | 0 | |
p02598 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
/* template */
using ll = long long;
void debug_out() { std::cout << std::endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
cout << H << " ";
debug_out(T...);
}
#ifdef LOCAL
#define debug(...) \
cout << "debug: "; \
debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n - 1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i < (long long)(n); i++)
#define RRep(i, a, n) \
for (long long i = ((long long)(n - 1ll)); i >= (long long)(a); i--)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
template <typename T>
std::ostream &operator<<(std::ostream &os, std::vector<T> vec) {
for (std::size_t i = 0; i < vec.size(); i++)
os << vec[i] << (i + 1 == vec.size() ? "" : " ");
return os;
}
struct Edge {
int to;
ll weight;
Edge(int t, ll w) : to(t), weight(w) {}
};
struct edge {
int from;
int to;
ll weight;
edge(int f, int t, ll w) : from(f), to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;
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;
}
template <class T> T lcm(T a, T b) { return (a * b) / gcd(a, b); }
ll ctoi(char c) {
switch (c) {
case '0':
return 0;
case '1':
return 1;
case '2':
return 2;
case '3':
return 3;
case '4':
return 4;
case '5':
return 5;
case '6':
return 6;
case '7':
return 7;
case '8':
return 8;
case '9':
return 9;
default:
return 0;
}
}
constexpr ll LNF = 1LL << 50;
constexpr int INF = 1e9 + 7;
const long double PI = 3.14159265358979323846;
vector<int> dx = {1, 0, -1, 1, -1, 0};
vector<int> dy = {1, 1, 1, 0, 0, -1};
/* template */
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n;
ll k;
cin >> n >> k;
vector<ll> a(n);
rep(i, 0, n) cin >> a[i];
ll ng = -1;
ll ok = 1e9 + 7;
while (abs(ok - ng) > 1ll) {
ll mid = (ok + ng) / 2ll;
int c = k;
rep(i, 0, n) {
if (mid >= a[i])
continue;
c -= a[i] / mid;
}
if (c < 0) {
ng = mid;
} else {
ok = mid;
}
}
cout << ok << endl;
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
/* template */
using ll = long long;
void debug_out() { std::cout << std::endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
cout << H << " ";
debug_out(T...);
}
#ifdef LOCAL
#define debug(...) \
cout << "debug: "; \
debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n - 1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i < (long long)(n); i++)
#define RRep(i, a, n) \
for (long long i = ((long long)(n - 1ll)); i >= (long long)(a); i--)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
template <typename T>
std::ostream &operator<<(std::ostream &os, std::vector<T> vec) {
for (std::size_t i = 0; i < vec.size(); i++)
os << vec[i] << (i + 1 == vec.size() ? "" : " ");
return os;
}
struct Edge {
int to;
ll weight;
Edge(int t, ll w) : to(t), weight(w) {}
};
struct edge {
int from;
int to;
ll weight;
edge(int f, int t, ll w) : from(f), to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;
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;
}
template <class T> T lcm(T a, T b) { return (a * b) / gcd(a, b); }
ll ctoi(char c) {
switch (c) {
case '0':
return 0;
case '1':
return 1;
case '2':
return 2;
case '3':
return 3;
case '4':
return 4;
case '5':
return 5;
case '6':
return 6;
case '7':
return 7;
case '8':
return 8;
case '9':
return 9;
default:
return 0;
}
}
constexpr ll LNF = 1LL << 50;
constexpr int INF = 1e9 + 7;
const long double PI = 3.14159265358979323846;
vector<int> dx = {1, 0, -1, 1, -1, 0};
vector<int> dy = {1, 1, 1, 0, 0, -1};
/* template */
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n;
ll k;
cin >> n >> k;
vector<ll> a(n);
rep(i, 0, n) cin >> a[i];
ll ng = -1;
ll ok = 1e9 + 7;
while (abs(ok - ng) > 1ll) {
ll mid = (ok + ng) / 2ll;
int c = k;
if (mid <= 1) {
ok = 1;
break;
}
rep(i, 0, n) {
if (mid >= a[i])
continue;
c -= a[i] / mid;
}
if (c < 0) {
ng = mid;
} else {
ok = mid;
}
}
cout << ok << endl;
} | insert | 143 | 143 | 143 | 147 | 0 | |
p02598 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define all(s) (s).begin(), (s).end()
ll n, k;
vl logs;
bool test(ll target) {
ll output = 0;
for (ll curr : logs) {
if (target + curr - 1 == 0)
cout << "blub" << endl;
output += ((target + curr - 1) / target) - 1;
}
return output <= k;
}
int main() {
cin >> n >> k;
ll mini = 0;
ll maxi = 0;
FOR(i, 0, n) {
ll next;
cin >> next;
logs.push_back(next);
maxi = max(maxi, next);
}
while (abs(maxi - mini) >= 1) {
ll mid = (maxi + mini) / 2;
if (test(mid)) {
maxi = mid;
} else {
mini = mid + 1;
}
}
cout << maxi << endl;
/*FOR(i, 0, k) {
ll next = logs.top();
logs.pop();
ll a, b;
ll other = logs.top();
if(other == next) {
a = next / 2;
b = next - a;
} else {
a = other;
b = next - a;
}
a = next / 2;
b = next - a;
cerr << a << " " << b << endl;
logs.push(a);
logs.push(b);
}*/
/*while(!logs.empty()) {
cout << logs.top() << endl;
logs.pop();
}*/
// cout << logs.top() << endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define all(s) (s).begin(), (s).end()
ll n, k;
vl logs;
bool test(ll target) {
ll output = 0;
for (ll curr : logs) {
if (target + curr - 1 == 0)
cout << "blub" << endl;
output += ((target + curr - 1) / target) - 1;
}
return output <= k;
}
int main() {
cin >> n >> k;
ll mini = 1;
ll maxi = 0;
FOR(i, 0, n) {
ll next;
cin >> next;
logs.push_back(next);
maxi = max(maxi, next);
}
while (abs(maxi - mini) >= 1) {
ll mid = (maxi + mini) / 2;
if (test(mid)) {
maxi = mid;
} else {
mini = mid + 1;
}
}
cout << maxi << endl;
/*FOR(i, 0, k) {
ll next = logs.top();
logs.pop();
ll a, b;
ll other = logs.top();
if(other == next) {
a = next / 2;
b = next - a;
} else {
a = other;
b = next - a;
}
a = next / 2;
b = next - a;
cerr << a << " " << b << endl;
logs.push(a);
logs.push(b);
}*/
/*while(!logs.empty()) {
cout << logs.top() << endl;
logs.pop();
}*/
// cout << logs.top() << endl;
} | replace | 25 | 26 | 25 | 26 | 0 | |
p02598 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0), ios::sync_with_stdio(false);
int n, k;
cin >> n >> k;
vector<int> a(n);
for (auto &&i : a)
cin >> i;
int L = -1, R = *max_element(a.begin(), a.end());
while (R - L > 1) {
int M = (L + R) / 2;
int cnt = 0;
for (auto &&i : a)
cnt += (i - 1) / M;
if (cnt > k)
L = M;
else
R = M;
}
cout << R << "\n"s;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0), ios::sync_with_stdio(false);
int n, k;
cin >> n >> k;
vector<int> a(n);
for (auto &&i : a)
cin >> i;
int L = 0, R = *max_element(a.begin(), a.end());
while (R - L > 1) {
int M = (L + R) / 2;
int cnt = 0;
for (auto &&i : a)
cnt += (i - 1) / M;
if (cnt > k)
L = M;
else
R = M;
}
cout << R << "\n"s;
}
| replace | 10 | 11 | 10 | 11 | 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 < n; i++)
int main() {
int n, k;
cin >> n >> k;
vector<int> a(n);
rep(i, n) cin >> a[i];
int start = 0;
int end = 1000000001;
int ans = 1000000000;
while (start != end) {
int mid = (start + end) / 2;
int count = 0;
rep(i, n) {
if (a[i] % mid == 0)
count += a[i] / mid;
else
count += a[i] / mid + 1;
count--;
}
if (count > k)
start = mid + 1;
else {
ans = min(mid, ans);
end = mid;
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
int main() {
int n, k;
cin >> n >> k;
vector<int> a(n);
rep(i, n) cin >> a[i];
int start = 1;
int end = 1000000001;
int ans = 1000000000;
while (start != end) {
int mid = (start + end) / 2;
int count = 0;
rep(i, n) {
if (a[i] % mid == 0)
count += a[i] / mid;
else
count += a[i] / mid + 1;
count--;
}
if (count > k)
start = mid + 1;
else {
ans = min(mid, ans);
end = mid;
}
}
cout << ans << endl;
}
| replace | 9 | 10 | 9 | 10 | 0 | |
p02598 | C++ | Runtime Error | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
const int MAX = 200000;
int N, K;
int A[MAX];
bool check(int len) {
int c = 0;
for (int i = 0; i < N; i++) {
c += (A[i] - 1) / len;
}
return c <= K;
}
int main() {
cin >> N >> K;
for (int i = 0; i < N; i++) {
cin >> A[i];
}
int l = 0;
int r = pow(10, 9);
int m = 0;
int ans = pow(10, 9);
while (l < r) {
m = (l + r) / 2;
if (check(m)) {
r = m;
ans = min(ans, m);
} else {
l = m + 1;
}
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
const int MAX = 200000;
int N, K;
int A[MAX];
bool check(int len) {
int c = 0;
for (int i = 0; i < N; i++) {
c += (A[i] - 1) / len;
}
return c <= K;
}
int main() {
cin >> N >> K;
for (int i = 0; i < N; i++) {
cin >> A[i];
}
int l = 1;
int r = pow(10, 9);
int m = 0;
int ans = pow(10, 9);
while (l < r) {
m = (l + r) / 2;
if (check(m)) {
r = m;
ans = min(ans, m);
} else {
l = m + 1;
}
}
cout << ans << endl;
return 0;
} | replace | 32 | 33 | 32 | 33 | 0 | |
p02598 | C++ | Runtime Error | #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
ll INF = 1ll << 60;
vi a;
void chmax(int &a, int b) {
if (a < b)
a = b;
}
bool is_ok(int x, int k) {
int sum = 0;
rep(i, 0, a.size()) { sum += (a[i] + (x - 1)) / x - 1; }
if (k >= sum)
return true;
else
return false;
}
int binary_search(int key, int amax) {
int ng = -1;
int ok = amax;
while (abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (is_ok(mid, key))
ok = mid;
else
ng = mid;
}
return ok;
}
int main() {
int n, k;
cin >> n >> k;
int amax = 0;
rep(i, 0, n) {
int tmp;
cin >> tmp;
a.push_back(tmp);
chmax(amax, tmp);
}
int ans = binary_search(k, amax);
cout << ans << endl;
return 0;
} | #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
ll INF = 1ll << 60;
vi a;
void chmax(int &a, int b) {
if (a < b)
a = b;
}
bool is_ok(int x, int k) {
int sum = 0;
rep(i, 0, a.size()) { sum += (a[i] + (x - 1)) / x - 1; }
if (k >= sum)
return true;
else
return false;
}
int binary_search(int key, int amax) {
int ng = 0;
int ok = amax;
while (abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (is_ok(mid, key))
ok = mid;
else
ng = mid;
}
return ok;
}
int main() {
int n, k;
cin >> n >> k;
int amax = 0;
rep(i, 0, n) {
int tmp;
cin >> tmp;
a.push_back(tmp);
chmax(amax, tmp);
}
int ans = binary_search(k, amax);
cout << ans << endl;
return 0;
} | replace | 34 | 35 | 34 | 35 | 0 | |
p02598 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
ll n, p, q, x, y, i, k, a, b;
cin >> n >> k;
ll ara[n];
for (i = 0; i < n; i++)
cin >> ara[i];
if (k == 0) {
cout << *max_element(ara, ara + n) << endl;
return 0;
}
ll mx = 1e18 + 100;
ll l = 0, r = mx;
bool bl = false;
while (l <= r) {
ll mid = (l + r) / 2ll;
ll tot = 0;
for (i = 0; i < n; i++) {
ll x = (ara[i] - 1) / mid;
tot += x;
}
if (tot <= k)
mx = min(mx, mid), r = mid - 1;
else
l = mid + 1;
}
cout << mx << '\n';
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
ll n, p, q, x, y, i, k, a, b;
cin >> n >> k;
ll ara[n];
for (i = 0; i < n; i++)
cin >> ara[i];
if (k == 0) {
cout << *max_element(ara, ara + n) << endl;
return 0;
}
ll mx = 1e18 + 100;
ll l = 1, r = mx;
bool bl = false;
while (l <= r) {
ll mid = (l + r) / 2ll;
ll tot = 0;
for (i = 0; i < n; i++) {
ll x = (ara[i] - 1) / mid;
tot += x;
}
if (tot <= k)
mx = min(mx, mid), r = mid - 1;
else
l = mid + 1;
}
cout << mx << '\n';
}
| replace | 19 | 20 | 19 | 20 | 0 | |
p02598 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int cut_times(int *logs, int n, int min_length) {
int ans = 0;
for (int i = 0; i < n; i++) {
ans += (logs[i] - 1) / min_length;
}
return ans;
}
int main() {
int n, k;
cin >> n >> k;
int a[n];
for (int i = 0; i < n; i++)
cin >> a[i];
// sort(a, a+n, greater<int>());
int left = 0;
int right = 1000000000;
while (left < right) {
int mid = (left + right) / 2;
if (cut_times(a, n, mid) > k) {
left = mid + 1;
} else if (cut_times(a, n, mid) <= k) {
right = mid;
}
}
cout << left << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int cut_times(int *logs, int n, int min_length) {
int ans = 0;
for (int i = 0; i < n; i++) {
ans += (logs[i] - 1) / min_length;
}
return ans;
}
int main() {
int n, k;
cin >> n >> k;
int a[n];
for (int i = 0; i < n; i++)
cin >> a[i];
// sort(a, a+n, greater<int>());
int left = 1;
int right = 1000000000;
while (left < right) {
int mid = (left + right) / 2;
if (cut_times(a, n, mid) > k) {
left = mid + 1;
} else if (cut_times(a, n, mid) <= k) {
right = mid;
}
}
cout << left << endl;
return 0;
} | replace | 21 | 22 | 21 | 22 | 0 | |
p02598 | C++ | Runtime Error | // #include<bits/stdc++.h>
// using namespace std;
// #define mem(a) memset(a,0,sizeof(a))
// #define dbg(x) cout<<#x<<" = "<<x<<endl
// #define ll long long
////不要再爆long long了!!!!!!!!不要再爆long long了!!!!!!!
// multiset<double>s;
// void prt()
//{
// for(multiset<double>::iterator it=s.begin();it!=s.end();it++)
// {
// prllf("%lf ",*it);
// }
// cout<<endl;
// }
// ll main()
//{
// ll n,k;
// cin>>n>>k;
// for(ll i=0;i<n;i++)
// {
// double t;
// scanf("%lf",&t);
// s.insert(t);
// prt();//************
// }
// for(ll i=0;i<k;i++)
// {
// multiset<double>::iterator it=--s.end();
// double t=*it;
// s.erase(it);
// t/=2;
// s.insert(t),s.insert(t);
// prt();//************
// }
// double t=*(--s.end());
// ll a=t;
// if(t-a>=0.5)a++;
// prllf("%d\n",a);
// return 0;
// }
#include <bits/stdc++.h>
using namespace std;
#define mem(a) memset(a, 0, sizeof(a))
#define dbg(x) cout << #x << " = " << x << endl
#define ll long long
// 不要再爆long long了!!!!!!!!不要再爆long long了!!!!!!!
ll len[200010];
ll M = 0, n, k;
ll erfen() {
ll m = 0, mid;
if (!k)
return M;
while (M > m) {
mid = (M + m) >> 1;
ll s = 0;
for (ll i = 0; i < n; i++) {
if (len[i] <= mid)
continue;
// //ll t=1.*len[i]/(1.*mid+0.5)-1;
// if(t<=0)t=1;
// long double l=1.*len[i]/(t+1);
// if(l-0.5>=mid)t++;
// s+=t;
ll t = len[i] / (mid);
if (t * (mid) == len[i])
t--;
s += t;
}
// printf("m=%d M=%d mid=%d s=%d\n",m,M,mid,s);
if (s > k)
m = mid + 1;
else
M = mid;
}
return (M + m) / 2;
}
int main() {
cin >> n >> k;
for (ll i = 0; i < n; i++) {
scanf("%lld", &len[i]);
M = (len[i] > M ? len[i] : M);
}
printf("%lld\n", erfen());
return 0;
} | // #include<bits/stdc++.h>
// using namespace std;
// #define mem(a) memset(a,0,sizeof(a))
// #define dbg(x) cout<<#x<<" = "<<x<<endl
// #define ll long long
////不要再爆long long了!!!!!!!!不要再爆long long了!!!!!!!
// multiset<double>s;
// void prt()
//{
// for(multiset<double>::iterator it=s.begin();it!=s.end();it++)
// {
// prllf("%lf ",*it);
// }
// cout<<endl;
// }
// ll main()
//{
// ll n,k;
// cin>>n>>k;
// for(ll i=0;i<n;i++)
// {
// double t;
// scanf("%lf",&t);
// s.insert(t);
// prt();//************
// }
// for(ll i=0;i<k;i++)
// {
// multiset<double>::iterator it=--s.end();
// double t=*it;
// s.erase(it);
// t/=2;
// s.insert(t),s.insert(t);
// prt();//************
// }
// double t=*(--s.end());
// ll a=t;
// if(t-a>=0.5)a++;
// prllf("%d\n",a);
// return 0;
// }
#include <bits/stdc++.h>
using namespace std;
#define mem(a) memset(a, 0, sizeof(a))
#define dbg(x) cout << #x << " = " << x << endl
#define ll long long
// 不要再爆long long了!!!!!!!!不要再爆long long了!!!!!!!
ll len[200010];
ll M = 0, n, k;
ll erfen() {
ll m = 0, mid;
if (!k)
return M;
while (M > m) {
mid = (M + m) >> 1;
ll s = 0;
for (ll i = 0; i < n; i++) {
if (len[i] <= mid)
continue;
// //ll t=1.*len[i]/(1.*mid+0.5)-1;
// if(t<=0)t=1;
// long double l=1.*len[i]/(t+1);
// if(l-0.5>=mid)t++;
// s+=t;
if (mid == 0) {
s = k + 1;
continue;
}
ll t = len[i] / (mid);
if (t * (mid) == len[i])
t--;
s += t;
}
// printf("m=%d M=%d mid=%d s=%d\n",m,M,mid,s);
if (s > k)
m = mid + 1;
else
M = mid;
}
return (M + m) / 2;
}
int main() {
cin >> n >> k;
for (ll i = 0; i < n; i++) {
scanf("%lld", &len[i]);
M = (len[i] > M ? len[i] : M);
}
printf("%lld\n", erfen());
return 0;
} | replace | 65 | 66 | 65 | 69 | 0 | |
p02598 | C++ | Runtime Error | #include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
bool check(int n, vector<ll> &a, ll k, ll x) {
ll cnt = 0;
for (int i = 0; i < n; i++)
cnt += (a[i] + x - 1) / x - 1;
return k >= cnt;
}
int main() {
int n;
cin >> n;
ll k;
cin >> k;
vector<ll> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
ll l = -1, r = 1e9, m;
while (r - l > 1) {
m = (r + l) / 2;
if (check(n, a, k, m))
r = m;
else
l = m;
}
cout << r << endl;
return 0;
} | #include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
bool check(int n, vector<ll> &a, ll k, ll x) {
ll cnt = 0;
for (int i = 0; i < n; i++)
cnt += (a[i] + x - 1) / x - 1;
return k >= cnt;
}
int main() {
int n;
cin >> n;
ll k;
cin >> k;
vector<ll> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
ll l = 0, r = 1e9, m;
while (r - l > 1) {
m = (r + l) / 2;
if (check(n, a, k, m))
r = m;
else
l = m;
}
cout << r << endl;
return 0;
} | replace | 33 | 34 | 33 | 34 | 0 | |
p02598 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i <= n; ++i)
#define F first
#define S second
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
using ll = long long;
using pi = pair<int, int>;
using ld = long double;
int main() {
int n, k;
cin >> n >> k;
vector<int> a(n);
rep(i, n) cin >> a[i];
int lb = -1, ub = 1e+9 + 1;
while (ub - lb > 1) {
int mid = (ub + lb) / 2;
int cnt = 0;
rep(i, n) { cnt += (a[i] - 1) / mid; }
(cnt <= k ? ub : lb) = mid;
}
cout << ub << "\n";
return 0;
}
| #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i <= n; ++i)
#define F first
#define S second
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
using ll = long long;
using pi = pair<int, int>;
using ld = long double;
int main() {
int n, k;
cin >> n >> k;
vector<int> a(n);
rep(i, n) cin >> a[i];
int lb = 0, ub = 1e+9 + 1;
while (ub - lb > 1) {
int mid = (ub + lb) / 2;
int cnt = 0;
rep(i, n) { cnt += (a[i] - 1) / mid; }
(cnt <= k ? ub : lb) = mid;
}
cout << ub << "\n";
return 0;
}
| replace | 37 | 38 | 37 | 38 | 0 | |
p02598 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int nax = 2e5 + 10;
int n, k;
int a[nax];
int main() {
cin.tie(0)->sync_with_stdio(false);
cin >> n >> k;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
int l = 0, r = 1e9;
int ans = -1;
while (l <= r) {
int mid = l + r >> 1;
long long tot = 0;
for (int i = 1; i <= n; ++i) {
tot += max(0, (a[i] - 1) / mid);
}
if (tot <= k) {
ans = mid;
r = mid - 1;
} else
l = mid + 1;
}
assert(ans != -1);
cout << ans << '\n';
}
| #include <bits/stdc++.h>
using namespace std;
const int nax = 2e5 + 10;
int n, k;
int a[nax];
int main() {
cin.tie(0)->sync_with_stdio(false);
cin >> n >> k;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
int l = 1, r = 1e9;
int ans = -1;
while (l <= r) {
int mid = l + r >> 1;
long long tot = 0;
for (int i = 1; i <= n; ++i) {
tot += max(0, (a[i] - 1) / mid);
}
if (tot <= k) {
ans = mid;
r = mid - 1;
} else
l = mid + 1;
}
assert(ans != -1);
cout << ans << '\n';
}
| replace | 14 | 15 | 14 | 15 | 0 | |
p02598 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
using namespace std;
using namespace __gnu_pbds;
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
indexed_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int n;
ll k;
cin >> n >> k;
vector<ll> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
ll lo = 0, hi = 2e9, opt = -1;
while (lo <= hi) {
ll mid = (lo + hi) >> 1, sum = 0;
for (int i = 0; i < n; i++)
sum += (a[i] + mid - 1) / mid - 1;
if (sum <= k) {
opt = mid;
hi = mid - 1;
} else
lo = mid + 1;
}
cout << opt << endl;
return 0;
} | #include <bits/stdc++.h>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
using namespace std;
using namespace __gnu_pbds;
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
indexed_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int n;
ll k;
cin >> n >> k;
vector<ll> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
ll lo = 1, hi = 2e9, opt = -1;
while (lo <= hi) {
ll mid = (lo + hi) >> 1, sum = 0;
for (int i = 0; i < n; i++)
sum += (a[i] + mid - 1) / mid - 1;
if (sum <= k) {
opt = mid;
hi = mid - 1;
} else
lo = mid + 1;
}
cout << opt << endl;
return 0;
} | replace | 35 | 36 | 35 | 36 | 0 | |
p02598 | C++ | Runtime Error | // #include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
// Some constants don't work
#ifndef INT_MAX
#define INT_MAX 2147483647
#endif
#ifndef INT_MIN
#define INT_MIN -2147483648
#endif
// short hand tricks
typedef long long ll;
using namespace std;
int main(int argc, char *argv[]) {
ios_base::sync_with_stdio(false);
ll N, K;
cin >> N >> K;
vector<ll> logs(N);
for (int i = 0; i < N; i++) {
cin >> logs[i];
}
ll low = 0;
ll high = 1e9;
ll res = 1e9;
while (low <= high) {
ll mid = low + (high - low) / 2;
// see if mid is a solution
// count how many cuts to make each log <=mid
ll kcuts = 0;
for (ll log : logs) {
if (log > mid) {
kcuts += log / mid;
if (log % mid == 0)
kcuts--;
}
}
if (kcuts <= K) {
res = min(mid, res);
high = mid - 1;
} else {
low = mid + 1;
}
}
cout << res << "\n";
return 0;
}
| // #include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
// Some constants don't work
#ifndef INT_MAX
#define INT_MAX 2147483647
#endif
#ifndef INT_MIN
#define INT_MIN -2147483648
#endif
// short hand tricks
typedef long long ll;
using namespace std;
int main(int argc, char *argv[]) {
ios_base::sync_with_stdio(false);
ll N, K;
cin >> N >> K;
vector<ll> logs(N);
for (int i = 0; i < N; i++) {
cin >> logs[i];
}
ll low = 1;
ll high = 1e9;
ll res = 1e9;
while (low <= high) {
ll mid = low + (high - low) / 2;
// see if mid is a solution
// count how many cuts to make each log <=mid
ll kcuts = 0;
for (ll log : logs) {
if (log > mid) {
kcuts += log / mid;
if (log % mid == 0)
kcuts--;
}
}
if (kcuts <= K) {
res = min(mid, res);
high = mid - 1;
} else {
low = mid + 1;
}
}
cout << res << "\n";
return 0;
}
| replace | 26 | 27 | 26 | 27 | 0 | |
p02598 | C++ | Runtime Error | /*
AtCoder Beginner Contest 174 - E - Logs
https://atcoder.jp/contests/abc174/tasks/abc174_e
*/
#include <bits/stdc++.h>
using namespace std;
#define FAST_INP \
ios_base::sync_with_stdio(false); \
cin.tie(NULL)
typedef long long ll;
const ll MOD = 1000000007;
int main() {
FAST_INP;
// binary search
int n, k;
cin >> n >> k;
vector<ll> a(n);
ll l = 0, r = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
r = max(r, a[i]);
}
while (l != r) {
int m = l + (r - l) / 2;
ll kk = 0;
for (int i = 0; i < n; i++) {
kk += (a[i] - 1) / m;
}
if (kk <= k)
r = m;
else
l = m + 1;
}
cout << l << endl;
return 0;
} | /*
AtCoder Beginner Contest 174 - E - Logs
https://atcoder.jp/contests/abc174/tasks/abc174_e
*/
#include <bits/stdc++.h>
using namespace std;
#define FAST_INP \
ios_base::sync_with_stdio(false); \
cin.tie(NULL)
typedef long long ll;
const ll MOD = 1000000007;
int main() {
FAST_INP;
// binary search
int n, k;
cin >> n >> k;
vector<ll> a(n);
ll l = 1, r = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
r = max(r, a[i]);
}
while (l != r) {
int m = l + (r - l) / 2;
ll kk = 0;
for (int i = 0; i < n; i++) {
kk += (a[i] - 1) / m;
}
if (kk <= k)
r = m;
else
l = m + 1;
}
cout << l << endl;
return 0;
} | replace | 19 | 20 | 19 | 20 | 0 | |
p02598 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int n, k;
vector<int> a;
bool f(int m) {
int cnt = 0;
for (int i = 0; i < n; i++) {
cnt += (a[i] - 1) / m;
}
return cnt <= k;
}
int main(void) {
cin >> n >> k;
a.assign(n, 0);
for (int i = 0; i < n; i++)
cin >> a[i];
int ng = 0, ok = 1e9;
for (int i = 0; i < 128; i++) {
double m = (ng + ok) / 2;
if (f(m))
ok = m;
else
ng = m;
}
cout << ok << endl;
}
| #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int n, k;
vector<int> a;
bool f(int m) {
int cnt = 0;
for (int i = 0; i < n; i++) {
cnt += (a[i] - 1) / m;
}
return cnt <= k;
}
int main(void) {
cin >> n >> k;
a.assign(n, 0);
for (int i = 0; i < n; i++)
cin >> a[i];
int ng = 0, ok = 1e9;
while (ng + 1 < ok) {
double m = (ng + ok) / 2;
if (f(m))
ok = m;
else
ng = m;
}
cout << ok << endl;
}
| replace | 22 | 23 | 22 | 23 | 0 | |
p02598 | C++ | Runtime Error | #include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll is(vector<ll> &a, ll m, ll k) {
ll count = 0;
for (ll i = 0; i < a.size(); i++) {
count = count + a[i] / m;
if (a[i] % m == 0)
count--;
}
if (count > k)
return 0;
else if (count == k)
return 1;
return 2;
}
int main() {
ll n, k;
cin >> n >> k;
vector<ll> a(n);
for (ll i = 0; i < n; i++)
cin >> a[i];
sort(a.begin(), a.end());
cout.setf(ios::fixed);
cout << setprecision(0);
if (!k) {
cout << a[n - 1] << endl;
return 0;
} else if (k == 1) {
if (n == 1)
cout << ((ll)round(a[0] / 2)) << endl;
else
cout << max((ll)round(a[n - 1] / 2), a[n - 2]) << endl;
}
double ans = 0;
ll l = 0, r = 1000000000;
while (l <= r) {
ll m = l + (r - l) / 2;
ll count = is(a, m, k);
if (count >= 1) {
ans = m;
r = m - 1;
} else {
l = m + 1;
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll is(vector<ll> &a, ll m, ll k) {
ll count = 0;
for (ll i = 0; i < a.size(); i++) {
count = count + a[i] / m;
if (a[i] % m == 0)
count--;
}
if (count > k)
return 0;
else if (count == k)
return 1;
return 2;
}
int main() {
ll n, k;
cin >> n >> k;
vector<ll> a(n);
for (ll i = 0; i < n; i++)
cin >> a[i];
sort(a.begin(), a.end());
cout.setf(ios::fixed);
cout << setprecision(0);
if (!k) {
cout << a[n - 1] << endl;
return 0;
} else if (k == 1) {
if (n == 1)
cout << ((ll)round(a[0] / 2)) << endl;
else
cout << max((ll)round(a[n - 1] / 2), a[n - 2]) << endl;
}
double ans = 0;
ll l = 1, r = 1000000000;
while (l <= r) {
ll m = l + (r - l) / 2;
ll count = is(a, m, k);
if (count >= 1) {
ans = m;
r = m - 1;
} else {
l = m + 1;
}
}
cout << ans << endl;
}
| replace | 45 | 46 | 45 | 46 | 0 | |
p02598 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;
int main() {
int N, K;
cin >> N >> K;
vector<int> A(N);
REP(i, N) { cin >> A[i]; }
sort(ALL(A));
int ng = -1;
int ok = A[N - 1];
while (abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
ll cnt = 0;
REP(i, N) { cnt += (A[i] - 1) / mid; }
if (cnt <= 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 REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;
int main() {
int N, K;
cin >> N >> K;
vector<int> A(N);
REP(i, N) { cin >> A[i]; }
sort(ALL(A));
int ng = 0;
int ok = A[N - 1];
while (abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
ll cnt = 0;
REP(i, N) { cnt += (A[i] - 1) / mid; }
if (cnt <= K) { // ここに条件をかく
ok = mid;
} else {
ng = mid;
}
}
cout << ok << endl;
return 0;
} | replace | 18 | 19 | 18 | 19 | 0 | |
p02598 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
const ll MOD = 1000000007;
const long double PI = 3.14159265358979;
const ll MAX = 0;
int main() {
ll N, K;
cin >> N >> K;
ll a[N];
rep(i, N) { cin >> a[i]; }
ll l = 1, r = 1000000000;
while (r - l > 10000) {
ll mid = (l + r) / 2;
ll k = 0;
rep(i, N) { k += (a[i] - 1) / mid; }
if (k > K) {
l = mid;
} else {
r = mid;
}
}
ll ans = l;
while (1) {
ll k = 0;
rep(i, N) { k += (a[i] - 1) / ans; }
if (k > K) {
ans++;
} else {
break;
}
}
cout << ans;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
const ll MOD = 1000000007;
const long double PI = 3.14159265358979;
const ll MAX = 0;
int main() {
ll N, K;
cin >> N >> K;
ll a[N];
rep(i, N) { cin >> a[i]; }
ll l = 1, r = 1000000000;
while (r - l > 10) {
ll mid = (l + r) / 2;
ll k = 0;
rep(i, N) { k += (a[i] - 1) / mid; }
if (k > K) {
l = mid;
} else {
r = mid;
}
}
ll ans = l;
while (1) {
ll k = 0;
rep(i, N) { k += (a[i] - 1) / ans; }
if (k > K) {
ans++;
} else {
break;
}
}
cout << ans;
} | replace | 14 | 15 | 14 | 15 | TLE | |
p02598 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int n, k;
int a[200200];
bool check(int now) {
int cnt = 0;
rep(i, n) { cnt += ((a[i] - 1) / now); }
return cnt <= k;
}
int main() {
ios::sync_with_stdio(false);
cin >> n >> k;
rep(i, n) cin >> a[i];
int lb = 0, ub = 1000000000;
while (lb <= ub) {
int mid = (lb + ub) >> 1;
if (check(mid))
ub = mid - 1;
else
lb = mid + 1;
}
cout << lb << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int n, k;
int a[200200];
bool check(int now) {
if (now == 0)
return 0;
int cnt = 0;
rep(i, n) { cnt += ((a[i] - 1) / now); }
return cnt <= k;
}
int main() {
ios::sync_with_stdio(false);
cin >> n >> k;
rep(i, n) cin >> a[i];
int lb = 0, ub = 1000000000;
while (lb <= ub) {
int mid = (lb + ub) >> 1;
if (check(mid))
ub = mid - 1;
else
lb = mid + 1;
}
cout << lb << endl;
return 0;
} | insert | 8 | 8 | 8 | 10 | 0 | |
p02598 | C++ | Runtime Error | #include <algorithm>
#include <assert.h>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
#define ALL(c) (c).begin(), (c).end()
#define PB push_back
#define IN(x, c) (find(c.begin(), c.end(), x) != (c).end())
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define INIT(a, v) memset(a, v, sizeof(a))
#define SORT_UNIQUE(c) \
(sort(c.begin(), c.end()), \
c.resize(distance(c.begin(), unique(c.begin(), c.end()))))
template <class A, class B> A cvt(B x) {
stringstream ss;
ss << x;
A y;
ss >> y;
return y;
}
#define SPC << " " <<
#define DEBUG(x) \
cerr << #x << " = "; \
cerr << x << endl;
#define DEBUG_ITER(x) \
cerr << #x << " = "; \
for (auto _ : x) \
cerr << _ << ' '; \
cerr << endl;
typedef pair<int, int> PII;
typedef long long int64;
typedef vector<int> VI;
int n, k;
int a[200000];
int main() {
// freopen("test.in","r",stdin);
scanf("%d %d", &n, &k);
REP(i, n) scanf("%d", &a[i]);
int cant = 0, can = 1e9;
REP(it, 200) {
int l = (can + cant) / 2;
int64 x = 0;
REP(i, n) {
x += a[i] / l;
if (a[i] % l == 0)
x--;
}
if (x > k)
cant = l;
else
can = l;
}
printf("%d\n", can);
return 0;
}
| #include <algorithm>
#include <assert.h>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
#define ALL(c) (c).begin(), (c).end()
#define PB push_back
#define IN(x, c) (find(c.begin(), c.end(), x) != (c).end())
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define INIT(a, v) memset(a, v, sizeof(a))
#define SORT_UNIQUE(c) \
(sort(c.begin(), c.end()), \
c.resize(distance(c.begin(), unique(c.begin(), c.end()))))
template <class A, class B> A cvt(B x) {
stringstream ss;
ss << x;
A y;
ss >> y;
return y;
}
#define SPC << " " <<
#define DEBUG(x) \
cerr << #x << " = "; \
cerr << x << endl;
#define DEBUG_ITER(x) \
cerr << #x << " = "; \
for (auto _ : x) \
cerr << _ << ' '; \
cerr << endl;
typedef pair<int, int> PII;
typedef long long int64;
typedef vector<int> VI;
int n, k;
int a[200000];
int main() {
// freopen("test.in","r",stdin);
scanf("%d %d", &n, &k);
REP(i, n) scanf("%d", &a[i]);
int cant = 0, can = 1e9;
while (can - cant > 1) {
int l = (can + cant) / 2;
int64 x = 0;
REP(i, n) {
x += a[i] / l;
if (a[i] % l == 0)
x--;
}
if (x > k)
cant = l;
else
can = l;
}
printf("%d\n", can);
return 0;
}
| replace | 59 | 60 | 59 | 60 | 0 | |
p02598 | C++ | Runtime Error | #include <bits/stdc++.h> // ver2.7.1
#define int long long
#define endl "\n" // fflush(stdout);
#define ALL(v) (v).begin(), (v).end()
#define Vi vector<int>
#define VVi vector<Vi>
#define VVVi vector<VVi>
#define Vm vector<mint>
#define Vs vector<string>
#define Vd vector<double>
#define Vc vector<char>
#define Pii pair<int, int>
#define Pdd pair<double, double>
#define VPii vector<Pii>
#define Tiii tuple<int, int, int>
#define VTiii vector<Tiii>
#define PQi priority_queue<int>
#define PQir priority_queue<int, vector<int>, greater<int>>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define itos to_string
#define stoi stoll
#define FI first
#define SE second
#define cYES cout << "YES" << endl
#define cNO cout << "NO" << endl
#define cYes cout << "Yes" << endl
#define cNo cout << "No" << endl
#define cyes cout << "yes" << endl
#define cno cout << "no" << endl
#define sortr(v) sort(v, greater<>())
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repeq(i, a, b) for (int i = a; i <= b; i++)
#define repreq(i, a, b) for (int i = a; i >= b; i--)
#define dem(a, b) ((a + b - 1) / (b))
#define INF 3000000000000000000 // 3.0*10^18
#define MAX LLONG_MAX
#define PI acos(-1.0L)
// int MOD = 998244353; // case
const int MOD = 1000000007; // 10^9 + 7
const double EPS = 1e-10;
using namespace std;
struct mint {
int x;
mint(int x = 0) : x((x % MOD + MOD) % MOD) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint a) {
if ((x += a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator-=(const mint a) {
if ((x += MOD - a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= MOD;
return *this;
}
mint operator+(const mint a) const { return mint(*this) += a; }
mint operator-(const mint a) const { return mint(*this) -= a; }
mint operator*(const mint a) const { return mint(*this) *= a; }
mint pow(int t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
mint inv() const { return pow(MOD - 2); }
mint &operator/=(const mint a) { return *this *= a.inv(); }
mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
/* debug */
template <typename T> // vector
ostream &operator<<(ostream &os, const vector<T> &V) {
int N = V.size();
if (N == 0) {
os << '.';
return os;
}
rep(i, 0, N - 1) { os << V[i] << ' '; }
os << V[N - 1];
return os;
}
template <typename T> // vector vector
ostream &operator<<(ostream &os, const vector<vector<T>> &V) {
int N = V.size();
rep(i, 0, N - 1) cout << V[i] << endl;
cout << V[N - 1];
return os;
}
template <typename T, typename S> // pair
ostream &operator<<(ostream &os, pair<T, S> const &P) {
os << P.FI << ' ' << P.SE;
return os;
}
template <typename T> // set
ostream &operator<<(ostream &os, set<T> &S) {
auto it = S.begin();
while (it != S.end()) {
os << *it;
if (next(it, 1) != S.end())
os << ' ';
it++;
};
return os;
}
template <typename T> // deque
ostream &operator<<(ostream &os, deque<T> &q) {
for (auto it = q.begin(); it < q.end(); it++) {
os << *it;
if (it + 1 != q.end())
os << " ";
}
return os;
}
/* useful */
template <typename T> void Vin(vector<T> &v) {
int n = v.size();
rep(i, 0, n) cin >> v[i];
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int mypow(int x, int n, int m) {
if (n == 0)
return 1;
if (n % 2 == 0)
return mypow(x * x % m, n / 2, m);
else
return x * mypow(x, n - 1, m) % m;
}
int scomb(int n, int r) {
if (r < 0 || r > n)
return 0;
if ((n - r) < r)
r = n - r; // nCr
int a = 1;
for (int i = n; i > n - r; --i) {
a = a * i;
}
for (int i = 1; i < r + 1; ++i) {
a = a / i;
}
return a;
}
Vi vis(Vi &v) {
Vi S(v.size() + 1);
rep(i, 1, S.size()) S[i] += v[i - 1] + S[i - 1];
return S;
}
int digitsum(int n) {
int ret = 0;
while (n > 0) {
ret += n % 10;
n /= 10;
}
return ret;
}
int digit(int k, int i) {
string s = itos(k);
return s[s.size() - i] - '0';
} // i桁目の数字
template <typename T> void press(T &v) {
v.erase(unique(ALL(v)), v.end());
} // 圧縮
Vi zip(Vi b) {
int Z = b.size(); // 座標圧縮
Pii p[Z + 10];
int a = b.size();
Vi l(a);
for (int i = 0; i < a; i++)
p[i] = mp(b[i], i);
sort(p, p + a);
int w = 0;
for (int i = 0; i < a; i++) {
if (i && p[i].first != p[i - 1].first)
w++;
l[p[i].second] = w;
}
return l;
}
Vi nibe2V() {
Vi a(63);
int q = 1;
rep(i, 0, 63) {
a[i] = q;
q *= 2;
}
return a;
}
Vi nibe = nibe2V(); // 2^n
int modiv(int a, int b) {
return a * mypow(b, MOD - 2, MOD) % MOD;
} // a÷b(%MOD)
int SMALLER(Vi &a, int x) {
return lower_bound(a.begin(), a.end(), x) - a.begin();
}
int orSMALLER(Vi &a, int x) {
return upper_bound(a.begin(), a.end(), x) - a.begin();
}
int BIGGER(Vi &a, int x) { return a.size() - orSMALLER(a, x); }
int orBIGGER(Vi &a, int x) { return a.size() - SMALLER(a, x); }
int COUNT(Vi &a, int x) {
return upper_bound(ALL(a), x) - lower_bound(ALL(a), x);
}
int maxind(Vi &a) { return max_element(ALL(a)) - a.begin(); }
int minind(Vi &a) { return min_element(ALL(a)) - a.begin(); }
Vi stpowV() {
Vi a(1000005);
a[0] = 1;
repeq(i, 1, 1000004) a[i] = a[i - 1] * i % MOD;
return a;
}
Vi stpow = stpowV(); // 階乗配列(%MOD)
/****************************** START ******************************/
int n, k;
Vi a;
bool check(int mid) { // ([...,0,0,0,"1",1,1,...])
int tmp = 0;
rep(i, 0, n) { tmp += dem(a[i], mid) - 1; }
if (tmp > k)
return 0;
else
return 1;
}
int binary() {
int L = 0, R = 1000000010; // [L,R]の範囲内に解
int mid = (L + R) / 2;
while (L < R) {
if (check(mid)) {
R = mid;
} else {
L = mid + 1;
}
mid = (L + R) / 2;
}
return mid;
}
signed main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(12);
cin >> n >> k;
a = Vi(n);
Vin(a);
cout << binary() << endl;
return 0;
} | #include <bits/stdc++.h> // ver2.7.1
#define int long long
#define endl "\n" // fflush(stdout);
#define ALL(v) (v).begin(), (v).end()
#define Vi vector<int>
#define VVi vector<Vi>
#define VVVi vector<VVi>
#define Vm vector<mint>
#define Vs vector<string>
#define Vd vector<double>
#define Vc vector<char>
#define Pii pair<int, int>
#define Pdd pair<double, double>
#define VPii vector<Pii>
#define Tiii tuple<int, int, int>
#define VTiii vector<Tiii>
#define PQi priority_queue<int>
#define PQir priority_queue<int, vector<int>, greater<int>>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define itos to_string
#define stoi stoll
#define FI first
#define SE second
#define cYES cout << "YES" << endl
#define cNO cout << "NO" << endl
#define cYes cout << "Yes" << endl
#define cNo cout << "No" << endl
#define cyes cout << "yes" << endl
#define cno cout << "no" << endl
#define sortr(v) sort(v, greater<>())
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repeq(i, a, b) for (int i = a; i <= b; i++)
#define repreq(i, a, b) for (int i = a; i >= b; i--)
#define dem(a, b) ((a + b - 1) / (b))
#define INF 3000000000000000000 // 3.0*10^18
#define MAX LLONG_MAX
#define PI acos(-1.0L)
// int MOD = 998244353; // case
const int MOD = 1000000007; // 10^9 + 7
const double EPS = 1e-10;
using namespace std;
struct mint {
int x;
mint(int x = 0) : x((x % MOD + MOD) % MOD) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint a) {
if ((x += a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator-=(const mint a) {
if ((x += MOD - a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= MOD;
return *this;
}
mint operator+(const mint a) const { return mint(*this) += a; }
mint operator-(const mint a) const { return mint(*this) -= a; }
mint operator*(const mint a) const { return mint(*this) *= a; }
mint pow(int t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
mint inv() const { return pow(MOD - 2); }
mint &operator/=(const mint a) { return *this *= a.inv(); }
mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
/* debug */
template <typename T> // vector
ostream &operator<<(ostream &os, const vector<T> &V) {
int N = V.size();
if (N == 0) {
os << '.';
return os;
}
rep(i, 0, N - 1) { os << V[i] << ' '; }
os << V[N - 1];
return os;
}
template <typename T> // vector vector
ostream &operator<<(ostream &os, const vector<vector<T>> &V) {
int N = V.size();
rep(i, 0, N - 1) cout << V[i] << endl;
cout << V[N - 1];
return os;
}
template <typename T, typename S> // pair
ostream &operator<<(ostream &os, pair<T, S> const &P) {
os << P.FI << ' ' << P.SE;
return os;
}
template <typename T> // set
ostream &operator<<(ostream &os, set<T> &S) {
auto it = S.begin();
while (it != S.end()) {
os << *it;
if (next(it, 1) != S.end())
os << ' ';
it++;
};
return os;
}
template <typename T> // deque
ostream &operator<<(ostream &os, deque<T> &q) {
for (auto it = q.begin(); it < q.end(); it++) {
os << *it;
if (it + 1 != q.end())
os << " ";
}
return os;
}
/* useful */
template <typename T> void Vin(vector<T> &v) {
int n = v.size();
rep(i, 0, n) cin >> v[i];
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int mypow(int x, int n, int m) {
if (n == 0)
return 1;
if (n % 2 == 0)
return mypow(x * x % m, n / 2, m);
else
return x * mypow(x, n - 1, m) % m;
}
int scomb(int n, int r) {
if (r < 0 || r > n)
return 0;
if ((n - r) < r)
r = n - r; // nCr
int a = 1;
for (int i = n; i > n - r; --i) {
a = a * i;
}
for (int i = 1; i < r + 1; ++i) {
a = a / i;
}
return a;
}
Vi vis(Vi &v) {
Vi S(v.size() + 1);
rep(i, 1, S.size()) S[i] += v[i - 1] + S[i - 1];
return S;
}
int digitsum(int n) {
int ret = 0;
while (n > 0) {
ret += n % 10;
n /= 10;
}
return ret;
}
int digit(int k, int i) {
string s = itos(k);
return s[s.size() - i] - '0';
} // i桁目の数字
template <typename T> void press(T &v) {
v.erase(unique(ALL(v)), v.end());
} // 圧縮
Vi zip(Vi b) {
int Z = b.size(); // 座標圧縮
Pii p[Z + 10];
int a = b.size();
Vi l(a);
for (int i = 0; i < a; i++)
p[i] = mp(b[i], i);
sort(p, p + a);
int w = 0;
for (int i = 0; i < a; i++) {
if (i && p[i].first != p[i - 1].first)
w++;
l[p[i].second] = w;
}
return l;
}
Vi nibe2V() {
Vi a(63);
int q = 1;
rep(i, 0, 63) {
a[i] = q;
q *= 2;
}
return a;
}
Vi nibe = nibe2V(); // 2^n
int modiv(int a, int b) {
return a * mypow(b, MOD - 2, MOD) % MOD;
} // a÷b(%MOD)
int SMALLER(Vi &a, int x) {
return lower_bound(a.begin(), a.end(), x) - a.begin();
}
int orSMALLER(Vi &a, int x) {
return upper_bound(a.begin(), a.end(), x) - a.begin();
}
int BIGGER(Vi &a, int x) { return a.size() - orSMALLER(a, x); }
int orBIGGER(Vi &a, int x) { return a.size() - SMALLER(a, x); }
int COUNT(Vi &a, int x) {
return upper_bound(ALL(a), x) - lower_bound(ALL(a), x);
}
int maxind(Vi &a) { return max_element(ALL(a)) - a.begin(); }
int minind(Vi &a) { return min_element(ALL(a)) - a.begin(); }
Vi stpowV() {
Vi a(1000005);
a[0] = 1;
repeq(i, 1, 1000004) a[i] = a[i - 1] * i % MOD;
return a;
}
Vi stpow = stpowV(); // 階乗配列(%MOD)
/****************************** START ******************************/
int n, k;
Vi a;
bool check(int mid) { // ([...,0,0,0,"1",1,1,...])
int tmp = 0;
rep(i, 0, n) { tmp += dem(a[i], mid) - 1; }
if (tmp > k)
return 0;
else
return 1;
}
int binary() {
int L = 1, R = 1000000010; // [L,R]の範囲内に解
int mid = (L + R) / 2;
while (L < R) {
if (check(mid)) {
R = mid;
} else {
L = mid + 1;
}
mid = (L + R) / 2;
}
return mid;
}
signed main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(12);
cin >> n >> k;
a = Vi(n);
Vin(a);
cout << binary() << endl;
return 0;
} | replace | 241 | 242 | 241 | 242 | 0 | |
p02598 | C++ | Runtime Error | #pragma GCC optimize("O3")
#include "bits/stdc++.h"
using namespace std;
using ll = long long int;
#define all(v) (v).begin(), (v).end()
#define repeat(cnt, l) \
for (typename remove_const< \
typename remove_reference<decltype(l)>::type>::type cnt = {}; \
(cnt) < (l); ++(cnt))
#define rrepeat(cnt, l) for (auto cnt = (l)-1; 0 <= (cnt); --(cnt))
#define iterate(cnt, b, e) for (auto cnt = (b); (cnt) != (e); ++(cnt))
#define diterate(cnt, b, e) for (auto cnt = (b); (cnt) != (e); --(cnt))
const long long MD = 1000000007ll;
const long double PI = 3.1415926535897932384626433832795L;
template <typename T1, typename T2>
inline ostream &operator<<(ostream &o, const pair<T1, T2> p) {
o << '(' << p.first << ':' << p.second << ')';
return o;
}
template <typename T> inline T &chmax(T &to, const T &val) {
return to = max(to, val);
}
template <typename T> inline T &chmin(T &to, const T &val) {
return to = min(to, val);
}
void bye(string s, int code = 0) {
cout << s << endl;
exit(code);
}
mt19937_64 randdev(8901016);
template <typename T, typename Random = decltype(randdev),
typename enable_if<is_integral<T>::value>::type * = nullptr>
inline T rand(T l, T h, Random &rand = randdev) {
return uniform_int_distribution<T>(l, h)(rand);
}
template <typename T, typename Random = decltype(randdev),
typename enable_if<is_floating_point<T>::value>::type * = nullptr>
inline T rand(T l, T h, Random &rand = randdev) {
return uniform_real_distribution<T>(l, h)(rand);
}
template <typename I> struct MyRangeFormat {
I b, e;
MyRangeFormat(I _b, I _e) : b(_b), e(_e) {}
};
template <typename I>
static ostream &operator<<(ostream &o, const MyRangeFormat<I> &f) {
o << "[ ";
iterate(i, f.b, f.e) o << *i << ' ';
return o << ']';
}
template <typename I> struct MyMatrixFormat {
const I &p;
long long n, m;
MyMatrixFormat(const I &_p, long long _n, long long _m)
: p(_p), n(_n), m(_m) {}
};
template <typename I>
static ostream &operator<<(ostream &o, const MyMatrixFormat<I> &f) {
o << '\n';
repeat(i, (f.n)) {
repeat(j, f.m) o << f.p[i][j] << ' ';
o << '\n';
}
return o;
}
struct LOG_t {
~LOG_t() { cout << endl; }
};
#define LOG (LOG_t(), cout << 'L' << __LINE__ << ": ")
#define FMTA(m, w) (MyRangeFormat<decltype(m + 0)>(m, m + w))
#define FMTR(b, e) (MyRangeFormat<decltype(e)>(b, e))
#define FMTV(v) FMTR(v.begin(), v.end())
#define FMTM(m, h, w) (MyMatrixFormat<decltype(m + 0)>(m, h, w))
#if defined(_WIN32) || defined(_WIN64)
#define getc_x _getc_nolock
#define putc_x _putc_nolock
#elif defined(__GNUC__)
#define getc_x getc_unlocked
#define putc_x putc_unlocked
#else
#define getc_x getc
#define putc_x putc
#endif
class MaiScanner {
FILE *fp_;
constexpr bool isvisiblechar(char c) noexcept {
return (0x21 <= (c) && (c) <= 0x7E);
}
public:
inline MaiScanner(FILE *fp) : fp_(fp) {}
template <typename T> void input_integer(T &var) noexcept {
var = 0;
T sign = 1;
int cc = getc_x(fp_);
for (; cc < '0' || '9' < cc; cc = getc_x(fp_))
if (cc == '-')
sign = -1;
for (; '0' <= cc && cc <= '9'; cc = getc_x(fp_))
var = (var << 3) + (var << 1) + cc - '0';
var = var * sign;
}
inline int c() noexcept { return getc_x(fp_); }
template <typename T, typename enable_if<is_integral<T>::value,
nullptr_t>::type = nullptr>
inline MaiScanner &operator>>(T &var) noexcept {
input_integer<T>(var);
return *this;
}
inline MaiScanner &operator>>(string &var) {
int cc = getc_x(fp_);
for (; !isvisiblechar(cc); cc = getc_x(fp_))
;
for (; isvisiblechar(cc); cc = getc_x(fp_))
var.push_back(cc);
return *this;
}
template <typename IT> inline void in(IT begin, IT end) {
for (auto it = begin; it != end; ++it)
*this >> *it;
}
};
class MaiPrinter {
FILE *fp_;
public:
inline MaiPrinter(FILE *fp) : fp_(fp) {}
template <typename T> void output_integer(T var) noexcept {
if (var == 0) {
putc_x('0', fp_);
return;
}
if (var < 0)
putc_x('-', fp_), var = -var;
char stack[32];
int stack_p = 0;
while (var)
stack[stack_p++] = '0' + (var % 10), var /= 10;
while (stack_p)
putc_x(stack[--stack_p], fp_);
}
inline MaiPrinter &operator<<(char c) noexcept {
putc_x(c, fp_);
return *this;
}
template <typename T, typename enable_if<is_integral<T>::value,
nullptr_t>::type = nullptr>
inline MaiPrinter &operator<<(T var) noexcept {
output_integer<T>(var);
return *this;
}
inline MaiPrinter &operator<<(char *str_p) noexcept {
while (*str_p)
putc_x(*(str_p++), fp_);
return *this;
}
inline MaiPrinter &operator<<(const string &str) {
const char *p = str.c_str();
const char *l = p + str.size();
while (p < l)
putc_x(*p++, fp_);
return *this;
}
template <typename IT> void join(IT begin, IT end, char sep = ' ') {
for (bool b = 0; begin != end; ++begin, b = 1)
b ? *this << sep << *begin : *this << *begin;
}
};
MaiScanner scanner(stdin);
MaiPrinter printer(stdout);
//
int N;
int K;
int A[100010];
//
bool judge(int X) {
int total = 0;
repeat(i, N) {
int a = A[i];
int m = (a - 1) / X;
total += m;
if (total > K)
return false;
}
return true;
}
int main() {
scanner >> N >> K;
scanner.in(A, A + N);
int ng = 1;
int ok = 1e9;
while (ok - ng > 1) {
int m = (ok + ng) / 2;
(judge(m) ? ok : ng) = m;
}
if (ok == 2) {
// check 1
int sum = 0;
repeat(i, N) { sum += A[i] - 1; }
if (sum <= K)
ok = 1;
}
cout << ok << endl;
return 0;
}
| #pragma GCC optimize("O3")
#include "bits/stdc++.h"
using namespace std;
using ll = long long int;
#define all(v) (v).begin(), (v).end()
#define repeat(cnt, l) \
for (typename remove_const< \
typename remove_reference<decltype(l)>::type>::type cnt = {}; \
(cnt) < (l); ++(cnt))
#define rrepeat(cnt, l) for (auto cnt = (l)-1; 0 <= (cnt); --(cnt))
#define iterate(cnt, b, e) for (auto cnt = (b); (cnt) != (e); ++(cnt))
#define diterate(cnt, b, e) for (auto cnt = (b); (cnt) != (e); --(cnt))
const long long MD = 1000000007ll;
const long double PI = 3.1415926535897932384626433832795L;
template <typename T1, typename T2>
inline ostream &operator<<(ostream &o, const pair<T1, T2> p) {
o << '(' << p.first << ':' << p.second << ')';
return o;
}
template <typename T> inline T &chmax(T &to, const T &val) {
return to = max(to, val);
}
template <typename T> inline T &chmin(T &to, const T &val) {
return to = min(to, val);
}
void bye(string s, int code = 0) {
cout << s << endl;
exit(code);
}
mt19937_64 randdev(8901016);
template <typename T, typename Random = decltype(randdev),
typename enable_if<is_integral<T>::value>::type * = nullptr>
inline T rand(T l, T h, Random &rand = randdev) {
return uniform_int_distribution<T>(l, h)(rand);
}
template <typename T, typename Random = decltype(randdev),
typename enable_if<is_floating_point<T>::value>::type * = nullptr>
inline T rand(T l, T h, Random &rand = randdev) {
return uniform_real_distribution<T>(l, h)(rand);
}
template <typename I> struct MyRangeFormat {
I b, e;
MyRangeFormat(I _b, I _e) : b(_b), e(_e) {}
};
template <typename I>
static ostream &operator<<(ostream &o, const MyRangeFormat<I> &f) {
o << "[ ";
iterate(i, f.b, f.e) o << *i << ' ';
return o << ']';
}
template <typename I> struct MyMatrixFormat {
const I &p;
long long n, m;
MyMatrixFormat(const I &_p, long long _n, long long _m)
: p(_p), n(_n), m(_m) {}
};
template <typename I>
static ostream &operator<<(ostream &o, const MyMatrixFormat<I> &f) {
o << '\n';
repeat(i, (f.n)) {
repeat(j, f.m) o << f.p[i][j] << ' ';
o << '\n';
}
return o;
}
struct LOG_t {
~LOG_t() { cout << endl; }
};
#define LOG (LOG_t(), cout << 'L' << __LINE__ << ": ")
#define FMTA(m, w) (MyRangeFormat<decltype(m + 0)>(m, m + w))
#define FMTR(b, e) (MyRangeFormat<decltype(e)>(b, e))
#define FMTV(v) FMTR(v.begin(), v.end())
#define FMTM(m, h, w) (MyMatrixFormat<decltype(m + 0)>(m, h, w))
#if defined(_WIN32) || defined(_WIN64)
#define getc_x _getc_nolock
#define putc_x _putc_nolock
#elif defined(__GNUC__)
#define getc_x getc_unlocked
#define putc_x putc_unlocked
#else
#define getc_x getc
#define putc_x putc
#endif
class MaiScanner {
FILE *fp_;
constexpr bool isvisiblechar(char c) noexcept {
return (0x21 <= (c) && (c) <= 0x7E);
}
public:
inline MaiScanner(FILE *fp) : fp_(fp) {}
template <typename T> void input_integer(T &var) noexcept {
var = 0;
T sign = 1;
int cc = getc_x(fp_);
for (; cc < '0' || '9' < cc; cc = getc_x(fp_))
if (cc == '-')
sign = -1;
for (; '0' <= cc && cc <= '9'; cc = getc_x(fp_))
var = (var << 3) + (var << 1) + cc - '0';
var = var * sign;
}
inline int c() noexcept { return getc_x(fp_); }
template <typename T, typename enable_if<is_integral<T>::value,
nullptr_t>::type = nullptr>
inline MaiScanner &operator>>(T &var) noexcept {
input_integer<T>(var);
return *this;
}
inline MaiScanner &operator>>(string &var) {
int cc = getc_x(fp_);
for (; !isvisiblechar(cc); cc = getc_x(fp_))
;
for (; isvisiblechar(cc); cc = getc_x(fp_))
var.push_back(cc);
return *this;
}
template <typename IT> inline void in(IT begin, IT end) {
for (auto it = begin; it != end; ++it)
*this >> *it;
}
};
class MaiPrinter {
FILE *fp_;
public:
inline MaiPrinter(FILE *fp) : fp_(fp) {}
template <typename T> void output_integer(T var) noexcept {
if (var == 0) {
putc_x('0', fp_);
return;
}
if (var < 0)
putc_x('-', fp_), var = -var;
char stack[32];
int stack_p = 0;
while (var)
stack[stack_p++] = '0' + (var % 10), var /= 10;
while (stack_p)
putc_x(stack[--stack_p], fp_);
}
inline MaiPrinter &operator<<(char c) noexcept {
putc_x(c, fp_);
return *this;
}
template <typename T, typename enable_if<is_integral<T>::value,
nullptr_t>::type = nullptr>
inline MaiPrinter &operator<<(T var) noexcept {
output_integer<T>(var);
return *this;
}
inline MaiPrinter &operator<<(char *str_p) noexcept {
while (*str_p)
putc_x(*(str_p++), fp_);
return *this;
}
inline MaiPrinter &operator<<(const string &str) {
const char *p = str.c_str();
const char *l = p + str.size();
while (p < l)
putc_x(*p++, fp_);
return *this;
}
template <typename IT> void join(IT begin, IT end, char sep = ' ') {
for (bool b = 0; begin != end; ++begin, b = 1)
b ? *this << sep << *begin : *this << *begin;
}
};
MaiScanner scanner(stdin);
MaiPrinter printer(stdout);
//
int N;
int K;
int A[200010];
//
bool judge(int X) {
int total = 0;
repeat(i, N) {
int a = A[i];
int m = (a - 1) / X;
total += m;
if (total > K)
return false;
}
return true;
}
int main() {
scanner >> N >> K;
scanner.in(A, A + N);
int ng = 1;
int ok = 1e9;
while (ok - ng > 1) {
int m = (ok + ng) / 2;
(judge(m) ? ok : ng) = m;
}
if (ok == 2) {
// check 1
int sum = 0;
repeat(i, N) { sum += A[i] - 1; }
if (sum <= K)
ok = 1;
}
cout << ok << endl;
return 0;
}
| replace | 179 | 180 | 179 | 180 | 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 int long long int
#define mod 1000000007
#define string_mod 2549536629329_base_255
#define pb push_back
#define F first
#define S second
#define ff first
#define endl "\n"
#define ss second
#define all(v) v.begin(), v.end()
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int power(int x, unsigned int y, int p) {
int res = 1;
x = x % p;
while (y > 0) {
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res % p;
}
void solve() {
int n, k;
cin >> n >> k;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int lo = 0, hi = 1e9;
int ans = 0;
while (lo <= hi) {
int mid = lo + hi;
mid /= 2;
int re = 0;
for (int i = 0; i < n; i++) {
int f = a[i] + mid - 1;
f /= mid;
f--;
re += f;
}
if (re <= k) {
ans = mid;
hi = mid - 1;
} else {
lo = mid + 1;
}
}
cout << ans << endl;
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int tc;
tc = 1;
// cin >> tc;
while (tc--) {
solve();
}
return 0;
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define mod 1000000007
#define string_mod 2549536629329_base_255
#define pb push_back
#define F first
#define S second
#define ff first
#define endl "\n"
#define ss second
#define all(v) v.begin(), v.end()
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int power(int x, unsigned int y, int p) {
int res = 1;
x = x % p;
while (y > 0) {
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res % p;
}
void solve() {
int n, k;
cin >> n >> k;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int lo = 1, hi = 1e9;
int ans = 0;
while (lo <= hi) {
int mid = lo + hi;
mid /= 2;
int re = 0;
for (int i = 0; i < n; i++) {
int f = a[i] + mid - 1;
f /= mid;
f--;
re += f;
}
if (re <= k) {
ans = mid;
hi = mid - 1;
} else {
lo = mid + 1;
}
}
cout << ans << endl;
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int tc;
tc = 1;
// cin >> tc;
while (tc--) {
solve();
}
return 0;
} | replace | 36 | 37 | 36 | 37 | 0 | |
p02598 | C++ | Runtime Error | #include <bits/stdc++.h>
#define nl '\n'
#define dbg(a) cout << #a << "=" << a << endl
#define fast \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define ll long long
#define vl vector<ll>
#define pll pair<ll, ll>
#define ii pair<ll, ll>
#define vi vector<ll>
#define MX 600000
#define MXX 1000000000
using namespace std;
vl v;
ll cut(ll x) {
ll ct = 0;
for (int i = 0; i < v.size(); i++) {
ct += (v[i] + x - 1) / x;
ct--;
// dbg(ct);
}
// dbg(ct);
return ct;
}
void solve() {
ll n, k;
cin >> n >> k;
v.clear();
v.resize(n);
// dbg(n);
for (auto &it : v)
cin >> it;
sort(v.begin(), v.end());
ll l = 0, r = v.back();
while (l < r) {
ll m = (l + r) / 2;
// dbg(m);
// dbg(cut(m));
if (cut(m) <= k) {
r = m;
} else
l = m + 1;
}
cout << l << endl;
}
int main() {
fast;
solve();
return 0;
}
| #include <bits/stdc++.h>
#define nl '\n'
#define dbg(a) cout << #a << "=" << a << endl
#define fast \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define ll long long
#define vl vector<ll>
#define pll pair<ll, ll>
#define ii pair<ll, ll>
#define vi vector<ll>
#define MX 600000
#define MXX 1000000000
using namespace std;
vl v;
ll cut(ll x) {
ll ct = 0;
for (int i = 0; i < v.size(); i++) {
ct += (v[i] + x - 1) / x;
ct--;
// dbg(ct);
}
// dbg(ct);
return ct;
}
void solve() {
ll n, k;
cin >> n >> k;
v.clear();
v.resize(n);
// dbg(n);
for (auto &it : v)
cin >> it;
sort(v.begin(), v.end());
ll l = 1, r = v.back();
while (l < r) {
ll m = (l + r) / 2;
// dbg(m);
// dbg(cut(m));
if (cut(m) <= k) {
r = m;
} else
l = m + 1;
}
cout << l << endl;
}
int main() {
fast;
solve();
return 0;
}
| replace | 38 | 39 | 38 | 39 | 0 | |
p02598 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
bool kmax(vector<ll> &v, ll log, ll k) {
ll sum = 0;
for (int i = 0; i < v.size(); i++)
sum += (v[i] - 1) / log;
return sum <= k;
}
ll bs(vector<ll> &v, ll low, ll high, ll k) {
if (low < high) {
ll mid = (high + low) / 2;
if (kmax(v, mid, k))
return bs(v, low, mid, k);
else
return bs(v, mid + 1, high, k);
}
return low;
}
int main() {
ll n, k;
cin >> n >> k;
vector<ll> v(n);
ll max_val = 0;
for (int i = 0; i < n; i++) {
cin >> v[i];
if (max_val < v[i])
max_val = v[i];
}
cout << bs(v, 0, max_val, k) << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
bool kmax(vector<ll> &v, ll log, ll k) {
ll sum = 0;
for (int i = 0; i < v.size(); i++)
sum += (v[i] - 1) / log;
return sum <= k;
}
ll bs(vector<ll> &v, ll low, ll high, ll k) {
if (low < high) {
ll mid = (high + low) / 2;
if (kmax(v, mid, k))
return bs(v, low, mid, k);
else
return bs(v, mid + 1, high, k);
}
return low;
}
int main() {
ll n, k;
cin >> n >> k;
vector<ll> v(n);
ll max_val = 0;
for (int i = 0; i < n; i++) {
cin >> v[i];
if (max_val < v[i])
max_val = v[i];
}
cout << bs(v, 1, max_val, k) << endl;
return 0;
} | replace | 31 | 32 | 31 | 32 | 0 | |
p02598 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
int n, k, a[MAXN];
bool can(int L) {
long long sum = 0;
for (int i = 0; i < n; i++) {
sum += (a[i] - 1) / L;
}
if (sum > k)
return false;
else
return true;
}
int main() {
scanf("%d %d", &n, &k);
for (int i = 0; i < n; i++)
scanf("%d", &a[i]);
int L = 0, R = 1e9 + 50;
while (L < R) {
int mid = (L + R) / 2;
if (can(mid))
R = mid;
else
L = mid + 1;
}
printf("%d\n", L);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
int n, k, a[MAXN];
bool can(int L) {
long long sum = 0;
for (int i = 0; i < n; i++) {
sum += (a[i] - 1) / L;
}
if (sum > k)
return false;
else
return true;
}
int main() {
scanf("%d %d", &n, &k);
for (int i = 0; i < n; i++)
scanf("%d", &a[i]);
int L = 1, R = 1e9 + 50;
while (L < R) {
int mid = (L + R) / 2;
if (can(mid))
R = mid;
else
L = mid + 1;
}
printf("%d\n", L);
return 0;
}
| replace | 24 | 25 | 24 | 25 | 0 | |
p02598 | C++ | Runtime Error | /* winners never quit and quitters never win.
#swap */
#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;
#pragma GCC optimize("-O3")
using ll = long long;
using ld = long double;
const ll mod = 1000000007;
const ll inf = 1000000000000000000;
const ll rk = 256;
const ld PI = 3.141592653589793;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
template <typename T> void make_unique(vector<T> &vec) {
sort(all(vec));
vec.erase(unique(all(vec)), vec.end());
}
#define endl '\n'
#define pb push_back
#define mp make_pair
#define vc vector
#define fs first
#define sec second
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll, ll>
#define pls pair<ll, string>
#define psl pair<string, ll>
#define plc pair<ll, char>
#define pcl pair<char, ll>
#define pss pair<string, string>
#define all(x) (x).begin(), (x).end()
#define tol(s) transform(s.begin(), s.end(), s.begin(), ::tolower);
#define tou(s) transform(s.begin(), s.end(), s.begin(), ::toupper);
#define printclock \
cerr << "Time : " << 1000 * (ld)clock() / (ld)CLOCKS_PER_SEC << "ms\n";
#define error(args...) \
{ \
string _s = #args; \
replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); \
istream_iterator<string> _it(_ss); \
err(_it, args); \
}
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...);
}
#define rep(i, begin, end) \
for (__typeof(end) i = (begin) - ((begin) > (end)); \
i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define T \
ll t = 0; \
cin >> t; \
for (ll test = 0; test < t; test++)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll nxt() {
ll TemporaryVariable;
cin >> TemporaryVariable;
return TemporaryVariable;
}
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);
}
};
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// isprime();
// coeff();
/*freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);*/
/*rlimit rlim;
if (getrlimit(RLIMIT_STACK, &rlim)) return 1;
rlim.rlim_cur = rlim.rlim_max;
if (setrlimit(RLIMIT_STACK, &rlim)) return 2;*/
ll n = nxt(), k = nxt();
vc<ll> v(n);
generate(all(v), nxt);
sort(all(v));
ll low = 0, high = v[n - 1];
while (low <= high) {
ll mid = (low + high) / 2;
ll tot = 0;
rep(a, 0, n) {
if (v[a] > mid)
tot += v[a] / mid;
}
if (tot > k)
low = mid + 1;
else
high = mid - 1;
}
cout << low << endl;
return 0;
} | /* winners never quit and quitters never win.
#swap */
#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;
#pragma GCC optimize("-O3")
using ll = long long;
using ld = long double;
const ll mod = 1000000007;
const ll inf = 1000000000000000000;
const ll rk = 256;
const ld PI = 3.141592653589793;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
template <typename T> void make_unique(vector<T> &vec) {
sort(all(vec));
vec.erase(unique(all(vec)), vec.end());
}
#define endl '\n'
#define pb push_back
#define mp make_pair
#define vc vector
#define fs first
#define sec second
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll, ll>
#define pls pair<ll, string>
#define psl pair<string, ll>
#define plc pair<ll, char>
#define pcl pair<char, ll>
#define pss pair<string, string>
#define all(x) (x).begin(), (x).end()
#define tol(s) transform(s.begin(), s.end(), s.begin(), ::tolower);
#define tou(s) transform(s.begin(), s.end(), s.begin(), ::toupper);
#define printclock \
cerr << "Time : " << 1000 * (ld)clock() / (ld)CLOCKS_PER_SEC << "ms\n";
#define error(args...) \
{ \
string _s = #args; \
replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); \
istream_iterator<string> _it(_ss); \
err(_it, args); \
}
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...);
}
#define rep(i, begin, end) \
for (__typeof(end) i = (begin) - ((begin) > (end)); \
i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define T \
ll t = 0; \
cin >> t; \
for (ll test = 0; test < t; test++)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll nxt() {
ll TemporaryVariable;
cin >> TemporaryVariable;
return TemporaryVariable;
}
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);
}
};
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// isprime();
// coeff();
/*freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);*/
/*rlimit rlim;
if (getrlimit(RLIMIT_STACK, &rlim)) return 1;
rlim.rlim_cur = rlim.rlim_max;
if (setrlimit(RLIMIT_STACK, &rlim)) return 2;*/
ll n = nxt(), k = nxt();
vc<ll> v(n);
generate(all(v), nxt);
sort(all(v));
ll low = 1, high = v[n - 1];
while (low <= high) {
ll mid = (low + high) / 2;
ll tot = 0;
rep(a, 0, n) {
if (v[a] > mid)
tot += v[a] / mid;
}
if (tot > k)
low = mid + 1;
else
high = mid - 1;
}
cout << low << endl;
return 0;
} | replace | 110 | 111 | 110 | 111 | 0 | |
p02598 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
long long N, K;
cin >> N >> K;
long long A[N];
for (int i = 0; i < N; i++)
cin >> A[i];
long long left = -1, right = 1000000000;
while (right - left > 1) {
long long mid = (left + right) / 2;
long long count = 0;
for (long long i = 0; i < N; i++) {
count += A[i] / mid;
if (A[i] % mid == 0)
count--;
if (count > K)
break;
}
if (count <= K)
right = mid;
else
left = mid;
}
cout << right << endl;
} | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
long long N, K;
cin >> N >> K;
long long A[N];
for (int i = 0; i < N; i++)
cin >> A[i];
long long left = -1, right = 1000000000;
while (right - left > 1) {
long long mid = (left + right) / 2;
long long count = 0;
for (long long i = 0; i < N; i++) {
if (mid == 0) {
count = 100000000000;
break;
}
count += A[i] / mid;
if (A[i] % mid == 0)
count--;
if (count > K)
break;
}
if (count <= K)
right = mid;
else
left = mid;
}
cout << right << endl;
}
| insert | 16 | 16 | 16 | 20 | 0 | |
p02598 | C++ | Runtime Error | #include <bits/stdc++.h>
#define MSET(x, y) memset(x, y, sizeof(x))
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 100005
#define ll long long
#define ld long double
#define INF 1e18
#define endl "\n"
#define fastio \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
using namespace std;
ll MOD = 1000000007;
string yes = "Yes\n";
string no = "No\n";
vector<ll> a;
ll k;
bool f(ll mid) {
ll ans = 0;
for (auto itr : a) {
ans += (itr - 1) / mid;
}
if (ans > k)
return true;
else
return false;
}
int32_t main() {
fastio;
#ifndef ONLINE_JUDGE
freopen("i.txt", "r", stdin);
freopen("o.txt", "w", stdout);
#endif
ll n;
cin >> n >> k;
for (ll i = 0; i < n; i++) {
ll x;
cin >> x;
a.PB(x);
}
sort(a.begin(), a.end());
ll lo = 1, hi = 1e9, ans = -1, mid;
while (lo <= hi) {
mid = (lo + hi) / 2;
if (f(mid))
ans = mid, lo = mid + 1;
else
hi = mid - 1;
}
if (ans == -1) {
ll a = 0;
cout << 2 / a;
}
cout << ans + 1 << endl;
} | #include <bits/stdc++.h>
#define MSET(x, y) memset(x, y, sizeof(x))
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 100005
#define ll long long
#define ld long double
#define INF 1e18
#define endl "\n"
#define fastio \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
using namespace std;
ll MOD = 1000000007;
string yes = "Yes\n";
string no = "No\n";
vector<ll> a;
ll k;
bool f(ll mid) {
ll ans = 0;
for (auto itr : a) {
ans += (itr - 1) / mid;
}
if (ans > k)
return true;
else
return false;
}
int32_t main() {
fastio;
#ifndef ONLINE_JUDGE
freopen("i.txt", "r", stdin);
freopen("o.txt", "w", stdout);
#endif
ll n;
cin >> n >> k;
for (ll i = 0; i < n; i++) {
ll x;
cin >> x;
a.PB(x);
}
sort(a.begin(), a.end());
ll lo = 1, hi = 1e9, ans = -1, mid;
while (lo <= hi) {
mid = (lo + hi) / 2;
if (f(mid))
ans = mid, lo = mid + 1;
else
hi = mid - 1;
}
if (ans == -1) {
cout << 1 << endl;
return 0;
}
cout << ans + 1 << endl;
} | replace | 58 | 60 | 58 | 60 | -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;
typedef long long ll;
typedef pair<int, int> P;
struct edge {
int to;
ll cost;
};
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, 1, -1};
ll GCD(ll a, ll b) {
if (b == 0)
return a;
else
return GCD(b, a % b);
}
ll LCM(ll a, ll b) {
if (a < b)
swap(a, b);
return a / GCD(a, b) * b;
}
int main() {
int n;
ll k;
cin >> n >> k;
ll a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
ll lo = -1, hi = 1000000005;
while (hi - lo > 1) {
ll mid = (lo + hi) / 2;
ll tmp = 0;
for (int i = 0; i < n; i++) {
tmp += a[i] / mid - 1;
if (a[i] % mid)
tmp++;
}
if (tmp > k)
lo = mid;
else
hi = mid;
}
cout << hi << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
struct edge {
int to;
ll cost;
};
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, 1, -1};
ll GCD(ll a, ll b) {
if (b == 0)
return a;
else
return GCD(b, a % b);
}
ll LCM(ll a, ll b) {
if (a < b)
swap(a, b);
return a / GCD(a, b) * b;
}
int main() {
int n;
ll k;
cin >> n >> k;
ll a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
ll lo = 0, hi = 1000000005;
while (hi - lo > 1) {
ll mid = (lo + hi) / 2;
ll tmp = 0;
for (int i = 0; i < n; i++) {
tmp += a[i] / mid - 1;
if (a[i] % mid)
tmp++;
}
if (tmp > k)
lo = mid;
else
hi = mid;
}
cout << hi << endl;
return 0;
}
| replace | 35 | 36 | 35 | 36 | 0 | |
p02598 | C++ | Time Limit Exceeded | #pragma region header
#include <bits/stdc++.h>
#define int long long
#define all(a) begin(a), end(a)
#define rall(a) rbegin(a), rend(a)
#define mp make_pair
#define mt make_tuple
#define rep1(i, n) for (decltype(+n) i = 0; i < (n); i++)
#define rrep1(i, n) for (auto i = n - 1; i > static_cast<decltype(i)>(-1); i--)
#define rep2(i, a, b) for (auto i = (a); i < (b); i++)
#define rrep2(i, a, b) for (auto i = b - 1; i >= a; i--)
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define rrep(...) GET_MACRO(__VA_ARGS__, rrep2, rrep1)(__VA_ARGS__)
#define each(i, a) for (auto &&i : (a))
using namespace std;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using vvs = vector<vs>;
using vd = vector<ld>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using vp = vector<pii>;
using vvp = vector<vp>;
using mii = map<int, int>;
using vm = vector<mii>;
using vvm = vector<vm>;
template <class T, class U> using umap = unordered_map<T, U>;
using umii = umap<int, int>;
using seti = set<int>;
template <class T> using uset = unordered_set<T>;
using useti = uset<int>;
template <class T> using less_queue = priority_queue<T>;
template <class T>
using greater_queue = priority_queue<T, vector<T>, greater<T>>;
constexpr int INF = 1e18;
template <class T> void SORT(T &a) { stable_sort(all(a)); }
template <class T> void RSORT(T &a) { stable_sort(rall(a)); }
template <class T> void rev(T &a) { reverse(rall(a)); }
template <class T> void uniq(T &a) { a.erase(unique(all(a)), end(a)); }
template <class T> auto min_of(T a) { return *min_element(all(a)); }
template <class T> auto max_of(T a) { return *max_element(all(a)); }
template <class T> int sum_of(T a) { return accumulate(all(a), 0ll); }
template <class T, class U> auto sum_of(T a, U init) {
return accumulate(all(a), init);
}
template <class T, class U> int count_of(T a, U i) { return count(all(a), i); }
template <class T, class U> bool has(T a, U i) {
return find(all(a), i) != end(a);
}
template <class T> int sz(T a) { return a.size(); };
template <class T> void COUT(T x) { cout << x << endl; }
template <class T, class U> void COUT(T x, U y) {
cout << x << ' ' << y << endl;
}
template <class T, class U, class V> void COUT(T x, U y, V z) {
cout << x << ' ' << y << ' ' << z << endl;
}
template <class T> void CSP(T x) { cout << x << ' '; }
template <class T> void CVEC(T v) {
int c = v.size() - 1;
for (size_t i = 0; i < c; i++)
cout << v[i] << ' ';
if (c > -1)
cout << v[c];
cout << endl;
}
template <class T> bool amin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> bool amax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
constexpr int lshift(int x) noexcept { return 1ll << x; }
constexpr int popcount(unsigned int x) noexcept {
return __builtin_popcountll(x);
}
constexpr int least1(unsigned int x) noexcept { return __builtin_ffsll(x); }
constexpr int ceil_div(int x, int y) noexcept { return (x - 1) / y + 1; }
#pragma endregion header
// no MOD
void solve(int n, int k, vi a) {
RSORT(a);
int l = 0, r = a[0];
while (r - l > 1) {
int m = (l + r) / 2;
int cnt = k;
bool ok = true;
rep(i, n) {
bool cut = false;
rep(d, cnt + 1) {
if (ceil_div(a[i], d + 1) <= m) {
cnt -= d;
cut = true;
break;
}
}
if (!cut) {
ok = false;
break;
}
}
(ok ? r : l) = m;
}
COUT(r);
}
#pragma region main
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout << fixed << setprecision(15);
int n;
cin >> n;
int k;
cin >> k;
vi a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
solve(n, k, move(a));
}
#pragma endregion main
| #pragma region header
#include <bits/stdc++.h>
#define int long long
#define all(a) begin(a), end(a)
#define rall(a) rbegin(a), rend(a)
#define mp make_pair
#define mt make_tuple
#define rep1(i, n) for (decltype(+n) i = 0; i < (n); i++)
#define rrep1(i, n) for (auto i = n - 1; i > static_cast<decltype(i)>(-1); i--)
#define rep2(i, a, b) for (auto i = (a); i < (b); i++)
#define rrep2(i, a, b) for (auto i = b - 1; i >= a; i--)
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define rrep(...) GET_MACRO(__VA_ARGS__, rrep2, rrep1)(__VA_ARGS__)
#define each(i, a) for (auto &&i : (a))
using namespace std;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using vvs = vector<vs>;
using vd = vector<ld>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using vp = vector<pii>;
using vvp = vector<vp>;
using mii = map<int, int>;
using vm = vector<mii>;
using vvm = vector<vm>;
template <class T, class U> using umap = unordered_map<T, U>;
using umii = umap<int, int>;
using seti = set<int>;
template <class T> using uset = unordered_set<T>;
using useti = uset<int>;
template <class T> using less_queue = priority_queue<T>;
template <class T>
using greater_queue = priority_queue<T, vector<T>, greater<T>>;
constexpr int INF = 1e18;
template <class T> void SORT(T &a) { stable_sort(all(a)); }
template <class T> void RSORT(T &a) { stable_sort(rall(a)); }
template <class T> void rev(T &a) { reverse(rall(a)); }
template <class T> void uniq(T &a) { a.erase(unique(all(a)), end(a)); }
template <class T> auto min_of(T a) { return *min_element(all(a)); }
template <class T> auto max_of(T a) { return *max_element(all(a)); }
template <class T> int sum_of(T a) { return accumulate(all(a), 0ll); }
template <class T, class U> auto sum_of(T a, U init) {
return accumulate(all(a), init);
}
template <class T, class U> int count_of(T a, U i) { return count(all(a), i); }
template <class T, class U> bool has(T a, U i) {
return find(all(a), i) != end(a);
}
template <class T> int sz(T a) { return a.size(); };
template <class T> void COUT(T x) { cout << x << endl; }
template <class T, class U> void COUT(T x, U y) {
cout << x << ' ' << y << endl;
}
template <class T, class U, class V> void COUT(T x, U y, V z) {
cout << x << ' ' << y << ' ' << z << endl;
}
template <class T> void CSP(T x) { cout << x << ' '; }
template <class T> void CVEC(T v) {
int c = v.size() - 1;
for (size_t i = 0; i < c; i++)
cout << v[i] << ' ';
if (c > -1)
cout << v[c];
cout << endl;
}
template <class T> bool amin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> bool amax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
constexpr int lshift(int x) noexcept { return 1ll << x; }
constexpr int popcount(unsigned int x) noexcept {
return __builtin_popcountll(x);
}
constexpr int least1(unsigned int x) noexcept { return __builtin_ffsll(x); }
constexpr int ceil_div(int x, int y) noexcept { return (x - 1) / y + 1; }
#pragma endregion header
// no MOD
void solve(int n, int k, vi a) {
RSORT(a);
int l = 0, r = a[0];
while (r - l > 1) {
int m = (l + r) / 2;
int cnt = k;
bool ok = true;
rep(i, n) {
cnt -= ceil_div(a[i], m) - 1;
if (cnt < 0) {
ok = false;
break;
}
}
(ok ? r : l) = m;
}
COUT(r);
}
#pragma region main
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout << fixed << setprecision(15);
int n;
cin >> n;
int k;
cin >> k;
vi a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
solve(n, k, move(a));
}
#pragma endregion main
| replace | 110 | 119 | 110 | 112 | TLE | |
p02598 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define endl "\n"
const int N = 1e5 + 5;
int n, k;
int a[N];
bool check(int x) {
int reqd = 0;
for (int i = 0; i + 1 <= n; i++) {
int diff = a[i];
reqd += (diff - 1) / x;
if (reqd > k)
return 0;
}
return 1;
}
int binsearch(int lo, int hi) {
while (lo < hi) {
int mid = (lo + hi) / 2;
if (mid == 0) {
return 0;
}
if (check(mid))
hi = mid;
else
lo = mid + 1;
}
return lo;
}
int main() {
IOS;
int t = 1;
int tc = 0;
while (t--) {
tc++;
cin >> n >> k;
for (int i = 0; i < n; i++)
cin >> a[i];
int ans = binsearch(1, 1e9);
cout << ans;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define endl "\n"
const int N = 200001;
int n, k;
int a[N];
bool check(int x) {
int reqd = 0;
for (int i = 0; i + 1 <= n; i++) {
int diff = a[i];
reqd += (diff - 1) / x;
if (reqd > k)
return 0;
}
return 1;
}
int binsearch(int lo, int hi) {
while (lo < hi) {
int mid = (lo + hi) / 2;
if (mid == 0) {
return 0;
}
if (check(mid))
hi = mid;
else
lo = mid + 1;
}
return lo;
}
int main() {
IOS;
int t = 1;
int tc = 0;
while (t--) {
tc++;
cin >> n >> k;
for (int i = 0; i < n; i++)
cin >> a[i];
int ans = binsearch(1, 1e9);
cout << ans;
}
return 0;
} | replace | 9 | 10 | 9 | 10 | 0 | |
p02598 | C++ | Runtime Error | #include <bits/stdc++.h> //Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(), (v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vii vector<pii>
#define MOD 1000000007
#define MOD2 998244353
#define MOD3 1000000009
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER \
ios_base::sync_with_stdio(0); \
cin.tie(0)
template <class A, class B>
ostream &operator<<(ostream &out, const pair<A, B> &a) {
return out << "(" << a.first << "," << a.second << ")";
}
template <class A> ostream &operator<<(ostream &out, const vector<A> &a) {
for (const A &it : a)
out << it << " ";
return out;
}
template <class A, class B> istream &operator>>(istream &in, pair<A, B> &a) {
return in >> a.first >> a.second;
}
template <class A> istream &operator>>(istream &in, vector<A> &a) {
for (A &i : a)
in >> i;
return in;
}
// ifstream cinn("in.in");ofstream coutt("out.out");
int poww(const int &a, int b, const int &m = MOD) {
if (b == 0)
return 1;
int x = poww(a, b / 2, m);
x = x * x % m;
if (b & 1)
x = x * a % m;
return x;
}
int ceil(const int &a, const int &b) { return (a + b - 1) / b; }
////Read:
// Check corner cases, n==1;
//
////Some function:
//__builtin_popcountll(), is_sorted(),
int n, k;
vi v;
bool f(int mnLen) { // mnLen-0.999 , mnLen , possible ?
int cnt = 0;
for (int i : v) {
cnt += ceil(i, mnLen) - 1;
}
return cnt <= k;
}
signed main() {
FASTER;
cin >> n >> k;
v = vi(n);
cin >> v;
int s = 0, e = 1e9, ans = -1;
while (s <= e) {
int mid = (s + e) / 2;
if (f(mid))
e = mid - 1, ans = mid;
else
s = mid + 1;
}
cout << ans;
}
| #include <bits/stdc++.h> //Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(), (v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vii vector<pii>
#define MOD 1000000007
#define MOD2 998244353
#define MOD3 1000000009
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER \
ios_base::sync_with_stdio(0); \
cin.tie(0)
template <class A, class B>
ostream &operator<<(ostream &out, const pair<A, B> &a) {
return out << "(" << a.first << "," << a.second << ")";
}
template <class A> ostream &operator<<(ostream &out, const vector<A> &a) {
for (const A &it : a)
out << it << " ";
return out;
}
template <class A, class B> istream &operator>>(istream &in, pair<A, B> &a) {
return in >> a.first >> a.second;
}
template <class A> istream &operator>>(istream &in, vector<A> &a) {
for (A &i : a)
in >> i;
return in;
}
// ifstream cinn("in.in");ofstream coutt("out.out");
int poww(const int &a, int b, const int &m = MOD) {
if (b == 0)
return 1;
int x = poww(a, b / 2, m);
x = x * x % m;
if (b & 1)
x = x * a % m;
return x;
}
int ceil(const int &a, const int &b) { return (a + b - 1) / b; }
////Read:
// Check corner cases, n==1;
//
////Some function:
//__builtin_popcountll(), is_sorted(),
int n, k;
vi v;
bool f(int mnLen) { // mnLen-0.999 , mnLen , possible ?
int cnt = 0;
for (int i : v) {
cnt += ceil(i, mnLen) - 1;
}
return cnt <= k;
}
signed main() {
FASTER;
cin >> n >> k;
v = vi(n);
cin >> v;
int s = 1, e = 1e9, ans = -1;
while (s <= e) {
int mid = (s + e) / 2;
if (f(mid))
e = mid - 1, ans = mid;
else
s = mid + 1;
}
cout << ans;
}
| replace | 69 | 70 | 69 | 70 | 0 | |
p02598 | C++ | Runtime Error | #include <bits/stdc++.h>
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for (ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
return a > b && (a = b, true);
}
/*-------------------------------------------*/
int n;
ll a[100009];
ll k;
bool f(ll x) {
ll cnt = 0;
rep(i, n) cnt += (a[i] + x - 1) / x;
return cnt - n <= k;
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cin >> n >> k;
rep(i, n) cin >> a[i];
ll ng = 0, ok = 1e9 + 1;
while (ng + 1 < ok)
(f(ng + ok >> 1) ? ok : ng) = ng + ok >> 1;
cout << ok << endl;
return 0;
} | #include <bits/stdc++.h>
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for (ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
return a > b && (a = b, true);
}
/*-------------------------------------------*/
int n;
ll a[200009];
ll k;
bool f(ll x) {
ll cnt = 0;
rep(i, n) cnt += (a[i] + x - 1) / x;
return cnt - n <= k;
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cin >> n >> k;
rep(i, n) cin >> a[i];
ll ng = 0, ok = 1e9 + 1;
while (ng + 1 < ok)
(f(ng + ok >> 1) ? ok : ng) = ng + ok >> 1;
cout << ok << endl;
return 0;
} | replace | 20 | 21 | 20 | 21 | 0 | |
p02598 | C++ | Runtime Error | #include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define sz 200009
ll n, m, i, j, k, l, t, arr[sz], brr[sz], crr[sz], ans, hi, lo, mi;
char c[sz];
int main() {
scanf("%lld %lld", &n, &k);
for (i = 1; i <= n; i++)
scanf("%lld", &arr[i]), hi = max(hi, arr[i]);
ans = hi;
while (hi >= lo) {
mi = (hi + lo) / 2;
j = 0;
for (i = 1; i <= n; i++) {
j += arr[i] / mi;
if (arr[i] % mi)
j++;
j--;
}
if (j <= k) {
ans = min(ans, mi);
hi = mi - 1;
} else
lo = mi + 1;
}
printf("%lld\n", ans);
return 0;
}
| #include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define sz 200009
ll n, m, i, j, k, l, t, arr[sz], brr[sz], crr[sz], ans, hi, lo, mi;
char c[sz];
int main() {
scanf("%lld %lld", &n, &k);
for (i = 1; i <= n; i++)
scanf("%lld", &arr[i]), hi = max(hi, arr[i]);
ans = hi;
lo = 1;
while (hi >= lo) {
mi = (hi + lo) / 2;
j = 0;
for (i = 1; i <= n; i++) {
j += arr[i] / mi;
if (arr[i] % mi)
j++;
j--;
}
if (j <= k) {
ans = min(ans, mi);
hi = mi - 1;
} else
lo = mi + 1;
}
printf("%lld\n", ans);
return 0;
}
| insert | 11 | 11 | 11 | 12 | 0 | |
p02598 | C++ | Time Limit Exceeded |
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif
void d_err() { cerr << endl; }
template <typename H, typename... T> void d_err(H h, T... t) {
cerr << h << " ";
d_err(t...);
}
template <typename T> void print(T x) { cout << x << endl; }
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pin;
ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9 + 7;
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(20);
ll N, K;
cin >> N >> K;
vll v(N);
REP(i, N) cin >> v[i];
ll ng = 0, ok = INF;
while (ok - ng > 1) {
ll mid = (ng + ok) / 2;
ll cnt = 0;
REP(i, N) {
ll c = v[i];
while (c > mid) {
c -= mid;
cnt++;
}
}
if (cnt <= K)
ok = mid;
else
ng = mid;
}
print(ok);
}
|
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif
void d_err() { cerr << endl; }
template <typename H, typename... T> void d_err(H h, T... t) {
cerr << h << " ";
d_err(t...);
}
template <typename T> void print(T x) { cout << x << endl; }
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pin;
ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9 + 7;
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(20);
ll N, K;
cin >> N >> K;
vll v(N);
REP(i, N) cin >> v[i];
ll ng = 0, ok = INF;
while (ok - ng > 1) {
ll mid = (ng + ok) / 2;
ll cnt = 0;
REP(i, N) {
ll c = v[i];
if (mid >= c)
continue;
cnt += c / mid;
}
if (cnt <= K)
ok = mid;
else
ng = mid;
}
print(ok);
}
| replace | 62 | 66 | 62 | 65 | TLE | |
p02598 | C++ | Time Limit Exceeded | #define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int N, K, tmp, high, mid, low, res = 0;
priority_queue<long long int> A;
cin >> N >> K;
rep(i, N) {
cin >> tmp;
A.push(tmp);
}
high = A.top() + 1;
low = 0;
while (high > low) {
mid = (high + low) / 2 + 1;
priority_queue<long long int> tmp_que = A;
long long int count = 0;
rep(i, N) {
long long int tmp = tmp_que.top();
if (tmp <= mid) {
break;
}
if (tmp % mid == 0) {
count += (tmp / mid - 1);
} else {
count += tmp / mid;
}
tmp_que.pop();
}
if (count <= K) {
res = mid;
high = mid;
} else {
low = mid + 1;
}
}
cout << res;
return 0;
} | #define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int N, K, tmp, high, mid, low, res = 0;
priority_queue<long long int> A;
cin >> N >> K;
rep(i, N) {
cin >> tmp;
A.push(tmp);
}
high = A.top() + 1;
low = 0;
while (high > low) {
mid = (high + low) / 2;
if (mid == 0) {
break;
}
priority_queue<long long int> tmp_que = A;
long long int count = 0;
rep(i, N) {
long long int tmp = tmp_que.top();
if (tmp <= mid) {
break;
}
if (tmp % mid == 0) {
count += (tmp / mid - 1);
} else {
count += tmp / mid;
}
tmp_que.pop();
}
if (count <= K) {
res = mid;
high = mid;
} else {
low = mid + 1;
}
}
cout << res;
return 0;
} | replace | 21 | 22 | 21 | 25 | TLE | |
p02598 | C++ | Runtime Error | #pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<pair<ll, ll>> vpll;
#define kill \
freopen("input.txt", "r", stdin); \
freopen("output.txt", "w", stdout);
#define pb push_back
#define fo(i, n) for (ll i = 0; i < n; i++)
#define rev(i, n) for (ll i = n - 1; i >= 0; i--)
#define all(c) c.begin(), c.end()
#define go(c, it) for (auto it = (c).begin(); it != (c).end(); it++)
#define fi first
#define se second
#define MOD 998244353
#define Boost() \
ios_base::sync_with_stdio(false); \
cin.tie(NULL)
#define MOD1 1000000007
ll power(ll a, ll b) {
ll res = 1;
a = a % MOD;
while (b > 0) {
if (b & 1) {
res = (res * a) % MOD;
}
a = (a * a) % MOD;
b >>= 1;
}
return res;
}
ll fermat_inv(ll y) { return power(y, MOD - 2); }
ll gcd(ll a, ll b) { return (b == 0) ? a : gcd(b, a % b); }
#define oo 100000000000000000
const ll dx[] = {-1, 0, 1, 0, -1, 1, 1, -1};
const ll dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
void solve() {
ll n, k;
cin >> n >> k;
ll a[n];
fo(i, n) cin >> a[i];
ll ans = oo;
ll lo = 0, hi = 1e12;
while (lo <= hi) {
ll mid = (lo + hi) >> 1LL;
ll val = 0;
fo(i, n) {
if (a[i] > mid) {
ll cut = a[i] / mid;
if (a[i] % mid == 0)
cut--;
val += cut;
}
}
if (val <= k) {
ans = min(ans, mid);
hi = mid - 1;
} else {
lo = mid + 1;
}
}
cout << ans;
}
int main() {
Boost();
ll T = 1;
// cin>>T;
while (T--) {
solve();
}
return 0;
}
| #pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<pair<ll, ll>> vpll;
#define kill \
freopen("input.txt", "r", stdin); \
freopen("output.txt", "w", stdout);
#define pb push_back
#define fo(i, n) for (ll i = 0; i < n; i++)
#define rev(i, n) for (ll i = n - 1; i >= 0; i--)
#define all(c) c.begin(), c.end()
#define go(c, it) for (auto it = (c).begin(); it != (c).end(); it++)
#define fi first
#define se second
#define MOD 998244353
#define Boost() \
ios_base::sync_with_stdio(false); \
cin.tie(NULL)
#define MOD1 1000000007
ll power(ll a, ll b) {
ll res = 1;
a = a % MOD;
while (b > 0) {
if (b & 1) {
res = (res * a) % MOD;
}
a = (a * a) % MOD;
b >>= 1;
}
return res;
}
ll fermat_inv(ll y) { return power(y, MOD - 2); }
ll gcd(ll a, ll b) { return (b == 0) ? a : gcd(b, a % b); }
#define oo 100000000000000000
const ll dx[] = {-1, 0, 1, 0, -1, 1, 1, -1};
const ll dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
void solve() {
ll n, k;
cin >> n >> k;
ll a[n];
fo(i, n) cin >> a[i];
ll ans = oo;
ll lo = 0, hi = 1e12;
while (lo <= hi) {
ll mid = (lo + hi) >> 1LL;
if (mid == 0) {
ans = 1;
break;
}
ll val = 0;
fo(i, n) {
if (a[i] > mid) {
ll cut = a[i] / mid;
if (a[i] % mid == 0)
cut--;
val += cut;
}
}
if (val <= k) {
ans = min(ans, mid);
hi = mid - 1;
} else {
lo = mid + 1;
}
}
cout << ans;
}
int main() {
Boost();
ll T = 1;
// cin>>T;
while (T--) {
solve();
}
return 0;
}
| insert | 52 | 52 | 52 | 56 | 0 | |
p02598 | C++ | Runtime Error | #include "bits/stdc++.h"
using namespace std;
bool possible(long long longestLog, const vector<long long> &A, long long K) {
long long N = A.size();
long long numOfLongestLogs = 0;
for (long long i = 0; i < N; ++i) {
numOfLongestLogs += A[i] / longestLog;
if (A[i] % longestLog == 0) {
--numOfLongestLogs;
}
}
return (numOfLongestLogs <= K);
}
void Main() {
long long N, K;
cin >> N >> K;
vector<long long> A(N, 0LL);
for (long long i = 0; i < N; ++i) {
cin >> A[i];
}
sort(A.begin(), A.end(), greater<long long>());
long long ub = A.front();
long long lb = 0LL;
while (ub - lb > 1LL) {
long long mid = (ub + lb) / 2LL;
if (possible(mid, A, K)) {
ub = mid;
} else {
lb = mid;
}
}
bool test = possible(lb, A, K);
if (test) {
cout << "";
}
cout << ub << endl;
}
int main() {
std::cout << std::fixed << std::setprecision(15);
Main();
return 0;
}
| #include "bits/stdc++.h"
using namespace std;
bool possible(long long longestLog, const vector<long long> &A, long long K) {
long long N = A.size();
long long numOfLongestLogs = 0;
for (long long i = 0; i < N; ++i) {
numOfLongestLogs += A[i] / longestLog;
if (A[i] % longestLog == 0) {
--numOfLongestLogs;
}
}
return (numOfLongestLogs <= K);
}
void Main() {
long long N, K;
cin >> N >> K;
vector<long long> A(N, 0LL);
for (long long i = 0; i < N; ++i) {
cin >> A[i];
}
sort(A.begin(), A.end(), greater<long long>());
long long ub = A.front();
long long lb = 0LL;
while (ub - lb > 1LL) {
long long mid = (ub + lb) / 2LL;
if (possible(mid, A, K)) {
ub = mid;
} else {
lb = mid;
}
}
bool test = possible(lb, A, K);
if (test) {
test != test;
}
cout << ub << endl;
}
int main() {
std::cout << std::fixed << std::setprecision(15);
Main();
return 0;
}
| replace | 37 | 38 | 37 | 38 | 0 | |
p02598 | C++ | Runtime Error | /*
`-:://:::-
`//:-------:/:`
.+:--.......--:+`
`+:--..`````..--//`
.o:--..`` ``..--:o`
.o:--...```..---+/`
`/y+o/---....---:+o.
`...````-os+/:---:/+o/--.`
`-/+++++/:. `...` :h+d+oooo+/+-` ...
`/++//:::://++-`....` -.`//````````:` `..`
`o+/::------://o/` `-` -. -` `..`
`---.-o/:./o/::-..``..-ЗАПУСКАЕМ .. .. -` `... ``..``
`....o+:-++/:--.```..-://s. `-` .- -` `-o:
.-//::::/:-`
`:s+/:--....-::/+s-` .- `- -` -///:--------:/:`
./s+//:::::://oo-``..НЕЙРОННУЮ: СЕТЬ:::::::-`РАБОТЯГИ
`+:--........--:/`
.:ooo+++++osso-` `.:-...`/` ./::-------:/:` -`
:+--..``````.--:+:...-+:-`
`.-/+++++/+-.-` -. ``:so:/:--.......--:+`
`-```````o+/+--..`````..--:o/-..:s+:.
```````:``.. `-` -`
`+:--..`````..--/+-.../.`````..-o:--.......---/o. `
`: `:- -. .o:--..`` ``..--:o` `-`
`:o+:--------:+o-`
`-`-... .. .o/--...```..--:+/` `-`
`oy/so/////++o/.`
-/` `-` `- ``+s/o/:---...---:++. `-`
.-../d://///:-.`
`.---..``-..- .-/..`````-oo+/:::::/+o+- `-``-` `-.
````
`:++++/+++++- ..``.-/:` /y-:/++o++/:.`..` ./. `-
-++/::::::://+/..:-``:` .. `-.` ```.``` `..` `..`-` `-
`` -o//:--....-::/++` -.-` `-`.-` `..`..` `-.-
-----ss+:++/:--.```..-://s. /. `:: `-:. ./`
`````/:..+o/::-..``.--:/+s. ..-` `-``-` ..` `-` `-`-`
`-s+/::-----::/+oo---``-` .. .:- ``` .-` .-.- `-`
`:oo+//::://+os/..:`..-/:` :y.-:::::::.`.-` ./-` `-`
`./+oooooooo+/.`- .-:...`.. .//:-------://` `- `..` `:.
``.-::::-.``-/` `-` `- `oo:+:--.......--:/` `-
`.:--h.``..```
-.-`.- .- `+:--..`````..--//` `-
/s-//::::::::.
-` `/- .. .o:--..`` ``..--:o.```.-
`//:--------://`
-` .-`.-`
-.`-o/--...```..--:+/.``-:....``:-.+:--....`...--:+`
..`-. `-. ``:os:o/:---...---:++. `-
``///+:-..``````.--:+-````-.`
`.:///////.-` .:-..` -``-+o+/:::::/+o/. `-
`:+:-..`````..--:o/:--/ys+-
`-++///////+o/. ``....`-. :` `.:++++++/:.` .- -o/---......---/o.
`.`
`++//:-----::/+o:..` .-` : ``````` .- `+so+:--------:++-`
`````:-``:o/::-..`..--:/+o` -. `- .- `../../+o+////+o+:.`
-----syo/o+/:--.```..-://s. .-` `- .- `...
``-:////:-``
.` `/s//:--....-::/+s. -. `-` .- `..`
.+o+/:::--:://+s/-..` .::+y ``` .- `..`
./oo++////+oso-` `.... :y-+:::::::/` ...
`.:+oooooo/-` `....-. .//:-------:/:-.`
``...`` /+:+:--.......--:+`
`+:--..`````..--//`
.o:--..`` ``..--:o`
.+/--...```..--:+/`
`-o/:---...---:++.
`-+o+/:---:/+o/.
`.:+oooo+/-.`
``````
*/
// #pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target( \
"sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
// #pragma GCC optimize("section-anchors")
// #pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
// #pragma GCC optimize("vpt")
// #pragma GCC optimize("rename-registers")
// #pragma GCC optimize("move-loop-invariants")
// #pragma GCC optimize("unswitch-loops")
// #pragma GCC optimize("function-sections")
// #pragma GCC optimize("data-sections")
// #pragma GCC optimize("branch-target-load-optimize")
// #pragma GCC optimize("branch-target-load-optimize2")
// #pragma GCC optimize("btr-bb-exclusive")
// #pragma comment(linker, "/STACK:367077216")
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define DEBUG
#define fi first
#define se second
#define pqueue priority_queue
#define pb(x) push_back(x)
// #define endl '\n'
#define all(x) x.begin(), x.end()
#define int long long
#define mk(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ull> vull;
typedef vector<ll> vll;
// typedef tuple<ll, ll, ll> tiii;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vpii;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<vector<ll>> vvll;
typedef vector<char> vc;
const int INF = 1e9 + 228;
const ll INFLL = 1e18;
const ll MOD = 1e9 + 7;
// static const int maxn = 1e6 + 228;
const ld eps = 1e-6;
const ld eps2 = 1e-9;
const ll MOD2 = 998244353;
const ll dosz = 5e5;
const ll SZ = (1 << 18);
const ld PI = atan2l(0, -1);
void fast_io() {
ios_base::sync_with_stdio(0);
cin.tie(0);
// freopen("a.in", "r", stdin);
// freopen("logs.out", "w", stdout);
}
void solve() {
int n, k;
cin >> n >> k;
vi nums(n);
for (int i = 0; i < n; i++) {
cin >> nums[i];
}
int l = 0, r = 1e9;
int ans = 1e9;
while (l <= r) {
int mid = (l + r) / 2;
int cnt = 0;
for (int i : nums) {
cnt += (i + mid - 1) / mid - 1;
}
if (cnt > k) {
l = mid + 1;
} else {
ans = mid;
r = mid - 1;
}
}
cout << ans << endl;
}
signed main() {
fast_io();
// srand(time(NULL));
// cout << fixed << setprecision(12);
int q = 1;
// cin >> q;
while (q--)
solve();
} | /*
`-:://:::-
`//:-------:/:`
.+:--.......--:+`
`+:--..`````..--//`
.o:--..`` ``..--:o`
.o:--...```..---+/`
`/y+o/---....---:+o.
`...````-os+/:---:/+o/--.`
`-/+++++/:. `...` :h+d+oooo+/+-` ...
`/++//:::://++-`....` -.`//````````:` `..`
`o+/::------://o/` `-` -. -` `..`
`---.-o/:./o/::-..``..-ЗАПУСКАЕМ .. .. -` `... ``..``
`....o+:-++/:--.```..-://s. `-` .- -` `-o:
.-//::::/:-`
`:s+/:--....-::/+s-` .- `- -` -///:--------:/:`
./s+//:::::://oo-``..НЕЙРОННУЮ: СЕТЬ:::::::-`РАБОТЯГИ
`+:--........--:/`
.:ooo+++++osso-` `.:-...`/` ./::-------:/:` -`
:+--..``````.--:+:...-+:-`
`.-/+++++/+-.-` -. ``:so:/:--.......--:+`
`-```````o+/+--..`````..--:o/-..:s+:.
```````:``.. `-` -`
`+:--..`````..--/+-.../.`````..-o:--.......---/o. `
`: `:- -. .o:--..`` ``..--:o` `-`
`:o+:--------:+o-`
`-`-... .. .o/--...```..--:+/` `-`
`oy/so/////++o/.`
-/` `-` `- ``+s/o/:---...---:++. `-`
.-../d://///:-.`
`.---..``-..- .-/..`````-oo+/:::::/+o+- `-``-` `-.
````
`:++++/+++++- ..``.-/:` /y-:/++o++/:.`..` ./. `-
-++/::::::://+/..:-``:` .. `-.` ```.``` `..` `..`-` `-
`` -o//:--....-::/++` -.-` `-`.-` `..`..` `-.-
-----ss+:++/:--.```..-://s. /. `:: `-:. ./`
`````/:..+o/::-..``.--:/+s. ..-` `-``-` ..` `-` `-`-`
`-s+/::-----::/+oo---``-` .. .:- ``` .-` .-.- `-`
`:oo+//::://+os/..:`..-/:` :y.-:::::::.`.-` ./-` `-`
`./+oooooooo+/.`- .-:...`.. .//:-------://` `- `..` `:.
``.-::::-.``-/` `-` `- `oo:+:--.......--:/` `-
`.:--h.``..```
-.-`.- .- `+:--..`````..--//` `-
/s-//::::::::.
-` `/- .. .o:--..`` ``..--:o.```.-
`//:--------://`
-` .-`.-`
-.`-o/--...```..--:+/.``-:....``:-.+:--....`...--:+`
..`-. `-. ``:os:o/:---...---:++. `-
``///+:-..``````.--:+-````-.`
`.:///////.-` .:-..` -``-+o+/:::::/+o/. `-
`:+:-..`````..--:o/:--/ys+-
`-++///////+o/. ``....`-. :` `.:++++++/:.` .- -o/---......---/o.
`.`
`++//:-----::/+o:..` .-` : ``````` .- `+so+:--------:++-`
`````:-``:o/::-..`..--:/+o` -. `- .- `../../+o+////+o+:.`
-----syo/o+/:--.```..-://s. .-` `- .- `...
``-:////:-``
.` `/s//:--....-::/+s. -. `-` .- `..`
.+o+/:::--:://+s/-..` .::+y ``` .- `..`
./oo++////+oso-` `.... :y-+:::::::/` ...
`.:+oooooo/-` `....-. .//:-------:/:-.`
``...`` /+:+:--.......--:+`
`+:--..`````..--//`
.o:--..`` ``..--:o`
.+/--...```..--:+/`
`-o/:---...---:++.
`-+o+/:---:/+o/.
`.:+oooo+/-.`
``````
*/
// #pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target( \
"sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
// #pragma GCC optimize("section-anchors")
// #pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
// #pragma GCC optimize("vpt")
// #pragma GCC optimize("rename-registers")
// #pragma GCC optimize("move-loop-invariants")
// #pragma GCC optimize("unswitch-loops")
// #pragma GCC optimize("function-sections")
// #pragma GCC optimize("data-sections")
// #pragma GCC optimize("branch-target-load-optimize")
// #pragma GCC optimize("branch-target-load-optimize2")
// #pragma GCC optimize("btr-bb-exclusive")
// #pragma comment(linker, "/STACK:367077216")
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define DEBUG
#define fi first
#define se second
#define pqueue priority_queue
#define pb(x) push_back(x)
// #define endl '\n'
#define all(x) x.begin(), x.end()
#define int long long
#define mk(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ull> vull;
typedef vector<ll> vll;
// typedef tuple<ll, ll, ll> tiii;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vpii;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<vector<ll>> vvll;
typedef vector<char> vc;
const int INF = 1e9 + 228;
const ll INFLL = 1e18;
const ll MOD = 1e9 + 7;
// static const int maxn = 1e6 + 228;
const ld eps = 1e-6;
const ld eps2 = 1e-9;
const ll MOD2 = 998244353;
const ll dosz = 5e5;
const ll SZ = (1 << 18);
const ld PI = atan2l(0, -1);
void fast_io() {
ios_base::sync_with_stdio(0);
cin.tie(0);
// freopen("a.in", "r", stdin);
// freopen("logs.out", "w", stdout);
}
void solve() {
int n, k;
cin >> n >> k;
vi nums(n);
for (int i = 0; i < n; i++) {
cin >> nums[i];
}
int l = 1, r = 1e9;
int ans = 1e9;
while (l <= r) {
int mid = (l + r) / 2;
int cnt = 0;
for (int i : nums) {
cnt += (i + mid - 1) / mid - 1;
}
if (cnt > k) {
l = mid + 1;
} else {
ans = mid;
r = mid - 1;
}
}
cout << ans << endl;
}
signed main() {
fast_io();
// srand(time(NULL));
// cout << fixed << setprecision(12);
int q = 1;
// cin >> q;
while (q--)
solve();
} | replace | 155 | 156 | 155 | 156 | 0 | |
p02598 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, k, a[200500];
bool check(ll x) {
ll cnt = 0;
for (int i = 0; i < n; i++) {
cnt += a[i] / x - (a[i] % x == 0);
}
return cnt <= k;
}
void solve() {
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
ll l = -1, r = 1e9;
while (r - l > 1) {
ll mid = l + (r - l) / 2;
if (check(mid))
r = mid;
else
l = mid;
}
cout << r;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t = 1;
// cin >> t;
for (int i = 1; i <= t; i++) {
solve();
}
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, k, a[200500];
bool check(ll x) {
ll cnt = 0;
for (int i = 0; i < n; i++) {
cnt += a[i] / x - (a[i] % x == 0);
}
return cnt <= k;
}
void solve() {
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
ll l = 0, r = 1e9;
while (r - l > 1) {
ll mid = l + (r - l) / 2;
if (check(mid))
r = mid;
else
l = mid;
}
cout << r;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t = 1;
// cin >> t;
for (int i = 1; i <= t; i++) {
solve();
}
} | replace | 18 | 19 | 18 | 19 | 0 | |
p02598 | C++ | Runtime Error | #include <algorithm>
#include <functional>
#include <iostream>
#include <string>
using namespace std;
#include <climits>
#include <iomanip>
#include <math.h>
#include <queue>
#include <vector>
using Graph = vector<vector<int>>;
const double PI = 3.14159265358979323846;
int needed_kaisu(long long a, long long N, long long *A) {
int count = 0;
for (long long i = 0; i < N; i++) {
count += (A[i] + a - 1) / a - 1;
}
return count;
}
int main() {
long long N, K, A[200100], ans, mem[200100];
priority_queue<pair<long long, long long>> queue;
long long max = 0;
cin >> N >> K;
for (long long i = 0; i < N; i++) {
cin >> A[i];
if (max < A[i]) {
max = A[i];
}
}
long long lb = 0;
long long ub = max;
if (K == 0) {
cout << max << endl;
return 0;
}
while (1) {
long long tmp = (lb + ub) / 2;
if (needed_kaisu(tmp, N, A) <= K) {
ub = tmp;
}
if (needed_kaisu(tmp, N, A) >= K + 1) {
lb = tmp;
}
if (ub <= lb + 1) {
break;
}
}
cout << ub << endl;
cin >> N;
return 0;
}
| #include <algorithm>
#include <functional>
#include <iostream>
#include <string>
using namespace std;
#include <climits>
#include <iomanip>
#include <math.h>
#include <queue>
#include <vector>
using Graph = vector<vector<int>>;
const double PI = 3.14159265358979323846;
int needed_kaisu(long long a, long long N, long long *A) {
int count = 0;
for (long long i = 0; i < N; i++) {
count += (A[i] + a - 1) / a - 1;
}
return count;
}
int main() {
long long N, K, A[200100], ans, mem[200100];
priority_queue<pair<long long, long long>> queue;
long long max = 0;
cin >> N >> K;
for (long long i = 0; i < N; i++) {
cin >> A[i];
if (max < A[i]) {
max = A[i];
}
}
long long lb = 0;
long long ub = max;
if (K == 0) {
cout << max << endl;
return 0;
}
while (1) {
long long tmp = (lb + ub + 1) / 2;
if (needed_kaisu(tmp, N, A) <= K) {
ub = tmp;
}
if (needed_kaisu(tmp, N, A) >= K + 1) {
lb = tmp;
}
if (ub <= lb + 1) {
break;
}
}
cout << ub << endl;
cin >> N;
return 0;
}
| replace | 46 | 47 | 46 | 47 | 0 | |
p02598 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
vector<ll> a(200000);
int main(void) {
ll n, k;
cin >> n >> k;
rep(i, n) cin >> a[i];
ll l = 0, h = *max_element(a.begin(), a.begin() + n);
while (l < h) {
ll mid = (l + h) / 2, cnt = 0;
rep(i, n) {
cnt += a[i] / mid;
if (a[i] % mid == 0)
--cnt;
}
if (cnt <= k)
h = mid;
else
l = mid + 1;
}
cout << h << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
vector<ll> a(200000);
int main(void) {
ll n, k;
cin >> n >> k;
rep(i, n) cin >> a[i];
ll l = 1, h = *max_element(a.begin(), a.begin() + n);
while (l < h) {
ll mid = (l + h) / 2, cnt = 0;
rep(i, n) {
cnt += a[i] / mid;
if (a[i] % mid == 0)
--cnt;
}
if (cnt <= k)
h = mid;
else
l = mid + 1;
}
cout << h << endl;
return 0;
} | replace | 11 | 12 | 11 | 12 | 0 | |
p02598 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> P;
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
int main() {
ll n, k;
cin >> n >> k;
vector<ll> a(n);
rep(i, n) cin >> a[i];
ll l = 0, r = 1e9, m;
while (l < r) {
m = (l + r) / 2;
ll cnt = 0;
for (int i = 0; i < n; i++)
cnt += (a[i] - 1) / m;
if (k < cnt)
l = m + 1;
else
r = m - 1;
}
r = max(1ll, r - 2);
while (1) {
ll cnt = 0;
for (int i = 0; i < n; i++)
cnt += (a[i] - 1) / r;
if (cnt <= k) {
cout << r << endl;
return 0;
} else
r++;
}
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> P;
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
int main() {
ll n, k;
cin >> n >> k;
vector<ll> a(n);
rep(i, n) cin >> a[i];
ll l = 0, r = 1e9, m;
while (r > 1 && l < r) {
m = (l + r) / 2;
ll cnt = 0;
for (int i = 0; i < n; i++)
cnt += (a[i] - 1) / m;
if (k < cnt)
l = m + 1;
else
r = m - 1;
}
r = max(1ll, r - 2);
while (1) {
ll cnt = 0;
for (int i = 0; i < n; i++)
cnt += (a[i] - 1) / r;
if (cnt <= k) {
cout << r << endl;
return 0;
} else
r++;
}
} | replace | 20 | 21 | 20 | 21 | 0 | |
p02598 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define RREP(i, m, n) for (int i = (int)(m); i >= (int)(n); i--)
#define rrep(i, n) RREP(i, (n)-1, 0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
const ld eps = 1e-10;
template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) {
if (a > b)
a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) {
if (a < b)
a = b;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
ll k;
cin >> n >> k;
vector<ll> A(n);
rep(i, n) cin >> A[i];
auto bsearch = [&]() {
auto test = [&](ll t) {
ll need = 0;
rep(i, n) need += (A[i] + t - 1) / t - 1;
return need <= k;
};
ll ok = *max_element(all(A)), ng = -1;
while (ok - ng > 1) {
ll mid = (ok + ng) / 2;
(test(mid) ? ok : ng) = mid;
}
return ok;
};
cout << bsearch() << endk;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define RREP(i, m, n) for (int i = (int)(m); i >= (int)(n); i--)
#define rrep(i, n) RREP(i, (n)-1, 0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
const ld eps = 1e-10;
template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) {
if (a > b)
a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) {
if (a < b)
a = b;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
ll k;
cin >> n >> k;
vector<ll> A(n);
rep(i, n) cin >> A[i];
auto bsearch = [&]() {
auto test = [&](ll t) {
ll need = 0;
rep(i, n) need += (A[i] + t - 1) / t - 1;
return need <= k;
};
ll ok = *max_element(all(A)), ng = 0;
while (ok - ng > 1) {
ll mid = (ok + ng) / 2;
(test(mid) ? ok : ng) = mid;
}
return ok;
};
cout << bsearch() << endk;
return 0;
}
| replace | 37 | 38 | 37 | 38 | 0 | |
p02598 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int n, k;
double mid, Left, Right, len[200005];
const double eps = 1e-8;
bool Judge(double lim) {
int cnt = 0;
for (int i = 1; i <= n; i++)
cnt += ceil(len[i] / lim) - 1;
return cnt <= k;
}
int main() {
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++)
scanf("%lf", &len[i]), Right = max(Right, len[i]);
while (abs(Left - Right) > eps) {
mid = (Left + Right) / 2.0;
if (Judge(mid))
Right = mid;
else
Left = mid;
}
printf("%.0lf\n", ceil(Right));
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int n, k;
double mid, Left, Right, len[200005];
const double eps = 1e-6;
bool Judge(double lim) {
int cnt = 0;
for (int i = 1; i <= n; i++)
cnt += ceil(len[i] / lim) - 1;
return cnt <= k;
}
int main() {
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++)
scanf("%lf", &len[i]), Right = max(Right, len[i]);
while (abs(Left - Right) > eps) {
mid = (Left + Right) / 2.0;
if (Judge(mid))
Right = mid;
else
Left = mid;
}
printf("%.0lf\n", ceil(Right));
return 0;
}
| replace | 4 | 5 | 4 | 5 | TLE | |
p02598 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int n, k, mid, Left, Right, len[200005];
bool Judge(int lim) {
int cnt = 0;
for (int i = 1; i <= n; i++) {
if (len[i] % lim == 0)
cnt += len[i] / lim - 1;
else
cnt += len[i] / lim;
}
return cnt > k;
}
int main() {
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++)
scanf("%d", &len[i]), Right = max(Right, len[i]);
while (Left <= Right) {
mid = (Left + Right) / 2;
if (Judge(mid))
Left = mid + 1;
else
Right = mid - 1;
}
printf("%d\n", Left);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int n, k, mid, Left, Right, len[200005];
bool Judge(int lim) {
int cnt = 0;
for (int i = 1; i <= n; i++) {
if (len[i] % lim == 0)
cnt += len[i] / lim - 1;
else
cnt += len[i] / lim;
}
return cnt > k;
}
int main() {
scanf("%d%d", &n, &k), Left = 1;
for (int i = 1; i <= n; i++)
scanf("%d", &len[i]), Right = max(Right, len[i]);
while (Left <= Right) {
mid = (Left + Right) / 2;
if (Judge(mid))
Left = mid + 1;
else
Right = mid - 1;
}
printf("%d\n", Left);
return 0;
}
| replace | 14 | 15 | 14 | 15 | 0 | |
p02598 | C++ | Runtime Error | /*
-------------- | /
| | /
| | /
| * |/ | | ------ *
| | | | / \
| | |\ | | | |\ |
\ | | | \ | | | | \ |
\ | | | \ | | \ / \ |
V | | \ \__/| ----- \ |
*/
#include <bits/stdc++.h>
using namespace std;
#define EmiliaMyWife \
ios::sync_with_stdio(0); \
cin.tie(NULL);
#define mem(i, j) memset(i, j, sizeof(i));
#define F first
#define S second
#define lowbit(x) ((x) & (-(x)))
#define siz(v) (int)(v).size()
typedef int64_t ll;
typedef uint64_t ull;
typedef long double ld;
const double EPS = 1e-8;
const int INF = 0x3F3F3F3F;
const ll LINF = 4611686018427387903;
const int MOD = 1e9 + 7;
/*-----------------------------------------------------------------------------------------------------*/
ll check(ll leg, vector<int> &arr) {
ll res = 0;
for (int &a : arr)
res += (a / leg + !!(a % leg)) - 1;
return res;
}
signed main() {
EmiliaMyWife
int n,
k;
cin >> n >> k;
vector<int> arr(n);
for (auto &a : arr)
cin >> a;
ll l = 0, r = 1e18;
while (l < r) {
ll m = (l + r) >> 1;
if (check(m, arr) <= k)
r = m;
else
l = m + 1;
}
cout << l << '\n';
return 0;
}
| /*
-------------- | /
| | /
| | /
| * |/ | | ------ *
| | | | / \
| | |\ | | | |\ |
\ | | | \ | | | | \ |
\ | | | \ | | \ / \ |
V | | \ \__/| ----- \ |
*/
#include <bits/stdc++.h>
using namespace std;
#define EmiliaMyWife \
ios::sync_with_stdio(0); \
cin.tie(NULL);
#define mem(i, j) memset(i, j, sizeof(i));
#define F first
#define S second
#define lowbit(x) ((x) & (-(x)))
#define siz(v) (int)(v).size()
typedef int64_t ll;
typedef uint64_t ull;
typedef long double ld;
const double EPS = 1e-8;
const int INF = 0x3F3F3F3F;
const ll LINF = 4611686018427387903;
const int MOD = 1e9 + 7;
/*-----------------------------------------------------------------------------------------------------*/
ll check(ll leg, vector<int> &arr) {
ll res = 0;
for (int &a : arr)
res += (a / leg + !!(a % leg)) - 1;
return res;
}
signed main() {
EmiliaMyWife
int n,
k;
cin >> n >> k;
vector<int> arr(n);
for (auto &a : arr)
cin >> a;
ll l = 1, r = 1e18;
while (l < r) {
ll m = (l + r) >> 1;
if (check(m, arr) <= k)
r = m;
else
l = m + 1;
}
cout << l << '\n';
return 0;
}
| replace | 47 | 48 | 47 | 48 | 0 | |
p02598 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
using namespace std;
long long int lis[200003];
int main() {
long long int N, K;
cin >> N >> K;
for (int i = 0; i < N; i++)
cin >> lis[i];
long long int l = 0, r = 2100000000, mid;
for (int i = 0; i < 100; i++) {
mid = (l + r) / 2;
long long int cou = 0;
for (int i = 0; i < N; i++) {
cou += (lis[i] - 1) / mid;
}
if (cou <= K)
r = mid;
else
l = mid;
if (mid == 0) {
cout << 1 << endl;
return 0;
}
}
cout << r << endl;
return 0;
}
| #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
using namespace std;
long long int lis[200003];
int main() {
long long int N, K;
cin >> N >> K;
for (int i = 0; i < N; i++)
cin >> lis[i];
long long int l = 0, r = 2100000000, mid;
for (int i = 0; i < 100; i++) {
mid = (l + r) / 2;
if (mid == 0) {
cout << 1 << endl;
return 0;
}
long long int cou = 0;
for (int i = 0; i < N; i++) {
cou += (lis[i] - 1) / mid;
}
if (cou <= K)
r = mid;
else
l = mid;
if (mid == 0) {
cout << 1 << endl;
return 0;
}
}
cout << r << endl;
return 0;
}
| insert | 15 | 15 | 15 | 19 | 0 | |
p02598 | C++ | Runtime Error | #pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
#define I_AM_SPEED \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define printclock \
cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << " sec\n";
#define mp(a, b) make_pair(a, b)
#define eb(a) emplace_back(a)
#define SZ(n) ((int)(n).size())
#define all(n) (n).begin(), (n).end()
#define anal '\n'
#define mod 1000000007
#define fst first
#define sec second
#define pr(n) cerr << n << " ";
#define pfor(a) \
for (auto(w) : (a)) \
pr(w)
// const double PI = acos(-1.0);
typedef long long ll;
typedef unsigned long long ull;
//_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
//_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
int main() {
I_AM_SPEED;
#ifndef ONLINE_JUDGE
freopen("input.in", "r", stdin);
freopen("output.in", "w", stdout);
#endif
//_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
ll n, k;
cin >> n >> k;
vector<ll> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
ll l = 0, r = *max_element(all(a));
while (l < r) {
ll mid = l + (r - l) / 2;
bool chk = true;
ll cut = 0;
for (int i = 0; i < n; i++) {
cut += (a[i] - 1) / mid;
if (cut > k) {
chk = false;
break;
}
}
if (chk)
r = mid;
else
l = mid + 1;
}
cout << l << anal;
//_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
// printclock;
return 0;
}
| #pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
#define I_AM_SPEED \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define printclock \
cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << " sec\n";
#define mp(a, b) make_pair(a, b)
#define eb(a) emplace_back(a)
#define SZ(n) ((int)(n).size())
#define all(n) (n).begin(), (n).end()
#define anal '\n'
#define mod 1000000007
#define fst first
#define sec second
#define pr(n) cerr << n << " ";
#define pfor(a) \
for (auto(w) : (a)) \
pr(w)
// const double PI = acos(-1.0);
typedef long long ll;
typedef unsigned long long ull;
//_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
//_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
int main() {
I_AM_SPEED;
#ifndef ONLINE_JUDGE
freopen("input.in", "r", stdin);
freopen("output.in", "w", stdout);
#endif
//_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
ll n, k;
cin >> n >> k;
vector<ll> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
ll l = 1, r = *max_element(all(a));
while (l < r) {
ll mid = l + (r - l) / 2;
bool chk = true;
ll cut = 0;
for (int i = 0; i < n; i++) {
cut += (a[i] - 1) / mid;
if (cut > k) {
chk = false;
break;
}
}
if (chk)
r = mid;
else
l = mid + 1;
}
cout << l << anal;
//_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
// printclock;
return 0;
}
| replace | 42 | 43 | 42 | 43 | -6 | terminate called after throwing an instance of 'std::length_error'
what(): cannot create std::vector larger than max_size()
|
p02598 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int cut(int k, int *a, int n, int u) {
int res = 0;
for (int i = 0; i < n; ++i) {
res += (a[i] + k - 1) / k - 1;
}
// cout<<k<<" "<<res<<endl;
return (res <= u) ? 1 : 0;
}
signed main() {
int n, k, a[200200] = {0};
cin >> n >> k;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
int l = -1, r = 1000000001, m;
while (l < r - 1) {
m = l + (r - l) / 2;
if (cut(m, a, n, k)) {
r = m;
} else {
l = m;
}
}
cout << r << endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int cut(int k, int *a, int n, int u) {
int res = 0;
if (!k)
return 0;
for (int i = 0; i < n; ++i) {
res += (a[i] + k - 1) / k - 1;
}
// cout<<k<<" "<<res<<endl;
return (res <= u) ? 1 : 0;
}
signed main() {
int n, k, a[200200] = {0};
cin >> n >> k;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
int l = -1, r = 1000000001, m;
while (l < r - 1) {
m = l + (r - l) / 2;
if (cut(m, a, n, k)) {
r = m;
} else {
l = m;
}
}
cout << r << endl;
return 0;
} | insert | 8 | 8 | 8 | 10 | 0 | |
p02598 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, s, n) for (int i = s; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
ll n, k;
bool isOK(vector<ll> &a, ll mid) {
ll l = 0;
rep(i, 0, n) {
if (a[i] % mid == 0) {
l += a[i] / mid - 1;
} else {
l += a[i] / mid;
}
}
if (l <= k)
return true;
else
return false;
}
ll binary_search(vector<ll> &a, ll m) {
ll left = -1;
ll right = m + 1;
while (right - left > 1) {
ll mid = (right + left) / 2;
if (isOK(a, mid))
right = mid;
else
left = mid;
}
return right;
}
int main() {
cin >> n >> k;
vector<ll> a(n);
ll m = 0;
rep(i, 0, n) {
cin >> a[i];
m = max(m, a[i]);
}
sort(a.begin(), a.end());
int ans = binary_search(a, m);
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, s, n) for (int i = s; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
ll n, k;
bool isOK(vector<ll> &a, ll mid) {
ll l = 0;
rep(i, 0, n) {
if (a[i] % mid == 0) {
l += a[i] / mid - 1;
} else {
l += a[i] / mid;
}
}
if (l <= k)
return true;
else
return false;
}
ll binary_search(vector<ll> &a, ll m) {
ll left = 0;
ll right = m;
while (right - left > 1) {
ll mid = (right + left) / 2;
if (isOK(a, mid))
right = mid;
else
left = mid;
}
return right;
}
int main() {
cin >> n >> k;
vector<ll> a(n);
ll m = 0;
rep(i, 0, n) {
cin >> a[i];
m = max(m, a[i]);
}
sort(a.begin(), a.end());
int ans = binary_search(a, m);
cout << ans << endl;
return 0;
}
| replace | 24 | 26 | 24 | 26 | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.