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
p02623
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main(void) { int N, M, K; cin >> N >> M >> K; vector<long long> A(N), B(N); long long A_sum = 0, B_sum = 0; for (int i = 0; i < N; i++) { long long a; cin >> a; A[i] = a; } for (int i = 0; i < M; i++) { long long b; cin >> b; B[M - 1 - i] = b; B_sum += b; } long long j = M; long long ans = 0; for (long long i = 0; i <= N; i++) { while (A_sum + B_sum > K && j > 0) { j--; B_sum -= B[M - 1 - j]; } if (A_sum + B_sum <= K) { ans = max(ans, i + j); } A_sum += A[i]; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main(void) { int N, M, K; cin >> N >> M >> K; vector<long long> A(N), B(M); long long A_sum = 0, B_sum = 0; for (int i = 0; i < N; i++) { long long a; cin >> a; A[i] = a; } for (int i = 0; i < M; i++) { long long b; cin >> b; B[M - 1 - i] = b; B_sum += b; } long long j = M; long long ans = 0; for (long long i = 0; i <= N; i++) { while (A_sum + B_sum > K && j > 0) { j--; B_sum -= B[M - 1 - j]; } if (A_sum + B_sum <= K) { ans = max(ans, i + j); } A_sum += A[i]; } cout << ans << endl; return 0; }
replace
6
7
6
7
-6
Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)
p02623
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long lint; typedef long long llint; typedef pair<int, int> pint; typedef pair<long long, long long> pllint; // static const int MAX = 1e6; // static const int NIL = -1; // static const llint INF = 1<<21; // static const llint MOD = 1e9 + 7; bool compPair(const pint &arg1, const pint &arg2) { return arg1.first > arg2.first; } template <class T> void chmax(T &a, T b) { if (a < b) { a = b; } } template <class T> void chmin(T &a, T b) { if (a > b) { a = b; } } int main(void) { llint n, m, k; cin >> n >> m >> k; vector<llint> asum(n + 1); vector<llint> bsum(m + 1); llint atmp, btmp; for (int in = 0; in < n; in++) { cin >> atmp; asum.at(in + 1) = asum.at(in) + atmp; } for (int im = 0; im < m; im++) { cin >> btmp; bsum.at(im + 1) = bsum.at(im) + btmp; } int ans = 0; for (int in = 0; in <= n; in++) { for (int im = 0; im <= m; im++) { if (asum.at(in) + bsum.at(im) <= k && ans <= in + im) ans = in + im; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long lint; typedef long long llint; typedef pair<int, int> pint; typedef pair<long long, long long> pllint; // static const int MAX = 1e6; // static const int NIL = -1; // static const llint INF = 1<<21; // static const llint MOD = 1e9 + 7; bool compPair(const pint &arg1, const pint &arg2) { return arg1.first > arg2.first; } template <class T> void chmax(T &a, T b) { if (a < b) { a = b; } } template <class T> void chmin(T &a, T b) { if (a > b) { a = b; } } int main(void) { llint n, m, k; cin >> n >> m >> k; vector<llint> asum(n + 1); vector<llint> bsum(m + 1); llint atmp, btmp; for (int in = 0; in < n; in++) { cin >> atmp; asum.at(in + 1) = asum.at(in) + atmp; } for (int im = 0; im < m; im++) { cin >> btmp; bsum.at(im + 1) = bsum.at(im) + btmp; } llint ans = 0, anstmp, bmax = m; for (llint in = 0; in <= n; in++) { for (llint ib = bmax; ib >= 0; ib--) { if (asum.at(in) + bsum.at(ib) <= k) { bmax = ib; anstmp = in + ib; if (ans < anstmp) ans = anstmp; break; } } } cout << ans << endl; return 0; }
replace
43
48
43
53
TLE
p02623
C++
Runtime Error
#include <bits/stdc++.h> #include <iostream> using namespace std; int main() { #ifdef LOCAL_EXEC #else ios_base::sync_with_stdio(false); cin.tie(NULL); #endif // LOCAL_EXEC long long int n, i, j, k, m, ans = 0, a, b, mid; cin >> n >> m >> k; long long int A[n + 1], B[m + 1]; A[0] = 0; B[0] = 0; for (i = 1; i <= n; i++) { cin >> A[i]; A[i] += A[i - 1]; } for (i = 1; i <= m; i++) { cin >> B[i]; B[i] += B[i - 1]; } for (i = 1; i <= n; i++) { if (A[i] > k) break; a = 1; b = m; while (a <= b) { mid = a + (b - a) / 2; if (B[mid] == k - A[i]) { a = mid + 1; break; } else if (B[mid] > k - A[i]) b = mid - 1; else a = mid + 1; } ans = max(ans, i + a - 1); } for (i = 1; i <= m; i++) { if (B[i] > k) break; a = 1; b = m; while (a <= b) { mid = a + (b - a) / 2; if (A[mid] == k - B[i]) { a = mid + 1; break; } else if (A[mid] > k - B[i]) b = mid - 1; else a = mid + 1; } ans = max(ans, i + a - 1); } cout << ans; return 0; }
#include <bits/stdc++.h> #include <iostream> using namespace std; int main() { #ifdef LOCAL_EXEC #else ios_base::sync_with_stdio(false); cin.tie(NULL); #endif // LOCAL_EXEC long long int n, i, j, k, m, ans = 0, a, b, mid; cin >> n >> m >> k; long long int A[n + 1], B[m + 1]; A[0] = 0; B[0] = 0; for (i = 1; i <= n; i++) { cin >> A[i]; A[i] += A[i - 1]; } for (i = 1; i <= m; i++) { cin >> B[i]; B[i] += B[i - 1]; } for (i = 1; i <= n; i++) { if (A[i] > k) break; a = 1; b = m; while (a <= b) { mid = a + (b - a) / 2; if (B[mid] == k - A[i]) { a = mid + 1; break; } else if (B[mid] > k - A[i]) b = mid - 1; else a = mid + 1; } ans = max(ans, i + a - 1); } for (i = 1; i <= m; i++) { if (B[i] > k) break; a = 1; b = n; while (a <= b) { mid = a + (b - a) / 2; if (A[mid] == k - B[i]) { a = mid + 1; break; } else if (A[mid] > k - B[i]) b = mid - 1; else a = mid + 1; } ans = max(ans, i + a - 1); } cout << ans; return 0; }
replace
45
46
45
46
0
p02623
C++
Time Limit Exceeded
/** * author: yuya1234 * created: 30.06.2020 10:57:25 **/ #include <bits/stdc++.h> using namespace std; typedef long long ll; #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 SORT(s) sort((s).begin(), (s).end()) #define SORTD(s) sort((s).rbegin(), (s).rend()) #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()); #define SZ(x) ((int)(x).size()) #define MEMSET(v, h) memset((v), h, sizeof(v)) int main() { cin.tie(0); ios_base::sync_with_stdio(false); int n, m, k; cin >> n >> m >> k; ll a[200001], b[200001]; ll aMax = 1, bMax = 1, tmp, sum = 0; a[0] = b[0] = 0; FOR(i, 1, n) { cin >> tmp; sum += tmp; a[i] = sum; if (sum <= k) { aMax = i + 1; } } sum = 0; FOR(i, 1, m) { cin >> tmp; sum += tmp; b[i] = sum; if (sum <= k) { bMax = i + 1; } } ll ans = 0; REP(i, aMax) { REPD(j, bMax) { if (k >= a[i] + b[j]) { ans = max(ans, i + j); break; } } } cout << ans << endl; return 0; }
/** * author: yuya1234 * created: 30.06.2020 10:57:25 **/ #include <bits/stdc++.h> using namespace std; typedef long long ll; #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 SORT(s) sort((s).begin(), (s).end()) #define SORTD(s) sort((s).rbegin(), (s).rend()) #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()); #define SZ(x) ((int)(x).size()) #define MEMSET(v, h) memset((v), h, sizeof(v)) int main() { cin.tie(0); ios_base::sync_with_stdio(false); int n, m, k; cin >> n >> m >> k; ll a[200001], b[200001]; ll aMax = 1, bMax = 1, tmp, sum = 0; a[0] = b[0] = 0; FOR(i, 1, n) { cin >> tmp; sum += tmp; a[i] = sum; if (sum <= k) { aMax = i + 1; } } sum = 0; FOR(i, 1, m) { cin >> tmp; sum += tmp; b[i] = sum; if (sum <= k) { bMax = i + 1; } } ll ans = 0; REP(i, aMax) { REPD(j, bMax) { if (k >= a[i] + b[j]) { ans = max(ans, i + j); bMax = j + 1; break; } } } cout << ans << endl; return 0; }
insert
57
57
57
58
TLE
p02623
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main(void) { long n, m, k; cin >> n >> m >> k; vector<long> a(n); vector<long> b(m); for (long i = 0; i < n; i++) cin >> a[i]; for (long i = 0; i < m; i++) cin >> b[i]; long total = 0; long c = 0; long cnt = 0; while (true) { if (total + a[c] <= k) { total += a[c]; c++; cnt++; if (c == n) break; } else break; } long A = cnt; long e = 0; while (true) { if (total + b[e] <= k) { total += b[e]; e++; cnt++; if (e == m) break; } else break; } long B = cnt - A; long ans = cnt; for (int i = 0; i < A; i++) { total -= a[A - 1 - i]; cnt--; while (true) { if (total + b[B] <= k) { total += b[B]; B++; cnt++; } else break; } if (cnt > ans) ans = cnt; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main(void) { long n, m, k; cin >> n >> m >> k; vector<long> a(n); vector<long> b(m); for (long i = 0; i < n; i++) cin >> a[i]; for (long i = 0; i < m; i++) cin >> b[i]; long total = 0; long c = 0; long cnt = 0; while (true) { if (total + a[c] <= k) { total += a[c]; c++; cnt++; if (c == n) break; } else break; } long A = cnt; long e = 0; while (true) { if (total + b[e] <= k) { total += b[e]; e++; cnt++; if (e == m) break; } else break; } long B = cnt - A; long ans = cnt; for (int i = 0; i < A; i++) { total -= a[A - 1 - i]; cnt--; while (true) { if (B == m) break; if (total + b[B] <= k) { total += b[B]; B++; cnt++; } else break; } if (cnt > ans) ans = cnt; } cout << ans << endl; }
insert
42
42
42
44
0
p02623
C++
Time Limit Exceeded
#include <iostream> #include <vector> using namespace std; int main() { int n, m, k; vector<int> a, b; vector<int> sum_a, sum_b; int n_max, m_max; cin >> n >> m >> k; for (int i = 0; i < n; i++) { int tmp; cin >> tmp; a.push_back(tmp); } for (int i = 0; i < m; i++) { int tmp; cin >> tmp; b.push_back(tmp); } for (int i = 0; i < n; i++) { int tmp2; if (i == 0) { sum_a.push_back(a[0]); n_max = i + 1; } else { tmp2 = sum_a[i - 1] + a[i]; if (tmp2 <= k) { sum_a.push_back(tmp2); n_max = i + 1; } else { break; } } } for (int i = 0; i < m; i++) { int tmp2; if (i == 0) { sum_b.push_back(b[0]); m_max = i + 1; } else { tmp2 = sum_b[i - 1] + b[i]; if (tmp2 <= k) { sum_b.push_back(tmp2); m_max = i + 1; } else { break; } } } // cout << n_max << " " << m_max << endl; // for (int i = 0; i < n_max; i++) // { // cout << sum_a[i] << " "; // } // cout << endl; // for (int j = 0; j < m_max; j++) // { // cout << sum_b[j] << " "; // } // cout << endl; int max = 0; int sum = 0; // pick 0 books from A // pick j books from B int max_0; for (int j = 0; j < m_max; j++) { if (sum_b[j] <= k) { // cout << sum_b[j] << endl; if (max < j + 1) { max = j + 1; } } else { break; } } max_0 = max; // pick i books from A // pick 0 books from B for (int i = 0; i < n_max; i++) { if (sum_a[i] <= k) { // cout << sum_a[i] << endl; if (max < i + 1) { max = i + 1; } } else { break; } } // pick max_0-1 to 0 books from A // increase the number of books from B for (int l = max_0 - 1; l >= 0; l--) { sum = sum_b[l]; for (int o = 0; o < n_max; o++) { sum = sum_b[l] + sum_a[o]; if (sum <= k) { if (max < l + 1 + o + 1) { max = l + 1 + o + 1; } } else { break; } } } // pick i books from A // pick j books from B // for (int i = 0; i < n_max; i++) // { // // sum = sum_a[i]; // for (int j = 0; j < m_max; j++) // { // sum = sum_a[i] + sum_b[j]; // // cout << sum << endl; // if (sum <= k) // { // if (max < i + 1 + j + 1) // { // max = i + 1 + j + 1; // } // } // else // { // break; // } // } // } cout << max << endl; return 0; }
#include <iostream> #include <vector> using namespace std; int main() { int n, m, k; vector<int> a, b; vector<int> sum_a, sum_b; int n_max, m_max; cin >> n >> m >> k; for (int i = 0; i < n; i++) { int tmp; cin >> tmp; a.push_back(tmp); } for (int i = 0; i < m; i++) { int tmp; cin >> tmp; b.push_back(tmp); } for (int i = 0; i < n; i++) { int tmp2; if (i == 0) { sum_a.push_back(a[0]); n_max = i + 1; } else { tmp2 = sum_a[i - 1] + a[i]; if (tmp2 <= k) { sum_a.push_back(tmp2); n_max = i + 1; } else { break; } } } for (int i = 0; i < m; i++) { int tmp2; if (i == 0) { sum_b.push_back(b[0]); m_max = i + 1; } else { tmp2 = sum_b[i - 1] + b[i]; if (tmp2 <= k) { sum_b.push_back(tmp2); m_max = i + 1; } else { break; } } } // cout << n_max << " " << m_max << endl; // for (int i = 0; i < n_max; i++) // { // cout << sum_a[i] << " "; // } // cout << endl; // for (int j = 0; j < m_max; j++) // { // cout << sum_b[j] << " "; // } // cout << endl; int max = 0; int sum = 0; // pick 0 books from A // pick j books from B int max_0; for (int j = 0; j < m_max; j++) { if (sum_b[j] <= k) { // cout << sum_b[j] << endl; if (max < j + 1) { max = j + 1; } } else { break; } } max_0 = max; // pick i books from A // pick 0 books from B for (int i = 0; i < n_max; i++) { if (sum_a[i] <= k) { // cout << sum_a[i] << endl; if (max < i + 1) { max = i + 1; } } else { break; } } // pick max_0-1 to 0 books from A // increase the number of books from B for (int l = max_0 - 1; l >= 0; l--) { sum = sum_b[l]; for (int o = max - l - 1; o < n_max; o++) { sum = sum_b[l] + sum_a[o]; if (sum <= k) { if (max < l + 1 + o + 1) { max = l + 1 + o + 1; } } else { break; } } } // pick i books from A // pick j books from B // for (int i = 0; i < n_max; i++) // { // // sum = sum_a[i]; // for (int j = 0; j < m_max; j++) // { // sum = sum_a[i] + sum_b[j]; // // cout << sum << endl; // if (sum <= k) // { // if (max < i + 1 + j + 1) // { // max = i + 1 + j + 1; // } // } // else // { // break; // } // } // } cout << max << endl; return 0; }
replace
98
99
98
99
TLE
p02623
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long int ll; // #define rep(i, a, b) for (int i = a; i <= b; i++) #define rep(i, a, b) for (ll i = a; i <= b; i++) #define repr(i, a, b) for (ll i = a; i >= b; i--) int main() { ll n, m, k; cin >> n >> m >> k; ll *a = new ll[n]; ll *b = new ll[m]; rep(i, 0, n - 1) { cin >> a[i]; } rep(i, 0, m - 1) { cin >> b[i]; } ll as = 0; ll bs = 0; ll bp = 0; ll ans = 0; rep(i, 0, n - 1) { as += a[i]; } repr(i, n, 0) { if (i < n) { as -= a[i]; } // as -= a[i]; if (as <= k) { while (bp < m && (as + bs <= k)) { bs += b[i]; bp++; } ans = max(ans, bp + i); } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; // #define rep(i, a, b) for (int i = a; i <= b; i++) #define rep(i, a, b) for (ll i = a; i <= b; i++) #define repr(i, a, b) for (ll i = a; i >= b; i--) int main() { ll n, m, k; cin >> n >> m >> k; ll *a = new ll[n]; ll *b = new ll[m]; rep(i, 0, n - 1) { cin >> a[i]; } rep(i, 0, m - 1) { cin >> b[i]; } ll as = 0; ll bs = 0; ll bp = 0; ll ans = 0; rep(i, 0, n - 1) { as += a[i]; } repr(i, n, 0) { if (i < n) { as -= a[i]; } // as -= a[i]; if (as <= k) { while (bp < m && (as + bs + b[bp] <= k)) { bs += b[bp]; bp++; } ans = max(ans, bp + i); } } cout << ans << endl; }
replace
27
29
27
29
0
p02623
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using str = string; using ll = long long; #define REP(i, n) for (int i = 0; i < int(n); i++) #define RREP(i, n) for (int i = int(n) - 1; i >= 0; i--) #define FOR(i, f, t) for (int i = int(f); i <= int(t); i++) #define RFOR(i, f, t) for (int i = int(f); i >= int(t); i--) #define ALL(vec) (vec).begin(), (vec).end() #define ASORT(vec) sort(ALL(vec)) #define DSORT(vec) sort(ALL(vec), greater<int>()); #define MAX(x) *max_element(ALL(x)) #define MIN(x) *min_element(ALL(x)) #define YES(ans) \ if (ans) \ cout << "YES" << endl; \ else \ cout << "NO" << endl; #define Yes(ans) \ if (ans) \ cout << "Yes" << endl; \ else \ cout << "No" << endl; #define yes(ans) \ if (ans) \ cout << "yes" << endl; \ else \ cout << "no" << endl; int main() { int n, m, k; cin >> n >> m >> k; vector<int> a(n); REP(i, n) cin >> a.at(i); vector<int> b(m); REP(i, m) cin >> b.at(i); vector<ll> a_(n + 1); a_.at(0) = 0; REP(i, n) a_.at(i + 1) = a_.at(i) + a.at(i); vector<ll> b_(m + 1); b_.at(0) = 0; REP(i, m) b_.at(i + 1) = b_.at(i) + b.at(i); int s = 0, a_i = 0, b_i = 0; while (a_.at(a_i) <= k) { a_i++; if (a_i > n) { a_i = n; break; } } while (b_.at(b_i) <= k) { b_i++; if (b_i > m) { b_i = m; break; } } n = a_i + 1; m = b_i + 1; REP(i, n) { REP(j, m) { if (a_.at(i) + b_.at(j) <= k) { if (i + j > s) s = i + j; } else { break; } } } cout << s << endl; }
#include <bits/stdc++.h> using namespace std; using str = string; using ll = long long; #define REP(i, n) for (int i = 0; i < int(n); i++) #define RREP(i, n) for (int i = int(n) - 1; i >= 0; i--) #define FOR(i, f, t) for (int i = int(f); i <= int(t); i++) #define RFOR(i, f, t) for (int i = int(f); i >= int(t); i--) #define ALL(vec) (vec).begin(), (vec).end() #define ASORT(vec) sort(ALL(vec)) #define DSORT(vec) sort(ALL(vec), greater<int>()); #define MAX(x) *max_element(ALL(x)) #define MIN(x) *min_element(ALL(x)) #define YES(ans) \ if (ans) \ cout << "YES" << endl; \ else \ cout << "NO" << endl; #define Yes(ans) \ if (ans) \ cout << "Yes" << endl; \ else \ cout << "No" << endl; #define yes(ans) \ if (ans) \ cout << "yes" << endl; \ else \ cout << "no" << endl; int main() { int n, m, k; cin >> n >> m >> k; vector<int> a(n); REP(i, n) cin >> a.at(i); vector<int> b(m); REP(i, m) cin >> b.at(i); vector<ll> a_(n + 1); a_.at(0) = 0; REP(i, n) a_.at(i + 1) = a_.at(i) + a.at(i); vector<ll> b_(m + 1); b_.at(0) = 0; REP(i, m) b_.at(i + 1) = b_.at(i) + b.at(i); int s = 0, a_i = 0, b_i = 0; while (a_.at(a_i) <= k) { a_i++; if (a_i > n) { a_i = n; break; } } while (b_.at(b_i) <= k) { b_i++; if (b_i > m) { b_i = m; break; } } n = a_i + 1; m = b_i + 1; REP(i, n) { for (int j = max(s - i, 0); j < m; j++) { if (a_.at(i) + b_.at(j) <= k) { if (i + j > s) s = i + j; } else { break; } } } cout << s << endl; }
replace
67
68
67
68
TLE
p02623
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define all(v) v.begin(), v.end() int main() { ll n, m, k; cin >> n >> m >> k; vector<ll> a(n), b(m), aa(n + 1), bb(m + 1), time(n + m + 1); aa[0] = 0; bb[0] = 0; for (ll i = 0; i < n; i++) { cin >> a[i]; } for (ll i = 0; i < m; i++) { cin >> b[i]; } for (ll i = 1; i <= n; i++) { aa[i] = aa[i - 1] + a[i - 1]; } for (ll i = 1; i <= m; i++) { bb[i] = bb[i - 1] + b[i - 1]; } ll max = 0; for (ll j = 0; j <= m; j++) { if (bb[j] <= k) { if (j > max) { max = j; } } else { break; } } ll maxmax = max; for (ll i = 1; i <= n; i++) { if (aa[i] > k) break; for (ll j = max; j >= 0; j--) { if (aa[i] + bb[j] <= k) { if (i + j > maxmax) { maxmax = j + i; } j = max; break; } } } cout << maxmax << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define all(v) v.begin(), v.end() int main() { ll n, m, k; cin >> n >> m >> k; vector<ll> a(n), b(m), aa(n + 1), bb(m + 1), time(n + m + 1); aa[0] = 0; bb[0] = 0; for (ll i = 0; i < n; i++) { cin >> a[i]; } for (ll i = 0; i < m; i++) { cin >> b[i]; } for (ll i = 1; i <= n; i++) { aa[i] = aa[i - 1] + a[i - 1]; } for (ll i = 1; i <= m; i++) { bb[i] = bb[i - 1] + b[i - 1]; } ll max = 0; for (ll j = 0; j <= m; j++) { if (bb[j] <= k) { if (j > max) { max = j; } } else { break; } } ll maxmax = max; for (ll i = 1; i <= n; i++) { if (aa[i] > k) break; for (ll j = max; bb[j] > k - aa[i]; j--) { max--; } if (i + max > maxmax) { maxmax = max + i; } } cout << maxmax << endl; }
replace
41
49
41
46
TLE
p02623
C++
Runtime Error
#include <bits/stdc++.h> #include <time.h> using namespace std; #include <math.h> #define ll long long // to increase precision // std::cout<<std::fixed; // std::cout<<std::setprecision(6)<<z; // clock_t tStart = clock(); // printf("Time taken: %.9fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC); #define maxn 100001 #define ll long long int main() { int n, m, k; cin >> n >> m >> k; vector<long long int> a(n + 1), b(m + 1); a[0] = 0; b[0] = 0; for (int i = 0; i < n; ++i) { int t; cin >> t; a[i + 1] = a[i] + t; } for (int i = 0; i < m; ++i) { int t; cin >> t; b[i + 1] = b[i] + t; } // for(auto x:a) // cout<<x<<" "; // cout<<endl; // for(auto x:b) // cout<<x<<" "; // cout<<endl; int ans = 0; int i = 0; while (b[i] <= k) { long long int res = k - b[i]; // cout<<res<<endl; int ind = upper_bound(a.begin(), a.end(), res) - a.begin(); // cout<<a[ind]<<endl; ans = max(ans, i + ind - 1); // cout<<i<<" "<<ind<<endl; i++; } cout << ans << endl; }
#include <bits/stdc++.h> #include <time.h> using namespace std; #include <math.h> #define ll long long // to increase precision // std::cout<<std::fixed; // std::cout<<std::setprecision(6)<<z; // clock_t tStart = clock(); // printf("Time taken: %.9fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC); #define maxn 100001 #define ll long long int main() { int n, m, k; cin >> n >> m >> k; vector<long long int> a(n + 1), b(m + 1); a[0] = 0; b[0] = 0; for (int i = 0; i < n; ++i) { int t; cin >> t; a[i + 1] = a[i] + t; } for (int i = 0; i < m; ++i) { int t; cin >> t; b[i + 1] = b[i] + t; } // for(auto x:a) // cout<<x<<" "; // cout<<endl; // for(auto x:b) // cout<<x<<" "; // cout<<endl; int ans = 0; int i = 0; while (b[i] <= k && i <= m) { long long int res = k - b[i]; // cout<<res<<endl; int ind = upper_bound(a.begin(), a.end(), res) - a.begin(); // cout<<a[ind]<<endl; ans = max(ans, i + ind - 1); // cout<<i<<" "<<ind<<endl; i++; } cout << ans << endl; }
replace
38
39
38
39
0
p02623
C++
Runtime Error
//{{{ #include <algorithm> #include <cmath> #include <deque> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <sys/time.h> #include <unordered_map> #include <unordered_set> #include <vector> using ll = long long; enum : int { M = (int)1e9 + 7 }; enum : ll { MLL = (ll)1e18L + 9 }; using namespace std; #ifdef LOCAL #include "rprint2.hpp" #else #define FUNC(name) \ template <ostream &out = cout, class... T> void name(T &&...) {} FUNC(printde) FUNC(printdbe) FUNC(printdwe) FUNC(printdu) FUNC(printe) FUNC(printe0); #endif template <template <class T, class = std::allocator<T>> class V, class E> istream &operator>>(istream &in, V<E> &v) { for (auto &e : v) { in >> e; } return in; } //}}} int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, m, k; cin >> n >> m >> k; vector<ll> as(n); cin >> as; vector<ll> bs(m); cin >> bs; vector<ll> acca(n + 1), accb(m + 1); for (int i = 0; i < n; i++) { acca[i + 1] = acca[i] + as[i]; } for (int i = 0; i < m; i++) { accb[i + 1] = acca[i] + bs[i]; } printde(acca); printde(accb); int ans = 0; for (int i = 0; i <= n; i++) { if (acca[i] > k) { break; } ans = max(ans, i + (int)(upper_bound(accb.begin(), accb.end(), k - acca[i]) - accb.begin() - 1)); } cout << ans << '\n'; }
//{{{ #include <algorithm> #include <cmath> #include <deque> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <sys/time.h> #include <unordered_map> #include <unordered_set> #include <vector> using ll = long long; enum : int { M = (int)1e9 + 7 }; enum : ll { MLL = (ll)1e18L + 9 }; using namespace std; #ifdef LOCAL #include "rprint2.hpp" #else #define FUNC(name) \ template <ostream &out = cout, class... T> void name(T &&...) {} FUNC(printde) FUNC(printdbe) FUNC(printdwe) FUNC(printdu) FUNC(printe) FUNC(printe0); #endif template <template <class T, class = std::allocator<T>> class V, class E> istream &operator>>(istream &in, V<E> &v) { for (auto &e : v) { in >> e; } return in; } //}}} int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, m, k; cin >> n >> m >> k; vector<ll> as(n); cin >> as; vector<ll> bs(m); cin >> bs; vector<ll> acca(n + 1), accb(m + 1); for (int i = 0; i < n; i++) { acca[i + 1] = acca[i] + as[i]; } for (int i = 0; i < m; i++) { accb[i + 1] = accb[i] + bs[i]; } printde(acca); printde(accb); int ans = 0; for (int i = 0; i <= n; i++) { if (acca[i] > k) { break; } ans = max(ans, i + (int)(upper_bound(accb.begin(), accb.end(), k - acca[i]) - accb.begin() - 1)); } cout << ans << '\n'; }
replace
52
53
52
53
0
p02623
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<int, int> P; typedef pair<ll, ll> Pll; typedef pair<string, string> Pstring; typedef pair<double, double> Pdouble; #define REP(i, n) for (ll i = 0; i < n; i++) #define REP1(i, n) for (ll i = 1; i <= n; i++) #define Precision13 cout << fixed << setprecision(13) const double PI = 3.14159265358979323846; const int MAX = 510000; const int MOD = 1000000007; const int INF = 1 << 29; using Graph = vector<vector<int>>; int main() { ll n, m, k; cin >> n >> m >> k; vector<ll> a(n + 1); vector<ll> b(m + 1); REP1(i, n) cin >> a[i]; REP1(i, m) cin >> b[i]; vector<ll> asum(n + 1, 0); vector<ll> bsum(m + 1, 0); for (ll i = 1; i <= n; i++) { asum[i] = asum[i - 1] + a[i]; } for (ll i = 1; i <= m; i++) { bsum[i] = bsum[i - 1] + b[i]; } ll ans = 0; ll j = m; for (ll i = 1; i <= n; i++) { if (a[i] > k) { break; } while (asum[i] + bsum[j] > k) { j--; } ans = max(ans, i + j); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<int, int> P; typedef pair<ll, ll> Pll; typedef pair<string, string> Pstring; typedef pair<double, double> Pdouble; #define REP(i, n) for (ll i = 0; i < n; i++) #define REP1(i, n) for (ll i = 1; i <= n; i++) #define Precision13 cout << fixed << setprecision(13) const double PI = 3.14159265358979323846; const int MAX = 510000; const int MOD = 1000000007; const int INF = 1 << 29; using Graph = vector<vector<int>>; int main() { ll n, m, k; cin >> n >> m >> k; vector<ll> a(n + 1); vector<ll> b(m + 1); REP1(i, n) cin >> a[i]; REP1(i, m) cin >> b[i]; vector<ll> asum(n + 1, 0); vector<ll> bsum(m + 1, 0); for (ll i = 1; i <= n; i++) { asum[i] = asum[i - 1] + a[i]; } for (ll i = 1; i <= m; i++) { bsum[i] = bsum[i - 1] + b[i]; } ll ans = 0; ll j = m; for (ll i = 0; i <= n; i++) { if (asum[i] > k) { break; } while (asum[i] + bsum[j] > k) { j--; } ans = max(ans, i + j); } cout << ans << endl; }
replace
39
41
39
41
-11
p02623
C++
Runtime Error
// Compiler optimization #pragma GCC optimize("Ofast") // include #include <bits/stdc++.h> using namespace std; // typedef typedef long long ll; typedef double db; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<string> vs; typedef vector<char> vc; typedef string S; typedef queue<int> qi; typedef pair<ll, ll> P; typedef vector<P> vp; typedef vector<vl> mat; // macro #define reverse(a) reverse(a.begin(), a.end()) #define unique(a) a.erase(unique(a.begin(), a.end()), a.end()) #define fr(i, n) for (ll i = 0; i < (n); i++) #define ifr(i, n) for (ll i = (n)-1; i >= 0; i--) #define all(x) x.begin(), x.end() #define each(x, v) for (auto &x : v) // abbreviation #define pb push_back #define elif else if #define mp make_pair #define endl '\n' // debug #define debug(x) cerr << #x << ": " << x << endl #define v_debug(v) \ cerr << #v << endl; \ fr(i, v.size()) cerr << i << ": " << v[i] << endl // const const ll INF = 1e18; int main() { cin.tie(0); ios::sync_with_stdio(0); cout << setprecision(20); ll n, m, k; cin >> n >> m >> k; vl a(n), b(m); fr(i, n) cin >> a[i]; fr(i, m) cin >> b[i]; vl a_sum(n + 1), b_sum(n + 1); a_sum[0] = b_sum[0] = 0; fr(i, n) a_sum[i + 1] = a_sum[i] + a[i]; fr(i, m) b_sum[i + 1] = b_sum[i] + b[i]; ll ans = 0, now = 0; ll ok = 0, ng = m, mid; fr(i, n + 1) { now = a_sum[i]; // debug(now); if (now + b_sum[m] <= k) { ans = max(ans, i + m); continue; } if (now > k) break; ok = 0; ng = m; while (ng - ok > 1) { mid = (ok + ng) / 2; if (now + b_sum[mid] <= k) ok = mid; else ng = mid; } ans = max(ans, i + ok); } cout << ans << endl; }
// Compiler optimization #pragma GCC optimize("Ofast") // include #include <bits/stdc++.h> using namespace std; // typedef typedef long long ll; typedef double db; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<string> vs; typedef vector<char> vc; typedef string S; typedef queue<int> qi; typedef pair<ll, ll> P; typedef vector<P> vp; typedef vector<vl> mat; // macro #define reverse(a) reverse(a.begin(), a.end()) #define unique(a) a.erase(unique(a.begin(), a.end()), a.end()) #define fr(i, n) for (ll i = 0; i < (n); i++) #define ifr(i, n) for (ll i = (n)-1; i >= 0; i--) #define all(x) x.begin(), x.end() #define each(x, v) for (auto &x : v) // abbreviation #define pb push_back #define elif else if #define mp make_pair #define endl '\n' // debug #define debug(x) cerr << #x << ": " << x << endl #define v_debug(v) \ cerr << #v << endl; \ fr(i, v.size()) cerr << i << ": " << v[i] << endl // const const ll INF = 1e18; int main() { cin.tie(0); ios::sync_with_stdio(0); cout << setprecision(20); ll n, m, k; cin >> n >> m >> k; vl a(n), b(m); fr(i, n) cin >> a[i]; fr(i, m) cin >> b[i]; vl a_sum(n + 1), b_sum(m + 1); a_sum[0] = b_sum[0] = 0; fr(i, n) a_sum[i + 1] = a_sum[i] + a[i]; fr(i, m) b_sum[i + 1] = b_sum[i] + b[i]; ll ans = 0, now = 0; ll ok = 0, ng = m, mid; fr(i, n + 1) { now = a_sum[i]; // debug(now); if (now + b_sum[m] <= k) { ans = max(ans, i + m); continue; } if (now > k) break; ok = 0; ng = m; while (ng - ok > 1) { mid = (ok + ng) / 2; if (now + b_sum[mid] <= k) ok = mid; else ng = mid; } ans = max(ans, i + ok); } cout << ans << endl; }
replace
52
53
52
53
0
p02623
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define repa(i, a, n) for (int i = (a); i < (n); i++) #define rrep(i, n) for (int i = n - 1; i >= 0; i--) #define rrepa(i, a, n) for (int i = n - 1; i >= (a); i--) #define all(a) (a).begin(), (a).end() #define MOD 1000000007 #define cmax(a, b) a = max(a, b) #define cmin(a, b) a = min(a, b) #define vc vector typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<double> vd; typedef vector<vd> vvd; typedef pair<int, int> pi; typedef pair<ll, ll> pl; int main() { int n, m, k; cin >> n >> m >> k; vl sa(n + 1), sb(n + 1); rep(i, n) { int a; cin >> a; sa[i + 1] = sa[i] + a; } rep(i, m) { int b; cin >> b; sb[i + 1] = sb[i] + b; } int idx = m, ans = 0; rep(i, n + 1) { if (sa[i] > k) break; while (idx > 0 && sa[i] + sb[idx] > k) idx--; cmax(ans, i + idx); } cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define repa(i, a, n) for (int i = (a); i < (n); i++) #define rrep(i, n) for (int i = n - 1; i >= 0; i--) #define rrepa(i, a, n) for (int i = n - 1; i >= (a); i--) #define all(a) (a).begin(), (a).end() #define MOD 1000000007 #define cmax(a, b) a = max(a, b) #define cmin(a, b) a = min(a, b) #define vc vector typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<double> vd; typedef vector<vd> vvd; typedef pair<int, int> pi; typedef pair<ll, ll> pl; int main() { int n, m, k; cin >> n >> m >> k; vl sa(n + 1), sb(m + 1); rep(i, n) { int a; cin >> a; sa[i + 1] = sa[i] + a; } rep(i, m) { int b; cin >> b; sb[i + 1] = sb[i] + b; } int idx = m, ans = 0; rep(i, n + 1) { if (sa[i] > k) break; while (idx > 0 && sa[i] + sb[idx] > k) idx--; cmax(ans, i + idx); } cout << ans << "\n"; return 0; }
replace
28
29
28
29
0
p02623
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long int ll; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll n, m, k; cin >> n >> m >> k; vector<ll> a(n + 1), b(m + 1), prefa(m + 1), prefb(m + 1); for (int i = 1; i <= n; i++) { cin >> a[i]; prefa[i] = prefa[i - 1] + a[i]; } for (int i = 1; i <= m; i++) { cin >> b[i]; prefb[i] = prefb[i - 1] + b[i]; } ll ans; if (k >= prefb[m]) ans = m; else if (k < b[1]) ans = 0; else ans = upper_bound(prefb.begin(), prefb.end(), k) - prefb.begin() - 1; for (int i = 1; i <= n; i++) { if (k - prefa[i] < 0) continue; if (k - prefa[i] >= prefb[m]) { ans = max(ans, i + m); continue; } if (k - prefa[i] < b[1]) { ans = max(ans, (ll)i); continue; } ans = max(ans, upper_bound(prefb.begin(), prefb.end(), k - prefa[i]) - prefb.begin() - 1 + (ll)i); } cout << ans << '\n'; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll n, m, k; cin >> n >> m >> k; vector<ll> a(n + 1), b(m + 1), prefa(n + 1), prefb(m + 1); for (int i = 1; i <= n; i++) { cin >> a[i]; prefa[i] = prefa[i - 1] + a[i]; } for (int i = 1; i <= m; i++) { cin >> b[i]; prefb[i] = prefb[i - 1] + b[i]; } ll ans; if (k >= prefb[m]) ans = m; else if (k < b[1]) ans = 0; else ans = upper_bound(prefb.begin(), prefb.end(), k) - prefb.begin() - 1; for (int i = 1; i <= n; i++) { if (k - prefa[i] < 0) continue; if (k - prefa[i] >= prefb[m]) { ans = max(ans, i + m); continue; } if (k - prefa[i] < b[1]) { ans = max(ans, (ll)i); continue; } ans = max(ans, upper_bound(prefb.begin(), prefb.end(), k - prefa[i]) - prefb.begin() - 1 + (ll)i); } cout << ans << '\n'; }
replace
13
14
13
14
0
p02623
C++
Runtime Error
// author rhythmicankur // god_is_almighty #pragma GCC optimize("O3") #pragma GCC target("sse4") #include <bits/stdc++.h> #define f first #define s second #define int long long #define ll int #define ld long double #define pb push_back #define eb emplace_back #define mk make_pair #define vi vector<int> #define pii pair<int, int> #define pip pair<int, pii> #define vpi vector<pii> #define sbcount(x) __builtin_popcountll(x) #define REP(i, n) for (int i = 1; i <= n; i++) #define trav(a, x) for (auto &a : x) #define all(x) x.begin(), x.end() #define fill(a, val) memset(a, val, sizeof(a)) #define PI acos(-1) #define coud(a, b) cout << fixed << setprecision((b)) << (a) #define M1 998244353 #define M2 1000000007 const ll LL_INF = 0x3f3f3f3f3f3f3f3f; template <typename T> T gcd(T a, T b) { if (a == 0) return b; return gcd(b % a, a); } #define test4(x, y, z, a) \ cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << " | " << #a << ": " << a << endl; #define test1(x) cerr << #x << ": " << x << endl #define test2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl #define test3(x, y, z) \ cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl ll power(ll a, ll b, ll m = M2) { ll answer = 1; while (b) { if (b & 1) answer = (answer * a) % m; b /= 2; a = (a * a) % m; } return answer; } using namespace std; void ctrl() { cout << "Control" << endl; } int make_num(string p) { stringstream geek(p); int x = 0; geek >> x; return x; } string make_str(int x) { ostringstream str1; str1 << x; string geek = str1.str(); return geek; } int n, m, k; int pref1[200000 + 5], pref2[200000 + 5]; bool chk(int x) { // test3(n,m,k); if (x > n + m) return false; if (x == 0) return true; // test1(x); if (pref1[x - 1] <= k && x <= n) return true; if (pref2[x - 1] <= k && x <= m) return true; for (int i = 1; i < x; i++) { if (i > n || x - i > m) continue; int val = pref1[i - 1] + pref2[x - i - 1]; // test2(val,x); if (val <= k) return true; } return false; } signed main() { ios::sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit); cin >> n >> m >> k; int A[n], B[m]; for (int i = 0; i < n; i++) cin >> A[i]; for (int i = 0; i < n; i++) { if (!i) pref1[i] = A[i]; else { pref1[i] = pref1[i - 1] + A[i]; } } for (int i = 0; i < m; i++) cin >> B[i]; for (int i = 0; i < m; i++) { if (!i) pref2[i] = B[i]; else { pref2[i] = pref2[i - 1] + B[i]; } } int s = 0; for (int z = n + m; z > 0; z = z / 2) { while (chk(s + z)) s += z; } cout << s; return 0; }
// author rhythmicankur // god_is_almighty #pragma GCC optimize("O3") #pragma GCC target("sse4") #include <bits/stdc++.h> #define f first #define s second #define int long long #define ll int #define ld long double #define pb push_back #define eb emplace_back #define mk make_pair #define vi vector<int> #define pii pair<int, int> #define pip pair<int, pii> #define vpi vector<pii> #define sbcount(x) __builtin_popcountll(x) #define REP(i, n) for (int i = 1; i <= n; i++) #define trav(a, x) for (auto &a : x) #define all(x) x.begin(), x.end() #define fill(a, val) memset(a, val, sizeof(a)) #define PI acos(-1) #define coud(a, b) cout << fixed << setprecision((b)) << (a) #define M1 998244353 #define M2 1000000007 const ll LL_INF = 0x3f3f3f3f3f3f3f3f; template <typename T> T gcd(T a, T b) { if (a == 0) return b; return gcd(b % a, a); } #define test4(x, y, z, a) \ cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << " | " << #a << ": " << a << endl; #define test1(x) cerr << #x << ": " << x << endl #define test2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl #define test3(x, y, z) \ cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl ll power(ll a, ll b, ll m = M2) { ll answer = 1; while (b) { if (b & 1) answer = (answer * a) % m; b /= 2; a = (a * a) % m; } return answer; } using namespace std; void ctrl() { cout << "Control" << endl; } int make_num(string p) { stringstream geek(p); int x = 0; geek >> x; return x; } string make_str(int x) { ostringstream str1; str1 << x; string geek = str1.str(); return geek; } int n, m, k; int pref1[500000 + 5], pref2[500000 + 5]; bool chk(int x) { // test3(n,m,k); if (x > n + m) return false; if (x == 0) return true; // test1(x); if (pref1[x - 1] <= k && x <= n) return true; if (pref2[x - 1] <= k && x <= m) return true; for (int i = 1; i < x; i++) { if (i > n || x - i > m) continue; int val = pref1[i - 1] + pref2[x - i - 1]; // test2(val,x); if (val <= k) return true; } return false; } signed main() { ios::sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit); cin >> n >> m >> k; int A[n], B[m]; for (int i = 0; i < n; i++) cin >> A[i]; for (int i = 0; i < n; i++) { if (!i) pref1[i] = A[i]; else { pref1[i] = pref1[i - 1] + A[i]; } } for (int i = 0; i < m; i++) cin >> B[i]; for (int i = 0; i < m; i++) { if (!i) pref2[i] = B[i]; else { pref2[i] = pref2[i - 1] + B[i]; } } int s = 0; for (int z = n + m; z > 0; z = z / 2) { while (chk(s + z)) s += z; } cout << s; return 0; }
replace
66
67
66
67
0
p02623
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; int n, m, k; vi a, b; bool Read() { cin >> n; if (cin.eof()) return 0; cin >> m >> k; a.resize(n); b.resize(m); for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m; i++) cin >> b[i]; return 1; } void Process() { int ans = 0, x = 0; ll suma = 0; for (int i = 0; i <= n && suma <= k; i++) { int y = 0; ll sumb = 0; for (int j = 0; j <= m && suma + sumb <= k; j++) { ans = max(ans, x + y); ++y; sumb += j < m ? b[j] : 0; } ++x; suma += i < n ? a[i] : 0; } cout << ans << "\n"; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); while (Read()) Process(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; int n, m, k; vi a, b; bool Read() { cin >> n; if (cin.eof()) return 0; cin >> m >> k; a.resize(n); b.resize(m); for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m; i++) cin >> b[i]; return 1; } void Process() { vector<ll> psaa(n), psab(m); psaa[0] = a[0]; psab[0] = b[0]; for (int i = 1; i < n; i++) psaa[i] = psaa[i - 1] + a[i]; for (int i = 1; i < m; i++) psab[i] = psab[i - 1] + b[i]; int i = 0, j = 0; while (i < n && psaa[i] <= k) i++; int ans = i; while (i >= 0) { const ll t = i ? psaa[i - 1] : 0; while (j < m && t + psab[j] <= k) j++; ans = max(ans, i + j); i--; } cout << ans << "\n"; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); while (Read()) Process(); return 0; }
replace
24
36
24
41
TLE
p02623
C++
Time Limit Exceeded
#include <algorithm> #include <cstdio> #include <iostream> #include <locale.h> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> using namespace std; int main() { int n, m, k; long long int a[200002], b[200002]; // int possa = 0; long long int ssx = 0, ax; // scanf("%d %d %d", &n, &m, &k); for (int i = 1; i <= n; i++) { scanf("%lld", &a[i]); ssx += a[i]; if (ssx <= k) { possa = i; ax = ssx; } // possaはAだけ読んだ時に読める本の数 その時にかかる時間がax } for (int i = 1; i <= m; i++) { scanf("%lld", &b[i]); } int nj = 1; long long int bx = 0; // int ans = possa; for (int i = possa; i >= 0; i--) { for (int j = nj; j <= m; j++) { if (ax + bx + b[nj] <= k) { bx += b[nj]; nj++; ans = max(ans, (i + j)); } } ax -= a[i]; // axはiを読むまでにかかる時間を表す } printf("%d", ans); }
#include <algorithm> #include <cstdio> #include <iostream> #include <locale.h> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> using namespace std; int main() { int n, m, k; long long int a[200002], b[200002]; // int possa = 0; long long int ssx = 0, ax; // scanf("%d %d %d", &n, &m, &k); for (int i = 1; i <= n; i++) { scanf("%lld", &a[i]); ssx += a[i]; if (ssx <= k) { possa = i; ax = ssx; } // possaはAだけ読んだ時に読める本の数 その時にかかる時間がax } for (int i = 1; i <= m; i++) { scanf("%lld", &b[i]); } int nj = 1; long long int bx = 0; // int ans = possa; for (int i = possa; i >= 0; i--) { for (int j = nj; j <= m; j++) { if (ax + bx + b[nj] <= k) { bx += b[nj]; nj++; ans = max(ans, (i + j)); } else { break; } } ax -= a[i]; // axはiを読むまでにかかる時間を表す } printf("%d", ans); }
insert
37
37
37
39
TLE
p02623
C++
Runtime Error
#include <bits/stdc++.h> #define _GLIBCXX_DEBUG #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep1(i, n) for (int i = 1; i < (n); ++i) using namespace std; typedef long long ll; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); ll n, m, k; cin >> n >> m >> k; vector<ll> a(n + 1, 0), b(m + 1, 0); rep(i, n) cin >> a[i + 1]; rep(i, n) a[i + 1] += a[i]; rep(i, m) cin >> b[i + 1]; rep(i, m) b[i + 1] += b[i]; int b_cnt = m; int res = 0; rep(a_cnt, n + 1) { while (a[a_cnt] + b[b_cnt] > k) --b_cnt; res = max(res, a_cnt + b_cnt); } cout << res << endl; return 0; }
#include <bits/stdc++.h> #define _GLIBCXX_DEBUG #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep1(i, n) for (int i = 1; i < (n); ++i) using namespace std; typedef long long ll; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); ll n, m, k; cin >> n >> m >> k; vector<ll> a(n + 1, 0), b(m + 1, 0); rep(i, n) cin >> a[i + 1]; rep(i, n) a[i + 1] += a[i]; rep(i, m) cin >> b[i + 1]; rep(i, m) b[i + 1] += b[i]; int b_cnt = m; int res = 0; rep(a_cnt, n + 1) { if (a[a_cnt] > k) break; while (a[a_cnt] + b[b_cnt] > k) --b_cnt; res = max(res, a_cnt + b_cnt); } cout << res << endl; return 0; }
insert
22
22
22
24
-11
p02623
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; long long int psumA[100001]; long long int psumB[100001]; int A[100001], B[100001]; int main(void) { cin.tie(0); ios::sync_with_stdio(false); int n, m, k; cin >> n >> m >> k; for (int i = 1; i <= n; i++) { cin >> A[i]; } for (int i = 1; i <= m; i++) { cin >> B[i]; } for (int i = 1; i <= n; i++) { psumA[i] = psumA[i - 1] + A[i]; } for (int i = 1; i <= m; i++) { psumB[i] = psumB[i - 1] + B[i]; } int res = 0; for (int i = 0; i <= n; i++) { if (psumA[i] > k) { break; } int lo = 0; int hi = m; int Max = 0; long long int val = k - psumA[i]; while (lo <= hi) { int mid = (lo + hi) / 2; if (psumB[mid] <= val) { Max = max(Max, mid); lo = mid + 1; } else { hi = mid - 1; } } res = max(res, i + Max); } cout << res << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; long long int psumA[200001]; long long int psumB[200001]; int A[200001], B[200001]; int main(void) { cin.tie(0); ios::sync_with_stdio(false); int n, m, k; cin >> n >> m >> k; for (int i = 1; i <= n; i++) { cin >> A[i]; } for (int i = 1; i <= m; i++) { cin >> B[i]; } for (int i = 1; i <= n; i++) { psumA[i] = psumA[i - 1] + A[i]; } for (int i = 1; i <= m; i++) { psumB[i] = psumB[i - 1] + B[i]; } int res = 0; for (int i = 0; i <= n; i++) { if (psumA[i] > k) { break; } int lo = 0; int hi = m; int Max = 0; long long int val = k - psumA[i]; while (lo <= hi) { int mid = (lo + hi) / 2; if (psumB[mid] <= val) { Max = max(Max, mid); lo = mid + 1; } else { hi = mid - 1; } } res = max(res, i + Max); } cout << res << '\n'; return 0; }
replace
4
7
4
7
0
p02623
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ll n, m, k = 0; cin >> n >> m >> k; vector<ll> a(n); vector<ll> b(m); for (ll i = 0; i < n; i++) { cin >> a[i]; } for (ll i = 0; i < m; i++) { cin >> b[i]; } vector<ll> aSum(n + 1); vector<ll> bSum(m + 1); aSum[0] = 0; bSum[0] = 0; for (ll i = 1; i < n + 1; i++) { aSum[i] = a[i - 1] + aSum[i - 1]; } for (ll i = 1; i < m + 1; i++) { bSum[i] = b[i - 1] + bSum[i - 1]; } /* for(ll i = 0;i <= n;i++){ cout << aSum[i] << endl; } for(ll i = 0;i <= m;i++){ cout << bSum[i] << endl; } */ ll bCP = m; ll sum = 0; for (ll i = 0; i <= n; i++) { if (aSum[i] > k) { continue; } for (ll j = bCP; j >= 0; j--) { if (aSum[i] + bSum[j] <= k) { bCP = j + 1; break; } } // cout << aSum[i] << " " << bSum[bCP] << endl; sum = max(sum, i + bCP); } cout << sum << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ll n, m, k = 0; cin >> n >> m >> k; vector<ll> a(n); vector<ll> b(m); for (ll i = 0; i < n; i++) { cin >> a[i]; } for (ll i = 0; i < m; i++) { cin >> b[i]; } vector<ll> aSum(n + 1); vector<ll> bSum(m + 1); aSum[0] = 0; bSum[0] = 0; for (ll i = 1; i < n + 1; i++) { aSum[i] = a[i - 1] + aSum[i - 1]; } for (ll i = 1; i < m + 1; i++) { bSum[i] = b[i - 1] + bSum[i - 1]; } /* for(ll i = 0;i <= n;i++){ cout << aSum[i] << endl; } for(ll i = 0;i <= m;i++){ cout << bSum[i] << endl; } */ ll bCP = m; ll sum = 0; for (ll i = 0; i <= n; i++) { if (aSum[i] > k) { continue; } for (ll j = bCP; j >= 0; j--) { if (aSum[i] + bSum[j] <= k) { bCP = j; break; } } // cout << aSum[i] << " " << bSum[bCP] << endl; sum = max(sum, i + bCP); } cout << sum << endl; return 0; }
replace
42
43
42
43
0
p02623
C++
Runtime Error
#include <bits/stdc++.h> #include <iostream> #define ll long long int #define boost \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) #define md 1000000007 double PI = 3.1415926535; const int N = (int)(1 * 1e6 + 10); using namespace std; int main() { ll n, m, k; cin >> n >> m >> k; ll a[n + 1], b[m + 1]; ll A[n + 1], B[m + 1]; A[0] = 0; B[0] = 0; for (ll i = 1; i <= n; i++) { cin >> a[i]; A[i] = A[i - 1] + a[i]; } for (ll i = 1; i <= m; i++) { cin >> b[i]; B[i] = B[i - 1] + b[i]; } ll j = m, ans = 0; for (ll i = 1; i <= n; i++) { if (B[j] > k) j--; while (A[i] + B[j] > k) j--; ans = max(ans, i + j); } cout << ans << endl; }
#include <bits/stdc++.h> #include <iostream> #define ll long long int #define boost \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) #define md 1000000007 double PI = 3.1415926535; const int N = (int)(1 * 1e6 + 10); using namespace std; int main() { ll n, m, k; cin >> n >> m >> k; ll a[n + 1], b[m + 1]; ll A[n + 1], B[m + 1]; A[0] = 0; B[0] = 0; for (ll i = 1; i <= n; i++) { cin >> a[i]; A[i] = A[i - 1] + a[i]; } for (ll i = 1; i <= m; i++) { cin >> b[i]; B[i] = B[i - 1] + b[i]; } ll j = m, ans = 0; for (ll i = 0; i <= n; i++) { if (A[i] > k) break; while (A[i] + B[j] > k) j--; ans = max(ans, i + j); } cout << ans << endl; }
replace
28
31
28
31
0
p02623
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define pb emplace_back #define fi first #define se second #define all(x) (x).begin(), (x).end() #define ll long long #define pii pair<int, int> int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); int n, m, k; cin >> n >> m >> k; vector<int> a(n), b(m); for (auto &c : a) cin >> c; for (auto &c : b) cin >> c; ll now = 0; for (auto &c : a) now += c; int j = 0, ans = 0; for (int i = n; i >= 0; i--) { if (i < n) now -= a[i]; while (j < m && now + a[j] <= k) { now += a[j]; j++; } if (now <= k) ans = max(ans, i + j); } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define pb emplace_back #define fi first #define se second #define all(x) (x).begin(), (x).end() #define ll long long #define pii pair<int, int> int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); int n, m, k; cin >> n >> m >> k; vector<int> a(n), b(m); for (auto &c : a) cin >> c; for (auto &c : b) cin >> c; ll now = 0; for (auto &c : a) now += c; int j = 0, ans = 0; for (int i = n; i >= 0; i--) { if (i < n) now -= a[i]; while (j < m && now + b[j] <= k) { now += b[j]; j++; } if (now <= k) ans = max(ans, i + j); } cout << ans; return 0; }
replace
29
31
29
31
0
p02623
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(0); ll N; cin >> N; ll M; cin >> M; ll K; cin >> K; vector<ll> A(N); for (ll i = 0; i < N; i++) cin >> A[i]; vector<ll> B(M); for (ll i = 0; i < M; i++) cin >> B[i]; vector<ll> sumA(N + 1, 0); vector<ll> sumB(M + 1, 0); for (ll i = 0; i < N; i++) sumA[i + 1] = sumA[i] + A[i]; for (ll i = 0; i < M; i++) sumB[i + 1] = sumB[i] + B[i]; ll ans = 0; ll b = 0; for (ll i = N; i >= 0; i--) { while (sumA[i] + sumB[b] <= K) { ans = max(ans, i + b); b++; b = min(b, M); } } cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(0); ll N; cin >> N; ll M; cin >> M; ll K; cin >> K; vector<ll> A(N); for (ll i = 0; i < N; i++) cin >> A[i]; vector<ll> B(M); for (ll i = 0; i < M; i++) cin >> B[i]; vector<ll> sumA(N + 1, 0); vector<ll> sumB(M + 1, 0); for (ll i = 0; i < N; i++) sumA[i + 1] = sumA[i] + A[i]; for (ll i = 0; i < M; i++) sumB[i + 1] = sumB[i] + B[i]; ll ans = 0; ll b = 0; for (ll i = N; i >= 0; i--) { while (sumA[i] + sumB[b] <= K) { ans = max(ans, i + b); b++; if (b > M) { b = M; break; } } } cout << ans << '\n'; return 0; }
replace
34
35
34
38
TLE
p02623
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define M_PI 3.1415926535 #define ll long long #define ld long double #define all(a) a.begin(), a.end() #define Summon_Tourist \ ios::sync_with_stdio(false); \ cin.tie(0); ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll inf = 1e9 + 7; ll modexp(ll base, ll power) { if (power == 0) return 1; if (power & 1) return base * modexp(base, power - 1) % inf; return modexp(base * base % inf, power / 2); } int main() { Summon_Tourist freopen("input.txt", "r", stdin); ll t = 1; // cin>>t; while (t--) { ll n, m, k; cin >> n >> m >> k; vector<ll> a(n), b(m); vector<ll> prefa(n, 0), prefb(m, 0); ll ma = -1; for (ll i = 0; i < n; i++) { cin >> a[i]; if (i == 0) prefa[i] = a[i]; else prefa[i] = a[i] + prefa[i - 1]; } for (ll i = 0; i < m; i++) { cin >> b[i]; if (i == 0) prefb[i] = b[i]; else prefb[i] = b[i] + prefb[i - 1]; if (prefb[i] <= k) ma = i + 1; } for (ll i = 0; i < n; i++) { ll temp = 0; ll tempmax = k; if (prefa[i] <= k) { temp = i + 1; tempmax -= prefa[i]; } ll y = lower_bound(prefb.begin(), prefb.end(), tempmax) - prefb.begin(); if ((y < m && tempmax < prefb[y]) || y == m) { --y; } temp += (y + 1); ma = max(ma, temp); } cout << ma; } return 0; }
#include <bits/stdc++.h> using namespace std; #define M_PI 3.1415926535 #define ll long long #define ld long double #define all(a) a.begin(), a.end() #define Summon_Tourist \ ios::sync_with_stdio(false); \ cin.tie(0); ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll inf = 1e9 + 7; ll modexp(ll base, ll power) { if (power == 0) return 1; if (power & 1) return base * modexp(base, power - 1) % inf; return modexp(base * base % inf, power / 2); } int main() { Summon_Tourist // freopen("input.txt" , "r" , stdin ); ll t = 1; // cin>>t; while (t--) { ll n, m, k; cin >> n >> m >> k; vector<ll> a(n), b(m); vector<ll> prefa(n, 0), prefb(m, 0); ll ma = -1; for (ll i = 0; i < n; i++) { cin >> a[i]; if (i == 0) prefa[i] = a[i]; else prefa[i] = a[i] + prefa[i - 1]; } for (ll i = 0; i < m; i++) { cin >> b[i]; if (i == 0) prefb[i] = b[i]; else prefb[i] = b[i] + prefb[i - 1]; if (prefb[i] <= k) ma = i + 1; } for (ll i = 0; i < n; i++) { ll temp = 0; ll tempmax = k; if (prefa[i] <= k) { temp = i + 1; tempmax -= prefa[i]; } ll y = lower_bound(prefb.begin(), prefb.end(), tempmax) - prefb.begin(); if ((y < m && tempmax < prefb[y]) || y == m) { --y; } temp += (y + 1); ma = max(ma, temp); } cout << ma; } return 0; }
replace
21
23
21
24
0
p02623
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; const int N = 2e5 + 10, mod = 1e9 + 7; void solve() { int n, m, k; cin >> n >> m >> k; ll a[n + 1], b[m + 1]; a[0] = 0, b[0] = 0; for (int i = 1; i <= n; ++i) { int in; cin >> in; a[i] = a[i - 1] + in; } for (int i = 1; i <= m; ++i) { int in; cin >> in; b[i] = b[i - 1] + in; } int ans = 0; for (int i = 0; i <= n; ++i) { if (a[i] > k) { break; } int j = m; while (a[i] + b[j] > k) { --j; } ans = max(ans, i + j); } cout << ans << endl; } int main(void) { int t = 1; while (t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; const int N = 2e5 + 10, mod = 1e9 + 7; void solve() { int n, m, k; cin >> n >> m >> k; ll a[n + 1], b[m + 1]; a[0] = 0, b[0] = 0; for (int i = 1; i <= n; ++i) { int in; cin >> in; a[i] = a[i - 1] + in; } for (int i = 1; i <= m; ++i) { int in; cin >> in; b[i] = b[i - 1] + in; } int ans = 0; int j = m; for (int i = 0; i <= n && a[i] <= k; ++i) { while (a[i] + b[j] > k) { --j; } ans = max(ans, i + j); } cout << ans << endl; } int main(void) { int t = 1; while (t--) solve(); return 0; }
replace
26
32
26
28
TLE
p02623
C++
Runtime Error
#include <bits/stdc++.h> #define fi first #define se second #define pb push_back #define mp make_pair #define maxn 500005 #define inf int(21e8) #define mod int(1e9 + 7) #define db double #define ll long long #define si stack<int> #define qi queue<int> #define vi vector<int> #define pi pair<int, int> #define pq priority_queue<int, vector<int>, greater<int>> using namespace std; ll powmod(ll a, ll b) { ll res = 1; a %= mod; for (; b; b >>= 1) res = (res * ((b & 1) ? a : 1)) % mod, a = a * a % mod; return res; } ll gcd(ll a, ll b) { return b ? gcd(a, b) : a; } ll a[500005], b[500005]; ll sa[500005], sb[500005]; int main() { int n, m, k; cin >> n >> m >> k; for (int i = 1; i <= n; i++) cin >> a[i], sa[i] = sa[i - 1] + a[i]; for (int i = 1; i <= m; i++) cin >> b[i], sb[i] = sb[i - 1] + b[i]; int now = 1, ans = 0; for (int i = n; i >= 1; i--) { while (sa[i] + sb[now] <= k && now <= m) now++; now--; ans = max(ans, i + now); } cout << ans << endl; system("pause"); return 0; }
#include <bits/stdc++.h> #define fi first #define se second #define pb push_back #define mp make_pair #define maxn 500005 #define inf int(21e8) #define mod int(1e9 + 7) #define db double #define ll long long #define si stack<int> #define qi queue<int> #define vi vector<int> #define pi pair<int, int> #define pq priority_queue<int, vector<int>, greater<int>> using namespace std; ll powmod(ll a, ll b) { ll res = 1; a %= mod; for (; b; b >>= 1) res = (res * ((b & 1) ? a : 1)) % mod, a = a * a % mod; return res; } ll gcd(ll a, ll b) { return b ? gcd(a, b) : a; } ll a[500005], b[500005]; ll sa[500005], sb[500005]; int main() { int n, m, k; cin >> n >> m >> k; for (int i = 1; i <= n; i++) cin >> a[i], sa[i] = sa[i - 1] + a[i]; for (int i = 1; i <= m; i++) cin >> b[i], sb[i] = sb[i - 1] + b[i]; int now = m, ans = 0; for (int i = 0; i <= n; i++) { while (sa[i] + sb[now] > k && now > 0) now--; if (sa[i] + sb[now] <= k) ans = max(ans, i + now); } cout << ans << endl; system("pause"); return 0; }
replace
33
39
33
39
0
sh: 1: pause: not found
p02623
C++
Runtime Error
/****************************************************************************** Online C++ Compiler. Code, Compile, Run and Debug C++ program online. Write your code in this editor and press "Run" button to compile and execute it. *******************************************************************************/ #include <iostream> using namespace std; long long puf[200004], suf[200004], k, n, m; bool func(long long x) { long long sum = 0LL; if (x == 0LL) { return true; } for (long long i = 1; i <= x; i++) { if (x >= i + 1 && i <= n) { sum = suf[i] + puf[x - i]; if (sum <= k) { return true; } } // cout<<"bbb"; } if ((x <= n && suf[x] <= k) || (x <= m && puf[x] <= k)) { return true; } return false; } int main() { long long i, lo, hi, mid; cin >> n >> m >> k; long long arr[n + 1], brr[m + 1]; for (i = 1; i <= n; i++) { cin >> arr[i]; } for (i = 1; i <= m; i++) { cin >> brr[i]; } // if(arr[0]>k&&brr[0]>k){cout<<0;return 0;} for (i = 1; i <= n; i++) { if (i == 1) { suf[i] = arr[i]; } else { suf[i] = suf[i - 1] + arr[i]; } } for (i = 1; i <= m; i++) { if (i == 1) { puf[i] = brr[i]; } else { puf[i] = puf[i - 1] + brr[i]; } } // for(i=1;i<=n;i++){cout<<suf[i]<<" "<<puf[i]<<" "<<i<<"\n";} lo = 0LL; hi = n + m; while (lo < hi) { // cout<<func(1)<<"aa "; mid = lo + (hi - lo + 1) / 2; if (func(mid)) { lo = mid; } else { hi = mid - 1; } } cout << lo; return 0; }
/****************************************************************************** Online C++ Compiler. Code, Compile, Run and Debug C++ program online. Write your code in this editor and press "Run" button to compile and execute it. *******************************************************************************/ #include <iostream> using namespace std; long long puf[200004], suf[200004], k, n, m; bool func(long long x) { long long sum = 0LL; if (x == 0LL) { return true; } for (long long i = 1; i <= x; i++) { if (x >= i + 1 && i <= n && x - i <= m) { sum = suf[i] + puf[x - i]; if (sum <= k) { return true; } } // cout<<"bbb"; } if ((x <= n && suf[x] <= k) || (x <= m && puf[x] <= k)) { return true; } return false; } int main() { long long i, lo, hi, mid; cin >> n >> m >> k; long long arr[n + 1], brr[m + 1]; for (i = 1; i <= n; i++) { cin >> arr[i]; } for (i = 1; i <= m; i++) { cin >> brr[i]; } // if(arr[0]>k&&brr[0]>k){cout<<0;return 0;} for (i = 1; i <= n; i++) { if (i == 1) { suf[i] = arr[i]; } else { suf[i] = suf[i - 1] + arr[i]; } } for (i = 1; i <= m; i++) { if (i == 1) { puf[i] = brr[i]; } else { puf[i] = puf[i - 1] + brr[i]; } } // for(i=1;i<=n;i++){cout<<suf[i]<<" "<<puf[i]<<" "<<i<<"\n";} lo = 0LL; hi = n + m; while (lo < hi) { // cout<<func(1)<<"aa "; mid = lo + (hi - lo + 1) / 2; if (func(mid)) { lo = mid; } else { hi = mid - 1; } } cout << lo; return 0; }
replace
19
20
19
20
0
p02623
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { int N, M; cin >> N >> M; long long K; cin >> K; long long a; vector<long long> A(N + 1); vector<long long> B(M + 1); A[0] = 0; B[0] = 0; for (int i = 1; i < N + 1; i++) { cin >> a; A[i] = A[i - 1] + a; } for (int i = 1; i < M + 1; i++) { cin >> a; B[i] = B[i - 1] + a; } int ans = 0; int J = M; for (int i = 0; i < N + 1; i++) { if (A[i] > K) break; for (int j = 0; j < J + 1; j++) { if ((A[i] + B[j]) > K) { J = j; break; } ans = max(ans, i + j); } } cout << ans << endl; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { int N, M; cin >> N >> M; long long K; cin >> K; long long a; vector<long long> A(N + 1); vector<long long> B(M + 1); A[0] = 0; B[0] = 0; for (int i = 1; i < N + 1; i++) { cin >> a; A[i] = A[i - 1] + a; } for (int i = 1; i < M + 1; i++) { cin >> a; B[i] = B[i - 1] + a; } int ans = 0; int J = M; for (int i = 0; i < N + 1; i++) { if (A[i] > K) break; auto it = upper_bound(B.begin(), B.end(), K - A[i]); int j = it - B.begin(); ans = max(ans, i + j - 1); } cout << ans << endl; }
replace
28
35
28
31
TLE
p02623
C++
Time Limit Exceeded
#include <bits/stdc++.h> #include <iostream> using namespace std; #define SZ(c) int(c.size()) #define pb push_back #define loop(i, start, n) for (int i = start; i < n; i++) #define rloop(i, start, n) for (int i = start; i > n; i--) using ll = long long; using vi = vector<int>; using vll = vector<ll>; using vvi = vector<vi>; using vs = vector<string>; const ll inf = 2e9 + 3; void solve() { int tc = 1; // cin >> tc; while (tc--) { ll n, m, k, res = 0; cin >> n >> m >> k; vll va(n + 1), vb(m + 1); ll A = 0, B = 0; loop(i, 1, n + 1) { cin >> va[i]; va[i] = va[i] + va[i - 1]; } loop(i, 1, m + 1) { cin >> vb[i]; vb[i] = vb[i] + vb[i - 1]; } ll b = m, a = n; loop(i, 1, n + 1) if (va[i] <= k) a = i; loop(i, 1, m + 1) if (vb[i] <= k) b = i; // res = a; rloop(i, a, -1) { loop(j, 0, b + 1) { if (va[i] + vb[j] <= k) res = max(res, (ll)(i + j)); } } cout << res; } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); solve(); return 0; }
#include <bits/stdc++.h> #include <iostream> using namespace std; #define SZ(c) int(c.size()) #define pb push_back #define loop(i, start, n) for (int i = start; i < n; i++) #define rloop(i, start, n) for (int i = start; i > n; i--) using ll = long long; using vi = vector<int>; using vll = vector<ll>; using vvi = vector<vi>; using vs = vector<string>; const ll inf = 2e9 + 3; void solve() { int tc = 1; // cin >> tc; while (tc--) { ll n, m, k, res = 0; cin >> n >> m >> k; vll va(n + 1), vb(m + 1); ll A = 0, B = 0; loop(i, 1, n + 1) { cin >> va[i]; va[i] = va[i] + va[i - 1]; } loop(i, 1, m + 1) { cin >> vb[i]; vb[i] = vb[i] + vb[i - 1]; } ll b = m, a = n; loop(i, 1, n + 1) if (va[i] <= k) a = i; loop(i, 1, m + 1) if (vb[i] <= k) b = i; loop(i, 0, a + 1) { if (vb[b] <= k - va[i]) res = max(res, i + b); else b--; /*loop(j,0,b+1) { if (va[i] + vb[j] <= k) res = max(res,(ll)(i+j)); }*/ } cout << res; } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); solve(); return 0; }
replace
34
40
34
42
TLE
p02623
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int n, m, K, ans; long long a[100004], b[100004]; int main() { cin >> n >> m >> K; for (int i = 1; i <= n; i++) cin >> a[i], a[i] = a[i - 1] + a[i]; for (int i = 1; i <= m; i++) cin >> b[i], b[i] = b[i - 1] + b[i]; for (int i = 0; i <= n; i++) if (K >= a[i]) { int res = upper_bound(b + 1, b + 1 + m, K - a[i]) - b - 1; ans = max(ans, res + i); } cout << ans; }
#include <bits/stdc++.h> using namespace std; int n, m, K, ans; long long a[200004], b[200004]; int main() { cin >> n >> m >> K; for (int i = 1; i <= n; i++) cin >> a[i], a[i] = a[i - 1] + a[i]; for (int i = 1; i <= m; i++) cin >> b[i], b[i] = b[i - 1] + b[i]; for (int i = 0; i <= n; i++) if (K >= a[i]) { int res = upper_bound(b + 1, b + 1 + m, K - a[i]) - b - 1; ans = max(ans, res + i); } cout << ans; }
replace
3
4
3
4
0
p02623
C++
Time Limit Exceeded
#include <algorithm> #include <bits/stdc++.h> #include <climits> #include <cmath> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <utility> #include <vector> using namespace std; using ll = long long int; #define REP(i, n) for (ll i = 0; i < (ll)(n); i++) // REP(i, 5) cout<<i; #define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--) #define FOR(i, a, b) for (ll i = (a); i <= (b); i++) #define MOD 1000000007 // 10^9+7 // #define MOD 1 ll gcd(ll a, ll b) { ll tmp; if (b > a) { tmp = a; a = b; b = tmp; } while (a % b != 0) { tmp = b; b = a % b; a = tmp; } return b; } const int MAX = 2000; long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } void sosuu(ll n, vector<ll> &v) { vector<ll> num(n, 0); FOR(i, 1, sqrt(n)) { if (num[i] == 0) { FOR(j, 0, n / i) { num[i + (j * i)] = 1; } } } REP(i, n) { if (num[i] == 0) v.push_back(i + 1); } } ll GetDigit(ll num) { ll digit = 0; while (num != 0) { num /= 10; digit++; } return digit; } ll power(ll a, ll b) { ll ans = 1; if (b % 2 == 0) { REP(i, b / 2) { ans *= a; if (ans > 1000000000) { return -1; } } return ans * ans; } else { b = b / 2; REP(i, b) { ans *= a; if (ans > 1000000000) { return -1; } } return ans * ans * a; } } vector<pair<long long, long long>> prime_factorize(long long N) { vector<pair<long long, long long>> res; for (long long a = 2; a * a <= N; ++a) { if (N % a != 0) continue; long long ex = 0; // 指数 // 割れる限り割り続ける while (N % a == 0) { ++ex; N /= a; } // その結果を push res.push_back({a, ex}); } // 最後に残った数について if (N != 1) res.push_back({N, 1}); return res; } int main(void) { ll n, m, k; cin >> n >> m >> k; vector<ll> a(n); vector<ll> b(m); vector<ll> a_sum(n + 1); vector<ll> b_sum(m + 1); a_sum[0] = 0; b_sum[0] = 0; REP(i, n) { ll x; cin >> x; a[i] = x; // if(i!=0) a_sum[i + 1] = a_sum[i] + x; // else a_sum[i] = x; // cout<<a[i]<<" "; } // cout<<endl; REP(i, m) { ll x; cin >> x; b[i] = x; // if(i!=0) b_sum[i + 1] = b_sum[i] + x; // else b_sum[i] = x; // cout<<b[i]<<" "; } // cout<<endl; // REP(i, n+1) cout<<a_sum[i]<<" "; // cout<<endl; // REP(i, m+1) cout<<b_sum[i]<<" "; // cout<<endl; ll ans = 0; REP(i, n + 1) { ll left = 0; ll right = b_sum.size() - 1; ll mid = (left + right) / 2; if (a_sum[i] + b_sum[mid] < k) { left = mid; } else { right = mid; } // cout<<left<<" "<<mid<<" "<<right<<endl; for (ll j = left; j <= right; j++) { // cout<<i<<" "<<j<<endl; if (a_sum[i] + b_sum[j] <= k) { ans = max(ans, i + j); // if(i==j && i==0) ans -=2; // else if(i==0 || j==0) ans-=1; // cout<<ans<<endl; } else break; } } cout << ans << endl; return 0; }
#include <algorithm> #include <bits/stdc++.h> #include <climits> #include <cmath> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <utility> #include <vector> using namespace std; using ll = long long int; #define REP(i, n) for (ll i = 0; i < (ll)(n); i++) // REP(i, 5) cout<<i; #define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--) #define FOR(i, a, b) for (ll i = (a); i <= (b); i++) #define MOD 1000000007 // 10^9+7 // #define MOD 1 ll gcd(ll a, ll b) { ll tmp; if (b > a) { tmp = a; a = b; b = tmp; } while (a % b != 0) { tmp = b; b = a % b; a = tmp; } return b; } const int MAX = 2000; long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } void sosuu(ll n, vector<ll> &v) { vector<ll> num(n, 0); FOR(i, 1, sqrt(n)) { if (num[i] == 0) { FOR(j, 0, n / i) { num[i + (j * i)] = 1; } } } REP(i, n) { if (num[i] == 0) v.push_back(i + 1); } } ll GetDigit(ll num) { ll digit = 0; while (num != 0) { num /= 10; digit++; } return digit; } ll power(ll a, ll b) { ll ans = 1; if (b % 2 == 0) { REP(i, b / 2) { ans *= a; if (ans > 1000000000) { return -1; } } return ans * ans; } else { b = b / 2; REP(i, b) { ans *= a; if (ans > 1000000000) { return -1; } } return ans * ans * a; } } vector<pair<long long, long long>> prime_factorize(long long N) { vector<pair<long long, long long>> res; for (long long a = 2; a * a <= N; ++a) { if (N % a != 0) continue; long long ex = 0; // 指数 // 割れる限り割り続ける while (N % a == 0) { ++ex; N /= a; } // その結果を push res.push_back({a, ex}); } // 最後に残った数について if (N != 1) res.push_back({N, 1}); return res; } int main(void) { ll n, m, k; cin >> n >> m >> k; vector<ll> a(n); vector<ll> b(m); vector<ll> a_sum(n + 1); vector<ll> b_sum(m + 1); a_sum[0] = 0; b_sum[0] = 0; REP(i, n) { ll x; cin >> x; a[i] = x; // if(i!=0) a_sum[i + 1] = a_sum[i] + x; // else a_sum[i] = x; // cout<<a[i]<<" "; } // cout<<endl; REP(i, m) { ll x; cin >> x; b[i] = x; // if(i!=0) b_sum[i + 1] = b_sum[i] + x; // else b_sum[i] = x; // cout<<b[i]<<" "; } // cout<<endl; // REP(i, n+1) cout<<a_sum[i]<<" "; // cout<<endl; // REP(i, m+1) cout<<b_sum[i]<<" "; // cout<<endl; ll ans = 0; REP(i, n + 1) { ll left = 0; ll right = b_sum.size() - 1; ll mid = (left + right) / 2; ll count = 0; while (count != 1000) { if (a_sum[i] + b_sum[mid] < k) { left = mid; } else { right = mid; } mid = (left + right) / 2; count++; } // cout<<left<<" "<<mid<<" "<<right<<endl; for (ll j = left; j <= right; j++) { // cout<<i<<" "<<j<<endl; if (a_sum[i] + b_sum[j] <= k) { ans = max(ans, i + j); // if(i==j && i==0) ans -=2; // else if(i==0 || j==0) ans-=1; // cout<<ans<<endl; } else break; } } cout << ans << endl; return 0; }
replace
178
182
178
187
TLE
p02623
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cmath> #include <iostream> #include <list> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <tuple> #include <vector> // ceil(a/b) (a + (b - 1))/ b using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) typedef long long ll; typedef pair<int, int> P; const int inf = 1000000007; const ll mod = 1000000007; const double PI = 3.14159265358979323846; int dx[] = {1, -1, 0, 0}; int dy[] = {0, 0, 1, -1}; ll gcd(ll a, ll b) { if (b == 0) return a; else return gcd(b, a % b); } int cans(bool f) { if (f) cout << "Yes" << endl; else cout << "No" << endl; return 0; } int main() { ll N, M, K; ll ans = 0; cin >> N >> M >> K; ll a[N]; ll b[M]; vector<ll> Acum(N, 0); vector<ll> Bcum(M, 0); Acum[0] = 0; Bcum[0] = 0; ll posb = 0; rep(i, N) { cin >> a[i]; Acum[i + 1] += Acum[i] + a[i]; } rep(i, M) { cin >> b[i]; Bcum[i + 1] += Bcum[i] + b[i]; } posb = M; for (ll posa = 0; posa < N + 1; posa++) { if (K < Acum[posa]) break; while (Acum[posa] + Bcum[posb] > K) { posb--; if (posb == 0) break; } // cout << posa << " " << posb << endl; ans = max(ans, posa + posb); } cout << ans << endl; return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <iostream> #include <list> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <tuple> #include <vector> // ceil(a/b) (a + (b - 1))/ b using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) typedef long long ll; typedef pair<int, int> P; const int inf = 1000000007; const ll mod = 1000000007; const double PI = 3.14159265358979323846; int dx[] = {1, -1, 0, 0}; int dy[] = {0, 0, 1, -1}; ll gcd(ll a, ll b) { if (b == 0) return a; else return gcd(b, a % b); } int cans(bool f) { if (f) cout << "Yes" << endl; else cout << "No" << endl; return 0; } int main() { ll N, M, K; ll ans = 0; cin >> N >> M >> K; ll a[N]; ll b[M]; vector<ll> Acum(N + 1, 0); vector<ll> Bcum(M + 1, 0); Acum[0] = 0; Bcum[0] = 0; ll posb = 0; rep(i, N) { cin >> a[i]; Acum[i + 1] += Acum[i] + a[i]; } rep(i, M) { cin >> b[i]; Bcum[i + 1] += Bcum[i] + b[i]; } posb = M; for (ll posa = 0; posa < N + 1; posa++) { if (K < Acum[posa]) break; while (Acum[posa] + Bcum[posb] > K) { posb--; if (posb == 0) break; } // cout << posa << " " << posb << endl; ans = max(ans, posa + posb); } cout << ans << endl; return 0; }
replace
47
49
47
49
-6
munmap_chunk(): invalid pointer
p02623
C++
Runtime Error
// ░░░░░░░░( •̪●)░░░░░░░░░░░░░░░░░░░░░░░░ // ░░░░░░███████ ]▄▄▄▄▄▄▄▄▃░░░▃░░░░ ▃░ // ▂▄▅█████████▅▄▃▂░░░░░░░░░░░░░░░░░ // [███████████████████].░░░░░░░░░░░░░░ // ◥⊙▲⊙▲⊙▲⊙▲⊙▲⊙▲⊙◤...░░░░░░░░░░░░ // PointBlank's code (⌐■_■) #include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; ll power(ll x, ll y); #define repp(I, A, B) for (int I = A; I <= B; I++) #define rep(I, A, B) for (int I = A; I < B; I++) #define rrep(I, B, A) for (int I = B; I >= A; I--) #define pb emplace_back #define ff first #define ss second #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define LB lower_bound #define UB upper_bound #define MP make_pair #define mem(A, B) memset(A, B, sizeof(A)); #define mem0(A) memset(A, 0, sizeof(A)); #define quickio \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define debug(this) cerr << "> " << #this << " : " << this << "\n" #define bitcount(n) __builtin_popcountll(n) #define in_edges(M) \ repp(I, 1, M) { \ ll A, B; \ cin >> A >> B; \ v[A].pb(B), v[B].pb(A); \ } #define in_edges2(M) \ repp(I, 1, M) { \ ll A, B; \ cin >> A >> B; \ v[A].pb(B); \ } #define endl "\n" const ll MOD = 1000000007; const int MX = 1e6 + 5; int a[MX], b[MX]; ll pa[MX], pb[MX]; int n, m; ll k; bool chk(int x) { // if(n + m < x) return 0; repp(i, 0, n) { int A = i, B = x - A; if (B > m || A > n) continue; if (pa[A] + pb[B] <= k) return 1; } return 0; } int main() // PointBlank's code ¯\_(ツ)_/¯ { quickio cin >> n >> m >> k; repp(i, 1, n) cin >> a[i]; repp(i, 1, m) cin >> b[i]; rep(i, 1, MX) pa[i] = pa[i - 1] + a[i], pb[i] = pb[i - 1] + b[i]; ll l = 0, r = n + m + 1; while (l <= r) { ll mid = (l + r) / 2; if (chk(mid)) l = mid + 1; else r = mid - 1; } cout << r; } ll power(ll x, ll y) { ll res = 1; x %= MOD; while (y > 0) { if (y & 1) res = (res * x) % MOD; y = y >> 1, x = (x * x) % MOD; } return res; }
// ░░░░░░░░( •̪●)░░░░░░░░░░░░░░░░░░░░░░░░ // ░░░░░░███████ ]▄▄▄▄▄▄▄▄▃░░░▃░░░░ ▃░ // ▂▄▅█████████▅▄▃▂░░░░░░░░░░░░░░░░░ // [███████████████████].░░░░░░░░░░░░░░ // ◥⊙▲⊙▲⊙▲⊙▲⊙▲⊙▲⊙◤...░░░░░░░░░░░░ // PointBlank's code (⌐■_■) #include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; ll power(ll x, ll y); #define repp(I, A, B) for (int I = A; I <= B; I++) #define rep(I, A, B) for (int I = A; I < B; I++) #define rrep(I, B, A) for (int I = B; I >= A; I--) #define pb emplace_back #define ff first #define ss second #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define LB lower_bound #define UB upper_bound #define MP make_pair #define mem(A, B) memset(A, B, sizeof(A)); #define mem0(A) memset(A, 0, sizeof(A)); #define quickio \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define debug(this) cerr << "> " << #this << " : " << this << "\n" #define bitcount(n) __builtin_popcountll(n) #define in_edges(M) \ repp(I, 1, M) { \ ll A, B; \ cin >> A >> B; \ v[A].pb(B), v[B].pb(A); \ } #define in_edges2(M) \ repp(I, 1, M) { \ ll A, B; \ cin >> A >> B; \ v[A].pb(B); \ } #define endl "\n" const ll MOD = 1000000007; const int MX = 1e6 + 5; int a[MX], b[MX]; ll pa[MX], pb[MX]; int n, m; ll k; bool chk(int x) { // if(n + m < x) return 0; repp(i, 0, x) { int A = i, B = x - A; if (B > m || A > n) continue; if (pa[A] + pb[B] <= k) return 1; } return 0; } int main() // PointBlank's code ¯\_(ツ)_/¯ { quickio cin >> n >> m >> k; repp(i, 1, n) cin >> a[i]; repp(i, 1, m) cin >> b[i]; rep(i, 1, MX) pa[i] = pa[i - 1] + a[i], pb[i] = pb[i - 1] + b[i]; ll l = 0, r = n + m + 1; while (l <= r) { ll mid = (l + r) / 2; if (chk(mid)) l = mid + 1; else r = mid - 1; } cout << r; } ll power(ll x, ll y) { ll res = 1; x %= MOD; while (y > 0) { if (y & 1) res = (res * x) % MOD; y = y >> 1, x = (x * x) % MOD; } return res; }
replace
57
58
57
58
0
p02623
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < n; i++) #define all(x) (x).begin(), (x).end() #define INF 1000000007 #define mod 1005 #define ll long long int const double mx = 2e6 + 5; void solve() { ll n, m, k; ll maxPos = 0; cin >> n >> m >> k; // cout<<"nmk\n"; vector<ll> a(n + 1), b(m + 1); a[0] = b[0] = 0; // cout<<"workng\n"; for (int i = 1; i <= n; i++) { cin >> a[i]; a[i] += a[i - 1]; // cout<<a[i]<<" "; } // cout<<"working\n"; for (int i = 1; i <= m; i++) { cin >> b[i]; b[i] += b[i - 1]; // cout<<b[i]<<" "; } // cout<<"\n"; for (int i = 0; i <= n; i++) { ll diff = k - a[i]; ll ans = 0; if (diff < 0) break; ll low = 1, high = m; while (low <= high) { ll mid = low + (high - low) / 2; if (b[mid] <= diff) { ans = mid; low = mid + 1; } else { high = mid - 1; } } maxPos = max(maxPos, ans + i); } cout << maxPos << "\n"; } int main() { // ios_base::sync_with_stdio(false); // cin.tie(NULL); freopen("abc172dInput.txt", "r", stdin); int t = 1; // cin>>t; while (t--) { // cout<<"ENTER\n"; solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < n; i++) #define all(x) (x).begin(), (x).end() #define INF 1000000007 #define mod 1005 #define ll long long int const double mx = 2e6 + 5; void solve() { ll n, m, k; ll maxPos = 0; cin >> n >> m >> k; // cout<<"nmk\n"; vector<ll> a(n + 1), b(m + 1); a[0] = b[0] = 0; // cout<<"workng\n"; for (int i = 1; i <= n; i++) { cin >> a[i]; a[i] += a[i - 1]; // cout<<a[i]<<" "; } // cout<<"working\n"; for (int i = 1; i <= m; i++) { cin >> b[i]; b[i] += b[i - 1]; // cout<<b[i]<<" "; } // cout<<"\n"; for (int i = 0; i <= n; i++) { ll diff = k - a[i]; ll ans = 0; if (diff < 0) break; ll low = 1, high = m; while (low <= high) { ll mid = low + (high - low) / 2; if (b[mid] <= diff) { ans = mid; low = mid + 1; } else { high = mid - 1; } } maxPos = max(maxPos, ans + i); } cout << maxPos << "\n"; } int main() { // ios_base::sync_with_stdio(false); // cin.tie(NULL); // freopen("abc172dInput.txt", "r", stdin); int t = 1; // cin>>t; while (t--) { // cout<<"ENTER\n"; solve(); } return 0; }
replace
51
52
51
52
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p02623
C++
Runtime Error
#include <bits/stdc++.h> // Begin Header {{{ using namespace std; using ll = long long; using P = pair<ll, ll>; using Graph = vector<vector<ll>>; #define rep(i, n) for (ll i = 0; i < n; i++) #define loop(i, j, n) for (ll i = j; i < n; i++) #define all(x) (x).begin(), (x).end() constexpr int INF = 0x3f3f3f3f; const long long mod = 1e9 + 7; const long double PI = acos(-1); // }}} End Header int main() { int n, m, k; cin >> n >> m >> k; vector<ll> a(n); vector<ll> b(n); rep(i, n) cin >> a[i]; rep(i, m) cin >> b[i]; ll t = 0; rep(i, m) t += b[i]; int j = m; int ans = 0; rep(i, n + 1) { while (j > 0 && t > k) { --j; t -= b[j]; } if (t > k) break; if (ans < i + j) ans = i + j; // ans = max(ans, i+j); if (i >= n) break; t += a[i]; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> // Begin Header {{{ using namespace std; using ll = long long; using P = pair<ll, ll>; using Graph = vector<vector<ll>>; #define rep(i, n) for (ll i = 0; i < n; i++) #define loop(i, j, n) for (ll i = j; i < n; i++) #define all(x) (x).begin(), (x).end() constexpr int INF = 0x3f3f3f3f; const long long mod = 1e9 + 7; const long double PI = acos(-1); // }}} End Header int main() { int n, m, k; cin >> n >> m >> k; vector<ll> a(n); vector<ll> b(m); rep(i, n) cin >> a[i]; rep(i, m) cin >> b[i]; ll t = 0; rep(i, m) t += b[i]; int j = m; int ans = 0; rep(i, n + 1) { while (j > 0 && t > k) { --j; t -= b[j]; } if (t > k) break; if (ans < i + j) ans = i + j; // ans = max(ans, i+j); if (i >= n) break; t += a[i]; } cout << ans << endl; return 0; }
replace
17
18
17
18
-6
Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)
p02623
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, start, end) for (long long i = start; i < end; ++i) #define repreverse(i, start, end) for (long long i = start; i >= end; --i) #define all(x) (x).begin(), (x).end() #define len(x) ((long long)(x).size()) #define lcm(a, b) ((a) / __gcd((a), (b)) * (b)) using namespace std; using ll = long long; using ld = long double; using vll = vector<ll>; using vllvll = vector<vll>; using pll = pair<ll, ll>; template <class T> void print1d(T x, ll n = -1) { if (n == -1) n = x.size(); rep(i, 0, n) { cout << x[i] << ' '; } cout << '\n'; } template <class T> void print2d(T x, ll r = -1, ll c = -1) { if (r == -1) r = x.size(); if (c == -1) c = x[0].size(); rep(i, 0, r) print1d(x[i], c); } template <class T, class U> bool haskey(T mp, U key) { return mp.find(key) != mp.end(); } template <class T, class U> bool isin(T el, U container) { return find(all(container), el) != container.end(); } 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> bool even(T n) { return !(n & 1); } template <class T> bool odd(T n) { return n & 1; } template <class T> ld deg2rad(T deg) { return M_PI * deg / 180.0; } template <class T> ld rad2deg(T rad) { return 180.0 * rad / M_PI; } ll intpow(ll a, ll n) { ll p = 1; while (n) { if (n & 1) p *= a; a *= a; n >>= 1; } return p; } const long double pi = M_PI; const long long big = 1LL << 50; const long long inf = 1LL << 60; const long long mod = 1e9 + 7; int main() { ll N, M, K; cin >> N >> M >> K; vll A(N), B(M); rep(i, 0, N) cin >> A[i]; rep(i, 0, M) cin >> B[i]; vll acc1(N + 1), acc2(M + 1); rep(i, 1, N + 1) acc1[i] += acc1[i - 1] + A[i - 1]; rep(i, 1, M + 1) acc2[i] += acc2[i - 1] + B[i - 1]; ll ans = 0; rep(i, 0, N) { if (K - acc1[i + 1] < 0) break; ll pos = upper_bound(all(acc2), K - acc1[i + 1]) - acc2.begin() - 1; ll tmp = max(pos, 0LL); chmax(ans, i + 1 + tmp); } rep(i, 0, N) { if (K - acc2[i + 1] < 0) break; ll pos = upper_bound(all(acc1), K - acc2[i + 1]) - acc1.begin() - 1; ll tmp = max(pos, 0LL); chmax(ans, i + 1 + tmp); } cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, start, end) for (long long i = start; i < end; ++i) #define repreverse(i, start, end) for (long long i = start; i >= end; --i) #define all(x) (x).begin(), (x).end() #define len(x) ((long long)(x).size()) #define lcm(a, b) ((a) / __gcd((a), (b)) * (b)) using namespace std; using ll = long long; using ld = long double; using vll = vector<ll>; using vllvll = vector<vll>; using pll = pair<ll, ll>; template <class T> void print1d(T x, ll n = -1) { if (n == -1) n = x.size(); rep(i, 0, n) { cout << x[i] << ' '; } cout << '\n'; } template <class T> void print2d(T x, ll r = -1, ll c = -1) { if (r == -1) r = x.size(); if (c == -1) c = x[0].size(); rep(i, 0, r) print1d(x[i], c); } template <class T, class U> bool haskey(T mp, U key) { return mp.find(key) != mp.end(); } template <class T, class U> bool isin(T el, U container) { return find(all(container), el) != container.end(); } 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> bool even(T n) { return !(n & 1); } template <class T> bool odd(T n) { return n & 1; } template <class T> ld deg2rad(T deg) { return M_PI * deg / 180.0; } template <class T> ld rad2deg(T rad) { return 180.0 * rad / M_PI; } ll intpow(ll a, ll n) { ll p = 1; while (n) { if (n & 1) p *= a; a *= a; n >>= 1; } return p; } const long double pi = M_PI; const long long big = 1LL << 50; const long long inf = 1LL << 60; const long long mod = 1e9 + 7; int main() { ll N, M, K; cin >> N >> M >> K; vll A(N), B(M); rep(i, 0, N) cin >> A[i]; rep(i, 0, M) cin >> B[i]; vll acc1(N + 1), acc2(M + 1); rep(i, 1, N + 1) acc1[i] += acc1[i - 1] + A[i - 1]; rep(i, 1, M + 1) acc2[i] += acc2[i - 1] + B[i - 1]; ll ans = 0; rep(i, 0, N) { if (K - acc1[i + 1] < 0) break; ll pos = upper_bound(all(acc2), K - acc1[i + 1]) - acc2.begin() - 1; ll tmp = max(pos, 0LL); chmax(ans, i + 1 + tmp); } rep(i, 0, M) { if (K - acc2[i + 1] < 0) break; ll pos = upper_bound(all(acc1), K - acc2[i + 1]) - acc1.begin() - 1; ll tmp = max(pos, 0LL); chmax(ans, i + 1 + tmp); } cout << ans << endl; }
replace
83
84
83
84
0
p02623
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define pb push_back using namespace std; typedef long long ll; int main() { ll n, m, k; cin >> n >> m >> k; vector<ll> a(n), b(m); rep(i, n) cin >> a[i]; rep(i, m) cin >> b[i]; vector<ll> c(n + 1), d(n + 1); rep(i, n) c[i + 1] = c[i] + a[i]; rep(j, m) d[j + 1] = d[j] + b[j]; ll ans = 0; rep(i, n + 1) { ll time = c[i]; if (time > k) continue; int p = upper_bound(d.begin(), d.end(), k - time) - d.begin(); if (p == m && time + d[m] <= k) ans = max(ans, (ll)p + i); else ans = max(ans, (ll)p + i - 1); } cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define pb push_back using namespace std; typedef long long ll; int main() { ll n, m, k; cin >> n >> m >> k; vector<ll> a(n), b(m); rep(i, n) cin >> a[i]; rep(i, m) cin >> b[i]; vector<ll> c(n + 1), d(m + 1); rep(i, n) c[i + 1] = c[i] + a[i]; rep(j, m) d[j + 1] = d[j] + b[j]; ll ans = 0; rep(i, n + 1) { ll time = c[i]; if (time > k) continue; int p = upper_bound(d.begin(), d.end(), k - time) - d.begin(); if (p == m && time + d[m] <= k) ans = max(ans, (ll)p + i); else ans = max(ans, (ll)p + i - 1); } cout << ans << endl; }
replace
13
14
13
14
0
p02623
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> #include <vector> int main() { int N, M, K; std::cin >> N >> M >> K; std::vector<unsigned long long> A, B; A.resize(N + 1); for (int i = 0; i < N; i++) { int tmp; std::cin >> tmp; A[i + 1] = A[i] + tmp; } B.resize(M + 1); for (int i = 0; i < M; i++) { int tmp; std::cin >> tmp; B[i + 1] = B[i] + tmp; } int max = 0; int an = std::upper_bound(A.begin(), A.end(), K) - A.begin(); for (int i = 0; i < an; i++) { int j; for (j = 0; j < B.size(); j++) { if (A[i] + B[j] > K) break; } max = std::max(max, i + j - 1); } std::cout << max << std::endl; }
#include <algorithm> #include <iostream> #include <vector> int main() { int N, M, K; std::cin >> N >> M >> K; std::vector<unsigned long long> A, B; A.resize(N + 1); for (int i = 0; i < N; i++) { int tmp; std::cin >> tmp; A[i + 1] = A[i] + tmp; } B.resize(M + 1); for (int i = 0; i < M; i++) { int tmp; std::cin >> tmp; B[i + 1] = B[i] + tmp; } int max = 0; int an = std::upper_bound(A.begin(), A.end(), K) - A.begin() - 1; for (int i = an; i >= 0; i--) { int j = std::upper_bound(B.begin(), B.end(), K - A[i]) - B.begin(); max = std::max(max, i + j - 1); } std::cout << max << std::endl; }
replace
21
28
21
24
TLE
p02623
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define ll long long int #define ull unsigned long long #define ld long double #define mod 1000000007 #define EULER 2.7182818284 #define INF 1000000000 #define pb push_back #define ins insert #define IT iterator #define PQ priority_queue #define nl "\n" #define fi first #define se second #define maxe max_element #define mine min_element #define er erase #define lb lower_bound #define ub upper_bound #define vi vector<int> #define vll vector<ll> #define vb vector<bool> #define pi pair<int, int> #define pll pair<ll, ll> #define all(v) v.begin(), v.end() #define mem(v, i) \ memset( \ v, i, \ sizeof( \ v)) // v is array. To set all elements to 0 or -1 only. mem(arr,0); #define repab(i, a, b) for (int i = (a); i <= (b); i++) #define reprab(i, a, b) for (int i = (a); i >= (b); i--) #define repll(i, a, b) for (ll i = (a); i <= (b); i++) #define rep(i, n) for (int i = (0); i < (n); i++) #define repr(i, n) for (int i = (n); i >= 0; i--) #define bs bitset #define bpc(a) __builtin_popcount(a) #define tc \ int t; \ cin >> t; \ while (t--) template <typename T> void TIME(T start, T end) { #ifndef ONLINE_JUDGE double time_taken = chrono::duration_cast<chrono::nanoseconds>(end - start).count(); time_taken *= 1e-9; cout << "\nExecuted in: " << fixed << time_taken << setprecision(9); cout << " sec"; #endif } int dx[] = {1, -1, 0, 0}; int dy[] = {0, 0, 1, -1}; ll max(ll a, ll b) { if (a > b) return a; return b; } ll min(ll a, ll b) { if (a < b) return a; return b; } ll mypow(ll a, ll b) { ll res = 1; while (b > 0) { if (b & 1) res = res * a; a = a * a; b >>= 1; } return res; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } //..............................!!!!!!Get ready to //fight!!!!!!............................ int main() { auto start = chrono::high_resolution_clock::now(); fast ll n, m, k; cin >> n >> m >> k; vll a(n + 1), b(m + 1); rep(i, n) cin >> a[i]; rep(i, m) cin >> b[i]; vll suma(n + 1), sumb(n + 1); suma[0] = 0; sumb[0] = 0; rep(i, n) { suma[i + 1] = suma[i] + a[i]; } rep(i, m) { sumb[i + 1] = sumb[i] + b[i]; } ll total = 0; for (ll i = 0; i <= n; i++) { ll rem = k - suma[i]; if (rem < 0) continue; ll l = lower_bound(sumb.begin(), sumb.end(), rem) - sumb.begin(); if (l > m || sumb[l] > rem) l--; total = max(total, i + l); } cout << total << nl; auto end = chrono::high_resolution_clock::now(); TIME(start, end); return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define ll long long int #define ull unsigned long long #define ld long double #define mod 1000000007 #define EULER 2.7182818284 #define INF 1000000000 #define pb push_back #define ins insert #define IT iterator #define PQ priority_queue #define nl "\n" #define fi first #define se second #define maxe max_element #define mine min_element #define er erase #define lb lower_bound #define ub upper_bound #define vi vector<int> #define vll vector<ll> #define vb vector<bool> #define pi pair<int, int> #define pll pair<ll, ll> #define all(v) v.begin(), v.end() #define mem(v, i) \ memset( \ v, i, \ sizeof( \ v)) // v is array. To set all elements to 0 or -1 only. mem(arr,0); #define repab(i, a, b) for (int i = (a); i <= (b); i++) #define reprab(i, a, b) for (int i = (a); i >= (b); i--) #define repll(i, a, b) for (ll i = (a); i <= (b); i++) #define rep(i, n) for (int i = (0); i < (n); i++) #define repr(i, n) for (int i = (n); i >= 0; i--) #define bs bitset #define bpc(a) __builtin_popcount(a) #define tc \ int t; \ cin >> t; \ while (t--) template <typename T> void TIME(T start, T end) { #ifndef ONLINE_JUDGE double time_taken = chrono::duration_cast<chrono::nanoseconds>(end - start).count(); time_taken *= 1e-9; cout << "\nExecuted in: " << fixed << time_taken << setprecision(9); cout << " sec"; #endif } int dx[] = {1, -1, 0, 0}; int dy[] = {0, 0, 1, -1}; ll max(ll a, ll b) { if (a > b) return a; return b; } ll min(ll a, ll b) { if (a < b) return a; return b; } ll mypow(ll a, ll b) { ll res = 1; while (b > 0) { if (b & 1) res = res * a; a = a * a; b >>= 1; } return res; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } //..............................!!!!!!Get ready to //fight!!!!!!............................ int main() { auto start = chrono::high_resolution_clock::now(); fast ll n, m, k; cin >> n >> m >> k; vll a(n + 1), b(m + 1); rep(i, n) cin >> a[i]; rep(i, m) cin >> b[i]; vll suma(n + 1), sumb(m + 1); suma[0] = 0; sumb[0] = 0; rep(i, n) { suma[i + 1] = suma[i] + a[i]; } rep(i, m) { sumb[i + 1] = sumb[i] + b[i]; } ll total = 0; for (ll i = 0; i <= n; i++) { ll rem = k - suma[i]; if (rem < 0) continue; ll l = lower_bound(sumb.begin(), sumb.end(), rem) - sumb.begin(); if (l > m || sumb[l] > rem) l--; total = max(total, i + l); } cout << total << nl; auto end = chrono::high_resolution_clock::now(); TIME(start, end); return 0; }
replace
109
110
109
110
0
p02623
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef vector<vector<int>> vvi; typedef vector<vector<bool>> vvb; typedef vector<vector<char>> vvc; typedef vector<int> vi; typedef vector<bool> vb; typedef vector<char> vc; typedef vector<long long> vl; int main() { long long N, M, K; cin >> N >> M >> K; vl a(N + 2), b(M + 2); a[0] = 0; b[0] = 0; a[N + 1] = 1e12; b[N + 1] = 1e12; for (int i = 1; i <= N; i++) { cin >> a[i]; } for (int i = 1; i <= M; i++) { cin >> b[i]; } for (int i = 1; i <= N; i++) { a[i] += a[i - 1]; } for (int i = 1; i <= M; i++) { b[i] += b[i - 1]; } long long ans = 0; for (int i = 0; i <= M; i++) { if (b[i] > K) break; long long index = upper_bound(a.begin(), a.end(), K - b[i]) - a.begin(); // cout << i << " " << index-1 << endl; if (index != 0) index--; ans = max(ans, i + index); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef vector<vector<int>> vvi; typedef vector<vector<bool>> vvb; typedef vector<vector<char>> vvc; typedef vector<int> vi; typedef vector<bool> vb; typedef vector<char> vc; typedef vector<long long> vl; int main() { long long N, M, K; cin >> N >> M >> K; vl a(N + 2), b(M + 2); a[0] = 0; b[0] = 0; a[N + 1] = 1e12; b[M + 1] = 1e12; for (int i = 1; i <= N; i++) { cin >> a[i]; } for (int i = 1; i <= M; i++) { cin >> b[i]; } for (int i = 1; i <= N; i++) { a[i] += a[i - 1]; } for (int i = 1; i <= M; i++) { b[i] += b[i - 1]; } long long ans = 0; for (int i = 0; i <= M; i++) { if (b[i] > K) break; long long index = upper_bound(a.begin(), a.end(), K - b[i]) - a.begin(); // cout << i << " " << index-1 << endl; if (index != 0) index--; ans = max(ans, i + index); } cout << ans << endl; return 0; }
replace
18
19
18
19
0
p02623
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) int main() { int n, m, k; cin >> n >> m >> k; vector<long> a(n + 1, 0); vector<long> b(m + 1, 0); for (int i = 1; i <= n; i++) { cin >> a[i]; a[i] += a[i - 1]; } for (int i = 1; i <= m; i++) { cin >> b[i]; b[i] += b[i - 1]; } int b_sum = m, max = 0; for (int i = 0; i <= n; i++) { while (a[i] + b[b_sum] > k) b_sum--; if (i + b_sum > max) max = i + b_sum; } cout << max << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) int main() { int n, m, k; cin >> n >> m >> k; vector<long> a(n + 1, 0); vector<long> b(m + 1, 0); for (int i = 1; i <= n; i++) { cin >> a[i]; a[i] += a[i - 1]; } for (int i = 1; i <= m; i++) { cin >> b[i]; b[i] += b[i - 1]; } int b_sum = m, max = 0; for (int i = 0; i <= n && a[i] <= k; i++) { while (a[i] + b[b_sum] > k) b_sum--; if (i + b_sum > max) max = i + b_sum; } cout << max << endl; }
replace
20
21
20
21
-11
p02623
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int A[100002], B[100002]; int main() { int t = 1; // cin >> t; while (t--) { int n, m, ms; scanf("%d%d%d", &n, &m, &ms); for (int A_i = 0; A_i < n; A_i++) { scanf("%d", &A[A_i]); } for (int B_i = 0; B_i < m; B_i++) { scanf("%d", &B[B_i]); } long long sum = 0; int x = 0, y = 0; while (x < n && sum + A[x] <= ms) { sum += A[x++]; } int ans = x; while (y < m && x >= 0) { sum += B[y++]; while (sum > ms && x > 0) { sum -= A[--x]; } if (sum <= ms && ans < x + y) { ans = x + y; } } printf("%d\n", ans); } return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 200010; int A[N], B[N]; int main() { int t = 1; // cin >> t; while (t--) { int n, m, ms; scanf("%d%d%d", &n, &m, &ms); for (int A_i = 0; A_i < n; A_i++) { scanf("%d", &A[A_i]); } for (int B_i = 0; B_i < m; B_i++) { scanf("%d", &B[B_i]); } long long sum = 0; int x = 0, y = 0; while (x < n && sum + A[x] <= ms) { sum += A[x++]; } int ans = x; while (y < m && x >= 0) { sum += B[y++]; while (sum > ms && x > 0) { sum -= A[--x]; } if (sum <= ms && ans < x + y) { ans = x + y; } } printf("%d\n", ans); } return 0; }
replace
3
5
3
5
0
p02623
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; using ll = long long; template <class T = ll> inline T in(istream &is = cin) { T ret; is >> ret; return ret; } template <class T> inline auto vec2(class vector<T>::size_type h, class vector<T>::size_type w, T v = T()) { return vector<vector<T>>(h, vector<T>(w, v)); } template <class RandomAccessIterator> inline void psortb(RandomAccessIterator first, RandomAccessIterator last) { using P = pair<decltype(first->first), decltype(first->second)>; sort(first, last, [](const P &p1, const P &p2) { return p1.second < p2.second || (p1.second == p2.second && p1.first < p2.first); }); } int main() { ll n = in(), m = in(), k = in(); vector<ll> sa(n + 1), sb(m + 1); for (ll i = 0; i < n; ++i) sa[i + 1] = in() + sa[i]; for (ll i = 0; i < m; ++i) sb[i + 1] = in() + sb[i]; ll ans = 0; ll idxa = n, idxb = 0; while (idxa >= 0 && idxb <= m) { if (sa[idxa] > k) { --idxa; } else if (sa[idxa] + sb[idxb] <= k) { ans = max(ans, idxa + idxb); idxb++; } else { --idxa; } } idxa = 0, idxb = m; while (idxa <= n && idxb >= 0) { if (sa[idxb] > k) { --idxb; } else if (sa[idxa] + sb[idxb] <= k) { ans = max(ans, idxa + idxb); idxa++; } else { --idxb; } } cout << ans << endl; }
#include "bits/stdc++.h" using namespace std; using ll = long long; template <class T = ll> inline T in(istream &is = cin) { T ret; is >> ret; return ret; } template <class T> inline auto vec2(class vector<T>::size_type h, class vector<T>::size_type w, T v = T()) { return vector<vector<T>>(h, vector<T>(w, v)); } template <class RandomAccessIterator> inline void psortb(RandomAccessIterator first, RandomAccessIterator last) { using P = pair<decltype(first->first), decltype(first->second)>; sort(first, last, [](const P &p1, const P &p2) { return p1.second < p2.second || (p1.second == p2.second && p1.first < p2.first); }); } int main() { ll n = in(), m = in(), k = in(); vector<ll> sa(n + 1), sb(m + 1); for (ll i = 0; i < n; ++i) sa[i + 1] = in() + sa[i]; for (ll i = 0; i < m; ++i) sb[i + 1] = in() + sb[i]; ll ans = 0; ll idxa = n, idxb = 0; while (idxa >= 0 && idxb <= m) { if (sa[idxa] > k) { --idxa; } else if (sa[idxa] + sb[idxb] <= k) { ans = max(ans, idxa + idxb); idxb++; } else { --idxa; } } idxa = 0, idxb = m; while (idxa <= n && idxb >= 0) { if (sb[idxb] > k) { --idxb; } else if (sa[idxa] + sb[idxb] <= k) { ans = max(ans, idxa + idxb); idxa++; } else { --idxb; } } cout << ans << endl; }
replace
46
47
46
47
0
p02623
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define FOR(i, r, n) for (int i = (int)(r); i <= (int)(n); i++) #define all(v) v.begin(), v.end() #define INF 2147483647 #define INF64 9223372036854775807 #define MOD 1000000007 int main() { int64_t n, m, k; cin >> n >> m >> k; vector<int64_t> a(n + 1, 0), b(m + 1, 0); FOR(i, 1, n) { int64_t x; cin >> x; a[i] = a[i - 1] + x; } FOR(i, 1, m) { int64_t x; cin >> x; b[i] = b[i - 1] + x; } int64_t ans = 0; FOR(i, 0, n) { if (a[i] > k) break; int64_t x = n / 2; int64_t best = x; while (x > 1) { x /= 2; if (a[i] + b[best] > k) best -= x; if (a[i] + b[best] == k) break; if (a[i] + b[best] < k) best += x; } if (a[i] + b[best] > k) { while (a[i] + b[best] > k) best--; } if (a[i] + b[best] < k) { while (a[i] + b[best] <= k) { best++; if (best > m) break; } best--; } if (i + best > ans) ans = i + best; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define FOR(i, r, n) for (int i = (int)(r); i <= (int)(n); i++) #define all(v) v.begin(), v.end() #define INF 2147483647 #define INF64 9223372036854775807 #define MOD 1000000007 int main() { int64_t n, m, k; cin >> n >> m >> k; vector<int64_t> a(n + 1, 0), b(m + 1, 0); FOR(i, 1, n) { int64_t x; cin >> x; a[i] = a[i - 1] + x; } FOR(i, 1, m) { int64_t x; cin >> x; b[i] = b[i - 1] + x; } int64_t ans = 0; FOR(i, 0, n) { if (a[i] > k) break; int64_t x = m / 2; int64_t best = x; while (x > 1) { x /= 2; if (a[i] + b[best] > k) best -= x; if (a[i] + b[best] == k) break; if (a[i] + b[best] < k) best += x; } if (a[i] + b[best] > k) { while (a[i] + b[best] > k) best--; } if (a[i] + b[best] < k) { while (a[i] + b[best] <= k) { best++; if (best > m) break; } best--; } if (i + best > ans) ans = i + best; } cout << ans << endl; }
replace
30
31
30
31
0
p02623
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define ll long long const int mxN = 2e5 + 10; int n, m; ll k, a[mxN], b[mxN]; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> m >> k; for (int i = 0; i < n; ++i) { cin >> a[i + 1]; a[i + 1] += a[i]; } for (int i = 0; i < m; ++i) { cin >> b[i + 1]; b[i + 1] += b[i]; } int ans = 0; for (int i = 0; i <= n; ++i) { if (a[i] > k) break; int j = m; while (a[i] + b[j] > k) j--; ans = max(i + j, ans); } cout << ans << "\n"; }
#include <bits/stdc++.h> using namespace std; #define ll long long const int mxN = 2e5 + 10; int n, m; ll k, a[mxN], b[mxN]; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> m >> k; for (int i = 0; i < n; ++i) { cin >> a[i + 1]; a[i + 1] += a[i]; } for (int i = 0; i < m; ++i) { cin >> b[i + 1]; b[i + 1] += b[i]; } int ans = 0; for (int i = 0; i <= n; ++i) { if (a[i] > k) break; // int j = m; // while (a[i] + b[j] > k) // j--; int j = upper_bound(b, b + m + 1, k - a[i]) - b; ans = max(i + j - 1, ans); } cout << ans << "\n"; }
replace
26
30
26
31
TLE
p02623
C++
Runtime Error
// #pragma GCC target ("avx") // #pragma GCC optimize("Ofast") // #pragma GCC optimize("unroll-loops") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include <bits/stdc++.h> using namespace std; #define int long long // #define endl '\n' #pragma region TEMPLATE /* TYPE */ typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<pii> vpii; typedef vector<pll> vpll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<string> vst; typedef vector<bool> vb; typedef vector<ld> vld; typedef vector<vector<int>> vvi; template <typename T, typename Cmp = less<>> using prique = priority_queue<T, vector<T>, Cmp>; template <typename T> using prique_r = prique<T, greater<>>; /* CONSTANT */ #define ln '\n' const int INF = 1 << 30; const ll INFF = 1LL << 60; const string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; const int MOD = 1e9 + 7; const int MODD = 998244353; const string alphabet = "abcdefghijklmnopqrstuvwxyz"; const double EPS = 1e-9; const ld PI = 3.14159265358979323846264338327950288; const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1, 0}; const int dy[] = {0, 1, 0, -1, -1, -1, 1, 1, 0}; /* CONTAINER */ #define PB emplace_back #define ALL(v) (v).begin(), (v).end() #define RALL(v) (v).rbegin(), (v).rend() #define SORT(v) sort(ALL(v)) #define RSORT(v) sort(RALL(v)) #define LESS(x, val) (lower_bound(x.begin(), x.end(), val) - x.begin()) #define LEQ(x, val) (upper_bound(x.begin(), x.end(), val) - x.begin()) #define GREATER(x, val) (int)(x).size() - LEQ((x), (val)) #define GEQ(x, val) (int)(x).size() - LESS((x), (val)) #define UNIQUE(v) \ sort(ALL(v)); \ (v).erase(unique(ALL(v)), (v).end()) template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } template <typename T, typename U, typename... V> enable_if_t<is_same<T, U>::value != 0> fill_v(U &u, const V... v) { u = U(v...); } template <typename T, typename U, typename... V> enable_if_t<is_same<T, U>::value == 0> fill_v(U &u, const V... v) { for (auto &e : u) fill_v<T>(e, v...); } /* LOOP */ #define _overload3(_1, _2, _3, name, ...) name #define _REP(i, n) REPI(i, 0, n) #define REPI(i, a, b) for (ll i = (ll)a; i < (ll)b; ++i) #define REP(...) _overload3(__VA_ARGS__, REPI, _REP, )(__VA_ARGS__) #define _RREP(i, n) RREPI(i, n, 0) #define RREPI(i, a, b) for (ll i = (ll)a; i >= (ll)b; --i) #define RREP(...) _overload3(__VA_ARGS__, RREPI, _RREP, )(__VA_ARGS__) #define EACH(e, v) for (auto &e : v) #define PERM(v) \ sort(ALL(v)); \ for (bool c##p = true; c##p; c##p = next_permutation(ALL(v))) /* INPUT */ template <typename T> void SSS(T &t) { cin >> t; } template <typename Head, typename... Tail> void SSS(Head &&head, Tail &&...tail) { cin >> head; SSS(tail...); } #define SS(T, ...) \ T __VA_ARGS__; \ SSS(__VA_ARGS__); #define SV(T, v, n) \ vector<T> v(n); \ for (auto &i : v) \ cin >> i; #define SVV(T, v, n, m) \ vector<vector<T>> v(n, vector<T>(m)); \ for (auto &r : v) \ for (auto &i : r) \ cin >> i; /* OUTPUT */ // Yes / No inline int YES(bool x) { cout << (x ? "YES" : "NO") << endl; return 0; } inline int Yes(bool x) { cout << (x ? "Yes" : "No") << endl; return 0; } inline int yes(bool x) { cout << (x ? "yes" : "no") << endl; return 0; } inline int yES(bool x) { cout << (x ? "yES" : "nO") << endl; return 0; } inline int Yay(bool x) { cout << (x ? "Yay!" : ":(") << endl; return 0; } // PROTOTYPE DECLARATION template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &j); template <typename... T> ostream &operator<<(ostream &os, const tuple<T...> &t); template <class C, enable_if_t<!is_same<C, string>::value, decltype(declval<const C &>().begin(), nullptr)> = nullptr> ostream &operator<<(ostream &os, const C &c); template <typename T> ostream &operator<<(ostream &os, const stack<T> &j); template <typename T> ostream &operator<<(ostream &os, const queue<T> &j); template <typename T, typename C, typename Cmp> ostream &operator<<(ostream &os, const priority_queue<T, C, Cmp> &j); // IMPLEMENTATION template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &j) { return os << '{' << j.first << ", " << j.second << '}'; } template <size_t num = 0, typename... T> enable_if_t<num == sizeof...(T)> PRINT_TUPLE(ostream &os, const tuple<T...> &t) {} template <size_t num = 0, typename... T> enable_if_t < num<sizeof...(T)> PRINT_TUPLE(ostream &os, const tuple<T...> &t) { os << get<num>(t); if (num + 1 < sizeof...(T)) os << ", "; PRINT_TUPLE<num + 1>(os, t); } template <typename... T> ostream &operator<<(ostream &os, const tuple<T...> &t) { PRINT_TUPLE(os << '{', t); return os << '}'; } template <class C, enable_if_t<!is_same<C, string>::value, decltype(declval<const C &>().begin(), nullptr)>> ostream &operator<<(ostream &os, const C &c) { os << '{'; for (auto it = begin(c); it != end(c); it++) { if (begin(c) != it) os << ", "; os << *it; } return os << '}'; } template <typename T> ostream &operator<<(ostream &os, const stack<T> &j) { deque<T> d; for (auto c = j; !c.empty(); c.pop()) d.push_front(c.top()); return os << d; } template <typename T> ostream &operator<<(ostream &os, const queue<T> &j) { deque<T> d; for (auto c = j; !c.empty(); c.pop()) d.push_back(c.front()); return os << d; } template <typename T, typename C, typename Cmp> ostream &operator<<(ostream &os, const priority_queue<T, C, Cmp> &j) { deque<T> d; for (auto c = j; !c.empty(); c.pop()) d.push_front(c.top()); return os << d; } // OUTPUT FUNCTION template <typename T> int PV(T &v) { int sz = v.size(); for (int i = 0; i < sz; ++i) cout << v[i] << " \n"[i == sz - 1]; return 0; } inline int print() { cout << endl; return 0; } template <typename Head> int print(Head &&head) { cout << head; return print(); } template <typename Head, typename... Tail> int print(Head &&head, Tail &&...tail) { cout << head << " "; return print(forward<Tail>(tail)...); } #ifdef LOCAL inline void dump() { cerr << endl; } template <typename Head> void dump(Head &&head) { cerr << head; dump(); } template <typename Head, typename... Tail> void dump(Head &&head, Tail &&...tail) { cerr << head << ", "; dump(forward<Tail>(tail)...); } #define debug(...) \ do { \ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; \ dump(__VA_ARGS__); \ } while (false) #else #define dump(...) #define debug(...) #endif /* OTHER */ #define fi first #define se second #define MP make_pair #define MT make_tuple #define tmax(x, y, z) max((x), max((y), (z))) #define tmin(x, y, z) min((x), min((y), (z))) template <typename T, typename A, typename B> inline bool between(T x, A a, B b) { return ((a <= x) && (x < b)); } template <typename A, typename B> inline bool chmax(A &a, const B &b) { if (a < b) { a = b; return true; } return false; } template <typename A, typename B> inline bool chmin(A &a, const B &b) { if (a > b) { a = b; return true; } return false; } inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } inline ll POW(ll a, ll b) { ll r = 1; do { if (b & 1) r *= a; a *= a; } while (b >>= 1); return r; } struct abracadabra { abracadabra() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); cerr << fixed << setprecision(5); }; } ABRACADABRA; #pragma endregion signed main() { SS(int, N, M, K); SV(ll, A, N); SV(ll, B, N); vl C(1, 0); REP(i, M) C.emplace_back(C.back() + B[i]); ll acc = 0, res = 0; REP(i, N + 1) { ll rst = K - acc; if (rst < 0) break; auto itr = lower_bound(C.begin(), C.end(), rst + 1); if (itr != C.begin()) { itr = prev(itr); ll tmp = i + (int)(itr - C.begin()); chmax(res, tmp); } if (i != N) acc += A[i]; if (acc > K) break; } print(res); }
// #pragma GCC target ("avx") // #pragma GCC optimize("Ofast") // #pragma GCC optimize("unroll-loops") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include <bits/stdc++.h> using namespace std; #define int long long // #define endl '\n' #pragma region TEMPLATE /* TYPE */ typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<pii> vpii; typedef vector<pll> vpll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<string> vst; typedef vector<bool> vb; typedef vector<ld> vld; typedef vector<vector<int>> vvi; template <typename T, typename Cmp = less<>> using prique = priority_queue<T, vector<T>, Cmp>; template <typename T> using prique_r = prique<T, greater<>>; /* CONSTANT */ #define ln '\n' const int INF = 1 << 30; const ll INFF = 1LL << 60; const string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; const int MOD = 1e9 + 7; const int MODD = 998244353; const string alphabet = "abcdefghijklmnopqrstuvwxyz"; const double EPS = 1e-9; const ld PI = 3.14159265358979323846264338327950288; const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1, 0}; const int dy[] = {0, 1, 0, -1, -1, -1, 1, 1, 0}; /* CONTAINER */ #define PB emplace_back #define ALL(v) (v).begin(), (v).end() #define RALL(v) (v).rbegin(), (v).rend() #define SORT(v) sort(ALL(v)) #define RSORT(v) sort(RALL(v)) #define LESS(x, val) (lower_bound(x.begin(), x.end(), val) - x.begin()) #define LEQ(x, val) (upper_bound(x.begin(), x.end(), val) - x.begin()) #define GREATER(x, val) (int)(x).size() - LEQ((x), (val)) #define GEQ(x, val) (int)(x).size() - LESS((x), (val)) #define UNIQUE(v) \ sort(ALL(v)); \ (v).erase(unique(ALL(v)), (v).end()) template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } template <typename T, typename U, typename... V> enable_if_t<is_same<T, U>::value != 0> fill_v(U &u, const V... v) { u = U(v...); } template <typename T, typename U, typename... V> enable_if_t<is_same<T, U>::value == 0> fill_v(U &u, const V... v) { for (auto &e : u) fill_v<T>(e, v...); } /* LOOP */ #define _overload3(_1, _2, _3, name, ...) name #define _REP(i, n) REPI(i, 0, n) #define REPI(i, a, b) for (ll i = (ll)a; i < (ll)b; ++i) #define REP(...) _overload3(__VA_ARGS__, REPI, _REP, )(__VA_ARGS__) #define _RREP(i, n) RREPI(i, n, 0) #define RREPI(i, a, b) for (ll i = (ll)a; i >= (ll)b; --i) #define RREP(...) _overload3(__VA_ARGS__, RREPI, _RREP, )(__VA_ARGS__) #define EACH(e, v) for (auto &e : v) #define PERM(v) \ sort(ALL(v)); \ for (bool c##p = true; c##p; c##p = next_permutation(ALL(v))) /* INPUT */ template <typename T> void SSS(T &t) { cin >> t; } template <typename Head, typename... Tail> void SSS(Head &&head, Tail &&...tail) { cin >> head; SSS(tail...); } #define SS(T, ...) \ T __VA_ARGS__; \ SSS(__VA_ARGS__); #define SV(T, v, n) \ vector<T> v(n); \ for (auto &i : v) \ cin >> i; #define SVV(T, v, n, m) \ vector<vector<T>> v(n, vector<T>(m)); \ for (auto &r : v) \ for (auto &i : r) \ cin >> i; /* OUTPUT */ // Yes / No inline int YES(bool x) { cout << (x ? "YES" : "NO") << endl; return 0; } inline int Yes(bool x) { cout << (x ? "Yes" : "No") << endl; return 0; } inline int yes(bool x) { cout << (x ? "yes" : "no") << endl; return 0; } inline int yES(bool x) { cout << (x ? "yES" : "nO") << endl; return 0; } inline int Yay(bool x) { cout << (x ? "Yay!" : ":(") << endl; return 0; } // PROTOTYPE DECLARATION template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &j); template <typename... T> ostream &operator<<(ostream &os, const tuple<T...> &t); template <class C, enable_if_t<!is_same<C, string>::value, decltype(declval<const C &>().begin(), nullptr)> = nullptr> ostream &operator<<(ostream &os, const C &c); template <typename T> ostream &operator<<(ostream &os, const stack<T> &j); template <typename T> ostream &operator<<(ostream &os, const queue<T> &j); template <typename T, typename C, typename Cmp> ostream &operator<<(ostream &os, const priority_queue<T, C, Cmp> &j); // IMPLEMENTATION template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &j) { return os << '{' << j.first << ", " << j.second << '}'; } template <size_t num = 0, typename... T> enable_if_t<num == sizeof...(T)> PRINT_TUPLE(ostream &os, const tuple<T...> &t) {} template <size_t num = 0, typename... T> enable_if_t < num<sizeof...(T)> PRINT_TUPLE(ostream &os, const tuple<T...> &t) { os << get<num>(t); if (num + 1 < sizeof...(T)) os << ", "; PRINT_TUPLE<num + 1>(os, t); } template <typename... T> ostream &operator<<(ostream &os, const tuple<T...> &t) { PRINT_TUPLE(os << '{', t); return os << '}'; } template <class C, enable_if_t<!is_same<C, string>::value, decltype(declval<const C &>().begin(), nullptr)>> ostream &operator<<(ostream &os, const C &c) { os << '{'; for (auto it = begin(c); it != end(c); it++) { if (begin(c) != it) os << ", "; os << *it; } return os << '}'; } template <typename T> ostream &operator<<(ostream &os, const stack<T> &j) { deque<T> d; for (auto c = j; !c.empty(); c.pop()) d.push_front(c.top()); return os << d; } template <typename T> ostream &operator<<(ostream &os, const queue<T> &j) { deque<T> d; for (auto c = j; !c.empty(); c.pop()) d.push_back(c.front()); return os << d; } template <typename T, typename C, typename Cmp> ostream &operator<<(ostream &os, const priority_queue<T, C, Cmp> &j) { deque<T> d; for (auto c = j; !c.empty(); c.pop()) d.push_front(c.top()); return os << d; } // OUTPUT FUNCTION template <typename T> int PV(T &v) { int sz = v.size(); for (int i = 0; i < sz; ++i) cout << v[i] << " \n"[i == sz - 1]; return 0; } inline int print() { cout << endl; return 0; } template <typename Head> int print(Head &&head) { cout << head; return print(); } template <typename Head, typename... Tail> int print(Head &&head, Tail &&...tail) { cout << head << " "; return print(forward<Tail>(tail)...); } #ifdef LOCAL inline void dump() { cerr << endl; } template <typename Head> void dump(Head &&head) { cerr << head; dump(); } template <typename Head, typename... Tail> void dump(Head &&head, Tail &&...tail) { cerr << head << ", "; dump(forward<Tail>(tail)...); } #define debug(...) \ do { \ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; \ dump(__VA_ARGS__); \ } while (false) #else #define dump(...) #define debug(...) #endif /* OTHER */ #define fi first #define se second #define MP make_pair #define MT make_tuple #define tmax(x, y, z) max((x), max((y), (z))) #define tmin(x, y, z) min((x), min((y), (z))) template <typename T, typename A, typename B> inline bool between(T x, A a, B b) { return ((a <= x) && (x < b)); } template <typename A, typename B> inline bool chmax(A &a, const B &b) { if (a < b) { a = b; return true; } return false; } template <typename A, typename B> inline bool chmin(A &a, const B &b) { if (a > b) { a = b; return true; } return false; } inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } inline ll POW(ll a, ll b) { ll r = 1; do { if (b & 1) r *= a; a *= a; } while (b >>= 1); return r; } struct abracadabra { abracadabra() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); cerr << fixed << setprecision(5); }; } ABRACADABRA; #pragma endregion signed main() { SS(int, N, M, K); SV(ll, A, N); SV(ll, B, M); vl C(1, 0); REP(i, M) C.emplace_back(C.back() + B[i]); ll acc = 0, res = 0; REP(i, N + 1) { ll rst = K - acc; if (rst < 0) break; auto itr = lower_bound(C.begin(), C.end(), rst + 1); if (itr != C.begin()) { itr = prev(itr); ll tmp = i + (int)(itr - C.begin()); chmax(res, tmp); } if (i != N) acc += A[i]; if (acc > K) break; } print(res); }
replace
272
273
272
273
0
p02623
C++
Runtime Error
#include <bits/stdc++.h> #define llint long long int using namespace std; int main() { int N, M, K; cin >> N >> M >> K; vector<llint> A(N), B(M); for (int i = 0; i < N; i++) { cin >> A[i]; } for (int i = 1; i < N; i++) { A[i] += A[i - 1]; } for (int i = 0; i < M; i++) { cin >> B[i]; } for (int i = 1; i < M; i++) { B[i] += B[i - 1]; } auto it = upper_bound(B.begin(), B.end(), K); int ans = (it - B.begin()); for (int i = 0; A[i] < K; i++) { auto it = upper_bound(B.begin(), B.end(), K - A[i]); int temp = (i + 1) + (it - B.begin()); if (temp > ans) { ans = temp; } } cout << ans << endl; }
#include <bits/stdc++.h> #define llint long long int using namespace std; int main() { int N, M, K; cin >> N >> M >> K; vector<llint> A(N), B(M); for (int i = 0; i < N; i++) { cin >> A[i]; } for (int i = 1; i < N; i++) { A[i] += A[i - 1]; } for (int i = 0; i < M; i++) { cin >> B[i]; } for (int i = 1; i < M; i++) { B[i] += B[i - 1]; } auto it = upper_bound(B.begin(), B.end(), K); int ans = (it - B.begin()); for (int i = 0; i < N; i++) { if (A[i] > K) { break; } it = upper_bound(B.begin(), B.end(), K - A[i]); int temp = (i + 1) + (it - B.begin()); if (temp > ans) { ans = temp; } } cout << ans << endl; }
replace
29
31
29
34
0
p02623
C++
Runtime Error
#include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, n) for (int i = 0; i < (n); i++) #define ALL(obj) (obj).begin(), (obj).end() #define SCANF(i) \ int i; \ scanf("%d", &i) typedef long long ll; using namespace std; using P = pair<int, int>; const long long INF = 1LL << 60; const int IINF = 100000000; const int MOD = (int)1e9 + 7; // 約数列挙 vector<long long> divisor(long long n) { vector<long long> ret; for (long long i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } // sort(ret.begin(), ret.end()); // 昇順に並べる return ret; } vector<int> dx = {1, 0, -1, 0}; vector<int> dy = {0, -1, 0, 1}; signed main() { ll n, m, k; cin >> n >> m >> k; vector<ll> alist(n + 1, 0); vector<ll> blist(n + 1, 0); REP(i, n) { ll tmp; cin >> tmp; alist[i + 1] = alist[i] + tmp; } REP(i, m) { ll tmp; cin >> tmp; blist[i + 1] = blist[i] + tmp; } ll ans = 0; REP(i, n + 1) { ll target = alist[i]; if (k - target < 0) continue; auto bitr = upper_bound(ALL(blist), k - target); ll cnt = bitr - blist.begin() - 1; ans = max(ans, cnt + i); } REP(i, m + 1) { ll target = blist[i]; if (k - target < 0) continue; auto aitr = upper_bound(ALL(alist), k - target); ll cnt = aitr - alist.begin() - 1; ans = max(ans, cnt + i); } cout << ans << endl; } // https://atcoder.jp/contests/abc172/tasks/abc172_c
#include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, n) for (int i = 0; i < (n); i++) #define ALL(obj) (obj).begin(), (obj).end() #define SCANF(i) \ int i; \ scanf("%d", &i) typedef long long ll; using namespace std; using P = pair<int, int>; const long long INF = 1LL << 60; const int IINF = 100000000; const int MOD = (int)1e9 + 7; // 約数列挙 vector<long long> divisor(long long n) { vector<long long> ret; for (long long i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } // sort(ret.begin(), ret.end()); // 昇順に並べる return ret; } vector<int> dx = {1, 0, -1, 0}; vector<int> dy = {0, -1, 0, 1}; signed main() { ll n, m, k; cin >> n >> m >> k; vector<ll> alist(n + 1, 0); vector<ll> blist(m + 1, 0); REP(i, n) { ll tmp; cin >> tmp; alist[i + 1] = alist[i] + tmp; } REP(i, m) { ll tmp; cin >> tmp; blist[i + 1] = blist[i] + tmp; } ll ans = 0; REP(i, n + 1) { ll target = alist[i]; if (k - target < 0) continue; auto bitr = upper_bound(ALL(blist), k - target); ll cnt = bitr - blist.begin() - 1; ans = max(ans, cnt + i); } REP(i, m + 1) { ll target = blist[i]; if (k - target < 0) continue; auto aitr = upper_bound(ALL(alist), k - target); ll cnt = aitr - alist.begin() - 1; ans = max(ans, cnt + i); } cout << ans << endl; } // https://atcoder.jp/contests/abc172/tasks/abc172_c
replace
33
34
33
34
0
p02623
C++
Runtime Error
#include <iostream> #include <vector> /* 二台の机 A, B があります。机 A には N 冊の本が、机 B には M 冊の本が、それぞれ縦に積まれています。 机 A に現在上から i 番目に積まれている本 (1≤i≤N) は読むのに Ai 分を要し、 机 B に現在上から i 番目に積まれている本 (1≤i≤M) は読むのに Bi 分を要します。 次の行為を考えます。 本が残っている机を選び、その机の最も上に積まれた本を読んで机から取り除く。 合計所要時間が K 分を超えないようにこの行為を繰り返すとき、最大で何冊の本を読むことができるでしょうか。本を読むこと以外に要する時間は無視します。 */ void N_Greedy(int n = -1) { unsigned int N, M, K; std::vector<long long> A, B; std::cin >> N >> M >> K; unsigned int A_Cursor = 0, B_Cursor = 0; unsigned long long time = 0; unsigned int numReadBook = 0; unsigned long long sumMinTime, sumBufTime; int pivot; unsigned int i; if (n == -1) n = (int)N; A = std::vector<long long>(N); B = std::vector<long long>(M); for (i = 0; i < N; ++i) std::cin >> A[i]; for (i = 0; i < M; ++i) std::cin >> B[i]; while (n > 0) { // sumMinTime=-1; pivot = -1; for (i = 0; i < (unsigned int)n + 1; ++i) { sumBufTime = 0; // int cnt=0; if (A_Cursor + i > N || B_Cursor + (n - i) > M) { continue; } for (unsigned int j = A_Cursor; j < A_Cursor + i; ++j) { sumBufTime += A[j]; // std::cout<<A[i]<<" "; // cnt++; } // std::cout<<std::endl; for (unsigned int j = B_Cursor; j < B_Cursor + (n - i); ++j) { sumBufTime += B[j]; // std::cout<<B[i]<<" "; // cnt++; } // std::cout<<std::endl; // std::cout<<n<<":"<<cnt<<std::endl; if (pivot == -1 || sumMinTime > sumBufTime) { sumMinTime = sumBufTime; pivot = i; // std::cout<<"check"<<std::endl; } } if (pivot != -1 && (K - time) >= sumMinTime) { time += sumMinTime; numReadBook += n; // std::cout<<sumMinTime<<std::endl; A_Cursor += pivot; B_Cursor += n - pivot; } else { --n; } } std::cout << numReadBook; } void correct() { int N, M; unsigned long long K; std::vector<unsigned long long> A, B; std::vector<unsigned long long> sumA, sumB; std::cin >> N >> M >> K; A = std::vector<unsigned long long>(N); B = std::vector<unsigned long long>(M); sumA = std::vector<unsigned long long>(N + 1, 0); sumB = std::vector<unsigned long long>(M + 1, 0); int numReadBook = -1, bufReadBook; int startJ = M; for (int i = 0; i < N; ++i) { std::cin >> A[i]; sumA[i + 1] = sumA[i] + A[i]; } for (int i = 0; i < M; ++i) { std::cin >> B[i]; sumB[i + 1] = sumB[i] + B[i]; } for (int i = 0; i < N + 1; ++i) { for (int j = startJ; j >= 0; ++j) { // 降順 if (sumA[i] + sumB[j] <= K) { bufReadBook = i + j; startJ = j; break; } } if (numReadBook == -1 || numReadBook < bufReadBook) { numReadBook = bufReadBook; } } if (numReadBook > -1) std::cout << numReadBook; else std::cout << 0; } int main() { // N_Greedy(); correct(); return 0; }
#include <iostream> #include <vector> /* 二台の机 A, B があります。机 A には N 冊の本が、机 B には M 冊の本が、それぞれ縦に積まれています。 机 A に現在上から i 番目に積まれている本 (1≤i≤N) は読むのに Ai 分を要し、 机 B に現在上から i 番目に積まれている本 (1≤i≤M) は読むのに Bi 分を要します。 次の行為を考えます。 本が残っている机を選び、その机の最も上に積まれた本を読んで机から取り除く。 合計所要時間が K 分を超えないようにこの行為を繰り返すとき、最大で何冊の本を読むことができるでしょうか。本を読むこと以外に要する時間は無視します。 */ void N_Greedy(int n = -1) { unsigned int N, M, K; std::vector<long long> A, B; std::cin >> N >> M >> K; unsigned int A_Cursor = 0, B_Cursor = 0; unsigned long long time = 0; unsigned int numReadBook = 0; unsigned long long sumMinTime, sumBufTime; int pivot; unsigned int i; if (n == -1) n = (int)N; A = std::vector<long long>(N); B = std::vector<long long>(M); for (i = 0; i < N; ++i) std::cin >> A[i]; for (i = 0; i < M; ++i) std::cin >> B[i]; while (n > 0) { // sumMinTime=-1; pivot = -1; for (i = 0; i < (unsigned int)n + 1; ++i) { sumBufTime = 0; // int cnt=0; if (A_Cursor + i > N || B_Cursor + (n - i) > M) { continue; } for (unsigned int j = A_Cursor; j < A_Cursor + i; ++j) { sumBufTime += A[j]; // std::cout<<A[i]<<" "; // cnt++; } // std::cout<<std::endl; for (unsigned int j = B_Cursor; j < B_Cursor + (n - i); ++j) { sumBufTime += B[j]; // std::cout<<B[i]<<" "; // cnt++; } // std::cout<<std::endl; // std::cout<<n<<":"<<cnt<<std::endl; if (pivot == -1 || sumMinTime > sumBufTime) { sumMinTime = sumBufTime; pivot = i; // std::cout<<"check"<<std::endl; } } if (pivot != -1 && (K - time) >= sumMinTime) { time += sumMinTime; numReadBook += n; // std::cout<<sumMinTime<<std::endl; A_Cursor += pivot; B_Cursor += n - pivot; } else { --n; } } std::cout << numReadBook; } void correct() { int N, M; unsigned long long K; std::vector<unsigned long long> A, B; std::vector<unsigned long long> sumA, sumB; std::cin >> N >> M >> K; A = std::vector<unsigned long long>(N); B = std::vector<unsigned long long>(M); sumA = std::vector<unsigned long long>(N + 1, 0); sumB = std::vector<unsigned long long>(M + 1, 0); int numReadBook = -1, bufReadBook; int startJ = M; for (int i = 0; i < N; ++i) { std::cin >> A[i]; sumA[i + 1] = sumA[i] + A[i]; } for (int i = 0; i < M; ++i) { std::cin >> B[i]; sumB[i + 1] = sumB[i] + B[i]; } for (int i = 0; i < N + 1; ++i) { for (int j = startJ; j >= 0; --j) { // 降順 if (sumA[i] + sumB[j] <= K) { bufReadBook = i + j; startJ = j; break; } } if (numReadBook == -1 || numReadBook < bufReadBook) { numReadBook = bufReadBook; } } if (numReadBook > -1) std::cout << numReadBook; else std::cout << 0; } int main() { // N_Greedy(); correct(); return 0; }
replace
98
99
98
99
-11
p02623
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = (0); i < (n); ++i) #define rrep(i, n) for (int i = 1; i <= (n); ++i) #define drep(i, n) for (int i = (n)-1; i >= 0; --i) #define srep(i, s, t) for (int i = s; i < t; ++i) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define limit(x, l, r) max(l, min(x, r)) #define lims(x, l, r) (x = max(l, min(x, r))) #define isin(x, l, r) ((l) <= (x) && (x) < (r)) #define show(x) cout << #x << " = " << (x) << endl #define show2(x, y) \ cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl #define show3(x, y, z) \ cout << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z \ << " = " << (z) << endl #define showv(v) \ rep(i, v.size()) printf("%d%c", v[i], i == v.size() - 1 ? '\n' : ' ') #define showv2(v) rep(j, v.size()) showv(v[j]) #define showt(t, n) rep(i, n) printf("%d%c", t[i], i == n - 1 ? '\n' : ' ') #define showt2(t, r, c) rep(j, r) showt(t[j], c) #define showvp(p) rep(i, p.size()) printf("%d %d\n", p[i].first, p[i].second) #define printv(v) rep(i, v.size()) printf("%d\n", v[i]) #define printt(t, n) rep(i, n) printf("%d\n", t[i]) #define incl(v, x) (find(all(v), x) != v.end()) #define incls(s, c) (s.find(c) != string::npos) #define lb(a, x) distance((a).begin(), lower_bound(all(a), (x))) #define ub(a, x) distance((a).begin(), upper_bound(all(a), (x))) #define fi first #define se second #define pb push_back #define eb emplace_back #define sz(x) (int)(x).size() #define pcnt __builtin_popcountll #define bit(n, k) ((n >> k) & 1) // nのk bit目 #define bn(x) ((1 << x) - 1) #define dup(x, y) (((x) + (y)-1) / (y)) #define newline puts("") #define uni(x) x.erase(unique(all(x)), x.end()) #define SP << " " << using namespace std; using ll = long long; using ld = long double; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; using vc = vector<char>; using vvc = vector<vc>; using vs = vector<string>; using vb = vector<bool>; using vvb = vector<vb>; using P = pair<int, int>; using T = tuple<int, int, int>; using vp = vector<P>; using vt = vector<T>; const int mod = 1000000007; const double EPS = 1e-9; // const long double EPS = 1e-14; const int INF = (1 << 30) - 1; const ll LINF = (1LL << 62) - 1; #define dame \ { \ puts("No"); \ return 0; \ } #define yn \ { puts("Yes"); } \ else { \ puts("No"); \ } inline int in() { int x; cin >> x; return x; } inline ll lin() { ll x; cin >> x; return x; } inline char chin() { char x; cin >> x; return x; } inline string stin() { string x; cin >> x; return x; } inline double din() { double x; cin >> x; return x; } // template<class T = int> inline T in() { T x; cin >> x; return (x);} template <typename T> inline ll suma(const vector<T> &a) { ll res(0); for (auto &&x : a) res += x; return res; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } char itoa(int n) { return n + '0'; } ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; int main() { int n, m, k; cin >> n >> m >> k; vi a(n); rep(i, n) cin >> a[i]; vi b(m); rep(i, m) cin >> b[i]; vector<ll> ca(a.size() + 1); rep(i, a.size()) { ca[i + 1] = ca[i] + a[i]; } vector<ll> cb(b.size() + 1); rep(i, b.size()) { cb[i + 1] = cb[i] + b[i]; } int ans = 0, j = m; rep(i, n + 1) { // i: 読んだ机Aの本の数 // j: 読んだ机Bの本の数 while (ca[i] + cb[j] > (ll)k) j--; chmax(ans, i + j); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = (0); i < (n); ++i) #define rrep(i, n) for (int i = 1; i <= (n); ++i) #define drep(i, n) for (int i = (n)-1; i >= 0; --i) #define srep(i, s, t) for (int i = s; i < t; ++i) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define limit(x, l, r) max(l, min(x, r)) #define lims(x, l, r) (x = max(l, min(x, r))) #define isin(x, l, r) ((l) <= (x) && (x) < (r)) #define show(x) cout << #x << " = " << (x) << endl #define show2(x, y) \ cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl #define show3(x, y, z) \ cout << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z \ << " = " << (z) << endl #define showv(v) \ rep(i, v.size()) printf("%d%c", v[i], i == v.size() - 1 ? '\n' : ' ') #define showv2(v) rep(j, v.size()) showv(v[j]) #define showt(t, n) rep(i, n) printf("%d%c", t[i], i == n - 1 ? '\n' : ' ') #define showt2(t, r, c) rep(j, r) showt(t[j], c) #define showvp(p) rep(i, p.size()) printf("%d %d\n", p[i].first, p[i].second) #define printv(v) rep(i, v.size()) printf("%d\n", v[i]) #define printt(t, n) rep(i, n) printf("%d\n", t[i]) #define incl(v, x) (find(all(v), x) != v.end()) #define incls(s, c) (s.find(c) != string::npos) #define lb(a, x) distance((a).begin(), lower_bound(all(a), (x))) #define ub(a, x) distance((a).begin(), upper_bound(all(a), (x))) #define fi first #define se second #define pb push_back #define eb emplace_back #define sz(x) (int)(x).size() #define pcnt __builtin_popcountll #define bit(n, k) ((n >> k) & 1) // nのk bit目 #define bn(x) ((1 << x) - 1) #define dup(x, y) (((x) + (y)-1) / (y)) #define newline puts("") #define uni(x) x.erase(unique(all(x)), x.end()) #define SP << " " << using namespace std; using ll = long long; using ld = long double; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; using vc = vector<char>; using vvc = vector<vc>; using vs = vector<string>; using vb = vector<bool>; using vvb = vector<vb>; using P = pair<int, int>; using T = tuple<int, int, int>; using vp = vector<P>; using vt = vector<T>; const int mod = 1000000007; const double EPS = 1e-9; // const long double EPS = 1e-14; const int INF = (1 << 30) - 1; const ll LINF = (1LL << 62) - 1; #define dame \ { \ puts("No"); \ return 0; \ } #define yn \ { puts("Yes"); } \ else { \ puts("No"); \ } inline int in() { int x; cin >> x; return x; } inline ll lin() { ll x; cin >> x; return x; } inline char chin() { char x; cin >> x; return x; } inline string stin() { string x; cin >> x; return x; } inline double din() { double x; cin >> x; return x; } // template<class T = int> inline T in() { T x; cin >> x; return (x);} template <typename T> inline ll suma(const vector<T> &a) { ll res(0); for (auto &&x : a) res += x; return res; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } char itoa(int n) { return n + '0'; } ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; int main() { int n, m, k; cin >> n >> m >> k; vi a(n); rep(i, n) cin >> a[i]; vi b(m); rep(i, m) cin >> b[i]; vector<ll> ca(a.size() + 1); rep(i, a.size()) { ca[i + 1] = ca[i] + a[i]; } vector<ll> cb(b.size() + 1); rep(i, b.size()) { cb[i + 1] = cb[i] + b[i]; } int ans = 0, j = m; rep(i, n + 1) { // i: 読んだ机Aの本の数 // j: 読んだ机Bの本の数 if (ca[i] > k) break; while (ca[i] + cb[j] > k) j--; chmax(ans, i + j); } cout << ans << endl; return 0; }
replace
140
141
140
143
-11
p02623
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define rep2(i, n) for (int i = 1; i <= (n); i++) typedef long long ll; // int a[200001]; // int b[200001]; ll a[10]; ll b[10]; int main() { int N, M, K; cin >> N >> M >> K; a[0] = 0; b[0] = 0; rep2(i, N) { int x; cin >> x; a[i] = i == 1 ? x : x + a[i - 1]; } rep2(i, M) { int x; cin >> x; b[i] = i == 1 ? x : x + b[i - 1]; } int j = M, ans = 0; for (int i = 0; i <= N; i++) { if (a[i] > K) break; while (a[i] + b[j] > K) j--; ans = max(ans, i + j); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define rep2(i, n) for (int i = 1; i <= (n); i++) typedef long long ll; ll a[200001]; ll b[200001]; int main() { int N, M, K; cin >> N >> M >> K; a[0] = 0; b[0] = 0; rep2(i, N) { int x; cin >> x; a[i] = i == 1 ? x : x + a[i - 1]; } rep2(i, M) { int x; cin >> x; b[i] = i == 1 ? x : x + b[i - 1]; } int j = M, ans = 0; for (int i = 0; i <= N; i++) { if (a[i] > K) break; while (a[i] + b[j] > K) j--; ans = max(ans, i + j); } cout << ans << endl; }
replace
6
10
6
8
0
p02623
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> using namespace std; typedef long long ll; typedef vector<ll> v; typedef vector<vector<ll>> vv; #define MOD 1000000007 #define INF 1001001001 #define MIN -1001001001 #define rep(i, k, N) for (int i = k; i < N; i++) #define MP make_pair #define MT make_tuple // tie,make_tuple は別物 #define PB push_back #define PF push_front #define all(x) (x).begin(), (x).end() int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; void YN(bool ans) { if (ans) cout << "Yes" << endl; else cout << "No" << endl; return; } int main() { ll N, M, K; cin >> N >> M >> K; v A(N), B(M); rep(i, 0, N) cin >> A[i]; rep(i, 0, M) cin >> B[i]; ll sum = 0, books = 0, mb = 0; while (books < N) { if (A[books] + sum <= K) { sum += A[books]; books++; } else { break; } } mb = books; ll i = books - 1; bool ok = true; rep(j, 0, M) { while (B[j] + sum > K) { if (i == -1) { ok = false; } sum -= A[i]; i--; books--; } sum += B[j]; books++; if (ok) mb = max(mb, books); } cout << mb; return 0; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> using namespace std; typedef long long ll; typedef vector<ll> v; typedef vector<vector<ll>> vv; #define MOD 1000000007 #define INF 1001001001 #define MIN -1001001001 #define rep(i, k, N) for (int i = k; i < N; i++) #define MP make_pair #define MT make_tuple // tie,make_tuple は別物 #define PB push_back #define PF push_front #define all(x) (x).begin(), (x).end() int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; void YN(bool ans) { if (ans) cout << "Yes" << endl; else cout << "No" << endl; return; } int main() { ll N, M, K; cin >> N >> M >> K; v A(N), B(M); rep(i, 0, N) cin >> A[i]; rep(i, 0, M) cin >> B[i]; ll sum = 0, books = 0, mb = 0; while (books < N) { if (A[books] + sum <= K) { sum += A[books]; books++; } else { break; } } mb = books; ll i = books - 1; bool ok = true; rep(j, 0, M) { while (B[j] + sum > K) { if (i == -1) { ok = false; break; } sum -= A[i]; i--; books--; } sum += B[j]; books++; if (ok) mb = max(mb, books); } cout << mb; return 0; }
insert
62
62
62
63
0
p02623
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long #define _ \ ios::sync_with_stdio(false); \ cout.tie(NULL); \ cin.tie(NULL); using namespace std; int main() { _ ll n, m, k, sum = 0, ans = 0, max1 = 0, l = 0, r = 0; cin >> n >> m >> k; deque<ll> dq1, dq2; for (ll i = 0; i < n; i++) { ll x; cin >> x; dq1.push_back(x); } for (ll i = 0; i < m; i++) { ll x; cin >> x; dq2.push_back(x); } while (l < n) { if (sum + dq1[l] <= k) { sum += dq1[l]; ans++; l++; } else { l--; break; } } if (l == n) l--; max1 = max(max1, ans); while (l >= -1 && r < m) { if (sum + dq2[r] <= k) { sum += dq2[r]; ans++; r++; } else { sum -= dq1[l]; l--; ans--; } max1 = max(ans, max1); } max1 = max(ans, max1); cout << max1 << endl; }
#include <bits/stdc++.h> #define ll long long #define _ \ ios::sync_with_stdio(false); \ cout.tie(NULL); \ cin.tie(NULL); using namespace std; int main() { _ ll n, m, k, sum = 0, ans = 0, max1 = 0, l = 0, r = 0; cin >> n >> m >> k; deque<ll> dq1, dq2; for (ll i = 0; i < n; i++) { ll x; cin >> x; dq1.push_back(x); } for (ll i = 0; i < m; i++) { ll x; cin >> x; dq2.push_back(x); } while (l < n) { if (sum + dq1[l] <= k) { sum += dq1[l]; ans++; l++; } else { l--; break; } } if (l == n) l--; max1 = max(max1, ans); while (l >= -1 && r < m) { if (sum + dq2[r] <= k) { sum += dq2[r]; ans++; r++; } else { if (l < 0) break; sum -= dq1[l]; l--; ans--; } max1 = max(ans, max1); } max1 = max(ans, max1); cout << max1 << endl; }
insert
41
41
41
43
-11
p02623
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (ll i = 0; i < (n); ++i) using namespace std; using ll = long long; const double PI = acos(-1); template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } int main() { ll n, m, k; cin >> n >> m >> k; vector<ll> a(n), b(m); vector<ll> as(n + 1, 0), bs(m + 1, 0); rep(i, n) { cin >> a[i]; as[i + 1] = as[i] + a[i]; } rep(i, m) { cin >> b[i]; bs[i + 1] = bs[i] + b[i]; } ll ans = 0, j = m; rep(i, n + 1) { if (as[i] > k) break; while (bs[j] >= k - as[i]) j--; ans = max(ans, i + j); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (ll i = 0; i < (n); ++i) using namespace std; using ll = long long; const double PI = acos(-1); template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } int main() { ll n, m, k; cin >> n >> m >> k; vector<ll> a(n), b(m); vector<ll> as(n + 1, 0), bs(m + 1, 0); rep(i, n) { cin >> a[i]; as[i + 1] = as[i] + a[i]; } rep(i, m) { cin >> b[i]; bs[i + 1] = bs[i] + b[i]; } ll ans = 0, j = m; rep(i, n + 1) { if (as[i] > k) break; while (bs[j] > k - as[i]) j--; ans = max(ans, i + j); } cout << ans << endl; return 0; }
replace
29
30
29
30
0
p02623
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll mod = 1e9 + 7; const ll N = 5e5 + 1; const ll INF = 1e10; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); int n, m, k; cin >> n >> m >> k; vector<ll> a(n), b(m); for (ll &i : a) cin >> i; for (ll &i : b) cin >> i; int ans = 0, aptr = 0, bptr = 0; ll sum = 0; while (aptr < n and sum + a[aptr] <= k) sum += a[aptr++]; ans = aptr; while (aptr) { while (bptr < m and sum + b[bptr] <= k) sum += b[bptr++]; ans = max(ans, aptr + bptr); sum -= a[--aptr]; } bptr = 0, sum = 0; while (sum + b[bptr] <= k) sum += b[bptr++]; ans = max(ans, bptr); cout << ans; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll mod = 1e9 + 7; const ll N = 5e5 + 1; const ll INF = 1e10; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); int n, m, k; cin >> n >> m >> k; vector<ll> a(n), b(m); for (ll &i : a) cin >> i; for (ll &i : b) cin >> i; int ans = 0, aptr = 0, bptr = 0; ll sum = 0; while (aptr < n and sum + a[aptr] <= k) sum += a[aptr++]; ans = aptr; while (aptr) { while (bptr < m and sum + b[bptr] <= k) sum += b[bptr++]; ans = max(ans, aptr + bptr); sum -= a[--aptr]; } bptr = 0, sum = 0; while (bptr < m and sum + b[bptr] <= k) sum += b[bptr++]; ans = max(ans, bptr); cout << ans; }
replace
30
31
30
31
0
p02623
C++
Time Limit Exceeded
#include <iostream> #include <vector> using namespace std; int main() { vector<long long> A, B; long long K; long long N, M; cin >> N >> M >> K; vector<long long> Sum_A(N + 1, 0), Sum_B(M + 1, 0); int tmp; Sum_A.push_back(0); for (int i = 1; i <= N; i++) { cin >> tmp; A.push_back(tmp); Sum_A[i] = Sum_A[i - 1] + tmp; } Sum_B.push_back(0); for (int i = 1; i <= M; i++) { cin >> tmp; B.push_back(tmp); Sum_B[i] = Sum_B[i - 1] + tmp; } int ans = 0; long long p = M; for (int i = 0; i <= N; i++) { for (int j = p; j >= 0; j--) { if (Sum_A[i] + Sum_B[j] <= K) { if (ans < i + j) { ans = i + j; } // p = j; break; } } } cout << ans << endl; return 0; }
#include <iostream> #include <vector> using namespace std; int main() { vector<long long> A, B; long long K; long long N, M; cin >> N >> M >> K; vector<long long> Sum_A(N + 1, 0), Sum_B(M + 1, 0); int tmp; Sum_A.push_back(0); for (int i = 1; i <= N; i++) { cin >> tmp; A.push_back(tmp); Sum_A[i] = Sum_A[i - 1] + tmp; } Sum_B.push_back(0); for (int i = 1; i <= M; i++) { cin >> tmp; B.push_back(tmp); Sum_B[i] = Sum_B[i - 1] + tmp; } int ans = 0; long long p = M; for (int i = 0; i <= N; i++) { for (int j = p; j >= 0; j--) { if (Sum_A[i] + Sum_B[j] <= K) { if (ans < i + j) { ans = i + j; } p = j; break; } } } cout << ans << endl; return 0; }
replace
31
32
31
32
TLE
p02623
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { int t = 1; // cin>>t; while (t--) { ll n, m, k; cin >> n >> m >> k; ll arr1[n], arr2[m]; for (int i = 0; i < n; i++) cin >> arr1[i]; for (int i = 0; i < m; i++) cin >> arr2[i]; ll dp[n + 1]; dp[0] = arr1[0]; ll max_ = 0, run = 0, i = 0; for (i = 0; i < n && run + arr1[i] <= k; i++) { run += arr1[i]; } max_ = i; run = 0; for (int i = 1; i < m; i++) dp[i] = dp[i - 1] + arr1[i]; for (int i = 0; i < m && run <= k; i++) { // i books from second pile // costed run run += arr2[i]; if (run > k) break; ll idx = upper_bound(dp, dp + n, k - run) - dp; // cout<<" for run ="<<run<<" "<<i+1<<" + "<<idx<<endl; max_ = max(max_, i + 1 + idx); } cout << max_; } }
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { int t = 1; // cin>>t; while (t--) { ll n, m, k; cin >> n >> m >> k; ll arr1[n], arr2[m]; for (int i = 0; i < n; i++) cin >> arr1[i]; for (int i = 0; i < m; i++) cin >> arr2[i]; ll dp[n + 1]; dp[0] = arr1[0]; ll max_ = 0, run = 0, i = 0; for (i = 0; i < n && run + arr1[i] <= k; i++) { run += arr1[i]; } max_ = i; run = 0; for (int i = 1; i < n; i++) dp[i] = dp[i - 1] + arr1[i]; for (int i = 0; i < m && run <= k; i++) { // i books from second pile // costed run run += arr2[i]; if (run > k) break; ll idx = upper_bound(dp, dp + n, k - run) - dp; // cout<<" for run ="<<run<<" "<<i+1<<" + "<<idx<<endl; max_ = max(max_, i + 1 + idx); } cout << max_; } }
replace
23
24
23
24
0
p02623
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, int>; int main() { int n, m, k; cin >> n >> m >> k; vector<int> a(n), b(m); a[0] = 0; b[0] = 0; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m; i++) cin >> b[i]; int ans = 0, j = m; ll tot = 0; for (int i = 0; i < m; i++) tot += b[i]; for (int i = 0; i < n + 1; i++) { while (tot > k) { j--; tot -= b[j]; } if (tot > k) break; ans = max(ans, i + j); if (i == n) break; tot += a[i]; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, int>; int main() { int n, m, k; cin >> n >> m >> k; vector<int> a(n), b(m); a[0] = 0; b[0] = 0; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m; i++) cin >> b[i]; int ans = 0, j = m; ll tot = 0; for (int i = 0; i < m; i++) tot += b[i]; for (int i = 0; i < n + 1; i++) { while (tot > k && j > 0) { j--; tot -= b[j]; } if (tot > k) break; ans = max(ans, i + j); if (i == n) break; tot += a[i]; } cout << ans << endl; return 0; }
replace
22
23
22
23
0
p02623
C++
Runtime Error
#include <bits/stdc++.h> #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define endl "\n" using namespace std; using ll = long long; const ll MOD = 1000000007LL; // = 10^9 + 7 const double PI = 3.14159265358979; void solve() { ll n, m, k; cin >> n >> m >> k; vector<ll> a(n + 1, 0); vector<ll> b(m + 1, 0); // dp[a][b] vector<vector<ll>> dp(n, vector<ll>(m, 0)); for (int i = 1; i <= n; ++i) { cin >> a[i]; } for (int i = 1; i <= m; ++i) { cin >> b[i]; } for (int i = 1; i <= n; ++i) { a[i] += a[i - 1]; // cout << i << " " << a[i] << endl; } // cout << " --- " << endl; for (int i = 1; i <= m; ++i) { b[i] += b[i - 1]; // cout << i << " " << b[i] << endl; } int ans = 0; for (int i = 0; i <= n; ++i) { if (k - a[i] < 0) continue; auto b_iter = upper_bound(b.begin(), b.end(), k - a[i]); int b_ind = distance(b.begin(), b_iter); // cout << i << " " << b_ind << endl; ans = max(ans, i + b_ind - 1); } cout << ans; } int main() { fastio; solve(); return 0; }
#include <bits/stdc++.h> #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define endl "\n" using namespace std; using ll = long long; const ll MOD = 1000000007LL; // = 10^9 + 7 const double PI = 3.14159265358979; void solve() { ll n, m, k; cin >> n >> m >> k; vector<ll> a(n + 1, 0); vector<ll> b(m + 1, 0); for (int i = 1; i <= n; ++i) { cin >> a[i]; } for (int i = 1; i <= m; ++i) { cin >> b[i]; } for (int i = 1; i <= n; ++i) { a[i] += a[i - 1]; // cout << i << " " << a[i] << endl; } // cout << " --- " << endl; for (int i = 1; i <= m; ++i) { b[i] += b[i - 1]; // cout << i << " " << b[i] << endl; } int ans = 0; for (int i = 0; i <= n; ++i) { if (k - a[i] < 0) continue; auto b_iter = upper_bound(b.begin(), b.end(), k - a[i]); int b_ind = distance(b.begin(), b_iter); // cout << i << " " << b_ind << endl; ans = max(ans, i + b_ind - 1); } cout << ans; } int main() { fastio; solve(); return 0; }
delete
19
22
19
19
0
p02623
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long using namespace std; int main() { ll n, m, k; cin >> n >> m >> k; ll A[n]; ll B[n]; ll preA[n + 1]; ll preB[m + 1]; preA[0] = 0; preB[0] = 0; for (ll i = 0; i < n; ++i) { cin >> A[i]; preA[i + 1] = preA[i] + A[i]; } for (ll i = 0; i < m; ++i) { cin >> B[i]; preB[i + 1] = preB[i] + B[i]; } ll max = 0; ll index = m; for (ll i = 0; i <= n; ++i) { ll totalLeft = k - preA[i]; if (totalLeft < 0) { break; } while (preB[index] > totalLeft) { index--; } if (index + i > max) { max = index + i; } } cout << max; }
#include <bits/stdc++.h> #define ll long long using namespace std; int main() { ll n, m, k; cin >> n >> m >> k; ll A[n]; ll B[m]; ll preA[n + 1]; ll preB[m + 1]; preA[0] = 0; preB[0] = 0; for (ll i = 0; i < n; ++i) { cin >> A[i]; preA[i + 1] = preA[i] + A[i]; } for (ll i = 0; i < m; ++i) { cin >> B[i]; preB[i + 1] = preB[i] + B[i]; } ll max = 0; ll index = m; for (ll i = 0; i <= n; ++i) { ll totalLeft = k - preA[i]; if (totalLeft < 0) { break; } while (preB[index] > totalLeft) { index--; } if (index + i > max) { max = index + i; } } cout << max; }
replace
9
10
9
10
0
p02623
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> #include <limits.h> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <vector> typedef unsigned long long ULLONG; typedef long long LLONG; static const LLONG MOD_NUM = 1000000007; template <class _T> static void getval(_T &a) { std::cin >> a; } template <class _T> static void getval(_T &a, _T &b) { std::cin >> a >> b; } template <class _T> static void getval(_T &a, _T &b, _T &c) { std::cin >> a >> b >> c; } template <class _T> static _T tp_abs(_T a) { if (a < (_T)0) { a *= (_T)-1; } return a; } template <class _T> static void tp_swap(_T &right, _T &left) { // usage: tp_swap<type name>(a, b); _T tmp = right; right = left; left = tmp; } static void C(); int main() { C(); fflush(stdout); return 0; } static void C() { int N, M; getval(N, M); LLONG K; getval(K); std::vector<LLONG> sumAi(N + 1, 0), sumBi(M + 1, 0); for (int i = 1; i <= N; i++) { LLONG ai; getval(ai); sumAi[i] = sumAi[i - 1] + ai; } for (int i = 1; i <= M; i++) { LLONG bi; getval(bi); sumBi[i] = sumBi[i - 1] + bi; } int bookMax = 0, cnt = 0; for (int b = M; b >= 0; b--) { for (int a = 0; a <= N; a++) { if (sumAi[a] + sumBi[b] <= K) { bookMax = std::max(bookMax, b + a); } } } printf("%d\n", bookMax); }
#include <algorithm> #include <iostream> #include <limits.h> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <vector> typedef unsigned long long ULLONG; typedef long long LLONG; static const LLONG MOD_NUM = 1000000007; template <class _T> static void getval(_T &a) { std::cin >> a; } template <class _T> static void getval(_T &a, _T &b) { std::cin >> a >> b; } template <class _T> static void getval(_T &a, _T &b, _T &c) { std::cin >> a >> b >> c; } template <class _T> static _T tp_abs(_T a) { if (a < (_T)0) { a *= (_T)-1; } return a; } template <class _T> static void tp_swap(_T &right, _T &left) { // usage: tp_swap<type name>(a, b); _T tmp = right; right = left; left = tmp; } static void C(); int main() { C(); fflush(stdout); return 0; } static void C() { int N, M; getval(N, M); LLONG K; getval(K); std::vector<LLONG> sumAi(N + 1, 0), sumBi(M + 1, 0); for (int i = 1; i <= N; i++) { LLONG ai; getval(ai); sumAi[i] = sumAi[i - 1] + ai; } for (int i = 1; i <= M; i++) { LLONG bi; getval(bi); sumBi[i] = sumBi[i - 1] + bi; } int bookMax = 0, bIdx = M; for (int a = 0; a <= N; a++) { if (sumAi[a] <= K) { bookMax = std::max(bookMax, a); } while (bIdx) { if (sumAi[a] + sumBi[bIdx] <= K) { bookMax = std::max(bookMax, bIdx + a); break; } else { bIdx--; } } } printf("%d\n", bookMax); }
replace
63
68
63
74
TLE
p02623
C++
Runtime Error
#include <algorithm> #include <iostream> #include <vector> int main() { std::ios_base::sync_with_stdio(false); int n, m; long long k; std::cin >> n >> m >> k; std::vector<long long> a(n + 1), b(m + 1); for (int i = 1; i <= n; i++) { std::cin >> a[i]; a[i] += a[i - 1]; } for (int i = 1; i <= m; i++) { std::cin >> b[i]; b[i] += b[i - 1]; } int c = 0; for (int i = 0; i <= n && a[i] <= k; i++) { int j = std::lower_bound(b.begin(), b.end(), k - a[i]) - b.begin(); if (j > m) j = m; if (b[j] > k - a[j]) j--; if (j < 0) j = 0; c = std::max(c, i + j); } std::cout << c << '\n'; return 0; }
#include <algorithm> #include <iostream> #include <vector> int main() { std::ios_base::sync_with_stdio(false); int n, m; long long k; std::cin >> n >> m >> k; std::vector<long long> a(n + 1), b(m + 1); for (int i = 1; i <= n; i++) { std::cin >> a[i]; a[i] += a[i - 1]; } for (int i = 1; i <= m; i++) { std::cin >> b[i]; b[i] += b[i - 1]; } int i = 0, j = 0; while (i <= n && a[i] <= k) i++; i--; while (j <= m && a[i] + b[j] <= k) j++; j--; int c = i + j; while (i > 0) { i--; while (j <= m && a[i] + b[j] <= k) j++; j--; c = std::max(c, i + j); } std::cout << c << '\n'; return 0; }
replace
18
27
18
31
0
p02623
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll INF = 1LL << 60; int main() { int n, m, k; cin >> n >> m >> k; vector<int> a(n), b(n); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < m; i++) { cin >> b[i]; } ll time = 0; ll book_b = 0; ll book_a = 0; ll books = 0; for (ll i = 0; i < n and time + a[i] <= k; i++) { time += a[i]; book_a = i + 1; } for (ll i = book_a - 1; i >= -1; i--) { for (ll j = book_b; j < m and time + b[j] <= k; j++) { time += b[j]; book_b = j + 1; } books = max(books, book_a + book_b); if (book_a != 0) { time -= a[i]; book_a--; } } cout << books << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll INF = 1LL << 60; int main() { int n, m, k; cin >> n >> m >> k; vector<int> a(n), b(m); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < m; i++) { cin >> b[i]; } ll time = 0; ll book_b = 0; ll book_a = 0; ll books = 0; for (ll i = 0; i < n and time + a[i] <= k; i++) { time += a[i]; book_a = i + 1; } for (ll i = book_a - 1; i >= -1; i--) { for (ll j = book_b; j < m and time + b[j] <= k; j++) { time += b[j]; book_b = j + 1; } books = max(books, book_a + book_b); if (book_a != 0) { time -= a[i]; book_a--; } } cout << books << endl; return 0; }
replace
8
9
8
9
0
p02623
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i = a; i < b; i += 1) #define repb(i, a, b) for (int i = a; i >= b; i--) #define repv(arr) for (auto it = arr[i].begin(); it != arr[i].end(); it++) #define vi vector<int> #define vb vector<bool> #define vs vector<string> #define vl vector<long long int> #define ssortA(arr) stable_sort(arr.begin(), arr.end()) #define search(arr, c) binary_search(arr.begin(), arr.end(), c) #define pb push_back #define ll long long #define LCM(a, b) boost::math::lcm(a, b) #define cl_bf cin.ignore(numeric_limits<streamsize>::max(), '\n'); int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m; ll k; cin >> n >> m >> k; vl arr(n + 1), b(m + 1); rep(i, 1, n + 1) { cin >> arr[i]; } rep(i, 1, m + 1) { cin >> b[i]; } int max = 0; vl prea(n + 1, 0), preb(m + 1, 0); rep(i, 1, n + 1) { prea[i] += prea[i - 1] + arr[i]; } rep(i, 1, n + 1) { preb[i] += b[i] + preb[i - 1]; } int i = 1, j = n; while (1) { if (j < 0 || i > m) { break; } else { if (prea[j] + preb[i] <= k) { if (i + j > max) max = i + j; i++; } else { j--; } } } cout << max << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i = a; i < b; i += 1) #define repb(i, a, b) for (int i = a; i >= b; i--) #define repv(arr) for (auto it = arr[i].begin(); it != arr[i].end(); it++) #define vi vector<int> #define vb vector<bool> #define vs vector<string> #define vl vector<long long int> #define ssortA(arr) stable_sort(arr.begin(), arr.end()) #define search(arr, c) binary_search(arr.begin(), arr.end(), c) #define pb push_back #define ll long long #define LCM(a, b) boost::math::lcm(a, b) #define cl_bf cin.ignore(numeric_limits<streamsize>::max(), '\n'); int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m; ll k; cin >> n >> m >> k; vl arr(n + 1), b(m + 1); rep(i, 1, n + 1) { cin >> arr[i]; } rep(i, 1, m + 1) { cin >> b[i]; } int max = 0; vl prea(n + 1, 0), preb(m + 1, 0); rep(i, 1, n + 1) { prea[i] += prea[i - 1] + arr[i]; } rep(i, 1, m + 1) { preb[i] += preb[i - 1] + b[i]; } int i = 0, j = n; while (1) { if (j < 0 || i > m) { break; } else { if (prea[j] + preb[i] <= k) { if (i + j > max) max = i + j; i++; } else { j--; } } } cout << max << endl; }
replace
32
34
32
34
0
p02623
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; using ll = long long; #define eb emplace_back #define pb push_back // #define mp make_pair #define ff first #define ss second #ifdef LOCAL #include "debug.h" #else #define debug(...) 42 #endif void io() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // #include <ext/rope> // using namespace __gnu_pbds; // using namespace __gnu_cxx; // template<typename T> using oset = tree <T, null_type, less <T>, rb_tree_tag, // tree_order_statistics_node_update >; template<typename T> using // MinPriorityQueue = priority_queue <T, vector <T>, greater <T> >; // template<typename T> void done(T ans) {cout << ans << "\n"; exit(0);} template <typename A> istream &operator>>(istream &input, vector<A> &x) { for (auto &i : x) input >> i; return input; } template <typename A> ostream &operator<<(ostream &output, vector<A> &x) { for (auto &i : x) output << i << ' '; return output; } template <typename T, typename U> istream &operator>>(istream &is, pair<T, U> &p) { is >> p.first >> p.second; return is; } template <typename T, typename U> ostream &operator<<(ostream &os, pair<T, U> &p) { os << p.first << ' ' << p.second; return os; } const int mod = 1e9 + 7; const int N = 1e6 + 5; int main() { io(); ll n, m, k; cin >> n >> m >> k; ll a[n], b[n]; vector<ll> pre1(n), pre2(m); for (int i = 0; i < n; i++) { cin >> a[i]; if (i) pre1[i] += pre1[i - 1]; pre1[i] += a[i]; } for (int i = 0; i < m; i++) { cin >> b[i]; if (i) pre2[i] += pre2[i - 1]; pre2[i] += b[i]; } int ans = 0; for (int i = 0; i < m; i++) { if (k >= pre2[i]) { ans = i + 1; } } for (int i = 0; i < n; i++) { if (pre1[i] > k) break; int rem = k - pre1[i]; auto it = upper_bound(pre2.begin(), pre2.end(), rem); if (it == pre2.begin()) { ans = max(ans, i + 1); continue; } else { ans = max(ans, (int)(it - pre2.begin() + i + 1)); debug(ans); } } cout << ans; }
#include "bits/stdc++.h" using namespace std; using ll = long long; #define eb emplace_back #define pb push_back // #define mp make_pair #define ff first #define ss second #ifdef LOCAL #include "debug.h" #else #define debug(...) 42 #endif void io() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // #include <ext/rope> // using namespace __gnu_pbds; // using namespace __gnu_cxx; // template<typename T> using oset = tree <T, null_type, less <T>, rb_tree_tag, // tree_order_statistics_node_update >; template<typename T> using // MinPriorityQueue = priority_queue <T, vector <T>, greater <T> >; // template<typename T> void done(T ans) {cout << ans << "\n"; exit(0);} template <typename A> istream &operator>>(istream &input, vector<A> &x) { for (auto &i : x) input >> i; return input; } template <typename A> ostream &operator<<(ostream &output, vector<A> &x) { for (auto &i : x) output << i << ' '; return output; } template <typename T, typename U> istream &operator>>(istream &is, pair<T, U> &p) { is >> p.first >> p.second; return is; } template <typename T, typename U> ostream &operator<<(ostream &os, pair<T, U> &p) { os << p.first << ' ' << p.second; return os; } const int mod = 1e9 + 7; const int N = 1e6 + 5; int main() { io(); ll n, m, k; cin >> n >> m >> k; ll a[n], b[m]; vector<ll> pre1(n), pre2(m); for (int i = 0; i < n; i++) { cin >> a[i]; if (i) pre1[i] += pre1[i - 1]; pre1[i] += a[i]; } for (int i = 0; i < m; i++) { cin >> b[i]; if (i) pre2[i] += pre2[i - 1]; pre2[i] += b[i]; } int ans = 0; for (int i = 0; i < m; i++) { if (k >= pre2[i]) { ans = i + 1; } } for (int i = 0; i < n; i++) { if (pre1[i] > k) break; int rem = k - pre1[i]; auto it = upper_bound(pre2.begin(), pre2.end(), rem); if (it == pre2.begin()) { ans = max(ans, i + 1); continue; } else { ans = max(ans, (int)(it - pre2.begin() + i + 1)); debug(ans); } } cout << ans; }
replace
64
65
64
65
0
p02623
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep2(i, n) for (int i = 1; i <= (n); ++i) #define all(x) (x).begin(), (x).end() #define Sort(x) sort((x).begin(), (x).end()) #define Sort2(x) sort((x).begin(), (x).end(), greater<int>()) #define pb push_back using namespace std; using ll = long long; using P = pair<int, int>; using Graph = vector<vector<int>>; // グラフ型 int main() { int n, m, k; cin >> n >> m >> k; vector<int> a(n); rep(i, n) cin >> a[i]; vector<int> b(m); rep(i, m) cin >> b[i]; vector<ll> sa(n + 1); rep(i, n) { sa[i + 1] = a[i] + sa[i]; } vector<ll> sb(m + 1); rep(i, m) { sb[i + 1] = a[i] + sb[i]; } int ans = 0; rep(i, n + 1) { ll k2 = k - sa[i]; if (k2 < 0) continue; auto c = upper_bound(sb.begin(), sb.end(), k2); int j = distance(sb.begin(), c); ans = max(ans, i + j - 1); } cout << ans << endl; } /* sb = 0,1,5,7,8,9 5 = 3 4 = 2 0 = 1 */ /* g++ b.cpp ./a.out oj d https://atcoder.jp/contests/abc172/tasks/abc172_c oj t */
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep2(i, n) for (int i = 1; i <= (n); ++i) #define all(x) (x).begin(), (x).end() #define Sort(x) sort((x).begin(), (x).end()) #define Sort2(x) sort((x).begin(), (x).end(), greater<int>()) #define pb push_back using namespace std; using ll = long long; using P = pair<int, int>; using Graph = vector<vector<int>>; // グラフ型 int main() { int n, m, k; cin >> n >> m >> k; vector<int> a(n); rep(i, n) cin >> a[i]; vector<int> b(m); rep(i, m) cin >> b[i]; vector<ll> sa(n + 1); rep(i, n) { sa[i + 1] = a[i] + sa[i]; } vector<ll> sb(m + 1); rep(i, m) { sb[i + 1] = b[i] + sb[i]; } int ans = 0; rep(i, n + 1) { ll k2 = k - sa[i]; if (k2 < 0) continue; auto c = upper_bound(sb.begin(), sb.end(), k2); int j = distance(sb.begin(), c); ans = max(ans, i + j - 1); } cout << ans << endl; } /* sb = 0,1,5,7,8,9 5 = 3 4 = 2 0 = 1 */ /* g++ b.cpp ./a.out oj d https://atcoder.jp/contests/abc172/tasks/abc172_c oj t */
replace
23
24
23
24
0
p02623
C++
Runtime Error
#include <algorithm> #include <iostream> #include <vector> int main() { long long n, m, k; std::cin >> n >> m >> k; // long long a[n+1], b[m+1]; std::vector<long long> a{n + 1}, b{m + 1}; a[0] = 0; b[0] = 0; for (int i = 1; i < n + 1; i++) std::cin >> a[i]; for (int i = 1; i < m + 1; i++) std::cin >> b[i]; for (int i = 1; i < n + 1; i++) a[i] += a[i - 1]; for (int i = 1; i < m + 1; i++) b[i] += b[i - 1]; long long ans = 0, r = m; for (int i = 0; i < n + 1; i++) { if (a[i] > k) break; while (a[i] + b[r] > k) r--; ans = std::max({ans, i + r}); } std::cout << ans; return 0; }
#include <algorithm> #include <iostream> #include <vector> int main() { long long n, m, k; std::cin >> n >> m >> k; // long long a[n+1], b[m+1]; std::vector<long long> a(n + 1), b(m + 1); a[0] = 0; b[0] = 0; for (int i = 1; i < n + 1; i++) std::cin >> a[i]; for (int i = 1; i < m + 1; i++) std::cin >> b[i]; for (int i = 1; i < n + 1; i++) a[i] += a[i - 1]; for (int i = 1; i < m + 1; i++) b[i] += b[i - 1]; long long ans = 0, r = m; for (int i = 0; i < n + 1; i++) { if (a[i] > k) break; while (a[i] + b[r] > k) r--; ans = std::max({ans, i + r}); } std::cout << ans; return 0; }
replace
8
9
8
9
-6
Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)
p02623
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (long long i = 0; i < n; i++) #define Rep(i, n) for (long long i = 1; i < n; i++) #define ll long long #include <cmath> #include <iomanip> #include <iostream> #include <math.h> #include <numeric> #include <queue> #include <set> #include <vector> using namespace std; #define PI acos(-1) using P = pair<ll, ll>; ll ketasu(ll a) { ll num = 1; while (a / 10) { num++; a /= 10; } return num; } ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a * b / gcd(a, b); } ll kosuu(ll a) { ll sum = 0; for (ll i = 1; i * i <= a; i++) { if (a % i == 0) { if (a != 1 && i * i != a) { sum += 2; } else { sum++; } } } return sum; } ll di[] = {1, 0, -1, 0}; ll dj[] = {0, -1, 0, 1}; struct UnionFind { vector<int> d; UnionFind(int n = 0) : d(n, -1) {} int find(int x) { if ((d[x]) < 0) return x; return d[x] = find(d[x]); } bool unite(int x, int y) { x = find(x); y = find(y); if (x == y) return false; if (d[x] > d[y]) swap(x, y); d[x] += d[y]; d[y] = x; return true; } bool same(int x, int y) { return find(x) == find(y); }; int size(int x) { return -d[find(x)]; }; }; int deg[100005]; vector<int> to[100005]; ll n, m, q; vector<ll> a, b, c, d; ll ans; void dfs(vector<ll> A) { if (A.size() == n + 1) { ll sum = 0; rep(i, q) { if (A[b[i]] - A[a[i]] == c[i]) sum += d[i]; } ans = max(ans, sum); return; } A.push_back(A.back()); while (A.back() <= m) { dfs(A); A.back()++; } } // auto mod int // https://youtu.be/L8grWxBlIZ4?t=9858 // https://youtu.be/ERZuLAxZffQ?t=4807 : optimize // https://youtu.be/8uowVvQ_-Mo?t=1329 : division const int mod = 1000000007; 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 { return mint(*this) += a; } mint operator-(const mint a) const { return mint(*this) -= a; } mint operator*(const mint a) const { return mint(*this) *= a; } mint pow(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 { return mint(*this) /= a; } }; istream &operator>>(istream &is, mint &a) { return is >> a.x; } ostream &operator<<(ostream &os, const mint &a) { return os << a.x; } mint f(int n) { if (n == 0) return 1; mint x = f(2 / n); x *= x; if (n % 2 == 1) x *= 2; return x; } mint choose(int n, int a) { mint x = 1, y = 1; rep(i, a) { x *= n - i; y *= a + i; } return x / y; } int main() { ll n, m, k; cin >> n >> m >> k; vector<ll> a(n); vector<ll> b(m); rep(i, n) cin >> a[i]; rep(i, m) cin >> b[i]; vector<ll> A(n + 1); vector<ll> B(m + 1); A[0] = 0; B[0] = 0; Rep(i, n + 1) A[i] = A[i - 1] + a[i - 1]; Rep(i, m + 1) B[i] = B[i - 1] + b[i - 1]; ll ans = 0; ll j = m; rep(i, n + 1) { ll sum = A[i]; if (k < sum) break; while (k <= sum + B[j]) { j--; } ans = max(ans, i + j); } cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (long long i = 0; i < n; i++) #define Rep(i, n) for (long long i = 1; i < n; i++) #define ll long long #include <cmath> #include <iomanip> #include <iostream> #include <math.h> #include <numeric> #include <queue> #include <set> #include <vector> using namespace std; #define PI acos(-1) using P = pair<ll, ll>; ll ketasu(ll a) { ll num = 1; while (a / 10) { num++; a /= 10; } return num; } ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a * b / gcd(a, b); } ll kosuu(ll a) { ll sum = 0; for (ll i = 1; i * i <= a; i++) { if (a % i == 0) { if (a != 1 && i * i != a) { sum += 2; } else { sum++; } } } return sum; } ll di[] = {1, 0, -1, 0}; ll dj[] = {0, -1, 0, 1}; struct UnionFind { vector<int> d; UnionFind(int n = 0) : d(n, -1) {} int find(int x) { if ((d[x]) < 0) return x; return d[x] = find(d[x]); } bool unite(int x, int y) { x = find(x); y = find(y); if (x == y) return false; if (d[x] > d[y]) swap(x, y); d[x] += d[y]; d[y] = x; return true; } bool same(int x, int y) { return find(x) == find(y); }; int size(int x) { return -d[find(x)]; }; }; int deg[100005]; vector<int> to[100005]; ll n, m, q; vector<ll> a, b, c, d; ll ans; void dfs(vector<ll> A) { if (A.size() == n + 1) { ll sum = 0; rep(i, q) { if (A[b[i]] - A[a[i]] == c[i]) sum += d[i]; } ans = max(ans, sum); return; } A.push_back(A.back()); while (A.back() <= m) { dfs(A); A.back()++; } } // auto mod int // https://youtu.be/L8grWxBlIZ4?t=9858 // https://youtu.be/ERZuLAxZffQ?t=4807 : optimize // https://youtu.be/8uowVvQ_-Mo?t=1329 : division const int mod = 1000000007; 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 { return mint(*this) += a; } mint operator-(const mint a) const { return mint(*this) -= a; } mint operator*(const mint a) const { return mint(*this) *= a; } mint pow(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 { return mint(*this) /= a; } }; istream &operator>>(istream &is, mint &a) { return is >> a.x; } ostream &operator<<(ostream &os, const mint &a) { return os << a.x; } mint f(int n) { if (n == 0) return 1; mint x = f(2 / n); x *= x; if (n % 2 == 1) x *= 2; return x; } mint choose(int n, int a) { mint x = 1, y = 1; rep(i, a) { x *= n - i; y *= a + i; } return x / y; } int main() { ll n, m, k; cin >> n >> m >> k; vector<ll> a(n); vector<ll> b(m); rep(i, n) cin >> a[i]; rep(i, m) cin >> b[i]; vector<ll> A(n + 1); vector<ll> B(m + 1); A[0] = 0; B[0] = 0; Rep(i, n + 1) A[i] = A[i - 1] + a[i - 1]; Rep(i, m + 1) B[i] = B[i - 1] + b[i - 1]; ll ans = 0; ll j = m; rep(i, n + 1) { ll sum = A[i]; if (k < sum) break; while (k < sum + B[j]) { j--; } ans = max(ans, i + j); } cout << ans << endl; }
replace
176
177
176
177
0
p02623
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; /*bool subseq(string s,string t){ ll y=0; for(ll i=0;y<s.size()&& i<t.size();i++){ if(s[y]==t[i]){ y++; } } if(y==s.size()) return true; else return false; }*/ /*ll x=1000000001; vector<bool>p(x,false); void prime(){ p[2]=true; for(ll i=3;i<x;i=i+2) p[i]=true; for(ll i=0;i<x;i=i+2){ if(p[i]){ for(ll j=i*i;j<x;j=j+i) p[j]=false; } } }*/ /*vector<ll> divisor(ll n){ vector<ll> d; for(ll i=1;i<=sqrt(n);i++){ if(n%i==0){ d.push_back(i); d.push_back(n/i); } } sort(d.begin(),d.end(),greater<ll>()); return d; }*/ /*bool bs(ll n,string s){ ll a[4]={0}; for(ll i=0;i<n-1;i++){ a[s[i]-'0']++; } for(ll i=n-1;i<s.size();i++){ a[s[i]-'0']++; if(a[1]>0 && a[2]>0 && a[3]>0) return true; a[s[i-n+1]-'0']--; } return false; }*/ /*ll binarySearch(ll n,ll a[],ll x){ ll low=0,high=n-1,mid,ans=-1; while(low<=high){ mid=low+(high-low)/2; if(a[mid]>=x){ high=mid-1; } else{ ans=mid; low=mid+1; } } return a[ans]; }*/ /*ll lcs(string a,string b,ll n,ll m){ ll dp[n+1][m+1]; for(ll i=0;i<=n;i++){ for(ll j=0;j<=m;j++){ if(i==0|| j==0) dp[i][j]=0; else if(a[i]==b[j]) dp[i][j]=1+dp[i-1][j-1]; else dp[i][j]=max(dp[i-1][j],dp[i][j-1]); } } return dp[n][m]; }*/ /*ll editDist(string a,string b,ll n,ll m){ vector<vector<ll> >dp(n+1,vector<ll>(m+1,-1)); for(ll i=0;i<=n;i++){ for(ll j=0;j<=m;j++){ if(i==0) dp[i][j]=j; else if(j==0) dp[i][j]=i; else if(a[i]==b[j]) dp[i][j]=dp[i-1][j-1]; else{ dp[i][j]=1+min(dp[i-1][j-1],min(dp[i-1][j],dp[i][j-1])); } } } return dp[n][m]; }*/ /*ll d1(vector<string>a,ll n,ll m,vector<vector<ll> >dp){ if(n<0 || m<0 ) return 0; if(n==0 && m==0) return 0; if(a[n][m]=='#') dp[n][m]=0; if((n==0 &&m==1) || (m==0&&n==1)) return 1 ; if(dp[n][m]!=-1) return dp[n][m]; dp[n][m]=d(a,n-1,m,dp)+d(a,n,m-1,dp); return dp[n][m]; }*/ /*ll solve(vector<ll>a,vector<ll>b,vector<ll>c,ll n,ll f,ll dp[][4]){ if(n==0) return 0; if(dp[n][f]!=-1) return dp[n][f]; if (f==1) return dp[n][1]=max(b[n-1]+solve(a,b,c,n-1,2,dp),c[n-1]+solve(a,b,c,n-1,3,dp)); if(f==2) return dp[n][2]=max(a[n-1]+solve(a,b,c,n-1,1,dp),c[n-1]+solve(a,b,c,n-1,3,dp)); if(f==3) return dp[n][3]=max(b[n-1]+solve(a,b,c,n-1,2,dp),a[n-1]+solve(a,b,c,n-1,1,dp)); return max(a[n-1]+solve(a,b,c,n-1,1,dp),max(b[n-1]+solve(a,b,c,n-1,2,dp),c[n-1]+solve(a,b,c,n-1,3,dp))); }*/ ll solve(vector<ll> a, vector<ll> b, ll n, ll m, ll k) {} int main() { ll n, m, k; cin >> n >> m >> k; vector<ll> a(n); vector<ll> b(m); for (ll i = 0; i < n; i++) cin >> a[i]; for (ll i = 0; i < m; i++) cin >> b[i]; ll i = 0, j = 0; ll x = 0; while (i < n && a[i] + x <= k) { x = x + a[i]; i++; } while (j < m && b[j] + x <= k) { x = x + b[j]; j++; } ll ans = i + j, y = i + j; // cout<<i<<j; if (i == 0) { cout << j; return 0; } for (ll p = i - 1; p >= 0; p--) { y--; x = x - a[i]; while (j < n && b[j] + x <= k) { x = x + b[j]; j++; y++; } ans = max(ans, y); } cout << ans; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; /*bool subseq(string s,string t){ ll y=0; for(ll i=0;y<s.size()&& i<t.size();i++){ if(s[y]==t[i]){ y++; } } if(y==s.size()) return true; else return false; }*/ /*ll x=1000000001; vector<bool>p(x,false); void prime(){ p[2]=true; for(ll i=3;i<x;i=i+2) p[i]=true; for(ll i=0;i<x;i=i+2){ if(p[i]){ for(ll j=i*i;j<x;j=j+i) p[j]=false; } } }*/ /*vector<ll> divisor(ll n){ vector<ll> d; for(ll i=1;i<=sqrt(n);i++){ if(n%i==0){ d.push_back(i); d.push_back(n/i); } } sort(d.begin(),d.end(),greater<ll>()); return d; }*/ /*bool bs(ll n,string s){ ll a[4]={0}; for(ll i=0;i<n-1;i++){ a[s[i]-'0']++; } for(ll i=n-1;i<s.size();i++){ a[s[i]-'0']++; if(a[1]>0 && a[2]>0 && a[3]>0) return true; a[s[i-n+1]-'0']--; } return false; }*/ /*ll binarySearch(ll n,ll a[],ll x){ ll low=0,high=n-1,mid,ans=-1; while(low<=high){ mid=low+(high-low)/2; if(a[mid]>=x){ high=mid-1; } else{ ans=mid; low=mid+1; } } return a[ans]; }*/ /*ll lcs(string a,string b,ll n,ll m){ ll dp[n+1][m+1]; for(ll i=0;i<=n;i++){ for(ll j=0;j<=m;j++){ if(i==0|| j==0) dp[i][j]=0; else if(a[i]==b[j]) dp[i][j]=1+dp[i-1][j-1]; else dp[i][j]=max(dp[i-1][j],dp[i][j-1]); } } return dp[n][m]; }*/ /*ll editDist(string a,string b,ll n,ll m){ vector<vector<ll> >dp(n+1,vector<ll>(m+1,-1)); for(ll i=0;i<=n;i++){ for(ll j=0;j<=m;j++){ if(i==0) dp[i][j]=j; else if(j==0) dp[i][j]=i; else if(a[i]==b[j]) dp[i][j]=dp[i-1][j-1]; else{ dp[i][j]=1+min(dp[i-1][j-1],min(dp[i-1][j],dp[i][j-1])); } } } return dp[n][m]; }*/ /*ll d1(vector<string>a,ll n,ll m,vector<vector<ll> >dp){ if(n<0 || m<0 ) return 0; if(n==0 && m==0) return 0; if(a[n][m]=='#') dp[n][m]=0; if((n==0 &&m==1) || (m==0&&n==1)) return 1 ; if(dp[n][m]!=-1) return dp[n][m]; dp[n][m]=d(a,n-1,m,dp)+d(a,n,m-1,dp); return dp[n][m]; }*/ /*ll solve(vector<ll>a,vector<ll>b,vector<ll>c,ll n,ll f,ll dp[][4]){ if(n==0) return 0; if(dp[n][f]!=-1) return dp[n][f]; if (f==1) return dp[n][1]=max(b[n-1]+solve(a,b,c,n-1,2,dp),c[n-1]+solve(a,b,c,n-1,3,dp)); if(f==2) return dp[n][2]=max(a[n-1]+solve(a,b,c,n-1,1,dp),c[n-1]+solve(a,b,c,n-1,3,dp)); if(f==3) return dp[n][3]=max(b[n-1]+solve(a,b,c,n-1,2,dp),a[n-1]+solve(a,b,c,n-1,1,dp)); return max(a[n-1]+solve(a,b,c,n-1,1,dp),max(b[n-1]+solve(a,b,c,n-1,2,dp),c[n-1]+solve(a,b,c,n-1,3,dp))); }*/ ll solve(vector<ll> a, vector<ll> b, ll n, ll m, ll k) {} int main() { ll n, m, k; cin >> n >> m >> k; vector<ll> a(n); vector<ll> b(m); for (ll i = 0; i < n; i++) cin >> a[i]; for (ll i = 0; i < m; i++) cin >> b[i]; ll i = 0, j = 0; ll x = 0; while (i < n && a[i] + x <= k) { x = x + a[i]; i++; } while (j < m && b[j] + x <= k) { x = x + b[j]; j++; } ll ans = i + j, y = i + j; // cout<<i<<j; if (i == 0) { cout << j; return 0; } for (ll p = i - 1; p >= 0; p--) { y--; x = x - a[p]; while (j < m && b[j] + x <= k) { x = x + b[j]; j++; y++; } ans = max(ans, y); } cout << ans; }
replace
155
157
155
157
0
p02623
C++
Runtime Error
#include <bits/stdc++.h> #define int long long int using namespace std; #undef int int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif #define int long long int ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; while (t--) { int n, m, k; cin >> n >> m >> k; int crr[n], drr[n]; for (int i = 0; i < n; i++) { cin >> crr[i]; } for (int i = 0; i < m; i++) { cin >> drr[i]; } int s = 0; int i, j; for (i = 0; i < n; i++) { if (s + crr[i] <= k) s += crr[i]; else break; } int z = i - 1; for (j = 0; j < m; j++) { if (s + drr[j] <= k) s += drr[j]; else break; } int x = j; int ans = 0; ans = max(ans, z + x + 1); while (z >= 0) { if (x >= m) break; if (z < 0) break; s = s - crr[z]; z--; ans = max(ans, z + x + 1); if (x >= m) break; while (s + drr[x] <= k) { if (x >= m) break; s += drr[x]; x++; ans = max(ans, z + x + 1); if (x >= m) break; } } ans = max(ans, z + x + 1); cout << ans << endl; } return 0; }
#include <bits/stdc++.h> #define int long long int using namespace std; #undef int int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif #define int long long int ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; while (t--) { int n, m, k; cin >> n >> m >> k; int crr[n], drr[m]; for (int i = 0; i < n; i++) { cin >> crr[i]; } for (int i = 0; i < m; i++) { cin >> drr[i]; } int s = 0; int i, j; for (i = 0; i < n; i++) { if (s + crr[i] <= k) s += crr[i]; else break; } int z = i - 1; for (j = 0; j < m; j++) { if (s + drr[j] <= k) s += drr[j]; else break; } int x = j; int ans = 0; ans = max(ans, z + x + 1); while (z >= 0) { if (x >= m) break; if (z < 0) break; s = s - crr[z]; z--; ans = max(ans, z + x + 1); if (x >= m) break; while (s + drr[x] <= k) { if (x >= m) break; s += drr[x]; x++; ans = max(ans, z + x + 1); if (x >= m) break; } } ans = max(ans, z + x + 1); cout << ans << endl; } return 0; }
replace
18
19
18
19
-11
p02623
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; constexpr int inf = 0x3f3f3f3f; constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, m; cin >> n >> m; ll k; cin >> k; vector<ll> a(n + 1), b(n + 1); for (int i = 0; i < n; i++) { ll t; cin >> t; a[i + 1] = a[i] + t; } for (int i = 0; i < m; i++) { ll t; cin >> t; b[i + 1] = b[i] + t; } int ans = 0; for (int i = 0; i <= n; i++) { if (a[i] > k) break; int l = 0, r = m + 1; while (r - l > 1) { int mid = (l + r) / 2; if (a[i] + b[mid] <= k) l = mid; else r = mid; } ans = max(ans, i + l); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; constexpr int inf = 0x3f3f3f3f; constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, m; cin >> n >> m; ll k; cin >> k; vector<ll> a(n + 1), b(m + 1); for (int i = 0; i < n; i++) { ll t; cin >> t; a[i + 1] = a[i] + t; } for (int i = 0; i < m; i++) { ll t; cin >> t; b[i + 1] = b[i] + t; } int ans = 0; for (int i = 0; i <= n; i++) { if (a[i] > k) break; int l = 0, r = m + 1; while (r - l > 1) { int mid = (l + r) / 2; if (a[i] + b[mid] <= k) l = mid; else r = mid; } ans = max(ans, i + l); } cout << ans << endl; return 0; }
replace
15
16
15
16
0
p02623
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; using ii = pair<ll, ll>; const int MAX{200010}; const ll MOD{1000000007}, oo{1LL << 62}; ll solve(ll N, ll M, ll K, const vector<ll> &xs, const vector<ll> &ys) { ll ans = 0, sum = 0, a = 0, b = 0, c = 0; while (a < N and (sum + xs[a] <= K)) { ++c; sum += xs[a++]; } while (b < M and (sum + ys[b] <= K)) { sum += ys[b++]; ++c; } ans = c; --a; while (a >= 0) { sum -= xs[a--]; --c; while (b < M and (sum + xs[b] <= K)) { sum += ys[b++]; ++c; } ans = max(ans, c); } return ans; } int main() { ios::sync_with_stdio(false); ll N, M, K; cin >> N >> M >> K; vector<ll> xs(N), ys(M); for (int i = 0; i < N; ++i) cin >> xs[i]; for (int i = 0; i < M; ++i) cin >> ys[i]; auto ans = max(solve(N, M, K, xs, ys), solve(M, N, K, ys, xs)); cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ii = pair<ll, ll>; const int MAX{200010}; const ll MOD{1000000007}, oo{1LL << 62}; ll solve(ll N, ll M, ll K, const vector<ll> &xs, const vector<ll> &ys) { ll ans = 0, sum = 0, a = 0, b = 0, c = 0; while (a < N and (sum + xs[a] <= K)) { ++c; sum += xs[a++]; } while (b < M and (sum + ys[b] <= K)) { sum += ys[b++]; ++c; } ans = c; --a; while (a >= 0) { sum -= xs[a--]; --c; while (b < M and (sum + ys[b] <= K)) { sum += ys[b++]; ++c; } ans = max(ans, c); } return ans; } int main() { ios::sync_with_stdio(false); ll N, M, K; cin >> N >> M >> K; vector<ll> xs(N), ys(M); for (int i = 0; i < N; ++i) cin >> xs[i]; for (int i = 0; i < M; ++i) cin >> ys[i]; auto ans = max(solve(N, M, K, xs, ys), solve(M, N, K, ys, xs)); cout << ans << '\n'; return 0; }
replace
29
30
29
30
0
p02623
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N, M, K; long long sum = 0; cin >> N >> M >> K; vector<int> A(N), B(M); for (int i = 0; i < N; i++) { cin >> A.at(i); } for (int j = 0; j < N; j++) { cin >> B.at(j); sum += B.at(j); } int ans = 0; int j = M; for (int i = 0; i < N + 1; i++) { while (j > 0 && sum > K) { j--; sum -= B.at(j); } if (sum > K) { break; } ans = max(ans, i + j); if (i == N) { break; } sum += A.at(i); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N, M, K; long long sum = 0; cin >> N >> M >> K; vector<int> A(N), B(M); for (int i = 0; i < N; i++) { cin >> A.at(i); } for (int j = 0; j < M; j++) { cin >> B.at(j); sum += B.at(j); } int ans = 0; int j = M; for (int i = 0; i < N + 1; i++) { while (j > 0 && sum > K) { j--; sum -= B.at(j); } if (sum > K) { break; } ans = max(ans, i + j); if (i == N) { break; } sum += A.at(i); } cout << ans << endl; }
replace
11
12
11
12
0
p02623
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; ////////////////////////////// Begin Macros #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define in(x, a, b) (a <= x and x < b) #define rep(i, N) for (int i = 0; i < (int)(N); i++) #define reprev(i, N) for (int i = (int)(N)-1; i >= 0; i--) #define rep1(i, N) for (int i = 1; i <= (int)(N); i++) #define rep1rev(i, N) for (int i = (int)(N); i >= 0; i--) #define forbe(i, b, e) for (int i = (b); i < (e); i++) #define forberev(i, b, e) for (int i = (e)-1; i >= (b); i--) #define forfl(i, f, l) for (int i = (f); i <= (l); i++) #define forflrev(i, f, l) for (int i = (l); i >= (f); i--) using ll = long long; using pii = pair<int, int>; using pil = pair<int, ll>; using pli = pair<ll, int>; using pll = pair<ll, ll>; template <typename T> bool chmax(T &m, const T q) { if (m < q) { m = q; return true; } else return false; } template <typename T> bool chmin(T &m, const T q) { if (m > q) { m = q; return true; } else return false; } template <typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return {l.first + r.first, l.second + r.second}; } template <typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return {l.first - r.first, l.second - r.second}; } template <typename T> pair<T, T> operator*(const pair<T, T> &l, const T &r) { return {l.first * r, l.second * r}; } template <typename T> pair<T, T> operator/(const pair<T, T> &l, const T &r) { return {l.first / r, l.second / r}; } template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (auto &v : vec) is >> v; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; } template <typename T> ostream &operator<<(ostream &os, const deque<T> &vec) { os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; } template <typename T> ostream &operator<<(ostream &os, const set<T> &vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template <typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template <typename T> ostream &operator<<(ostream &os, const multiset<T> &vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &pa) { is >> pa.first >> pa.second; return is; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa) { os << "(" << pa.first << "," << pa.second << ")"; return os; } template <typename... Ts> istream &operator>>(istream &is, tuple<Ts...> &theTuple) { apply([&is](Ts &...tupleArgs) { ((is >> tupleArgs), ...); }, theTuple); return is; } template <typename... Ts> ostream &operator<<(ostream &os, const tuple<Ts...> &theTuple) { apply( [&os](const Ts &...tupleArgs) { os << '('; size_t n(0); ((os << tupleArgs << (++n < sizeof...(Ts) ? "," : "")), ...); os << ')'; }, theTuple); return os; } template <typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp) { os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; } template <typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp) { os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; } template <typename T> void reset(vector<T> &v, const T reset_to) { for (auto &x : v) x = reset_to; } inline int popcount(const unsigned int x) { return __builtin_popcount(x); } #define dbg(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl; ll nC2(ll n) { return n * (n - 1) / 2; } const int intinf = numeric_limits<int>::max(); const ll llinf = numeric_limits<ll>::max(); const pii udlr[4] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; ////////////////////////////// End Macros void solve() { int N, M, K; cin >> N >> M >> K; vector<int> A(N), B(M); cin >> A >> B; vector<int> C(N + M); rep(i, N) C[i] = A[N - 1 - i]; rep(j, M) C[N + j] = B[j]; int l = 0, r = 0; int ans = 0; ll sum = 0; while (r < N + M) { if (sum + C[r] <= K) { sum += C[r]; r++; if (in(N - 1, l, r) or in(N, l, r)) chmax(ans, r - l); } else { sum -= C[l]; l++; } dbg(sum); } cout << ans << endl; } int main() { cerr << "start" << endl; // srand(time(0)); cout << fixed << setprecision(15); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; ////////////////////////////// Begin Macros #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define in(x, a, b) (a <= x and x < b) #define rep(i, N) for (int i = 0; i < (int)(N); i++) #define reprev(i, N) for (int i = (int)(N)-1; i >= 0; i--) #define rep1(i, N) for (int i = 1; i <= (int)(N); i++) #define rep1rev(i, N) for (int i = (int)(N); i >= 0; i--) #define forbe(i, b, e) for (int i = (b); i < (e); i++) #define forberev(i, b, e) for (int i = (e)-1; i >= (b); i--) #define forfl(i, f, l) for (int i = (f); i <= (l); i++) #define forflrev(i, f, l) for (int i = (l); i >= (f); i--) using ll = long long; using pii = pair<int, int>; using pil = pair<int, ll>; using pli = pair<ll, int>; using pll = pair<ll, ll>; template <typename T> bool chmax(T &m, const T q) { if (m < q) { m = q; return true; } else return false; } template <typename T> bool chmin(T &m, const T q) { if (m > q) { m = q; return true; } else return false; } template <typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return {l.first + r.first, l.second + r.second}; } template <typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return {l.first - r.first, l.second - r.second}; } template <typename T> pair<T, T> operator*(const pair<T, T> &l, const T &r) { return {l.first * r, l.second * r}; } template <typename T> pair<T, T> operator/(const pair<T, T> &l, const T &r) { return {l.first / r, l.second / r}; } template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (auto &v : vec) is >> v; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; } template <typename T> ostream &operator<<(ostream &os, const deque<T> &vec) { os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; } template <typename T> ostream &operator<<(ostream &os, const set<T> &vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template <typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template <typename T> ostream &operator<<(ostream &os, const multiset<T> &vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &pa) { is >> pa.first >> pa.second; return is; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa) { os << "(" << pa.first << "," << pa.second << ")"; return os; } template <typename... Ts> istream &operator>>(istream &is, tuple<Ts...> &theTuple) { apply([&is](Ts &...tupleArgs) { ((is >> tupleArgs), ...); }, theTuple); return is; } template <typename... Ts> ostream &operator<<(ostream &os, const tuple<Ts...> &theTuple) { apply( [&os](const Ts &...tupleArgs) { os << '('; size_t n(0); ((os << tupleArgs << (++n < sizeof...(Ts) ? "," : "")), ...); os << ')'; }, theTuple); return os; } template <typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp) { os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; } template <typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp) { os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; } template <typename T> void reset(vector<T> &v, const T reset_to) { for (auto &x : v) x = reset_to; } inline int popcount(const unsigned int x) { return __builtin_popcount(x); } #define dbg(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl; ll nC2(ll n) { return n * (n - 1) / 2; } const int intinf = numeric_limits<int>::max(); const ll llinf = numeric_limits<ll>::max(); const pii udlr[4] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; ////////////////////////////// End Macros void solve() { int N, M, K; cin >> N >> M >> K; vector<int> A(N), B(M); cin >> A >> B; vector<int> C(N + M); rep(i, N) C[i] = A[N - 1 - i]; rep(j, M) C[N + j] = B[j]; int l = 0, r = 0; int ans = 0; ll sum = 0; while (r < N + M) { if (sum + C[r] <= K) { sum += C[r]; r++; if (in(N - 1, l, r) or in(N, l, r)) chmax(ans, r - l); } else { sum -= C[l]; l++; } } cout << ans << endl; } int main() { cerr << "start" << endl; // srand(time(0)); cout << fixed << setprecision(15); solve(); return 0; }
delete
182
183
182
182
TLE
p02623
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> typedef long long ll; const ll MOD = 1e9 + 7; const long long INF = 1LL << 60; const double PI = 3.14159265358979323846; const int NMAX = 100005; using namespace std; int main() { ll n, m, k; cin >> n >> m >> k; ll suma[n + 1], sumb[m + 1]; vector<ll> a(n), b(m); suma[0] = 0; for (int i = 0; i < n; i++) { cin >> a[i]; suma[i + 1] = suma[i] + a[i]; } sumb[0] = 0; for (int i = 0; i < m; i++) { cin >> b[i]; sumb[i + 1] = sumb[i] + b[i]; } int j = m; int ans = 0; for (int i = 0; i <= n; i++) { ll d = suma[i]; if (d > k) break; for (j = m; j >= 0; j--) { if (d + sumb[j] <= k) break; } ans = max(ans, i + j); } cout << ans << endl; return 0; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> typedef long long ll; const ll MOD = 1e9 + 7; const long long INF = 1LL << 60; const double PI = 3.14159265358979323846; const int NMAX = 100005; using namespace std; int main() { ll n, m, k; cin >> n >> m >> k; ll suma[n + 1], sumb[m + 1]; vector<ll> a(n), b(m); suma[0] = 0; for (int i = 0; i < n; i++) { cin >> a[i]; suma[i + 1] = suma[i] + a[i]; } sumb[0] = 0; for (int i = 0; i < m; i++) { cin >> b[i]; sumb[i + 1] = sumb[i] + b[i]; } int j = m; int ans = 0; for (int i = 0; i <= n; i++) { ll d = suma[i]; if (d > k) break; for (j; j >= 0; j--) { if (d + sumb[j] <= k) break; } ans = max(ans, i + j); } cout << ans << endl; return 0; }
replace
40
41
40
41
TLE
p02623
C++
Runtime Error
#include <iostream> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ll int64_t using namespace std; // memory exceed /* int main() { int64_t n,m,k; cin >> n>>m>>k; vector<unsigned int> A(n+5); vector<unsigned int> B(m+5); rep(i,n){ cin >> A[i]; } rep(i,m){ cin >> B[i]; } vector<vector<unsigned int>> dp(n+5,vector<unsigned int>(m+5,0)); int ans = 0; dp[1][0] = A[0]; rep(i,n+1){ if(i>1){ dp[i][0] = dp[i-1][0] + A[i-1]; } if(dp[i][0] > k)break; if(ans < i){ ans = i; } rep(j,m+1){ if(j==0)continue; dp[i][j] = dp[i][j-1] + B[j-1]; if(dp[i][j] > k)break; if(ans < i+j){ ans = i+j; } } } cout << ans; return 0; } */ // time exceed /* int main(){ int64_t n,m,k; cin >> n>>m>>k; vector<int> A(n+5); vector<int> B(m+5); vector<int> Bsum(m+5); rep(i,n){ cin >> A[i]; } rep(i,m){ cin >> B[i]; if(i!=0){ Bsum[i] = Bsum[i-1] + B[i-1]; } } Bsum[m] = Bsum[m-1]+B[m-1]; int64_t asum =0; int ans =0; rep(i,n+1){ if(i!=0){ asum = asum + A[i-1]; } if(asum > k)break; rep(j,m+1){ if(asum + Bsum[j] > k)break; if(ans < i+j)ans = i+j; } } cout << ans; return 0; } */ int main() { int64_t n, m, k; cin >> n >> m >> k; vector<int> A(n + 5); vector<int> B(m + 5); ll sum = 0; rep(i, n) cin >> A[i + 1]; rep(i, m) cin >> B[i + 1]; int j = 0; while (sum < k || j < m + 1) { sum += B[j]; j++; } j--; int ans = 0; rep(i, n + 1) { sum += A[i]; while (true) { if (j == 0 || sum <= k) break; sum -= B[j]; j--; } if (sum > k) break; ans = max(ans, i + j); } cout << ans; return 0; }
#include <iostream> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ll int64_t using namespace std; // memory exceed /* int main() { int64_t n,m,k; cin >> n>>m>>k; vector<unsigned int> A(n+5); vector<unsigned int> B(m+5); rep(i,n){ cin >> A[i]; } rep(i,m){ cin >> B[i]; } vector<vector<unsigned int>> dp(n+5,vector<unsigned int>(m+5,0)); int ans = 0; dp[1][0] = A[0]; rep(i,n+1){ if(i>1){ dp[i][0] = dp[i-1][0] + A[i-1]; } if(dp[i][0] > k)break; if(ans < i){ ans = i; } rep(j,m+1){ if(j==0)continue; dp[i][j] = dp[i][j-1] + B[j-1]; if(dp[i][j] > k)break; if(ans < i+j){ ans = i+j; } } } cout << ans; return 0; } */ // time exceed /* int main(){ int64_t n,m,k; cin >> n>>m>>k; vector<int> A(n+5); vector<int> B(m+5); vector<int> Bsum(m+5); rep(i,n){ cin >> A[i]; } rep(i,m){ cin >> B[i]; if(i!=0){ Bsum[i] = Bsum[i-1] + B[i-1]; } } Bsum[m] = Bsum[m-1]+B[m-1]; int64_t asum =0; int ans =0; rep(i,n+1){ if(i!=0){ asum = asum + A[i-1]; } if(asum > k)break; rep(j,m+1){ if(asum + Bsum[j] > k)break; if(ans < i+j)ans = i+j; } } cout << ans; return 0; } */ int main() { int64_t n, m, k; cin >> n >> m >> k; vector<int> A(n + 5); vector<int> B(m + 5); ll sum = 0; rep(i, n) cin >> A[i + 1]; rep(i, m) cin >> B[i + 1]; int j = 0; while (sum < k && j < m + 1) { sum += B[j]; j++; } j--; int ans = 0; rep(i, n + 1) { sum += A[i]; while (true) { if (j == 0 || sum <= k) break; sum -= B[j]; j--; } if (sum > k) break; ans = max(ans, i + j); } cout << ans; return 0; }
replace
118
120
118
119
0
p02624
C++
Time Limit Exceeded
#include <bits/stdc++.h> #include <math.h> using namespace std; long long inf = 1000000007; int main() { long long n; cin >> n; long long ans = 0; for (long long i = 1; i <= n; i++) { long long pre = i; long long num = i; for (long long j = 2; j <= num; j++) { long long cnt = 0; while (num % j == 0) { num /= j; cnt++; } pre *= cnt + 1; } ans += pre; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #include <math.h> using namespace std; long long inf = 1000000007; int main() { long long n; cin >> n; long long ans = 0; for (long long i = 1; i <= n; i++) { long long y = n / i; ans += y * (1 + y) / 2 * i; } cout << ans << endl; return 0; }
replace
13
26
13
15
TLE
p02624
C++
Runtime Error
// Problem : D - Sum of Divisors // Contest : AtCoder - AtCoder Beginner Contest 172 // URL : https://atcoder.jp/contests/abc172/tasks/abc172_d // Memory Limit : 1024 MB // Time Limit : 3000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) #include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <unordered_map> #include <unordered_set> #include <vector> #define ll long long #define fi first #define se second #define pb push_back #define me memset const int N = 1e6 + 10; const int mod = 1e9 + 7; const int INF = 0x3f3f3f3f; using namespace std; typedef pair<int, int> PII; typedef pair<ll, ll> PLL; int n; ll a[N]; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; ll res = 1; for (int i = 2; i <= n; ++i) { for (int j = i; j <= n; j += i) { a[j]++; } } for (int i = 2; i <= n; ++i) { res += (a[i] + 1) * i; } cout << res << endl; return 0; }
// Problem : D - Sum of Divisors // Contest : AtCoder - AtCoder Beginner Contest 172 // URL : https://atcoder.jp/contests/abc172/tasks/abc172_d // Memory Limit : 1024 MB // Time Limit : 3000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) #include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <unordered_map> #include <unordered_set> #include <vector> #define ll long long #define fi first #define se second #define pb push_back #define me memset const int N = 1e7 + 10; const int mod = 1e9 + 7; const int INF = 0x3f3f3f3f; using namespace std; typedef pair<int, int> PII; typedef pair<ll, ll> PLL; int n; ll a[N]; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; ll res = 1; for (int i = 2; i <= n; ++i) { for (int j = i; j <= n; j += i) { a[j]++; } } for (int i = 2; i <= n; ++i) { res += (a[i] + 1) * i; } cout << res << endl; return 0; }
replace
25
26
25
26
0
p02624
C++
Time Limit Exceeded
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; typedef long long ll; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template <char cmp = '<'> bool icmp(ll a, ll b) { if (cmp == '>') return a > b; else return a < b; } namespace enhanced_pair { typedef pair<ll, ll> pll; ostream &operator<<(ostream &o, const pll a) { o << a.first << " " << a.second; return o; } istream &operator>>(istream &i, pll &p) { i >> p.first >> p.second; return i; } template <char cmp1 = '<', char cmp2 = '<'> bool pcmp(pll a, pll b) { return icmp<cmp1>(a.first, b.first) || (a.first == b.first && icmp<cmp2>(a.second, b.second)); } } // namespace enhanced_pair using namespace enhanced_pair; const ll NMAX = 1e7; const ll MOD = 1e9 + 7; ll lastbit(ll num) { return num & -num; } ll binPow(ll num, ll p, ll mod = MOD) { if (!p) return 1; ll aux = binPow(num, p / 2); return aux * aux % mod * (p % 2 ? num : 1) % mod; } bool p[NMAX]; ll primes[NMAX], cnt; void sieve() { for (ll i = 4; i < NMAX; i += 2) p[i] = 1; for (ll i = 3; i * i < NMAX; i += 2) { if (p[i] == 0) { for (ll j = i * i; j < NMAX; j += i) p[j] = 1; } } for (ll i = 2; i < 216; i++) if (!p[i]) primes[cnt++] = i; } ll f(ll n) { ll d = 1, initialN = n; for (ll i = 0; i < cnt && primes[i] * primes[i] * primes[i] <= initialN; i++) { ll pw = 0; while (n % primes[i] == 0) { n /= primes[i]; pw++; } d *= (pw + 1); } if (n == 1) return d; if (p[n] == 0) return d * 2; else { ll x = sqrt(n); if (x * x == n && p[x] == 0) return d * 3; } return d * 4; } int main() { sieve(); ll n, ans = 0; cin >> n; for (ll i = 1; i <= n; i++) ans += i * f(i); cout << ans; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; typedef long long ll; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template <char cmp = '<'> bool icmp(ll a, ll b) { if (cmp == '>') return a > b; else return a < b; } namespace enhanced_pair { typedef pair<ll, ll> pll; ostream &operator<<(ostream &o, const pll a) { o << a.first << " " << a.second; return o; } istream &operator>>(istream &i, pll &p) { i >> p.first >> p.second; return i; } template <char cmp1 = '<', char cmp2 = '<'> bool pcmp(pll a, pll b) { return icmp<cmp1>(a.first, b.first) || (a.first == b.first && icmp<cmp2>(a.second, b.second)); } } // namespace enhanced_pair using namespace enhanced_pair; const ll NMAX = 1e7; const ll MOD = 1e9 + 7; ll lastbit(ll num) { return num & -num; } ll binPow(ll num, ll p, ll mod = MOD) { if (!p) return 1; ll aux = binPow(num, p / 2); return aux * aux % mod * (p % 2 ? num : 1) % mod; } bool p[NMAX]; ll primes[NMAX], cnt; void sieve() { for (ll i = 4; i < NMAX; i += 2) p[i] = 1; for (ll i = 3; i * i < NMAX; i += 2) { if (p[i] == 0) { for (ll j = i * i; j < NMAX; j += i) p[j] = 1; } } for (ll i = 2; i < 216; i++) if (!p[i]) primes[cnt++] = i; } ll f(ll n) { ll d = 1, initialN = n; for (ll i = 0; i < cnt && primes[i] * primes[i] * primes[i] <= n; i++) { ll pw = 0; while (n % primes[i] == 0) { n /= primes[i]; pw++; } d *= (pw + 1); } if (n == 1) return d; if (p[n] == 0) return d * 2; else { ll x = sqrt(n); if (x * x == n && p[x] == 0) return d * 3; } return d * 4; } int main() { sieve(); ll n, ans = 0; cin >> n; for (ll i = 1; i <= n; i++) ans += i * f(i); cout << ans; return 0; }
replace
59
61
59
60
TLE
p02624
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long; ll a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, ans, tmp, hoge, fuga, piyo, sum; ll A[200100], B[200100], C[200100], D[200100]; string st, str; char ch; vector<pair<long long, long long>> prime_factorize(long long N) { vector<pair<long long, long long>> res; for (long long a = 2; a * a <= N; ++a) { if (N % a != 0) continue; long long ex = 0; while (N % a == 0) { ++ex; N /= a; } res.push_back({a, ex}); } if (N != 1) res.push_back({N, 1}); return res; } int main() { cin >> n; long double nn = (long double)n; for (int i = 1; i <= n; i++) { const auto &pf = prime_factorize(i); long long res = 1; for (auto p : pf) res *= p.second + 1; ans += i * res; } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; ll a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, ans, tmp, hoge, fuga, piyo, sum; ll A[200100], B[200100], C[200100], D[200100]; string st, str; char ch; vector<pair<long long, long long>> prime_factorize(long long N) { vector<pair<long long, long long>> res; for (long long a = 2; a * a <= N; ++a) { if (N % a != 0) continue; long long ex = 0; while (N % a == 0) { ++ex; N /= a; } res.push_back({a, ex}); } if (N != 1) res.push_back({N, 1}); return res; } int main() { cin >> n; if (n <= 100000) { m = 1; } else if (n <= 200000) { ans += 60838190672; m = 100001; } else if (n <= 300000) { ans += 257212470774; m = 200001; } else if (n <= 400000) { ans += 596981215450; m = 300001; } else if (n <= 500000) { ans += 1084296609104; m = 400001; } else if (n <= 600000) { ans += 1722125036282; m = 500001; } else if (n <= 700000) { ans += 2512661322551; m = 600001; } else if (n <= 800000) { ans += 3457770622390; m = 700001; } else if (n <= 900000) { ans += 4558987534475; m = 800001; } else if (n <= 1000000) { ans += 5817729717828; m = 900001; } else if (n <= 1100000) { ans += 7235062807366; m = 1000001; } else if (n <= 1200000) { ans += 8812039622862; m = 1100001; } else if (n <= 1300000) { ans += 10549659220862; m = 1200001; } else if (n <= 1400000) { ans += 12448845177256; m = 1300001; } else if (n <= 1500000) { ans += 14510332007222; m = 1400001; } else if (n <= 1600000) { ans += 16734924755096; m = 1500001; } else if (n <= 1700000) { ans += 19123138141378; m = 1600001; } else if (n <= 1800000) { ans += 21675833225770; m = 1700001; } else if (n <= 1900000) { ans += 24393634293809; m = 1800001; } else if (n <= 2000000) { ans += 27276821356759; m = 1900001; } else if (n <= 2100000) { ans += 30326413365285; m = 2000001; } else if (n <= 2200000) { ans += 33542358268005; m = 2100001; } else if (n <= 2300000) { ans += 36925459066686; m = 2200001; } else if (n <= 2400000) { ans += 40476248899052; m = 2300001; } else if (n <= 2500000) { ans += 44194833598353; m = 2400001; } else if (n <= 2600000) { ans += 48081994935671; m = 2500001; } else if (n <= 2700000) { ans += 52138123487538; m = 2600001; } else if (n <= 2800000) { ans += 56363615930452; m = 2700001; } else if (n <= 2900000) { ans += 60758384185743; m = 2800001; } else if (n <= 3000000) { ans += 65323182791149; m = 2900001; } else if (n <= 3100000) { ans += 70058785460280; m = 3000001; } else if (n <= 3200000) { ans += 74964555109988; m = 3100001; } else if (n <= 3300000) { ans += 80041527790312; m = 3200001; } else if (n <= 3400000) { ans += 85290161753688; m = 3300001; } else if (n <= 3500000) { ans += 90709780843282; m = 3400001; } else if (n <= 3600000) { ans += 96301520878991; m = 3500001; } else if (n <= 3700000) { ans += 102065855149715; m = 3600001; } else if (n <= 3800000) { ans += 108002269398516; m = 3700001; } else if (n <= 3900000) { ans += 114111807921375; m = 3800001; } else if (n <= 4000000) { ans += 120394329084663; m = 3900001; } else if (n <= 4100000) { ans += 126850549017804; m = 4000001; } else if (n <= 4200000) { ans += 133479467089246; m = 4100001; } else if (n <= 4300000) { ans += 140282617787827; m = 4200001; } else if (n <= 4400000) { ans += 147259491582477; m = 4300001; } else if (n <= 4500000) { ans += 154411235469265; m = 4400001; } else if (n <= 4600000) { ans += 161737467121483; m = 4500001; } else if (n <= 4700000) { ans += 169238102781982; m = 4600001; } else if (n <= 4800000) { ans += 176913242475822; m = 4700001; } else if (n <= 4900000) { ans += 184764302482181; m = 4800001; } else if (n <= 5000000) { ans += 192790925674795; m = 4900001; } else if (n <= 5100000) { ans += 200992441246692; m = 5000001; } else if (n <= 5200000) { ans += 209370037656611; m = 5100001; } else if (n <= 5300000) { ans += 217923890158764; m = 5200001; } else if (n <= 5400000) { ans += 226653316365413; m = 5300001; } else if (n <= 5500000) { ans += 235560022983960; m = 5400001; } else if (n <= 5600000) { ans += 244642548171917; m = 5500001; } else if (n <= 5700000) { ans += 253902107151677; m = 5600001; } else if (n <= 5800000) { ans += 263338334303632; m = 5700001; } else if (n <= 5900000) { ans += 272951354222680; m = 5800001; } else if (n <= 6000000) { ans += 282742772106696; m = 5900001; } else if (n <= 6100000) { ans += 292711324081941; m = 6000001; } else if (n <= 6200000) { ans += 302856699362737; m = 6100001; } else if (n <= 6300000) { ans += 313180253381239; m = 6200001; } else if (n <= 6400000) { ans += 323682486495499; m = 6300001; } else if (n <= 6500000) { ans += 334361760892115; m = 6400001; } else if (n <= 6600000) { ans += 345219904513529; m = 6500001; } else if (n <= 6700000) { ans += 356256480873339; m = 6600001; } else if (n <= 6800000) { ans += 367470747430202; m = 6700001; } else if (n <= 6900000) { ans += 378864539458650; m = 6800001; } else if (n <= 7000000) { ans += 390437889429971; m = 6900001; } else if (n <= 7100000) { ans += 402188826344049; m = 7000001; } else if (n <= 7200000) { ans += 414118956306590; m = 7100001; } else if (n <= 7300000) { ans += 426229374669116; m = 7200001; } else if (n <= 7400000) { ans += 438519040875971; m = 7300001; } else if (n <= 7500000) { ans += 450987322450746; m = 7400001; } else if (n <= 7600000) { ans += 463635895079489; m = 7500001; } else if (n <= 7700000) { ans += 476465015795706; m = 7600001; } else if (n <= 7800000) { ans += 489473701762655; m = 7700001; } else if (n <= 7900000) { ans += 502662434241804; m = 7800001; } else if (n <= 8000000) { ans += 516031076204871; m = 7900001; } else if (n <= 8100000) { ans += 529581632274134; m = 8000001; } else if (n <= 8200000) { ans += 543311223215741; m = 8100001; } else if (n <= 8300000) { ans += 557220889209512; m = 8200001; } else if (n <= 8400000) { ans += 571311613610574; m = 8300001; } else if (n <= 8500000) { ans += 585584064718129; m = 8400001; } else if (n <= 8600000) { ans += 600036645526326; m = 8500001; } else if (n <= 8700000) { ans += 614670553358276; m = 8600001; } else if (n <= 8800000) { ans += 629486032479553; m = 8700001; } else if (n <= 8900000) { ans += 644482906053419; m = 8800001; } else if (n <= 9000000) { ans += 659661281999214; m = 8900001; } else if (n <= 9100000) { ans += 675021515919670; m = 9000001; } else if (n <= 9200000) { ans += 690561394962114; m = 9100001; } else if (n <= 9300000) { ans += 706285619557381; m = 9200001; } else if (n <= 9400000) { ans += 722190402701363; m = 9300001; } else if (n <= 9500000) { ans += 738276491989247; m = 9400001; } else if (n <= 9600000) { ans += 754546104527913; m = 9500001; } else if (n <= 9700000) { ans += 770997444637057; m = 9600001; } else if (n <= 9800000) { ans += 787630213195247; m = 9700001; } else if (n <= 9900000) { ans += 804447590347769; m = 9800001; } else { ans += 821446543739323; m = 9900001; } for (int i = m; i <= n; i++) { const auto &pf = prime_factorize(i); long long res = 1; for (auto p : pf) res *= p.second + 1; ans += i * res; } cout << ans; return 0; }
replace
28
30
28
329
TLE
p02624
C++
Runtime Error
/* @uthor: Amit Kumar user -->GitHub: drviruses ; CodeChef: dr_virus_ ; Codeforces,AtCoder,Hackerearth,Hakerrank: dr_virus; */ #include <bits/stdc++.h> #include <chrono> using namespace std; using namespace std::chrono; // #include <boost/multiprecision/cpp_int.hpp> // namespace mp = boost::multiprecision; // #define ln mp::cpp_int; #define int long long #define ll long long #define ld long double #define ull unsigned long long #define endl "\n" ll google_itr = 1; #define google(x) cout << "Case #" << x << ":" #define pi 3.14159265358979323846264338327950L const ll mod = 1e9 + 7; const ll inf = 1e18; const ll mx = 1e7 + 2; ll dp[mx]; ll popcount(ll num) { num = num - ((num >> 1) & 0x55555555); num = (num & 0x33333333) + ((num >> 2) & 0x33333333); return ((num + (num >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; } void SieveOfEratosthenes(int n, bool prime[], bool primesquare[], int a[]) { // Create a boolean array "prime[0..n]" and // initialize all entries it as true. A value // in prime[i] will finally be false if i is // Not a prime, else true. for (int i = 2; i <= n; i++) prime[i] = true; // Create a boolean array "primesquare[0..n*n+1]" // and initialize all entries it as false. A value // in squareprime[i] will finally be true if i is // square of prime, else false. for (int i = 0; i <= (n * n + 1); i++) primesquare[i] = false; // 1 is not a prime number prime[1] = false; for (int p = 2; p * p <= n; p++) { // If prime[p] is not changed, then // it is a prime if (prime[p] == true) { // Update all multiples of p for (int i = p * 2; i <= n; i += p) prime[i] = false; } } int j = 0; for (int p = 2; p <= n; p++) { if (prime[p]) { // Storing primes in an array a[j] = p; // Update value in primesquare[p*p], // if p is prime. primesquare[p * p] = true; j++; } } } // Function to count divisors int fac(int n) { // If number is 1, then it will have only 1 // as a factor. So, total factors will be 1. if (n == 1) return 1; bool prime[n + 1], primesquare[n * n + 1]; int a[n]; // for storing primes upto n // Calling SieveOfEratosthenes to store prime // factors of n and to store square of prime // factors of n SieveOfEratosthenes(n, prime, primesquare, a); // ans will contain total number of distinct // divisors int ans = 1; // Loop for counting factors of n for (int i = 0;; i++) { // a[i] is not less than cube root n if (a[i] * a[i] * a[i] > n) break; // Calculating power of a[i] in n. int cnt = 1; // cnt is power of prime a[i] in n. while (n % a[i] == 0) // if a[i] is a factor of n { n = n / a[i]; cnt = cnt + 1; // incrementing power } // Calculating number of divisors // If n = a^p * b^q then total divisors of n // are (p+1)*(q+1) ans = ans * cnt; } // if a[i] is greater than cube root of n // First case if (prime[n]) ans = ans * 2; // Second case else if (primesquare[n]) ans = ans * 3; // Third casse else if (n != 1) ans = ans * 4; return ans; // Total divisors } void pre() { for (auto i = 0; i < mx + 1; i++) { dp[i] = 1; } for (auto i = 2; i <= mx; i++) { for (auto j = i; j <= mx; j++) { dp[j]++; } } } void virus() { pre(); ll num; cin >> num; ll sum = 0; for (auto i = 1; i <= num; i++) { sum += (i * dp[i]); } cout << sum; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); /*#ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif*/ ll t = 1; // cin>>t; while (t--) { auto start = high_resolution_clock::now(); virus(); auto stop = high_resolution_clock::now(); auto duration = duration_cast<seconds>(stop - start); // cout << "Time: "<<duration.count()<<endl; // your code goes here } return 0; }
/* @uthor: Amit Kumar user -->GitHub: drviruses ; CodeChef: dr_virus_ ; Codeforces,AtCoder,Hackerearth,Hakerrank: dr_virus; */ #include <bits/stdc++.h> #include <chrono> using namespace std; using namespace std::chrono; // #include <boost/multiprecision/cpp_int.hpp> // namespace mp = boost::multiprecision; // #define ln mp::cpp_int; #define int long long #define ll long long #define ld long double #define ull unsigned long long #define endl "\n" ll google_itr = 1; #define google(x) cout << "Case #" << x << ":" #define pi 3.14159265358979323846264338327950L const ll mod = 1e9 + 7; const ll inf = 1e18; const ll mx = 1e7 + 2; ll dp[mx]; ll popcount(ll num) { num = num - ((num >> 1) & 0x55555555); num = (num & 0x33333333) + ((num >> 2) & 0x33333333); return ((num + (num >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; } void SieveOfEratosthenes(int n, bool prime[], bool primesquare[], int a[]) { // Create a boolean array "prime[0..n]" and // initialize all entries it as true. A value // in prime[i] will finally be false if i is // Not a prime, else true. for (int i = 2; i <= n; i++) prime[i] = true; // Create a boolean array "primesquare[0..n*n+1]" // and initialize all entries it as false. A value // in squareprime[i] will finally be true if i is // square of prime, else false. for (int i = 0; i <= (n * n + 1); i++) primesquare[i] = false; // 1 is not a prime number prime[1] = false; for (int p = 2; p * p <= n; p++) { // If prime[p] is not changed, then // it is a prime if (prime[p] == true) { // Update all multiples of p for (int i = p * 2; i <= n; i += p) prime[i] = false; } } int j = 0; for (int p = 2; p <= n; p++) { if (prime[p]) { // Storing primes in an array a[j] = p; // Update value in primesquare[p*p], // if p is prime. primesquare[p * p] = true; j++; } } } // Function to count divisors int fac(int n) { // If number is 1, then it will have only 1 // as a factor. So, total factors will be 1. if (n == 1) return 1; bool prime[n + 1], primesquare[n * n + 1]; int a[n]; // for storing primes upto n // Calling SieveOfEratosthenes to store prime // factors of n and to store square of prime // factors of n SieveOfEratosthenes(n, prime, primesquare, a); // ans will contain total number of distinct // divisors int ans = 1; // Loop for counting factors of n for (int i = 0;; i++) { // a[i] is not less than cube root n if (a[i] * a[i] * a[i] > n) break; // Calculating power of a[i] in n. int cnt = 1; // cnt is power of prime a[i] in n. while (n % a[i] == 0) // if a[i] is a factor of n { n = n / a[i]; cnt = cnt + 1; // incrementing power } // Calculating number of divisors // If n = a^p * b^q then total divisors of n // are (p+1)*(q+1) ans = ans * cnt; } // if a[i] is greater than cube root of n // First case if (prime[n]) ans = ans * 2; // Second case else if (primesquare[n]) ans = ans * 3; // Third casse else if (n != 1) ans = ans * 4; return ans; // Total divisors } void pre() { for (auto i = 0; i < mx + 1; i++) { dp[i] = 1; } for (auto i = 2; i <= mx; i++) { for (auto j = i; j <= mx; j += i) { dp[j]++; } } } void virus() { pre(); ll num; cin >> num; ll sum = 0; for (auto i = 1; i <= num; i++) { sum += (i * dp[i]); } cout << sum; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); /*#ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif*/ ll t = 1; // cin>>t; while (t--) { auto start = high_resolution_clock::now(); virus(); auto stop = high_resolution_clock::now(); auto duration = duration_cast<seconds>(stop - start); // cout << "Time: "<<duration.count()<<endl; // your code goes here } return 0; }
replace
134
135
134
135
TLE
p02624
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; #define pb push_back #define pp pop_back #define f first #define s second #define sz(a) (int)((a).size()) #define NoType ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL) #define mp make_pair typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; // find_by_order(x) -> returns an iterator to the element at a given position // order_of_key(x) -> returns the position of a given element typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pi; const int mod = (int)1e9 + 7; const int MAXN = 2e5 + 12; // indexed_set s; int n; int main() { NoType; cin >> n; int m[n + 1]; for (int i = 1; i <= 10000000; i++) m[i] = 0; for (int i = 1; i <= n; i++) { for (int j = i; j <= n; j += i) { m[j]++; } } ll ans = 0; for (int i = 1; i <= n; i++) { ans += (i * m[i]); } cout << ans; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; #define pb push_back #define pp pop_back #define f first #define s second #define sz(a) (int)((a).size()) #define NoType ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL) #define mp make_pair typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; // find_by_order(x) -> returns an iterator to the element at a given position // order_of_key(x) -> returns the position of a given element typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pi; const int mod = (int)1e9 + 7; const int MAXN = 2e5 + 12; // indexed_set s; int n; int main() { NoType; cin >> n; ll m[n + 1] = {0}; for (int i = 1; i <= n; i++) { for (int j = i; j <= n; j += i) { m[j]++; } } ll ans = 0; for (int i = 1; i <= n; i++) { ans += (i * m[i]); } cout << ans; return 0; }
replace
36
39
36
37
TLE
p02624
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> VI; ll mm = 1000000000; ll MM = mm + 7; #define rep(i, n) for (int i = 0; i < n; i++) #define PI 3.141592653589793 int main() { ll n; cin >> n; ll sum = 0; for (ll i = 1; i <= n; i++) { ll cnt = 0; for (ll j = 1; j <= sqrt(i); j++) { if (i % j == 0) { if (j == sqrt(i)) { cnt++; } else { cnt += 2; } } } sum += i * cnt; } cout << sum << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> VI; ll mm = 1000000000; ll MM = mm + 7; #define rep(i, n) for (int i = 0; i < n; i++) #define PI 3.141592653589793 int main() { ll n; cin >> n; ll sum = 0; for (ll i = 1; i <= n; i++) { ll m = n / i; sum += i * (1 + m) * m / 2; } cout << sum << endl; }
replace
15
26
15
17
TLE
p02624
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int _max = 1e7 + 10; const int mod = 1e9 + 7; typedef long long ll; ll a[_max]; int init() { for (int i = 1; i <= _max; i++) { int begin = i; while (1) { if (begin > _max) { break; } a[begin]++; begin = begin + i; } } } int main() { init(); int n; cin >> n; ll he = 0; for (int i = 1; i <= n; i++) { he = he + a[i] * i; } cout << he << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int _max = 1e7 + 10; const int mod = 1e9 + 7; typedef long long ll; ll a[_max]; void init() { for (int i = 1; i <= _max; i++) { int begin = i; while (1) { if (begin > _max) { break; } a[begin]++; begin = begin + i; } } } int main() { init(); int n; cin >> n; ll he = 0; for (int i = 1; i <= n; i++) { he = he + a[i] * i; } cout << he << endl; return 0; }
replace
8
9
8
9
TLE
p02624
C++
Time Limit Exceeded
// K-OS WITH THE OCDE #include <bits/stdc++.h> using namespace std; #define ll long long int #define ff first #define ss second #define ar array #define mod 1000000007 #define pb push_back #define mpa make_pair #define TEST \ ll t; \ cin >> t; \ while (t--) #define vell vector<ll> #define vel2 vector<vector<ll>> #define all(v) v.begin(), v.end() #define for0(i, n) for (ll i = 0; i < (ll)n; i++) #define for1(i, n) for (ll i = 1; i <= (ll)n; i++) #define forr(i, n) for (ll i = (ll)n - 1; i >= 0; i--) #define fall(i, a, b, c) for (ll i = a; i <= (ll)b; i += (ll)c) #define db long double #define endl "\n" #define MAX INT_MAX #define MIN INT_MIN //////////////////////////////////////////////////////////////////////// /*Parity and inversion - ( (grid width odd) && (#inversions even) ) || ( (grid width even) && ((blank on odd row from bottom) == (#inversions even)) )*/ //////////////////////////////////////////////////////////////////////// ll add(ll a, ll b) { return ((a % mod + b % mod) % mod); } ll mult(ll a, ll b) { return (((a % mod) * (b % mod)) % mod); } ll gcdExtended(ll a, ll b, ll *x, ll *y) { if (a == 0) { *x = 0, *y = 1; return b; } ll x1, y1; ll gcd = gcdExtended(b % a, a, &x1, &y1); *x = y1 - (b / a) * x1; *y = x1; return gcd; } ll modInverse(ll b, ll m) { ll x, y; ll g = gcdExtended(b, m, &x, &y); if (g != 1) return -1; return (x % m + m) % m; } ll modDivide(ll a, ll b, ll m) { a = a % m; int inv = modInverse(b, m); return (inv * a) % m; } ll power(ll a, ll n) { ll ans = 1; while (n > 0) { ll lastbit = (n & 1); if (lastbit) ans *= a; a *= a; n >>= 1; } return ans; } ///////////////////////////////////////////////// int sieveo(ll n) { bool prime[n + 1]; memset(prime, true, sizeof(prime)); ll ans = 0; for (ll p = 2; p * p <= n; p++) { if (prime[p] == true) { for (ll i = p * p; i <= n; i += p) prime[i] = false; } } for (ll p = 2; p <= n; p++) if (prime[p]) ans++; return ans; } /////////////////////////////// void primesieve(ll N, ll s[]) { vector<bool> prime(N + 1, false); for (ll i = 2; i <= N; i += 2) s[i] = 2; for (ll i = 3; i <= N; i += 2) { if (prime[i] == false) { s[i] = i; for (ll j = i; j * i <= N; j += 2) { if (prime[i * j] == false) { prime[i * j] = true; s[i * j] = i; } } } } } void primefactor(ll N) { ll s[N + 1]; primesieve(N, s); ll curr = s[N]; ll cnt = 1; while (N > 1) { N /= s[N]; if (curr == s[N]) { cnt++; continue; } // curr==prime n. // cnt=power curr = s[N]; cnt = 1; } } ///////////////////////////////////////////////////////// void solve() { ll n; cin >> n; ll sum = 0; for (ll i = 1; i <= n; ++i) { ll c = 0; for (ll j = 1; j * j <= i; ++j) { if (i % j == 0) c += (i / j == j ? 1 : 2); } sum += i * c; } cout << sum; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(0); cin.tie(0); // TEST solve(); }
// K-OS WITH THE OCDE #include <bits/stdc++.h> using namespace std; #define ll long long int #define ff first #define ss second #define ar array #define mod 1000000007 #define pb push_back #define mpa make_pair #define TEST \ ll t; \ cin >> t; \ while (t--) #define vell vector<ll> #define vel2 vector<vector<ll>> #define all(v) v.begin(), v.end() #define for0(i, n) for (ll i = 0; i < (ll)n; i++) #define for1(i, n) for (ll i = 1; i <= (ll)n; i++) #define forr(i, n) for (ll i = (ll)n - 1; i >= 0; i--) #define fall(i, a, b, c) for (ll i = a; i <= (ll)b; i += (ll)c) #define db long double #define endl "\n" #define MAX INT_MAX #define MIN INT_MIN //////////////////////////////////////////////////////////////////////// /*Parity and inversion - ( (grid width odd) && (#inversions even) ) || ( (grid width even) && ((blank on odd row from bottom) == (#inversions even)) )*/ //////////////////////////////////////////////////////////////////////// ll add(ll a, ll b) { return ((a % mod + b % mod) % mod); } ll mult(ll a, ll b) { return (((a % mod) * (b % mod)) % mod); } ll gcdExtended(ll a, ll b, ll *x, ll *y) { if (a == 0) { *x = 0, *y = 1; return b; } ll x1, y1; ll gcd = gcdExtended(b % a, a, &x1, &y1); *x = y1 - (b / a) * x1; *y = x1; return gcd; } ll modInverse(ll b, ll m) { ll x, y; ll g = gcdExtended(b, m, &x, &y); if (g != 1) return -1; return (x % m + m) % m; } ll modDivide(ll a, ll b, ll m) { a = a % m; int inv = modInverse(b, m); return (inv * a) % m; } ll power(ll a, ll n) { ll ans = 1; while (n > 0) { ll lastbit = (n & 1); if (lastbit) ans *= a; a *= a; n >>= 1; } return ans; } ///////////////////////////////////////////////// int sieveo(ll n) { bool prime[n + 1]; memset(prime, true, sizeof(prime)); ll ans = 0; for (ll p = 2; p * p <= n; p++) { if (prime[p] == true) { for (ll i = p * p; i <= n; i += p) prime[i] = false; } } for (ll p = 2; p <= n; p++) if (prime[p]) ans++; return ans; } /////////////////////////////// void primesieve(ll N, ll s[]) { vector<bool> prime(N + 1, false); for (ll i = 2; i <= N; i += 2) s[i] = 2; for (ll i = 3; i <= N; i += 2) { if (prime[i] == false) { s[i] = i; for (ll j = i; j * i <= N; j += 2) { if (prime[i * j] == false) { prime[i * j] = true; s[i * j] = i; } } } } } void primefactor(ll N) { ll s[N + 1]; primesieve(N, s); ll curr = s[N]; ll cnt = 1; while (N > 1) { N /= s[N]; if (curr == s[N]) { cnt++; continue; } // curr==prime n. // cnt=power curr = s[N]; cnt = 1; } } ///////////////////////////////////////////////////////// void solve() { ll n; cin >> n; ll sum = 0; for (ll i = 1; i <= n; ++i) { ll x = n / i; sum += (i * (x * (x + 1)) / 2); } cout << sum; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(0); cin.tie(0); // TEST solve(); }
replace
153
159
153
156
TLE
p02624
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define SPEED \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) #define int long long #define ld long double #define fi first #define se second #define mp make_pair #define pb push_back #define eb emplace_back #define pll pair<int, int> #define ppll pair<pll, pll> #define mod 1000000007 unsigned int bp(int n) // built_in_pop_count // { unsigned int count = 0; while (n) { n &= (n - 1); count++; } return count; } int countDivisors(int n) { int cnt = 0; for (int i = 1; i <= sqrt(n); i++) { if (n % i == 0) { if (n / i == i) cnt++; else cnt = cnt + 2; } } return cnt; } int32_t main() { SPEED; int n; cin >> n; int ans = 0; for (int i = 1; i <= n; ++i) { ans += i * countDivisors(i); } cout << ans; }
#include <bits/stdc++.h> using namespace std; #define SPEED \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) #define int long long #define ld long double #define fi first #define se second #define mp make_pair #define pb push_back #define eb emplace_back #define pll pair<int, int> #define ppll pair<pll, pll> #define mod 1000000007 unsigned int bp(int n) // built_in_pop_count // { unsigned int count = 0; while (n) { n &= (n - 1); count++; } return count; } int countDivisors(int n) { int cnt = 0; for (int i = 1; i <= sqrt(n); i++) { if (n % i == 0) { if (n / i == i) cnt++; else cnt = cnt + 2; } } return cnt; } int32_t main() { SPEED; int n; cin >> n; int ans = 0; for (int i = 1; i <= n; ++i) { ans += (i * (n / i) * (1 + n / i)) / 2; } cout << ans; }
replace
44
45
44
45
TLE
p02624
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; class Osa_k { private: int n; vector<int> factor; public: // O(NloglogN) Osa_k(int _n) : n(_n) { factor.assign(n, 0); iota(factor.begin(), factor.end(), 0); for (int i = 2; i * i < n; i++) { if (factor[i] < i) continue; for (int j = i * i; j < n; j += i) { if (factor[j] == j) factor[j] = i; } } } // O(logV) map<int, int> sieve(int v) { map<int, int> ret; while (v != factor[v]) { ret[factor[v]]++; v /= factor[v]; } if (v != 1) ret[v]++; return ret; } vector<int> divisor(int v) {} // O(N) vector<int> get_list() { vector<int> prime; for (int i = 2; i < n; i++) if (factor[i] == i) prime.emplace_back(i); return prime; } // O(1) bool is_prime(int v) { if (v <= 1) return false; return (factor[v] == v); } } fact(1000001); int main() { int n; cin >> n; ll sum = 0; for (int i = 1; i <= n; i++) { auto v = fact.sieve(i); ll ans = 1; for (auto j : v) ans *= j.second + 1; sum += ans * i; } cout << sum << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; class Osa_k { private: int n; vector<int> factor; public: // O(NloglogN) Osa_k(int _n) : n(_n) { factor.assign(n, 0); iota(factor.begin(), factor.end(), 0); for (int i = 2; i * i < n; i++) { if (factor[i] < i) continue; for (int j = i * i; j < n; j += i) { if (factor[j] == j) factor[j] = i; } } } // O(logV) map<int, int> sieve(int v) { map<int, int> ret; while (v != factor[v]) { ret[factor[v]]++; v /= factor[v]; } if (v != 1) ret[v]++; return ret; } vector<int> divisor(int v) {} // O(N) vector<int> get_list() { vector<int> prime; for (int i = 2; i < n; i++) if (factor[i] == i) prime.emplace_back(i); return prime; } // O(1) bool is_prime(int v) { if (v <= 1) return false; return (factor[v] == v); } } fact(10000001); int main() { int n; cin >> n; ll sum = 0; for (int i = 1; i <= n; i++) { auto v = fact.sieve(i); ll ans = 1; for (auto j : v) ans *= j.second + 1; sum += ans * i; } cout << sum << endl; }
replace
55
56
55
56
0
p02624
C++
Runtime Error
#include <algorithm> #include <iostream> #include <map> #include <stdio.h> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) #define rep_one(i, n) for (int i = 1; i < n; i++) using namespace std; typedef long long ll; int main() { int n; cin >> n; int prime[n + 1]; rep(i, n + 1) prime[i] = 0; for (int i = 2; i * i < n + 1; i++) { for (int j = i; j < n + 1; j += i) { if (prime[j] == 0) prime[j] = j / i; } } map<int, int> div[n + 1]; for (int i = 2; i < n + 1; i++) { if (prime[i] == 0) div[i][i] = 1; else { int tmp = i / prime[i]; div[i] = div[prime[i]]; div[i][tmp] += 1; } } ll ans = 1; for (int i = 2; i < n + 1; i++) { int div_count = 1; for (auto itr = div[i].begin(); itr != div[i].end(); itr++) { // cout << "key=" << itr->first << " value=" << itr->second << endl; div_count *= itr->second + 1; } ans += i * div_count; // cout << "i=" << i << " div_count="<< div_count << endl << endl; } cout << ans << endl; }
#include <algorithm> #include <iostream> #include <map> #include <stdio.h> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) #define rep_one(i, n) for (int i = 1; i < n; i++) using namespace std; typedef long long ll; int main() { int n; cin >> n; ll ans = 0; rep_one(k, n + 1) { ll tmp = n / k; ans += k * tmp * (1 + tmp) / 2; } cout << ans << endl; }
replace
14
41
14
18
0
p02624
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using P = pair<ll, ll>; using Pld = pair<ld, ld>; using Vec = vector<ll>; using VecP = vector<P>; using VecB = vector<bool>; using VecC = vector<char>; using VecD = vector<ld>; using VecS = vector<string>; using Graph = vector<VecP>; template <typename T> using Vec1 = vector<T>; template <typename T> using Vec2 = vector<Vec1<T>>; #define REP(i, m, n) for (ll i = (m); i < (n); ++i) #define REPN(i, m, n) for (ll i = (m); i <= (n); ++i) #define REPR(i, m, n) for (ll i = (m)-1; i >= (n); --i) #define REPNR(i, m, n) for (ll i = (m); i >= (n); --i) #define rep(i, n) REP(i, 0, n) #define repn(i, n) REPN(i, 1, n) #define repr(i, n) REPR(i, n, 0) #define repnr(i, n) REPNR(i, n, 1) #define all(s) (s).begin(), (s).end() #define pb push_back #define fs first #define sc second template <typename T> bool chmax(T &a, const T b) { if (a < b) { a = b; return true; } return false; } template <typename T> bool chmin(T &a, const T b) { if (a > b) { a = b; return true; } return false; } template <typename T> ll pow2(const T n) { return (1LL << n); } template <typename T> void cosp(const T n) { cout << n << ' '; } void co(void) { cout << '\n'; } template <typename T> void co(const T n) { cout << n << '\n'; } template <typename T1, typename T2> void co(pair<T1, T2> p) { cout << p.fs << ' ' << p.sc << '\n'; } template <typename T> void co(const Vec1<T> &v) { for (T i : v) cosp(i); co(); } template <typename T> void co(initializer_list<T> v) { for (T i : v) cosp(i); co(); } template <typename T> void ce(const T n) { cerr << n << endl; } void sonic() { ios::sync_with_stdio(false); cin.tie(0); } void setp(const ll n) { cout << fixed << setprecision(n); } constexpr int INF = 1e9 + 1; constexpr ll LINF = 1e18 + 1; constexpr ll MOD = 1e9 + 7; // constexpr ll MOD = 998244353; constexpr ld EPS = 1e-11; const ld PI = acos(-1); using VecP = Vec1<P>; Vec pn; bool isPrime(ll n) { if (n == 1) return false; for (ll i : pn) { if (i * i > n) return true; if (n % i == 0) return false; } return true; } void init(ll n = 2e5) { pn.pb(2); REP(num, 3, n) if (isPrime(num)) pn.pb(num); } VecP primeFactorization(ll n) { VecP res; for (ll i : pn) { ll cnt = 0; while (n % i == 0) { n /= i; cnt++; } if (cnt) res.pb({i, cnt}); if (n < i * i) break; } if (n != 1) res.pb({n, 1}); return res; } Vec divisorEnumeration(ll n) { auto v = primeFactorization(n); Vec res, a, b, cp; res.pb(1); for (auto p : v) { cp.resize(res.size()); copy(all(res), cp.begin()); a.resize(res.size()); repn(k, p.sc) { ll t = pow(p.fs, k); rep(i, a.size()) a[i] = cp[i] * t; merge(all(res), all(a), back_inserter(b)); swap(res, b); b.clear(); } } return res; } int main(void) { init(); ll n; cin >> n; Vec f(n + 1, 1); for (ll i = 2; i <= n; ++i) { for (ll j = i; j <= n; ++j) if (j % i == 0) ++f[j]; } ll ans = 0; repn(i, n) ans += i * f[i]; co(ans); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using P = pair<ll, ll>; using Pld = pair<ld, ld>; using Vec = vector<ll>; using VecP = vector<P>; using VecB = vector<bool>; using VecC = vector<char>; using VecD = vector<ld>; using VecS = vector<string>; using Graph = vector<VecP>; template <typename T> using Vec1 = vector<T>; template <typename T> using Vec2 = vector<Vec1<T>>; #define REP(i, m, n) for (ll i = (m); i < (n); ++i) #define REPN(i, m, n) for (ll i = (m); i <= (n); ++i) #define REPR(i, m, n) for (ll i = (m)-1; i >= (n); --i) #define REPNR(i, m, n) for (ll i = (m); i >= (n); --i) #define rep(i, n) REP(i, 0, n) #define repn(i, n) REPN(i, 1, n) #define repr(i, n) REPR(i, n, 0) #define repnr(i, n) REPNR(i, n, 1) #define all(s) (s).begin(), (s).end() #define pb push_back #define fs first #define sc second template <typename T> bool chmax(T &a, const T b) { if (a < b) { a = b; return true; } return false; } template <typename T> bool chmin(T &a, const T b) { if (a > b) { a = b; return true; } return false; } template <typename T> ll pow2(const T n) { return (1LL << n); } template <typename T> void cosp(const T n) { cout << n << ' '; } void co(void) { cout << '\n'; } template <typename T> void co(const T n) { cout << n << '\n'; } template <typename T1, typename T2> void co(pair<T1, T2> p) { cout << p.fs << ' ' << p.sc << '\n'; } template <typename T> void co(const Vec1<T> &v) { for (T i : v) cosp(i); co(); } template <typename T> void co(initializer_list<T> v) { for (T i : v) cosp(i); co(); } template <typename T> void ce(const T n) { cerr << n << endl; } void sonic() { ios::sync_with_stdio(false); cin.tie(0); } void setp(const ll n) { cout << fixed << setprecision(n); } constexpr int INF = 1e9 + 1; constexpr ll LINF = 1e18 + 1; constexpr ll MOD = 1e9 + 7; // constexpr ll MOD = 998244353; constexpr ld EPS = 1e-11; const ld PI = acos(-1); using VecP = Vec1<P>; Vec pn; bool isPrime(ll n) { if (n == 1) return false; for (ll i : pn) { if (i * i > n) return true; if (n % i == 0) return false; } return true; } void init(ll n = 2e5) { pn.pb(2); REP(num, 3, n) if (isPrime(num)) pn.pb(num); } VecP primeFactorization(ll n) { VecP res; for (ll i : pn) { ll cnt = 0; while (n % i == 0) { n /= i; cnt++; } if (cnt) res.pb({i, cnt}); if (n < i * i) break; } if (n != 1) res.pb({n, 1}); return res; } Vec divisorEnumeration(ll n) { auto v = primeFactorization(n); Vec res, a, b, cp; res.pb(1); for (auto p : v) { cp.resize(res.size()); copy(all(res), cp.begin()); a.resize(res.size()); repn(k, p.sc) { ll t = pow(p.fs, k); rep(i, a.size()) a[i] = cp[i] * t; merge(all(res), all(a), back_inserter(b)); swap(res, b); b.clear(); } } return res; } int main(void) { init(); ll n; cin >> n; Vec f(n + 1, 1); for (ll i = 2; i <= n; ++i) { for (ll j = i; j <= n; j += i) ++f[j]; } ll ans = 0; repn(i, n) ans += i * f[i]; co(ans); return 0; }
replace
140
143
140
142
TLE
p02624
Python
Time Limit Exceeded
n = int(input()) ans = 0 for i in range(1, n + 1): for j in range(i, n + 1, i): ans += j print(ans)
n = int(input()) ans = 0 for i in range(1, int(n**0.5) + 1): k = n // i ans += i * k * (k + 1) // 2 if i != k: l = n // (i + 1) ans += i * (i + 1) * (k + l + 1) * (k - l) // 4 print(ans)
replace
2
5
2
8
TLE
p02624
Python
Time Limit Exceeded
def main(): num = int(input()) ans = 0 for div in range(1, num + 1): for i in range(div, num + 1): if i % div == 0: ans += i print(ans) if __name__ == "__main__": main()
def main(): num = int(input()) ans = 0 for divisor in range(1, num + 1): quotient = num // divisor ans += (quotient + 1) * quotient * divisor // 2 print(ans) if __name__ == "__main__": main()
replace
4
8
4
7
TLE
p02624
Python
Time Limit Exceeded
n = int(input()) # 愚直にやると約数の個数テーブルをO(NlogN) print(sum(i * j for i in range(1, n + 1) for j in range(1, n // i + 1)))
n = int(input()) ans = 0 for a in range(1, n + 1): num = n // a ans += num * (num + 1) // 2 * a print(ans)
replace
1
3
1
7
TLE
p02624
Python
Time Limit Exceeded
from numba import njit import numpy as np @njit("i8(i8)") def solve(n): ans = 1 res = np.ones(n + 1, dtype=np.int64) for i in range(2, n + 1): res[i::i] += 1 res[i] *= i ans += res[i] return ans N = int(input()) print(solve(N))
from numba import njit import numpy as np @njit("i8(i8)") def solve(n): ans = 1 res = np.ones(n + 1, dtype=np.int64) for i in range(2, n + 1): for j in range(i, n + 1, i): res[j] += 1 ans += i * res[i] return ans N = int(input()) print(solve(N))
replace
9
12
9
12
TLE
p02624
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define srep(i, s, t) for (int i = s; i < t; ++i) #define drep(i, n) for (int i = (n)-1; i >= 0; --i) using namespace std; typedef long long int ll; typedef pair<int, int> P; #define yn \ { puts("Yes"); } \ else { \ puts("No"); \ } #define MAX_N 10000005 ll f[MAX_N] = {}; int main() { ll n; cin >> n; ll ans = 0; srep(i, 1, n + 1) { int ii = i; while (ii <= n) { ans += ii; // f[ii]++; // ii += i; } } /* srep(i,1,n+1){ ll ii = i; ans += f[i] * ii; } */ cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define srep(i, s, t) for (int i = s; i < t; ++i) #define drep(i, n) for (int i = (n)-1; i >= 0; --i) using namespace std; typedef long long int ll; typedef pair<int, int> P; #define yn \ { puts("Yes"); } \ else { \ puts("No"); \ } #define MAX_N 10000005 ll f[MAX_N] = {}; int main() { ll n; cin >> n; ll ans = 0; srep(i, 1, n + 1) { int ii = i; while (ii <= n) { ans += ii; // f[ii]++; ii += i; } } /* srep(i,1,n+1){ ll ii = i; ans += f[i] * ii; } */ cout << ans << endl; return 0; }
replace
25
26
25
26
TLE
p02624
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int N; cin >> N; vector<ll> v(1e9); for (int i = 1; i <= N; ++i) { for (int j = i; j <= N; j += i) { v[j]++; } } ll ans = 0; for (int i = 1; i <= N; ++i) { ans += i * (v[i]); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int N; cin >> N; vector<ll> v(N + 1); for (int i = 1; i <= N; ++i) { for (int j = i; j <= N; j += i) { v[j]++; } } ll ans = 0; for (int i = 1; i <= N; ++i) { ans += i * (v[i]); } cout << ans << endl; }
replace
7
8
7
8
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p02624
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define d(x) cerr << #x ":" << x << endl; #define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl #define rep(i, n) for (int i = (int)(0); i < (int)(n); i++) #define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define all(v) v.begin(), v.end() #define dump(v) \ cerr << #v ":[ "; \ for (auto macro_vi : v) { \ cerr << macro_vi << " "; \ } \ cerr << "]" << endl; #define ddump(v) \ cerr << #v ":" << endl; \ for (auto macro_row : v) { \ cerr << "["; \ for (auto macro__vi : macro_row) { \ cerr << macro__vi << " "; \ } \ cerr << "]" << endl; \ } using lint = long long; const int INF = 1e9; const lint LINF = 1e18; const lint MOD = 1e9 + 7; const double EPS = 1e-10; // 約数列挙 template <class T> vector<T> dividers(T n) { vector<T> ret; for (T x = 1; x * x <= n; x++) { if (n % x == 0) { ret.push_back(x); if (x * x != n) ret.push_back(n / x); } } sort(ret.begin(), ret.end()); return ret; } int main() { lint N; cin >> N; vector<lint> divs(N + 1, 0); for (int x = 1; x <= N; x++) { divs[x] = dividers(x).size(); } lint ans = 0; for (int i = 1; i <= N; i++) { ans += divs[i] * i; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define d(x) cerr << #x ":" << x << endl; #define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl #define rep(i, n) for (int i = (int)(0); i < (int)(n); i++) #define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define all(v) v.begin(), v.end() #define dump(v) \ cerr << #v ":[ "; \ for (auto macro_vi : v) { \ cerr << macro_vi << " "; \ } \ cerr << "]" << endl; #define ddump(v) \ cerr << #v ":" << endl; \ for (auto macro_row : v) { \ cerr << "["; \ for (auto macro__vi : macro_row) { \ cerr << macro__vi << " "; \ } \ cerr << "]" << endl; \ } using lint = long long; const int INF = 1e9; const lint LINF = 1e18; const lint MOD = 1e9 + 7; const double EPS = 1e-10; // 約数列挙 template <class T> vector<T> dividers(T n) { vector<T> ret; for (T x = 1; x * x <= n; x++) { if (n % x == 0) { ret.push_back(x); if (x * x != n) ret.push_back(n / x); } } sort(ret.begin(), ret.end()); return ret; } int main() { lint N; cin >> N; vector<lint> divs(N + 1, 0); for (int x = 1; x <= N; x++) { for (int y = 1; y <= (int)N / x; y++) { divs[x * y]++; } } lint ans = 0; for (int i = 1; i <= N; i++) { ans += divs[i] * i; } cout << ans << endl; return 0; }
replace
49
50
49
52
TLE
p02624
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <math.h> #include <queue> #include <stdio.h> #include <string> #include <unordered_map> #include <vector> #define rep(i, n) for (int i = 0; i < (n); i++) #define rep2(i, n) for (int i = -1; i < (n); i++) #define PI 3.141592653589793 using namespace std; using ll = unsigned long long; const ll MA = 10000000; ll to[MA]; int main() { ll n; cin >> n; ll ans = 1; for (ll i = 2; i <= n; i++) { ll j = i; while (j + i <= n * 2) { to[j] += 1; j += i; } ans += i * (to[i] + 1); } cout << ans << endl; return 0; }
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <math.h> #include <queue> #include <stdio.h> #include <string> #include <unordered_map> #include <vector> #define rep(i, n) for (int i = 0; i < (n); i++) #define rep2(i, n) for (int i = -1; i < (n); i++) #define PI 3.141592653589793 using namespace std; using ll = unsigned long long; const ll MA = 10000000; ll to[MA]; int main() { ll n; cin >> n; ll ans = 1; for (ll i = 2; i <= n; i++) { ll j = i; while (j <= n) { to[j] += 1; j += i; } ans += i * (to[i] + 1); } cout << ans << endl; return 0; }
replace
29
30
29
30
0
p02624
C++
Runtime Error
#include <stdio.h> using namespace std; typedef long long llong; #define MAX int main() { int N; llong ans = 0; scanf("%lld", &N); for (llong x = 1; x <= N; x++) { llong n = N / x; ans += n * (2 * x + (n - 1) * x) / 2; } printf("%lld\n", ans); return 0; }
#include <stdio.h> using namespace std; typedef long long llong; #define MAX int main() { llong N; llong ans = 0; scanf("%lld", &N); for (llong x = 1; x <= N; x++) { llong n = N / x; ans += n * (2 * x + (n - 1) * x) / 2; } printf("%lld\n", ans); return 0; }
replace
8
9
8
9
0
p02624
C++
Time Limit Exceeded
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <cstdio> #include <ctime> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define en '\n' #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) int((x).size()) typedef unsigned int uint; typedef long long ll; typedef unsigned long long ull; typedef double db; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int INF = 1e9 + 7; const ll INFLL = 1e18; const double EPS = 1e-9; const double PI = 3.1415926535897932384626433832795; const int MAX_SIZE = 5e5; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); bool IS_ONE_TEST = 1; ld START_TIME, TIME; void fast_in_out() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } ll get(ll n) { ll res = 0; for (ll i = 1; i * i <= n; ++i) { if (n % i == 0) { ++res; if (n / i != i) { ++res; } } } return res; } void solve() { int n; cin >> n; ll ans = 0; for (int i = 1; i <= n; ++i) { ll x = get(i); ans += i * x; } cout << ans << en; } int main() { START_TIME = clock(); fast_in_out(); int TESTS = 1; if (!IS_ONE_TEST) cin >> TESTS; while (TESTS--) { solve(); } #ifdef __APPLE__ TIME = (clock() - START_TIME) / CLOCKS_PER_SEC; cerr << en << TIME * 1000 << " ms." << en; #endif return 0; } /* ▄▀▀▀▄ ▄███▀░◐░░░▌ ▌░░░░░▐ ▐░░░░░▐ ▌░░░░░▐▄▄ ▌░░░░▄▀▒▒▀▀▀▀▄ ▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄ ▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄ ▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄ ▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄ ▌▌░▌▌ ▌▌░▌▌ ▄▄▌▌▄▌▌ */
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <cstdio> #include <ctime> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define en '\n' #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) int((x).size()) typedef unsigned int uint; typedef long long ll; typedef unsigned long long ull; typedef double db; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int INF = 1e9 + 7; const ll INFLL = 1e18; const double EPS = 1e-9; const double PI = 3.1415926535897932384626433832795; const int MAX_SIZE = 5e5; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); bool IS_ONE_TEST = 1; ld START_TIME, TIME; void fast_in_out() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } ll get(ll n) { ll res = 0; for (ll i = 1; i * i <= n; ++i) { if (n % i == 0) { ++res; if (n / i != i) { ++res; } } } return res; } void solve() { int n; cin >> n; vector<ll> kek(n + 1, 1); ll ans = 1; for (ll i = 2; i <= n; ++i) { for (ll j = i; j <= n; j += i) { ++kek[j]; } ans += i * kek[i]; } cout << ans << en; } int main() { START_TIME = clock(); fast_in_out(); int TESTS = 1; if (!IS_ONE_TEST) cin >> TESTS; while (TESTS--) { solve(); } #ifdef __APPLE__ TIME = (clock() - START_TIME) / CLOCKS_PER_SEC; cerr << en << TIME * 1000 << " ms." << en; #endif return 0; } /* ▄▀▀▀▄ ▄███▀░◐░░░▌ ▌░░░░░▐ ▐░░░░░▐ ▌░░░░░▐▄▄ ▌░░░░▄▀▒▒▀▀▀▀▄ ▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄ ▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄ ▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄ ▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄ ▌▌░▌▌ ▌▌░▌▌ ▄▄▌▌▄▌▌ */
replace
69
73
69
76
TLE