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
p02881
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { long long buf, n, ans; cin >> n; buf = 1; std::vector<long long> vec; while (buf <= n / 2) { if (n % buf == 0) { vec.push_back(n / buf + buf - 2); // cout << n/buf; // cout << " "; // cout << buf; // cout << " "; } buf++; } std::sort(vec.begin(), vec.end()); cout << *vec.begin(); }
#include <bits/stdc++.h> using namespace std; int main() { long long buf, n, ans; cin >> n; buf = 1; std::vector<long long> vec; while (buf <= sqrt(n)) { if (n % buf == 0) { vec.push_back(n / buf + buf - 2); // cout << n/buf; // cout << " "; // cout << buf; // cout << " "; } buf++; } std::sort(vec.begin(), vec.end()); cout << *vec.begin(); }
replace
8
9
8
9
TLE
p02881
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define max 1e12 using namespace std; int main() { long long int n; cin >> n; long long int count = 0; long long int min = max; long long int j = 0; for (long long int i = 1; i <= n / 2; i++) { if (n % i == 0) { j = n / i; count = i + j - 2; if (min > count) min = count; } } cout << min << endl; return 0; }
#include <bits/stdc++.h> #define max 1e12 using namespace std; int main() { long long int n; cin >> n; long long count = 0; long long min = max; long long j = 0; for (long long i = 1; i * i <= n; i++) { if (n % i == 0) { j = n / i; count = i + j - 2; if (min > count) min = count; } } cout << min << endl; return 0; }
replace
7
11
7
11
TLE
p02881
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ul; int main(void) { ul n; cin >> n; ul ans = n - 1; for (ul i = 0; i * i <= n; ++i) { if (n % i != 0) continue; ans = min(ans, i + n / i - 2); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ul; int main(void) { ul n; cin >> n; ul ans = n - 1; for (ul i = 1; i * i <= n; ++i) { if (n % i != 0) continue; ans = min(ans, i + n / i - 2); } cout << ans << endl; return 0; }
replace
8
9
8
9
-8
p02881
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define ll long long int int main() { ll n; cin >> n; string flag = "No"; int Max = pow(10, 6); ll res = pow(10, 13); for (int i = 1; i * i <= n; i++) { if (n % i == 0) { ll ans = n / i + i - 2; res = min(res, ans); } } cout << res << endl; // cout<<flag<<endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long int int main() { ll n; cin >> n; string flag = "No"; int Max = pow(10, 6); ll res = pow(10, 13); for (int i = 1; i <= Max; i++) { if (n % i == 0) { ll ans = n / i + i - 2; res = min(res, ans); } } cout << res << endl; // cout<<flag<<endl; }
replace
9
10
9
10
TLE
p02881
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = int64_t; using pint = pair<int, int>; int main() { ll n; cin >> n; int s = sqrt(n); while (s--) { if (n % s == 0) { cout << s + (n / s) - 2 << endl; return 0; } } }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = int64_t; using pint = pair<int, int>; int main() { ll n; cin >> n; int s = sqrt(n) + 1; while (s--) { if (n % s == 0) { cout << s + (n / s) - 2 << endl; return 0; } } }
replace
10
11
10
11
0
p02881
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll N; cin >> N; stack<ll> S; for (int i = 1; i * i <= N; i++) { if (N % i == 0) { S.push(i); } } ll b = N / S.top(); cout << S.top() + b - 2 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll N; cin >> N; stack<ll> S; for (ll i = 1; i * i <= N; i++) { if (N % i == 0) { S.push(i); } } ll b = N / S.top(); cout << S.top() + b - 2 << endl; return 0; }
replace
7
8
7
8
TLE
p02881
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> ii; typedef pair<int, ii> pii; typedef vector<ii> vii; typedef vector<ii> vpii; typedef vector<int> vi; typedef vector<vi> vvi; typedef long long int ll; typedef unsigned long long int ull; #define pb push_back #define Add1(a, b) ady[a].pb(b) #define Add1c(a, b, c) ady[a].pb({b, c}) #define AddS1(a, b) ady[a].insert(b) #define AddS1c(a, b, c) ady[a].insert({b, c}) #define Add2(a, b) ady[a].pb(b), ady[b].pb(a) #define Add2c(a, b, c) ady[a].pb({b, c}), ady[b].pb({a, c}) #define AddS2(a, b) ady[a].insert(b), ady[b].insert(a) #define AddS2c(a, b, c) ady[a].insert({b, c}), ady[b].insert({a, c}) #define f first #define s second #define SZ(a) (int)(a.size()) #define ALL(a) a.begin(), a.end() #define SET(a, b) memset(a, b, sizeof(a)) #define si(n) scanf("%d", &n) #define dout(n) printf("%d\n", n) #define sll(n) scanf("%lld", &n) #define lldout(n) printf("%lld\n", n) #define DRT() \ int t; \ si(t); \ while (t--) #define rep(i, begin, end) \ for (__typeof(end) i = (begin) - ((begin) > (end)); \ i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) #define TRACE #ifdef TRACE #define trace cerr << "Hola mundo" << endl; #define trace1(x) cerr << #x << ": " << x << endl; #define trace2(x, y) \ cerr << #x << ": " << x << " | " << #y << ": " << y << endl; #define trace3(x, y, z) \ cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl; #define trace4(a, b, c, d) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl; #define trace5(a, b, c, d, e) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl; #define trace6(a, b, c, d, e, f) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << endl; #else #define trace #define trace1(x) #define trace2(x, y) #define trace3(x, y, z) #define trace4(a, b, c, d) #define trace5(a, b, c, d, e) #define trace6(a, b, c, d, e, f) #endif const int maxn = 1e5 + 1; const int maxe = 20; const int oo = 1 << 30; int main() { long long n; cin >> n; long long sol = INFINITY; for (long long i = n / 2; i >= 1; i--) { if (i * (n / i) == n) sol = min(sol, (i - 1) + (n / i) - 1); } cout << sol; }
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> ii; typedef pair<int, ii> pii; typedef vector<ii> vii; typedef vector<ii> vpii; typedef vector<int> vi; typedef vector<vi> vvi; typedef long long int ll; typedef unsigned long long int ull; #define pb push_back #define Add1(a, b) ady[a].pb(b) #define Add1c(a, b, c) ady[a].pb({b, c}) #define AddS1(a, b) ady[a].insert(b) #define AddS1c(a, b, c) ady[a].insert({b, c}) #define Add2(a, b) ady[a].pb(b), ady[b].pb(a) #define Add2c(a, b, c) ady[a].pb({b, c}), ady[b].pb({a, c}) #define AddS2(a, b) ady[a].insert(b), ady[b].insert(a) #define AddS2c(a, b, c) ady[a].insert({b, c}), ady[b].insert({a, c}) #define f first #define s second #define SZ(a) (int)(a.size()) #define ALL(a) a.begin(), a.end() #define SET(a, b) memset(a, b, sizeof(a)) #define si(n) scanf("%d", &n) #define dout(n) printf("%d\n", n) #define sll(n) scanf("%lld", &n) #define lldout(n) printf("%lld\n", n) #define DRT() \ int t; \ si(t); \ while (t--) #define rep(i, begin, end) \ for (__typeof(end) i = (begin) - ((begin) > (end)); \ i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) #define TRACE #ifdef TRACE #define trace cerr << "Hola mundo" << endl; #define trace1(x) cerr << #x << ": " << x << endl; #define trace2(x, y) \ cerr << #x << ": " << x << " | " << #y << ": " << y << endl; #define trace3(x, y, z) \ cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl; #define trace4(a, b, c, d) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl; #define trace5(a, b, c, d, e) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl; #define trace6(a, b, c, d, e, f) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << endl; #else #define trace #define trace1(x) #define trace2(x, y) #define trace3(x, y, z) #define trace4(a, b, c, d) #define trace5(a, b, c, d, e) #define trace6(a, b, c, d, e, f) #endif const int maxn = 1e5 + 1; const int maxe = 20; const int oo = 1 << 30; int main() { long long n; cin >> n; long long sol = n - 1; for (long long i = 2; i <= (int)sqrt(n); i++) { if (i * (n / i) == n) sol = min(sol, (i - 1) + (n / i) - 1); } cout << sol; }
replace
85
87
85
87
TLE
p02881
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define pb push_back #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define rep(i, n) FOR(i, 0, n) #define ll long long using namespace std; const ll P = 1000000007; int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; } int lcm(int a, int b) { return a / gcd(a, b) * b; } int main() { cout << fixed << setprecision(10); ll N; cin >> N; ll M = pow(N, 0.5); ll ans = 100000000000000; for (ll i = M; i < N; i++) { if (N % i == 0) { cout << i + (N / i) - 2 << endl; return 0; } } return 0; }
#include <bits/stdc++.h> #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define pb push_back #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define rep(i, n) FOR(i, 0, n) #define ll long long using namespace std; const ll P = 1000000007; int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; } int lcm(int a, int b) { return a / gcd(a, b) * b; } int main() { cout << fixed << setprecision(10); ll N; cin >> N; ll M = pow(N, 0.5); ll ans = 100000000000000; for (ll i = M; i > 0; i--) { if (N % i == 0) { cout << i + (N / i) - 2 << endl; return 0; } } return 0; }
replace
19
20
19
20
TLE
p02881
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define rep(i, n) for (ll i = 0; i < n; i++) #define FOR(i, a, b) for (ll i = a; i < b; i++) #define len(v) ll(v.size()) template <class T> void cout_vec(const vector<T> &vec1) { rep(i, len(vec1)) { cout << vec1[i] << ' '; } cout << '\n'; } typedef pair<ll, ll> P; const ll mod = 1e9 + 7; const ll min_max = 1e12; ll gcd(ll a, ll b) { ll r; while ((r = a % b)) { a = b; b = r; } return b; } bool IsPrime(int num) { if (num < 2) return false; else 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; } // 単純な素数か素数じゃないかの問題ではない。 int main() { ll A; cin >> A; ll first = 1; ll second = 1; ll min = min_max + 1; if (A <= 1e6) { for (int i = 1; i <= A; i++) { if (A % i == 0) { if (i + A / i <= min) { first = i; second = A / i; min = first + second; } } } } else { for (int i = 1; i < A / 1000; i++) { if (A % i == 0) { if (i + A / i <= min) { first = i; second = A / i; min = first + second; } } } } ll ans = 0; if (first == 1 || second == 1) { cout << A - 1 << endl; } else { cout << min - 2 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define rep(i, n) for (ll i = 0; i < n; i++) #define FOR(i, a, b) for (ll i = a; i < b; i++) #define len(v) ll(v.size()) template <class T> void cout_vec(const vector<T> &vec1) { rep(i, len(vec1)) { cout << vec1[i] << ' '; } cout << '\n'; } typedef pair<ll, ll> P; const ll mod = 1e9 + 7; const ll min_max = 1e12; ll gcd(ll a, ll b) { ll r; while ((r = a % b)) { a = b; b = r; } return b; } bool IsPrime(int num) { if (num < 2) return false; else 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; } // 単純な素数か素数じゃないかの問題ではない。 int main() { ll A; cin >> A; ll first = 1; ll second = 1; ll min = min_max + 1; if (A <= 1e6) { for (int i = 1; i <= A; i++) { if (A % i == 0) { if (i + A / i <= min) { first = i; second = A / i; min = first + second; } } } } else { for (int i = 1; i < A / 100000; i++) { if (A % i == 0) { if (i + A / i <= min) { first = i; second = A / i; min = first + second; } } } } ll ans = 0; if (first == 1 || second == 1) { cout << A - 1 << endl; } else { cout << min - 2 << endl; } return 0; }
replace
68
69
68
69
TLE
p02881
C++
Runtime Error
#include <bits/stdc++.h> #include <stdlib.h> using namespace std; typedef long long ll; typedef pair<int, int> P; typedef pair<ll, ll> llP; int main() { ll n; cin >> n; map<int, int> memo; for (int i = 0; i <= sqrt(n); i++) { if (n % i == 0) memo[i]++; } ll ans = 1e13; for (auto itr = memo.begin(); itr != memo.end(); itr++) { ans = min(ans, (itr->first) + n / (itr->first) - 2); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #include <stdlib.h> using namespace std; typedef long long ll; typedef pair<int, int> P; typedef pair<ll, ll> llP; int main() { ll n; cin >> n; map<int, int> memo; for (int i = 1; i <= sqrt(n); i++) { if (n % i == 0) memo[i]++; } ll ans = 1e13; for (auto itr = memo.begin(); itr != memo.end(); itr++) { ans = min(ans, (itr->first) + n / (itr->first) - 2); } cout << ans << endl; return 0; }
replace
11
12
11
12
-8
p02881
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> using namespace std; int main() { long n; long i, mod, div, tmp; long ans; cin >> n; ans = n - 1; for (i = 1; i < n; i++) { mod = n % i; if (mod == 0) { div = n / i; tmp = (div - 1) + (i - 1); ans = min(ans, tmp); } } cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> using namespace std; int main() { long n; long i, mod, div, tmp; long ans; cin >> n; ans = n - 1; for (i = 1; i * i <= n; i++) { mod = n % i; if (mod == 0) { div = n / i; tmp = (div - 1) + (i - 1); ans = min(ans, tmp); } } cout << ans << endl; return 0; }
replace
11
12
11
12
TLE
p02881
C++
Time Limit Exceeded
#include <algorithm> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stdio.h> #include <string.h> #include <string> #include <vector> using namespace std; #define int64 long long #define pii pair<int64, int64> #define fr first #define sc second #define heap priority_queue struct piii { int64 fr, sc, th; bool operator<(const piii &b) { if (fr != b.fr) return fr < b.fr; if (sc != b.sc) return sc < b.sc; return th < b.th; } }; /////////////////////////////////////////////// /////////////////////////////////////////////// int main() { cout << setprecision(2) << fixed; ios::sync_with_stdio(false), cin.tie(0); // freopen("input.txt", "r", stdin); int64 n; cin >> n; int64 res = n + 3; for (int i = 1; i * i <= n; i++) if (n % i == 0) { res = min(res, i + n / i); } cout << res - 2; return 0; }
#include <algorithm> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stdio.h> #include <string.h> #include <string> #include <vector> using namespace std; #define int64 long long #define pii pair<int64, int64> #define fr first #define sc second #define heap priority_queue struct piii { int64 fr, sc, th; bool operator<(const piii &b) { if (fr != b.fr) return fr < b.fr; if (sc != b.sc) return sc < b.sc; return th < b.th; } }; /////////////////////////////////////////////// /////////////////////////////////////////////// int main() { cout << setprecision(2) << fixed; ios::sync_with_stdio(false), cin.tie(0); // freopen("input.txt", "r", stdin); int64 n; cin >> n; int64 res = n + 3; for (int64 i = 1; i * i <= n; i++) if (n % i == 0) { res = min(res, i + n / i); } cout << res - 2; return 0; }
replace
39
40
39
40
TLE
p02881
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; long long prime(long long a) { long long y, i; y = sqrt(a); for (i = 2; i <= y; i++) { if (a % i == 0) { return -1; } } if (i > y) return 1; } int main() { long long a, c, d; cin >> a; c = prime(a); if (c == 1) { cout << a - 1; } else { d = sqrt(a); while (a % d != 0) { d++; } cout << (d - 1) + (a / d - 1); } return 0; }
#include <bits/stdc++.h> using namespace std; long long prime(long long a) { long long y, i; y = sqrt(a); for (i = 2; i <= y; i++) { if (a % i == 0) { return -1; } } if (i > y) return 1; } int main() { long long a, c, d; cin >> a; c = prime(a); if (c == 1) { cout << a - 1; } else { d = sqrt(a); while (a % d != 0) { d--; } cout << (d - 1) + (a / d - 1); } return 0; }
replace
22
23
22
23
TLE
p02881
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main() { ll n, minv = 1000000000001; cin >> n; for (ll i = 1; i <= n; i++) { if (n % i == 0) { minv = min(i + (n / i) - 2, minv); } } cout << minv << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main() { ll n, minv = 1000000000001; cin >> n; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { minv = min(i + (n / i) - 2, minv); } } cout << minv << endl; return 0; }
replace
8
9
8
9
TLE
p02881
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main() { ll n; cin >> n; ll j = 1; for (ll i = sqrt(n); i > 1; i++) { if (n % i == 0) { j = i; break; } } ll i = n / j; cout << i - 1 + j - 1 << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main() { ll n; cin >> n; ll j = 1; for (ll i = sqrt(n); i > 1; i--) { if (n % i == 0) { j = i; break; } } ll i = n / j; cout << i - 1 + j - 1 << endl; }
replace
10
11
10
11
TLE
p02881
C++
Runtime Error
#include <bits //stdc++.h> #define rep(i, k) for (int i = 0; i < k; i++) #define int unsigned long long using namespace std; signed main(void) { int n, m, a, b, c, ans; cin >> n; for (int i = 1; i < n; i++) { if (i * i > n) { ans = i; break; } } for (int i = ans; i > 0; i--) { if (n % i == 0) { b = i; break; } } cout << n / b + b - 2 << endl; }
#include <bits //stdc++.h> #define rep(i, k) for (int i = 0; i < k; i++) #define int unsigned long long using namespace std; signed main(void) { int n, m, a, b, c, ans; cin >> n; for (int i = 1; i < n; i++) { if (i * i > n) { ans = i; break; } } b = 1; for (int i = ans; i > 0; i--) { if (n % i == 0) { b = i; break; } } cout << n / b + b - 2 << endl; }
replace
14
15
14
15
0
p02881
C++
Runtime Error
#include <algorithm> #include <iostream> #include <math.h> #include <sstream> #include <string> #include <tuple> #include <vector> #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef long long ll; using namespace std; int main() { ll n; cin >> n; ll ans = 0; for (ll i = 0; i < sqrt(n); i++) { if (n % i == 0) { ans = min(i + n / i - 2, ans); } } cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> #include <math.h> #include <sstream> #include <string> #include <tuple> #include <vector> #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef long long ll; using namespace std; int main() { ll n; cin >> n; ll ans = 1e18; for (ll i = 1; i * i <= n; i++) { if (n % i != 0) continue; ll j = n / i; ans = min(i + j - 2, ans); } cout << ans << endl; return 0; }
replace
13
18
13
19
-8
p02881
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long min = 10000000000000; for (long long i = 1; i <= n / 2; i++) { long long t; if ((n % i) == 0) { t = (i - 1) + ((n / i) - 1); if (min > t) { min = t; } } } cout << min << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long min = n - 1; long long t; for (long long i = 1; i <= sqrt(n); i++) { if ((n % i) == 0) { t = (i - 1) + ((n / i) - 1); if (min > t) { min = t; } } } cout << min << endl; }
replace
6
9
6
9
TLE
p02881
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; unsigned long long int min; long long int ans1, ans2; for (long long int i = 1; i <= n; i++) { if (n % i == 0) { long long int j = n / i; unsigned long long int min1 = sqrt(pow(i - 1, 2) + pow(j - 1, 2)); if (min1 < min or i == 1) { min = min1; ans1 = i; ans2 = j; } } } cout << (ans1 - 1) + (ans2 - 1); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; unsigned long long int min; long long int ans1, ans2; for (long long int i = 1; i <= sqrt(n); i++) { if (n % i == 0) { long long int j = n / i; unsigned long long int min1 = sqrt(pow(i - 1, 2) + pow(j - 1, 2)); if (min1 < min or i == 1) { min = min1; ans1 = i; ans2 = j; } } } cout << (ans1 - 1) + (ans2 - 1); return 0; }
replace
7
8
7
8
TLE
p02881
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define ll long long #define mod 1e9 + 7 #define endl '\n' void solve() { ll n; cin >> n; ll ans = 1e12; for (int i = 1; i * i <= n; i++) { if (n % i == 0) { ans = min(ans, i + n / i - 2); } } cout << ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; while (t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define mod 1e9 + 7 #define endl '\n' void solve() { ll n; cin >> n; ll ans = 1e12; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { ans = min(ans, i + n / i - 2); } } cout << ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; while (t--) solve(); return 0; }
replace
13
14
13
14
TLE
p02881
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef double db; const double pi = 3.141592654; #define pb push_back #define forab(i, a, b) for (int i = (a); i <= (b); i++) #define CIN \ ios_base::sync_with_stdio(0); \ cin.tie(0) #define pcase(z, x) printf("Case %ld: %lld\n", z, x) #define nw "\n" #define mod 1000000007 int main(void) { CIN; ll tc, l, k = 0, sum = 0, x = 0, y, z = 0, m = 1, n = 0, ans = 0, cnt = 0; cin >> n; ll mx = 1e16; for (ll i = 1; i <= n; i++) { if (n % i == 0) { z = (i * i + n - 2 * i) / i; mx = min(mx, z); } } cout << mx; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef double db; const double pi = 3.141592654; #define pb push_back #define forab(i, a, b) for (int i = (a); i <= (b); i++) #define CIN \ ios_base::sync_with_stdio(0); \ cin.tie(0) #define pcase(z, x) printf("Case %ld: %lld\n", z, x) #define nw "\n" #define mod 1000000007 int main(void) { CIN; ll tc, l, k = 0, sum = 0, x = 0, y, z = 0, m = 1, n = 0, ans = 0, cnt = 0; cin >> n; ll mx = 1e16; for (ll i = 1; i <= sqrt(n); i++) { if (n % i == 0) { z = (i * i + n - 2 * i) / i; mx = min(mx, z); } } cout << mx; }
replace
19
20
19
20
TLE
p02881
C++
Time Limit Exceeded
#include <algorithm> #include <cctype> #include <cstdlib> #include <fstream> #include <iostream> #include <istream> #include <math.h> #include <sstream> #include <string> #include <vector> using namespace std; int main() { long long N; vector<long long> NN; cin >> N; for (long long i = 1; i < N; i++) { if (N % i == 0) { NN.push_back(i + (N / i) - 2); } } sort(NN.begin(), NN.end()); cout << NN[0] << endl; }
#include <algorithm> #include <cctype> #include <cstdlib> #include <fstream> #include <iostream> #include <istream> #include <math.h> #include <sstream> #include <string> #include <vector> using namespace std; int main() { long long N; vector<long long> NN; cin >> N; for (long long i = 1; i <= sqrt(N); i++) { if (N % i == 0) { NN.push_back(i + (N / i) - 2); } } sort(NN.begin(), NN.end()); cout << NN[0] << endl; }
replace
16
17
16
17
TLE
p02881
C++
Time Limit Exceeded
#define _USE_MAT_DEFINES #include <algorithm> #include <cmath> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <utility> #include <vector> using namespace std; static const int MOD = 1e9 + 7; int main() { long long N; cin >> N; long long ans = N - 1; for (int i = 2; i * i <= N; i++) { if (N % i == 0) ans = min(ans, N / i + i - 2); } cout << ans; }
#define _USE_MAT_DEFINES #include <algorithm> #include <cmath> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <utility> #include <vector> using namespace std; static const int MOD = 1e9 + 7; int main() { long long N; cin >> N; long long ans = N - 1; for (long long i = 2; i * i <= N; i++) { if (N % i == 0) ans = min(ans, N / i + i - 2); } cout << ans; }
replace
26
27
26
27
TLE
p02881
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; // 10^19 < 9223372036854775807 typedef unsigned long long ull; // 10^20 < 18446744073709551615 #define REP(i, n) for (ll i = 0; i < ll(n); i++) #define REPD(i, n) for (ll i = n - 1; i >= 0; i--) #define FOR(i, a, b) for (ll i = a; i <= ll(b); i++) #define FORD(i, a, b) for (ll i = a; i >= ll(b); i--) #define FORA(i, I) for (const auto &i : I) #define ALL(x) x.begin(), x.end() #define SIZE(x) ll(x.size()) #define MOD 1000000007 int main(void) { ll N; cin >> N; ll ans = 1000000000010; for (ll i = 1; i <= N / 2; i++) { if (N % i == 0) { ans = min((N / i - 1) + i - 1, ans); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; // 10^19 < 9223372036854775807 typedef unsigned long long ull; // 10^20 < 18446744073709551615 #define REP(i, n) for (ll i = 0; i < ll(n); i++) #define REPD(i, n) for (ll i = n - 1; i >= 0; i--) #define FOR(i, a, b) for (ll i = a; i <= ll(b); i++) #define FORD(i, a, b) for (ll i = a; i >= ll(b); i--) #define FORA(i, I) for (const auto &i : I) #define ALL(x) x.begin(), x.end() #define SIZE(x) ll(x.size()) #define MOD 1000000007 int main(void) { ll N; cin >> N; ll ans = 1000000000010; for (ll i = 1; i <= sqrt(N); i++) { if (N % i == 0) { ans = min((N / i - 1) + i - 1, ans); } } cout << ans << endl; return 0; }
replace
20
21
20
21
TLE
p02881
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; const long long INF = 1e18; const long long MOD = 1e9 + 7; #define all(v) v.begin(), v.end() #define repi(i, n, init) for (long long i = init; i < (n); i++) #define repd(i, n, init) for (long long i = (n); i >= init; i--) #define repm(i, m) for (auto i = m.begin(); i != m.end(); i++) int main() { ll N; cin >> N; ll ans = INF; repi(i, N, 1) { if (N % i != 0) { continue; } ll j = N / i; ans = min(ans, i + j - 2); } cout << ans << endl; return 0; } /*memo*/ // 数学的考察をしましょう // 表を使うときは対称性に気をつける。 // 2次元にとらわれすぎない // 整数の性質を使う // sqrt(N)よりかはi*i < Nのほうがよき
#include <bits/stdc++.h> using namespace std; typedef long long ll; const long long INF = 1e18; const long long MOD = 1e9 + 7; #define all(v) v.begin(), v.end() #define repi(i, n, init) for (long long i = init; i * i <= (n); i++) #define repd(i, n, init) for (long long i = (n); i >= init; i--) #define repm(i, m) for (auto i = m.begin(); i != m.end(); i++) int main() { ll N; cin >> N; ll ans = INF; repi(i, N, 1) { if (N % i != 0) { continue; } ll j = N / i; ans = min(ans, i + j - 2); } cout << ans << endl; return 0; } /*memo*/ // 数学的考察をしましょう // 表を使うときは対称性に気をつける。 // 2次元にとらわれすぎない // 整数の性質を使う // sqrt(N)よりかはi*i < Nのほうがよき
replace
6
7
6
7
TLE
p02881
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <complex> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <vector> using namespace std; #define rep(i, t, n) for (ll i = (t); i <= (n); ++i) #define per(i, n, t) for (int i = (n); i >= (t); --i) #define mmm(a, b) memset(a, b, sizeof(a)) #define pb push_back #define Decimal fixed << setprecision(20) #define debug(x) cerr << #x << ":" << x << endl #define FAST_IO \ ios::sync_with_stdio(0); \ cin.tie(0) typedef long long ll; const ll mod = 1e9 + 7; const int maxn = 2e3 + 5; typedef double db; const int N = 10; bool ok(int x) { return x >= 1 && x <= 9; } int main() { FAST_IO; ll n; cin >> n; ll ans = 1e18; for (int i = 1; i * i <= n; i++) if (n % i == 0) { ans = min(i + n / i, ans); } cout << ans - 2 << endl; } /* 2 A 0 0 2 B 1 0 2 */
#include <algorithm> #include <cmath> #include <complex> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <vector> using namespace std; #define rep(i, t, n) for (ll i = (t); i <= (n); ++i) #define per(i, n, t) for (int i = (n); i >= (t); --i) #define mmm(a, b) memset(a, b, sizeof(a)) #define pb push_back #define Decimal fixed << setprecision(20) #define debug(x) cerr << #x << ":" << x << endl #define FAST_IO \ ios::sync_with_stdio(0); \ cin.tie(0) typedef long long ll; const ll mod = 1e9 + 7; const int maxn = 2e3 + 5; typedef double db; const int N = 10; bool ok(int x) { return x >= 1 && x <= 9; } int main() { FAST_IO; ll n; cin >> n; ll ans = 1e18; for (ll i = 1; i * i <= n; i++) if (n % i == 0) { ans = min(i + n / i, ans); } cout << ans - 2 << endl; } /* 2 A 0 0 2 B 1 0 2 */
replace
36
37
36
37
TLE
p02881
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll n; cin >> n; ll ans = 0; for (ll i = 2; i * i <= n; i++) { if (n % i == 0) ans = i; } cout << n / ans + ans - 2 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll n; cin >> n; ll ans = 1; for (ll i = 2; i * i <= n; i++) { if (n % i == 0) ans = i; } cout << n / ans + ans - 2 << endl; return 0; }
replace
7
8
7
8
0
p02881
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; int main() { long n, ans = LONG_MAX; cin >> n; for (int i = 1; i * i <= n; i++) { if (n % i == 0) ans = min(ans, n / i + i - 2); } cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; int main() { long n, ans = LONG_MAX; cin >> n; for (long i = 1; i * i <= n; i++) { if (n % i == 0) ans = min(ans, n / i + i - 2); } cout << ans << endl; }
replace
7
8
7
8
TLE
p02881
C++
Time Limit Exceeded
#define _USE_MATH_DEFINES // for C++ #include "bits/stdc++.h" #define NUM ((long long)1000000007) #define int unsigned long long using namespace std; signed main() { int n; cin >> n; auto v = vector<int>(); for (size_t i = 1; i < n / 2 + 1; i++) { if (n % i == 0) { v.push_back(i + (n / i) - 2); } } cout << *min_element(v.begin(), v.end()) << endl; }
#define _USE_MATH_DEFINES // for C++ #include "bits/stdc++.h" #define NUM ((long long)1000000007) #define int unsigned long long using namespace std; signed main() { int n; cin >> n; auto v = vector<int>(); for (size_t i = 1; i < sqrt(n) + 1; i++) { if (n % i == 0) { v.push_back(i + (n / i) - 2); } } cout << *min_element(v.begin(), v.end()) << endl; }
replace
13
14
13
14
TLE
p02881
C++
Time Limit Exceeded
#include <iomanip> #include <iostream> #include <vector> #define _USE_MATH_DEFINES #include <math.h> using namespace std; void walk_on_multiplication_table() { long long int n; cin >> n; long long int ans = n; for (long long int i = 1; i <= n; ++i) { if (n % i == 0 && ans > (i - 1) + (n / i - 1)) { ans = (i - 1) + (n / i - 1); } } cout << ans << '\n'; } void average_length() { int n; cin >> n; vector<int> x(n); vector<int> y(n); for (int i = 0; i < n; i++) cin >> x[i] >> y[i]; double sum = 0; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { if (i == j) continue; sum += sqrt(pow(x[i] - x[j], 2) + pow(y[i] - y[j], 2)); } } cout << setprecision(14) << sum / n << '\n'; } int calc_digits(long long int n) { int digits = 0; while (n >= 1) { n /= 10; ++digits; } return digits; } void buy_an_interger() { long long int a, b; long long int x; cin >> a >> b >> x; long long int left = 0, right = 1000000001; long long int mid; while (right - left > 1) { mid = left + (right - left) / 2; if (a * mid + b * calc_digits(mid) <= x) left = mid; else right = mid; } cout << left << '\n'; } void honest_or_unkind2() { // 後回し } long long int gcd(int a, int b) { if (a < b) { int tmp; tmp = a; a = b; b = tmp; } int r = a % b; while (r != 0) { a = b; b = r; r = a % b; } return b; } long long int lcm(long long int a, long long int b) { return a * b / gcd(a, b); } void snack() { long long int a, b; cin >> a >> b; cout << lcm(a, b) << "\n"; } bool is_prime(int n) { if (n <= 1) return false; if (n == 2) return true; if (n % 2 == 0) return false; for (int i = 3; i * i <= n; i += 2) { if (n % i == 0) return false; } return true; } void next_prime() { int x; cin >> x; int prime = x; while (!is_prime(prime)) ++prime; cout << prime << "\n"; } int factorial(int n) { int fact = 1; for (int i = n; i > 0; --i) fact *= i; return fact; } int calc_order(int n, vector<int> x) { int cnt = 0; for (int i = 0; i < n; ++i) { cnt += (x[i] - 1) * factorial(n - 1 - i); for (int j = i + 1; j < n; ++j) { if (x[j] > x[i]) --x[j]; } } return cnt; } void count_order() { int n; cin >> n; vector<int> p(n); vector<int> q(n); for (int i = 0; i < n; i++) cin >> p[i]; for (int i = 0; i < n; i++) cin >> q[i]; int p_cnt = 0, q_cnt = 0; p_cnt = calc_order(n, p); q_cnt = calc_order(n, q); cout << abs(p_cnt - q_cnt); } int main() { walk_on_multiplication_table(); // average_length(); // buy_an_interger(); // cout << calc_digits(1000000000) << '\n'; // honest_or_unkind2(); // snack(); // next_prime(); // count_order(); }
#include <iomanip> #include <iostream> #include <vector> #define _USE_MATH_DEFINES #include <math.h> using namespace std; void walk_on_multiplication_table() { long long int n; cin >> n; long long int ans = n; for (int i = 1; i <= sqrt(n); ++i) { if (n % i == 0 && ans > (i - 1) + (n / i - 1)) { ans = (i - 1) + (n / i - 1); } } cout << ans << '\n'; } void average_length() { int n; cin >> n; vector<int> x(n); vector<int> y(n); for (int i = 0; i < n; i++) cin >> x[i] >> y[i]; double sum = 0; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { if (i == j) continue; sum += sqrt(pow(x[i] - x[j], 2) + pow(y[i] - y[j], 2)); } } cout << setprecision(14) << sum / n << '\n'; } int calc_digits(long long int n) { int digits = 0; while (n >= 1) { n /= 10; ++digits; } return digits; } void buy_an_interger() { long long int a, b; long long int x; cin >> a >> b >> x; long long int left = 0, right = 1000000001; long long int mid; while (right - left > 1) { mid = left + (right - left) / 2; if (a * mid + b * calc_digits(mid) <= x) left = mid; else right = mid; } cout << left << '\n'; } void honest_or_unkind2() { // 後回し } long long int gcd(int a, int b) { if (a < b) { int tmp; tmp = a; a = b; b = tmp; } int r = a % b; while (r != 0) { a = b; b = r; r = a % b; } return b; } long long int lcm(long long int a, long long int b) { return a * b / gcd(a, b); } void snack() { long long int a, b; cin >> a >> b; cout << lcm(a, b) << "\n"; } bool is_prime(int n) { if (n <= 1) return false; if (n == 2) return true; if (n % 2 == 0) return false; for (int i = 3; i * i <= n; i += 2) { if (n % i == 0) return false; } return true; } void next_prime() { int x; cin >> x; int prime = x; while (!is_prime(prime)) ++prime; cout << prime << "\n"; } int factorial(int n) { int fact = 1; for (int i = n; i > 0; --i) fact *= i; return fact; } int calc_order(int n, vector<int> x) { int cnt = 0; for (int i = 0; i < n; ++i) { cnt += (x[i] - 1) * factorial(n - 1 - i); for (int j = i + 1; j < n; ++j) { if (x[j] > x[i]) --x[j]; } } return cnt; } void count_order() { int n; cin >> n; vector<int> p(n); vector<int> q(n); for (int i = 0; i < n; i++) cin >> p[i]; for (int i = 0; i < n; i++) cin >> q[i]; int p_cnt = 0, q_cnt = 0; p_cnt = calc_order(n, p); q_cnt = calc_order(n, q); cout << abs(p_cnt - q_cnt); } int main() { walk_on_multiplication_table(); // average_length(); // buy_an_interger(); // cout << calc_digits(1000000000) << '\n'; // honest_or_unkind2(); // snack(); // next_prime(); // count_order(); }
replace
13
14
13
14
TLE
p02881
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <numeric> #include <queue> #include <stack> #include <vector> using namespace std; typedef long long LL; typedef vector<LL> VL; typedef vector<vector<LL>> VVL; typedef vector<string> VS; #define REPD(i, a, b) for (LL i = (a); i < (b); i++) #define REP(i, n) REPD(i, 0, n) LL llRead() { LL a; cin >> a; return a; }; string stringRead() { string a; cin >> a; return a; }; vector<LL> vlRead(LL a) { vector<LL> rv; REP(i, a) { LL input; cin >> input; rv.push_back(input); } return rv; } vector<string> vsRead(LL a) { vector<string> rv; REP(i, a) { string input; cin >> input; rv.push_back(input); } return rv; } vector<vector<LL>> vvlRead(LL a, LL b) { vector<vector<LL>> rv; REP(i, a) { rv.push_back(vector<LL>()); REP(j, b) { LL input; cin >> input; rv.at(i).push_back(input); } } return rv; } #if 0 #define debug(d) debug1(__LINE__, #d, d) void debug1(LL line, const char* name, VL& v) { cout << line << ":" << name << ":vector<LL>(" << v.size() << ") "; REP(i, (LL)v.size()) { cout << v.at(i) << " "; } cout << endl; } void debug1(LL line, const char* name, LL i) { cout << line << ":" << name << ":LL " << i << endl;; } void debug1(LL line, const char* name, VS& v) { cout << line << ":" << name << ":vector<string>(" << v.size() << ") "; REP(i, (LL)v.size()) { cout << v.at(i) << " "; } cout << endl; } void debug1(LL line, const char* name, VVL& v) { cout << line << ":" << name << ":vector<vector<LL>>(" << v.size() << ") "; REP(i, (LL)v.size()) { REP(j, (LL)v.at(i).size()) { cout << v.at(i).at(j) << " "; } cout << ", "; } cout << endl; } void debug1(LL line, const char* name, char* s) { cout << line << ":" << name << ":char* " << s << endl;; } void debug1(LL line, const char* name, vector<const char*>& v) { cout << line << ":" << name << ":vector<const char*>(" << v.size() << ") "; REP(i, (LL)v.size()) { cout << v.at(i) << " "; } cout << endl; } void debug1(LL line, const char* name, priority_queue<LL>& p) { cout << line << ":" << name << ":priority_queue<LL>(" << p.size() << ") "; priority_queue<LL> copy = p; while(!copy.empty()) { cout << copy.top() << " "; copy.pop(); } cout << endl; } #else #define debug(n) #endif int main(int argc, const char *argv[]) { cout.precision(16); // source code auto n = llRead(); VL s; LL c = 2; LL n2 = n; LL sn = sqrt(n); while (true) { if (n2 == 1) break; if (c > sn) { s.push_back(n2); break; } if ((n2 / c) * c == n2) { s.push_back(c); n2 = n2 / c; continue; } c++; } debug(s); #if 0 LL a = 1; LL b = 1; while(!s.empty()) { LL cu = s.back(); s.pop_back(); if (b > a) a = a*cu; else b = b*cu; } cout << (a-1) + (b-1) << endl; #endif LL a = 1; LL b = 1; LL min = 10000000000000L; function<void(LL)> check = [&](LL i) { if (a + b > min) return; if (i < s.size()) { a *= s.at(i); check(i + 1); a /= s.at(i); b *= s.at(i); check(i + 1); b /= s.at(i); } else { if (a + b < min) min = a + b; } }; check(0); cout << min - 2 << endl; return 0; }
#include <algorithm> #include <cmath> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <numeric> #include <queue> #include <stack> #include <vector> using namespace std; typedef long long LL; typedef vector<LL> VL; typedef vector<vector<LL>> VVL; typedef vector<string> VS; #define REPD(i, a, b) for (LL i = (a); i < (b); i++) #define REP(i, n) REPD(i, 0, n) LL llRead() { LL a; cin >> a; return a; }; string stringRead() { string a; cin >> a; return a; }; vector<LL> vlRead(LL a) { vector<LL> rv; REP(i, a) { LL input; cin >> input; rv.push_back(input); } return rv; } vector<string> vsRead(LL a) { vector<string> rv; REP(i, a) { string input; cin >> input; rv.push_back(input); } return rv; } vector<vector<LL>> vvlRead(LL a, LL b) { vector<vector<LL>> rv; REP(i, a) { rv.push_back(vector<LL>()); REP(j, b) { LL input; cin >> input; rv.at(i).push_back(input); } } return rv; } #if 0 #define debug(d) debug1(__LINE__, #d, d) void debug1(LL line, const char* name, VL& v) { cout << line << ":" << name << ":vector<LL>(" << v.size() << ") "; REP(i, (LL)v.size()) { cout << v.at(i) << " "; } cout << endl; } void debug1(LL line, const char* name, LL i) { cout << line << ":" << name << ":LL " << i << endl;; } void debug1(LL line, const char* name, VS& v) { cout << line << ":" << name << ":vector<string>(" << v.size() << ") "; REP(i, (LL)v.size()) { cout << v.at(i) << " "; } cout << endl; } void debug1(LL line, const char* name, VVL& v) { cout << line << ":" << name << ":vector<vector<LL>>(" << v.size() << ") "; REP(i, (LL)v.size()) { REP(j, (LL)v.at(i).size()) { cout << v.at(i).at(j) << " "; } cout << ", "; } cout << endl; } void debug1(LL line, const char* name, char* s) { cout << line << ":" << name << ":char* " << s << endl;; } void debug1(LL line, const char* name, vector<const char*>& v) { cout << line << ":" << name << ":vector<const char*>(" << v.size() << ") "; REP(i, (LL)v.size()) { cout << v.at(i) << " "; } cout << endl; } void debug1(LL line, const char* name, priority_queue<LL>& p) { cout << line << ":" << name << ":priority_queue<LL>(" << p.size() << ") "; priority_queue<LL> copy = p; while(!copy.empty()) { cout << copy.top() << " "; copy.pop(); } cout << endl; } #else #define debug(n) #endif int main(int argc, const char *argv[]) { cout.precision(16); // source code auto n = llRead(); VL s; LL c = 2; LL n2 = n; LL sn = sqrt(n); while (true) { if (n2 == 1) break; if (c > sn) { s.push_back(n2); break; } if ((n2 / c) * c == n2) { s.push_back(c); n2 = n2 / c; continue; } c++; } debug(s); #if 0 LL a = 1; LL b = 1; while(!s.empty()) { LL cu = s.back(); s.pop_back(); if (b > a) a = a*cu; else b = b*cu; } cout << (a-1) + (b-1) << endl; #endif LL a = 1; LL b = 1; LL min = 10000000000000L; function<void(LL)> check = [&](LL i) { if (a + b > min) return; if (i < s.size()) { LL cn = 1; for (LL j = i + 1; j < s.size(); j++) { if (s.at(i) == s.at(j)) { cn++; } else { break; } } if (cn == 1) { a *= s.at(i); check(i + 1); a /= s.at(i); b *= s.at(i); check(i + 1); b /= s.at(i); } else { debug(i); debug(cn); for (LL k = 0; k < cn; k++) { LL ba = a; LL bb = b; for (LL l = 0; l < k; l++) { a *= s.at(i); } for (LL l = 0; l < cn - k; l++) { b *= s.at(i); } check(i + cn); a = ba; b = bb; } } } else { if (a + b < min) min = a + b; } }; check(0); cout << min - 2 << endl; return 0; }
replace
160
166
160
192
TLE
p02881
C++
Time Limit Exceeded
#include <bits/stdc++.h> #include <math.h> #include <stdio.h> using namespace std; using vi = vector<int>; using vll = vector<long long int>; using vb = vector<bool>; using vvi = vector<vector<int>>; using vvll = vector<vector<long long int>>; using ll = long long int; int main() { ll N; cin >> N; ll p = N - 1; for (int i = 2; i < N; i++) { if (N % i == 0) { if ((N / i - 1) + i - 1 < p) { p = (N / i - 1) + i - 1; } else { break; } } else { continue; } } cout << p; }
#include <bits/stdc++.h> #include <math.h> #include <stdio.h> using namespace std; using vi = vector<int>; using vll = vector<long long int>; using vb = vector<bool>; using vvi = vector<vector<int>>; using vvll = vector<vector<long long int>>; using ll = long long int; int main() { ll N; cin >> N; ll p = N - 1; for (int i = 2; pow(i, 2) <= N; i++) { if (N % i == 0) { if ((N / i - 1) + i - 1 < p) { p = (N / i - 1) + i - 1; } else { break; } } else { continue; } } cout << p; }
replace
15
16
15
16
TLE
p02881
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main(void) { long long n; cin >> n; long long min = n + 1; long long tmp; for (long long i = 1; i * 2 <= n; i++) { long long j; if (n % i == 0) { j = n / i; tmp = j + i - 2; } if (min > tmp) min = tmp; } cout << min << endl; return 0; }
#include <iostream> using namespace std; int main(void) { long long n; cin >> n; long long min = n + 1; long long tmp; for (long long i = 1; i * i <= n; i++) { long long j; if (n % i == 0) { j = n / i; tmp = j + i - 2; } if (min > tmp) min = tmp; } cout << min << endl; return 0; }
replace
7
8
7
8
TLE
p02881
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { long int N; cin >> N; long int c = N - 1; for (long int i = N / 2; i > 0; i--) { long int q; q = N / i; if (i * q == N && i + q - 2 <= c) { c = i + q - 2; } } cout << c << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long int N; cin >> N; long int c = N - 1; for (long int i = (int)sqrt(N); i > 0; i--) { long int q; q = N / i; if (i * q == N && i + q - 2 <= c) { c = i + q - 2; } } cout << c << endl; }
replace
9
10
9
10
TLE
p02881
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) \ ; \ for (long long i = 0; i < (n); i++) using namespace std; typedef long long ll; int main() { ll n; cin >> n; ll r = sqrt(n); for (ll i = r; i <= n; i++) { if (n % i == 0) { cout << i + n / i - 2 << endl; break; } } }
#include <bits/stdc++.h> #define rep(i, n) \ ; \ for (long long i = 0; i < (n); i++) using namespace std; typedef long long ll; int main() { ll n; cin >> n; ll r = sqrt(n); for (ll i = r; i > 0; i--) { if (n % i == 0) { cout << i + n / i - 2 << endl; break; } } }
replace
10
11
10
11
TLE
p02881
C++
Time Limit Exceeded
#include <algorithm> #include <bits/stdc++.h> #include <iostream> #include <math.h> #include <string> #include <vector> #define rep(i, n) \ for (int i = 0; i < n; i++) \ ; using namespace std; typedef long long ll; int main() { cin.tie(0); ios::sync_with_stdio(false); ll N; cin >> N; ll result = N - 1; for (ll i = 1; i <= N; i++) { for (ll j = i; j <= N; j++) { if (N == i * j) { result = min(result, i + j - 2); } } } cout << result << endl; }
#include <algorithm> #include <bits/stdc++.h> #include <iostream> #include <math.h> #include <string> #include <vector> #define rep(i, n) \ for (int i = 0; i < n; i++) \ ; using namespace std; typedef long long ll; int main() { cin.tie(0); ios::sync_with_stdio(false); ll N; cin >> N; ll result = N - 1; for (ll i = 1; i <= sqrt(N); i++) { if (N % i == 0) { result = min(result, i + (N / i) - 2); } } cout << result << endl; }
replace
19
24
19
22
TLE
p02881
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define ll long long #define ss second #define ff first #define all(a) a.begin(), a.end() #define All(a) a.rbegin(), a.rend() #define ios \ ios_base::sync_with_stdio(0), cin.tie(0), cout.precision(10), cout << fixed int main() { ios; ll n; cin >> n; int ans = 1; for (int i = 1; i * i <= n; ++i) if (n % i == 0) ans = i; cout << (n / ans + ans - 2) << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ss second #define ff first #define all(a) a.begin(), a.end() #define All(a) a.rbegin(), a.rend() #define ios \ ios_base::sync_with_stdio(0), cin.tie(0), cout.precision(10), cout << fixed int main() { ios; ll n; cin >> n; ll ans = 1; for (ll i = 1; i * i <= n; ++i) if (n % i == 0) ans = i; cout << (n / ans + ans - 2) << '\n'; return 0; }
replace
13
15
13
15
TLE
p02881
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main() { ll n; cin >> n; ll ans = 1e18; for (int i = 1; i * i < n; i++) { if (n % i != 0) continue; ll j = n / i; ans = min(ans, i + j - 2); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main() { ll n; cin >> n; ll ans = 1e18; for (ll i = 1; i * i <= n; ++i) { if (n % i != 0) continue; ll j = n / i; ans = min(ans, i + j - 2); } cout << ans << endl; return 0; }
replace
9
10
9
10
TLE
p02881
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main(void) { long long N; cin >> N; long long minum = N - 1; for (long long i = 2; i <= N; i++) { if (N % i == 0) { minum = min(minum, i + N / i - 2); } } cout << minum << endl; }
#include <iostream> using namespace std; int main(void) { long long N; cin >> N; long long minum = N - 1; for (long long i = 2; i * i <= N; i++) { if (N % i == 0) { minum = min(minum, i + N / i - 2); } } cout << minum << endl; }
replace
6
7
6
7
TLE
p02881
C++
Time Limit Exceeded
#include <algorithm> #include <cstdlib> #include <iostream> #include <string> #include <vector> using namespace std; int main() { long n, max, sa; cin >> n; sa = n; for (long i = 1; i <= n; i++) { if (n % i == 0) { long aho = n / i; long sasa = abs(aho - i); if (sasa <= sa) { sa = sasa; max = i; } } } long k = n / max; cout << k + max - 2; return 0; }
#include <algorithm> #include <cstdlib> #include <iostream> #include <string> #include <vector> using namespace std; int main() { long n, max, sa; cin >> n; sa = n; max = 1; long jougen = n; if (n > 1000000) jougen = 1000000; for (long i = 1; i <= jougen; i++) { if (n % i == 0) { long aho = n / i; long sasa = abs(aho - i); if (sasa <= sa) { sa = sasa; max = i; } } } long k = n / max; cout << k + max - 2; return 0; }
replace
12
13
12
17
TLE
p02881
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int64_t n; cin >> n; int64_t ans = n - 1; for (int i = 1; i * i <= n; i++) { if (n % i != 0) continue; ans = min(ans, i + n / i - 2); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int64_t n; cin >> n; int64_t ans = n - 1; for (int64_t i = 1; i * i <= n; i++) { if (n % i != 0) continue; ans = min(ans, i + n / i - 2); } cout << ans << endl; }
replace
9
10
9
10
TLE
p02881
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <string> #include <unordered_map> #include <utility> #include <vector> 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; } using namespace std; #define min_3(a, b, c) min(a, min(b, c)) #define max_3(a, b, c) max(a, max(b, c)) #define inf 1e12 + 7 typedef long long ll; int main() { ll n; cin >> n; ll ans = inf; for (ll i = 1; i <= n / 2 + 1; i++) { ll j = n / i; if (n % i == 0) { ans = min(ans, i - 1 + j - 1); } } cout << ans << endl; return 0; }
#include <algorithm> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <string> #include <unordered_map> #include <utility> #include <vector> 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; } using namespace std; #define min_3(a, b, c) min(a, min(b, c)) #define max_3(a, b, c) max(a, max(b, c)) #define inf 1e12 + 7 typedef long long ll; int main() { ll n; cin >> n; ll ans = inf; for (ll i = 1; i <= sqrt(n); i++) { ll j = n / i; if (n % i == 0) { ans = min(ans, i - 1 + j - 1); } } cout << ans << endl; return 0; }
replace
38
39
38
39
TLE
p02881
C++
Runtime Error
#include <iostream> #include <math.h> using namespace std; int main() { long long int n; cin >> n; long long int nn = (long long int)sqrt(n); int ojisan; for (long long int i = 1; i < nn; i++) { if (n % i == 0) ojisan = i; } long long int ojisan1 = n / ojisan; // cout << ojisan << '\n'; cout << ojisan + ojisan1 - 2; }
#include <iostream> #include <math.h> using namespace std; int main() { long long int n; cin >> n; long long int nn = (long long int)sqrt(n); int ojisan; for (long long int i = 1; i <= nn; i++) { if (n % i == 0) ojisan = i; } long long int ojisan1 = n / ojisan; // cout << ojisan << '\n'; cout << ojisan + ojisan1 - 2; }
replace
12
13
12
13
0
p02881
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using P = pair<int, int>; int main() { ll n; cin >> n; ll ans = 1e18; for (int i = 1; i * i <= n; i++) { if (n % i != 0) continue; ll j = n / i; ans = (ans, i + j - 2); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using P = pair<int, int>; int main() { ll n; cin >> n; ll ans = 1e18; for (ll i = 1; i * i <= n; i++) { if (n % i != 0) continue; ll j = n / i; ans = (ans, i + j - 2); } cout << ans << endl; return 0; }
replace
10
11
10
11
TLE
p02881
C++
Time Limit Exceeded
#include <algorithm> #include <cassert> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <vector> using namespace std; typedef long long LL; template <typename F, typename S> std::ostream &operator<<(ostream &os, const pair<F, S> &p) { os << "(" << p.first << "," << p.second << ")"; return os; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "["; for (const T &a : v) { os << a << ", "; } os << "]"; return os; } template <typename K, typename V> ostream &operator<<(ostream &os, const map<K, V> &m) { os << "{"; for (const auto &p : m) { os << p.first << ":" << p.second << ", "; } os << "}"; return os; } int main() { LL n; cin >> n; LL ans = n + 1; for (LL i = 1; i < n; ++i) { if (n % i != 0) continue; ans = min(ans, i + n / i - 2); } cout << ans << endl; return 0; }
#include <algorithm> #include <cassert> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <vector> using namespace std; typedef long long LL; template <typename F, typename S> std::ostream &operator<<(ostream &os, const pair<F, S> &p) { os << "(" << p.first << "," << p.second << ")"; return os; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "["; for (const T &a : v) { os << a << ", "; } os << "]"; return os; } template <typename K, typename V> ostream &operator<<(ostream &os, const map<K, V> &m) { os << "{"; for (const auto &p : m) { os << p.first << ":" << p.second << ", "; } os << "}"; return os; } int main() { LL n; cin >> n; LL ans = n + 1; for (LL i = 1; i * i <= n; ++i) { if (n % i != 0) continue; ans = min(ans, i + n / i - 2); } cout << ans << endl; return 0; }
replace
41
42
41
42
TLE
p02881
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) typedef long long ll; typedef pair<int, int> pii; int main() { ll n; cin >> n; ll res = n - 1; for (ll i = 1; i <= i * i; i++) { if (n % i == 0) res = min(res, i - 1 + n / i - 1); } cout << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) typedef long long ll; typedef pair<int, int> pii; int main() { ll n; cin >> n; ll res = n - 1; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) res = min(res, i - 1 + n / i - 1); } cout << res << endl; return 0; }
replace
9
10
9
10
TLE
p02881
C++
Runtime Error
#include <algorithm> #include <array> #include <cassert> #include <cmath> #include <cstdio> #include <deque> #include <iostream> #include <limits> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define for0(i, N) for (int i = 0; i < (N); ++i) #define for1n(i, N) for (int i = 1; i <= (N); ++i) #define for1(i, N) for (int i = 1; i < (N); ++i) #define forn(i, N) for (int i = 0; i <= (N); ++i) #define forx(i, N, x) for (int i = (x); i < (N); ++i) #define forl(i, N, x, a) \ for (int i = (x), a = 0; a < (N); i = (i + 1) % (N), ++a) using namespace std; typedef long long ll; typedef long double ld; typedef priority_queue<ll> pq; typedef priority_queue<ll, vector<ll>, greater<ll>> pql; typedef stack<ll> stk; typedef queue<ll> qu; typedef pair<ll, ll> pll; typedef map<ll, ll> mll; typedef unordered_map<ll, ll> umll; typedef set<ll> sll; typedef unordered_set<ll> usll; map<ll, ll> pf(ll x) { ll y = x; ll a = 2; map<ll, ll> m; while (a * a <= x) { if (y % a == 0) { y /= a; ++m[a]; } else { ++a; } } if (y != 1) ++m[y]; return m; } int main(void) { cin.tie(0); ios::sync_with_stdio(false); long long N; cin >> N; long long result = 1e16; // for(auto &&i : pf(N)){ // for (ll j = 1; j <= i.second; ++j) // result = // (result < 0) ? // (N / (ll)pow(i.first, j) + (ll)pow(i.first, j)) : // min(result, N / (ll)pow(i.first, j) + (ll)pow(i.first, j)); // } // cout << result - 2; for0(i, sqrt(N) + 1) { if (N % i == 0) { result = min(result, N / i + i); } } cout << result - 2; return 0; }
#include <algorithm> #include <array> #include <cassert> #include <cmath> #include <cstdio> #include <deque> #include <iostream> #include <limits> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define for0(i, N) for (int i = 0; i < (N); ++i) #define for1n(i, N) for (int i = 1; i <= (N); ++i) #define for1(i, N) for (int i = 1; i < (N); ++i) #define forn(i, N) for (int i = 0; i <= (N); ++i) #define forx(i, N, x) for (int i = (x); i < (N); ++i) #define forl(i, N, x, a) \ for (int i = (x), a = 0; a < (N); i = (i + 1) % (N), ++a) using namespace std; typedef long long ll; typedef long double ld; typedef priority_queue<ll> pq; typedef priority_queue<ll, vector<ll>, greater<ll>> pql; typedef stack<ll> stk; typedef queue<ll> qu; typedef pair<ll, ll> pll; typedef map<ll, ll> mll; typedef unordered_map<ll, ll> umll; typedef set<ll> sll; typedef unordered_set<ll> usll; map<ll, ll> pf(ll x) { ll y = x; ll a = 2; map<ll, ll> m; while (a * a <= x) { if (y % a == 0) { y /= a; ++m[a]; } else { ++a; } } if (y != 1) ++m[y]; return m; } int main(void) { cin.tie(0); ios::sync_with_stdio(false); long long N; cin >> N; long long result = 1e16; // for(auto &&i : pf(N)){ // for (ll j = 1; j <= i.second; ++j) // result = // (result < 0) ? // (N / (ll)pow(i.first, j) + (ll)pow(i.first, j)) : // min(result, N / (ll)pow(i.first, j) + (ll)pow(i.first, j)); // } // cout << result - 2; for1(i, sqrt(N) + 1) { if (N % i == 0) { result = min(result, N / i + i); } } cout << result - 2; return 0; }
replace
79
80
79
80
-8
p02881
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { long long N; cin >> N; long long res; for (int i = 1; i * i < N; i++) { if (N % i == 0) { res = N / i + i - 2; } } cout << res; }
#include <bits/stdc++.h> using namespace std; int main() { long long N; cin >> N; long long res; for (long long i = 1; i * i <= N; i++) { if (N % i == 0) { res = N / i + i - 2; } } cout << res; }
replace
8
9
8
9
TLE
p02881
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { long long x; cin >> x; long long ans = 1LL << 60; for (int i = 1; i * i <= x; ++i) { if (x % i) continue; ans = min(ans, i + x / i - 2); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long x; cin >> x; long long ans = 1LL << 60; for (long long i = 1; i * i <= x; ++i) { if (x % i) continue; ans = min(ans, i + x / i - 2); } cout << ans << endl; }
replace
7
8
7
8
TLE
p02881
C++
Time Limit Exceeded
#include <algorithm> #include <fstream> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; long long MOD = 1000000007; int main() { long long N; cin >> N; long long ans = MOD * MOD; for (int i = 1; i * i <= N; i++) { if (N % i == 0) { ans = min(ans, i + N / i - 2); } } cout << ans << endl; }
#include <algorithm> #include <fstream> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; long long MOD = 1000000007; int main() { long long N; cin >> N; long long ans = MOD * MOD; for (long long i = 1; i * i <= N; i++) { if (N % i == 0) { ans = min(ans, i + N / i - 2); } } cout << ans << endl; }
replace
21
22
21
22
TLE
p02881
C++
Runtime Error
#include <iostream> using namespace std; int main() { long long n, a = 0, b = 0; cin >> n; for (long long d = 2; d * d <= n; d++) { if (n % d == 0) a = d; } b = n / a; cout << a - 1 + b - 1; return 0; }
#include <iostream> using namespace std; int main() { unsigned long long n, a = 1, b = 0; cin >> n; for (long long d = 2; d * d <= n; d++) { if (n % d == 0) a = d; } b = n / a; cout << a - 1 + b - 1; return 0; }
replace
5
6
5
6
0
p02881
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define ll long long using namespace std; int main() { ll n; cin >> n; int m = sqrt(n); for (int i = m; i >= 1; i++) { if (n % i == 0) { m = n / i; ll sum = (i - 1) + (m - 1); cout << sum << endl; return 0; } } return 0; }
#include <bits/stdc++.h> #define ll long long using namespace std; int main() { ll n; cin >> n; ll m = sqrt(n); for (ll i = m; i >= 1; i--) { if (n % i == 0) { m = n / i; ll sum = (i - 1) + (m - 1); cout << sum << endl; return 0; } } return 0; }
replace
6
8
6
8
TLE
p02881
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; ++i) #define repe(i, n) for (int i = 0; i <= n; ++i) #define repr(i, n) for (int i = n - 1; i > 0; --i) #define all(x) (x).begin(), (x).end() #define pb(x) push_back(x) 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 (b < a) { a = b; return 1; } return 0; } template <class T> using V = vector<T>; typedef long long ll; const int INF = 1e9; const ll mod = 1000000007; 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 main() { ll n; cin >> n; ll res = 1000000000010; ll tmp = 0; for (ll i = 1; i < n; ++i) { if (n % i == 0) { tmp = (i - 1) + (n / i) - 1; res = min(tmp, res); } } cout << res << "\n"; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; ++i) #define repe(i, n) for (int i = 0; i <= n; ++i) #define repr(i, n) for (int i = n - 1; i > 0; --i) #define all(x) (x).begin(), (x).end() #define pb(x) push_back(x) 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 (b < a) { a = b; return 1; } return 0; } template <class T> using V = vector<T>; typedef long long ll; const int INF = 1e9; const ll mod = 1000000007; 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 main() { ll n; cin >> n; ll res = 1000000000010; ll tmp = 0; for (ll i = 1; i * i <= n; ++i) { if (n % i == 0) { tmp = (i - 1) + (n / i) - 1; res = min(tmp, res); } } cout << res << "\n"; }
replace
34
35
34
35
TLE
p02881
C++
Time Limit Exceeded
#include <cstring> #include <iostream> #include <queue> #include <utility> #include <vector> typedef long long ll; using namespace std; int main() { ll N; ll tmp, out; out = 1000000000000; cin >> N; for (ll i = 2; i <= N / 2; i++) { if (N % i == 0) { tmp = N / i; if (out > (tmp + i - 2)) out = tmp + i - 2; } } if (out == 1000000000000) out = N - 1; cout << out; return 0; }
#include <cstring> #include <iostream> #include <queue> #include <utility> #include <vector> typedef long long ll; using namespace std; int main() { ll N; ll tmp, out; out = 1000000000000; cin >> N; for (ll i = 2; i * i <= N; i++) { if (N % i == 0) { tmp = N / i; if (out > (tmp + i - 2)) out = tmp + i - 2; } } if (out == 1000000000000) out = N - 1; cout << out; return 0; }
replace
16
17
16
17
TLE
p02881
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 1; i < (int)(n); i++) using namespace std; typedef long long ll; int main() { ll n; cin >> n; ll max = 0; rep(i, sqrt(n)) { if (n % i == 0) max = i; } cout << max - 1 + n / max - 1 << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 1; i < (int)(n); i++) using namespace std; typedef long long ll; int main() { ll n; cin >> n; ll max = 0; for (int i = 1; i <= sqrt(n); i++) { if (n % i == 0) max = i; } cout << max - 1 + n / max - 1 << endl; }
replace
10
11
10
11
0
p02882
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define all(x) (x).begin(), (x).end() const int mod = 1000000007, MAX = 100003, INF = 1 << 30; int main() { double A, B, X; cin >> A >> B >> X; double S = X / A; if (A * A * B == X) return 1; double left = 0.0, right = M_PI / 2.0; for (int i = 0; i < 300; i++) { double mid = (left + right) / 2.0; double l = A * sin(mid), h = B * sin(M_PI / 2.0 - mid); double size; if (l <= h) { size = A * B - A * A * tan(mid) / 2.0; } else { size = B * B * tan(M_PI / 2.0 - mid) / 2.0; } if (size >= S) left = mid; else right = mid; } printf("%.12lf\n", left * 90.0 / (M_PI / 2.0)); // cout<<setprecision(25)<<left*90.0/(M_PI/2.0)<<endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define all(x) (x).begin(), (x).end() const int mod = 1000000007, MAX = 100003, INF = 1 << 30; int main() { double A, B, X; cin >> A >> B >> X; double S = X / A; if (A * A * B == X) { cout << 1.130863886742583809729988e-14 << endl; return 0; } double left = 0.0, right = M_PI / 2.0; for (int i = 0; i < 300; i++) { double mid = (left + right) / 2.0; double l = A * sin(mid), h = B * sin(M_PI / 2.0 - mid); double size; if (l <= h) { size = A * B - A * A * tan(mid) / 2.0; } else { size = B * B * tan(M_PI / 2.0 - mid) / 2.0; } if (size >= S) left = mid; else right = mid; } printf("%.12lf\n", left * 90.0 / (M_PI / 2.0)); // cout<<setprecision(25)<<left*90.0/(M_PI/2.0)<<endl; }
replace
12
14
12
16
0
p02882
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); double base, height, waterVolume; cin >> base >> height >> waterVolume; double waterHeight = waterVolume / base / base; if (waterHeight * 2.0 > height) { height = (height - waterHeight) * 2.0; if (height == 0) { throw; } waterHeight = height / 2.0; } double waterArea = waterHeight * base; double ret = atan(2.0 * waterArea / height / height); ret = 90.0 - (ret / M_PI * 180.0); cout << setprecision(20) << ret << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); double base, height, waterVolume; cin >> base >> height >> waterVolume; double waterHeight = waterVolume / base / base; if (waterHeight * 2.0 > height) { height = (height - waterHeight) * 2.0; if (abs(height) <= 1e-10) { cout << "0\n"; return 0; } waterHeight = height / 2.0; } double waterArea = waterHeight * base; double ret = atan(2.0 * waterArea / height / height); ret = 90.0 - (ret / M_PI * 180.0); cout << setprecision(20) << ret << '\n'; return 0; }
replace
13
15
13
16
0
p02882
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { double a, b, x; cin >> a >> b >> x; double delta = M_PI / pow(2, 28); double capa; double ans; if (a * a * b / 2 < x) { for (double theta = 0; tan(theta) <= (b / a); theta += delta) { capa = a * a * b - 0.5 * a * a * a * tan(theta); if (x >= capa) { ans = theta; break; } } } else { for (double theta = atan(b / a); theta <= M_PI / 2; theta += delta) { capa = 0.5 * a * b * b / tan(theta); if (x >= capa) { ans = theta; break; } } } printf("%lf\n", ans * 180 / M_PI); }
#include <bits/stdc++.h> using namespace std; int main() { double a, b, x; cin >> a >> b >> x; double delta = M_PI / pow(2, 26); double capa; double ans; if (a * a * b / 2 < x) { for (double theta = 0; tan(theta) <= (b / a); theta += delta) { capa = a * a * b - 0.5 * a * a * a * tan(theta); if (x >= capa) { ans = theta; break; } } } else { for (double theta = atan(b / a); theta <= M_PI / 2; theta += delta) { capa = 0.5 * a * b * b / tan(theta); if (x >= capa) { ans = theta; break; } } } printf("%lf\n", ans * 180 / M_PI); }
replace
6
7
6
7
TLE
p02882
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define debug(x) cerr << #x << ": " << x << endl; #define iosbase ios_base::sync_with_stdio(false) #define tie \ cin.tie(); \ cout.tie(); #define endl '\n' typedef pair<int, int> ii; typedef long long ll; #define pi acos(-1) long double converte(long double N) { return (N * pi) / 180.0; } int n, m; int main() { // debug(co); iosbase; tie; int a, b, x; cin >> a >> b >> x; long double porcentagem = (long double)x / ((long double)a * a * b); // debug(porcentagem); long double angle, lo = 0.0, hi = 90.0; long double ans = 0.0; int it = 0; while (it < 10000000) { it++; angle = (lo + hi) / 2.0; // debug(angle); long double t = tan(converte(90.0 - angle)); long double co = t * b; // debug(co); if (co > a) { // cout << "triangulo de cima" << endl; t = tan(converte(angle)); co = t * a; long double area = (co * a) / 2.0; // debug(area); // debug(area / (long double)(a*b)); if (area / (long double)(a * b) <= (1.0 - porcentagem)) { // cout << "resposta possivel" << endl; ans = angle; lo = angle + 0.0000000001; } else { hi = angle - 0.0000000001; } } else { // cout << "triangulo debaixo" << endl; long double area = (co * b) / 2.0; // debug(area); // debug( area / (long double)(a*b) ); if (area / (long double)(a * b) >= porcentagem) { ans = angle; // cout << "resposta possivel" << endl; lo = angle + 0.0000000001; } else { hi = angle - 0.0000000001; } } } cout << setprecision(10) << fixed << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define debug(x) cerr << #x << ": " << x << endl; #define iosbase ios_base::sync_with_stdio(false) #define tie \ cin.tie(); \ cout.tie(); #define endl '\n' typedef pair<int, int> ii; typedef long long ll; #define pi acos(-1) long double converte(long double N) { return (N * pi) / 180.0; } int n, m; int main() { // debug(co); iosbase; tie; int a, b, x; cin >> a >> b >> x; long double porcentagem = (long double)x / ((long double)a * a * b); // debug(porcentagem); long double angle, lo = 0.0, hi = 90.0; long double ans = 0.0; int it = 0; while (it < 100000) { it++; angle = (lo + hi) / 2.0; // debug(angle); long double t = tan(converte(90.0 - angle)); long double co = t * b; // debug(co); if (co > a) { // cout << "triangulo de cima" << endl; t = tan(converte(angle)); co = t * a; long double area = (co * a) / 2.0; // debug(area); // debug(area / (long double)(a*b)); if (area / (long double)(a * b) <= (1.0 - porcentagem)) { // cout << "resposta possivel" << endl; ans = angle; lo = angle + 0.0000000001; } else { hi = angle - 0.0000000001; } } else { // cout << "triangulo debaixo" << endl; long double area = (co * b) / 2.0; // debug(area); // debug( area / (long double)(a*b) ); if (area / (long double)(a * b) >= porcentagem) { ans = angle; // cout << "resposta possivel" << endl; lo = angle + 0.0000000001; } else { hi = angle - 0.0000000001; } } } cout << setprecision(10) << fixed << ans << endl; }
replace
32
33
32
33
TLE
p02882
Python
Runtime Error
from math import atan, degrees def main(): a, b, x = map(int, input().split()) full = a * a * b half = full * 0.5 if x <= half: s = x / a ans = 90 - degrees(atan(2 * s / b**2)) else: s = (full - x) / a ans = 90 - degrees(atan(a**2 / (2 * s))) print(ans) if __name__ == "__main__": main()
from math import atan, degrees def main(): a, b, x = map(int, input().split()) full = a * a * b half = full * 0.5 if x <= half: s = x / a ans = 90 - degrees(atan(2 * s / b**2)) else: s = (full - x) / a if s != 0: ans = 90 - degrees(atan(a**2 / (2 * s))) else: ans = 0 print(ans) if __name__ == "__main__": main()
replace
15
16
15
19
0
p02882
Python
Runtime Error
from sys import stdin import math a, b, x = [int(x) for x in stdin.readline().rstrip().split()] if 2 * x >= (a**2) * b: v = (a**2) * b - x c = (2 * v) / (a**2) print(90 - math.atan(a / c) * 180 / math.pi) else: c = 2 * x / (a * b) print(math.atan(b / c) * 180 / math.pi)
from sys import stdin import math a, b, x = [int(x) for x in stdin.readline().rstrip().split()] if x == (a**2) * b: print(0) exit() if 2 * x >= (a**2) * b: v = (a**2) * b - x c = (2 * v) / (a**2) print(90 - math.atan(a / c) * 180 / math.pi) else: c = 2 * x / (a * b) print(math.atan(b / c) * 180 / math.pi)
insert
5
5
5
8
0
p02882
Python
Runtime Error
import math a, b, x = map(int, input().split()) b_1 = x / (a**2) area_1 = a * b_1 area_2 = (a * b) / 2 if area_2 > area_1: # 三角形 h = (a * b_1 * 2) / b ans = math.degrees(math.atan(h / b)) else: # 梯形 upside_len = b_1 * 2 - b ans = math.degrees(math.atan(a / (b - upside_len))) print(90 - ans)
import math a, b, x = map(int, input().split()) b_1 = x / (a**2) area_1 = a * b_1 area_2 = (a * b) / 2 if b_1 == b: ans = 90 elif area_2 > area_1: # 三角形 h = (a * b_1 * 2) / b ans = math.degrees(math.atan(h / b)) else: # 梯形 upside_len = b_1 * 2 - b ans = math.degrees(math.atan(a / (b - upside_len))) print(90 - ans)
replace
8
9
8
11
0
p02882
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; //**************************************************** #define lp(var, start, end) for (ll var = start; var < end; ++var) #define rlp(var, start, end) for (ll var = start; var >= end; var--) #define pb push_back #define mp make_pair #define pf push_front #define ff first #define ss second #define vll vector<ll> #define pll pair<ll, ll> #define vpll vector<pll> #define all(X) X.begin(), X.end() #define endl "\n" // comment it for interactive questions #define trace1(a) cerr << #a << ": " << a << endl; #define trace2(a, b) cerr << #a << ": " << a << " " << #b << ": " << b << endl; #define trace3(a, b, c) \ cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c \ << endl; #define trace4(a, b, c, d) \ cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c \ << #d << ": " << d << endl; #define OC \ freopen("input.txt", "r", stdin); \ freopen("output.txt", "w", stdout) #define MOD (ll)1e9 + 7; #define PI 3.14159265 // change it for other mods #define FAST_IO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) //******************************************************* // Some Functions ll powmod(ll a, ll b) { ll res = 1; while (b > 0) { if (b & 1) res = (res * a) % MOD; a = (a * a) % MOD; b = b >> 1; } return res % MOD; } void solve() { double a, b, x; cin >> a >> b >> x; double h = 2 * (b - (x / (a * a))); if (h == 0) { cout << 0 << "\n"; return; } if (h > 0 && h < b) { cout << fixed << setprecision(8) << ((atan(h / a) * 180) / PI) << "\n"; return; } double k = (2 * x) / (a * b); // cout << k << "\n"; cout << fixed << setprecision(8) << atan(b / k) * 180 / PI << "\n"; } int main() { FAST_IO; #ifndef ONLINE_JUDGE OC; #endif ll t = 1; // cin >> t; while (t--) { solve(); } }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; //**************************************************** #define lp(var, start, end) for (ll var = start; var < end; ++var) #define rlp(var, start, end) for (ll var = start; var >= end; var--) #define pb push_back #define mp make_pair #define pf push_front #define ff first #define ss second #define vll vector<ll> #define pll pair<ll, ll> #define vpll vector<pll> #define all(X) X.begin(), X.end() #define endl "\n" // comment it for interactive questions #define trace1(a) cerr << #a << ": " << a << endl; #define trace2(a, b) cerr << #a << ": " << a << " " << #b << ": " << b << endl; #define trace3(a, b, c) \ cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c \ << endl; #define trace4(a, b, c, d) \ cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c \ << #d << ": " << d << endl; #define OC \ freopen("input.txt", "r", stdin); \ freopen("output.txt", "w", stdout) #define MOD (ll)1e9 + 7; #define PI 3.14159265 // change it for other mods #define FAST_IO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) //******************************************************* // Some Functions ll powmod(ll a, ll b) { ll res = 1; while (b > 0) { if (b & 1) res = (res * a) % MOD; a = (a * a) % MOD; b = b >> 1; } return res % MOD; } void solve() { double a, b, x; cin >> a >> b >> x; double h = 2 * (b - (x / (a * a))); if (h == 0) { cout << 0 << "\n"; return; } if (h > 0 && h < b) { cout << fixed << setprecision(8) << ((atan(h / a) * 180) / PI) << "\n"; return; } double k = (2 * x) / (a * b); // cout << k << "\n"; cout << fixed << setprecision(8) << atan(b / k) * 180 / PI << "\n"; } int main() { FAST_IO; // #ifndef ONLINE_JUDGE // OC; // #endif ll t = 1; // cin >> t; while (t--) { solve(); } }
replace
69
72
69
72
0
p02882
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define EPS 0.0000000001 int main() { cout << fixed; cout << setprecision(10); long double a, b; long double x, y; cin >> a >> b >> x; y = a * a * b; long double xx, yy; xx = x / a; yy = y / a; long double h, w, theta; h = b - x / (a * a); if (h > b / 2.0) { long double d = 0.0, u = 90.0; int i = 0; while (i < 10000000) { theta = (d + u) / 2.0; // if (abs(xx - a * a * tan(theta * M_PI / 180.0) / 2.0) < EPS) break; if (b / tan(theta * M_PI / 180.0) * b / 2.0 < xx) u = theta; else d = theta; i++; } // w = 2.0 * xx / h; // theta = atan2(w , h); // cout << (M_PI / 2.0 - theta) / M_PI * 180.0; cout << theta; return 0; } else { w = a; theta = atan2(2.0 * h, w); cout << theta / M_PI * 180.0; return 0; } return 0; }
#include <bits/stdc++.h> using namespace std; #define EPS 0.0000000001 int main() { cout << fixed; cout << setprecision(10); long double a, b; long double x, y; cin >> a >> b >> x; y = a * a * b; long double xx, yy; xx = x / a; yy = y / a; long double h, w, theta; h = b - x / (a * a); if (h > b / 2.0) { long double d = 0.0, u = 90.0; int i = 0; while (i < 10000000) { theta = (d + u) / 2.0; if (abs(xx - b / tan(theta * M_PI / 180.0) * b / 2.0) < EPS) break; if (b / tan(theta * M_PI / 180.0) * b / 2.0 < xx) u = theta; else d = theta; i++; } // w = 2.0 * xx / h; // theta = atan2(w , h); // cout << (M_PI / 2.0 - theta) / M_PI * 180.0; cout << theta; return 0; } else { w = a; theta = atan2(2.0 * h, w); cout << theta / M_PI * 180.0; return 0; } return 0; }
replace
26
27
26
28
TLE
p02882
Python
Runtime Error
# -*- coding: utf-8 -*- def main(): from math import degrees, atan a, b, x = map(int, input().split()) h = x / (a**2) y = 2 * h * a / b z = 2 * b - 2 * h if 2 * h >= b: print(90 - degrees(atan(a / z))) else: print(degrees(atan(b / y))) if __name__ == "__main__": main()
# -*- coding: utf-8 -*- def main(): from math import degrees, atan a, b, x = map(int, input().split()) h = x / (a**2) y = 2 * h * a / b z = 2 * b - 2 * h if x == (a**2) * b: print(0) elif 2 * h >= b: print(90 - degrees(atan(a / z))) else: print(degrees(atan(b / y))) if __name__ == "__main__": main()
replace
11
12
11
14
0
p02882
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll mod = 1e9 + 7; const ll INF = mod * mod; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define all(x) (x).begin(), (x).end() ll min(ll a, ll b) { if (a > b) { return b; } else { return a; } } ll max(ll a, ll b) { if (a > b) { return a; } else { return b; } } ll power(ll a, ll b) { ll ans = 1; for (ll i = 1; i <= b; i++) { ans *= a; } return ans; } ll gcd(ll m, ll n) { if (n == 0) { return m; } return gcd(n, m % n); } ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / gcd(a, b) * b; } int main() { double a, b, x; cin >> a >> b >> x; double h = (2 * x) / (a * b * 1.0); double pi; pi = 4.0 * atan(1.0); /* πの値 */ double unit_r = 180.0 / pi; /* ラジアン → 度 */ double atan(double t); if (h <= a) { return 1; printf("%0.10lf\n", 1.0 * atan(b / a) * unit_r); } else { printf("%0.10lf\n", 1.0 * atan((2 * b * pow(a, 2) - 2 * x) / pow(a, 3)) * unit_r); } // cout<<pi<<endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll mod = 1e9 + 7; const ll INF = mod * mod; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define all(x) (x).begin(), (x).end() ll min(ll a, ll b) { if (a > b) { return b; } else { return a; } } ll max(ll a, ll b) { if (a > b) { return a; } else { return b; } } ll power(ll a, ll b) { ll ans = 1; for (ll i = 1; i <= b; i++) { ans *= a; } return ans; } ll gcd(ll m, ll n) { if (n == 0) { return m; } return gcd(n, m % n); } ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / gcd(a, b) * b; } int main() { double a, b, x; cin >> a >> b >> x; double h = (2 * x) / (a * b * 1.0); double pi; pi = 4.0 * atan(1.0); /* πの値 */ double unit_r = 180.0 / pi; /* ラジアン → 度 */ double atan(double t); if (h <= a) { // return 1; printf("%0.10lf\n", 1.0 * atan(b / h) * unit_r); } else { printf("%0.10lf\n", 1.0 * atan((2 * b * pow(a, 2) - 2 * x) / pow(a, 3)) * unit_r); } // cout<<pi<<endl; }
replace
54
56
54
56
1
p02882
C++
Time Limit Exceeded
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <functional> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <string> #include <unordered_map> #include <vector> using namespace std; using ll = long long; int main() { const double PI = 3.14159265358979; double a, b, x; cin >> a >> b >> x; double lo = 0., hi = 90.; for (int i = 0; i < 100000; i++) { double mid = lo + (hi - lo) / 2.; double theta = (90 - mid) / 180 * PI; double r = sqrt(2 * x / (a * tan(theta))); double t = r * tan(theta); if (t > a) { double k = t - a; double v = a * k * k / tan(theta) / 2; double u = v / (a * a); r += u; } if (r > b) hi = mid; else lo = mid; } printf("%.15f\n", lo); return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <functional> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <string> #include <unordered_map> #include <vector> using namespace std; using ll = long long; int main() { const double PI = 3.14159265358979; double a, b, x; cin >> a >> b >> x; double lo = 0., hi = 90.; for (int i = 0; i < 1000; i++) { double mid = lo + (hi - lo) / 2.; double theta = (90 - mid) / 180 * PI; double r = sqrt(2 * x / (a * tan(theta))); double t = r * tan(theta); if (t > a) { double k = t - a; double v = a * k * k / tan(theta) / 2; double u = v / (a * a); r += u; } if (r > b) hi = mid; else lo = mid; } printf("%.15f\n", lo); return 0; }
replace
21
22
21
22
TLE
p02882
C++
Time Limit Exceeded
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <functional> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <string> #include <unordered_map> #include <vector> using namespace std; using ll = long long; int main() { const double PI = 3.14159265358979; double a, b, x; cin >> a >> b >> x; double lo = 0., hi = 90.; for (int i = 0; i < 100000; i++) { double mid = lo + (hi - lo) / 2.; double theta = (90 - mid) / 180 * PI; double r = sqrt(2 * x / (a * tan(theta))); double t = r * tan(theta); if (t > a) { double k = t - a; double v = a * k * k / tan(theta) / 2; double u = v / (a * a); r += u; } if (r > b) hi = mid; else lo = mid; } printf("%.15f\n", lo); return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <functional> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <string> #include <unordered_map> #include <vector> using namespace std; using ll = long long; int main() { const double PI = 3.14159265358979; double a, b, x; cin >> a >> b >> x; double lo = 0., hi = 90.; for (int i = 0; i < 10000; i++) { double mid = lo + (hi - lo) / 2.; double theta = (90 - mid) / 180 * PI; double r = sqrt(2 * x / (a * tan(theta))); double t = r * tan(theta); if (t > a) { double k = t - a; double v = a * k * k / tan(theta) / 2; double u = v / (a * a); r += u; } if (r > b) hi = mid; else lo = mid; } printf("%.15f\n", lo); return 0; }
replace
21
22
21
22
TLE
p02882
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(vec) vec.begin(), vec.end() #define MOD 1000000007 #define int long long signed main() { int a, b, x; cin >> a >> b >> x; double v = a * a * b, s; const double k = 360 / (2 * 3.141592653589793); double ans, c; if (x > v / 2) { s = v - x; double l = 2 * s / (a * a); c = l / a; } else { s = x; double l = 2 * s / (a * b); c = b / l; } for (int i = 1; i < 1580000000; i += 25) { ans = i / 1000000000.0; if (c - tan(ans) < 0.000000001) { printf("%.10lf\n", ans * k); return 0; } } }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(vec) vec.begin(), vec.end() #define MOD 1000000007 #define int long long signed main() { int a, b, x; cin >> a >> b >> x; double v = a * a * b, s; const double k = 360 / (2 * 3.141592653589793); double ans, c; if (x > v / 2) { s = v - x; double l = 2 * s / (a * a); c = l / a; } else { s = x; double l = 2 * s / (a * b); c = b / l; } printf("%.10lf\n", atan(c) * k); }
replace
22
29
22
23
TLE
p02883
C++
Runtime Error
#include "bits/stdc++.h" #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long int ll; typedef pair<int, int> P; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } int main() { cin.tie(0); ios::sync_with_stdio(false); int n, k; cin >> n >> k; vector<ll> a(n), f(n); rep(i, n) cin >> a[i]; rep(i, n) cin >> f[i]; sort(a.rbegin(), a.rend()); sort(f.begin(), f.end()); ll ng = -1, ok = 1e12; while (ok - ng > 1) { ll mid = (ok + ng) / 2; ll cost = 0; rep(i, n) { cost += max(a[i] - min(a[i], mid / f[i]), 0LL); } if (cost <= k) ok = mid; else ng = mid; } cout << ok << endl; return 0; }
#include "bits/stdc++.h" #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long int ll; typedef pair<int, int> P; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } int main() { cin.tie(0); ios::sync_with_stdio(false); int n; ll k; cin >> n >> k; vector<ll> a(n), f(n); rep(i, n) cin >> a[i]; rep(i, n) cin >> f[i]; sort(a.rbegin(), a.rend()); sort(f.begin(), f.end()); ll ng = -1, ok = 1e12; while (ok - ng > 1) { ll mid = (ok + ng) / 2; ll cost = 0; rep(i, n) { cost += max(a[i] - min(a[i], mid / f[i]), 0LL); } if (cost <= k) ok = mid; else ng = mid; } cout << ok << endl; return 0; }
replace
23
24
23
25
0
p02883
C++
Runtime Error
/************************************************ *Author : xzj213 *Created Time : 2019.10.27.20:59 *Mail : xzj213@qq.com *Problem : E ************************************************/ #include <bits/stdc++.h> #define int long long using namespace std; const int maxn = 1e5 + 5; int a[maxn], f[maxn], l, r, n, k; int read() { int x = 0, f = 1; char ch = getchar(); while (ch > 57 || ch < 48) { if (ch == 45) f = -1; ch = getchar(); } while (ch <= 57 && ch >= 48) { x = x * 10 + ch - 48; ch = getchar(); } return x * f; } bool check(int point) { int num = k; for (int i = 1; i <= n; i++) { int b = point / f[i]; if (a[i] - b > 0) num -= (a[i] - b); if (num < 0) return false; } return true; } bool cmp(int a, int b) { return a > b; } signed main() { n = read(); k = read(); for (int i = 1; i <= n; i++) a[i] = read(); for (int i = 1; i <= n; i++) f[i] = read(); sort(a + 1, a + 1 + n); sort(f + 1, f + 1 + n, cmp); l = 0; r = 1e18; while (l < r) { int Mid = (l + r) >> 1; if (check(Mid)) r = Mid; else l = Mid + 1; } cout << r << endl; return 0; }
/************************************************ *Author : xzj213 *Created Time : 2019.10.27.20:59 *Mail : xzj213@qq.com *Problem : E ************************************************/ #include <bits/stdc++.h> #define int long long using namespace std; const int maxn = 2e5 + 5; int a[maxn], f[maxn], l, r, n, k; int read() { int x = 0, f = 1; char ch = getchar(); while (ch > 57 || ch < 48) { if (ch == 45) f = -1; ch = getchar(); } while (ch <= 57 && ch >= 48) { x = x * 10 + ch - 48; ch = getchar(); } return x * f; } bool check(int point) { int num = k; for (int i = 1; i <= n; i++) { int b = point / f[i]; if (a[i] - b > 0) num -= (a[i] - b); if (num < 0) return false; } return true; } bool cmp(int a, int b) { return a > b; } signed main() { n = read(); k = read(); for (int i = 1; i <= n; i++) a[i] = read(); for (int i = 1; i <= n; i++) f[i] = read(); sort(a + 1, a + 1 + n); sort(f + 1, f + 1 + n, cmp); l = 0; r = 1e18; while (l < r) { int Mid = (l + r) >> 1; if (check(Mid)) r = Mid; else l = Mid + 1; } cout << r << endl; return 0; }
replace
9
10
9
10
0
p02883
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstdlib> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; #define INF 1000000007 #define LINF 100000000000000007 #define MOD 1000000007 #define int long long #define rep(i, n) for (int i = 0; i < n; i++) #define repb(i, n) for (int i = n - 1; i >= 0; i--) // #define MODE 1 #ifdef MODE #define DEB(X) cout << #X << ": " << X << " "; #define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " "; #define END cout << endl; #else #define DEB(X) \ {} #define ARDEB(i, X) \ {} #define END \ {} #endif int ceil2(int a, int b) { if (a % b) { return a / b + 1; } else { return a / b; } } // typedef long long int ll; typedef pair<int, int> P; struct edge { int to, cost; }; int n, k; int a[111111], f[111111]; int ans; signed main() { cin >> n >> k; rep(i, n) cin >> a[i]; rep(i, n) cin >> f[i]; sort(a, a + n); sort(f, f + n, greater<>()); int ng = -1, ok = 10000000000000; while (abs(ok - ng) > 1) { int mid = (ng + ok) / 2; int syugyo = 0; rep(i, n) { if (a[i] * f[i] > mid) { syugyo += ceil2(a[i] * f[i] - mid, f[i]); } } if (syugyo <= k) ok = mid; else ng = mid; } cout << ok << endl; }
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstdlib> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; #define INF 1000000007 #define LINF 100000000000000007 #define MOD 1000000007 #define int long long #define rep(i, n) for (int i = 0; i < n; i++) #define repb(i, n) for (int i = n - 1; i >= 0; i--) // #define MODE 1 #ifdef MODE #define DEB(X) cout << #X << ": " << X << " "; #define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " "; #define END cout << endl; #else #define DEB(X) \ {} #define ARDEB(i, X) \ {} #define END \ {} #endif int ceil2(int a, int b) { if (a % b) { return a / b + 1; } else { return a / b; } } // typedef long long int ll; typedef pair<int, int> P; struct edge { int to, cost; }; int n, k; int a[211111], f[211111]; int ans; signed main() { cin >> n >> k; rep(i, n) cin >> a[i]; rep(i, n) cin >> f[i]; sort(a, a + n); sort(f, f + n, greater<>()); int ng = -1, ok = 10000000000000; while (abs(ok - ng) > 1) { int mid = (ng + ok) / 2; int syugyo = 0; rep(i, n) { if (a[i] * f[i] > mid) { syugyo += ceil2(a[i] * f[i] - mid, f[i]); } } if (syugyo <= k) ok = mid; else ng = mid; } cout << ok << endl; }
replace
49
50
49
50
0
p02883
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define all(a) a.begin(), a.end() #define F first #define S second #define sz(x) (int)x.size() #define pb push_back #define ll long long #define vi vector<long long> #define pi pair<long long, long long> #define mp make_pair #define endl '\n' #define _ << ' ' #define FAST_LOG2(x) \ (sizeof(unsigned long) * 8 - 1 - __builtin_clzl((unsigned long)(x))) #define clog2(x) (((x) - (1 << FAST_LOG2(x))) ? FAST_LOG2(x) + 1 : FAST_LOG2(x)) using namespace __gnu_pbds; using namespace std; typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> idxset; // find_by_order(i) : iterator to the value at index i, order_of_key(x) : the // index of value x const ll mod = (ll)1e9 + 7; const ll INF = (ll)1e18; const ll N = (1 << 5); const double PI = 3.1415926535897; ll n, kk, a[200001], f[200001], ans; bool check(ll x) { ll k = kk; for (int i = 0; i < n; i++) { if (a[i] * f[i] > x) { k -= (a[i] * f[i] - x + f[i] - 1) / f[i]; } if (k < 0) return 0; } return 1; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); #ifndef ONLINE_JUDGE freopen("C.txt", "r", stdin); #endif cin >> n >> kk; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> f[i]; sort(a, a + n, greater<ll>()); sort(f, f + n); ll lb = 0, rb = (ll)1e12 + 1; while (lb < rb) { ll mid = (lb + rb) / 2; if (check(mid)) { ans = mid; rb = mid; } else { lb = mid + 1; } } cout << ans; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define all(a) a.begin(), a.end() #define F first #define S second #define sz(x) (int)x.size() #define pb push_back #define ll long long #define vi vector<long long> #define pi pair<long long, long long> #define mp make_pair #define endl '\n' #define _ << ' ' #define FAST_LOG2(x) \ (sizeof(unsigned long) * 8 - 1 - __builtin_clzl((unsigned long)(x))) #define clog2(x) (((x) - (1 << FAST_LOG2(x))) ? FAST_LOG2(x) + 1 : FAST_LOG2(x)) using namespace __gnu_pbds; using namespace std; typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> idxset; // find_by_order(i) : iterator to the value at index i, order_of_key(x) : the // index of value x const ll mod = (ll)1e9 + 7; const ll INF = (ll)1e18; const ll N = (1 << 5); const double PI = 3.1415926535897; ll n, kk, a[200001], f[200001], ans; bool check(ll x) { ll k = kk; for (int i = 0; i < n; i++) { if (a[i] * f[i] > x) { k -= (a[i] * f[i] - x + f[i] - 1) / f[i]; } if (k < 0) return 0; } return 1; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); #ifndef ONLINE_JUDGE // freopen("C.txt", "r", stdin); #endif cin >> n >> kk; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> f[i]; sort(a, a + n, greater<ll>()); sort(f, f + n); ll lb = 0, rb = (ll)1e12 + 1; while (lb < rb) { ll mid = (lb + rb) / 2; if (check(mid)) { ans = mid; rb = mid; } else { lb = mid + 1; } } cout << ans; }
replace
47
48
47
48
0
p02883
C++
Runtime Error
#include <bits/stdc++.h> // #include <tr1/unordered_map> // #include "Bignum/bignum.h" // #define big bignum #define lowbit(x) (x & -x) #define debug(x) (cout << "#x = " << (x) << endl) #define Set(x, i) memset(x, i, sizeof(x)) #define R register #define For(i, j, k) for (R int i = (j); i <= (int)(k); ++i) #define Rep(i, j, k) for (R int i = (j); i >= (int)(k); --i) #define Cross(i, j, k) for (R int i = (j); i; i = (k)) using namespace std; typedef long long ll; const ll N = 100011; const ll INF = 5e16; namespace IO { inline char gc() { static char buf[100000], *p1 = buf, *p2 = buf; return (p1 == p2) && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++; } #define dd ch = getchar() inline ll read() { R ll x = 0; R int f = 0; R char dd; for (; !isdigit(ch); dd) f ^= (ch == '-'); for (; isdigit(ch); dd) x = x * 10 + (ch ^ 48); return f ? -x : x; } #undef dd inline void write(ll x) { if (x < 0) x = -x, putchar('-'); if (x > 9) write(x / 10); putchar(x % 10 | 48); } inline void wrn(ll x) { write(x), putchar(' '); } inline void wln(ll x) { write(x), putchar('\n'); } inline void wlnn(ll x, ll y) { wrn(x), wln(y); } } // namespace IO using IO::read; using IO::wln; namespace Cesare { ll n, k, a[N], f[N]; inline int Check(ll x) { ll s = k; For(i, 1, n) if (a[i] * f[i] > x) { ll cc = x / f[i]; if (a[i] - cc > s) return 0; s -= a[i] - cc; } return s >= 0; } ll Ans; int main() { n = read(), k = read(); For(i, 1, n) a[i] = read(); For(i, 1, n) f[i] = read(); sort(a + 1, a + n + 1); sort(f + 1, f + n + 1, greater<ll>()); ll l = 0, r = 1e12; while (l <= r) { ll Mid = (l + r) >> 1; Check(Mid) ? Ans = Mid, r = Mid - 1 : l = Mid + 1; } return wln(Ans), 0; } } // namespace Cesare int main() { // freopen(".in", "r", stdin); // freopen(".out", "w", stdout); return Cesare ::main(); } /* */
#include <bits/stdc++.h> // #include <tr1/unordered_map> // #include "Bignum/bignum.h" // #define big bignum #define lowbit(x) (x & -x) #define debug(x) (cout << "#x = " << (x) << endl) #define Set(x, i) memset(x, i, sizeof(x)) #define R register #define For(i, j, k) for (R int i = (j); i <= (int)(k); ++i) #define Rep(i, j, k) for (R int i = (j); i >= (int)(k); --i) #define Cross(i, j, k) for (R int i = (j); i; i = (k)) using namespace std; typedef long long ll; const ll N = 1000011; const ll INF = 5e16; namespace IO { inline char gc() { static char buf[100000], *p1 = buf, *p2 = buf; return (p1 == p2) && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++; } #define dd ch = getchar() inline ll read() { R ll x = 0; R int f = 0; R char dd; for (; !isdigit(ch); dd) f ^= (ch == '-'); for (; isdigit(ch); dd) x = x * 10 + (ch ^ 48); return f ? -x : x; } #undef dd inline void write(ll x) { if (x < 0) x = -x, putchar('-'); if (x > 9) write(x / 10); putchar(x % 10 | 48); } inline void wrn(ll x) { write(x), putchar(' '); } inline void wln(ll x) { write(x), putchar('\n'); } inline void wlnn(ll x, ll y) { wrn(x), wln(y); } } // namespace IO using IO::read; using IO::wln; namespace Cesare { ll n, k, a[N], f[N]; inline int Check(ll x) { ll s = k; For(i, 1, n) if (a[i] * f[i] > x) { ll cc = x / f[i]; if (a[i] - cc > s) return 0; s -= a[i] - cc; } return s >= 0; } ll Ans; int main() { n = read(), k = read(); For(i, 1, n) a[i] = read(); For(i, 1, n) f[i] = read(); sort(a + 1, a + n + 1); sort(f + 1, f + n + 1, greater<ll>()); ll l = 0, r = 1e12; while (l <= r) { ll Mid = (l + r) >> 1; Check(Mid) ? Ans = Mid, r = Mid - 1 : l = Mid + 1; } return wln(Ans), 0; } } // namespace Cesare int main() { // freopen(".in", "r", stdin); // freopen(".out", "w", stdout); return Cesare ::main(); } /* */
replace
13
14
13
14
0
p02883
C++
Runtime Error
#include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, n) FOR(i, 0, n) #define all(x) (x).begin(), (x).end() #define bit(x) (1L << (x)) using ll = long long; using namespace std; template <typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); } template <typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); } int main() { int n, k; cin >> n >> k; vector<ll> a(n), f(n); REP(i, n) cin >> a[i]; REP(i, n) cin >> f[i]; sort(a.begin(), a.end()); sort(f.begin(), f.end(), [](ll x, ll y) { return x > y; }); auto check = [&](ll x) { ll t = 0; REP(i, n) { t += max(0LL, a[i] - x / f[i]); } return t <= k; }; ll l = -1, r = 1e18; while (r - l > 1) { ll m = (l + r) / 2; if (check(m)) { r = m; } else { l = m; } } cout << r << endl; return 0; }
#include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, n) FOR(i, 0, n) #define all(x) (x).begin(), (x).end() #define bit(x) (1L << (x)) using ll = long long; using namespace std; template <typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); } template <typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); } int main() { ll n, k; cin >> n >> k; vector<ll> a(n), f(n); REP(i, n) cin >> a[i]; REP(i, n) cin >> f[i]; sort(a.begin(), a.end()); sort(f.begin(), f.end(), [](ll x, ll y) { return x > y; }); auto check = [&](ll x) { ll t = 0; REP(i, n) { t += max(0LL, a[i] - x / f[i]); } return t <= k; }; ll l = -1, r = 1e18; while (r - l > 1) { ll m = (l + r) / 2; if (check(m)) { r = m; } else { l = m; } } cout << r << endl; return 0; }
replace
17
18
17
18
0
p02883
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long const int maxn = 100100; int a[maxn], f[maxn]; ll check(int n, ll t) { ll ret = 0; for (int i = 1; i <= n; i++) { ret += max(0ll, a[i] - t / f[n - i + 1]); } return ret; } int main(void) { int n; ll k; scanf("%d%lld", &n, &k); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= n; i++) scanf("%d", &f[i]); sort(a + 1, a + n + 1); sort(f + 1, f + n + 1); ll l = 0, r = 1e12, ans = r; while (l <= r) { ll mid = (l + r) / 2; if (check(n, mid) <= k) { ans = min(ans, mid), r = mid - 1; } else l = mid + 1; } printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long const int maxn = 200100; int a[maxn], f[maxn]; ll check(int n, ll t) { ll ret = 0; for (int i = 1; i <= n; i++) { ret += max(0ll, a[i] - t / f[n - i + 1]); } return ret; } int main(void) { int n; ll k; scanf("%d%lld", &n, &k); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= n; i++) scanf("%d", &f[i]); sort(a + 1, a + n + 1); sort(f + 1, f + n + 1); ll l = 0, r = 1e12, ans = r; while (l <= r) { ll mid = (l + r) / 2; if (check(n, mid) <= k) { ans = min(ans, mid), r = mid - 1; } else l = mid + 1; } printf("%lld\n", ans); return 0; }
replace
3
4
3
4
0
p02883
C++
Runtime Error
#include <algorithm> #include <iostream> using namespace std; int N_MAX = 20000; int main() { long long a[N_MAX], f[N_MAX]; long long n, k, i, t, s = 0, p, l = 0, r = 0; cin >> n >> k; for (i = 0; i < n; i++) { cin >> a[i]; s += a[i]; } for (i = 0; i < n; i++) cin >> f[i]; if (k >= s) { cout << "0" << endl; return 0; } sort(a, a + n); sort(f, f + n, greater<long long>()); for (i = 0; i < n; i++) { t = a[i] * f[i]; r = max(t, r); } while (r > l + 1) { t = 0; p = (l + r) / 2; for (i = 0; i < n; i++) t += max(a[i] - p / f[i], (long long)0); if (t <= k) r = p; else l = p; } cout << r << endl; return 0; }
#include <algorithm> #include <iostream> using namespace std; int N_MAX = 200000; int main() { long long a[N_MAX], f[N_MAX]; long long n, k, i, t, s = 0, p, l = 0, r = 0; cin >> n >> k; for (i = 0; i < n; i++) { cin >> a[i]; s += a[i]; } for (i = 0; i < n; i++) cin >> f[i]; if (k >= s) { cout << "0" << endl; return 0; } sort(a, a + n); sort(f, f + n, greater<long long>()); for (i = 0; i < n; i++) { t = a[i] * f[i]; r = max(t, r); } while (r > l + 1) { t = 0; p = (l + r) / 2; for (i = 0; i < n; i++) t += max(a[i] - p / f[i], (long long)0); if (t <= k) r = p; else l = p; } cout << r << endl; return 0; }
replace
3
4
3
4
0
p02883
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int maxV = 90010; const int maxN = 2e5 + 10; const int MOD = 1e9 + 7; const ll INF = 1000000000000000010LL; const int inf = 1e9 + 10; #define X first; #define Y second; ll a[maxN]; ll f[maxN]; int n; bool check(ll x, ll k) { for (int i = 1; i <= n; i++) { if (a[i] * f[i] > x) { ll cnt = (a[i] * f[i] - x); if (cnt % f[i] == 0) { cnt /= f[i]; } else { cnt = cnt / f[i] + 1; } if (k >= cnt) { k -= cnt; } else return false; } } if (k >= 0) return true; else return false; } int main() { ll k; scanf("%d %lld", &n, &k); for (int i = 1; i <= n; i++) { scanf("%lld", &a[i]); } for (int i = 1; i <= n; i++) { scanf("%lld", &f[i]); } sort(a + 1, a + 1 + n); sort(f + 1, f + 1 + n); reverse(f + 1, f + 1 + n); ll R = 0; for (int i = 1; i <= n; i++) { R = max(a[i] * f[i], R); } ll L = 0; ll ans = 0; while (L <= R) { int mid = (L + R) / 2; if (check(mid, k)) { ans = mid; R = mid - 1; } else { L = mid + 1; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int maxV = 90010; const int maxN = 2e5 + 10; const int MOD = 1e9 + 7; const ll INF = 1000000000000000010LL; const int inf = 1e9 + 10; #define X first; #define Y second; ll a[maxN]; ll f[maxN]; int n; bool check(ll x, ll k) { for (int i = 1; i <= n; i++) { if (a[i] * f[i] > x) { ll cnt = (a[i] * f[i] - x); if (cnt % f[i] == 0) { cnt /= f[i]; } else { cnt = cnt / f[i] + 1; } if (k >= cnt) { k -= cnt; } else return false; } } if (k >= 0) return true; else return false; } int main() { ll k; scanf("%d %lld", &n, &k); for (int i = 1; i <= n; i++) { scanf("%lld", &a[i]); } for (int i = 1; i <= n; i++) { scanf("%lld", &f[i]); } sort(a + 1, a + 1 + n); sort(f + 1, f + 1 + n); reverse(f + 1, f + 1 + n); ll R = 0; for (int i = 1; i <= n; i++) { R = max(a[i] * f[i], R); } ll L = 0; ll ans = 0; while (L <= R) { ll mid = (L + R) / 2; if (check(mid, k)) { ans = mid; R = mid - 1; } else { L = mid + 1; } } cout << ans << endl; return 0; }
replace
57
58
57
58
TLE
p02883
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define pb push_back #define sz(x) (int)x.size() #define all(x) begin(x), end(x) typedef long long ll; const int mn = 1e5 + 5; typedef pair<ll, int> pii; int n; ll k, ans; int a[mn], f[mn]; bool c(ll x) { ll tk = k; for (int i = 1; i <= n; i++) { if (1ll * a[i] * f[i] <= x) continue; int needa = x / f[i]; tk -= (a[i] - needa); } return tk >= 0; } int main() { // cin.sync_with_stdio(0); #ifdef trote freopen("../1.txt", "r", stdin); #endif cin >> n >> k; for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); } sort(a + 1, a + n + 1); for (int i = 1; i <= n; i++) { scanf("%d", &f[i]); } sort(f + 1, f + n + 1, [](int a, int b) { return a > b; }); ll L = 0, R = n * 1000000000000ll, ans = 0; while (L <= R) { ll mid = L + R >> 1; if (c(mid)) R = mid - 1, ans = mid; else L = mid + 1; } printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; #define pb push_back #define sz(x) (int)x.size() #define all(x) begin(x), end(x) typedef long long ll; const int mn = 1e6 + 5; typedef pair<ll, int> pii; int n; ll k, ans; int a[mn], f[mn]; bool c(ll x) { ll tk = k; for (int i = 1; i <= n; i++) { if (1ll * a[i] * f[i] <= x) continue; int needa = x / f[i]; tk -= (a[i] - needa); } return tk >= 0; } int main() { // cin.sync_with_stdio(0); #ifdef trote freopen("../1.txt", "r", stdin); #endif cin >> n >> k; for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); } sort(a + 1, a + n + 1); for (int i = 1; i <= n; i++) { scanf("%d", &f[i]); } sort(f + 1, f + n + 1, [](int a, int b) { return a > b; }); ll L = 0, R = n * 1000000000000ll, ans = 0; while (L <= R) { ll mid = L + R >> 1; if (c(mid)) R = mid - 1, ans = mid; else L = mid + 1; } printf("%lld\n", ans); return 0; }
replace
7
8
7
8
0
p02883
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<vll> vvll; typedef vector<vector<int>> vvi; typedef vector<string> vs; typedef unordered_set<int> si; typedef pair<int, int> pp; typedef vector<pp> vpp; typedef unsigned int i64; #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) #define all(e) (e).begin(), (e).end() #define pb push_back template <typename T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <typename T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <typename T> void printV(vector<T> A) { if (A.empty()) cerr << "EMTPY\n"; else { cerr << "["; for (int i = 0; i < A.size() - 1; ++i) { cerr << A[i] << ", "; } if (A.size()) cerr << A.back() << "]\n"; } } template <typename T> void printVV(vector<vector<T>> A) { cerr << "["; for (auto v : A) { printV<T>(v); } cerr << "]"; } 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...); } const int N = 2e5 + 10; ll members[N], dishes[N]; int main(int argc, char **argv) { ios::sync_with_stdio(false); cin.tie(0); ll n, k; cin >> n >> k; for (int i = 0; i < n; i++) cin >> members[i]; for (int i = 0; i < n; i++) cin >> dishes[i]; sort(members, members + n); sort(dishes, dishes + n); ll begin = 0, end = 0; ll total = 0; for (int i = 0; i < n; i++) { end = max(end, members[i] * dishes[n - i - 1]); total += members[i]; } if (k == 0) { cout << end << endl; return 0; } if (k >= total) { cout << 0 << endl; return 0; } while (begin < end) { ll mid = begin + (end - begin / 2); bool fail = false; ll kk = k; for (int i = 0; i < n; i++) { ll x = members[i]; ll y = dishes[n - i - 1]; if (x * y <= mid) continue; kk -= (x - mid / y); if (kk < 0) { fail = true; break; } } if (fail) begin = mid + 1; else end = mid; } cout << end << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<vll> vvll; typedef vector<vector<int>> vvi; typedef vector<string> vs; typedef unordered_set<int> si; typedef pair<int, int> pp; typedef vector<pp> vpp; typedef unsigned int i64; #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) #define all(e) (e).begin(), (e).end() #define pb push_back template <typename T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <typename T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <typename T> void printV(vector<T> A) { if (A.empty()) cerr << "EMTPY\n"; else { cerr << "["; for (int i = 0; i < A.size() - 1; ++i) { cerr << A[i] << ", "; } if (A.size()) cerr << A.back() << "]\n"; } } template <typename T> void printVV(vector<vector<T>> A) { cerr << "["; for (auto v : A) { printV<T>(v); } cerr << "]"; } 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...); } const int N = 2e5 + 10; ll members[N], dishes[N]; int main(int argc, char **argv) { ios::sync_with_stdio(false); cin.tie(0); ll n, k; cin >> n >> k; for (int i = 0; i < n; i++) cin >> members[i]; for (int i = 0; i < n; i++) cin >> dishes[i]; sort(members, members + n); sort(dishes, dishes + n); ll begin = 0, end = 0; ll total = 0; for (int i = 0; i < n; i++) { end = max(end, members[i] * dishes[n - i - 1]); total += members[i]; } if (k == 0) { cout << end << endl; return 0; } if (k >= total) { cout << 0 << endl; return 0; } while (begin < end) { ll mid = begin + ((end - begin) / 2); bool fail = false; ll kk = k; for (int i = 0; i < n; i++) { ll x = members[i]; ll y = dishes[n - i - 1]; if (x * y <= mid) continue; kk -= (x - mid / y); if (kk < 0) { fail = true; break; } } if (fail) begin = mid + 1; else end = mid; } cout << end << endl; return 0; }
replace
99
100
99
100
TLE
p02883
Python
Time Limit Exceeded
N, K = map(int, input().split()) A = sorted(list(map(int, input().split())), reverse=True) F = sorted(list(map(int, input().split()))) def binary_search(min_n, max_n): while max_n - min_n != 1: tn = (min_n + max_n) // 2 if judge(tn): max_n = tn else: min_n = tn return max_n def judge(tn): k = 0 for i in range(N): if A[i] * F[i] > tn: k += A[i] - (tn // F[i]) if k > K: return False return True def solve(): ans = binary_search(-1, 10**12) print(ans) if __name__ == "__main__": solve()
import sys input = lambda: sys.stdin.readline().rstrip() N, K = map(int, input().split()) A = sorted(list(map(int, input().split())), reverse=True) F = sorted(list(map(int, input().split()))) def binary_search(min_n, max_n): while max_n - min_n != 1: tn = (min_n + max_n) // 2 if judge(tn): max_n = tn else: min_n = tn return max_n def judge(tn): k = 0 for i in range(N): if A[i] * F[i] > tn: k += A[i] - (tn // F[i]) if k > K: return False return True def solve(): ans = binary_search(-1, 10**12) print(ans) if __name__ == "__main__": solve()
insert
0
0
0
4
TLE
p02883
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; #define rep(i, n) for (int i = 0; i < (int)(n); ++i) // cout<<fixed<<setprecision(10); 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; } const int NM = 2 * 1e5; int ar[NM]; int fr[NM]; int main() { int n, k; cin >> n >> k; rep(i, n) { int a; cin >> a; ar[i] = a; // 消化コスト } rep(i, n) { int a; cin >> a; fr[i] = a; // 食べにくさ } sort(ar, ar + n); sort(fr, fr + n, greater<int>()); // へらす ll l = -1; ll r = 1e12; while (l + 1 < r) { ll mid = (l + r) / 2; // bool isOk = [&] { ll s = 0; rep(i, n) { s += max(0ll, ar[i] - mid / fr[i]); } return s <= k; }(); if (isOk) r = mid; else l = mid; } cout << r << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; #define rep(i, n) for (int i = 0; i < (int)(n); ++i) // cout<<fixed<<setprecision(10); 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; } const int NM = 2 * 1e5; int ar[NM]; int fr[NM]; int main() { int n; ll k; cin >> n >> k; rep(i, n) { int a; cin >> a; ar[i] = a; // 消化コスト } rep(i, n) { int a; cin >> a; fr[i] = a; // 食べにくさ } sort(ar, ar + n); sort(fr, fr + n, greater<int>()); // へらす ll l = -1; ll r = 1e12; while (l + 1 < r) { ll mid = (l + r) / 2; // bool isOk = [&] { ll s = 0; rep(i, n) { s += max(0ll, ar[i] - mid / fr[i]); } return s <= k; }(); if (isOk) r = mid; else l = mid; } cout << r << endl; }
replace
29
30
29
31
0
p02883
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef pair<int, int> P; typedef long long ll; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } // 最大公約数 ll gcd(ll x, ll y) { ll tmp = 0; if (x < y) { tmp = x; x = y; y = tmp; } while (y > 0) { ll r = x % y; x = y; y = r; } return x; } // 最大公倍数 ll lcm(ll x, ll y) { return x / gcd(x, y) * y; } const int MAX = 1e6 + 1; const ll MOD = 998244353; long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } struct mint { ll x; // typedef long long ll; mint(ll x = 0) : x((x % MOD + MOD) % MOD) {} mint operator-() const { return mint(-x); } mint &operator+=(const mint a) { if ((x += a.x) >= MOD) x -= MOD; return *this; } mint &operator-=(const mint a) { if ((x += MOD - a.x) >= MOD) x -= MOD; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= MOD; return *this; } mint operator+(const mint a) const { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime MOD mint inv() const { return pow(MOD - 2); } mint &operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res /= a; } }; // 二項係数計算 long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } // 階乗 ll kaijo(ll k) { ll sum = 1; for (ll i = 1; i <= k; ++i) { sum *= i; sum %= 1000000000 + 7; } return sum; } long long modpow(long long a, long long n, long long MOD) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % MOD; a = a * a % MOD; n >>= 1; } return res; } // sieve(MAX);でベクトルIsPrimeに「MAXまでの数値の素数の真偽」を格納する。 struct Sieve { int n; vector<int> f, primes; Sieve(int n = 1) : n(n), f(n + 1) { f[0] = f[1] = -1; for (ll i = 2; i <= n; ++i) { if (f[i]) continue; primes.push_back(i); f[i] = i; for (ll j = i * i; j <= n; j += i) { if (!f[j]) f[j] = i; } } } bool isPrime(int x) { return f[x] == x; } vector<int> factorList(int x) { vector<int> res; while (x != 1) { res.push_back(f[x]); x /= f[x]; } return res; } vector<P> factor(int x) { vector<int> fl = factorList(x); if (fl.size() == 0) return {}; vector<P> res(1, P(fl[0], 0)); for (int p : fl) { if (res.back().first == p) { res.back().second++; } else { res.emplace_back(p, 1); } } return res; } }; struct UnionFind { vector<int> par; UnionFind(int n) : par(n, -1) {} int root(int x) { if (par[x] < 0) return x; else return par[x] = root(par[x]); } bool issame(int x, int y) { return root(x) == root(y); } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (par[x] > par[y]) swap(x, y); // merge technique par[x] += par[y]; par[y] = x; return true; } int size(int x) { return -par[root(x)]; } }; ll count(int n, int a) { ll bunshi = 1; for (int i = 0; i < a; i++) { bunshi *= (n - i); bunshi %= MOD; } ll bunbo = 1; for (int i = 1; i < a + 1; i++) { bunbo *= i; bunbo %= MOD; } bunbo = modpow(bunbo, MOD - 2, MOD); // cout<<(bunshi*bunbo)%MOD<<endl; return (bunshi * bunbo) % MOD; } // 約数列挙。約数をvector<ll>で返す。計算量はsqrt(n)。 vector<ll> divisor(ll n) { vector<ll> ret; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(begin(ret), end(ret)); return (ret); } // ここから開始 const ll INF = 1e18; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; int main() { int N, K; cin >> N >> K; vector<int> a(N); vector<int> f(N); rep(i, N) cin >> a[i]; rep(i, N) cin >> f[i]; sort(f.begin(), f.end()); reverse(f.begin(), f.end()); sort(a.begin(), a.end()); // 二分探索 ll left = -1, right = 1e12; while (right - left > 1) { ll mid = (left + right) / 2; ll tmp = 0; rep(i, N) { tmp += max((ll)0, a[i] - mid / f[i]); } if (tmp <= K) right = mid; else left = mid; } cout << right << endl; // cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef pair<int, int> P; typedef long long ll; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } // 最大公約数 ll gcd(ll x, ll y) { ll tmp = 0; if (x < y) { tmp = x; x = y; y = tmp; } while (y > 0) { ll r = x % y; x = y; y = r; } return x; } // 最大公倍数 ll lcm(ll x, ll y) { return x / gcd(x, y) * y; } const int MAX = 1e6 + 1; const ll MOD = 998244353; long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } struct mint { ll x; // typedef long long ll; mint(ll x = 0) : x((x % MOD + MOD) % MOD) {} mint operator-() const { return mint(-x); } mint &operator+=(const mint a) { if ((x += a.x) >= MOD) x -= MOD; return *this; } mint &operator-=(const mint a) { if ((x += MOD - a.x) >= MOD) x -= MOD; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= MOD; return *this; } mint operator+(const mint a) const { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime MOD mint inv() const { return pow(MOD - 2); } mint &operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res /= a; } }; // 二項係数計算 long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } // 階乗 ll kaijo(ll k) { ll sum = 1; for (ll i = 1; i <= k; ++i) { sum *= i; sum %= 1000000000 + 7; } return sum; } long long modpow(long long a, long long n, long long MOD) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % MOD; a = a * a % MOD; n >>= 1; } return res; } // sieve(MAX);でベクトルIsPrimeに「MAXまでの数値の素数の真偽」を格納する。 struct Sieve { int n; vector<int> f, primes; Sieve(int n = 1) : n(n), f(n + 1) { f[0] = f[1] = -1; for (ll i = 2; i <= n; ++i) { if (f[i]) continue; primes.push_back(i); f[i] = i; for (ll j = i * i; j <= n; j += i) { if (!f[j]) f[j] = i; } } } bool isPrime(int x) { return f[x] == x; } vector<int> factorList(int x) { vector<int> res; while (x != 1) { res.push_back(f[x]); x /= f[x]; } return res; } vector<P> factor(int x) { vector<int> fl = factorList(x); if (fl.size() == 0) return {}; vector<P> res(1, P(fl[0], 0)); for (int p : fl) { if (res.back().first == p) { res.back().second++; } else { res.emplace_back(p, 1); } } return res; } }; struct UnionFind { vector<int> par; UnionFind(int n) : par(n, -1) {} int root(int x) { if (par[x] < 0) return x; else return par[x] = root(par[x]); } bool issame(int x, int y) { return root(x) == root(y); } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (par[x] > par[y]) swap(x, y); // merge technique par[x] += par[y]; par[y] = x; return true; } int size(int x) { return -par[root(x)]; } }; ll count(int n, int a) { ll bunshi = 1; for (int i = 0; i < a; i++) { bunshi *= (n - i); bunshi %= MOD; } ll bunbo = 1; for (int i = 1; i < a + 1; i++) { bunbo *= i; bunbo %= MOD; } bunbo = modpow(bunbo, MOD - 2, MOD); // cout<<(bunshi*bunbo)%MOD<<endl; return (bunshi * bunbo) % MOD; } // 約数列挙。約数をvector<ll>で返す。計算量はsqrt(n)。 vector<ll> divisor(ll n) { vector<ll> ret; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(begin(ret), end(ret)); return (ret); } // ここから開始 const ll INF = 1e18; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; int main() { int N; ll K; cin >> N >> K; vector<int> a(N); vector<int> f(N); rep(i, N) cin >> a[i]; rep(i, N) cin >> f[i]; sort(f.begin(), f.end()); reverse(f.begin(), f.end()); sort(a.begin(), a.end()); // 二分探索 ll left = -1, right = 1e12; while (right - left > 1) { ll mid = (left + right) / 2; ll tmp = 0; rep(i, N) { tmp += max((ll)0, a[i] - mid / f[i]); } if (tmp <= K) right = mid; else left = mid; } cout << right << endl; // cout<<ans<<endl; return 0; }
replace
237
238
237
239
0
p02883
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cout.tie(nullptr); cin.tie(nullptr); int n, k; cin >> n >> k; vector<long long> a(n), d(n); for (int i = 0; i < n; ++i) cin >> a[i]; for (int i = 0; i < n; ++i) cin >> d[i]; sort(a.begin(), a.end()); sort(d.begin(), d.end(), greater<long long>()); auto check = [&](long long x) { long long ret = 0; for (int i = 0; i < n; ++i) { long long cur = x / d[i]; ret += max(0ll, a[i] - cur); } return ret; }; long long l = 0, r = 1e18; while (l < r) { long long mid = (l + r) / 2; if (check(mid) <= k) r = mid; else l = mid + 1; } cout << r << '\n'; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cout.tie(nullptr); cin.tie(nullptr); long long n, k; cin >> n >> k; vector<long long> a(n), d(n); for (int i = 0; i < n; ++i) cin >> a[i]; for (int i = 0; i < n; ++i) cin >> d[i]; sort(a.begin(), a.end()); sort(d.begin(), d.end(), greater<long long>()); auto check = [&](long long x) { long long ret = 0; for (int i = 0; i < n; ++i) { long long cur = x / d[i]; ret += max(0ll, a[i] - cur); } return ret; }; long long l = 0, r = 1e18; while (l < r) { long long mid = (l + r) / 2; if (check(mid) <= k) r = mid; else l = mid + 1; } cout << r << '\n'; }
replace
9
10
9
10
0
p02883
C++
Time Limit Exceeded
#include <algorithm> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <math.h> #include <numeric> #include <queue> #include <stack> #include <string> #include <tuple> #include <vector> using namespace std; typedef long long LL; typedef unsigned long long ULL; typedef vector<LL> VLL; typedef vector<ULL> VULL; typedef vector<VLL> VVLL; class Large_Integer { private: // n進数 static const LL shinsuu = 7; // 符号付絶対値で表現 LL sign; VLL numbers; // 補数表現された整数の足し算 static VLL plusVector(VLL a, VLL b) { VLL ans(max(a.size(), b.size()), 0); for (LL i = 0; i < ans.size(); i++) { if (i < a.size()) ans[i] += a[i]; if (i < b.size()) ans[i] += b[i]; if (i + 1 < ans.size()) { ans[i + 1] += (ans[i] / Large_Integer::shinsuu); } ans[i] %= Large_Integer::shinsuu; } return ans; } // 符号付絶対値を補数表現に変換 static VLL ToVLL(Large_Integer const &a, LL const &min) { LL i; VLL ans; if (a.sign == 1) { ans = VLL(max(min, (LL)a.numbers.size()) + 5, 0); for (i = 0; i < a.numbers.size(); i++) { ans[i] += a.numbers[i]; } } else { ans = VLL(max(min, (LL)a.numbers.size()) + 5, Large_Integer::shinsuu - 1); for (i = 0; i < a.numbers.size(); i++) { ans[i] -= a.numbers[i]; } ans = Large_Integer::plusVector(ans, VLL(1, 1)); } return ans; } // 補数表現を符号付き絶対値に変換 static Large_Integer ToInteger(VLL const &a) { Large_Integer ans; LL i, j, k, n; n = a.size(); if (a[n - 1] == Large_Integer::shinsuu - 1) { auto temp = VLL(n, Large_Integer::shinsuu - 1); temp = Large_Integer::plusVector(a, temp); // ここから for (i = 0; i < temp.size(); i++) { temp[i] -= Large_Integer::shinsuu; temp[i] *= -1; } ans.sign = -1; ans.numbers = temp; ans.Syusei(); } else { ans.sign = 1; ans.numbers = a; ans.Syusei(); } return ans; } // シフト演算子 Large_Integer operator<<(Large_Integer const &a) const { LL shift = a.to_LongLong(), i; if (shift < 0) { return *this >> (shift * -1); } Large_Integer ans = *this; ans.numbers = VLL(this->numbers.size() + shift, 0); for (i = 0; i < this->numbers.size(); i++) { ans.numbers[i + shift] += this->numbers[i]; } ans.Syusei(); return ans; } Large_Integer operator>>(Large_Integer const &a) const { LL shift = a.to_LongLong(), i; if (shift < 0) { return *this << (shift * -1); } Large_Integer ans = *this; ans.numbers = VLL(max((LL)0, (LL)this->numbers.size() - shift), 0); for (i = 0; i < this->numbers.size(); i++) { if (i - shift >= 0) { ans.numbers[i - shift] = this->numbers[i]; } } ans.Syusei(); return ans; } // 掛け算(long long) Large_Integer operator*(LL const &b) const { Large_Integer ans; ans.sign = this->sign; ans.numbers = VLL(this->numbers.size() + 2, 0); LL i, a = b; if (a < 0) { a *= -1; ans.sign *= -1; } for (i = 0; i < this->numbers.size(); i++) { ans.numbers[i] = a * this->numbers[i]; } for (i = 0; i < ans.numbers.size(); i++) { if (i + 1 < ans.numbers.size()) { ans.numbers[i + 1] = (ans.numbers[i] / Large_Integer::shinsuu); } ans.numbers[i] %= Large_Integer::shinsuu; } return ans; } // 誤りの検知と修正 void Syusei() { LL i, j, k; if (abs(this->sign) != 1) { j = 0; j = 1 / j; } k = 0; for (i = 0; i < this->numbers.size(); i++) { if (this->numbers[i] < 0) { j = 0; j = 1 / j; } if (i + 1 < this->numbers.size()) { this->numbers[i + 1] += (this->numbers[i] / Large_Integer::shinsuu); } this->numbers[i] %= Large_Integer::shinsuu; if (this->numbers[i] > 0) k = i + 1; } VLL ans(k, 0); for (i = 0; i < k; i++) { ans[i] = this->numbers[i]; } this->numbers = ans; if (this->sign == -1 && this->numbers.size() == 0) { this->sign = 1; } } public: // コンストラクタたち Large_Integer(Large_Integer const &b) { *this = b; } Large_Integer(LL const &b) { if (b < 0) this->sign = -1; else this->sign = 1; auto c = abs(b); while (c > 0) { this->numbers.push_back(c % this->shinsuu); c /= this->shinsuu; } this->Syusei(); } Large_Integer() { this->sign = 1; this->numbers = VLL(0); } // long long型に変換する LL to_LongLong() const { LL ans = 0, i; for (i = this->numbers.size() - 1; i >= 0; i--) { ans *= this->shinsuu; ans += this->numbers[i]; } ans *= this->sign; return ans; } // 代入演算子 Large_Integer operator=(Large_Integer const &b) { this->sign = b.sign; this->numbers = b.numbers; return *this; } // 足し算 Large_Integer operator+(Large_Integer const &b) const { LL i, j; VLL x, y; LL size = max(this->numbers.size(), b.numbers.size()); x = Large_Integer::ToVLL(*this, size); y = Large_Integer::ToVLL(b, size); x = Large_Integer::plusVector(x, y); auto ans = Large_Integer::ToInteger(x); ans.Syusei(); return ans; } Large_Integer operator+=(Large_Integer const &b) { return *this = (*this + b); } // 掛け算 Large_Integer operator*(Large_Integer const &b) const { Large_Integer ans = 0; LL i; for (i = 0; i < b.numbers.size(); i++) { ans += ((*this * b.numbers[i]) << i); } return ans; } Large_Integer operator*=(Large_Integer const &b) { return *this = (*this * b); } Large_Integer operator-(Large_Integer const &b) const { return *this + (b * -1); } Large_Integer operator-=(Large_Integer const &b) { return *this = (*this - b); } // 未完成 bool operator<(Large_Integer const &b) const { LL i, j, k; if (this->sign < b.sign) { return true; } if (this->sign > b.sign) { return false; } if (this->sign == 1) { if (this->numbers.size() < b.numbers.size()) { return true; } if (this->numbers.size() > b.numbers.size()) { return false; } for (i = this->numbers.size() - 1; i >= 0; i--) { if (this->numbers[i] < b.numbers[i]) { return true; } if (this->numbers[i] > b.numbers[i]) { return false; } } } } }; // 改良vector template <typename T> class ArrayList : public vector<T> { public: ArrayList(long long const &size, T const &a) : vector<T>(size, a) {} ArrayList(long long const &size) : vector<T>(size) {} ArrayList() : vector<T>() {} T &operator[](long long const &index) { return vector<T>::at(index); } }; typedef ArrayList<LL> ALL; typedef ArrayList<ALL> AALL; // 剰余整数 class ModInt { private: LL n; static LL modP; public: ModInt(ModInt const &b) { this->n = b.n; } ModInt(LL const &b) { this->n = b % ModInt::modP; } ModInt() { *this = ModInt(0); } LL GetMod() const { return ModInt::modP; } void SetMod(LL const &a) { ModInt::modP = abs(a); } LL getNumber() const { return this->n; } ModInt operator=(ModInt const &b) { this->n = b.n; return *this; } ModInt operator+(ModInt const &b) const { return ModInt(this->n + b.n); } ModInt operator+=(ModInt const &b) { return *this = (*this + b); } ModInt operator-(ModInt const &b) const { LL temp = this->n - b.n + ModInt::modP; return ModInt(temp); } ModInt operator-=(ModInt const &b) { return *this = (*this - b); } ModInt operator*(ModInt const &b) const { LL temp = this->n * b.n; return ModInt(temp); } ModInt operator*=(ModInt const &b) { return *this = (*this * b); } ModInt Pow(ModInt const &b) const { LL p = b.n; ModInt ans = 1; ModInt x = *this; while (p > 0) { if (p % 2 == 1) { ans *= x; } x = x * x; p /= 2; } return ans; } ModInt operator/(ModInt const &b) const { ModInt temp = b.Pow(ModInt::modP - 2); return *this * temp; } ModInt operator/=(ModInt const &b) { return *this = (*this / b); } }; LL ModInt::modP = 1000 * 1000 * 1000 + 7; // 関数詰め合わせ class KyoPro { public: static const LL MOD_CONST = (LL)1000 * 1000 * 1000 + 7; static LL DebugFlag; // 数値を区切って文字列にする static string MakeString_LongLong(vector<long long> const &numbers, string const &str) { if (numbers.size() == 0) return ""; string result = "" + to_string(numbers[0]); for (long long i = 1; i < numbers.size(); i++) { result += str; result += to_string(numbers[i]); } return result; } // 空白で区切る為のオーバーロード static string MakeString_LongLong(vector<long long> const &numbers) { if (numbers.size() == 0) return ""; string result = "" + to_string(numbers[0]); for (long long i = 1; i < numbers.size(); i++) { result += " "; result += to_string(numbers[i]); } return result; } // 文字列の配列を改行を挟んでまとめる static string MakeString_VectorString(vector<string> const &str) { string result = ""; for (long long i = 0; i < str.size(); i++) { result += str[i] + "\n"; } return result; } // 文字列を必要な個数だけ読み取る static vector<string> MyReadLineSplit(LL n) { vector<string> str(n); for (long long i = 0; i < n; i++) { std::cin >> str[i]; } return str; } // 数値を必要な個数だけ読み取る static vector<long long> ReadInts(long long number) { vector<long long> a(number); for (int i = 0; i < number; i++) { std::cin >> a[i]; } return a; } // 渡された自然数が素数ならtureを返す static bool PrimeCheck_Int(long long number) { if (number < 2) return false; for (ULL i = 2; i * i <= number; i++) { if (number % i == 0) return false; } return true; } // 自然数が平方数か判定する static bool SquareCheck(LL const &number) { if (KyoPro::PrimeCheck_Int(number)) return false; LL m = number; for (LL i = 2; i <= m; i++) { if (m % i == 0) { LL count = 0; while (m % i == 0) { m /= i; count++; } if (count % 2 == 1) return false; } } return true; } // 渡された数値以下の素数表を作る static vector<long long> MakePrimeList(long long n) { vector<long long> list; LL i, j, p; bool flag; for (i = 2; i <= n; i++) { flag = true; for (j = 0; j < list.size(); j++) { if (!(list[j] * list[j] <= i)) break; if (i % list[j] == 0) { flag = false; break; } } if (flag) list.push_back(i); } return list; } // 文字列の分割 static vector<string> split(string const &str, char sep) { vector<std::string> v; // 分割結果を格納するベクター auto first = str.begin(); // テキストの最初を指すイテレータ while (first != str.end()) { // テキストが残っている間ループ auto last = first; // 分割文字列末尾へのイテレータ while (last != str.end() && *last != sep) // 末尾 or セパレータ文字まで進める last++; v.push_back(string(first, last)); // 分割文字を出力 if (last != str.end()) last++; first = last; // 次の処理のためにイテレータを設定 } return v; } // 合計を求める template <typename T> static LL Sum(T const &a) { LL sum = 0; auto itr = a.begin(); while (itr != a.end()) { sum += (*itr); itr++; } return sum; } // 小文字ならtrueを返す static bool Komoji(char a) { if (a >= 'a' && a <= 'z') return true; return false; } // 大文字ならtrueを返す static bool Oomoji(char a) { if (a >= 'A' && a <= 'Z') return true; return false; } // 切り上げの整数値割り算 static LL KiriageWarizan(LL a, LL b) { LL result = a / b; if (a % b > 0) result++; return result; } // 最大公約数を求める static LL GreatestCommonFactor(LL a, LL b) { a = KyoPro::abs(a); b = KyoPro::abs(b); LL temp; if (a < b) { temp = b; b = a; a = temp; } while (b > 0) { temp = a % b; a = b; b = temp; } return a; } // 最小公倍数を求める static LL LeastCommonMultiple(LL a, LL b) { return (a / GreatestCommonFactor(a, b)) * b; } // 二次元配列を行列とみなして転置する static VVLL VVLLturn(VVLL a) { if (a.size() == 0) return VVLL(0); VVLL result(a[0].size(), VLL(a.size())); LL i, j; for (i = 0; i < a.size(); i++) { for (j = 0; j < a[0].size(); j++) { result[j][i] = a[i][j]; } } return result; } // 素因数分解、素数、指数の順 static vector<VLL> PrimeFactorization(LL n) { VLL p_list, s_list; LL i, j, k, count; for (i = 2; n > 1; i++) { if (i * i > n) { p_list.push_back(n); s_list.push_back(1); break; } if (n % i == 0) { count = 0; while (n % i == 0) { n /= i; count++; } p_list.push_back(i); s_list.push_back(count); } } vector<VLL> result; result.push_back(p_list); result.push_back(s_list); return KyoPro::VVLLturn(result); } // 整数nの約数の配列を作る static VLL MakeYakusuList(LL n) { auto primes = KyoPro::PrimeFactorization(n); VLL ans; VLL roop(primes.size(), 0); LL i, j, k, m, size = roop.size(); while (true) { LL a = 1; for (i = 0; i < size; i++) { for (j = 0; j < roop[i]; j++) { a *= primes[i][0]; } } ans.push_back(a); roop[0]++; for (i = 0; i < size; i++) { if (i + 1 < size) { roop[i + 1] += (roop[i] / (primes[i][1] + 1)); } roop[i] %= (primes[i][1] + 1); } bool flag = true; for (i = 0; i < size; i++) { if (roop[i] != 0) flag = false; } if (flag) break; } return KyoPro::Sort(ans); } // 組み合わせ nCrを10^9+7で割った余りを返す static LL Combination(LL n, LL r) { ModInt ans = 1; r = min(r, n - r); for (LL i = 0; i < r; i++) { ans *= (n - i); ans /= (i + 1); } return ans.getNumber(); } // 順列 nPrを10^9+7で割った余りを返す static LL Permutation(LL n, LL r) { ModInt ans = 1; for (LL i = 0; i < r; i++) { ans *= (n - i); } return ans.getNumber(); } // 重複組み合わせ。n種類からr個重複を許して選ぶ static LL nHr(LL n, LL r) { return KyoPro::Combination(n + r - 1, r); } template <typename T> static T pow(T const &a, LL const &b) { T ans = 1; auto p = b; auto x = a; while (p > 0) { if (p % 2 == 1) { ans *= x; } x = x * x; p /= 2; } return ans; } // 符号 template <typename T> static T sign(T const &x) { if (x > 0) return 1; if (x < 0) return -1; return 0; } // 絶対値 template <typename T> static T abs(T x) { if (x < 0) { x = x * -1; } return x; } // 円周率 static double PI() { return (double)3.1415926535898; } // 指定した桁でdoubleを出す。改行はしない。 static void CoutDoubleKeta(double a, LL keta) { cout << setprecision(keta) << a << flush; } // コンテナクラスの出力 template <typename T> static T CoutVector(T const &ls) { LL i, j, k, size = distance(ls.begin(), ls.end()); if (size == 0) return ls; auto itr = ls.begin(); for (i = 0; i < size - 1; i++) { cout << *itr << " " << flush; itr++; } cout << *itr << flush; return ls; } // コンテナクラスをソートする template <typename T> static T Sort(T &ls) { sort(ls.begin(), ls.end()); return ls; } // 順序関数付きでコンテナクラスをソートする template <typename T, typename F> static T Sort(T &ls, F const &func) { sort(ls.begin(), ls.end(), func); return ls; } // コンテナクラスを逆順に並び替える template <typename T> static T Reverse(T &ls) { reverse(ls.begin(), ls.end()); return ls; } // コンテナクラスの条件を満たす要素を数え上げる。bool func(S x) template <typename T, typename S> static LL Count(T const &ls, S func) { LL ans = 0; auto itr = ls.begin(); while (itr != ls.end()) { if (func(*itr)) ans++; itr++; } return ans; } // コンテナクラスの要素をすべて更新する。S func(S x) template <typename T, typename S> static T AllUpdate(T &ls, S func) { auto itr = ls.begin(); while (itr != ls.end()) { *itr = func(*itr); itr++; } return ls; } // リストをベクターに変換する template <typename T> static vector<T> FromListToVector(list<T> const &a) { vector<T> ans; for (auto itr = a.begin(); itr != a.end(); itr++) { ans.push_back(*itr); } return ans; } // ベクターをリストに変換する template <typename T> static list<T> FromVectorToList(vector<T> a) { list<T> ans; for (auto itr = a.begin(); itr != a.end(); itr++) { ans.push_back(*itr); } return ans; } // 最大値の要素番号を求める template <typename T> static LL MaxElementIndex(T const &ls) { return distance(ls.begin(), max_element(ls.begin(), ls.end())); } // 最小値の要素番号を求める template <typename T> static LL MinElementIndex(T const &ls) { return distance(ls.begin(), min_element(ls.begin(), ls.end())); } // デバッグ用出力 template <typename T> static LL DebugPrintf(T output) { if (KyoPro::DebugFlag) { std::cout << output << endl; } return KyoPro::DebugFlag; } // デバッグ用入力 static LL DebugCin() { LL a; if (KyoPro::DebugFlag) { cin >> a; } return a; } }; LL KyoPro::DebugFlag = 0; // 累積和を求めるクラス class Ruisekiwa { private: vector<LL> list; public: void MakeArray(vector<LL> data) { LL i; list = data; list.push_back(0); list[0] = 0; for (i = 1; i < list.size(); i++) { list[i] = list[i - 1] + data[i - 1]; } } LL Sum(LL start, LL end) { if (end < start) { std::cout << "startがendより大きいです"; return 0; } if (start < 0 || end >= list.size()) { std::cout << "範囲が異常"; return 0; } return list[end] - list[start]; } }; // n進数を管理するクラス class N_Number { public: N_Number(LL n, LL keta) { this->N_Shinsuu = n; VLL temp(keta, 0); this->numbers = temp; } // 数を足す void plus(LL a) { if (a < 0) { a *= (-1); this->minus(a); return; } this->numbers[0] += a; LL size = this->numbers.size(); for (LL i = 0; i < size; i++) { if (i + 1 < size) { this->numbers[i + 1] += this->numbers[i] / this->N_Shinsuu; } this->numbers[i] %= this->N_Shinsuu; } } // 全ての桁が同じ数字になっていればその数字を返す。それ以外の場合は -1 を返す LL check() { LL a = this->numbers[0]; for (LL i = 0; i < this->numbers.size(); i++) { if (this->numbers[i] != a) return -1; } return a; } LL getNumber(LL keta) { return this->numbers[keta]; } LL getKeta() { return this->numbers.size(); } LL getShinsuu() { return this->N_Shinsuu; } void setNumber(LL keta, LL number) { if (0 <= number && number < this->getShinsuu()) { if (0 <= keta && keta < this->getKeta()) { this->numbers[keta] = number; return; } } cout << "er" << endl; } void setAllNumbers(LL number) { LL size = this->getKeta(), i; for (i = 0; i < size; i++) { this->setNumber(i, number); } } string to_string_KetaSoroe() { string s = ""; for (LL i = this->getKeta() - 1; i >= 0; i--) { s += to_string(this->getNumber(i)); } return s; } private: void minus(LL a) { LL i, j, k, zettaiti = abs(a); k = KyoPro::KiriageWarizan(zettaiti, this->N_Shinsuu); j = k * (this->N_Shinsuu - 1); for (i = 0; i < this->getKeta(); i++) { this->numbers[i] += j; } this->numbers[0] += k - a; this->plus(0); } VLL numbers; LL N_Shinsuu; }; // UnionFind class Union_Find { private: VLL tree; VLL count; LL root(LL a) { if (this->tree[a] == a) return a; return this->tree[a] = this->root(this->tree[a]); } public: Union_Find(LL n) { VLL set(n); this->tree = set; this->count = set; for (LL i = 0; i < n; i++) { this->tree[i] = i; this->count[i] = 1; } } void unite(LL a, LL b) { LL x, y; if (!this->Check(a, b)) { x = this->getCount(a) + getCount(b); y = this->root(a); this->count[y] = x; y = this->root(b); this->count[y] = x; } x = this->root(a); y = this->root(b); this->tree[x] = y; } bool Check(LL a, LL b) { return this->root(a) == this->root(b); } LL getCount(LL index) { LL temp = this->root(index); return this->count[temp]; } LL getRoot(LL index) { return this->root(index); } VLL getList() { VLL ans(this->tree.size(), 0); for (LL i = 0; i < ans.size(); i++) { ans[i] = this->root(i); } return ans; } }; // プラスマイナス無限に対応したlong long型 class INF_LONG_LONG { private: LL inf, n; public: // コンストラクタ INF_LONG_LONG(LL a) { this->n = a; this->inf = 0; this->Syusei(); } INF_LONG_LONG() { *this = INF_LONG_LONG(0); } INF_LONG_LONG(INF_LONG_LONG const &a) { this->n = a.n; this->inf = a.inf; this->Syusei(); } // ゲッター LL getN() const { return this->n; } LL getInf() const { return this->inf; } // 正の無限大生成 static INF_LONG_LONG plus_inf() { INF_LONG_LONG a; a.n = 0; a.inf = 1; a.Syusei(); return a; } // 負の無限大生成 static INF_LONG_LONG minus_inf() { INF_LONG_LONG a; a.n = 0; a.inf = -1; a.Syusei(); return a; } // 符号を取得 LL sign() const { if (this->inf != 0) { return this->inf; } return KyoPro::sign(this->n); } // 代入演算子 INF_LONG_LONG operator=(INF_LONG_LONG const &b) { this->n = b.n; this->inf = b.inf; this->Syusei(); return *this; } INF_LONG_LONG operator=(LL const &b) { *this = INF_LONG_LONG(b); this->Syusei(); return *this; } // 比較演算子 bool operator==(INF_LONG_LONG const &b) const { if (this->n == b.n && this->inf == b.inf) return true; return false; } bool operator!=(INF_LONG_LONG const &b) const { return !(*this == b); } bool operator<(INF_LONG_LONG const &b) const { if (this->inf < b.inf) return true; if (this->inf > b.inf) return false; return this->n < b.n; } bool operator>(INF_LONG_LONG const &b) const { return b < *this; } bool operator<=(INF_LONG_LONG const &b) const { return !(*this > b); } bool operator>=(INF_LONG_LONG const &b) const { return !(*this < b); } // 算術演算子 INF_LONG_LONG operator+(INF_LONG_LONG const &b) const { if (max(this->inf, b.inf) > 0) return INF_LONG_LONG::plus_inf(); if (min(this->inf, b.inf) < 0) return INF_LONG_LONG::minus_inf(); auto ans = *this; ans.n += b.n; ans.Syusei(); return ans; } INF_LONG_LONG operator*(INF_LONG_LONG const &b) const { if (*this == INF_LONG_LONG(0) || b == INF_LONG_LONG(0)) { return INF_LONG_LONG(0); } if (this->inf != 0 || b.inf != 0) { LL s = this->sign() * b.sign(); INF_LONG_LONG ans(0); ans.n = 0; ans.inf = s; ans.Syusei(); return ans; } INF_LONG_LONG ans(0); ans.n = this->n * b.n; ans.Syusei(); return ans; } INF_LONG_LONG operator-(INF_LONG_LONG const &b) const { auto ans = (*this + (INF_LONG_LONG(-1) * b)); ans.Syusei(); return ans; } INF_LONG_LONG operator/(INF_LONG_LONG const &b) const { if (b == INF_LONG_LONG(0)) { LL a = this->n / b.n; return INF_LONG_LONG(a); } if (b.inf != 0) { return INF_LONG_LONG(0); } if (*this == INF_LONG_LONG(0)) { return INF_LONG_LONG(0); } if (this->inf != 0) { LL s = this->sign() * b.sign(); return INF_LONG_LONG::plus_inf() * INF_LONG_LONG(s); } INF_LONG_LONG ans; ans.n = this->n / b.n; ans.Syusei(); return ans; } INF_LONG_LONG operator%(INF_LONG_LONG const &b) const { if (this->inf == 0 && b.inf == 0) { INF_LONG_LONG ans; ans.n = this->n % b.n; ans.Syusei(); return ans; } auto x = *this / b; x.Syusei(); auto ans = *this - b * x; ans.Syusei(); return ans; } // 複合代入演算子 INF_LONG_LONG operator+=(INF_LONG_LONG const &b) { auto ans = *this + b; *this = ans; return *this; } INF_LONG_LONG operator-=(INF_LONG_LONG const &b) { auto ans = *this - b; *this = ans; return *this; } INF_LONG_LONG operator*=(INF_LONG_LONG const &b) { auto ans = *this * b; *this = ans; return *this; } INF_LONG_LONG operator/=(INF_LONG_LONG const &b) { auto ans = *this / b; *this = ans; return *this; } INF_LONG_LONG operator%=(INF_LONG_LONG const &b) { auto ans = *this % b; *this = ans; return *this; } // 符号演算子 INF_LONG_LONG operator+() const { return *this; } INF_LONG_LONG operator-() const { return *this * INF_LONG_LONG(-1); } // 前置きインクリメント・デクリメント INF_LONG_LONG operator++() { this->n++; this->Syusei(); return *this; } INF_LONG_LONG operator--() { this->n--; this->Syusei(); return *this; } // 後置きインクリメント・デクリメント INF_LONG_LONG operator++(int) { auto copy = *this; ++(*this); return copy; } INF_LONG_LONG operator--(int) { auto copy = *this; --(*this); return copy; } // 文字列への変換 string ToString() const { if (this->inf == 1) { return "+INF"; } if (this->inf == -1) { return "-INF"; } return to_string(this->n); } private: void Syusei() { if (this->inf != 0) { this->n = 0; } } }; typedef INF_LONG_LONG ILL_TYPE; typedef vector<ILL_TYPE> VILL_TYPE; typedef vector<VILL_TYPE> VVILL_TYPE; // ワーシャルフロイド class WarshallFloyd { public: // 最短距離を記録 VVILL_TYPE d; // 頂点数 LL v; // vは頂点数、edge_cost_listは辺の情報{始点、終点、コスト}の配列。無向グラフの場合、逆矢印の辺に注意。 WarshallFloyd(LL v, VVLL edge_cost_list) { this->v = v; this->d = VVILL_TYPE(v, VILL_TYPE(v, ILL_TYPE::plus_inf())); LL i, j, k, a, b, c; for (i = 0; i < edge_cost_list.size(); i++) { a = edge_cost_list[i][0]; b = edge_cost_list[i][1]; c = edge_cost_list[i][2]; this->d[a][b] = ILL_TYPE(c); } for (i = 0; i < v; i++) { this->d[i][i] = ILL_TYPE(0); } // ここから計算 for (k = 0; k < v; k++) { for (i = 0; i < v; i++) { for (j = 0; j < v; j++) { d[i][j] = min(d[i][j], d[i][k] + d[k][j]); } } } } }; // ベルマンフォード class BellmanFord { public: // 辺のリスト VVILL_TYPE edge; // 頂点数、辺数 LL v, e; // 始点 LL s; // 最短距離 VILL_TYPE d; // vは頂点数、startは始点、edge_cost_listは辺の情報{始点、終点、コスト}の配列。 BellmanFord(LL v, LL start, VVLL edge_cost_list) { this->v = v; this->s = start; this->e = edge_cost_list.size(); this->d = VILL_TYPE(v, ILL_TYPE::plus_inf()); this->d[start] = 0; LL i, j, k; for (i = 0; i < this->e; i++) { VILL_TYPE temp; LL a, b, c; a = edge_cost_list[i][0]; b = edge_cost_list[i][1]; c = edge_cost_list[i][2]; temp.push_back(ILL_TYPE(a)); temp.push_back(ILL_TYPE(b)); temp.push_back(ILL_TYPE(c)); this->edge.push_back(temp); } this->DoUpdata(); auto cpy = this->d; this->DoUpdata(); for (i = 0; i < this->d.size(); i++) { if (this->d[i] != cpy[i]) { this->d[i] = ILL_TYPE::minus_inf(); } } this->DoUpdata(); } private: void DoUpdata() { LL i, j, k; for (i = 0; i <= this->v; i++) { bool update = true; for (j = 0; j < this->e; j++) { ILL_TYPE c; LL a, b; a = this->edge[j][0].getN(); b = this->edge[j][1].getN(); c = this->edge[j][2]; if (this->d[a] < ILL_TYPE::plus_inf()) { if (this->d[a] + c < this->d[b]) { update = false; this->d[b] = this->d[a] + c; } } } if (update) break; } } }; // ダイクストラ class Dijkstra { public: Dijkstra(LL v, LL start, VVLL edge_cost_list) {} }; // ライブラリはここまで // ここから下を書く bool isNotOver(LL n, LL k, VLL const &a, VLL const &f, LL g) { if (g < 0) { return false; } VVLL pair(n, VLL(3, 0)); for (LL i = 0; i < n; i++) { pair[i][0] = a[i]; pair[i][1] = f[i]; pair[i][2] = a[i] * f[i]; } KyoPro::Sort(pair, [](VLL x, VLL y) { return x[2] < y[2]; }); KyoPro::Reverse(pair); for (LL i = 0; i < n; i++) { LL d = pair[i][2] - g; if (d <= 0) { continue; } LL e = KyoPro::KiriageWarizan(d, pair[i][1]); LL temp = min(e, k); k -= temp; pair[i][0] -= temp; pair[i][2] = pair[i][0] * pair[i][1]; if (pair[i][2] > g) { return false; } } return true; } // ここからメイン int main(void) { KyoPro::DebugFlag = 0; LL n, k; cin >> n >> k; auto a = KyoPro::ReadInts(n); auto f = KyoPro::ReadInts(n); KyoPro::Sort(a); KyoPro::Sort(f); KyoPro::Reverse(f); LL mn = 0, mx = KyoPro::pow((LL)10, 12) + 1; while (mn < mx) { LL c = mn + mx; c /= 2; string s = ""; bool b1 = isNotOver(n, k, a, f, c); bool b2 = isNotOver(n, k, a, f, c - 1); s = s + to_string(b1) + " " + to_string(b2) + " " + to_string(c); KyoPro::DebugPrintf(s); if (b1 && !b2) { cout << c << endl; return 0; } else if (b2) { mx = c - 1; } else { mn = c + 1; } } cout << mn << endl; return 0; }
#include <algorithm> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <math.h> #include <numeric> #include <queue> #include <stack> #include <string> #include <tuple> #include <vector> using namespace std; typedef long long LL; typedef unsigned long long ULL; typedef vector<LL> VLL; typedef vector<ULL> VULL; typedef vector<VLL> VVLL; class Large_Integer { private: // n進数 static const LL shinsuu = 7; // 符号付絶対値で表現 LL sign; VLL numbers; // 補数表現された整数の足し算 static VLL plusVector(VLL a, VLL b) { VLL ans(max(a.size(), b.size()), 0); for (LL i = 0; i < ans.size(); i++) { if (i < a.size()) ans[i] += a[i]; if (i < b.size()) ans[i] += b[i]; if (i + 1 < ans.size()) { ans[i + 1] += (ans[i] / Large_Integer::shinsuu); } ans[i] %= Large_Integer::shinsuu; } return ans; } // 符号付絶対値を補数表現に変換 static VLL ToVLL(Large_Integer const &a, LL const &min) { LL i; VLL ans; if (a.sign == 1) { ans = VLL(max(min, (LL)a.numbers.size()) + 5, 0); for (i = 0; i < a.numbers.size(); i++) { ans[i] += a.numbers[i]; } } else { ans = VLL(max(min, (LL)a.numbers.size()) + 5, Large_Integer::shinsuu - 1); for (i = 0; i < a.numbers.size(); i++) { ans[i] -= a.numbers[i]; } ans = Large_Integer::plusVector(ans, VLL(1, 1)); } return ans; } // 補数表現を符号付き絶対値に変換 static Large_Integer ToInteger(VLL const &a) { Large_Integer ans; LL i, j, k, n; n = a.size(); if (a[n - 1] == Large_Integer::shinsuu - 1) { auto temp = VLL(n, Large_Integer::shinsuu - 1); temp = Large_Integer::plusVector(a, temp); // ここから for (i = 0; i < temp.size(); i++) { temp[i] -= Large_Integer::shinsuu; temp[i] *= -1; } ans.sign = -1; ans.numbers = temp; ans.Syusei(); } else { ans.sign = 1; ans.numbers = a; ans.Syusei(); } return ans; } // シフト演算子 Large_Integer operator<<(Large_Integer const &a) const { LL shift = a.to_LongLong(), i; if (shift < 0) { return *this >> (shift * -1); } Large_Integer ans = *this; ans.numbers = VLL(this->numbers.size() + shift, 0); for (i = 0; i < this->numbers.size(); i++) { ans.numbers[i + shift] += this->numbers[i]; } ans.Syusei(); return ans; } Large_Integer operator>>(Large_Integer const &a) const { LL shift = a.to_LongLong(), i; if (shift < 0) { return *this << (shift * -1); } Large_Integer ans = *this; ans.numbers = VLL(max((LL)0, (LL)this->numbers.size() - shift), 0); for (i = 0; i < this->numbers.size(); i++) { if (i - shift >= 0) { ans.numbers[i - shift] = this->numbers[i]; } } ans.Syusei(); return ans; } // 掛け算(long long) Large_Integer operator*(LL const &b) const { Large_Integer ans; ans.sign = this->sign; ans.numbers = VLL(this->numbers.size() + 2, 0); LL i, a = b; if (a < 0) { a *= -1; ans.sign *= -1; } for (i = 0; i < this->numbers.size(); i++) { ans.numbers[i] = a * this->numbers[i]; } for (i = 0; i < ans.numbers.size(); i++) { if (i + 1 < ans.numbers.size()) { ans.numbers[i + 1] = (ans.numbers[i] / Large_Integer::shinsuu); } ans.numbers[i] %= Large_Integer::shinsuu; } return ans; } // 誤りの検知と修正 void Syusei() { LL i, j, k; if (abs(this->sign) != 1) { j = 0; j = 1 / j; } k = 0; for (i = 0; i < this->numbers.size(); i++) { if (this->numbers[i] < 0) { j = 0; j = 1 / j; } if (i + 1 < this->numbers.size()) { this->numbers[i + 1] += (this->numbers[i] / Large_Integer::shinsuu); } this->numbers[i] %= Large_Integer::shinsuu; if (this->numbers[i] > 0) k = i + 1; } VLL ans(k, 0); for (i = 0; i < k; i++) { ans[i] = this->numbers[i]; } this->numbers = ans; if (this->sign == -1 && this->numbers.size() == 0) { this->sign = 1; } } public: // コンストラクタたち Large_Integer(Large_Integer const &b) { *this = b; } Large_Integer(LL const &b) { if (b < 0) this->sign = -1; else this->sign = 1; auto c = abs(b); while (c > 0) { this->numbers.push_back(c % this->shinsuu); c /= this->shinsuu; } this->Syusei(); } Large_Integer() { this->sign = 1; this->numbers = VLL(0); } // long long型に変換する LL to_LongLong() const { LL ans = 0, i; for (i = this->numbers.size() - 1; i >= 0; i--) { ans *= this->shinsuu; ans += this->numbers[i]; } ans *= this->sign; return ans; } // 代入演算子 Large_Integer operator=(Large_Integer const &b) { this->sign = b.sign; this->numbers = b.numbers; return *this; } // 足し算 Large_Integer operator+(Large_Integer const &b) const { LL i, j; VLL x, y; LL size = max(this->numbers.size(), b.numbers.size()); x = Large_Integer::ToVLL(*this, size); y = Large_Integer::ToVLL(b, size); x = Large_Integer::plusVector(x, y); auto ans = Large_Integer::ToInteger(x); ans.Syusei(); return ans; } Large_Integer operator+=(Large_Integer const &b) { return *this = (*this + b); } // 掛け算 Large_Integer operator*(Large_Integer const &b) const { Large_Integer ans = 0; LL i; for (i = 0; i < b.numbers.size(); i++) { ans += ((*this * b.numbers[i]) << i); } return ans; } Large_Integer operator*=(Large_Integer const &b) { return *this = (*this * b); } Large_Integer operator-(Large_Integer const &b) const { return *this + (b * -1); } Large_Integer operator-=(Large_Integer const &b) { return *this = (*this - b); } // 未完成 bool operator<(Large_Integer const &b) const { LL i, j, k; if (this->sign < b.sign) { return true; } if (this->sign > b.sign) { return false; } if (this->sign == 1) { if (this->numbers.size() < b.numbers.size()) { return true; } if (this->numbers.size() > b.numbers.size()) { return false; } for (i = this->numbers.size() - 1; i >= 0; i--) { if (this->numbers[i] < b.numbers[i]) { return true; } if (this->numbers[i] > b.numbers[i]) { return false; } } } } }; // 改良vector template <typename T> class ArrayList : public vector<T> { public: ArrayList(long long const &size, T const &a) : vector<T>(size, a) {} ArrayList(long long const &size) : vector<T>(size) {} ArrayList() : vector<T>() {} T &operator[](long long const &index) { return vector<T>::at(index); } }; typedef ArrayList<LL> ALL; typedef ArrayList<ALL> AALL; // 剰余整数 class ModInt { private: LL n; static LL modP; public: ModInt(ModInt const &b) { this->n = b.n; } ModInt(LL const &b) { this->n = b % ModInt::modP; } ModInt() { *this = ModInt(0); } LL GetMod() const { return ModInt::modP; } void SetMod(LL const &a) { ModInt::modP = abs(a); } LL getNumber() const { return this->n; } ModInt operator=(ModInt const &b) { this->n = b.n; return *this; } ModInt operator+(ModInt const &b) const { return ModInt(this->n + b.n); } ModInt operator+=(ModInt const &b) { return *this = (*this + b); } ModInt operator-(ModInt const &b) const { LL temp = this->n - b.n + ModInt::modP; return ModInt(temp); } ModInt operator-=(ModInt const &b) { return *this = (*this - b); } ModInt operator*(ModInt const &b) const { LL temp = this->n * b.n; return ModInt(temp); } ModInt operator*=(ModInt const &b) { return *this = (*this * b); } ModInt Pow(ModInt const &b) const { LL p = b.n; ModInt ans = 1; ModInt x = *this; while (p > 0) { if (p % 2 == 1) { ans *= x; } x = x * x; p /= 2; } return ans; } ModInt operator/(ModInt const &b) const { ModInt temp = b.Pow(ModInt::modP - 2); return *this * temp; } ModInt operator/=(ModInt const &b) { return *this = (*this / b); } }; LL ModInt::modP = 1000 * 1000 * 1000 + 7; // 関数詰め合わせ class KyoPro { public: static const LL MOD_CONST = (LL)1000 * 1000 * 1000 + 7; static LL DebugFlag; // 数値を区切って文字列にする static string MakeString_LongLong(vector<long long> const &numbers, string const &str) { if (numbers.size() == 0) return ""; string result = "" + to_string(numbers[0]); for (long long i = 1; i < numbers.size(); i++) { result += str; result += to_string(numbers[i]); } return result; } // 空白で区切る為のオーバーロード static string MakeString_LongLong(vector<long long> const &numbers) { if (numbers.size() == 0) return ""; string result = "" + to_string(numbers[0]); for (long long i = 1; i < numbers.size(); i++) { result += " "; result += to_string(numbers[i]); } return result; } // 文字列の配列を改行を挟んでまとめる static string MakeString_VectorString(vector<string> const &str) { string result = ""; for (long long i = 0; i < str.size(); i++) { result += str[i] + "\n"; } return result; } // 文字列を必要な個数だけ読み取る static vector<string> MyReadLineSplit(LL n) { vector<string> str(n); for (long long i = 0; i < n; i++) { std::cin >> str[i]; } return str; } // 数値を必要な個数だけ読み取る static vector<long long> ReadInts(long long number) { vector<long long> a(number); for (int i = 0; i < number; i++) { std::cin >> a[i]; } return a; } // 渡された自然数が素数ならtureを返す static bool PrimeCheck_Int(long long number) { if (number < 2) return false; for (ULL i = 2; i * i <= number; i++) { if (number % i == 0) return false; } return true; } // 自然数が平方数か判定する static bool SquareCheck(LL const &number) { if (KyoPro::PrimeCheck_Int(number)) return false; LL m = number; for (LL i = 2; i <= m; i++) { if (m % i == 0) { LL count = 0; while (m % i == 0) { m /= i; count++; } if (count % 2 == 1) return false; } } return true; } // 渡された数値以下の素数表を作る static vector<long long> MakePrimeList(long long n) { vector<long long> list; LL i, j, p; bool flag; for (i = 2; i <= n; i++) { flag = true; for (j = 0; j < list.size(); j++) { if (!(list[j] * list[j] <= i)) break; if (i % list[j] == 0) { flag = false; break; } } if (flag) list.push_back(i); } return list; } // 文字列の分割 static vector<string> split(string const &str, char sep) { vector<std::string> v; // 分割結果を格納するベクター auto first = str.begin(); // テキストの最初を指すイテレータ while (first != str.end()) { // テキストが残っている間ループ auto last = first; // 分割文字列末尾へのイテレータ while (last != str.end() && *last != sep) // 末尾 or セパレータ文字まで進める last++; v.push_back(string(first, last)); // 分割文字を出力 if (last != str.end()) last++; first = last; // 次の処理のためにイテレータを設定 } return v; } // 合計を求める template <typename T> static LL Sum(T const &a) { LL sum = 0; auto itr = a.begin(); while (itr != a.end()) { sum += (*itr); itr++; } return sum; } // 小文字ならtrueを返す static bool Komoji(char a) { if (a >= 'a' && a <= 'z') return true; return false; } // 大文字ならtrueを返す static bool Oomoji(char a) { if (a >= 'A' && a <= 'Z') return true; return false; } // 切り上げの整数値割り算 static LL KiriageWarizan(LL a, LL b) { LL result = a / b; if (a % b > 0) result++; return result; } // 最大公約数を求める static LL GreatestCommonFactor(LL a, LL b) { a = KyoPro::abs(a); b = KyoPro::abs(b); LL temp; if (a < b) { temp = b; b = a; a = temp; } while (b > 0) { temp = a % b; a = b; b = temp; } return a; } // 最小公倍数を求める static LL LeastCommonMultiple(LL a, LL b) { return (a / GreatestCommonFactor(a, b)) * b; } // 二次元配列を行列とみなして転置する static VVLL VVLLturn(VVLL a) { if (a.size() == 0) return VVLL(0); VVLL result(a[0].size(), VLL(a.size())); LL i, j; for (i = 0; i < a.size(); i++) { for (j = 0; j < a[0].size(); j++) { result[j][i] = a[i][j]; } } return result; } // 素因数分解、素数、指数の順 static vector<VLL> PrimeFactorization(LL n) { VLL p_list, s_list; LL i, j, k, count; for (i = 2; n > 1; i++) { if (i * i > n) { p_list.push_back(n); s_list.push_back(1); break; } if (n % i == 0) { count = 0; while (n % i == 0) { n /= i; count++; } p_list.push_back(i); s_list.push_back(count); } } vector<VLL> result; result.push_back(p_list); result.push_back(s_list); return KyoPro::VVLLturn(result); } // 整数nの約数の配列を作る static VLL MakeYakusuList(LL n) { auto primes = KyoPro::PrimeFactorization(n); VLL ans; VLL roop(primes.size(), 0); LL i, j, k, m, size = roop.size(); while (true) { LL a = 1; for (i = 0; i < size; i++) { for (j = 0; j < roop[i]; j++) { a *= primes[i][0]; } } ans.push_back(a); roop[0]++; for (i = 0; i < size; i++) { if (i + 1 < size) { roop[i + 1] += (roop[i] / (primes[i][1] + 1)); } roop[i] %= (primes[i][1] + 1); } bool flag = true; for (i = 0; i < size; i++) { if (roop[i] != 0) flag = false; } if (flag) break; } return KyoPro::Sort(ans); } // 組み合わせ nCrを10^9+7で割った余りを返す static LL Combination(LL n, LL r) { ModInt ans = 1; r = min(r, n - r); for (LL i = 0; i < r; i++) { ans *= (n - i); ans /= (i + 1); } return ans.getNumber(); } // 順列 nPrを10^9+7で割った余りを返す static LL Permutation(LL n, LL r) { ModInt ans = 1; for (LL i = 0; i < r; i++) { ans *= (n - i); } return ans.getNumber(); } // 重複組み合わせ。n種類からr個重複を許して選ぶ static LL nHr(LL n, LL r) { return KyoPro::Combination(n + r - 1, r); } template <typename T> static T pow(T const &a, LL const &b) { T ans = 1; auto p = b; auto x = a; while (p > 0) { if (p % 2 == 1) { ans *= x; } x = x * x; p /= 2; } return ans; } // 符号 template <typename T> static T sign(T const &x) { if (x > 0) return 1; if (x < 0) return -1; return 0; } // 絶対値 template <typename T> static T abs(T x) { if (x < 0) { x = x * -1; } return x; } // 円周率 static double PI() { return (double)3.1415926535898; } // 指定した桁でdoubleを出す。改行はしない。 static void CoutDoubleKeta(double a, LL keta) { cout << setprecision(keta) << a << flush; } // コンテナクラスの出力 template <typename T> static T CoutVector(T const &ls) { LL i, j, k, size = distance(ls.begin(), ls.end()); if (size == 0) return ls; auto itr = ls.begin(); for (i = 0; i < size - 1; i++) { cout << *itr << " " << flush; itr++; } cout << *itr << flush; return ls; } // コンテナクラスをソートする template <typename T> static T Sort(T &ls) { sort(ls.begin(), ls.end()); return ls; } // 順序関数付きでコンテナクラスをソートする template <typename T, typename F> static T Sort(T &ls, F const &func) { sort(ls.begin(), ls.end(), func); return ls; } // コンテナクラスを逆順に並び替える template <typename T> static T Reverse(T &ls) { reverse(ls.begin(), ls.end()); return ls; } // コンテナクラスの条件を満たす要素を数え上げる。bool func(S x) template <typename T, typename S> static LL Count(T const &ls, S func) { LL ans = 0; auto itr = ls.begin(); while (itr != ls.end()) { if (func(*itr)) ans++; itr++; } return ans; } // コンテナクラスの要素をすべて更新する。S func(S x) template <typename T, typename S> static T AllUpdate(T &ls, S func) { auto itr = ls.begin(); while (itr != ls.end()) { *itr = func(*itr); itr++; } return ls; } // リストをベクターに変換する template <typename T> static vector<T> FromListToVector(list<T> const &a) { vector<T> ans; for (auto itr = a.begin(); itr != a.end(); itr++) { ans.push_back(*itr); } return ans; } // ベクターをリストに変換する template <typename T> static list<T> FromVectorToList(vector<T> a) { list<T> ans; for (auto itr = a.begin(); itr != a.end(); itr++) { ans.push_back(*itr); } return ans; } // 最大値の要素番号を求める template <typename T> static LL MaxElementIndex(T const &ls) { return distance(ls.begin(), max_element(ls.begin(), ls.end())); } // 最小値の要素番号を求める template <typename T> static LL MinElementIndex(T const &ls) { return distance(ls.begin(), min_element(ls.begin(), ls.end())); } // デバッグ用出力 template <typename T> static LL DebugPrintf(T output) { if (KyoPro::DebugFlag) { std::cout << output << endl; } return KyoPro::DebugFlag; } // デバッグ用入力 static LL DebugCin() { LL a; if (KyoPro::DebugFlag) { cin >> a; } return a; } }; LL KyoPro::DebugFlag = 0; // 累積和を求めるクラス class Ruisekiwa { private: vector<LL> list; public: void MakeArray(vector<LL> data) { LL i; list = data; list.push_back(0); list[0] = 0; for (i = 1; i < list.size(); i++) { list[i] = list[i - 1] + data[i - 1]; } } LL Sum(LL start, LL end) { if (end < start) { std::cout << "startがendより大きいです"; return 0; } if (start < 0 || end >= list.size()) { std::cout << "範囲が異常"; return 0; } return list[end] - list[start]; } }; // n進数を管理するクラス class N_Number { public: N_Number(LL n, LL keta) { this->N_Shinsuu = n; VLL temp(keta, 0); this->numbers = temp; } // 数を足す void plus(LL a) { if (a < 0) { a *= (-1); this->minus(a); return; } this->numbers[0] += a; LL size = this->numbers.size(); for (LL i = 0; i < size; i++) { if (i + 1 < size) { this->numbers[i + 1] += this->numbers[i] / this->N_Shinsuu; } this->numbers[i] %= this->N_Shinsuu; } } // 全ての桁が同じ数字になっていればその数字を返す。それ以外の場合は -1 を返す LL check() { LL a = this->numbers[0]; for (LL i = 0; i < this->numbers.size(); i++) { if (this->numbers[i] != a) return -1; } return a; } LL getNumber(LL keta) { return this->numbers[keta]; } LL getKeta() { return this->numbers.size(); } LL getShinsuu() { return this->N_Shinsuu; } void setNumber(LL keta, LL number) { if (0 <= number && number < this->getShinsuu()) { if (0 <= keta && keta < this->getKeta()) { this->numbers[keta] = number; return; } } cout << "er" << endl; } void setAllNumbers(LL number) { LL size = this->getKeta(), i; for (i = 0; i < size; i++) { this->setNumber(i, number); } } string to_string_KetaSoroe() { string s = ""; for (LL i = this->getKeta() - 1; i >= 0; i--) { s += to_string(this->getNumber(i)); } return s; } private: void minus(LL a) { LL i, j, k, zettaiti = abs(a); k = KyoPro::KiriageWarizan(zettaiti, this->N_Shinsuu); j = k * (this->N_Shinsuu - 1); for (i = 0; i < this->getKeta(); i++) { this->numbers[i] += j; } this->numbers[0] += k - a; this->plus(0); } VLL numbers; LL N_Shinsuu; }; // UnionFind class Union_Find { private: VLL tree; VLL count; LL root(LL a) { if (this->tree[a] == a) return a; return this->tree[a] = this->root(this->tree[a]); } public: Union_Find(LL n) { VLL set(n); this->tree = set; this->count = set; for (LL i = 0; i < n; i++) { this->tree[i] = i; this->count[i] = 1; } } void unite(LL a, LL b) { LL x, y; if (!this->Check(a, b)) { x = this->getCount(a) + getCount(b); y = this->root(a); this->count[y] = x; y = this->root(b); this->count[y] = x; } x = this->root(a); y = this->root(b); this->tree[x] = y; } bool Check(LL a, LL b) { return this->root(a) == this->root(b); } LL getCount(LL index) { LL temp = this->root(index); return this->count[temp]; } LL getRoot(LL index) { return this->root(index); } VLL getList() { VLL ans(this->tree.size(), 0); for (LL i = 0; i < ans.size(); i++) { ans[i] = this->root(i); } return ans; } }; // プラスマイナス無限に対応したlong long型 class INF_LONG_LONG { private: LL inf, n; public: // コンストラクタ INF_LONG_LONG(LL a) { this->n = a; this->inf = 0; this->Syusei(); } INF_LONG_LONG() { *this = INF_LONG_LONG(0); } INF_LONG_LONG(INF_LONG_LONG const &a) { this->n = a.n; this->inf = a.inf; this->Syusei(); } // ゲッター LL getN() const { return this->n; } LL getInf() const { return this->inf; } // 正の無限大生成 static INF_LONG_LONG plus_inf() { INF_LONG_LONG a; a.n = 0; a.inf = 1; a.Syusei(); return a; } // 負の無限大生成 static INF_LONG_LONG minus_inf() { INF_LONG_LONG a; a.n = 0; a.inf = -1; a.Syusei(); return a; } // 符号を取得 LL sign() const { if (this->inf != 0) { return this->inf; } return KyoPro::sign(this->n); } // 代入演算子 INF_LONG_LONG operator=(INF_LONG_LONG const &b) { this->n = b.n; this->inf = b.inf; this->Syusei(); return *this; } INF_LONG_LONG operator=(LL const &b) { *this = INF_LONG_LONG(b); this->Syusei(); return *this; } // 比較演算子 bool operator==(INF_LONG_LONG const &b) const { if (this->n == b.n && this->inf == b.inf) return true; return false; } bool operator!=(INF_LONG_LONG const &b) const { return !(*this == b); } bool operator<(INF_LONG_LONG const &b) const { if (this->inf < b.inf) return true; if (this->inf > b.inf) return false; return this->n < b.n; } bool operator>(INF_LONG_LONG const &b) const { return b < *this; } bool operator<=(INF_LONG_LONG const &b) const { return !(*this > b); } bool operator>=(INF_LONG_LONG const &b) const { return !(*this < b); } // 算術演算子 INF_LONG_LONG operator+(INF_LONG_LONG const &b) const { if (max(this->inf, b.inf) > 0) return INF_LONG_LONG::plus_inf(); if (min(this->inf, b.inf) < 0) return INF_LONG_LONG::minus_inf(); auto ans = *this; ans.n += b.n; ans.Syusei(); return ans; } INF_LONG_LONG operator*(INF_LONG_LONG const &b) const { if (*this == INF_LONG_LONG(0) || b == INF_LONG_LONG(0)) { return INF_LONG_LONG(0); } if (this->inf != 0 || b.inf != 0) { LL s = this->sign() * b.sign(); INF_LONG_LONG ans(0); ans.n = 0; ans.inf = s; ans.Syusei(); return ans; } INF_LONG_LONG ans(0); ans.n = this->n * b.n; ans.Syusei(); return ans; } INF_LONG_LONG operator-(INF_LONG_LONG const &b) const { auto ans = (*this + (INF_LONG_LONG(-1) * b)); ans.Syusei(); return ans; } INF_LONG_LONG operator/(INF_LONG_LONG const &b) const { if (b == INF_LONG_LONG(0)) { LL a = this->n / b.n; return INF_LONG_LONG(a); } if (b.inf != 0) { return INF_LONG_LONG(0); } if (*this == INF_LONG_LONG(0)) { return INF_LONG_LONG(0); } if (this->inf != 0) { LL s = this->sign() * b.sign(); return INF_LONG_LONG::plus_inf() * INF_LONG_LONG(s); } INF_LONG_LONG ans; ans.n = this->n / b.n; ans.Syusei(); return ans; } INF_LONG_LONG operator%(INF_LONG_LONG const &b) const { if (this->inf == 0 && b.inf == 0) { INF_LONG_LONG ans; ans.n = this->n % b.n; ans.Syusei(); return ans; } auto x = *this / b; x.Syusei(); auto ans = *this - b * x; ans.Syusei(); return ans; } // 複合代入演算子 INF_LONG_LONG operator+=(INF_LONG_LONG const &b) { auto ans = *this + b; *this = ans; return *this; } INF_LONG_LONG operator-=(INF_LONG_LONG const &b) { auto ans = *this - b; *this = ans; return *this; } INF_LONG_LONG operator*=(INF_LONG_LONG const &b) { auto ans = *this * b; *this = ans; return *this; } INF_LONG_LONG operator/=(INF_LONG_LONG const &b) { auto ans = *this / b; *this = ans; return *this; } INF_LONG_LONG operator%=(INF_LONG_LONG const &b) { auto ans = *this % b; *this = ans; return *this; } // 符号演算子 INF_LONG_LONG operator+() const { return *this; } INF_LONG_LONG operator-() const { return *this * INF_LONG_LONG(-1); } // 前置きインクリメント・デクリメント INF_LONG_LONG operator++() { this->n++; this->Syusei(); return *this; } INF_LONG_LONG operator--() { this->n--; this->Syusei(); return *this; } // 後置きインクリメント・デクリメント INF_LONG_LONG operator++(int) { auto copy = *this; ++(*this); return copy; } INF_LONG_LONG operator--(int) { auto copy = *this; --(*this); return copy; } // 文字列への変換 string ToString() const { if (this->inf == 1) { return "+INF"; } if (this->inf == -1) { return "-INF"; } return to_string(this->n); } private: void Syusei() { if (this->inf != 0) { this->n = 0; } } }; typedef INF_LONG_LONG ILL_TYPE; typedef vector<ILL_TYPE> VILL_TYPE; typedef vector<VILL_TYPE> VVILL_TYPE; // ワーシャルフロイド class WarshallFloyd { public: // 最短距離を記録 VVILL_TYPE d; // 頂点数 LL v; // vは頂点数、edge_cost_listは辺の情報{始点、終点、コスト}の配列。無向グラフの場合、逆矢印の辺に注意。 WarshallFloyd(LL v, VVLL edge_cost_list) { this->v = v; this->d = VVILL_TYPE(v, VILL_TYPE(v, ILL_TYPE::plus_inf())); LL i, j, k, a, b, c; for (i = 0; i < edge_cost_list.size(); i++) { a = edge_cost_list[i][0]; b = edge_cost_list[i][1]; c = edge_cost_list[i][2]; this->d[a][b] = ILL_TYPE(c); } for (i = 0; i < v; i++) { this->d[i][i] = ILL_TYPE(0); } // ここから計算 for (k = 0; k < v; k++) { for (i = 0; i < v; i++) { for (j = 0; j < v; j++) { d[i][j] = min(d[i][j], d[i][k] + d[k][j]); } } } } }; // ベルマンフォード class BellmanFord { public: // 辺のリスト VVILL_TYPE edge; // 頂点数、辺数 LL v, e; // 始点 LL s; // 最短距離 VILL_TYPE d; // vは頂点数、startは始点、edge_cost_listは辺の情報{始点、終点、コスト}の配列。 BellmanFord(LL v, LL start, VVLL edge_cost_list) { this->v = v; this->s = start; this->e = edge_cost_list.size(); this->d = VILL_TYPE(v, ILL_TYPE::plus_inf()); this->d[start] = 0; LL i, j, k; for (i = 0; i < this->e; i++) { VILL_TYPE temp; LL a, b, c; a = edge_cost_list[i][0]; b = edge_cost_list[i][1]; c = edge_cost_list[i][2]; temp.push_back(ILL_TYPE(a)); temp.push_back(ILL_TYPE(b)); temp.push_back(ILL_TYPE(c)); this->edge.push_back(temp); } this->DoUpdata(); auto cpy = this->d; this->DoUpdata(); for (i = 0; i < this->d.size(); i++) { if (this->d[i] != cpy[i]) { this->d[i] = ILL_TYPE::minus_inf(); } } this->DoUpdata(); } private: void DoUpdata() { LL i, j, k; for (i = 0; i <= this->v; i++) { bool update = true; for (j = 0; j < this->e; j++) { ILL_TYPE c; LL a, b; a = this->edge[j][0].getN(); b = this->edge[j][1].getN(); c = this->edge[j][2]; if (this->d[a] < ILL_TYPE::plus_inf()) { if (this->d[a] + c < this->d[b]) { update = false; this->d[b] = this->d[a] + c; } } } if (update) break; } } }; // ダイクストラ class Dijkstra { public: Dijkstra(LL v, LL start, VVLL edge_cost_list) {} }; // ライブラリはここまで // ここから下を書く bool isNotOver(LL n, LL k, VLL const &a, VLL const &f, LL g) { if (g < 0) { return false; } VVLL pair(n, VLL(3, 0)); for (LL i = 0; i < n; i++) { pair[i][0] = a[i]; pair[i][1] = f[i]; pair[i][2] = a[i] * f[i]; } for (LL i = 0; i < n; i++) { LL d = pair[i][2] - g; if (d <= 0) { continue; } LL e = KyoPro::KiriageWarizan(d, pair[i][1]); LL temp = min(e, k); k -= temp; pair[i][0] -= temp; pair[i][2] = pair[i][0] * pair[i][1]; if (pair[i][2] > g) { return false; } } return true; } // ここからメイン int main(void) { KyoPro::DebugFlag = 0; LL n, k; cin >> n >> k; auto a = KyoPro::ReadInts(n); auto f = KyoPro::ReadInts(n); KyoPro::Sort(a); KyoPro::Sort(f); KyoPro::Reverse(f); LL mn = 0, mx = KyoPro::pow((LL)10, 12) + 1; while (mn < mx) { LL c = mn + mx; c /= 2; string s = ""; bool b1 = isNotOver(n, k, a, f, c); bool b2 = isNotOver(n, k, a, f, c - 1); s = s + to_string(b1) + " " + to_string(b2) + " " + to_string(c); KyoPro::DebugPrintf(s); if (b1 && !b2) { cout << c << endl; return 0; } else if (b2) { mx = c - 1; } else { mn = c + 1; } } cout << mn << endl; return 0; }
delete
1,518
1,521
1,518
1,518
TLE
p02883
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef int64_t Int; Int N, K; vector<Int> A(200010), F(100010); bool possible(Int X) { Int shugyo = 0; for (int i = 0; i < N; i++) { shugyo += max((Int)0, (A[i] - X / F[i])); } return (shugyo <= K); } int main() { cin >> N >> K; Int sum = 0; for (int i = 0; i < N; i++) { cin >> A[i]; sum += A[i]; } for (int i = 0; i < N; i++) cin >> F[i]; if (sum <= K) { cout << 0 << endl; return 0; } sort(A.begin(), A.begin() + N); sort(F.begin(), F.begin() + N, greater<Int>()); Int ng = -1, ok = 1e13; while (ok - ng > 1) { Int m = (ok + ng) / 2; if (possible(m)) ok = m; else ng = m; } cout << ok << endl; }
#include <bits/stdc++.h> using namespace std; typedef int64_t Int; Int N, K; vector<Int> A(200010, 0), F(200010, 0); bool possible(Int X) { Int shugyo = 0; for (int i = 0; i < N; i++) { shugyo += max((Int)0, (A[i] - X / F[i])); } return (shugyo <= K); } int main() { cin >> N >> K; Int sum = 0; for (int i = 0; i < N; i++) { cin >> A[i]; sum += A[i]; } for (int i = 0; i < N; i++) cin >> F[i]; if (sum <= K) { cout << 0 << endl; return 0; } sort(A.begin(), A.begin() + N); sort(F.begin(), F.begin() + N, greater<Int>()); Int ng = -1, ok = 1e13; while (ok - ng > 1) { Int m = (ok + ng) / 2; if (possible(m)) ok = m; else ng = m; } cout << ok << endl; }
replace
5
6
5
6
0
p02883
C++
Runtime Error
#include <algorithm> #include <climits> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <set> #include <string> #include <tuple> #include <vector> using namespace std; #define Rep(i, n) for (int i = 0; i < (n); ++i) #define InitRep(i, begin, n) for (int i = (begin); i < (n); ++i) #define RepItr(it, begin, end) for (auto it = (begin); it != (end); ++it) using int64 = long long; using vint = vector<int>; using vint64 = vector<int64>; static double PI = ::acos(-1); int main() { int n, k; cin >> n >> k; vint a(n), f(n); Rep(i, n) { cin >> a[i]; } Rep(i, n) { cin >> f[i]; } sort(a.begin(), a.end()); sort(f.begin(), f.end(), greater<int>()); int64 left = -1, right = 1e12; while (left + 1 < right) { int64 center = (left + right) / 2; int64 sum = 0; Rep(i, n) { sum += max(0LL, a[i] - center / f[i]); } if (k >= sum) { right = center; } else { left = center; } } cout << right << endl; return 0; }
#include <algorithm> #include <climits> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <set> #include <string> #include <tuple> #include <vector> using namespace std; #define Rep(i, n) for (int i = 0; i < (n); ++i) #define InitRep(i, begin, n) for (int i = (begin); i < (n); ++i) #define RepItr(it, begin, end) for (auto it = (begin); it != (end); ++it) using int64 = long long; using vint = vector<int>; using vint64 = vector<int64>; static double PI = ::acos(-1); int main() { int64 n, k; cin >> n >> k; vint a(n), f(n); Rep(i, n) { cin >> a[i]; } Rep(i, n) { cin >> f[i]; } sort(a.begin(), a.end()); sort(f.begin(), f.end(), greater<int>()); int64 left = -1, right = 1e12; while (left + 1 < right) { int64 center = (left + right) / 2; int64 sum = 0; Rep(i, n) { sum += max(0LL, a[i] - center / f[i]); } if (k >= sum) { right = center; } else { left = center; } } cout << right << endl; return 0; }
replace
20
21
20
21
0
p02883
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int n; int64_t k; vector<int64_t> A; vector<int64_t> F; vector<int64_t> M; bool check(int64_t ma) { int64_t remain = k; for (int i = 0; i < n; i++) { if (M[i] <= ma) continue; remain -= A[i] - ma / F[i]; } return remain >= 0; } int main() { cin >> n; cin >> k; A.resize(n); F.resize(n); copy_n(istream_iterator<int64_t>(cin), n, A.begin()); copy_n(istream_iterator<int64_t>(cin), n, F.begin()); sort(A.begin(), A.end()); sort(F.begin(), F.end(), greater<int64_t>()); M.resize(n); for (int i = 0; i < n; i++) M[i] = A[i] * F[i]; int64_t ng = -1, ok = 1e12 + 1; while (abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if (check(mid)) ok = mid; else ng = mid; } cout << ok << endl; }
#include <bits/stdc++.h> using namespace std; int n; int64_t k; vector<int64_t> A; vector<int64_t> F; vector<int64_t> M; bool check(int64_t ma) { int64_t remain = k; for (int i = 0; i < n; i++) { if (M[i] <= ma) continue; remain -= A[i] - ma / F[i]; } return remain >= 0; } int main() { cin >> n; cin >> k; A.resize(n); F.resize(n); copy_n(istream_iterator<int64_t>(cin), n, A.begin()); copy_n(istream_iterator<int64_t>(cin), n, F.begin()); sort(A.begin(), A.end()); sort(F.begin(), F.end(), greater<int64_t>()); M.resize(n); for (int i = 0; i < n; i++) M[i] = A[i] * F[i]; int64_t ng = -1, ok = 1e12 + 1; while (abs(ok - ng) > 1) { int64_t mid = (ok + ng) / 2; if (check(mid)) ok = mid; else ng = mid; } cout << ok << endl; }
replace
38
39
38
39
TLE
p02883
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPr(i, n) for (int i = (n)-1; i >= 0; --i) #define FORq(i, m, n) for (int i = (m); i <= (n); ++i) #define FORqr(i, m, n) for (int i = (n); i >= (m); --i) #define PB push_back #define MP make_pair #define fst first #define snd second #define SIN(x, S) (S.count(x) != 0) #define M0(x) memset(x, 0, sizeof(x)) #define FILL(x, y) memset(x, y, sizeof(x)) #define MM(x) memset(x, -1, sizeof(x)) #define ALL(x) (x).begin(), (x).end() #define DB(x) cerr << #x << " = " << x << endl #define DB2(x, y) \ cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"; #define DEBUG \ int x12345; \ cin >> x12345; typedef pair<int, int> PII; typedef pair<long long, long long> PLL; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<long long> VL; typedef long long ll; typedef long long integer; /////////////////////////////////////////////// const ll MOD = 1e9 + 7; ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } 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 <int MOD> struct Fp { long long val; constexpr Fp(long long v = 0) noexcept : val(v % MOD) { if (val < 0) v += MOD; } constexpr int getmod() { return MOD; } constexpr Fp operator-() const noexcept { return val ? MOD - val : 0; } constexpr Fp operator+(const Fp &r) const noexcept { return Fp(*this) += r; } constexpr Fp operator-(const Fp &r) const noexcept { return Fp(*this) -= r; } constexpr Fp operator*(const Fp &r) const noexcept { return Fp(*this) *= r; } constexpr Fp operator/(const Fp &r) const noexcept { return Fp(*this) /= r; } constexpr Fp &operator+=(const Fp &r) noexcept { val += r.val; if (val >= MOD) val -= MOD; return *this; } constexpr Fp &operator-=(const Fp &r) noexcept { val -= r.val; if (val < 0) val += MOD; return *this; } constexpr Fp &operator*=(const Fp &r) noexcept { val = val * r.val % MOD; return *this; } constexpr Fp &operator/=(const Fp &r) noexcept { long long a = r.val, b = MOD, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } val = val * u % MOD; if (val < 0) val += MOD; return *this; } constexpr bool operator==(const Fp &r) const noexcept { return this->val == r.val; } constexpr bool operator!=(const Fp &r) const noexcept { return this->val != r.val; } friend constexpr ostream &operator<<(ostream &os, const Fp<MOD> &x) noexcept { return os << x.val; } friend constexpr istream &operator>>(istream &is, Fp<MOD> &x) noexcept { return is >> x.val; } friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept { if (n == 0) return 1; auto t = modpow(a, n / 2); t = t * t; if (n & 1) t = t * a; return t; } }; using mint = Fp<MOD>; void scdvec(vector<int> &a, int n, int s = 0) { for (int i = s; i < n; ++i) { scanf("%d", &a[i]); } } void sclldvec(vector<long long> &a, int n, int s = 0) { for (int i = s; i < n; ++i) { scanf("%lld", &a[i]); } } /////////////////////////////////////////////// /// ((((っ・ω・)っ |AC| ll N, K; vector<ll> A, F; bool check(ll target) { ll rest = K; REP(i, N) { ll a, f; a = A[i]; f = F[i]; if (a * f <= target) continue; ll change = target / f; rest -= (A[i] - change); } if (rest >= 0) return true; else return false; } ll binary_search() { // lower_bound (a-1,b] (ans = [a,b]) // <= left never satisfy // right <= always satisfy ll left = -1; ll right = 1e12 + 3; // index of size + 1; while (right - left > 1) { int mid = left + (right - left) / 2; if (check(mid)) right = mid; else left = mid; } // left is the maximum that don't satisfy the condition. // right is the minimum that satisfies the condtion. return right; } int main() { scanf("%lld%lld", &N, &K); REP(i, N) { ll x; scanf("%lld", &x); A.PB(x); } REP(i, N) { ll x; scanf("%lld", &x); F.PB(x); } sort(ALL(A)); sort(F.rbegin(), F.rend()); cout << binary_search() << endl; // ll target; cin >> target; // cout << check(target) << endl; }
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPr(i, n) for (int i = (n)-1; i >= 0; --i) #define FORq(i, m, n) for (int i = (m); i <= (n); ++i) #define FORqr(i, m, n) for (int i = (n); i >= (m); --i) #define PB push_back #define MP make_pair #define fst first #define snd second #define SIN(x, S) (S.count(x) != 0) #define M0(x) memset(x, 0, sizeof(x)) #define FILL(x, y) memset(x, y, sizeof(x)) #define MM(x) memset(x, -1, sizeof(x)) #define ALL(x) (x).begin(), (x).end() #define DB(x) cerr << #x << " = " << x << endl #define DB2(x, y) \ cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"; #define DEBUG \ int x12345; \ cin >> x12345; typedef pair<int, int> PII; typedef pair<long long, long long> PLL; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<long long> VL; typedef long long ll; typedef long long integer; /////////////////////////////////////////////// const ll MOD = 1e9 + 7; ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } 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 <int MOD> struct Fp { long long val; constexpr Fp(long long v = 0) noexcept : val(v % MOD) { if (val < 0) v += MOD; } constexpr int getmod() { return MOD; } constexpr Fp operator-() const noexcept { return val ? MOD - val : 0; } constexpr Fp operator+(const Fp &r) const noexcept { return Fp(*this) += r; } constexpr Fp operator-(const Fp &r) const noexcept { return Fp(*this) -= r; } constexpr Fp operator*(const Fp &r) const noexcept { return Fp(*this) *= r; } constexpr Fp operator/(const Fp &r) const noexcept { return Fp(*this) /= r; } constexpr Fp &operator+=(const Fp &r) noexcept { val += r.val; if (val >= MOD) val -= MOD; return *this; } constexpr Fp &operator-=(const Fp &r) noexcept { val -= r.val; if (val < 0) val += MOD; return *this; } constexpr Fp &operator*=(const Fp &r) noexcept { val = val * r.val % MOD; return *this; } constexpr Fp &operator/=(const Fp &r) noexcept { long long a = r.val, b = MOD, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } val = val * u % MOD; if (val < 0) val += MOD; return *this; } constexpr bool operator==(const Fp &r) const noexcept { return this->val == r.val; } constexpr bool operator!=(const Fp &r) const noexcept { return this->val != r.val; } friend constexpr ostream &operator<<(ostream &os, const Fp<MOD> &x) noexcept { return os << x.val; } friend constexpr istream &operator>>(istream &is, Fp<MOD> &x) noexcept { return is >> x.val; } friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept { if (n == 0) return 1; auto t = modpow(a, n / 2); t = t * t; if (n & 1) t = t * a; return t; } }; using mint = Fp<MOD>; void scdvec(vector<int> &a, int n, int s = 0) { for (int i = s; i < n; ++i) { scanf("%d", &a[i]); } } void sclldvec(vector<long long> &a, int n, int s = 0) { for (int i = s; i < n; ++i) { scanf("%lld", &a[i]); } } /////////////////////////////////////////////// /// ((((っ・ω・)っ |AC| ll N, K; vector<ll> A, F; bool check(ll target) { ll rest = K; REP(i, N) { ll a, f; a = A[i]; f = F[i]; if (a * f <= target) continue; ll change = target / f; rest -= (A[i] - change); } if (rest >= 0) return true; else return false; } ll binary_search() { // lower_bound (a-1,b] (ans = [a,b]) // <= left never satisfy // right <= always satisfy ll left = -1; ll right = 1e12 + 3; // index of size + 1; while (right - left > 1) { ll mid = left + (right - left) / 2; if (check(mid)) right = mid; else left = mid; } // left is the maximum that don't satisfy the condition. // right is the minimum that satisfies the condtion. return right; } int main() { scanf("%lld%lld", &N, &K); REP(i, N) { ll x; scanf("%lld", &x); A.PB(x); } REP(i, N) { ll x; scanf("%lld", &x); F.PB(x); } sort(ALL(A)); sort(F.rbegin(), F.rend()); cout << binary_search() << endl; // ll target; cin >> target; // cout << check(target) << endl; }
replace
175
176
175
176
TLE
p02883
C++
Time Limit Exceeded
// #define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; using ll = long long; #define INF 0x6fffffff #define INFL 0x6fffffffffffffffLL ll n, k; vector<int> a(1000001), f(1000001); // 二分探索法 // index が条件を満たすかどうか bool isOK(ll index) { ll c = 0; for (int i = 0; i < n; i++) { c += max(0ll, (a[i] - index / f[i])); if (c > k) return false; } return true; } // 汎用的な二分探索のテンプレ ll binary_search(ll m) { ll left = -1; // 「index = 0」が条件を満たすこともあるので、初期値は -1 ll right = m; // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は // a.size() /* どんな二分探索でもここの書き方を変えずにできる! */ while (right - left > 1) { int mid = (left + right) / 2; if (isOK(mid)) right = mid; else left = mid; } /* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */ return right; } int main() { ll b, c, d, w, h, i, j, l, m, x, y, z; ll ans = 0; string s; cin >> n >> k; vector<int> aa(n), ff(n); for (i = 0; i < n; i++) cin >> aa[i]; for (i = 0; i < n; i++) cin >> ff[i]; sort(aa.begin(), aa.end()); sort(ff.begin(), ff.end()); reverse(aa.begin(), aa.end()); for (i = 0; i < n; i++) { a[i] = aa[i]; f[i] = ff[i]; } ans = binary_search((ll)a[0] * f[n - 1] + 1); cout << ans << endl; return 0; }
// #define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; using ll = long long; #define INF 0x6fffffff #define INFL 0x6fffffffffffffffLL ll n, k; vector<int> a(1000001), f(1000001); // 二分探索法 // index が条件を満たすかどうか bool isOK(ll index) { ll c = 0; for (int i = 0; i < n; i++) { c += max(0ll, (a[i] - index / f[i])); if (c > k) return false; } return true; } // 汎用的な二分探索のテンプレ ll binary_search(ll m) { ll left = -1; // 「index = 0」が条件を満たすこともあるので、初期値は -1 ll right = m; // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は // a.size() /* どんな二分探索でもここの書き方を変えずにできる! */ while (right - left > 1) { ll mid = right + (left - right) / 2; if (isOK(mid)) right = mid; else left = mid; } /* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */ return right; } int main() { ll b, c, d, w, h, i, j, l, m, x, y, z; ll ans = 0; string s; cin >> n >> k; vector<int> aa(n), ff(n); for (i = 0; i < n; i++) cin >> aa[i]; for (i = 0; i < n; i++) cin >> ff[i]; sort(aa.begin(), aa.end()); sort(ff.begin(), ff.end()); reverse(aa.begin(), aa.end()); for (i = 0; i < n; i++) { a[i] = aa[i]; f[i] = ff[i]; } ans = binary_search((ll)a[0] * f[n - 1] + 1); cout << ans << endl; return 0; }
replace
30
31
30
31
TLE
p02883
C++
Runtime Error
#include <algorithm> #include <cassert> #include <cmath> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <vector> using namespace std; using lint = long long; constexpr int MOD = 1000000007, INF = 1010101010; constexpr lint LINF = 1LL << 60; template <class T> ostream &operator<<(ostream &os, const vector<T> &vec) { for (const auto &e : vec) os << e << (&e == &vec.back() ? "" : " "); return os; } #ifdef _DEBUG template <class T> void dump(const char *str, T &&h) { cerr << str << " = " << h << "\n"; }; template <class Head, class... Tail> void dump(const char *str, Head &&h, Tail &&...t) { while (*str != ',') cerr << *str++; cerr << " = " << h << "\n"; dump(str + (*(str + 1) == ' ' ? 2 : 1), t...); } #define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__) #else #define DMP(...) ((void)0) #endif int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int N, K; cin >> N >> K; vector<int> A(N), F(N); for (int i = 0; i < N; i++) cin >> A[i]; for (int i = 0; i < N; i++) cin >> F[i]; sort(A.begin(), A.end()); sort(F.begin(), F.end(), greater<int>()); auto judge = [&](lint idx) { lint sum = 0; for (int i = 0; i < N; i++) sum += max(A[i] - (idx / F[i]), 0LL); return sum <= K; }; auto biSearch = [&](auto f) { lint ok = 1e12; lint ng = -1; while (abs(ok - ng) > 1) { lint mid = (ok + ng) / 2; if (f(mid)) ok = mid; else ng = mid; } return ok; }; cout << biSearch(judge) << "\n"; return 0; }
#include <algorithm> #include <cassert> #include <cmath> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <vector> using namespace std; using lint = long long; constexpr int MOD = 1000000007, INF = 1010101010; constexpr lint LINF = 1LL << 60; template <class T> ostream &operator<<(ostream &os, const vector<T> &vec) { for (const auto &e : vec) os << e << (&e == &vec.back() ? "" : " "); return os; } #ifdef _DEBUG template <class T> void dump(const char *str, T &&h) { cerr << str << " = " << h << "\n"; }; template <class Head, class... Tail> void dump(const char *str, Head &&h, Tail &&...t) { while (*str != ',') cerr << *str++; cerr << " = " << h << "\n"; dump(str + (*(str + 1) == ' ' ? 2 : 1), t...); } #define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__) #else #define DMP(...) ((void)0) #endif int main() { cin.tie(nullptr); ios::sync_with_stdio(false); lint N, K; cin >> N >> K; vector<int> A(N), F(N); for (int i = 0; i < N; i++) cin >> A[i]; for (int i = 0; i < N; i++) cin >> F[i]; sort(A.begin(), A.end()); sort(F.begin(), F.end(), greater<int>()); auto judge = [&](lint idx) { lint sum = 0; for (int i = 0; i < N; i++) sum += max(A[i] - (idx / F[i]), 0LL); return sum <= K; }; auto biSearch = [&](auto f) { lint ok = 1e12; lint ng = -1; while (abs(ok - ng) > 1) { lint mid = (ok + ng) / 2; if (f(mid)) ok = mid; else ng = mid; } return ok; }; cout << biSearch(judge) << "\n"; return 0; }
replace
45
46
45
46
0
p02883
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll MAX = 200000, INF = 1e13; ll n, k; ll A[MAX], B[MAX], F[MAX]; bool C(ll x) { ll cnt = 0; sort(A, A + n); sort(F, F + n, greater<>()); for (int i = 0; i < n; i++) { B[i] = x / F[i]; } for (int i = 0; i < n; i++) { if (B[i] < A[i]) cnt += A[i] - B[i]; } if (cnt > k) return false; else return true; } void solve() { ll lb = 0, ub = INF; for (int i = 0; i < 1000; i++) { ll mid = (lb + ub) / 2; if (C(mid)) ub = mid; else lb = mid; } printf("%lld\n", ub); } int main() { cin >> n >> k; for (int i = 0; i < n; i++) cin >> A[i]; for (int i = 0; i < n; i++) cin >> F[i]; solve(); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll MAX = 200000, INF = 1e13; ll n, k; ll A[MAX], B[MAX], F[MAX]; bool C(ll x) { ll cnt = 0; sort(A, A + n); sort(F, F + n, greater<>()); for (int i = 0; i < n; i++) { B[i] = x / F[i]; } for (int i = 0; i < n; i++) { if (B[i] < A[i]) cnt += A[i] - B[i]; } if (cnt > k) return false; else return true; } void solve() { ll lb = 0, ub = INF; for (int i = 0; i < 100; i++) { ll mid = (lb + ub) / 2; if (C(mid)) ub = mid; else lb = mid; } printf("%lld\n", ub); } int main() { cin >> n >> k; for (int i = 0; i < n; i++) cin >> A[i]; for (int i = 0; i < n; i++) cin >> F[i]; solve(); }
replace
29
30
29
30
TLE
p02883
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, K; cin >> n >> K; vector<ll> a(n), f(n); for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> f[i]; sort(a.begin(), a.end()); sort(f.rbegin(), f.rend()); ll ok = 1e12, ng = -1; while (ok - ng > 1) { ll mid = (ok + ng) / 2; ll cnt = 0; for (int i = 0; i < n; i++) { cnt += max(a[i] - min(a[i], mid / f[i]), 0LL); } (cnt <= K ? ok : ng) = mid; } cout << ok << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { cin.tie(0); ios::sync_with_stdio(false); int n; ll K; cin >> n >> K; vector<ll> a(n), f(n); for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> f[i]; sort(a.begin(), a.end()); sort(f.rbegin(), f.rend()); ll ok = 1e12, ng = -1; while (ok - ng > 1) { ll mid = (ok + ng) / 2; ll cnt = 0; for (int i = 0; i < n; i++) { cnt += max(a[i] - min(a[i], mid / f[i]), 0LL); } (cnt <= K ? ok : ng) = mid; } cout << ok << "\n"; return 0; }
replace
9
10
9
11
0
p02883
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { // freopen("sample3.in", "r", stdin); int N, K; cin >> N >> K; vector<long> A(N), F(N); for (int i = 0; i < N; ++i) { cin >> A[i]; } for (int i = 0; i < N; ++i) { cin >> F[i]; } sort(A.begin(), A.end()); sort(F.begin(), F.end(), greater<long>()); long left = 0L, right = 1e18L; while (left < right) { long mid = (left + right) >> 1, need = 0L; for (int i = 0; i < N; ++i) need += max(A[i] - mid / F[i], 0L); if (need > K) left = mid + 1; else right = mid; } cout << left << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long N, K; cin >> N >> K; vector<long> A(N), F(N); for (int i = 0; i < N; ++i) { cin >> A[i]; } for (int i = 0; i < N; ++i) { cin >> F[i]; } sort(A.begin(), A.end()); sort(F.begin(), F.end(), greater<long>()); long left = 0L, right = 1e18L; while (left < right) { long mid = (left + right) >> 1, need = 0L; for (int i = 0; i < N; ++i) need += max(A[i] - mid / F[i], 0L); if (need > K) left = mid + 1; else right = mid; } cout << left << endl; }
replace
4
6
4
5
0
p02883
C++
Runtime Error
#pragma GCC optimize(3) #include <bits/stdc++.h> #define il inline #define rg register #define gi read<int> using namespace std; const int O = 2e5 + 10, N = 1e6 + 10; typedef long long ll; template <class TT> il TT read() { TT o = 0, fl = 1; char ch = getchar(); while (!isdigit(ch) && ch != '-') ch = getchar(); if (ch == '-') fl = -1, ch = getchar(); while (isdigit(ch)) o = o * 10 + ch - '0', ch = getchar(); return fl * o; } ll k, kk, l = 1, r, a[O], f[O], b[O], cnt[N], ans; int n; il bool check(ll x) { ll res = 0; memset(cnt, 0, sizeof cnt); for (int i = 1; i <= n; ++i) b[i] = x / f[i], ++cnt[b[i]]; for (int i = 0, j = 0; i < N; ++i) while (cnt[i]) b[j] = i, --cnt[i]; for (int i = 1; i <= n; ++i) res += max(0ll, a[i] - b[i]); return res <= k; } int main() { n = gi(), k = read<ll>(); for (int i = 1; i <= n; ++i) a[i] = read<ll>(), kk += a[i]; for (int i = 1; i <= n; ++i) f[i] = read<ll>(); if (kk <= k) return puts("0") & 0; sort(f + 1, f + n + 1); sort(a + 1, a + n + 1); reverse(a + 1, a + n + 1); for (int i = 1; i <= n; ++i) r = max(r, a[i] * f[i]); while (l <= r) { ll mid = l + r >> 1; if (check(mid)) r = mid - 1, ans = mid; else l = mid + 1; } printf("%lld\n", ans); return 0; }
#pragma GCC optimize(3) #include <bits/stdc++.h> #define il inline #define rg register #define gi read<int> using namespace std; const int O = 2e5 + 10, N = 1e6 + 10; typedef long long ll; template <class TT> il TT read() { TT o = 0, fl = 1; char ch = getchar(); while (!isdigit(ch) && ch != '-') ch = getchar(); if (ch == '-') fl = -1, ch = getchar(); while (isdigit(ch)) o = o * 10 + ch - '0', ch = getchar(); return fl * o; } ll k, kk, l = 1, r, a[O], f[O], b[O], cnt[N], ans; int n; il bool check(ll x) { ll res = 0; memset(cnt, 0, sizeof cnt); for (int i = 1; i <= n; ++i) b[i] = x / f[i], ++cnt[b[i] >= N ? (N - 1) : b[i]]; for (int i = 0, j = 0; i < N; ++i) while (cnt[i]) b[j] = i, --cnt[i]; for (int i = 1; i <= n; ++i) res += max(0ll, a[i] - b[i]); return res <= k; } int main() { n = gi(), k = read<ll>(); for (int i = 1; i <= n; ++i) a[i] = read<ll>(), kk += a[i]; for (int i = 1; i <= n; ++i) f[i] = read<ll>(); if (kk <= k) return puts("0") & 0; sort(f + 1, f + n + 1); sort(a + 1, a + n + 1); reverse(a + 1, a + n + 1); for (int i = 1; i <= n; ++i) r = max(r, a[i] * f[i]); while (l <= r) { ll mid = l + r >> 1; if (check(mid)) r = mid - 1, ans = mid; else l = mid + 1; } printf("%lld\n", ans); return 0; }
replace
25
26
25
26
0
p02883
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define sz(x) int(x.size()) #define show(x) \ { \ for (auto i : x) { \ cout << i << " "; \ } \ cout << endl; \ } using namespace std; using ll = long long; using P = pair<int, int>; const ll INF = 1e12; vector<ll> A; vector<ll> F; int N, K; bool check(ll x) { // K回以下の修行でx以下の成績に出来るならtrueを返す ll cnt = 0; rep(i, N) { ll need = x / F[i]; ll y = A[i] - need; cnt += ((y < 0) ? 0 : y); } return (cnt <= K); } int main() { // sort、二分探索 cin >> N >> K; A.resize(N); F.resize(N); rep(i, N) cin >> A[i]; rep(i, N) cin >> F[i]; sort(A.begin(), A.end()); sort(F.rbegin(), F.rend()); ll ok = INF; ll ng = -1; while (abs(ng - ok) > 1) { ll mid = (ok + ng) / 2; if (check(mid)) ok = mid; else ng = mid; } cout << ok << '\n'; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define sz(x) int(x.size()) #define show(x) \ { \ for (auto i : x) { \ cout << i << " "; \ } \ cout << endl; \ } using namespace std; using ll = long long; using P = pair<int, int>; const ll INF = 1e12; vector<ll> A; vector<ll> F; ll N, K; bool check(ll x) { // K回以下の修行でx以下の成績に出来るならtrueを返す ll cnt = 0; rep(i, N) { ll need = x / F[i]; ll y = A[i] - need; cnt += ((y < 0) ? 0 : y); } return (cnt <= K); } int main() { // sort、二分探索 cin >> N >> K; A.resize(N); F.resize(N); rep(i, N) cin >> A[i]; rep(i, N) cin >> F[i]; sort(A.begin(), A.end()); sort(F.rbegin(), F.rend()); ll ok = INF; ll ng = -1; while (abs(ng - ok) > 1) { ll mid = (ok + ng) / 2; if (check(mid)) ok = mid; else ng = mid; } cout << ok << '\n'; return 0; }
replace
17
18
17
18
0
p02883
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> using namespace std; #define ll long long #define _for(i, a, b) for (int i = (a); i < (b); i++) #define _rep(i, a, b) for (int i = (a); i <= (b); i++) const int N = 1e5 + 100; int a[N], f[N], n; int main() { ll k; cin >> n >> k; _for(i, 0, n) cin >> a[i]; _for(i, 0, n) cin >> f[i]; sort(a, a + n); sort(f, f + n, greater<int>()); ll l = 0, r = 1e12; while (l < r) { ll sum = 0; ll x = (l + r) >> 1; _for(i, 0, n) sum += max(0ll, a[i] - x / f[i]); if (sum <= k) r = x; else l = x + 1; } cout << l << endl; return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> using namespace std; #define ll long long #define _for(i, a, b) for (int i = (a); i < (b); i++) #define _rep(i, a, b) for (int i = (a); i <= (b); i++) const int N = 2e5 + 100; int a[N], f[N], n; int main() { ll k; cin >> n >> k; _for(i, 0, n) cin >> a[i]; _for(i, 0, n) cin >> f[i]; sort(a, a + n); sort(f, f + n, greater<int>()); ll l = 0, r = 1e12; while (l < r) { ll sum = 0; ll x = (l + r) >> 1; _for(i, 0, n) sum += max(0ll, a[i] - x / f[i]); if (sum <= k) r = x; else l = x + 1; } cout << l << endl; return 0; }
replace
8
9
8
9
0
p02883
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #define inf 2147483647 #define mem0(a) memset(a, 0, sizeof(a)) #define rep(i, a, b) for (int i = a; i < b; i++) #define rr read() #define ll long long #define pn putchar('\n') #define ps putchar(' ') #define repb(i, a, b) for (int i = a; i <= b; i++) #define CloseIo ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0) using namespace std; const int N = 1e5 + 5; ll a[N], f[N]; ll n, m; bool check(ll z, ll k) { rep(i, 0, n) { if (a[i] * f[n - 1 - i] < z) continue; if (a[i] - z / f[n - 1 - i] > k) return false; k -= (a[i] - z / f[n - 1 - i]); } return true; } int main() { scanf("%lld %lld", &n, &m); rep(i, 0, n) scanf("%lld", &a[i]); rep(i, 0, n) scanf("%lld", &f[i]); sort(a, a + n); sort(f, f + n); ll l = 0, r = 1e12 + 12; ll ans; while (l <= r) { ll mid = (l + r) >> 1; if (check(mid, m)) { ans = mid; r = mid - 1; } else l = mid + 1; } cout << ans; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #define inf 2147483647 #define mem0(a) memset(a, 0, sizeof(a)) #define rep(i, a, b) for (int i = a; i < b; i++) #define rr read() #define ll long long #define pn putchar('\n') #define ps putchar(' ') #define repb(i, a, b) for (int i = a; i <= b; i++) #define CloseIo ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0) using namespace std; const int N = 1e6 + 5; ll a[N], f[N]; ll n, m; bool check(ll z, ll k) { rep(i, 0, n) { if (a[i] * f[n - 1 - i] < z) continue; if (a[i] - z / f[n - 1 - i] > k) return false; k -= (a[i] - z / f[n - 1 - i]); } return true; } int main() { scanf("%lld %lld", &n, &m); rep(i, 0, n) scanf("%lld", &a[i]); rep(i, 0, n) scanf("%lld", &f[i]); sort(a, a + n); sort(f, f + n); ll l = 0, r = 1e12 + 12; ll ans; while (l <= r) { ll mid = (l + r) >> 1; if (check(mid, m)) { ans = mid; r = mid - 1; } else l = mid + 1; } cout << ans; }
replace
22
23
22
23
0
p02883
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef vector<int> veci; typedef pair<int, int> pii; typedef vector<pii> vecii; typedef long long ll; typedef pair<ll, ll> pll; typedef vector<ll> vecl; typedef vector<pll> vecll; #define EPS (1e-9) #define MOD (1e9 + 7) #define fi first #define se second #define endl '\n' void solve() { int n, k; cin >> n >> k; vector<ll> va(n); for (int i = 0; i < n; ++i) cin >> va[i]; sort(va.rbegin(), va.rend()); vector<ll> vf(n); for (int i = 0; i < n; ++i) cin >> vf[i]; sort(vf.begin(), vf.end()); ll l = 0, r = ll(1e12); while (l < r) { ll mid = l + (r - l) / 2; bool ok = true; ll rem = k; for (int i = 0; i < n; ++i) { ll needed = mid / vf[i]; if (va[i] > needed) { rem -= va[i] - needed; } if (rem < 0) { ok = false; break; } } if (ok) { r = mid; } else { l = mid + 1; } } cout << l << endl; } int main(int argc, char *argv[]) { ios::sync_with_stdio(false); cin.tie(nullptr); #ifdef LOCAL_TEST (void)argc; const string strpath = string(argv[0]) + string("-test.in"); freopen(strpath.c_str(), "r", stdin); int tcs; cin >> tcs; while (tcs-- > 0) #endif solve(); }
#include <bits/stdc++.h> using namespace std; typedef vector<int> veci; typedef pair<int, int> pii; typedef vector<pii> vecii; typedef long long ll; typedef pair<ll, ll> pll; typedef vector<ll> vecl; typedef vector<pll> vecll; #define EPS (1e-9) #define MOD (1e9 + 7) #define fi first #define se second #define endl '\n' void solve() { ll n, k; cin >> n >> k; vector<ll> va(n); for (int i = 0; i < n; ++i) cin >> va[i]; sort(va.rbegin(), va.rend()); vector<ll> vf(n); for (int i = 0; i < n; ++i) cin >> vf[i]; sort(vf.begin(), vf.end()); ll l = 0, r = ll(1e12); while (l < r) { ll mid = l + (r - l) / 2; bool ok = true; ll rem = k; for (int i = 0; i < n; ++i) { ll needed = mid / vf[i]; if (va[i] > needed) { rem -= va[i] - needed; } if (rem < 0) { ok = false; break; } } if (ok) { r = mid; } else { l = mid + 1; } } cout << l << endl; } int main(int argc, char *argv[]) { ios::sync_with_stdio(false); cin.tie(nullptr); #ifdef LOCAL_TEST (void)argc; const string strpath = string(argv[0]) + string("-test.in"); freopen(strpath.c_str(), "r", stdin); int tcs; cin >> tcs; while (tcs-- > 0) #endif solve(); }
replace
17
18
17
18
0
p02883
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define ll long long using namespace std; int n; ll k, l, r, ans; ll a[200010], f[200010]; bool cmp(int x, int y) { return x > y; } bool check(ll x) { ll kk = k; for (int i = 1; i <= n; i++) { ll res = 0; while (res * f[i] <= x) { res++; } res--; kk -= a[i] - res; } return kk >= 0; } int main() { scanf("%d%lld", &n, &k); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= n; i++) scanf("%d", &f[i]); sort(a + 1, a + n + 1), sort(f + 1, f + n + 1, cmp); for (int i = 1; i <= n; i++) { r = max(r, a[i] * f[i]); } l = 0; while (l <= r) { ll mid = l + r >> 1; if (check(mid)) { ans = mid, r = mid - 1; } else l = mid + 1; } printf("%lld", ans); return 0; }
#include <bits/stdc++.h> #define ll long long using namespace std; int n; ll k, l, r, ans; ll a[200010], f[200010]; bool cmp(int x, int y) { return x > y; } bool check(ll x) { ll kk = k; for (int i = 1; i <= n; i++) { ll res = x / f[i]; if (a[i] >= res) kk -= a[i] - res; } return kk >= 0; } int main() { scanf("%d%lld", &n, &k); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= n; i++) scanf("%d", &f[i]); sort(a + 1, a + n + 1), sort(f + 1, f + n + 1, cmp); for (int i = 1; i <= n; i++) { r = max(r, a[i] * f[i]); } l = 0; while (l <= r) { ll mid = l + r >> 1; if (check(mid)) { ans = mid, r = mid - 1; } else l = mid + 1; } printf("%lld", ans); return 0; }
replace
10
16
10
13
TLE