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++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
// input
int64_t N, M, K;
cin >> N >> M >> K;
vector<int64_t> A(N), B(M);
for (int64_t i = 0; i < N; i++) {
cin >> A[i];
}
for (int64_t i = 0; i < M; i++) {
cin >> B[i];
}
// calculation
vector<int64_t> sum_A(N + 1), sum_B(M + 1);
int64_t temp_sum = 0;
sum_A[0] = 0;
for (int64_t i = 0; i < N; i++) {
temp_sum += A[i];
sum_A[i + 1] = temp_sum;
}
temp_sum = 0;
sum_B[0] = 0;
for (int64_t i = 0; i < M; i++) {
temp_sum += B[i];
sum_B[i + 1] = temp_sum;
}
int64_t output = 0;
for (int64_t i = 0; i <= N; i++) {
for (int64_t j = 0; j <= M; j++) {
if (sum_A[i] + sum_B[j] > K) {
break;
}
if (output < i + j) {
output = i + j;
}
}
}
// output
cout << output << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
// input
int64_t N, M, K;
cin >> N >> M >> K;
vector<int64_t> A(N), B(M);
for (int64_t i = 0; i < N; i++) {
cin >> A[i];
}
for (int64_t i = 0; i < M; i++) {
cin >> B[i];
}
// calculation
vector<int64_t> sum_A(N + 1), sum_B(M + 1);
int64_t temp_sum = 0;
sum_A[0] = 0;
for (int64_t i = 0; i < N; i++) {
temp_sum += A[i];
sum_A[i + 1] = temp_sum;
}
temp_sum = 0;
sum_B[0] = 0;
for (int64_t i = 0; i < M; i++) {
temp_sum += B[i];
sum_B[i + 1] = temp_sum;
}
int64_t output = 0;
for (int64_t i = 0; i <= N; i++) {
int64_t start_j = output - i;
if (start_j < 0) {
start_j = 0;
}
for (int64_t j = start_j; j <= M; j++) {
if (sum_A[i] + sum_B[j] > K) {
break;
}
if (output < i + j) {
output = i + j;
}
}
}
// output
cout << output << endl;
return 0;
}
| replace | 33 | 34 | 33 | 38 | TLE | |
p02623 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1000000007;
int main() {
ll n, m, k;
cin >> n >> m >> k;
VL a(n), b(m);
VL sa(n + 1, 0), sb(m + 1, 0);
rep(i, n) {
cin >> a[i];
sa[i + 1] = sa[i] + a[i];
}
rep(i, m) {
cin >> b[i];
sb[i + 1] = sb[i] + b[i];
}
ll ans = 0;
rep(i, k + 1) {
ll cur = upper_bound(ALL(sa), i) - sa.begin() - 1;
cur += upper_bound(ALL(sb), k - i) - sb.begin() - 1;
// cerr << i << " " << cur << endl;
chmax(ans, cur);
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1000000007;
int main() {
ll n, m, k;
cin >> n >> m >> k;
VL a(n), b(m);
VL sa(n + 1, 0), sb(m + 1, 0);
rep(i, n) {
cin >> a[i];
sa[i + 1] = sa[i] + a[i];
}
rep(i, m) {
cin >> b[i];
sb[i + 1] = sb[i] + b[i];
}
ll ans = 0;
rep(i, n + 1) {
if (sa[i] > k) {
continue;
}
ll cur = i;
cur += upper_bound(ALL(sb), k - sa[i]) - sb.begin() - 1;
// cerr << i << " " << cur << endl;
chmax(ans, cur);
}
cout << ans << endl;
return 0;
} | replace | 36 | 39 | 36 | 42 | TLE | |
p02623 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using V = vector<int>;
int main(int argc, char const *argv[]) {
int n, m, k;
cin >> n >> m >> k;
long long int a, b, c[20010], d[20010];
c[0] = 0;
rep(i, n) {
cin >> a;
c[i + 1] = c[i] + a;
}
d[0] = 0;
rep(i, m) {
cin >> b;
d[i + 1] = d[i] + b;
}
int ans = 0;
int j = m;
rep(i, n + 1) {
if (k < c[i])
break;
while (k < c[i] + d[j]) {
j--;
}
ans = max(ans, i + j);
// cout << ans << " " << i << " " << j << endl;
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using V = vector<int>;
int main(int argc, char const *argv[]) {
int n, m, k;
cin >> n >> m >> k;
long long int a, b, c[200010], d[200010];
c[0] = 0;
rep(i, n) {
cin >> a;
c[i + 1] = c[i] + a;
}
d[0] = 0;
rep(i, m) {
cin >> b;
d[i + 1] = d[i] + b;
}
int ans = 0;
int j = m;
rep(i, n + 1) {
if (k < c[i])
break;
while (k < c[i] + d[j]) {
j--;
}
ans = max(ans, i + j);
// cout << ans << " " << i << " " << j << endl;
}
cout << ans << endl;
return 0;
}
| replace | 10 | 11 | 10 | 11 | 0 | |
p02623 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef pair<int, int> pii;
typedef pair<long long, int> pli;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
ll mod = 1000000007;
ll gcd(ll a, ll b) {
if (a % b == 0)
return (b);
else
return (gcd(b, a % b));
}
ll inv(ll x) {
ll res = 1;
ll k = mod - 2;
ll y = x;
while (k) {
if (k & 1)
res = (res * y) % mod;
y = (y * y) % mod;
k /= 2;
}
return res;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, m, k;
cin >> n >> m >> k;
vi a(n), b(n);
rep(i, n) cin >> a[i];
rep(i, m) cin >> b[i];
int ac = 0, bc = 0;
while (ac < n) {
if (a[ac] > k)
break;
k -= a[ac];
ac++;
}
while (bc < m) {
if (b[bc] > k)
break;
k -= b[bc];
bc++;
}
int ret = ac + bc;
while (ac > 0 && bc < m - 1) {
k += a[ac - 1];
ac--;
while (bc < m) {
if (b[bc] > k)
break;
k -= b[bc];
bc++;
}
ret = max(ret, ac + bc);
}
cout << ret << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef pair<int, int> pii;
typedef pair<long long, int> pli;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
ll mod = 1000000007;
ll gcd(ll a, ll b) {
if (a % b == 0)
return (b);
else
return (gcd(b, a % b));
}
ll inv(ll x) {
ll res = 1;
ll k = mod - 2;
ll y = x;
while (k) {
if (k & 1)
res = (res * y) % mod;
y = (y * y) % mod;
k /= 2;
}
return res;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, m, k;
cin >> n >> m >> k;
vi a(n), b(m);
rep(i, n) cin >> a[i];
rep(i, m) cin >> b[i];
int ac = 0, bc = 0;
while (ac < n) {
if (a[ac] > k)
break;
k -= a[ac];
ac++;
}
while (bc < m) {
if (b[bc] > k)
break;
k -= b[bc];
bc++;
}
int ret = ac + bc;
while (ac > 0 && bc < m - 1) {
k += a[ac - 1];
ac--;
while (bc < m) {
if (b[bc] > k)
break;
k -= b[bc];
bc++;
}
ret = max(ret, ac + bc);
}
cout << ret << endl;
} | replace | 42 | 43 | 42 | 43 | 0 | |
p02623 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
using ull = unsigned long long;
#define Rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define For(i, s, n) for (int i = s; i < (int)(n); ++i)
int main() {
ull N, M, K;
cin >> N >> M >> K;
vector<ull> As(N + 1);
vector<ull> Bs(M + 1);
{
ull sum = 0;
Rep(i, N) {
ull j;
cin >> j;
sum += j;
As[i + 1] = sum;
}
}
{
ull sum = 0;
Rep(i, M) {
ull j;
cin >> j;
sum += j;
Bs[i + 1] = sum;
}
}
int answer = 0;
Rep(n, N + 1) {
Rep(m, M + 1) {
if (As[n] + Bs[m] <= K) {
answer = max(answer, n + m);
}
}
}
cout << answer << endl;
return 0;
}
| #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
using ull = unsigned long long;
#define Rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define For(i, s, n) for (int i = s; i < (int)(n); ++i)
int main() {
ull N, M, K;
cin >> N >> M >> K;
vector<ull> As(N + 1);
vector<ull> Bs(M + 1);
{
ull sum = 0;
Rep(i, N) {
ull j;
cin >> j;
sum += j;
As[i + 1] = sum;
}
}
{
ull sum = 0;
Rep(i, M) {
ull j;
cin >> j;
sum += j;
Bs[i + 1] = sum;
}
}
int answer = 0;
Rep(n, N + 1) {
ull remain = K - As[n];
auto bound = lower_bound(Bs.begin(), Bs.end(), remain);
if (*bound > remain)
bound--;
if (bound != Bs.end()) {
int pos = (int)(bound - Bs.begin());
answer = max(answer, n + pos);
}
}
cout << answer << endl;
return 0;
}
| replace | 38 | 42 | 38 | 45 | TLE | |
p02623 | C++ | Runtime Error |
// Problem : C - Tsundoku
// Contest : AtCoder - AtCoder Beginner Contest 172
// URL : https://atcoder.jp/contests/abc172/tasks/abc172_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include <bits/stdc++.h>
#define int long long
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define vi vector<int>
#define vstr vector<string>
#define vdb vector<double>
#define vbool vector<bool>
#define vvi vector<vector<int>>
#define mii map<int, int>
#define pb push_back
#define pii pair<int, int>
#define vpair vector<pii>
#define mkp make_pair
#define scan(a, n) \
for (int i = 0; i < n; i++) \
cin >> a[i]
#define print(a, n) \
for (int i = 0; i < n; i++) { \
cout << a[i] << ' '; \
} \
cout << '\n'
#define mem(a, v) memset(a, v, sizeof(a))
#define loop(i, a, b) for (int i = a; i < b; i++)
#define loope(i, a, b) for (int i = a; i <= b; i++)
#define bloop(i, a, b) for (int i = a; i >= b; i--)
#define FastIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
#define PRECISION \
std::cout.unsetf(std::ios::fixed); \
std::cout.precision(9)
#define PI 3.14159265
#define S second
#define F first
#define CHECK cout << "CHEDEDWB" << endl
#define CHECK1(a) cout << a << endl
#define CHECK2(a, b) cout << a << ' ' << b << endl;
#define br '\n'
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
using namespace std;
int mod = 1e9 + 7;
int inf = 1e18;
int m_inf = INT_MIN;
// int extendedgcd(int a,int b,int &x,int &y){
// if(a == 0){
// x = 0; y = 1;
// return b;
// }
// int x1,y1;
// int d = extendedgcd(b%a,a,x1,y1);
// x = y1 - (b/a)*x1;y = x1;
// return d;
// }
// int expmod(int a,int b) {
// if(b == 1) return a;
// if(b == 0) return 1;
// int m1 = expmod(a,b/2)%mod;
// if(b%2) return ((m1*m1)%mod*a%mod)%mod;
// return (m1*m1)%mod;
// }
// int power(int a,int b) {
// if(b == 1) return a;
// if(b == 0) return 1;
// int m1 = power(a,b/2);
// if(b%2) return m1*m1*a;
// return m1*m1;
// }
// int logn(int n, int r)
// {
// return (n > r - 1) ? 1 + logn(n / r, r) : 0;
// }
// int nCr(int n,int r)
// {
// r = min(r,n-r);
// if(r<0)
// return 0;
// if(r == 0)
// return 1;
// int ans = 1;
// for(int i = 1;i<=r;i++)
// {
// ans = ans*(n-i+1)/i;
// }
// return ans;
//
// }
// vi factmod(int n)
// {
// vi ans(n+1);
// ans[0] = 1;
// loop(i,1,n+1)
// {
// ans[i] = (ans[i-1]*i)%mod;
// }
// return ans;
// }
// int nCrmod(int n,int r,vi &fact)
// {
// int x1,y1;
// extendedgcd(fact[r],mod,x1,y1);
// int x2,y2;
// extendedgcd(fact[n-r],mod,x2,y2);
// int ans = (fact[n]*((x1+mod)%mod))%mod;
// ans = (ans*((x2+mod)%mod))%mod;
// return ans;
// }
// void dfs(vector<vector<int> > &adj,int root,vbool &vis)
// {
// vis[root] = true;
// for(int i = 0;i<adj[root].size();i++){
// int v = adj[root][i];
// if(!vis[v])
// dfs(adj,v,vis);
// }
// }
int32_t main() {
FastIO;
PRECISION;
int t = 1;
// cin>>t;
while (t--) {
int n, m, k;
cin >> n >> m >> k;
vi a(n);
vi b(m);
scan(a, n);
scan(b, m);
int curr = 0;
int pos = n - 1;
int count = 0;
loop(i, 0, n) {
if (curr + a[i] > k) {
pos = i - 1;
break;
} else {
count++;
curr += a[i];
}
}
int ans = count;
loop(i, 0, m) {
if (curr + b[i] <= k) {
curr += b[i];
count++;
} else {
if (pos < 0)
break;
else {
curr -= a[curr];
pos--;
count--;
i--;
}
}
ans = max(ans, count);
}
cout << ans << '\n';
}
} |
// Problem : C - Tsundoku
// Contest : AtCoder - AtCoder Beginner Contest 172
// URL : https://atcoder.jp/contests/abc172/tasks/abc172_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include <bits/stdc++.h>
#define int long long
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define vi vector<int>
#define vstr vector<string>
#define vdb vector<double>
#define vbool vector<bool>
#define vvi vector<vector<int>>
#define mii map<int, int>
#define pb push_back
#define pii pair<int, int>
#define vpair vector<pii>
#define mkp make_pair
#define scan(a, n) \
for (int i = 0; i < n; i++) \
cin >> a[i]
#define print(a, n) \
for (int i = 0; i < n; i++) { \
cout << a[i] << ' '; \
} \
cout << '\n'
#define mem(a, v) memset(a, v, sizeof(a))
#define loop(i, a, b) for (int i = a; i < b; i++)
#define loope(i, a, b) for (int i = a; i <= b; i++)
#define bloop(i, a, b) for (int i = a; i >= b; i--)
#define FastIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
#define PRECISION \
std::cout.unsetf(std::ios::fixed); \
std::cout.precision(9)
#define PI 3.14159265
#define S second
#define F first
#define CHECK cout << "CHEDEDWB" << endl
#define CHECK1(a) cout << a << endl
#define CHECK2(a, b) cout << a << ' ' << b << endl;
#define br '\n'
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
using namespace std;
int mod = 1e9 + 7;
int inf = 1e18;
int m_inf = INT_MIN;
// int extendedgcd(int a,int b,int &x,int &y){
// if(a == 0){
// x = 0; y = 1;
// return b;
// }
// int x1,y1;
// int d = extendedgcd(b%a,a,x1,y1);
// x = y1 - (b/a)*x1;y = x1;
// return d;
// }
// int expmod(int a,int b) {
// if(b == 1) return a;
// if(b == 0) return 1;
// int m1 = expmod(a,b/2)%mod;
// if(b%2) return ((m1*m1)%mod*a%mod)%mod;
// return (m1*m1)%mod;
// }
// int power(int a,int b) {
// if(b == 1) return a;
// if(b == 0) return 1;
// int m1 = power(a,b/2);
// if(b%2) return m1*m1*a;
// return m1*m1;
// }
// int logn(int n, int r)
// {
// return (n > r - 1) ? 1 + logn(n / r, r) : 0;
// }
// int nCr(int n,int r)
// {
// r = min(r,n-r);
// if(r<0)
// return 0;
// if(r == 0)
// return 1;
// int ans = 1;
// for(int i = 1;i<=r;i++)
// {
// ans = ans*(n-i+1)/i;
// }
// return ans;
//
// }
// vi factmod(int n)
// {
// vi ans(n+1);
// ans[0] = 1;
// loop(i,1,n+1)
// {
// ans[i] = (ans[i-1]*i)%mod;
// }
// return ans;
// }
// int nCrmod(int n,int r,vi &fact)
// {
// int x1,y1;
// extendedgcd(fact[r],mod,x1,y1);
// int x2,y2;
// extendedgcd(fact[n-r],mod,x2,y2);
// int ans = (fact[n]*((x1+mod)%mod))%mod;
// ans = (ans*((x2+mod)%mod))%mod;
// return ans;
// }
// void dfs(vector<vector<int> > &adj,int root,vbool &vis)
// {
// vis[root] = true;
// for(int i = 0;i<adj[root].size();i++){
// int v = adj[root][i];
// if(!vis[v])
// dfs(adj,v,vis);
// }
// }
int32_t main() {
FastIO;
PRECISION;
int t = 1;
// cin>>t;
while (t--) {
int n, m, k;
cin >> n >> m >> k;
vi a(n);
vi b(m);
scan(a, n);
scan(b, m);
int curr = 0;
int pos = n - 1;
int count = 0;
loop(i, 0, n) {
if (curr + a[i] > k) {
pos = i - 1;
break;
} else {
count++;
curr += a[i];
}
}
int ans = count;
loop(i, 0, m) {
if (curr + b[i] <= k) {
curr += b[i];
count++;
} else {
if (pos < 0)
break;
else {
curr -= a[pos];
pos--;
count--;
i--;
}
}
ans = max(ans, count);
}
cout << ans << '\n';
}
} | replace | 163 | 164 | 163 | 164 | 0 | |
p02623 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
#define pb push_back
#define pp pop_back
#define ubo upper_bound
#define lbo lower_bound
#define VI vector<int>
#define VL vector<ll>
#define VP vector<pii>
#define all(x) x.begin(), x.end()
#define M vector<VI>
const int N = 202020;
using namespace std;
int n, m;
ll k, a[N], b[N];
int main() {
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++)
a[i] += a[i - 1];
for (int i = 1; i <= m; i++)
b[i] += b[i - 1];
int l = 0, r = m, ans = 0;
for (; l <= n && r >= 0; l++) {
while (a[l] + b[r] > k)
r--;
ans = max(ans, l + r);
}
cout << ans << '\n';
return 0;
}
| #include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
#define pb push_back
#define pp pop_back
#define ubo upper_bound
#define lbo lower_bound
#define VI vector<int>
#define VL vector<ll>
#define VP vector<pii>
#define all(x) x.begin(), x.end()
#define M vector<VI>
const int N = 202020;
using namespace std;
int n, m;
ll k, a[N], b[N];
int main() {
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++)
a[i] += a[i - 1];
for (int i = 1; i <= m; i++)
b[i] += b[i - 1];
int l = 0, r = m, ans = 0;
for (; l <= n && r >= 0; l++) {
while (r >= 0 && a[l] + b[r] > k)
r--;
ans = max(ans, l + r);
}
cout << ans << '\n';
return 0;
}
| replace | 39 | 40 | 39 | 40 | 0 | |
p02623 | C++ | Runtime Error | #include <bits/stdc++.h>
#define N 100123
#define ll long long
#define endl '\n'
using namespace std;
int n, m, ans, curr;
ll k, a[N], b[N];
void print_vetor(ll v[], int size) {
for (int i = 0; i < size; ++i) {
cout << v[i] << ' ';
}
cout << endl;
}
int main() {
ios_base::sync_with_stdio(0);
cin >> n >> m >> k;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
for (int i = 0; i < m; ++i) {
cin >> b[i];
}
partial_sum(a, a + n, a);
partial_sum(b, b + m, b);
for (int i = 0; i < n; ++i) {
curr = 0;
if (k >= a[i])
curr = i + 1;
if (k > a[i]) {
curr += upper_bound(b, b + m, k - a[i]) - b;
}
ans = max(ans, curr);
}
for (int i = 0; i < m; ++i) {
curr = 0;
if (k >= b[i])
curr = i + 1;
if (k > b[i]) {
curr += upper_bound(a, a + n, k - b[i]) - a;
}
ans = max(ans, curr);
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define N 200123
#define ll long long
#define endl '\n'
using namespace std;
int n, m, ans, curr;
ll k, a[N], b[N];
void print_vetor(ll v[], int size) {
for (int i = 0; i < size; ++i) {
cout << v[i] << ' ';
}
cout << endl;
}
int main() {
ios_base::sync_with_stdio(0);
cin >> n >> m >> k;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
for (int i = 0; i < m; ++i) {
cin >> b[i];
}
partial_sum(a, a + n, a);
partial_sum(b, b + m, b);
for (int i = 0; i < n; ++i) {
curr = 0;
if (k >= a[i])
curr = i + 1;
if (k > a[i]) {
curr += upper_bound(b, b + m, k - a[i]) - b;
}
ans = max(ans, curr);
}
for (int i = 0; i < m; ++i) {
curr = 0;
if (k >= b[i])
curr = i + 1;
if (k > b[i]) {
curr += upper_bound(a, a + n, k - b[i]) - a;
}
ans = max(ans, curr);
}
cout << ans << endl;
return 0;
}
| replace | 1 | 2 | 1 | 2 | 0 | |
p02623 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define SZ(x) (int)(x).size()
#define endl '\n'
#define FOR(a, b, c) for (auto a = (b); (a) < (c); ++(a))
#define F0R(a, b) FOR(a, 0, (b))
#define CEIL(a, b) ((a) + (b)-1) / (b)
template <class T> bool ckmin(T &a, const T &b) {
return a > b ? a = b, true : false;
}
template <class T> bool ckmax(T &a, const T &b) {
return a < b ? a = b, true : false;
}
#ifndef DEBUG
#define DEBUG 0
#endif
#define dout \
if (DEBUG) \
std::cerr
#define dvar(...) " [" << #__VA_ARGS__ ": " << mt(__VA_ARGS__) << "] "
template <typename T> struct IsC {
template <typename C> static char test(typename C::const_iterator *);
template <typename C> static int test(...);
static const bool value = sizeof(test<T>(0)) == sizeof(char);
};
template <> struct IsC<string> {
static const bool value = false;
};
template <typename C>
typename enable_if<IsC<C>::value, ostream &>::type operator<<(ostream &,
const C &);
template <typename T1, typename T2>
ostream &operator<<(ostream &, const pair<T1, T2> &);
template <typename... T> using TS = tuple_size<tuple<T...>>;
template <size_t idx, typename... T>
typename enable_if<TS<T...>::value == idx + 1, ostream &>::type
operator<<(ostream &o, const tuple<T...> &t) {
return o << ", " << get<idx>(t) << ')';
}
template <size_t idx, typename... T>
typename enable_if<0 < idx && idx + 1 < TS<T...>::value, ostream &>::type
operator<<(ostream &o, const tuple<T...> &t) {
return operator<< <idx + 1>(o << ", " << get<idx>(t), t);
}
template <size_t idx = 0, typename... T>
typename enable_if<1 < TS<T...>::value && !idx, ostream &>::type
operator<<(ostream &o, const tuple<T...> &t) {
return operator<< <idx + 1>(o << '(' << get<idx>(t), t);
}
template <typename T> ostream &operator<<(ostream &o, const tuple<T> &t) {
return o << get<0>(t);
}
template <typename T1, typename T2>
ostream &operator<<(ostream &o, const pair<T1, T2> &p) {
return o << mt(p.fi, p.se);
}
template <typename C>
typename enable_if<IsC<C>::value, ostream &>::type operator<<(ostream &o,
const C &c) {
o << '[';
for (auto it = c.cbegin(); it != c.cend(); ++it)
o << *it << (next(it) != c.cend() ? ", " : "");
return o << ']';
}
template <typename T>
void tprint(vector<vector<T>> &v, size_t width = 0, ostream &o = cerr) {
if (!DEBUG)
return;
for (auto &vv : v) {
for (auto &i : vv)
o << setw(width) << i;
o << endl;
}
}
void solve() {
int n, m;
ll k;
cin >> n >> m >> k;
vector<ll> as(n), bs(n);
F0R(i, n) {
cin >> as[i];
if (i)
as[i] += as[i - 1];
}
F0R(i, m) {
cin >> bs[i];
if (i)
bs[i] += bs[i - 1];
}
dout << dvar(as) << dvar(bs) << endl;
int best = 0;
F0R(i, n) {
if (as[i] > k)
break;
int bi = distance(bs.begin(), upper_bound(ALL(bs), k - as[i]));
dout << dvar(i, bi) << endl;
ckmax(best, i + 1 + bi);
}
F0R(i, m) {
if (bs[i] > k)
break;
int ai = distance(as.begin(), upper_bound(ALL(as), k - bs[i]));
dout << dvar(i, ai) << endl;
ckmax(best, i + 1 + ai);
}
cout << best << endl;
}
int main() {
ios_base::sync_with_stdio(0);
cout.tie(0);
int tt = 1;
FOR(t, 1, tt + 1) {
// cout << "Case #" << t << ": ";
solve();
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define SZ(x) (int)(x).size()
#define endl '\n'
#define FOR(a, b, c) for (auto a = (b); (a) < (c); ++(a))
#define F0R(a, b) FOR(a, 0, (b))
#define CEIL(a, b) ((a) + (b)-1) / (b)
template <class T> bool ckmin(T &a, const T &b) {
return a > b ? a = b, true : false;
}
template <class T> bool ckmax(T &a, const T &b) {
return a < b ? a = b, true : false;
}
#ifndef DEBUG
#define DEBUG 0
#endif
#define dout \
if (DEBUG) \
std::cerr
#define dvar(...) " [" << #__VA_ARGS__ ": " << mt(__VA_ARGS__) << "] "
template <typename T> struct IsC {
template <typename C> static char test(typename C::const_iterator *);
template <typename C> static int test(...);
static const bool value = sizeof(test<T>(0)) == sizeof(char);
};
template <> struct IsC<string> {
static const bool value = false;
};
template <typename C>
typename enable_if<IsC<C>::value, ostream &>::type operator<<(ostream &,
const C &);
template <typename T1, typename T2>
ostream &operator<<(ostream &, const pair<T1, T2> &);
template <typename... T> using TS = tuple_size<tuple<T...>>;
template <size_t idx, typename... T>
typename enable_if<TS<T...>::value == idx + 1, ostream &>::type
operator<<(ostream &o, const tuple<T...> &t) {
return o << ", " << get<idx>(t) << ')';
}
template <size_t idx, typename... T>
typename enable_if<0 < idx && idx + 1 < TS<T...>::value, ostream &>::type
operator<<(ostream &o, const tuple<T...> &t) {
return operator<< <idx + 1>(o << ", " << get<idx>(t), t);
}
template <size_t idx = 0, typename... T>
typename enable_if<1 < TS<T...>::value && !idx, ostream &>::type
operator<<(ostream &o, const tuple<T...> &t) {
return operator<< <idx + 1>(o << '(' << get<idx>(t), t);
}
template <typename T> ostream &operator<<(ostream &o, const tuple<T> &t) {
return o << get<0>(t);
}
template <typename T1, typename T2>
ostream &operator<<(ostream &o, const pair<T1, T2> &p) {
return o << mt(p.fi, p.se);
}
template <typename C>
typename enable_if<IsC<C>::value, ostream &>::type operator<<(ostream &o,
const C &c) {
o << '[';
for (auto it = c.cbegin(); it != c.cend(); ++it)
o << *it << (next(it) != c.cend() ? ", " : "");
return o << ']';
}
template <typename T>
void tprint(vector<vector<T>> &v, size_t width = 0, ostream &o = cerr) {
if (!DEBUG)
return;
for (auto &vv : v) {
for (auto &i : vv)
o << setw(width) << i;
o << endl;
}
}
void solve() {
int n, m;
ll k;
cin >> n >> m >> k;
vector<ll> as(n), bs(m);
F0R(i, n) {
cin >> as[i];
if (i)
as[i] += as[i - 1];
}
F0R(i, m) {
cin >> bs[i];
if (i)
bs[i] += bs[i - 1];
}
dout << dvar(as) << dvar(bs) << endl;
int best = 0;
F0R(i, n) {
if (as[i] > k)
break;
int bi = distance(bs.begin(), upper_bound(ALL(bs), k - as[i]));
dout << dvar(i, bi) << endl;
ckmax(best, i + 1 + bi);
}
F0R(i, m) {
if (bs[i] > k)
break;
int ai = distance(as.begin(), upper_bound(ALL(as), k - bs[i]));
dout << dvar(i, ai) << endl;
ckmax(best, i + 1 + ai);
}
cout << best << endl;
}
int main() {
ios_base::sync_with_stdio(0);
cout.tie(0);
int tt = 1;
FOR(t, 1, tt + 1) {
// cout << "Case #" << t << ": ";
solve();
}
return 0;
}
| replace | 93 | 94 | 93 | 94 | 0 | |
p02623 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod = 1000000007, MAX = 400005;
const ll INF = 1LL << 60;
int main() {
std::ifstream in("text.txt");
std::cin.rdbuf(in.rdbuf());
cin.tie(0);
ios::sync_with_stdio(false);
int N, M;
ll K;
cin >> N >> M >> K;
vector<ll> A(N + 1), B(M + 1);
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];
}
A.push_back(INF);
B.push_back(INF);
int ans = 0;
int j = N;
for (int i = 0; i <= N; i++) {
if (A[i] > K)
break;
while (j >= 0 && A[i] + B[j] > K)
j--;
chmax(ans, i + j);
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod = 1000000007, MAX = 400005;
const ll INF = 1LL << 60;
int main() {
std::ifstream in("text.txt");
std::cin.rdbuf(in.rdbuf());
cin.tie(0);
ios::sync_with_stdio(false);
int N, M;
ll K;
cin >> N >> M >> K;
vector<ll> A(N + 1), B(M + 1);
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];
}
A.push_back(INF);
B.push_back(INF);
int ans = 0;
int j = M;
for (int i = 0; i <= N; i++) {
if (A[i] > K)
break;
while (j >= 0 && A[i] + B[j] > K)
j--;
chmax(ans, i + j);
}
cout << ans << endl;
}
| replace | 48 | 49 | 48 | 49 | 0 | |
p02623 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define re register
#define int long long
using namespace std;
inline int read() {
re int ans = 0;
re bool f = 1;
re char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
f = 0;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
ans = (ans << 3) + (ans << 1) + (ch ^ 48);
ch = getchar();
}
return f ? ans : ~(ans - 1);
}
int a[204800], b[204800];
signed main(void) {
int n, m, k, ans = 0;
n = read(), m = read(), k = read();
for (re int i = 1; i <= n; ++i)
a[i] = a[i - 1] + read();
for (re int i = 1; i <= m; ++i)
b[i] = b[i - 1] + read();
for (re int i = 1; i <= n; ++i) {
if (a[i] > k)
n = i - 1;
}
for (re int i = 1; i <= m; ++i) {
if (b[i] > k)
m = i - 1;
}
for (re int i = 0; i <= n; ++i) {
if (a[i] > k)
break;
for (re int j = 0; j <= m; ++j) {
if (b[j] > k)
break;
if (i + j <= ans)
continue;
if (a[i] + b[j] <= k)
ans = max(ans, i + j);
else
break;
}
}
printf("%lld\n", ans);
return 0;
} | #include <bits/stdc++.h>
#define re register
#define int long long
using namespace std;
inline int read() {
re int ans = 0;
re bool f = 1;
re char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
f = 0;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
ans = (ans << 3) + (ans << 1) + (ch ^ 48);
ch = getchar();
}
return f ? ans : ~(ans - 1);
}
int a[204800], b[204800];
signed main(void) {
int n, m, k, ans = 0;
n = read(), m = read(), k = read();
for (re int i = 1; i <= n; ++i)
a[i] = a[i - 1] + read();
for (re int i = 1; i <= m; ++i)
b[i] = b[i - 1] + read();
int j = m;
for (re int i = 0; i <= n && a[i] <= k; ++i) {
while (j >= 0 && a[i] + b[j] > k)
j--;
ans = max(ans, i + j);
}
printf("%lld\n", ans);
return 0;
} | replace | 29 | 50 | 29 | 34 | TLE | |
p02623 | C++ | Time Limit Exceeded | #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template <typename T> bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T> bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
#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 all(vec) vec.begin(), vec.end()
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef tuple<ll, ll, ll> tlll;
typedef tuple<int, int, int> tiii;
const ll mod = 1e9 + 7;
const int inf = 1 << 30;
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];
for (int i = 1; i < n; i++)
a[i] = a[i] + a[i - 1];
for (int i = 1; i < m; i++)
b[i] = b[i] + b[i - 1];
ll ans = 0;
rep(i, n) {
ll cnt = 0;
if (k - a[i] >= 0)
cnt = i + 1;
cnt += upper_bound(all(b), k - a[i]) - b.begin();
chmax(ans, cnt);
}
chmax(ans, ll(upper_bound(all(b), k) - b.begin()));
cout << ans << endl;
} | // #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template <typename T> bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T> bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
#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 all(vec) vec.begin(), vec.end()
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef tuple<ll, ll, ll> tlll;
typedef tuple<int, int, int> tiii;
const ll mod = 1e9 + 7;
const int inf = 1 << 30;
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];
for (int i = 1; i < n; i++)
a[i] = a[i] + a[i - 1];
for (int i = 1; i < m; i++)
b[i] = b[i] + b[i - 1];
ll ans = 0;
rep(i, n) {
ll cnt = 0;
if (k - a[i] >= 0)
cnt = i + 1;
cnt += upper_bound(all(b), k - a[i]) - b.begin();
chmax(ans, cnt);
}
chmax(ans, ll(upper_bound(all(b), k) - b.begin()));
cout << ans << endl;
} | replace | 0 | 1 | 0 | 1 | TLE | |
p02623 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
template <class T> using V = vector<T>;
template <class S, class T> using P = pair<S, T>;
using ll = long long;
using ull = unsigned long long;
using vll = V<ll>;
using vvll = V<vll>;
using vvvll = V<vvll>;
using pl = P<ll, ll>;
using vpl = V<pl>;
using vvpl = V<vpl>;
using vs = V<string>;
using qll = queue<ll>;
using qpl = queue<pl>;
using mapll = map<ll, ll>;
using setll = set<ll>;
using pqll = priority_queue<ll>;
#define int ll
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
#define sz size()
#define bgn begin()
#define en end()
#define emp empty()
#define fr front()
#define bk back()
#define res resize
#define tp top()
#define p_q priority_queue
#define inv inverse()
#define FOR(i, a, b) for (ll i = (a); i <= (ll)(b); i++)
#define rFOR(i, a, b) for (ll i = (b); i >= (ll)(a); i--)
#define REP(i, a) FOR((i), 0, (ll)(a)-1)
#define REP0(i, a) FOR((i), 0, (ll)(a))
#define REP1(i, a) FOR((i), 1, (ll)(a))
#define rREP(i, a) rFOR((i), 0, (ll)(a)-1)
#define rREP0(i, a) rFOR((i), 0, (ll)(a))
#define rREP1(i, a) rFOR((i), 1, (ll)(a))
#define IOTA(a, n) iota((a).bgn, (a).en, (n))
#define SORT(a) sort((a).bgn, (a).en)
#define rSORT(a) sort((a).rbegin(), (a).rend())
#define UNIQUE(a) (a).erase(unique((a).bgn, (a).en), (a).en)
#define BINS(a, b) binary_search((a).bgn, (a).en, (b))
#define LOWB(a, b) (lower_bound((a).bgn, (a).en, (b)) - (a).bgn)
#define UPB(a, b) (upper_bound((a).bgn, (a).en, (b)) - (a).bgn)
#define CNT(a, b) count((a).bgn, (a).en, b)
#define SUM(a) accumulate((a).bgn, (a).en, 0)
#define REV(a) reverse((a).bgn, (a).en)
#define yn(a) cout << ((a) ? "yes" : "no") << "\n";
#define Yn(a) cout << ((a) ? "Yes" : "No") << "\n";
#define YN(a) cout << ((a) ? "YES" : "NO") << "\n";
#define imp(a) cout << ((a) ? "possible" : "impossible") << "\n";
#define Imp(a) cout << ((a) ? "Possible" : "Impossible") << "\n";
#define IMP(a) cout << ((a) ? "POSSIBLE" : "IMPOSSIBLE") << "\n";
#define dbg(a) cerr << (#a) << ": " << (a) << "\n";
#define DigN2(a) ((llabs(a) == 0) ? (1) : ((ll)(log2(double(llabs(a)))) + 1))
#define DigN10(a) ((llabs(a) == 0) ? (1) : ((ll)(log10(double(llabs(a)))) + 1))
#define Dig2(a, b) (((a) >> (b)) & 1)
#define Dig10(a, b) (ll)(((a) / ((ll)(pow(10.0, (double)(b))))) % 10)
#define Pow2(a) ((ll)(1) << (a))
#define Pow10(a) ((ll)(pow(10.0, double(a))))
#define powll(a, b) (ll)(pow((double)(a), (double)(b)))
#define li(...) \
ll __VA_ARGS__; \
Input(__VA_ARGS__);
#define si(...) \
string __VA_ARGS__; \
Input(__VA_ARGS__);
#define vli(size, ...) \
vll __VA_ARGS__; \
vInput(size, __VA_ARGS__);
#define vsi(size, ...) \
vs __VA_ARGS__; \
vInput(size, __VA_ARGS__);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
// const ll MOD = 924844033;
// const ll MOD = 9007199254740881;
const ll INF = 1LL << 60; // 1.15e18
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
void Input() {}
template <class Var, class... Args> void Input(Var &var, Args &...args) {
cin >> var;
Input(args...);
}
void vInit(ll size) {}
template <class T, class... Args> void vInit(ll size, V<T> &v, Args &...args) {
v.res(size);
vInit(size, args...);
}
void vInputNum(ll num) {}
template <class T, class... Args>
void vInputNum(ll num, V<T> &v, Args &...args) {
cin >> v[num];
vInputNum(num, args...);
}
void vInput(ll size) {}
template <class... Args> void vInput(ll size, Args &...args) {
vInit(size, args...);
REP(i, size) vInputNum(i, args...);
}
template <class S, class T>
ostream &operator<<(ostream &out, const P<S, T> &p) {
return out << "[" << p.fi << ", " << p.se << "]";
}
template <class T> ostream &operator<<(ostream &out, V<T> &v) {
if (v.emp)
return out << "{}";
else {
auto itr = v.bgn;
out << "{" << *itr;
itr++;
while (itr != v.en) {
out << ", " << *itr;
itr++;
}
out << "}";
return out;
}
}
template <class S, class T>
ostream &operator<<(ostream &out, const map<S, T> &m) {
if (m.emp)
return out << "<[]>";
else {
auto itr = m.bgn;
out << "< [" << (itr->fi) << ": " << (itr->se);
itr++;
while (itr != m.en) {
out << "], [" << (itr->fi) << ": " << (itr->se);
itr++;
}
out << "] >";
return out;
}
}
template <class T> ostream &operator<<(ostream &out, const set<T> &s) {
if (s.emp)
return out << "<>";
else {
auto itr = s.bgn;
out << "<" << *itr;
itr++;
while (itr != s.en) {
out << ", " << *itr;
itr++;
}
out << ">";
return out;
}
}
ll gcd(ll a, ll b) {
if (a < b) {
a ^= b;
b ^= a;
a ^= b;
}
return b ? gcd(b, a % b) : a;
}
// a > b
ll gcdex(ll a, ll b) { return b ? gcdex(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
struct UFT {
public:
ll tsize;
ll mode;
vll par;
vll rank;
UFT() {}
UFT(const UFT &uft) {}
UFT(ll tsizeget, ll modeget = 0) {
tsize = tsizeget;
mode = modeget;
par.assign(tsize, -1);
if (!mode)
rank.res(tsize, 0);
}
ll root(ll x) { return par[x] < 0 ? x : par[x] = root(par[x]); }
bool isRoot(ll x) { return x == root(x); }
bool same(ll x, ll y) { return root(x) == root(y); }
void merge(ll x, ll y) {
x = root(x);
y = root(y);
if (x == y)
return;
if (mode) {
par[x] += par[y];
par[y] = x;
} else {
if (rank[x] < rank[y]) {
par[y] += par[x];
par[x] = y;
} else {
par[x] += par[y];
par[y] = x;
if (rank[x] == rank[y])
rank[x]++;
}
}
}
ll size(ll x) { return -par[root(x)]; }
};
ll isP(ll n) {
if (n <= 1)
return 0;
FOR(i, 2, (ll)sqrt(n) + 1) {
if (n % i == 0)
return 0;
}
return 1;
}
vvll CombMemo(3000, vll(3000, -1));
ll Comb(ll n, ll k) {
if ((n < 0) || (k < 0))
return 0;
if (CombMemo[n][k] == -1) {
if (n < k)
CombMemo[n][k] = 0;
else {
if (n == 0)
CombMemo[n][k] = 1;
else if (k == 0)
CombMemo[n][k] = 1;
else if (n == k)
CombMemo[n][k] = 1;
else
CombMemo[n][k] = Comb(n - 1, k - 1) + Comb(n - 1, k);
}
}
return CombMemo[n][k];
}
vll Couunt(string s) {
vll v(0);
ll c;
char ch;
ch = s[0];
c = 1;
REP1(i, s.sz - 1) {
if (s[i] == ch) {
c++;
} else {
v.pb(c);
c = 1;
}
ch = s[i];
}
if (c) {
v.pb(c);
}
return v;
}
void Solve();
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << setprecision(20) << fixed;
Solve();
}
void Solve() {
li(n, m, k);
vli(n, a);
vli(n, b);
ll r = 0, wa = 0, wb = 0;
vll am(n + 1, 0), bm(m + 1, 0);
REP1(i, n) {
am[i] = am[i - 1] + a[i - 1];
if (am[i] <= k)
wa = i;
}
REP1(i, m) { bm[i] = bm[i - 1] + b[i - 1]; }
while (wa >= 0) {
while (wb <= m && am[wa] + bm[wb] <= k) {
r = max(r, wa + wb);
wb++;
}
wa--;
}
cout << r;
}
| #include <bits/stdc++.h>
using namespace std;
template <class T> using V = vector<T>;
template <class S, class T> using P = pair<S, T>;
using ll = long long;
using ull = unsigned long long;
using vll = V<ll>;
using vvll = V<vll>;
using vvvll = V<vvll>;
using pl = P<ll, ll>;
using vpl = V<pl>;
using vvpl = V<vpl>;
using vs = V<string>;
using qll = queue<ll>;
using qpl = queue<pl>;
using mapll = map<ll, ll>;
using setll = set<ll>;
using pqll = priority_queue<ll>;
#define int ll
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
#define sz size()
#define bgn begin()
#define en end()
#define emp empty()
#define fr front()
#define bk back()
#define res resize
#define tp top()
#define p_q priority_queue
#define inv inverse()
#define FOR(i, a, b) for (ll i = (a); i <= (ll)(b); i++)
#define rFOR(i, a, b) for (ll i = (b); i >= (ll)(a); i--)
#define REP(i, a) FOR((i), 0, (ll)(a)-1)
#define REP0(i, a) FOR((i), 0, (ll)(a))
#define REP1(i, a) FOR((i), 1, (ll)(a))
#define rREP(i, a) rFOR((i), 0, (ll)(a)-1)
#define rREP0(i, a) rFOR((i), 0, (ll)(a))
#define rREP1(i, a) rFOR((i), 1, (ll)(a))
#define IOTA(a, n) iota((a).bgn, (a).en, (n))
#define SORT(a) sort((a).bgn, (a).en)
#define rSORT(a) sort((a).rbegin(), (a).rend())
#define UNIQUE(a) (a).erase(unique((a).bgn, (a).en), (a).en)
#define BINS(a, b) binary_search((a).bgn, (a).en, (b))
#define LOWB(a, b) (lower_bound((a).bgn, (a).en, (b)) - (a).bgn)
#define UPB(a, b) (upper_bound((a).bgn, (a).en, (b)) - (a).bgn)
#define CNT(a, b) count((a).bgn, (a).en, b)
#define SUM(a) accumulate((a).bgn, (a).en, 0)
#define REV(a) reverse((a).bgn, (a).en)
#define yn(a) cout << ((a) ? "yes" : "no") << "\n";
#define Yn(a) cout << ((a) ? "Yes" : "No") << "\n";
#define YN(a) cout << ((a) ? "YES" : "NO") << "\n";
#define imp(a) cout << ((a) ? "possible" : "impossible") << "\n";
#define Imp(a) cout << ((a) ? "Possible" : "Impossible") << "\n";
#define IMP(a) cout << ((a) ? "POSSIBLE" : "IMPOSSIBLE") << "\n";
#define dbg(a) cerr << (#a) << ": " << (a) << "\n";
#define DigN2(a) ((llabs(a) == 0) ? (1) : ((ll)(log2(double(llabs(a)))) + 1))
#define DigN10(a) ((llabs(a) == 0) ? (1) : ((ll)(log10(double(llabs(a)))) + 1))
#define Dig2(a, b) (((a) >> (b)) & 1)
#define Dig10(a, b) (ll)(((a) / ((ll)(pow(10.0, (double)(b))))) % 10)
#define Pow2(a) ((ll)(1) << (a))
#define Pow10(a) ((ll)(pow(10.0, double(a))))
#define powll(a, b) (ll)(pow((double)(a), (double)(b)))
#define li(...) \
ll __VA_ARGS__; \
Input(__VA_ARGS__);
#define si(...) \
string __VA_ARGS__; \
Input(__VA_ARGS__);
#define vli(size, ...) \
vll __VA_ARGS__; \
vInput(size, __VA_ARGS__);
#define vsi(size, ...) \
vs __VA_ARGS__; \
vInput(size, __VA_ARGS__);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
// const ll MOD = 924844033;
// const ll MOD = 9007199254740881;
const ll INF = 1LL << 60; // 1.15e18
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
void Input() {}
template <class Var, class... Args> void Input(Var &var, Args &...args) {
cin >> var;
Input(args...);
}
void vInit(ll size) {}
template <class T, class... Args> void vInit(ll size, V<T> &v, Args &...args) {
v.res(size);
vInit(size, args...);
}
void vInputNum(ll num) {}
template <class T, class... Args>
void vInputNum(ll num, V<T> &v, Args &...args) {
cin >> v[num];
vInputNum(num, args...);
}
void vInput(ll size) {}
template <class... Args> void vInput(ll size, Args &...args) {
vInit(size, args...);
REP(i, size) vInputNum(i, args...);
}
template <class S, class T>
ostream &operator<<(ostream &out, const P<S, T> &p) {
return out << "[" << p.fi << ", " << p.se << "]";
}
template <class T> ostream &operator<<(ostream &out, V<T> &v) {
if (v.emp)
return out << "{}";
else {
auto itr = v.bgn;
out << "{" << *itr;
itr++;
while (itr != v.en) {
out << ", " << *itr;
itr++;
}
out << "}";
return out;
}
}
template <class S, class T>
ostream &operator<<(ostream &out, const map<S, T> &m) {
if (m.emp)
return out << "<[]>";
else {
auto itr = m.bgn;
out << "< [" << (itr->fi) << ": " << (itr->se);
itr++;
while (itr != m.en) {
out << "], [" << (itr->fi) << ": " << (itr->se);
itr++;
}
out << "] >";
return out;
}
}
template <class T> ostream &operator<<(ostream &out, const set<T> &s) {
if (s.emp)
return out << "<>";
else {
auto itr = s.bgn;
out << "<" << *itr;
itr++;
while (itr != s.en) {
out << ", " << *itr;
itr++;
}
out << ">";
return out;
}
}
ll gcd(ll a, ll b) {
if (a < b) {
a ^= b;
b ^= a;
a ^= b;
}
return b ? gcd(b, a % b) : a;
}
// a > b
ll gcdex(ll a, ll b) { return b ? gcdex(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
struct UFT {
public:
ll tsize;
ll mode;
vll par;
vll rank;
UFT() {}
UFT(const UFT &uft) {}
UFT(ll tsizeget, ll modeget = 0) {
tsize = tsizeget;
mode = modeget;
par.assign(tsize, -1);
if (!mode)
rank.res(tsize, 0);
}
ll root(ll x) { return par[x] < 0 ? x : par[x] = root(par[x]); }
bool isRoot(ll x) { return x == root(x); }
bool same(ll x, ll y) { return root(x) == root(y); }
void merge(ll x, ll y) {
x = root(x);
y = root(y);
if (x == y)
return;
if (mode) {
par[x] += par[y];
par[y] = x;
} else {
if (rank[x] < rank[y]) {
par[y] += par[x];
par[x] = y;
} else {
par[x] += par[y];
par[y] = x;
if (rank[x] == rank[y])
rank[x]++;
}
}
}
ll size(ll x) { return -par[root(x)]; }
};
ll isP(ll n) {
if (n <= 1)
return 0;
FOR(i, 2, (ll)sqrt(n) + 1) {
if (n % i == 0)
return 0;
}
return 1;
}
vvll CombMemo(3000, vll(3000, -1));
ll Comb(ll n, ll k) {
if ((n < 0) || (k < 0))
return 0;
if (CombMemo[n][k] == -1) {
if (n < k)
CombMemo[n][k] = 0;
else {
if (n == 0)
CombMemo[n][k] = 1;
else if (k == 0)
CombMemo[n][k] = 1;
else if (n == k)
CombMemo[n][k] = 1;
else
CombMemo[n][k] = Comb(n - 1, k - 1) + Comb(n - 1, k);
}
}
return CombMemo[n][k];
}
vll Couunt(string s) {
vll v(0);
ll c;
char ch;
ch = s[0];
c = 1;
REP1(i, s.sz - 1) {
if (s[i] == ch) {
c++;
} else {
v.pb(c);
c = 1;
}
ch = s[i];
}
if (c) {
v.pb(c);
}
return v;
}
void Solve();
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << setprecision(20) << fixed;
Solve();
}
void Solve() {
li(n, m, k);
vli(n, a);
vli(m, b);
ll r = 0, wa = 0, wb = 0;
vll am(n + 1, 0), bm(m + 1, 0);
REP1(i, n) {
am[i] = am[i - 1] + a[i - 1];
if (am[i] <= k)
wa = i;
}
REP1(i, m) { bm[i] = bm[i - 1] + b[i - 1]; }
while (wa >= 0) {
while (wb <= m && am[wa] + bm[wb] <= k) {
r = max(r, wa + wb);
wb++;
}
wa--;
}
cout << r;
}
| replace | 293 | 294 | 293 | 294 | 0 | |
p02623 | Python | Time Limit Exceeded | def main():
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
sum_A = [A[0]]
sum_B = [B[0]]
for i in range(n - 1):
sum_A.append(sum_A[i] + A[i + 1])
for i in range(m - 1):
sum_B.append(sum_B[i] + B[i + 1])
R = []
b = m - 1
flag = False
while b > -1:
if sum_B[b] <= k:
R.append(b + 1)
flag = True
break
else:
b -= 1
if not flag:
R.append(0)
for i in range(n):
a = sum_A[i]
b = m - 1
flag = False
while b > -1:
if sum_B[b] <= k - a:
R.append(i + 1 + b + 1)
flag = True
break
else:
b -= 1
if not flag:
if 0 <= k - a:
R.append(i + 1)
else:
R.append(0)
print(max(R))
# while k > 0 and (a < n or b < m):
# if a == n:
# time = B[b]
# elif b == m:
# time = A[a]
# else:
# time = min(A[a], B[b])
# if k - time < 0:
# break
# r += 1
# k -= time
# print(k)
# if a == n:
# b += 1
# elif b == m:
# a += 1
# else:
# if A[a] >= B[b]:
# b += 1
# else:
# a += 1
# print(r)
if __name__ == "__main__":
main()
| def main():
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
sum_A = [A[0]]
sum_B = [B[0]]
for i in range(n - 1):
sum_A.append(sum_A[i] + A[i + 1])
for i in range(m - 1):
sum_B.append(sum_B[i] + B[i + 1])
R = []
b = m - 1
flag = False
while b > -1:
if sum_B[b] <= k:
R.append(b + 1)
flag = True
break
else:
b -= 1
if not flag:
R.append(0)
for i in range(n):
a = sum_A[i]
flag = False
while b > -1:
if sum_B[b] <= k - a:
R.append(i + 1 + b + 1)
flag = True
break
else:
b -= 1
if not flag:
if 0 <= k - a:
R.append(i + 1)
else:
R.append(0)
print(max(R))
# while k > 0 and (a < n or b < m):
# if a == n:
# time = B[b]
# elif b == m:
# time = A[a]
# else:
# time = min(A[a], B[b])
# if k - time < 0:
# break
# r += 1
# k -= time
# print(k)
# if a == n:
# b += 1
# elif b == m:
# a += 1
# else:
# if A[a] >= B[b]:
# b += 1
# else:
# a += 1
# print(r)
if __name__ == "__main__":
main()
| delete | 32 | 33 | 32 | 32 | TLE | |
p02623 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fsp(x) fixed << setprecision(x)
#define xout cerr
const ll inf = LLONG_MAX;
const long double pi = acosl(-1);
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
bool is_ok(ll x, ll n, ll m, ll k, vector<ll> &suma, vector<ll> &sumb) {
for (ll i = 0; i <= min(x, n); i++) {
ll j = x - i;
if (j > m)
continue;
if (suma[i] + sumb[j] <= k)
return true;
}
return false;
}
ll binary_search(ll l, ll r, ll n, ll m, ll k, vector<ll> &suma,
vector<ll> &sumb) {
if (l + 1 == r)
return l;
ll mid = (l + r) / 2;
if (is_ok(mid, n, m, k, suma, sumb))
return binary_search(mid, r, n, m, k, suma, sumb);
else
return binary_search(l, mid, n, m, k, suma, sumb);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
// const ll p = 1e9 + 7;
// const ll p = 998244353;
ll n, m, k;
cin >> n >> m >> k;
vector<ll> a(n), b(m);
for (ll i = 0; i < n; i++)
cin >> a[i];
for (ll i = 0; i < m; i++)
cin >> b[i];
if (a[0] > k || b[0] > k) {
cout << 0 << endl;
return 0;
}
vector<ll> suma(n + 1, 0), 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];
if (suma[n] + sumb[n] <= k) {
cout << n + m << endl;
return 0;
}
cout << binary_search(0, n + m, n, m, k, suma, sumb) << endl;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fsp(x) fixed << setprecision(x)
#define xout cerr
const ll inf = LLONG_MAX;
const long double pi = acosl(-1);
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
bool is_ok(ll x, ll n, ll m, ll k, vector<ll> &suma, vector<ll> &sumb) {
for (ll i = 0; i <= min(x, n); i++) {
ll j = x - i;
if (j > m)
continue;
if (suma[i] + sumb[j] <= k)
return true;
}
return false;
}
ll binary_search(ll l, ll r, ll n, ll m, ll k, vector<ll> &suma,
vector<ll> &sumb) {
if (l + 1 == r)
return l;
ll mid = (l + r) / 2;
if (is_ok(mid, n, m, k, suma, sumb))
return binary_search(mid, r, n, m, k, suma, sumb);
else
return binary_search(l, mid, n, m, k, suma, sumb);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
// const ll p = 1e9 + 7;
// const ll p = 998244353;
ll n, m, k;
cin >> n >> m >> k;
vector<ll> a(n), b(m);
for (ll i = 0; i < n; i++)
cin >> a[i];
for (ll i = 0; i < m; i++)
cin >> b[i];
if (a[0] > k || b[0] > k) {
cout << 0 << endl;
return 0;
}
vector<ll> suma(n + 1, 0), 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];
if (suma[n] + sumb[m] <= k) {
cout << n + m << endl;
return 0;
}
cout << binary_search(0, n + m, n, m, k, suma, sumb) << endl;
} | replace | 60 | 61 | 60 | 61 | 0 | |
p02623 | Python | Runtime Error | def main():
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a, b = [0], [0]
for i in range(N):
a.append(a[i] + A[i])
for i in range(M):
a.append(b[i] + B[i])
ans, j = 0, M
for i in range(N + 1):
if a[i] > K:
break
while a[i] + b[j] > K:
j -= 1
ans = max(ans, i + j)
print(ans)
if __name__ == "__main__":
main()
| def main():
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a, b = [0], [0]
for i in range(N):
a.append(a[i] + A[i])
for i in range(M):
b.append(b[i] + B[i])
ans, j = 0, M
for i in range(N + 1):
if a[i] > K:
break
while a[i] + b[j] > K:
j -= 1
ans = max(ans, i + j)
print(ans)
if __name__ == "__main__":
main()
| replace | 9 | 10 | 9 | 10 | IndexError: list index out of range | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02623/Python/s656972231.py", line 26, in <module>
main()
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02623/Python/s656972231.py", line 10, in main
a.append(b[i] + B[i])
IndexError: list index out of range
|
p02623 | C++ | Runtime Error | #include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
using namespace std;
#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i, a, N) for ((i) = (a); (i) < (N); (i)++)
#define rrp(i, N, a) for ((i) = (N)-1; (i) >= (a); (i)--)
#define llfor ll i, j
#define sc(a) cin >> a
#define pr(a) cout << a << endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define all(a) a.begin(), a.end()
#define push(a, b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a, b) (a, vector<ll>(b))
#define llpvec vector<pair<ll, ll>>
llfor;
ll mod = 1000000007;
/*pi*/ double pi = acos(-1);
/*繰り上げ除算*/ ll cei(ll x, ll y) {
ll ans = x / y;
if (x % y != 0)
ans++;
return ans;
}
/*最大公約数*/ ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
/*最小公倍数*/ ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
/*n乗*/ ll llpow(ll x, ll n) {
ll ans = 1;
rep(i, 0, n) {
ans *= x;
ans %= mod;
}
return ans;
}
/*階乗*/ ll fact(ll x) {
ll ans = 1;
rep(i, 0, x) ans *= (x - i);
return ans;
}
/*nCr*/ ll ncr(ll n, ll r) {
ll ans = 1;
rrp(i, n - r + 1, n + 1) {
ans *= i;
ans %= mod;
}
return ans /= fact(r);
}
/*nPr*/ ll npr(ll n, ll r) { return fact(n) / fact(n - r); }
/*primejudge*/ bool prime(ll a) {
if (a <= 1)
return false;
for (i = 2; i * i <= a; i++) {
if (a % i == 0)
return false;
}
return true;
}
/*Fibonacci数列*/ ll fib(ll x) {
ll fibo[x + 10];
fibo[0] = 1;
fibo[1] = 1;
fibo[2] = 1;
rep(i, 3, x + 1) fibo[i] = fibo[i - 1] + fibo[i - 2];
return fibo[x];
}
/*桁数*/ ll dig(ll n) {
ll d = 1, tmp = n;
while (tmp / 10 > 0) {
tmp /= 10;
d++;
}
return d;
}
ll ans = 0;
////////////////////////////////////////////////////////////
int main() {
ll n, m, k;
cin >> n >> m >> k;
vector<ll> a, b;
ll ai, bi;
ans = 0;
rep(i, 0, n) {
sc(ai);
push(a, ai);
if (i != 0)
a.at(i) += a.at(i - 1);
if (a[i] <= k)
ans = max(ans, i + 1);
// cout<<ans<<endl;
}
// pnn;
rep(i, 0, m) {
sc(bi);
push(b, bi);
if (i != 0)
b.at(i) += b.at(i - 1);
if (b[i] <= k)
ans = max(ans, i + 1);
// cout<<ans<<endl;
}
// pnn;
ll st;
rep(i, 0, n) {
if (ans > 0)
st = ans - i - 1;
else
st = 0;
rep(j, st, m) {
// cout<<ans<<" "<<a[i]+b[j]<<" "<<i+j+2<<endl;
if (a[i] + b[j] <= k)
ans = max(ans, i + j + 2);
else
break;
}
}
pr(ans);
return 0;
}
| #include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
using namespace std;
#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i, a, N) for ((i) = (a); (i) < (N); (i)++)
#define rrp(i, N, a) for ((i) = (N)-1; (i) >= (a); (i)--)
#define llfor ll i, j
#define sc(a) cin >> a
#define pr(a) cout << a << endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define all(a) a.begin(), a.end()
#define push(a, b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a, b) (a, vector<ll>(b))
#define llpvec vector<pair<ll, ll>>
llfor;
ll mod = 1000000007;
/*pi*/ double pi = acos(-1);
/*繰り上げ除算*/ ll cei(ll x, ll y) {
ll ans = x / y;
if (x % y != 0)
ans++;
return ans;
}
/*最大公約数*/ ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
/*最小公倍数*/ ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
/*n乗*/ ll llpow(ll x, ll n) {
ll ans = 1;
rep(i, 0, n) {
ans *= x;
ans %= mod;
}
return ans;
}
/*階乗*/ ll fact(ll x) {
ll ans = 1;
rep(i, 0, x) ans *= (x - i);
return ans;
}
/*nCr*/ ll ncr(ll n, ll r) {
ll ans = 1;
rrp(i, n - r + 1, n + 1) {
ans *= i;
ans %= mod;
}
return ans /= fact(r);
}
/*nPr*/ ll npr(ll n, ll r) { return fact(n) / fact(n - r); }
/*primejudge*/ bool prime(ll a) {
if (a <= 1)
return false;
for (i = 2; i * i <= a; i++) {
if (a % i == 0)
return false;
}
return true;
}
/*Fibonacci数列*/ ll fib(ll x) {
ll fibo[x + 10];
fibo[0] = 1;
fibo[1] = 1;
fibo[2] = 1;
rep(i, 3, x + 1) fibo[i] = fibo[i - 1] + fibo[i - 2];
return fibo[x];
}
/*桁数*/ ll dig(ll n) {
ll d = 1, tmp = n;
while (tmp / 10 > 0) {
tmp /= 10;
d++;
}
return d;
}
ll ans = 0;
////////////////////////////////////////////////////////////
int main() {
ll n, m, k;
cin >> n >> m >> k;
vector<ll> a, b;
ll ai, bi;
ans = 0;
rep(i, 0, n) {
sc(ai);
push(a, ai);
if (i != 0)
a.at(i) += a.at(i - 1);
if (a[i] <= k)
ans = max(ans, i + 1);
// cout<<ans<<endl;
}
// pnn;
rep(i, 0, m) {
sc(bi);
push(b, bi);
if (i != 0)
b.at(i) += b.at(i - 1);
if (b[i] <= k)
ans = max(ans, i + 1);
// cout<<ans<<endl;
}
// pnn;
ll st;
rep(i, 0, n) {
if (ans - i - 1 > 0)
st = ans - i - 1;
else
st = 0;
rep(j, st, m) {
// cout<<ans<<" "<<a[i]+b[j]<<" "<<i+j+2<<endl;
if (a[i] + b[j] <= k)
ans = max(ans, i + j + 2);
else
break;
}
}
pr(ans);
return 0;
}
| replace | 129 | 130 | 129 | 130 | 0 | |
p02623 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define ll long long
inline int D() {
int t;
scanf("%d", &t);
return t;
}
inline ll LLD() {
ll t;
scanf("%lld", &t);
return t;
}
// const int INF = 0x3f3f3f3f;
// const int mod=1e9+7;
// const double pi=3.14159265359;
// ###################################################################
int main() {
int n = D(), m = D(), k = D();
int a[n], b[m];
ll cm1[n + 1], cm2[m + 1];
cm1[0] = 0, cm2[0] = 0;
for (int i = 0; i <= n; i++) {
if (i < n)
a[i] = D();
if (i)
cm1[i] = cm1[i - 1] + a[i - 1];
}
for (int i = 0; i <= m; i++) {
if (i < m)
b[i] = D();
if (i)
cm2[i] = cm2[i - 1] + b[i - 1];
}
int ans = 0;
for (int i = 0; i <= n && cm1[i] <= k; i++) {
if (cm1[i] > k)
break;
for (int j = 0; j <= m && (cm2[j] + cm1[i]) <= k; j++) {
if (cm2[j] + cm1[i] > k)
break;
ans = max(ans, i + j);
}
}
cout << ans;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
inline int D() {
int t;
scanf("%d", &t);
return t;
}
inline ll LLD() {
ll t;
scanf("%lld", &t);
return t;
}
// const int INF = 0x3f3f3f3f;
// const int mod=1e9+7;
// const double pi=3.14159265359;
// ###################################################################
int main() {
int n = D(), m = D(), k = D();
int a[n], b[m];
ll cm1[n + 1], cm2[m + 1];
cm1[0] = 0, cm2[0] = 0;
for (int i = 0; i <= n; i++) {
if (i < n)
a[i] = D();
if (i)
cm1[i] = cm1[i - 1] + a[i - 1];
}
for (int i = 0; i <= m; i++) {
if (i < m)
b[i] = D();
if (i)
cm2[i] = cm2[i - 1] + b[i - 1];
}
int ans = 0;
for (int i = 0; i <= n && cm1[i] <= k; i++) {
if (cm1[i] > k)
break;
int it = upper_bound(cm2, cm2 + m + 1, (k - cm1[i])) - cm2;
ans = max(ans, i + it - 1);
}
cout << ans;
} | replace | 41 | 46 | 41 | 43 | TLE | |
p02623 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) \
v.erase(unique(v.begin(), v.end()), v.end()) // sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
for (T &x : vec)
is >> x;
return is;
}
signed main() {
cin >> N >> M >> K;
vector<ll> a(N), b(M);
cin >> a;
cin >> b;
vector<ll> sb(M);
sb[0] = b[0];
REPS(i, N - 1) { sb[i] = sb[i - 1] + b[i]; }
auto itr = upper_bound(ALL(sb), K);
ans = itr - sb.begin();
dump(sb);
dump(ans);
REP(i, N) {
K -= a[i];
if (K < 0) {
break;
}
auto itr = upper_bound(ALL(sb), K);
ans = max(ans, (ll)(itr - sb.begin() + i + 1));
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) \
v.erase(unique(v.begin(), v.end()), v.end()) // sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
for (T &x : vec)
is >> x;
return is;
}
signed main() {
cin >> N >> M >> K;
vector<ll> a(N), b(M);
cin >> a;
cin >> b;
vector<ll> sb(M);
sb[0] = b[0];
REPS(i, M - 1) { sb[i] = sb[i - 1] + b[i]; }
auto itr = upper_bound(ALL(sb), K);
ans = itr - sb.begin();
dump(sb);
dump(ans);
REP(i, N) {
K -= a[i];
if (K < 0) {
break;
}
auto itr = upper_bound(ALL(sb), K);
ans = max(ans, (ll)(itr - sb.begin() + i + 1));
}
cout << ans << endl;
} | replace | 43 | 44 | 43 | 44 | 0 | |
p02623 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long
#define fl(i, n) for (i = 0; i < n; i++)
#define fld(i, a, b) for (i = a; i > b; i--)
#define fli(i, a, n) for (i = a; i < n; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define mod 998244353
#define all(x) x.begin(), x.end()
#define speedup ios_base::sync_with_stdio(false), cin.tie(0)
using namespace std;
ll power(ll x, ll y) {
ll out = 1;
while (y > 0) {
if (y & 1)
out = (out * x) % mod;
y = y >> 1;
x = (x * x) % mod;
}
return out % mod;
}
ll inverse(ll a) { return power(a, mod - 2) % mod; }
ll pref_v1[2001];
ll pref_v2[2001];
bool check(ll mid, ll k, ll m, ll n) {
ll i = 0, j;
while (i <= mid && i <= n) {
if (mid - i <= m) {
j = mid - i;
if (pref_v1[i] + pref_v2[j] <= k)
return true;
}
i++;
}
return false;
}
void comp() {
ll i, j, k, n, m;
cin >> n >> m >> k;
vector<ll> v1(n + 1), v2(m + 1);
fl(i, n) { cin >> v1[i + 1]; }
fl(i, m) { cin >> v2[i + 1]; }
pref_v2[1] = v2[1];
pref_v1[1] = v1[1];
fli(i, 2, n + 1) pref_v1[i] = pref_v1[i - 1] + v1[i];
fli(i, 2, m + 1) pref_v2[i] = pref_v2[i - 1] + v2[i];
ll low = 0, high = (n + m), mid;
ll ans = 0;
while (low <= high) {
mid = (low + high) / 2;
if (check(mid, k, m, n)) {
low = mid + 1;
ans = mid;
} else {
high = mid - 1;
}
}
cout << ans << "\n";
}
int main() {
speedup;
ll i = 0, t;
t = 1;
// cin>>t;
while (t--) {
comp();
}
return 0;
} | #include <bits/stdc++.h>
#define ll long long
#define fl(i, n) for (i = 0; i < n; i++)
#define fld(i, a, b) for (i = a; i > b; i--)
#define fli(i, a, n) for (i = a; i < n; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define mod 998244353
#define all(x) x.begin(), x.end()
#define speedup ios_base::sync_with_stdio(false), cin.tie(0)
using namespace std;
ll power(ll x, ll y) {
ll out = 1;
while (y > 0) {
if (y & 1)
out = (out * x) % mod;
y = y >> 1;
x = (x * x) % mod;
}
return out % mod;
}
ll inverse(ll a) { return power(a, mod - 2) % mod; }
ll pref_v1[200001];
ll pref_v2[200001];
bool check(ll mid, ll k, ll m, ll n) {
ll i = 0, j;
while (i <= mid && i <= n) {
if (mid - i <= m) {
j = mid - i;
if (pref_v1[i] + pref_v2[j] <= k)
return true;
}
i++;
}
return false;
}
void comp() {
ll i, j, k, n, m;
cin >> n >> m >> k;
vector<ll> v1(n + 1), v2(m + 1);
fl(i, n) { cin >> v1[i + 1]; }
fl(i, m) { cin >> v2[i + 1]; }
pref_v2[1] = v2[1];
pref_v1[1] = v1[1];
fli(i, 2, n + 1) pref_v1[i] = pref_v1[i - 1] + v1[i];
fli(i, 2, m + 1) pref_v2[i] = pref_v2[i - 1] + v2[i];
ll low = 0, high = (n + m), mid;
ll ans = 0;
while (low <= high) {
mid = (low + high) / 2;
if (check(mid, k, m, n)) {
low = mid + 1;
ans = mid;
} else {
high = mid - 1;
}
}
cout << ans << "\n";
}
int main() {
speedup;
ll i = 0, t;
t = 1;
// cin>>t;
while (t--) {
comp();
}
return 0;
} | replace | 24 | 26 | 24 | 26 | 0 | |
p02623 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ld double
#define ll long long
#define pb emplace_back
#define mk make_pair
#define mod 1000000007
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define FIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define all(x) x.begin(), x.end()
ll power(ll a, ll b) {
ll res = 1;
a = a % mod;
while (b) {
if (b & 1)
res = (res * a) % mod;
a = (a * a) % mod;
b /= 2;
}
return res;
}
ll invmod(ll a) { return power(a, mod - 2); }
int main(void) {
FIO int t = 1;
// cin >> t;
while (t--) {
ll n, m, k;
cin >> n >> m >> k;
ll a[n + 1], b[n + 1];
a[0] = b[0] = 0;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= m; i++)
cin >> b[i];
for (int i = 0; i < n; i++)
a[i + 1] += a[i];
for (int i = 0; i < m; i++)
b[i + 1] += b[i];
int ans = 0, j = m;
for (int i = 0; i <= n; i++) {
if (a[i] > k)
break;
while (j >= 0 && b[j] > k - a[i])
j--;
ans = max(ans, i + j);
}
cout << ans << "\n";
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ld double
#define ll long long
#define pb emplace_back
#define mk make_pair
#define mod 1000000007
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define FIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define all(x) x.begin(), x.end()
ll power(ll a, ll b) {
ll res = 1;
a = a % mod;
while (b) {
if (b & 1)
res = (res * a) % mod;
a = (a * a) % mod;
b /= 2;
}
return res;
}
ll invmod(ll a) { return power(a, mod - 2); }
int main(void) {
FIO int t = 1;
// cin >> t;
while (t--) {
ll n, m, k;
cin >> n >> m >> k;
ll a[n + 1], b[m + 1];
a[0] = b[0] = 0;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= m; i++)
cin >> b[i];
for (int i = 0; i < n; i++)
a[i + 1] += a[i];
for (int i = 0; i < m; i++)
b[i + 1] += b[i];
int ans = 0, j = m;
for (int i = 0; i <= n; i++) {
if (a[i] > k)
break;
while (j >= 0 && b[j] > k - a[i])
j--;
ans = max(ans, i + j);
}
cout << ans << "\n";
}
return 0;
} | replace | 33 | 34 | 33 | 34 | 0 | |
p02623 | C++ | Time Limit Exceeded | #define _GLIBCXX_DEBUG
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define rep0(TMS) for (int CNT = 0; CNT < (int)(TMS); CNT++)
#define rep(CNT, GOAL) for (int CNT = 0; CNT < (int)(GOAL); CNT++)
#define rep2(CNT, START, GOAL) \
for (int CNT = (int)(START); CNT < (int)(GOAL); CNT++)
#define rep3(CNT, START, GOAL) \
for (int CNT = (int)(START); CNT > (int)(GOAL); CNT--)
#define all(CONT) begin(CONT), end(CONT)
#define itrep(ITR, CONT) for (auto ITR = begin(CONT); ITR != end(CONT); ITR++)
#define itrep1(ITR, CONT) \
for (auto ITR = next(begin(CONT)); ITR != end(CONT); ITR++)
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;
}
void prec(const int &DIG) {
cerr << fixed << setprecision(DIG);
cout << fixed << setprecision(DIG);
}
template <typename T> void CERR(const T &ELEM) { cerr << ELEM; }
template <typename T, typename... Ts>
void CERR(const T &FIRST, const Ts &...REST) {
CERR(FIRST);
cerr << ", ";
CERR(REST...);
}
template <typename T1, typename T2> void CERR(const pair<T1, T2> &PAIR) {
cerr << "(";
CERR(PAIR.first);
cerr << ", ";
CERR(PAIR.second);
cerr << ")";
}
template <typename T> void CERR(const vector<T> &VEC) {
cerr << "{ ";
itrep(ITR, VEC) {
CERR(*ITR);
cerr << ", ";
}
cerr << "}";
}
template <typename T> void CERR1(const vector<T> &VEC) {
cerr << "{ ";
itrep1(ITR, VEC) {
CERR(*ITR);
cerr << ", ";
}
cerr << "}";
}
template <typename T> void CERR(const set<T> &SET) {
cerr << "{ ";
itrep(ITR, SET) {
CERR(*ITR);
cerr << ", ";
}
cerr << "}";
}
template <typename T> void CERR(const multiset<T> &MULTISET) {
cerr << "{ ";
itrep(ITR, MULTISET) {
CERR(*ITR);
cerr << ", ";
}
cerr << "}";
}
template <typename T1, typename T2> void CERR(const map<T1, T2> &MAP) {
cerr << "{ ";
itrep(ITR, MAP) {
CERR(*ITR);
cerr << ", ";
}
cerr << "}";
}
#define db(OBJ) \
cerr << #OBJ << ": "; \
CERR(OBJ); \
cerr << ", "
#define dbl(OBJ) \
cerr << #OBJ << ": "; \
CERR(OBJ); \
cerr << "\n"
#define db1(OBJ) \
cerr << #OBJ << ": "; \
CERR1(OBJ); \
cerr << "\n"
#define dbs(...) \
cerr << "(" << #__VA_ARGS__ << "): ("; \
CERR(__VA_ARGS__); \
cerr << ")\n"
#define dbvv(VV) \
cerr << #VV << ": {\n"; \
rep(CNT, VV.size()) { \
cerr << #VV << "[" << CNT << "]: "; \
CERR(VV[CNT]); \
cerr << ",\n"; \
} \
cerr << "}\n"
#define db01(VV) \
cerr << #VV << ": {\n"; \
rep(CNT, VV.size()) { \
cerr << #VV << "[" << CNT << "]: "; \
CERR1(VV[CNT]); \
cerr << ",\n"; \
} \
cerr << "}\n"
#define db10(VV) \
cerr << #VV << ": {\n"; \
rep2(CNT, 1, VV.size()) { \
cerr << #VV << "[" << CNT << "]: "; \
CERR(VV[CNT]); \
cerr << ",\n"; \
} \
cerr << "}\n"
#define db11(VV) \
cerr << #VV << ": {\n"; \
rep2(CNT, 1, VV.size()) { \
cerr << #VV << "[" << CNT << "]: "; \
CERR1(VV[CNT]); \
cerr << ",\n"; \
} \
cerr << "}\n"
#define YN(FLG) cout << (FLG ? "YES" : "NO") << "\n"
#define Yn(FLG) cout << (FLG ? "Yes" : "No") << "\n"
#define yn(FLG) cout << (FLG ? "yes" : "no") << "\n"
// const ll INF = 1'000'000'000'000'000'007;
const int INF = 1'000'000'007;
const ll MOD = 1'000'000'007; // 998'244'353;
int main() {
ll N, M, K;
cin >> N >> M >> K;
// dbs(N, M, K);
vector<ll> A(N);
rep(i, N) cin >> A[i];
vector<ll> B(M);
rep(i, M) cin >> B[i];
// dbl(A); dbl(B);
// Aの[0,i)の累積和,Bの[0,i)の累積和
vector<ll> accA(N + 1), accB(M + 1);
rep(i, N) accA[i + 1] = accA[i] + A[i];
rep(i, M) accB[i + 1] = accB[i] + B[i];
// dbl(A); dbl(accA); dbl(B); dbl(accB);
// 机Aの[0,i)(i冊)を読んだとき,Bを何冊[0,j)(j冊)読めるかを考える
int ans = 0;
rep(i, N + 1) {
if (K - accA[i] < 0)
break;
int j = upper_bound(all(accB), K - accA[i]) - begin(accB) - 1;
// dbl(i); dbs(accA[i], K - accA[i]); dbl(j); dbl(i + j);
chmax(ans, i + j);
}
cout << ans << endl;
} | // #define _GLIBCXX_DEBUG
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define rep0(TMS) for (int CNT = 0; CNT < (int)(TMS); CNT++)
#define rep(CNT, GOAL) for (int CNT = 0; CNT < (int)(GOAL); CNT++)
#define rep2(CNT, START, GOAL) \
for (int CNT = (int)(START); CNT < (int)(GOAL); CNT++)
#define rep3(CNT, START, GOAL) \
for (int CNT = (int)(START); CNT > (int)(GOAL); CNT--)
#define all(CONT) begin(CONT), end(CONT)
#define itrep(ITR, CONT) for (auto ITR = begin(CONT); ITR != end(CONT); ITR++)
#define itrep1(ITR, CONT) \
for (auto ITR = next(begin(CONT)); ITR != end(CONT); ITR++)
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;
}
void prec(const int &DIG) {
cerr << fixed << setprecision(DIG);
cout << fixed << setprecision(DIG);
}
template <typename T> void CERR(const T &ELEM) { cerr << ELEM; }
template <typename T, typename... Ts>
void CERR(const T &FIRST, const Ts &...REST) {
CERR(FIRST);
cerr << ", ";
CERR(REST...);
}
template <typename T1, typename T2> void CERR(const pair<T1, T2> &PAIR) {
cerr << "(";
CERR(PAIR.first);
cerr << ", ";
CERR(PAIR.second);
cerr << ")";
}
template <typename T> void CERR(const vector<T> &VEC) {
cerr << "{ ";
itrep(ITR, VEC) {
CERR(*ITR);
cerr << ", ";
}
cerr << "}";
}
template <typename T> void CERR1(const vector<T> &VEC) {
cerr << "{ ";
itrep1(ITR, VEC) {
CERR(*ITR);
cerr << ", ";
}
cerr << "}";
}
template <typename T> void CERR(const set<T> &SET) {
cerr << "{ ";
itrep(ITR, SET) {
CERR(*ITR);
cerr << ", ";
}
cerr << "}";
}
template <typename T> void CERR(const multiset<T> &MULTISET) {
cerr << "{ ";
itrep(ITR, MULTISET) {
CERR(*ITR);
cerr << ", ";
}
cerr << "}";
}
template <typename T1, typename T2> void CERR(const map<T1, T2> &MAP) {
cerr << "{ ";
itrep(ITR, MAP) {
CERR(*ITR);
cerr << ", ";
}
cerr << "}";
}
#define db(OBJ) \
cerr << #OBJ << ": "; \
CERR(OBJ); \
cerr << ", "
#define dbl(OBJ) \
cerr << #OBJ << ": "; \
CERR(OBJ); \
cerr << "\n"
#define db1(OBJ) \
cerr << #OBJ << ": "; \
CERR1(OBJ); \
cerr << "\n"
#define dbs(...) \
cerr << "(" << #__VA_ARGS__ << "): ("; \
CERR(__VA_ARGS__); \
cerr << ")\n"
#define dbvv(VV) \
cerr << #VV << ": {\n"; \
rep(CNT, VV.size()) { \
cerr << #VV << "[" << CNT << "]: "; \
CERR(VV[CNT]); \
cerr << ",\n"; \
} \
cerr << "}\n"
#define db01(VV) \
cerr << #VV << ": {\n"; \
rep(CNT, VV.size()) { \
cerr << #VV << "[" << CNT << "]: "; \
CERR1(VV[CNT]); \
cerr << ",\n"; \
} \
cerr << "}\n"
#define db10(VV) \
cerr << #VV << ": {\n"; \
rep2(CNT, 1, VV.size()) { \
cerr << #VV << "[" << CNT << "]: "; \
CERR(VV[CNT]); \
cerr << ",\n"; \
} \
cerr << "}\n"
#define db11(VV) \
cerr << #VV << ": {\n"; \
rep2(CNT, 1, VV.size()) { \
cerr << #VV << "[" << CNT << "]: "; \
CERR1(VV[CNT]); \
cerr << ",\n"; \
} \
cerr << "}\n"
#define YN(FLG) cout << (FLG ? "YES" : "NO") << "\n"
#define Yn(FLG) cout << (FLG ? "Yes" : "No") << "\n"
#define yn(FLG) cout << (FLG ? "yes" : "no") << "\n"
// const ll INF = 1'000'000'000'000'000'007;
const int INF = 1'000'000'007;
const ll MOD = 1'000'000'007; // 998'244'353;
int main() {
ll N, M, K;
cin >> N >> M >> K;
// dbs(N, M, K);
vector<ll> A(N);
rep(i, N) cin >> A[i];
vector<ll> B(M);
rep(i, M) cin >> B[i];
// dbl(A); dbl(B);
// Aの[0,i)の累積和,Bの[0,i)の累積和
vector<ll> accA(N + 1), accB(M + 1);
rep(i, N) accA[i + 1] = accA[i] + A[i];
rep(i, M) accB[i + 1] = accB[i] + B[i];
// dbl(A); dbl(accA); dbl(B); dbl(accB);
// 机Aの[0,i)(i冊)を読んだとき,Bを何冊[0,j)(j冊)読めるかを考える
int ans = 0;
rep(i, N + 1) {
if (K - accA[i] < 0)
break;
int j = upper_bound(all(accB), K - accA[i]) - begin(accB) - 1;
// dbl(i); dbs(accA[i], K - accA[i]); dbl(j); dbl(i + j);
chmax(ans, i + j);
}
cout << ans << endl;
} | replace | 0 | 1 | 0 | 1 | TLE | |
p02623 | C++ | Runtime Error | #include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
#define MOD 1000000007LL
int m, n;
ll k;
vector<ll> a, b;
int main() {
int bkmax = 0;
int amax, bmax;
int i, j;
cin >> n >> m >> k;
a.resize(n + 1);
b.resize(m + 1);
a[0] = 0;
for (i = 1; i <= n; i++) {
cin >> a[i];
a[i] += a[i - 1];
// printf("a[%d] = %lld\n", i, a[i]);
if (a[i - 1] <= k && a[i] > k)
amax = i - 1;
}
if (a[n] <= k)
amax = n;
// printf("amax = %d\n", amax);
b[0] = 0;
for (i = 1; i <= m; i++) {
cin >> b[i];
b[i] += b[i - 1];
// printf("b[%d] = %lld\n", i, b[i]);
if (b[i - 1] <= k && b[i] > k)
bmax = i - 1;
}
if (b[m] <= k)
bmax = m;
// printf("bmax = %d\n", bmax);
i = amax;
for (j = 0; j <= bmax; j++) {
if (a[i] + b[j] > k) {
break;
}
}
j--;
bkmax = max(bkmax, i + j);
// printf("bkmax = %d, a[%d]+b[%d] = %lld\n", bkmax, i, j, a[i]+b[j]);
for (i--; i >= 0; i--) {
while (a[i] + b[j] <= k) {
bkmax = max(bkmax, i + j);
// printf("bkmax = %d, a[%d]+b[%d] = %lld\n", bkmax, i, j, a[i]+b[j]);
j++;
}
}
cout << bkmax << endl;
return 0;
}
| #include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
#define MOD 1000000007LL
int m, n;
ll k;
vector<ll> a, b;
int main() {
int bkmax = 0;
int amax, bmax;
int i, j;
cin >> n >> m >> k;
a.resize(n + 1);
b.resize(m + 1);
a[0] = 0;
for (i = 1; i <= n; i++) {
cin >> a[i];
a[i] += a[i - 1];
// printf("a[%d] = %lld\n", i, a[i]);
if (a[i - 1] <= k && a[i] > k)
amax = i - 1;
}
if (a[n] <= k)
amax = n;
// printf("amax = %d\n", amax);
b[0] = 0;
for (i = 1; i <= m; i++) {
cin >> b[i];
b[i] += b[i - 1];
// printf("b[%d] = %lld\n", i, b[i]);
if (b[i - 1] <= k && b[i] > k)
bmax = i - 1;
}
if (b[m] <= k)
bmax = m;
// printf("bmax = %d\n", bmax);
i = amax;
for (j = 0; j <= bmax; j++) {
if (a[i] + b[j] > k) {
break;
}
}
j--;
bkmax = max(bkmax, i + j);
// printf("bkmax = %d, a[%d]+b[%d] = %lld\n", bkmax, i, j, a[i]+b[j]);
for (i--; i >= 0 && j <= m; i--) {
while (a[i] + b[j] <= k && j <= m) {
bkmax = max(bkmax, i + j);
// printf("bkmax = %d, a[%d]+b[%d] = %lld\n", bkmax, i, j, a[i]+b[j]);
j++;
}
}
cout << bkmax << endl;
return 0;
}
| replace | 60 | 62 | 60 | 62 | 0 | |
p02623 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
ll n, m, k, a[200001], b[200001], A, ans, L;
vector<ll> v, u;
int main(void) {
cin >> n >> m >> k;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < m; i++)
cin >> b[i];
v.push_back(0);
u.push_back(0);
for (int i = 0; i < n; i++) {
v.push_back(v[i] + a[i]);
}
for (int i = 0; i < m; i++) {
u.push_back(v[i] + b[i]);
}
for (ll i = 0LL; i <= n; i++) {
A = k - v[i];
// cout<<A<<endl;
if (A < 0)
continue;
L = upper_bound(u.begin(), u.end(), A) - u.begin();
// cout<<i<<" "<<L<<endl;
ans = max(ans, i + L - 1);
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
ll n, m, k, a[200001], b[200001], A, ans, L;
vector<ll> v, u;
int main(void) {
cin >> n >> m >> k;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < m; i++)
cin >> b[i];
v.push_back(0);
u.push_back(0);
for (int i = 0; i < n; i++) {
v.push_back(v[i] + a[i]);
}
for (int i = 0; i < m; i++) {
u.push_back(u[i] + b[i]);
}
for (ll i = 0LL; i <= n; i++) {
A = k - v[i];
// cout<<A<<endl;
if (A < 0)
continue;
L = upper_bound(u.begin(), u.end(), A) - u.begin();
// cout<<i<<" "<<L<<endl;
ans = max(ans, i + L - 1);
}
cout << ans << endl;
}
| replace | 18 | 19 | 18 | 19 | 0 | |
p02623 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
int read() {
int x = 0, f = 1;
char ch = ' ';
while (!isdigit(ch)) {
ch = getchar();
if (ch == '-')
f = -1;
}
while (isdigit(ch))
x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
return x * f;
}
ll a[100005], b[100005], n, m, k, ans;
int main() {
cin >> n >> m >> k;
for (int i = 1; i <= n; i++)
a[i] = a[i - 1] + read();
for (int i = 1; i <= m; i++)
b[i] = b[i - 1] + read();
ll now = 0;
while (b[now] <= k && now <= m)
now++;
now--;
ans = now;
for (int i = 1; i <= n; i++) {
if (a[i] > k)
break;
while (a[i] + b[now] > k)
now--;
ans = max(ans, i + now);
}
cout << ans;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
int read() {
int x = 0, f = 1;
char ch = ' ';
while (!isdigit(ch)) {
ch = getchar();
if (ch == '-')
f = -1;
}
while (isdigit(ch))
x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
return x * f;
}
ll a[200005], b[200005], n, m, k, ans;
int main() {
cin >> n >> m >> k;
for (int i = 1; i <= n; i++)
a[i] = a[i - 1] + read();
for (int i = 1; i <= m; i++)
b[i] = b[i - 1] + read();
ll now = 0;
while (b[now] <= k && now <= m)
now++;
now--;
ans = now;
for (int i = 1; i <= n; i++) {
if (a[i] > k)
break;
while (a[i] + b[now] > k)
now--;
ans = max(ans, i + now);
}
cout << ans;
}
| replace | 15 | 16 | 15 | 16 | 0 | |
p02623 | C++ | Runtime Error | #include <iostream>
#include <vector>
using namespace std;
int main() {
long long N, M, K;
cin >> N >> M >> K;
vector<long long> A(N), AS(N + 1, 0), B(M), BS(M + 1, 0);
for (int i = 0; i < N; ++i) {
cin >> A[i];
AS[i + 1] = AS[i] + A[i];
}
for (int i = 0; i < M; ++i) {
cin >> B[i];
BS[i + 1] = BS[i] + B[i];
}
int an = 0, bn = 0, ans = 0;
for (an = N; an >= 0; --an) {
while (BS[bn + 1] <= K - AS[an])
++bn;
if (K >= AS[an] + BS[bn])
ans = max(an + bn, ans);
}
cout << ans << endl;
} | #include <iostream>
#include <vector>
using namespace std;
int main() {
long long N, M, K;
cin >> N >> M >> K;
vector<long long> A(N), AS(N + 1, 0), B(M), BS(M + 1, 0);
for (int i = 0; i < N; ++i) {
cin >> A[i];
AS[i + 1] = AS[i] + A[i];
}
for (int i = 0; i < M; ++i) {
cin >> B[i];
BS[i + 1] = BS[i] + B[i];
}
int an = 0, bn = 0, ans = 0;
for (an = N; an >= 0; --an) {
while (bn + 1 <= M && BS[bn + 1] <= K - AS[an])
++bn;
if (K >= AS[an] + BS[bn])
ans = max(an + bn, ans);
}
cout << ans << endl;
} | replace | 22 | 23 | 22 | 23 | 0 | |
p02623 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll
using namespace std;
long long A[100002], B[100002];
int main() {
long long n, m, ms;
cin >> n >> m >> ms;
for (int A_i = 0; A_i < n; A_i++) {
cin >> A[A_i];
}
for (int B_i = 0; B_i < m; B_i++) {
cin >> B[B_i];
}
long long sum = 0;
long long x = 0, y = 0;
while (x < n && sum + A[x] <= ms) {
sum += A[x++];
}
long long 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;
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define ll
using namespace std;
long long A[200000], B[200000];
int main() {
long long n, m, ms;
cin >> n >> m >> ms;
for (int A_i = 0; A_i < n; A_i++) {
cin >> A[A_i];
}
for (int B_i = 0; B_i < m; B_i++) {
cin >> B[B_i];
}
long long sum = 0;
long long x = 0, y = 0;
while (x < n && sum + A[x] <= ms) {
sum += A[x++];
}
long long 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;
}
}
cout << ans << endl;
return 0;
} | replace | 4 | 5 | 4 | 5 | 0 | |
p02623 | Python | Runtime Error | # f = open('test.txt')
f = open("b11.txt")
n, m, k = map(int, f.readline().split())
a = list(map(int, f.readline().split()))
b = list(map(int, f.readline().split()))
a_sum = [0]
b_sum = [0]
cnt = 0
best_b = m
confirm = ()
for i in a:
a_sum.append(i + a_sum[-1])
for i in b:
b_sum.append(i + b_sum[-1])
for a_idx in range(n + 1):
if a_sum[a_idx] > k:
break
for b_idx in reversed(range(best_b + 1)):
if b_sum[b_idx] + a_sum[a_idx] <= k:
# if cnt < a_idx + b_idx:
cnt = max(cnt, a_idx + b_idx)
best_b = b_idx
break
print(cnt)
| n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a_sum = [0]
b_sum = [0]
cnt = 0
best_b = m
confirm = ()
for i in a:
a_sum.append(i + a_sum[-1])
for i in b:
b_sum.append(i + b_sum[-1])
for a_idx in range(n + 1):
if a_sum[a_idx] > k:
break
for b_idx in reversed(range(best_b + 1)):
if b_sum[b_idx] + a_sum[a_idx] <= k:
# if cnt < a_idx + b_idx:
cnt = max(cnt, a_idx + b_idx)
best_b = b_idx
break
print(cnt)
| replace | 0 | 5 | 0 | 3 | FileNotFoundError: [Errno 2] No such file or directory: 'b11.txt' | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02623/Python/s627350326.py", line 2, in <module>
f = open('b11.txt')
FileNotFoundError: [Errno 2] No such file or directory: 'b11.txt'
|
p02623 | Python | Runtime Error | n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a = [0]
b = [0]
for i in range(n):
a.append(a[i] + A[i])
for i in range(m):
b.append(b[i] + B[i])
ans = 0
j = m
for i in range(n + 1):
if a[0] > k:
break
while b[j] > k - a[i]:
j -= 1
ans = max(ans, i + j)
print(ans)
| n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a = [0]
b = [0]
for i in range(n):
a.append(a[i] + A[i])
for i in range(m):
b.append(b[i] + B[i])
ans = 0
j = m
for i in range(n + 1):
if a[i] > k:
break
while b[j] > k - a[i]:
j -= 1
ans = max(ans, i + j)
print(ans)
| replace | 12 | 13 | 12 | 13 | IndexError: list index out of range | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02623/Python/s808740023.py", line 15, in <module>
while b[j] > k - a[i]:
IndexError: list index out of range
|
p02623 | Python | Runtime Error | # -*- coding: utf-8 -*-
# 標準入力を取得
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
# 求解処理
a, b = [0], [0]
for i in range(N):
a.append(a[i] + A[i])
for j in range(M):
b.append(b[i] + B[i])
ans, j = 0, M
for i in range(N + 1):
if a[i] > K:
break
while b[j] > K - a[i]:
j -= 1
ans = max(ans, i + j)
# 結果出力
print(ans)
| # -*- coding: utf-8 -*-
# 標準入力を取得
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
# 求解処理
a, b = [0], [0]
for i in range(N):
a.append(a[i] + A[i])
for j in range(M):
b.append(b[j] + B[j])
ans, j = 0, M
for i in range(N + 1):
if a[i] > K:
break
while b[j] > K - a[i]:
j -= 1
ans = max(ans, i + j)
# 結果出力
print(ans)
| replace | 11 | 12 | 11 | 12 | IndexError: list index out of range | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02623/Python/s326586538.py", line 12, in <module>
b.append(b[i] + B[i])
IndexError: list index out of range
|
p02623 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long
#define endl "\n"
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define mi map<int, int>
#define pi pair<int, int>
#define Fori(i, a, b) for (int i = a; i < b; i++)
#define Ford(i, a, b) for (int i = a; i >= b; i--)
#define pb push_back
#define mp make_pair
#define read(a, n) \
for (int i = 0; i < n; i++) \
cin >> a[i];
#define print(x) cout << "X: == " << x << endl;
#define printMap(a) \
for (auto it = a.begin(); it != a.end(); it++) { \
cout << it->first << " " << it->second << endl; \
}
#define printVector(a) \
for (auto it = a.begin(); it != a.end(); it++) { \
cout << *it << endl; \
}
using namespace std;
int main() {
IOS ll n, m, k;
cin >> n >> m >> k;
vl a(n + 1), b(m + 1);
Fori(i, 1, n + 1) {
ll x;
cin >> x;
a[i] = a[i - 1] + x;
}
Fori(i, 1, m + 1) {
ll x;
cin >> x;
b[i] = b[i - 1] + x;
}
ll total = 0;
Fori(i, 0, n + 1) {
if (a[i] > k) {
continue;
}
ll other = k - a[i];
ll index = lower_bound(b.begin(), b.end(), other) - b.begin();
if (index == n + 1 || a[index] > other) {
index--;
}
total = max(total, i + index);
}
cout << total << endl;
return 0;
} | #include <bits/stdc++.h>
#define ll long long
#define endl "\n"
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define mi map<int, int>
#define pi pair<int, int>
#define Fori(i, a, b) for (int i = a; i < b; i++)
#define Ford(i, a, b) for (int i = a; i >= b; i--)
#define pb push_back
#define mp make_pair
#define read(a, n) \
for (int i = 0; i < n; i++) \
cin >> a[i];
#define print(x) cout << "X: == " << x << endl;
#define printMap(a) \
for (auto it = a.begin(); it != a.end(); it++) { \
cout << it->first << " " << it->second << endl; \
}
#define printVector(a) \
for (auto it = a.begin(); it != a.end(); it++) { \
cout << *it << endl; \
}
using namespace std;
int main() {
IOS ll n, m, k;
cin >> n >> m >> k;
vl a(n + 1), b(m + 1);
Fori(i, 1, n + 1) {
ll x;
cin >> x;
a[i] = a[i - 1] + x;
}
Fori(i, 1, m + 1) {
ll x;
cin >> x;
b[i] = b[i - 1] + x;
}
ll total = 0;
Fori(i, 0, n + 1) {
if (a[i] > k) {
continue;
}
ll other = k - a[i];
ll index = lower_bound(b.begin(), b.end(), other) - b.begin();
if (index == m + 1 || b[index] > other) {
index--;
}
total = max(total, i + index);
}
cout << total << endl;
return 0;
} | replace | 56 | 57 | 56 | 57 | 0 | |
p02623 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
int main() {
ll N, M, K;
cin >> N >> M >> K;
vector<ll> A(N), B(M);
for (ll i = 0; i < N; i++)
cin >> A.at(i);
for (ll i = 0; i < M; i++)
cin >> B.at(i);
ll ans = 0, i = 0, j = 0, T = K;
while (i < M) {
if (T - B.at(i) >= 0) {
T -= B.at(i);
i++;
ans++;
} else {
i--;
break;
}
}
ll tmp = ans;
while (j < N) {
// cout << tmp << ": i = " << i << ", j = " << j << ", T = " << T << endl;
if (T - A.at(j) >= 0) {
T -= A.at(j);
j++;
tmp++;
} else {
if (i >= 0) {
T += B.at(i);
i--;
tmp--;
} else
break;
}
ans = max(ans, tmp);
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
int main() {
ll N, M, K;
cin >> N >> M >> K;
vector<ll> A(N), B(M);
for (ll i = 0; i < N; i++)
cin >> A.at(i);
for (ll i = 0; i < M; i++)
cin >> B.at(i);
ll ans = 0, i = 0, j = 0, T = K;
while (true) {
if (i >= M) {
i--;
break;
}
if (T - B.at(i) >= 0) {
T -= B.at(i);
i++;
ans++;
} else {
i--;
break;
}
}
ll tmp = ans;
while (j < N) {
// cout << tmp << ": i = " << i << ", j = " << j << ", T = " << T << endl;
if (T - A.at(j) >= 0) {
T -= A.at(j);
j++;
tmp++;
} else {
if (i >= 0) {
T += B.at(i);
i--;
tmp--;
} else
break;
}
ans = max(ans, tmp);
}
cout << ans << endl;
return 0;
}
| replace | 16 | 17 | 16 | 21 | 0 | |
p02623 | C++ | Runtime Error | #define DEBUG 1
#include <bits/stdc++.h>
using namespace std;
typedef char s8;
typedef unsigned char u8;
typedef short s16;
typedef unsigned short u16;
typedef int s32;
typedef unsigned int u32;
typedef long int s64;
typedef unsigned long int u64;
typedef float f32;
typedef double f64;
#define rep(_i, _n) for (int _i = 0; _i < (int)(_n); _i++)
#if DEBUG
#define PHERE() \
{ cerr << "L" << setw(3) << __LINE__ << ": PHERE" << clock() << endl; }
#define PVAL(_var) \
{ cerr << "L" << setw(3) << __LINE__ << ":" << #_var "=" << (_var) << endl; }
#else
#define PHERE()
#define PVAL(_var)
#endif
int main() {
//////// 入力 ////////
s64 N, M, K;
cin >> N >> M >> K;
s64 ASum[N];
s64 AMax = -1;
rep(i, N) {
cin >> ASum[i];
if (i > 0) {
ASum[i] += ASum[i - 1];
}
if (AMax < 0) {
if (ASum[i] > K) {
AMax = i;
}
}
}
if (AMax < 0) {
AMax = N;
}
s64 BSum[N];
s64 BMax = -1;
rep(i, M) {
cin >> BSum[i];
if (i > 0) {
BSum[i] += BSum[i - 1];
}
if (BMax < 0) {
if (BSum[i] > K) {
BMax = i;
}
}
}
if (BMax < 0) {
BMax = M;
}
/////////////////////
s64 outMax = max(AMax, BMax);
// DEL for( s64 i = AMax-1; i >= 0; --i ) {
for (s64 i = -1; i < AMax; ++i) {
s64 posMin = 0;
s64 posMax = BMax;
s64 find = -1;
s64 curA = 0;
if (i >= 0) {
curA = ASum[i];
}
while (1) {
s64 bPos = (posMin + posMax) / 2;
if (curA + BSum[bPos] <= K) {
posMin = bPos;
} else {
posMax = bPos;
}
if (posMax - posMin <= 1) {
if (curA + BSum[posMin] <= K) {
find = posMin;
}
break;
}
}
if (find >= 0) {
if (i + find + 2 > outMax) {
outMax = i + find + 2;
}
}
#if 0
for( s64 j = max(0,outMax - i - 1); j < BMax; ++j ) {
if( ASum[i] + BSum[j] <= K ) {
outMax = i+j+2;
}
}
#endif
}
//////// 出力 ////////
cout << outMax;
/////////////////////
return 0;
}
#if 0
#endif
| #define DEBUG 1
#include <bits/stdc++.h>
using namespace std;
typedef char s8;
typedef unsigned char u8;
typedef short s16;
typedef unsigned short u16;
typedef int s32;
typedef unsigned int u32;
typedef long int s64;
typedef unsigned long int u64;
typedef float f32;
typedef double f64;
#define rep(_i, _n) for (int _i = 0; _i < (int)(_n); _i++)
#if DEBUG
#define PHERE() \
{ cerr << "L" << setw(3) << __LINE__ << ": PHERE" << clock() << endl; }
#define PVAL(_var) \
{ cerr << "L" << setw(3) << __LINE__ << ":" << #_var "=" << (_var) << endl; }
#else
#define PHERE()
#define PVAL(_var)
#endif
int main() {
//////// 入力 ////////
s64 N, M, K;
cin >> N >> M >> K;
s64 ASum[N];
s64 AMax = -1;
rep(i, N) {
cin >> ASum[i];
if (i > 0) {
ASum[i] += ASum[i - 1];
}
if (AMax < 0) {
if (ASum[i] > K) {
AMax = i;
}
}
}
if (AMax < 0) {
AMax = N;
}
s64 BSum[M];
s64 BMax = -1;
rep(i, M) {
cin >> BSum[i];
if (i > 0) {
BSum[i] += BSum[i - 1];
}
if (BMax < 0) {
if (BSum[i] > K) {
BMax = i;
}
}
}
if (BMax < 0) {
BMax = M;
}
/////////////////////
s64 outMax = max(AMax, BMax);
// DEL for( s64 i = AMax-1; i >= 0; --i ) {
for (s64 i = -1; i < AMax; ++i) {
s64 posMin = 0;
s64 posMax = BMax;
s64 find = -1;
s64 curA = 0;
if (i >= 0) {
curA = ASum[i];
}
while (1) {
s64 bPos = (posMin + posMax) / 2;
if (curA + BSum[bPos] <= K) {
posMin = bPos;
} else {
posMax = bPos;
}
if (posMax - posMin <= 1) {
if (curA + BSum[posMin] <= K) {
find = posMin;
}
break;
}
}
if (find >= 0) {
if (i + find + 2 > outMax) {
outMax = i + find + 2;
}
}
#if 0
for( s64 j = max(0,outMax - i - 1); j < BMax; ++j ) {
if( ASum[i] + BSum[j] <= K ) {
outMax = i+j+2;
}
}
#endif
}
//////// 出力 ////////
cout << outMax;
/////////////////////
return 0;
}
#if 0
#endif
| replace | 45 | 46 | 45 | 46 | 0 | |
p02623 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
#define rep(i, n) for (int i = 0; i < n; ++i)
typedef long long int ll;
typedef unsigned long long ull;
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
typedef pair<ll, ll> P;
int main() {
int n, m;
ll k;
cin >> n >> m >> k;
vector<ll> a(n + 1), b(m + 1);
int ans = 0, N = 0, M = 0;
a[0] = 0;
b[0] = 0;
rep(i, n) {
cin >> a[i + 1];
a[i + 1] += a[i];
}
rep(i, m) {
cin >> b[i + 1];
b[i + 1] += b[i];
}
int o = m;
for (int i = 0; i <= n; i++) {
while (a[o] + b[i] > k && o >= 0) {
o--;
}
// cout<<ans<<endl;
if (o >= 0)
ans = max(ans, i + o);
else
break;
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
#define rep(i, n) for (int i = 0; i < n; ++i)
typedef long long int ll;
typedef unsigned long long ull;
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
typedef pair<ll, ll> P;
int main() {
int n, m;
ll k;
cin >> n >> m >> k;
vector<ll> a(n + 1), b(m + 1);
int ans = 0, N = 0, M = 0;
a[0] = 0;
b[0] = 0;
rep(i, n) {
cin >> a[i + 1];
a[i + 1] += a[i];
}
rep(i, m) {
cin >> b[i + 1];
b[i + 1] += b[i];
}
int o = m;
for (int i = 0; i <= n; i++) {
while (a[i] + b[o] > k && o >= 0) {
o--;
}
// cout<<ans<<endl;
if (o >= 0)
ans = max(ans, i + o);
else
break;
}
cout << ans << endl;
return 0;
}
| replace | 40 | 41 | 40 | 41 | 0 | |
p02623 | Python | Runtime Error | N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A_sum = [0]
for i in range(N):
A_sum.append(A_sum[i] + A[i])
B_sum = [0]
for i in range(N):
B_sum.append(B_sum[i] + B[i])
B_sum.append(10**10)
res = 0
for i in range(len(A_sum)):
low = 0
high = len(B_sum)
while high - low > 1:
mid = (low + high) // 2
if A_sum[i] + B_sum[mid] <= K:
low = mid
else:
high = mid
if A_sum[i] + B_sum[low] <= K:
res = max(res, i + low)
print(res)
| N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A_sum = [0]
for i in range(N):
A_sum.append(A_sum[i] + A[i])
B_sum = [0]
for i in range(M):
B_sum.append(B_sum[i] + B[i])
B_sum.append(10**10)
res = 0
for i in range(len(A_sum)):
low = 0
high = len(B_sum)
while high - low > 1:
mid = (low + high) // 2
if A_sum[i] + B_sum[mid] <= K:
low = mid
else:
high = mid
if A_sum[i] + B_sum[low] <= K:
res = max(res, i + low)
print(res)
| replace | 8 | 9 | 8 | 9 | 0 | |
p02623 | Python | Runtime Error | N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
b_sum = 0
for i in range(M):
b_sum += B[i]
if b_sum > K:
b_sum -= B[i]
j = i - 1
break
result = j + 1
a_sum = 0
for i in range(N):
a_sum += A[i]
if a_sum > K:
break
while a_sum + b_sum > K:
b_sum -= B[j]
j -= 1
result = max(result, (i + 1) + (j + 1))
print(result)
| N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
b_sum = 0
for i in range(M):
b_sum += B[i]
if b_sum > K:
b_sum -= B[i]
j = i - 1
break
else:
j = M - 1
result = j + 1
a_sum = 0
for i in range(N):
a_sum += A[i]
if a_sum > K:
break
while a_sum + b_sum > K:
b_sum -= B[j]
j -= 1
result = max(result, (i + 1) + (j + 1))
print(result)
| insert | 11 | 11 | 11 | 13 | 0 | |
p02623 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
/*#ifdef TarekHasan
freopen("input.txt","r",stdin);
#endif // TarekHasan*/
int n, m, k;
cin >> n >> m >> k;
vector<long long int> first(n);
vector<long long int> second(m);
for (int i = 0; i < n; i++)
cin >> first[i];
for (int i = 0; i < m; i++)
cin >> second[i];
for (int i = 1; i < n; i++)
first[i] = first[i] + first[i - 1];
for (int i = 1; i < m; i++)
second[i] = second[i] + second[i - 1];
/*for(long long int x : first)
cout << x << " ";
cout << endl;
for(long long int x : second)
cout << x << " ";
cout << endl;*/
int answer = 0;
for (int i = 0; i < n; i++) {
if (first[i] > k)
break;
int t_a = i + 1;
int t_k = k - first[i];
int index = lower_bound(second.begin(), second.end(), t_k) - second.begin();
if (index == m || second[index] > t_k)
index -= 1;
t_a += (index + 1);
answer = max(answer, t_a);
}
for (int i = 0; i < m; i++) {
if (second[i] > k)
break;
int t_a = i + 1;
int t_k = k - second[i];
int index = lower_bound(first.begin(), first.end(), t_k) - first.begin();
if (index == m || second[index] > t_k)
index -= 1;
t_a += (index + 1);
answer = max(answer, t_a);
}
cout << answer << endl;
#ifdef TarekHasan
main();
#endif // TarekHasan
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
/*#ifdef TarekHasan
freopen("input.txt","r",stdin);
#endif // TarekHasan*/
int n, m, k;
cin >> n >> m >> k;
vector<long long int> first(n);
vector<long long int> second(m);
for (int i = 0; i < n; i++)
cin >> first[i];
for (int i = 0; i < m; i++)
cin >> second[i];
for (int i = 1; i < n; i++)
first[i] = first[i] + first[i - 1];
for (int i = 1; i < m; i++)
second[i] = second[i] + second[i - 1];
/*for(long long int x : first)
cout << x << " ";
cout << endl;
for(long long int x : second)
cout << x << " ";
cout << endl;*/
int answer = 0;
for (int i = 0; i < n; i++) {
if (first[i] > k)
break;
int t_a = i + 1;
int t_k = k - first[i];
int index = lower_bound(second.begin(), second.end(), t_k) - second.begin();
if (index == m || second[index] > t_k)
index -= 1;
t_a += (index + 1);
answer = max(answer, t_a);
}
for (int i = 0; i < m; i++) {
if (second[i] > k)
break;
int t_a = i + 1;
int t_k = k - second[i];
int index = lower_bound(first.begin(), first.end(), t_k) - first.begin();
if (index == n || first[index] > t_k)
index -= 1;
t_a += (index + 1);
answer = max(answer, t_a);
}
cout << answer << endl;
#ifdef TarekHasan
main();
#endif // TarekHasan
return 0;
}
| replace | 59 | 60 | 59 | 60 | 0 | |
p02623 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define M1 1000000007
#define M2 998244353
#define ww while
#define fl(i, a, b) for (ll i = a; i < b; i++)
#define bfl(i, a, b) for (ll i = b - 1; i >= a; i--)
#define f(i, n) for (ll i = 0; i < n; i++)
#define bf(i, n) for (ll i = n - 1; i >= 0; i--)
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
#define bn "\n"
//------------------------------------------------------------------------
// #define V(a) vector<a>
// #define vt() vector< tuple < ll ,ll ,ll > > ;
// #define vector< ll ,ll > pv;
// vector< pair <ll,ll> > vect;
//------------------------------------------------------------------------
ll modI(ll a, ll m);
ll gcd(ll a, ll b);
ll powM(ll x, ll y, ll m);
ll swap(ll a, ll b);
void swap(ll &a, ll &b) {
ll tp = a;
a = b;
b = tp;
}
ll gcd(ll x, ll y) {
if (x == 0)
return y;
return gcd(y % x, x);
}
ll powM(ll x, ll y, ll m) {
ll ans = 1, r = 1;
x %= m;
ww(r > 0 && r <= y) {
if (r & y) {
ans *= x;
ans %= m;
}
r <<= 1;
x *= x;
x %= m;
}
return ans;
}
ll modI(ll a, ll m) {
ll m0 = m, y = 0, x = 1;
if (m == 1)
return 0;
ww(a > 1) {
ll q = a / m;
ll t = m;
m = a % m;
a = t;
t = y;
y = x - q * y;
x = t;
}
if (x < 0)
x += m0;
return x;
}
//---------------------------------------------------------------------------
// variable = Expression1 ? Expression2 : Expression3
// max = (n1 > n2) ? n1 : n2;
// (n>m) ? cout<<"True"<<endl:cout<<"false"<<endl ;
// ---------------------------------------------------------------------------
// ll n;cin>>n;ll a[n];for(ll i=0;i<n;i++)cin>>a[i];
// for(ll i=0;i<n;i++)cout<<a[i];
// ll a,b;cin>>a>>b;
//----------------------------------------------------------------------------
// vector< tuple < ll ,ll ,ll > > tv;
// vector< ll ,ll > pv;
//----------------------------------------------------------------------------
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(0);
ll tt = 1;
// cin>>tt;
ww(tt--) {
ll n, m;
ll k;
cin >> n >> m >> k;
vector<ll> v1(n + 1);
vector<ll> v2(n + 1);
v1[0] = v2[0] = 0;
fl(i, 1, n + 1) {
cin >> v1[i];
v1[i] = v1[i] + v1[i - 1];
}
fl(i, 1, m + 1) {
cin >> v2[i];
v2[i] = v2[i] + v2[i - 1];
}
ll cnt = 0;
ll index1 = n, index2 = 0;
ww(index1 >= 0 && index2 <= m) {
ww(index1 >= 0 && v1[index1] + v2[index2] > k) index1--;
ww(index2 <= m && v1[index1] + v2[index2] <= k) index2++;
index2--;
cnt = max(cnt, index1 + index2);
index2++;
}
index1 = 0, index2 = m;
ww(index1 <= n && index2 >= 0) {
ww(index2 >= 0 && v1[index1] + v2[index2] > k) index2--;
ww(index1 <= n && v1[index1] + v2[index2] <= k) index1++;
index1--;
cnt = max(cnt, index1 + index2);
index1++;
}
// cout<<cnt;
p1(cnt);
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define M1 1000000007
#define M2 998244353
#define ww while
#define fl(i, a, b) for (ll i = a; i < b; i++)
#define bfl(i, a, b) for (ll i = b - 1; i >= a; i--)
#define f(i, n) for (ll i = 0; i < n; i++)
#define bf(i, n) for (ll i = n - 1; i >= 0; i--)
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
#define bn "\n"
//------------------------------------------------------------------------
// #define V(a) vector<a>
// #define vt() vector< tuple < ll ,ll ,ll > > ;
// #define vector< ll ,ll > pv;
// vector< pair <ll,ll> > vect;
//------------------------------------------------------------------------
ll modI(ll a, ll m);
ll gcd(ll a, ll b);
ll powM(ll x, ll y, ll m);
ll swap(ll a, ll b);
void swap(ll &a, ll &b) {
ll tp = a;
a = b;
b = tp;
}
ll gcd(ll x, ll y) {
if (x == 0)
return y;
return gcd(y % x, x);
}
ll powM(ll x, ll y, ll m) {
ll ans = 1, r = 1;
x %= m;
ww(r > 0 && r <= y) {
if (r & y) {
ans *= x;
ans %= m;
}
r <<= 1;
x *= x;
x %= m;
}
return ans;
}
ll modI(ll a, ll m) {
ll m0 = m, y = 0, x = 1;
if (m == 1)
return 0;
ww(a > 1) {
ll q = a / m;
ll t = m;
m = a % m;
a = t;
t = y;
y = x - q * y;
x = t;
}
if (x < 0)
x += m0;
return x;
}
//---------------------------------------------------------------------------
// variable = Expression1 ? Expression2 : Expression3
// max = (n1 > n2) ? n1 : n2;
// (n>m) ? cout<<"True"<<endl:cout<<"false"<<endl ;
// ---------------------------------------------------------------------------
// ll n;cin>>n;ll a[n];for(ll i=0;i<n;i++)cin>>a[i];
// for(ll i=0;i<n;i++)cout<<a[i];
// ll a,b;cin>>a>>b;
//----------------------------------------------------------------------------
// vector< tuple < ll ,ll ,ll > > tv;
// vector< ll ,ll > pv;
//----------------------------------------------------------------------------
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(0);
ll tt = 1;
// cin>>tt;
ww(tt--) {
ll n, m;
ll k;
cin >> n >> m >> k;
vector<ll> v1(n + 1);
vector<ll> v2(m + 1);
v1[0] = v2[0] = 0;
fl(i, 1, n + 1) {
cin >> v1[i];
v1[i] = v1[i] + v1[i - 1];
}
fl(i, 1, m + 1) {
cin >> v2[i];
v2[i] = v2[i] + v2[i - 1];
}
ll cnt = 0;
ll index1 = n, index2 = 0;
ww(index1 >= 0 && index2 <= m) {
ww(index1 >= 0 && v1[index1] + v2[index2] > k) index1--;
ww(index2 <= m && v1[index1] + v2[index2] <= k) index2++;
index2--;
cnt = max(cnt, index1 + index2);
index2++;
}
index1 = 0, index2 = m;
ww(index1 <= n && index2 >= 0) {
ww(index2 >= 0 && v1[index1] + v2[index2] > k) index2--;
ww(index1 <= n && v1[index1] + v2[index2] <= k) index1++;
index1--;
cnt = max(cnt, index1 + index2);
index1++;
}
// cout<<cnt;
p1(cnt);
}
return 0;
}
| replace | 114 | 115 | 114 | 115 | 0 | |
p02623 | C++ | Runtime Error | #ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
#define sim template <class c
#define int long long
#define ris return *this
#define dor > debug &operator<<
#define eni(x) \
sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<( \
c i) {
sim > struct rge {
c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i;
ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c &) { ris; }
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(0);
typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll N = 2e5 + 10;
const ll INF = 1e18 + 10;
signed main() {
fastio int n, m, k;
cin >> n >> m >> k;
vector<int> A(n + 1), B(n + 1);
for (int i = 0; i < n; i++) {
int x;
cin >> x;
A[i + 1] = A[i] + x;
}
for (int i = 0; i < m; i++) {
int x;
cin >> x;
B[i + 1] = B[i] + x;
}
int answer = 0;
for (int i = 0; i < n + 1; i++) {
if (A[i] <= k) {
int target = k - A[i];
int L = 0, R = m;
int ans = -1;
while (L <= R) {
int mid = L + (R - L) / 2;
if (B[mid] <= target) {
ans = mid;
L = mid + 1;
} else
R = mid - 1;
}
assert(ans != -1);
answer = max(answer, i + ans);
}
}
cout << answer << endl;
return 0;
} | #ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
#define sim template <class c
#define int long long
#define ris return *this
#define dor > debug &operator<<
#define eni(x) \
sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<( \
c i) {
sim > struct rge {
c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i;
ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c &) { ris; }
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(0);
typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll N = 2e5 + 10;
const ll INF = 1e18 + 10;
signed main() {
fastio int n, m, k;
cin >> n >> m >> k;
vector<int> A(n + 1), B(m + 1);
for (int i = 0; i < n; i++) {
int x;
cin >> x;
A[i + 1] = A[i] + x;
}
for (int i = 0; i < m; i++) {
int x;
cin >> x;
B[i + 1] = B[i] + x;
}
int answer = 0;
for (int i = 0; i < n + 1; i++) {
if (A[i] <= k) {
int target = k - A[i];
int L = 0, R = m;
int ans = -1;
while (L <= R) {
int mid = L + (R - L) / 2;
if (B[mid] <= target) {
ans = mid;
L = mid + 1;
} else
R = mid - 1;
}
assert(ans != -1);
answer = max(answer, i + ans);
}
}
cout << answer << endl;
return 0;
} | replace | 57 | 58 | 57 | 58 | 0 | |
p02623 | C++ | Runtime Error | #include <bits/stdc++.h>
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define endl '\n'
#define ll int64_t
#define ull uint64_t
using namespace std;
ull a[200001], b[200001];
int main() {
IOS;
ull n, m, k, i = 0, j = 0, time = 0, count = 0;
;
cin >> n >> m >> k;
for (ull x = 0; x < n; x += 1) {
cin >> a[x];
}
for (ull x = 0; x < m; x += 1) {
cin >> b[x];
}
for (ull x = 0; x < n + m; x += 1) {
ull temp = min(a[i], b[j]);
if (temp == a[i])
i += 1;
else
j += 1;
if (time + temp < k) {
time += temp;
count += 1;
} else {
break;
}
}
cout << count << endl;
return 0;
} | #include <bits/stdc++.h>
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define endl '\n'
#define ll int64_t
#define ull uint64_t
using namespace std;
ull a[200001], b[200001];
int main() {
IOS;
ull n, m, k, i = 0, j = 0, time = 0, count = 0;
;
cin >> n >> m >> k;
for (ull x = 0; x < n; x += 1) {
cin >> a[x];
}
for (ull x = 0; x < m; x += 1) {
cin >> b[x];
}
while (i < n && time + a[i] <= k) {
time += a[i++];
}
count = i;
while (j < m && i >= 0) {
time += b[j++];
while (time > k && i > 0) {
i--;
time -= a[i];
}
if (time <= k && i + j > count) {
count = i + j;
}
}
cout << count << endl;
return 0;
} | replace | 23 | 34 | 23 | 35 | 0 | |
p02623 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define dout cout
#define debug() if (true)
#define dvout(v) vout(v)
#else
#define dout \
if (false) \
cout
#define debug() if (false)
#define dvout(v) \
if (false) \
vout(v)
#endif
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define vout(v) \
for (auto &i : v) { \
cout << i << " "; \
} \
cout << "\n"; // 配列出力
#define vec(v, n) vector<int> v(n, 0);
#define vecll(v, n) vector<ll> v(n, 0);
#define vin(v) \
for (auto &i : v) \
cin >> i; // 配列入力
#define mod (int)(1e9 + 7)
typedef long long ll;
typedef unsigned long long ull;
#define next asdnext
#define prev asdprev
#define _n "\n"
#define _n2 "\n\n"
#define _t "\t"
vector<int> a = {1, 14, 32, 51, 51, 51, 243, 419, 750, 910};
void Main() {
int N, M, K;
cin >> N >> M >> K;
vec(A, N);
vec(B, M);
vin(A);
vin(B);
vec(sumA, N + 1);
vec(sumB, M + 1);
rep(i, N) { sumA[i + 1] = sumA[i] + A[i]; }
rep(i, N) { sumB[i + 1] = sumB[i] + A[i]; }
int ans = 0;
rep(i, N + 1) {
if (sumA[i] > K)
break;
ans = max(ans, i);
int l = -1, r = M + 1;
while (abs(l - r) > 1) {
int mid = (l + r) / 2;
if (sumB[mid] <= (K - sumA[i])) {
ans = max(ans, i + mid);
l = mid;
} else
r = mid;
}
}
cout << ans << endl;
}
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << std::fixed << std::setprecision(15);
Main();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define dout cout
#define debug() if (true)
#define dvout(v) vout(v)
#else
#define dout \
if (false) \
cout
#define debug() if (false)
#define dvout(v) \
if (false) \
vout(v)
#endif
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define vout(v) \
for (auto &i : v) { \
cout << i << " "; \
} \
cout << "\n"; // 配列出力
#define vec(v, n) vector<int> v(n, 0);
#define vecll(v, n) vector<ll> v(n, 0);
#define vin(v) \
for (auto &i : v) \
cin >> i; // 配列入力
#define mod (int)(1e9 + 7)
typedef long long ll;
typedef unsigned long long ull;
#define next asdnext
#define prev asdprev
#define _n "\n"
#define _n2 "\n\n"
#define _t "\t"
vector<int> a = {1, 14, 32, 51, 51, 51, 243, 419, 750, 910};
void Main() {
int N, M, K;
cin >> N >> M >> K;
vec(A, N);
vec(B, M);
vin(A);
vin(B);
vector<ll> sumA(N + 1, 0);
vector<ll> sumB(M + 1, 0);
rep(i, N) {
sumA[i + 1] = sumA[i] + A[i];
dout << "sumA" << i << ':' << sumA[i] << _n;
}
dout << "sumA" << N << ':' << sumA[N] << _n;
rep(i, M) {
sumB[i + 1] = sumB[i] + B[i];
dout << "sumB" << i << ':' << sumB[i] << _n;
}
dout << "sumB" << M << ':' << sumB[M] << _n;
int ans = 0;
rep(i, N + 1) {
if (sumA[i] > K)
break;
ans = max(ans, i);
int l = -1, r = M + 1;
while (abs(l - r) > 1) {
int mid = (l + r) / 2;
if (sumB[mid] <= (K - sumA[i])) {
ans = max(ans, i + mid);
l = mid;
} else
r = mid;
}
}
cout << ans << endl;
}
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << std::fixed << std::setprecision(15);
Main();
return 0;
}
| replace | 49 | 53 | 49 | 61 | 0 | |
p02623 | C++ | Runtime Error | #include <bits/stdc++.h>
#define pb push_back
#define f first
#define s second
#define mp make_pair
#define inlld(x) scanf("%lld", &x)
#define ind(x) scanf("%d", &x)
#define inlld2(x, y) scanf("%lld%lld", &x, &y)
#define inlld3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z)
#define ind2(x, y) scanf("%d%d", &x, &y)
#define ind3(x, y, z) scanf("%d%d%d", &x, &y, &z)
const int N = 1e5 + 5;
const int MOD = 1e9 + 7;
typedef long long ll;
typedef long double ld;
using namespace std;
ll n, m, k, arr1[N], arr2[N];
int main() {
inlld3(n, m, k);
for (ll a = 1; a <= n; a++) {
inlld(arr1[a]);
arr1[a] += arr1[a - 1];
}
for (ll a = 1; a <= m; a++) {
inlld(arr2[a]);
arr2[a] += arr2[a - 1];
}
ll ptr2 = m;
ll ans = 0;
while (arr2[ptr2] > k) {
ptr2--;
}
ans = ptr2;
for (ll ptr1 = 1; ptr1 <= n; ptr1++) {
if (arr1[ptr1] > k)
break;
while (ptr2 > 0 && arr1[ptr1] + arr2[ptr2] > k) {
ptr2--;
}
ans = max(ans, ptr1 + ptr2);
}
printf("%lld\n", ans);
return 0;
}
| #include <bits/stdc++.h>
#define pb push_back
#define f first
#define s second
#define mp make_pair
#define inlld(x) scanf("%lld", &x)
#define ind(x) scanf("%d", &x)
#define inlld2(x, y) scanf("%lld%lld", &x, &y)
#define inlld3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z)
#define ind2(x, y) scanf("%d%d", &x, &y)
#define ind3(x, y, z) scanf("%d%d%d", &x, &y, &z)
const int N = 2e5 + 5;
const int MOD = 1e9 + 7;
typedef long long ll;
typedef long double ld;
using namespace std;
ll n, m, k, arr1[N], arr2[N];
int main() {
inlld3(n, m, k);
for (ll a = 1; a <= n; a++) {
inlld(arr1[a]);
arr1[a] += arr1[a - 1];
}
for (ll a = 1; a <= m; a++) {
inlld(arr2[a]);
arr2[a] += arr2[a - 1];
}
ll ptr2 = m;
ll ans = 0;
while (arr2[ptr2] > k) {
ptr2--;
}
ans = ptr2;
for (ll ptr1 = 1; ptr1 <= n; ptr1++) {
if (arr1[ptr1] > k)
break;
while (ptr2 > 0 && arr1[ptr1] + arr2[ptr2] > k) {
ptr2--;
}
ans = max(ans, ptr1 + ptr2);
}
printf("%lld\n", ans);
return 0;
}
| replace | 12 | 13 | 12 | 13 | 0 | |
p02623 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
namespace IO {
template <typename T> inline void read(T &x) {
int f = 1;
x = 0;
char c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-')
f = -1;
for (; isdigit(c); c = getchar())
x = (x << 3) + (x << 1) + (c ^ 48);
x *= f;
}
template <typename T> inline void chkmax(T &x, T y) { x = x > y ? x : y; }
template <typename T> inline void chkmin(T &x, T y) { x = x < y ? x : y; }
template <typename T> inline void write(T x) {
if (x < 0)
putchar('-'), x = -x;
if (x > 9)
write(x / 10);
putchar(x % 10 + '0');
}
template <typename T> inline void writesp(T x) {
write(x);
putchar(' ');
}
template <typename T> inline void writeln(T x) {
write(x);
putchar('\n');
}
} // namespace IO
using namespace IO;
const int N = 2e5 + 5;
int n, m, k, a[N], b[N];
ll suma[N], sumb[N];
int main() {
read(n);
read(m);
read(k);
for (int i = 1; i <= n; i++)
read(a[i]);
for (int i = 1; i <= m; i++)
read(b[i]);
for (int i = 1; i <= n; i++)
suma[i] = suma[i - 1] + a[i];
for (int i = 1; i <= m; i++)
sumb[i] = sumb[i - 1] + b[i];
int ans = 0;
int npos = m;
for (int i = 1; i <= n; i++) {
while (suma[i] + sumb[npos] > k)
npos--;
if (suma[i] + sumb[npos] <= k)
chkmax(ans, i + npos);
}
writeln(ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
namespace IO {
template <typename T> inline void read(T &x) {
int f = 1;
x = 0;
char c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-')
f = -1;
for (; isdigit(c); c = getchar())
x = (x << 3) + (x << 1) + (c ^ 48);
x *= f;
}
template <typename T> inline void chkmax(T &x, T y) { x = x > y ? x : y; }
template <typename T> inline void chkmin(T &x, T y) { x = x < y ? x : y; }
template <typename T> inline void write(T x) {
if (x < 0)
putchar('-'), x = -x;
if (x > 9)
write(x / 10);
putchar(x % 10 + '0');
}
template <typename T> inline void writesp(T x) {
write(x);
putchar(' ');
}
template <typename T> inline void writeln(T x) {
write(x);
putchar('\n');
}
} // namespace IO
using namespace IO;
const int N = 2e5 + 5;
int n, m, k, a[N], b[N];
ll suma[N], sumb[N];
int main() {
read(n);
read(m);
read(k);
for (int i = 1; i <= n; i++)
read(a[i]);
for (int i = 1; i <= m; i++)
read(b[i]);
for (int i = 1; i <= n; i++)
suma[i] = suma[i - 1] + a[i];
for (int i = 1; i <= m; i++)
sumb[i] = sumb[i - 1] + b[i];
int ans = 0;
int npos = m;
for (int i = 0; i <= n; i++) {
while (npos >= 0 && suma[i] + sumb[npos] > k)
npos--;
if (suma[i] + sumb[npos] <= k)
chkmax(ans, i + npos);
}
writeln(ans);
return 0;
} | replace | 58 | 60 | 58 | 60 | 0 | |
p02623 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rep1(i, n) for (ll i = 1; i < n + 1; i++)
#define all(A) A.begin(), A.end()
typedef long long ll;
int main() {
ll n, m, k;
cin >> n >> m >> k;
vector<ll> a(n + 1);
rep1(i, n) {
if (i == 1)
cin >> a[i];
else {
cin >> a[i];
a[i] += a[i - 1];
}
}
vector<ll> b(m + 1);
rep1(i, m) {
if (i == 1)
cin >> b[i];
else {
cin >> b[i];
b[i] += b[i - 1];
}
}
ll ans = 0;
rep(i, n + 1) { // aのサーチ
rep(j, m + 1) {
// cout << i+j << "," << a[i]+b[j] << endl;
if (a[i] + b[j] <= k)
ans = max(ans, i + j);
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rep1(i, n) for (ll i = 1; i < n + 1; i++)
#define all(A) A.begin(), A.end()
typedef long long ll;
int main() {
ll n, m, k;
cin >> n >> m >> k;
vector<ll> a(n + 1);
rep1(i, n) {
if (i == 1)
cin >> a[i];
else {
cin >> a[i];
a[i] += a[i - 1];
}
}
vector<ll> b(m + 1);
rep1(i, m) {
if (i == 1)
cin >> b[i];
else {
cin >> b[i];
b[i] += b[i - 1];
}
}
ll ans = 0;
rep(i, n + 1) { // aのサーチ
ll target = k - a[i];
// cout << i << " " << target << " ";
// for(auto p : b) cout << p << ",";
ll b_num = upper_bound(all(b), target) - begin(b) - 1;
ll tmp = i + b_num;
ll val = a[i] + *(upper_bound(all(b), target) - 1);
// cout << " " << tmp << " " << val;
// cout << endl;
if (val <= k)
ans = max(ans, tmp);
}
cout << ans << endl;
} | replace | 30 | 35 | 30 | 40 | TLE | |
p02623 | C++ | Runtime Error | #include <bits/stdc++.h>
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define int long long
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repn(i, a, b) for (int i = a; i >= b; i--)
#define F first
#define S second
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
#define inf 1e18
using namespace std;
int max(int a, int b) {
if (a > b)
return a;
else
return b;
}
int min(int a, int b) {
if (a < b)
return a;
else
return b;
}
signed main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output1.txt", "w", stdout);
#endif
IOS;
int n, m, k, i;
cin >> n >> m >> k;
vi a(n + 1), b(n + 1);
vi suma(n + 1), sumb(m + 1);
for (i = 1; i <= n; i++) {
cin >> a[i];
suma[i] = suma[i - 1] + a[i];
}
for (i = 1; i <= m; i++) {
cin >> b[i];
sumb[i] = sumb[i - 1] + b[i];
}
int ans = 0;
for (i = 0; i <= n; i++) {
if (suma[i] > k)
break;
else {
int x = k - suma[i];
auto it = upper_bound(sumb.begin(), sumb.end(), x);
int pos = it - sumb.begin() - 1;
if (pos < 0)
pos = 0;
ans = max(ans, i + pos);
}
}
cout << ans;
}
| #include <bits/stdc++.h>
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define int long long
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repn(i, a, b) for (int i = a; i >= b; i--)
#define F first
#define S second
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
#define inf 1e18
using namespace std;
int max(int a, int b) {
if (a > b)
return a;
else
return b;
}
int min(int a, int b) {
if (a < b)
return a;
else
return b;
}
signed main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output1.txt", "w", stdout);
#endif
IOS;
int n, m, k, i;
cin >> n >> m >> k;
vi a(n + 1), b(m + 1);
vi suma(n + 1), sumb(m + 1);
for (i = 1; i <= n; i++) {
cin >> a[i];
suma[i] = suma[i - 1] + a[i];
}
for (i = 1; i <= m; i++) {
cin >> b[i];
sumb[i] = sumb[i - 1] + b[i];
}
int ans = 0;
for (i = 0; i <= n; i++) {
if (suma[i] > k)
break;
else {
int x = k - suma[i];
auto it = upper_bound(sumb.begin(), sumb.end(), x);
int pos = it - sumb.begin() - 1;
if (pos < 0)
pos = 0;
ans = max(ans, i + pos);
}
}
cout << ans;
}
| replace | 44 | 45 | 44 | 45 | -6 | terminate called after throwing an instance of 'std::length_error'
what(): cannot create std::vector larger than max_size()
|
p02623 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
long long int n, m, k;
std::cin >> n >> m >> k;
std::vector<long long int> a(n); // size
std::vector<long long int> b(m); // size
for (int i = 0; i < n; i++)
std::cin >> a[i];
for (int i = 0; i < m; i++)
std::cin >> b[i];
// by using perfix sum
std::vector<long long int> aSUM(n + 1); // size
std::vector<long long int> bSUM(n + 1); // size
int count = 0;
for (int i = 0; i < n; i++)
aSUM[i + 1] = aSUM[i] + a[i];
for (int i = 0; i < m; i++)
bSUM[i + 1] = bSUM[i] + b[i];
// 0 60 and so on
for (int i = 0; i <= n; i++) {
long long int other = k - aSUM[i];
if (other < 0)
continue;
// here get the position of other from bSum
int l = lower_bound(bSUM.begin(), bSUM.end(), other) - bSUM.begin();
if (l > m || bSUM[l] > other)
--l;
count = std::max(count, i + l);
}
std::cout << count << '\n';
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
long long int n, m, k;
std::cin >> n >> m >> k;
std::vector<long long int> a(n); // size
std::vector<long long int> b(m); // size
for (int i = 0; i < n; i++)
std::cin >> a[i];
for (int i = 0; i < m; i++)
std::cin >> b[i];
// by using perfix sum
std::vector<long long int> aSUM(n + 1); // size
std::vector<long long int> bSUM(m + 1); // size
int count = 0;
for (int i = 0; i < n; i++)
aSUM[i + 1] = aSUM[i] + a[i];
for (int i = 0; i < m; i++)
bSUM[i + 1] = bSUM[i] + b[i];
// 0 60 and so on
for (int i = 0; i <= n; i++) {
long long int other = k - aSUM[i];
if (other < 0)
continue;
// here get the position of other from bSum
int l = lower_bound(bSUM.begin(), bSUM.end(), other) - bSUM.begin();
if (l > m || bSUM[l] > other)
--l;
count = std::max(count, i + l);
}
std::cout << count << '\n';
return 0;
}
| replace | 18 | 19 | 18 | 19 | 0 | |
p02623 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;
typedef long long ll;
int main() {
ll n, m, a, b, ans = 0, k;
cin >> n >> m >> k;
vector<ll> suma(n + 10), sumb(n + 10);
for (int i = 0; i < n; i++) {
cin >> a;
suma[i + 1] = suma[i] + a;
}
for (int i = 0; i < m; i++) {
cin >> b;
sumb[i + 1] = sumb[i] + b;
}
for (int i = 0; i <= n; i++) {
while (m >= 0 && suma[i] + sumb[m] > k) {
m--;
}
if (m >= 0) {
ans = max(ans, i + m);
}
}
cout << ans << endl;
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;
typedef long long ll;
int main() {
ll n, m, a, b, ans = 0, k;
cin >> n >> m >> k;
vector<ll> suma(n + 10), sumb(m + 10);
for (int i = 0; i < n; i++) {
cin >> a;
suma[i + 1] = suma[i] + a;
}
for (int i = 0; i < m; i++) {
cin >> b;
sumb[i + 1] = sumb[i] + b;
}
for (int i = 0; i <= n; i++) {
while (m >= 0 && suma[i] + sumb[m] > k) {
m--;
}
if (m >= 0) {
ans = max(ans, i + m);
}
}
cout << ans << endl;
} | replace | 16 | 17 | 16 | 17 | 0 | |
p02623 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
int N, M, K;
cin >> N >> M >> K;
int m = 1;
while (m < M)
m *= 2;
vector<int> A(N + 1), B(M + 1);
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 l = 0;
for (int i = N; i >= 0; i--) {
int j = m / 4, k = M / 2;
while (j > 0) {
if (A[i] + B[k] < K)
k += j;
else
k -= j;
j = j / 2;
}
if (0 <= k + 2 && k + 2 <= M && A[i] + B[k + 2] <= K)
l = max(l, i + k + 1);
else if (0 <= k + 1 && k + 1 <= M && A[i] + B[k + 1] <= K)
l = max(l, i + k + 1);
else if (0 <= k && k <= M && A[i] + B[k] <= K)
l = max(l, i + k);
else if (0 <= k - 1 && k - 1 <= M && A[i] + B[k - 1] <= K)
l = max(l, i + k - 1);
else if (0 <= k - 2 && k - 2 <= M && A[i] + B[k - 2] <= K)
l = max(l, i + k - 1);
}
cout << l << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
int N, M, K;
cin >> N >> M >> K;
int m = 1;
while (m < M)
m *= 2;
vector<int> A(N + 1), B(M + 1);
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 l = 0;
for (int i = N; i >= 0; i--) {
int j = upper_bound(B.begin(), B.end(), K - A[i]) - B.begin();
if (j == M + 1)
l = max(l, i + M);
else if (j != 0 || A[i] < K)
l = max(l, i + j - 1);
}
cout << l << endl;
} | replace | 20 | 38 | 20 | 25 | 0 | |
p02623 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, m, n) for (int i = m; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
template <class T> void chmin(T &a, const T &b) noexcept {
if (b < a)
a = b;
}
template <class T> void chmax(T &a, const T &b) noexcept {
if (a < b)
a = b;
}
template <class T> void drop(const T &x) {
std::cout << x << endl;
exit(0);
}
void debug_out() { std::cout << "\n"; }
template <class T, class... Args>
void debug_out(const T &x, const Args &...args) {
std::cout << x << " ";
debug_out(args...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
struct InitIO {
InitIO() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
std::cout << std::fixed << std::setprecision(15);
}
} init_io;
int main() {
int n, m;
ll k;
cin >> n >> m >> k;
vector<ll> a(n), b(m);
rep(i, n) cin >> a[i];
rep(i, m) cin >> b[i];
ll sum = 0;
int cnt = 0, itr1 = 0;
rep(i, n) {
if (sum + a[i] <= k)
sum += a[i], cnt++, itr1 = i;
else
break;
}
int ans = cnt;
rep(i, m) {
if (sum + b[i] <= k)
sum += b[i], cnt++;
else {
while (sum > 0) {
sum -= a[itr1--];
cnt--;
if (sum + b[i] <= k)
break;
}
if (sum + b[i] <= k)
sum += b[i], cnt++;
else
break;
}
chmax(ans, cnt);
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, m, n) for (int i = m; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
template <class T> void chmin(T &a, const T &b) noexcept {
if (b < a)
a = b;
}
template <class T> void chmax(T &a, const T &b) noexcept {
if (a < b)
a = b;
}
template <class T> void drop(const T &x) {
std::cout << x << endl;
exit(0);
}
void debug_out() { std::cout << "\n"; }
template <class T, class... Args>
void debug_out(const T &x, const Args &...args) {
std::cout << x << " ";
debug_out(args...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
struct InitIO {
InitIO() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
std::cout << std::fixed << std::setprecision(15);
}
} init_io;
int main() {
int n, m;
ll k;
cin >> n >> m >> k;
vector<ll> a(n), b(m);
rep(i, n) cin >> a[i];
rep(i, m) cin >> b[i];
ll sum = 0;
int cnt = 0, itr1 = 0;
rep(i, n) {
if (sum + a[i] <= k)
sum += a[i], cnt++, itr1 = i;
else
break;
}
int ans = cnt;
rep(i, m) {
if (sum + b[i] <= k)
sum += b[i], cnt++;
else {
while (sum > 0 && itr1 >= 0) {
sum -= a[itr1--];
cnt--;
if (sum + b[i] <= k)
break;
}
if (sum + b[i] <= k)
sum += b[i], cnt++;
else
break;
}
chmax(ans, cnt);
}
cout << ans << endl;
return 0;
} | replace | 58 | 59 | 58 | 59 | 0 | |
p02623 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m, k;
cin >> n >> m >> k;
vector<int> a(n), b(m);
rep(i, 0, n) cin >> a[i];
rep(i, 0, m) cin >> b[i];
vector<ll> va(n + 1, 0), vb(n + 1, 0);
rep(i, 0, n) va[i + 1] = va[i] + a[i];
rep(i, 0, m) vb[i + 1] = vb[i] + b[i];
int ans = 0, j = m;
rep(i, 0, n + 1) {
if (va[i] > k)
break;
while (vb[j] > k - va[i])
j -= 1;
chmax(ans, i + j);
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m, k;
cin >> n >> m >> k;
vector<int> a(n), b(m);
rep(i, 0, n) cin >> a[i];
rep(i, 0, m) cin >> b[i];
vector<ll> va(n + 1, 0), vb(m + 1, 0);
rep(i, 0, n) va[i + 1] = va[i] + a[i];
rep(i, 0, m) vb[i + 1] = vb[i] + b[i];
int ans = 0, j = m;
rep(i, 0, n + 1) {
if (va[i] > k)
break;
while (vb[j] > k - va[i])
j -= 1;
chmax(ans, i + j);
}
cout << ans << endl;
}
| replace | 19 | 20 | 19 | 20 | 0 | |
p02623 | C++ | Runtime Error | // #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define loopinc(i, a, b, inc) for (int i = a; i < (b); i += inc)
#define loop(i, a, b) for (int i = a; i < (b); i++)
#define rep(i, n) loop(i, 0, n)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define endl "\n"
#define all(c) (c).begin(), (c).end()
#define lloopinc(i, a, b, inc) for (ll i = a; i < (b); i += inc)
#define lloop(i, a, b) for (ll i = a; i < (b); i++)
#define lrep(i, n) lloop(i, 0, n)
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef tuple<int, int, int> tiii;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V> void __print(const pair<T, V> &x) {
cerr << '{';
__print(x.first);
cerr << ',';
__print(x.second);
cerr << '}';
}
template <typename T> void __print(const T &x) {
int f = 0;
cerr << '{';
for (auto &i : x)
cerr << (f++ ? "," : ""), __print(i);
cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V> void _print(T t, V... v) {
__print(t);
if (sizeof...(v))
cerr << ", ";
_print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...) \
cerr << "[" << #x << "] = ["; \
_print(x)
#else
#define debug(x...)
#endif
signed main() {
// freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
std::ios::sync_with_stdio(false);
cin.tie(0);
ll n, m, k;
cin >> n >> m >> k;
vll a(n);
vll b(n);
rep(i, n) cin >> a[i];
rep(i, m) cin >> b[i];
vll pa(n + 1);
vll pb(m + 1);
rep(i, n) pa[i + 1] = pa[i] + a[i];
rep(i, m) pb[i + 1] = pb[i] + b[i];
int i = 0;
while (i < n and pa[i] <= k)
i++;
int best = i;
for (int j = i; j >= 0; j--) {
best = max(best, j + (int)(upper_bound(all(pb), k - pa[j]) - pb.begin()));
// debug(best, j, (int)(upper_bound(all(pb), k-pa[j]) - pb.begin()));
}
cout << best - 1 << endl;
}
| // #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define loopinc(i, a, b, inc) for (int i = a; i < (b); i += inc)
#define loop(i, a, b) for (int i = a; i < (b); i++)
#define rep(i, n) loop(i, 0, n)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define endl "\n"
#define all(c) (c).begin(), (c).end()
#define lloopinc(i, a, b, inc) for (ll i = a; i < (b); i += inc)
#define lloop(i, a, b) for (ll i = a; i < (b); i++)
#define lrep(i, n) lloop(i, 0, n)
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef tuple<int, int, int> tiii;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V> void __print(const pair<T, V> &x) {
cerr << '{';
__print(x.first);
cerr << ',';
__print(x.second);
cerr << '}';
}
template <typename T> void __print(const T &x) {
int f = 0;
cerr << '{';
for (auto &i : x)
cerr << (f++ ? "," : ""), __print(i);
cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V> void _print(T t, V... v) {
__print(t);
if (sizeof...(v))
cerr << ", ";
_print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...) \
cerr << "[" << #x << "] = ["; \
_print(x)
#else
#define debug(x...)
#endif
signed main() {
// freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
std::ios::sync_with_stdio(false);
cin.tie(0);
ll n, m, k;
cin >> n >> m >> k;
vll a(n);
vll b(m);
rep(i, n) cin >> a[i];
rep(i, m) cin >> b[i];
vll pa(n + 1);
vll pb(m + 1);
rep(i, n) pa[i + 1] = pa[i] + a[i];
rep(i, m) pb[i + 1] = pb[i] + b[i];
int i = 0;
while (i < n and pa[i] <= k)
i++;
int best = i;
for (int j = i; j >= 0; j--) {
best = max(best, j + (int)(upper_bound(all(pb), k - pa[j]) - pb.begin()));
// debug(best, j, (int)(upper_bound(all(pb), k-pa[j]) - pb.begin()));
}
cout << best - 1 << endl;
}
| replace | 73 | 74 | 73 | 74 | 0 | |
p02623 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long int;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
ll mod = 1000000007;
int main() {
ll n, m, k;
cin >> n >> m >> k;
vector<ll> a(n + 1, mod), b(m + 1, mod), A(n + 1), B(m + 1);
rep(i, n) cin >> a[i];
rep(j, m) cin >> b[j];
rep(i, n + 1) A[i + 1] = A[i] + a[i];
rep(j, m + 1) B[j + 1] = B[j] + b[j];
ll ans = 0, j = m;
rep(i, n + 1) {
if (A[i] > k)
break;
while (B[j] > k - A[i]) {
if (j == 0)
break;
j -= 1;
}
ans = max(ans, i + j);
}
cout << ans << endl;
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long int;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
ll mod = 1000000007;
int main() {
ll n, m, k;
cin >> n >> m >> k;
vector<ll> a(n + 1, mod), b(m + 1, mod), A(n + 1), B(m + 1);
rep(i, n) cin >> a[i];
rep(j, m) cin >> b[j];
rep(i, n) A[i + 1] = A[i] + a[i];
rep(j, m) B[j + 1] = B[j] + b[j];
ll ans = 0, j = m;
rep(i, n + 1) {
if (A[i] > k)
break;
while (B[j] > k - A[i]) {
if (j == 0)
break;
j -= 1;
}
ans = max(ans, i + j);
}
cout << ans << endl;
}
| replace | 17 | 19 | 17 | 19 | -6 | malloc(): corrupted top size
|
p02623 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
ll n, m;
ll k;
vector<ll> a, b;
cin >> n >> m >> k;
a.resize(n);
b.resize(m);
vector<ll> sum_a(n + 1, 0);
vector<ll> sum_b(n + 1, 0);
for (int i = 0; i < n; i++) {
cin >> a[i];
sum_a[i + 1] = sum_a[i] + a[i];
}
for (int j = 0; j < m; j++) {
cin >> b[j];
sum_b[j + 1] = sum_b[j] + b[j];
}
ll ans = 0;
ll j = m;
for (ll i = 0; i <= n; i++) {
if (sum_a[i] > k)
break;
ll temp_max = k - sum_a[i];
while (sum_b[j] > temp_max)
j--;
ans = max(ans, i + j);
}
cout << ans << "\n";
return 0;
}
| #include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
ll n, m;
ll k;
vector<ll> a, b;
cin >> n >> m >> k;
a.resize(200006);
b.resize(200006);
vector<ll> sum_a(200006, 0);
vector<ll> sum_b(200006, 0);
for (int i = 0; i < n; i++) {
cin >> a[i];
sum_a[i + 1] = sum_a[i] + a[i];
}
for (int j = 0; j < m; j++) {
cin >> b[j];
sum_b[j + 1] = sum_b[j] + b[j];
}
ll ans = 0;
ll j = m;
for (ll i = 0; i <= n; i++) {
if (sum_a[i] > k)
break;
ll temp_max = k - sum_a[i];
while (sum_b[j] > temp_max)
j--;
ans = max(ans, i + j);
}
cout << ans << "\n";
return 0;
}
| replace | 11 | 15 | 11 | 15 | 0 | |
p02623 | C++ | Runtime Error | /*note:- in first sight it seems that it will be solved with greddy techniqe
(but that is wrong as it will give wrong ans).*/
/*4 3 270
100 10 10 10
90 90 90
using greedy approach we will be able to read only three books in the above test
case(and it will consume entire 270 minutes) but actually we can read 4 books
(in just 130 minutes)
*/
/*
this approch uses calculation of prefix sum of both the arrays
refer editorial(and YT_vid) for more details
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ll n, m, k;
cin >> n >> m >> k;
vector<ll> a(n);
vector<ll> b(n);
for (ll i = 0; i < n; i++)
cin >> a[i];
for (ll j = 0; j < m; j++)
cin >> b[j];
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 j = 0; j < m; j++)
sumB[j + 1] = sumB[j] + b[j];
ll total = 0;
for (ll i = 0; i <= n; i++) {
ll other = k - sumA[i];
if (other < 0)
continue;
ll l = lower_bound(sumB.begin(), sumB.end(), other) - sumB.begin();
if (l > m || sumB[l] > other)
l--;
total = max(total, i + l);
}
cout << total;
return 0;
} | /*note:- in first sight it seems that it will be solved with greddy techniqe
(but that is wrong as it will give wrong ans).*/
/*4 3 270
100 10 10 10
90 90 90
using greedy approach we will be able to read only three books in the above test
case(and it will consume entire 270 minutes) but actually we can read 4 books
(in just 130 minutes)
*/
/*
this approch uses calculation of prefix sum of both the arrays
refer editorial(and YT_vid) for more details
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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 j = 0; j < m; j++)
cin >> b[j];
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 j = 0; j < m; j++)
sumB[j + 1] = sumB[j] + b[j];
ll total = 0;
for (ll i = 0; i <= n; i++) {
ll other = k - sumA[i];
if (other < 0)
continue;
ll l = lower_bound(sumB.begin(), sumB.end(), other) - sumB.begin();
if (l > m || sumB[l] > other)
l--;
total = max(total, i + l);
}
cout << total;
return 0;
}
| replace | 20 | 21 | 20 | 21 | -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;
long n, m, k;
vector<long> a, b;
vector<long long> sumA, sumB;
long getB(long inA) {
long long passedTime = 0;
if (inA != 0)
passedTime = sumA[inA - 1];
long long remainTime = k - passedTime;
long ret = 0;
for (long i = 0; i < m; i++) {
if (sumB[i] <= remainTime) {
ret++;
} else {
break;
}
}
return ret;
}
bool isValidA(long inA) {
if (inA == 0)
return true;
if (inA > n)
return false;
if (sumA[inA - 1] > k)
return false; // thisPath"inA">0
return true;
}
int main() {
cin >> n >> m >> k;
a = vector<long>(n);
sumA = vector<long long>(n, 0);
b = vector<long>(m);
sumB = vector<long long>(m, 0);
for (long i = 0; i < n; i++) {
cin >> a[i];
if (i == 0) {
sumA[i] = a[i];
} else {
sumA[i] = sumA[i - 1] + a[i];
}
}
for (long i = 0; i < m; i++) {
cin >> b[i];
if (i == 0) {
sumB[i] = b[i];
} else {
sumB[i] = sumB[i - 1] + b[i];
}
}
long ans = 0;
for (long i = 0; i <= n; i++) {
if (isValidA(i)) {
long bnum = getB(i);
ans = max(ans, bnum + i);
} else {
break;
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
long n, m, k;
vector<long> a, b;
vector<long long> sumA, sumB;
long getB(long inA) {
long long passedTime = 0;
if (inA != 0)
passedTime = sumA[inA - 1];
long long remainTime = k - passedTime;
long ret = 0;
// for(long i = 0; i < m; i++){
// if(sumB[i]<=remainTime){
// ret++;
// }else{
// break;
// }
// }
decltype(sumB)::iterator it =
upper_bound(sumB.begin(), sumB.end(), remainTime);
long index = it - sumB.begin();
ret = index;
return ret;
}
bool isValidA(long inA) {
if (inA == 0)
return true;
if (inA > n)
return false;
if (sumA[inA - 1] > k)
return false; // thisPath"inA">0
return true;
}
int main() {
cin >> n >> m >> k;
a = vector<long>(n);
sumA = vector<long long>(n, 0);
b = vector<long>(m);
sumB = vector<long long>(m, 0);
for (long i = 0; i < n; i++) {
cin >> a[i];
if (i == 0) {
sumA[i] = a[i];
} else {
sumA[i] = sumA[i - 1] + a[i];
}
}
for (long i = 0; i < m; i++) {
cin >> b[i];
if (i == 0) {
sumB[i] = b[i];
} else {
sumB[i] = sumB[i - 1] + b[i];
}
}
long ans = 0;
for (long i = 0; i <= n; i++) {
if (isValidA(i)) {
long bnum = getB(i);
ans = max(ans, bnum + i);
} else {
break;
}
}
cout << ans << endl;
return 0;
} | replace | 11 | 18 | 11 | 22 | TLE | |
p02623 | C++ | Runtime Error | /*
* Author: Arpit Bhayani
* https://arpitbhayani.me
*/
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define ll long long
#define MIN(a, b) a < b ? a : b
#define MAX(a, b) a > b ? a : b
using namespace std;
int readline(char *str) {
int i = 0;
char ch;
while ((ch = getchar()) != '\n') {
str[i++] = ch;
}
str[i] = '\0';
return i;
}
int arr1[100001];
int arr2[100001];
int foo(int n, int m, ll int x) {
ll int sum = 0;
int i = 0, j = 0;
int count = 0;
while (i < n) {
sum += (ll int)arr1[i];
i++;
if (sum > x) {
i--;
sum -= (ll int)arr1[i];
break;
}
}
count = i;
while (j < m) {
sum += (ll int)arr2[j];
j++;
while (sum > x && i > 0) {
i--;
sum -= (ll int)arr1[i];
}
count = (sum <= x) ? MAX((count), (i + j)) : count;
}
return count;
}
int main(int argc, char *argv[]) {
ll int x;
int n, m;
scanf("%d%d%lld", &n, &m, &x);
for (int i = 0; i < n; i++) {
scanf("%d", &arr1[i]);
}
for (int j = 0; j < m; j++) {
scanf("%d", &arr2[j]);
}
printf("%d\n", foo(n, m, x));
} | /*
* Author: Arpit Bhayani
* https://arpitbhayani.me
*/
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define ll long long
#define MIN(a, b) a < b ? a : b
#define MAX(a, b) a > b ? a : b
using namespace std;
int readline(char *str) {
int i = 0;
char ch;
while ((ch = getchar()) != '\n') {
str[i++] = ch;
}
str[i] = '\0';
return i;
}
int arr1[200001];
int arr2[200001];
int foo(int n, int m, ll int x) {
ll int sum = 0;
int i = 0, j = 0;
int count = 0;
while (i < n) {
sum += (ll int)arr1[i];
i++;
if (sum > x) {
i--;
sum -= (ll int)arr1[i];
break;
}
}
count = i;
while (j < m) {
sum += (ll int)arr2[j];
j++;
while (sum > x && i > 0) {
i--;
sum -= (ll int)arr1[i];
}
count = (sum <= x) ? MAX((count), (i + j)) : count;
}
return count;
}
int main(int argc, char *argv[]) {
ll int x;
int n, m;
scanf("%d%d%lld", &n, &m, &x);
for (int i = 0; i < n; i++) {
scanf("%d", &arr1[i]);
}
for (int j = 0; j < m; j++) {
scanf("%d", &arr2[j]);
}
printf("%d\n", foo(n, m, x));
} | replace | 35 | 37 | 35 | 37 | 0 | |
p02623 | C++ | Runtime Error | #include <bits/stdc++.h>
#define fast \
std::ios::sync_with_stdio(false); \
cin.tie(NULL);
#define int long long
#define all(c) (c).begin(), (c).end()
#define endl '\n'
using namespace std;
// mdsaqib
signed main() {
fast;
int n, m, k;
cin >> n >> m >> k;
vector<int> A(n, 0), B(m, 0);
for (int i = 0; i < n; i++) {
cin >> A[i];
}
for (int i = 0; i < m; i++) {
cin >> B[i];
}
vector<int> SA(n, 0), SB(m, 0);
int sum = 0;
for (int i = 0; i < n; i++) {
sum += A[i];
SA[i] = sum;
}
sum = 0;
for (int i = 0; i < n; i++) {
sum += B[i];
SB[i] = sum;
}
int mx = 0;
int ii = 0, jj = 0;
for (int i = 0; i < n; i++) {
if (SA[i] > k) {
break;
}
ii = i + 1;
}
mx = ii;
if (ii > 0) {
for (int i = ii - 1; i >= 0; i--) {
for (int j = jj; j < m; j++) {
if (SA[i] + SB[j] > k) {
break;
}
jj = j + 1;
}
mx = max(mx, i + jj + 1);
}
}
jj = 0;
for (int i = 0; i < m; i++) {
if (SB[i] > k) {
break;
}
jj = i + 1;
}
mx = max(mx, jj);
cout << mx;
} | #include <bits/stdc++.h>
#define fast \
std::ios::sync_with_stdio(false); \
cin.tie(NULL);
#define int long long
#define all(c) (c).begin(), (c).end()
#define endl '\n'
using namespace std;
// mdsaqib
signed main() {
fast;
int n, m, k;
cin >> n >> m >> k;
vector<int> A(n, 0), B(m, 0);
for (int i = 0; i < n; i++) {
cin >> A[i];
}
for (int i = 0; i < m; i++) {
cin >> B[i];
}
vector<int> SA(n, 0), SB(m, 0);
int sum = 0;
for (int i = 0; i < n; i++) {
sum += A[i];
SA[i] = sum;
}
sum = 0;
for (int i = 0; i < m; i++) {
sum += B[i];
SB[i] = sum;
}
int mx = 0;
int ii = 0, jj = 0;
for (int i = 0; i < n; i++) {
if (SA[i] > k) {
break;
}
ii = i + 1;
}
mx = ii;
if (ii > 0) {
for (int i = ii - 1; i >= 0; i--) {
for (int j = jj; j < m; j++) {
if (SA[i] + SB[j] > k) {
break;
}
jj = j + 1;
}
mx = max(mx, i + jj + 1);
}
}
jj = 0;
for (int i = 0; i < m; i++) {
if (SB[i] > k) {
break;
}
jj = i + 1;
}
mx = max(mx, jj);
cout << mx;
} | replace | 28 | 29 | 28 | 29 | 0 | |
p02623 | C++ | Runtime Error | #include <iostream>
#include <vector>
using namespace std;
using ll = long long;
int main() {
int i, ans, ia, ib = 0;
ll n, m, k, A, B;
cin >> n >> m >> k;
vector<ll> a(n + 1);
vector<ll> b(m + 1);
for (i = 1; i < n + 1; ++i) {
cin >> A;
a.at(i) = a.at(i - 1) + A;
}
for (i = 1; i < m + 1; ++i) {
cin >> B;
b.at(i) = b.at(i - 1) + B;
}
for (i = n; i > 0; --i) {
if (a.at(i) <= k) {
ans = i;
ia = i;
break;
}
}
while (ia >= 0) {
while (a.at(ia) + b.at(ib) <= k) {
++ib;
if (ib > m)
break;
}
--ib;
ans = max(ans, ia + ib);
--ia;
}
cout << ans << endl;
return 0;
} | #include <iostream>
#include <vector>
using namespace std;
using ll = long long;
int main() {
int i, ans, ia, ib = 0;
ll n, m, k, A, B;
cin >> n >> m >> k;
vector<ll> a(n + 1);
vector<ll> b(m + 1);
for (i = 1; i < n + 1; ++i) {
cin >> A;
a.at(i) = a.at(i - 1) + A;
}
for (i = 1; i < m + 1; ++i) {
cin >> B;
b.at(i) = b.at(i - 1) + B;
}
for (i = n; i >= 0; --i) {
if (a.at(i) <= k) {
ans = i;
ia = i;
break;
}
}
while (ia >= 0) {
while (a.at(ia) + b.at(ib) <= k) {
++ib;
if (ib > m)
break;
}
--ib;
ans = max(ans, ia + ib);
--ia;
}
cout << ans << endl;
return 0;
} | replace | 19 | 20 | 19 | 20 | 0 | |
p02623 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace std::chrono;
using namespace __gnu_pbds;
#define lli long long int
#define fr(i, a, b) for (lli i = a; i < b; i++)
#define bfr(i, a, b) for (lli i = a; i >= b; i--)
#define fio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL), cout.tie(NULL);
#define tc \
int t; \
cin >> t; \
while (t--)
#define mod 1000000007LL
#define mod2 998244353LL
#define all(vec) vec.begin(), vec.end()
#define ld long double
#define pb push_back
#define ordered_set \
tree<lli, null_type, less<lli>, rb_tree_tag, \
tree_order_statistics_node_update>
lli power(lli x, lli y, lli m) {
lli res = 1;
while (y > 0) {
if (y & 1)
res = ((res % m) * (x % m)) % m;
y >>= 2;
x = ((x % m) * (x % m)) % m;
}
return res % m;
}
int main() {
fio
lli n,
m, k;
cin >> n >> m >> k;
vector<lli> a(n), b(m);
fr(i, 0, n) cin >> a[i];
fr(j, 0, n) {
cin >> b[j];
if (j > 0)
b[j] += b[j - 1];
}
lli ans = 0, sum = 0;
vector<lli>::iterator itr;
itr = lower_bound(all(b), k);
ans = itr - b.begin();
if ((*itr) == k)
ans++;
fr(i, 0, n) {
sum += a[i];
if (k - sum < 0)
break;
itr = lower_bound(all(b), k - sum);
lli temp = itr - b.begin();
if ((*itr) == k - sum)
temp++;
ans = max(i + 1 + temp, ans);
}
cout << ans << '\n';
return 0;
}
| #include <bits/stdc++.h>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace std::chrono;
using namespace __gnu_pbds;
#define lli long long int
#define fr(i, a, b) for (lli i = a; i < b; i++)
#define bfr(i, a, b) for (lli i = a; i >= b; i--)
#define fio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL), cout.tie(NULL);
#define tc \
int t; \
cin >> t; \
while (t--)
#define mod 1000000007LL
#define mod2 998244353LL
#define all(vec) vec.begin(), vec.end()
#define ld long double
#define pb push_back
#define ordered_set \
tree<lli, null_type, less<lli>, rb_tree_tag, \
tree_order_statistics_node_update>
lli power(lli x, lli y, lli m) {
lli res = 1;
while (y > 0) {
if (y & 1)
res = ((res % m) * (x % m)) % m;
y >>= 2;
x = ((x % m) * (x % m)) % m;
}
return res % m;
}
int main() {
fio
lli n,
m, k;
cin >> n >> m >> k;
vector<lli> a(n), b(m);
fr(i, 0, n) cin >> a[i];
fr(j, 0, m) {
cin >> b[j];
if (j > 0)
b[j] += b[j - 1];
}
lli ans = 0, sum = 0;
vector<lli>::iterator itr;
itr = lower_bound(all(b), k);
ans = itr - b.begin();
if ((*itr) == k)
ans++;
fr(i, 0, n) {
sum += a[i];
if (k - sum < 0)
break;
itr = lower_bound(all(b), k - sum);
lli temp = itr - b.begin();
if ((*itr) == k - sum)
temp++;
ans = max(i + 1 + temp, ans);
}
cout << ans << '\n';
return 0;
}
| replace | 46 | 47 | 46 | 47 | 0 | |
p02623 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll, ll> pll;
const ll mod = 1e9 + 7;
// const ll mod=998244353;
const ll inf = 1LL << 61;
int main() {
ll n, m, k;
cin >> n >> m >> k;
vec a(n + 1), b(m + 1);
for (ll i = 0; i < n; i++) {
cin >> a[i + 1];
a[i + 1] += a[i];
}
for (ll i = 0; i < m; i++) {
cin >> b[i + 1];
b[i + 1] += b[i];
}
ll ok = 0, ng = n + m + 1;
while (ok + 1 < ng) {
ll mid = (ng + ok) >> 1;
ll v = inf;
for (ll i = max(0LL, mid - m); i <= n; i++) {
v = min(v, a[i] + b[mid - i]);
}
if (v <= k)
ok = mid;
else
ng = mid;
}
cout << ok << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll, ll> pll;
const ll mod = 1e9 + 7;
// const ll mod=998244353;
const ll inf = 1LL << 61;
int main() {
ll n, m, k;
cin >> n >> m >> k;
vec a(n + 1), b(m + 1);
for (ll i = 0; i < n; i++) {
cin >> a[i + 1];
a[i + 1] += a[i];
}
for (ll i = 0; i < m; i++) {
cin >> b[i + 1];
b[i + 1] += b[i];
}
ll ok = 0, ng = n + m + 1;
while (ok + 1 < ng) {
ll mid = (ng + ok) >> 1;
ll v = inf;
for (ll i = max(0LL, mid - m); i <= min(n, mid); i++) {
v = min(v, a[i] + b[mid - i]);
}
if (v <= k)
ok = mid;
else
ng = mid;
}
cout << ok << endl;
} | replace | 26 | 27 | 26 | 27 | 0 | |
p02623 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <cstring>
using namespace std;
int main() {
int n, m, k, a, cont1 = 0, cont2 = 0, r, i;
cin >> n >> m >> k;
int s1, s2;
vector<long long> x(n);
vector<long long> y(m);
for (i = 1; i <= n; i++) {
cin >> x[i];
}
for (i = 1; i <= m; i++) {
cin >> y[i];
}
s1 = s2 = 0;
for (i = 1; i <= n; i++) {
if (s1 + x[i] > k)
break;
cont1++;
s1 += x[i];
}
for (i = 1; i <= m; i++) {
if (s1 + s2 + y[i] > k)
break;
cont2++;
s2 += y[i];
}
r = cont1 + cont2;
while (cont1 > 0) {
s1 -= x[cont1--];
while (s1 + s2 + y[cont2 + 1] <= k && cont2 < m) {
cont2++;
s2 += y[cont2];
}
r = max(r, cont1 + cont2);
}
cout << r << endl;
return 0;
}
| #include <bits/stdc++.h>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <cstring>
using namespace std;
int main() {
int n, m, k, a, cont1 = 0, cont2 = 0, r, i;
cin >> n >> m >> k;
int s1, s2;
vector<long long> x(200005);
vector<long long> y(200005);
for (i = 1; i <= n; i++) {
cin >> x[i];
}
for (i = 1; i <= m; i++) {
cin >> y[i];
}
s1 = s2 = 0;
for (i = 1; i <= n; i++) {
if (s1 + x[i] > k)
break;
cont1++;
s1 += x[i];
}
for (i = 1; i <= m; i++) {
if (s1 + s2 + y[i] > k)
break;
cont2++;
s2 += y[i];
}
r = cont1 + cont2;
while (cont1 > 0) {
s1 -= x[cont1--];
while (s1 + s2 + y[cont2 + 1] <= k && cont2 < m) {
cont2++;
s2 += y[cont2];
}
r = max(r, cont1 + cont2);
}
cout << r << endl;
return 0;
}
| replace | 24 | 26 | 24 | 26 | -6 | free(): invalid size
|
p02623 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
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];
vector<ll> sumA(N + 1, 0), sumB(M + 1, 0);
for (int i = 0; i < N; ++i)
sumA[i + 1] = sumA[i] + A[i];
for (int i = 0; i < M; ++i)
sumB[i + 1] = sumB[i] + A[i];
int pa = upper_bound(sumA.begin(), sumA.end(), K) - sumA.begin() - 1;
int ans = pa;
for (int i = pa; i >= 0; --i) {
ll rest_t = K - sumA[i];
int pb = upper_bound(sumB.begin(), sumB.end(), rest_t) - sumB.begin() - 1;
pb = max(pb, 0);
ans = max(ans, i + pb);
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
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 sumA = 0;
int ia = 0;
ll sumB = 0;
int ib = 0;
while (ia < N && sumA + A[ia] <= K)
sumA += A[ia++];
int ans = ia;
for (int i = ia; i >= 0; --i) {
ll rt = K - sumA;
while (ib < M && sumB + B[ib] <= rt)
sumB += B[ib++];
ans = max(ans, i + ib);
if (i > 0)
sumA -= A[i - 1];
}
cout << ans << endl;
} | replace | 12 | 24 | 12 | 26 | 0 | |
p02623 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
int n, m, k;
int main() {
scanf("%d%d%d", &n, &m, &k);
vector<ll> a(n + 1, 0);
vector<ll> b(n + 1, 0);
for (int i = 1, x; i <= n; ++i)
scanf("%d", &x), a[i] = a[i - 1] + x;
for (int i = 1, x; i <= m; ++i)
scanf("%d", &x), b[i] = b[i - 1] + x;
int j = m;
ll 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 + 0LL);
}
printf("%lld\n", ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
int n, m, k;
int main() {
scanf("%d%d%d", &n, &m, &k);
vector<ll> a(n + 1, 0);
vector<ll> b(m + 1, 0);
for (int i = 1, x; i <= n; ++i)
scanf("%d", &x), a[i] = a[i - 1] + x;
for (int i = 1, x; i <= m; ++i)
scanf("%d", &x), b[i] = b[i - 1] + x;
int j = m;
ll 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 + 0LL);
}
printf("%lld\n", ans);
return 0;
} | replace | 13 | 14 | 13 | 14 | 0 | |
p02623 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <stdio.h>
using namespace std;
#include <vector>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define INF 1e9
#define llINF 1e18
#define base10_4 10000 // 1e4
#define base10_5 100000 // 1e5
#define base10_6 1000000 // 1e6
#define base10_7 10000000 // 1e7
#define base10_8 100000000 // 1e8
#define base10_9 1000000000 // 1e9
#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>
// #include <stack>
// #include <queue>
string ans_Yes = "Yes";
string ans_No = "No";
string ans_yes = "yes";
string ans_no = "no";
vll A;
vll B;
vll Ai;
vll Bi;
ll C;
ll N;
ll M;
ll K;
ll ltmp;
string stmp;
double dtmp;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> N;
cin >> M;
cin >> K;
ll sumA = 0;
A.push_back(0);
rep(ni, N) {
cin >> ltmp;
sumA += ltmp;
A.push_back(sumA);
}
ll sumB = 0;
B.push_back(0);
rep(ni, M) {
cin >> ltmp;
sumB += ltmp;
B.push_back(sumB);
}
ll bi = B.size() - 1;
ll cnt = 0;
rep(ai, A.size()) {
while (A[ai] + B[bi] > K) {
bi--;
}
if (cnt < ai + bi)
cnt = ai + bi;
}
cout << cnt << endl;
} | #include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <stdio.h>
using namespace std;
#include <vector>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define INF 1e9
#define llINF 1e18
#define base10_4 10000 // 1e4
#define base10_5 100000 // 1e5
#define base10_6 1000000 // 1e6
#define base10_7 10000000 // 1e7
#define base10_8 100000000 // 1e8
#define base10_9 1000000000 // 1e9
#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>
// #include <stack>
// #include <queue>
string ans_Yes = "Yes";
string ans_No = "No";
string ans_yes = "yes";
string ans_no = "no";
vll A;
vll B;
vll Ai;
vll Bi;
ll C;
ll N;
ll M;
ll K;
ll ltmp;
string stmp;
double dtmp;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> N;
cin >> M;
cin >> K;
ll sumA = 0;
A.push_back(0);
rep(ni, N) {
cin >> ltmp;
sumA += ltmp;
A.push_back(sumA);
}
ll sumB = 0;
B.push_back(0);
rep(ni, M) {
cin >> ltmp;
sumB += ltmp;
B.push_back(sumB);
}
ll bi = B.size() - 1;
ll cnt = 0;
rep(ai, A.size()) {
if (A[ai] > K)
break;
while (A[ai] + B[bi] > K) {
bi--;
}
if (cnt < ai + bi)
cnt = ai + bi;
}
cout << cnt << endl;
} | insert | 75 | 75 | 75 | 77 | 0 | |
p02623 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define IOS \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define deb(x) cout << #x << " " << x << endl;
typedef long long int ll;
void printst(stack<int> a) {
string astr = "";
while (!a.empty()) {
astr = to_string(a.top()) + " " + astr;
a.pop();
}
cout << astr << endl;
}
void printStack(stack<int> a, stack<int> b) {
cout << "a : ";
printst(a);
cout << "b : ";
printst(b);
}
int main() {
IOS
int n,
m, k;
cin >> n >> m >> k;
stack<int> a, b;
int ip;
int a_arr[n], b_arr[n];
for (int i = 0; i < n; i++)
cin >> a_arr[i];
for (int i = 0; i < m; i++)
cin >> b_arr[i];
for (int i = n - 1; i >= 0; i--) {
a.push(a_arr[i]);
}
for (int i = m - 1; i >= 0; i--) {
b.push(b_arr[i]);
}
stack<int> sta, stb;
int kk = k;
while (!a.empty() && kk > 0) {
if (kk - a.top() >= 0) {
sta.push(a.top());
kk -= a.top();
a.pop();
} else
break;
}
while (!b.empty() && kk > 0) {
if (kk - b.top() >= 0) {
stb.push(b.top());
kk -= b.top();
b.pop();
} else
break;
}
int taken = sta.size() + stb.size();
int max_taken = taken;
// printStack(sta, stb);
while (!sta.empty()) {
int popped = sta.top();
sta.pop();
kk += popped;
while (!b.empty() && kk > 0) {
if (kk - b.top() >= 0) {
stb.push(b.top());
kk -= b.top();
b.pop();
} else
break;
}
// printStack(sta, stb);
max_taken = max(max_taken, (int)sta.size() + (int)stb.size());
}
cout << max_taken;
return 0;
} | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define IOS \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define deb(x) cout << #x << " " << x << endl;
typedef long long int ll;
void printst(stack<int> a) {
string astr = "";
while (!a.empty()) {
astr = to_string(a.top()) + " " + astr;
a.pop();
}
cout << astr << endl;
}
void printStack(stack<int> a, stack<int> b) {
cout << "a : ";
printst(a);
cout << "b : ";
printst(b);
}
int main() {
IOS
int n,
m, k;
cin >> n >> m >> k;
stack<int> a, b;
int ip;
int a_arr[n], b_arr[m];
for (int i = 0; i < n; i++)
cin >> a_arr[i];
for (int i = 0; i < m; i++)
cin >> b_arr[i];
for (int i = n - 1; i >= 0; i--) {
a.push(a_arr[i]);
}
for (int i = m - 1; i >= 0; i--) {
b.push(b_arr[i]);
}
stack<int> sta, stb;
int kk = k;
while (!a.empty() && kk > 0) {
if (kk - a.top() >= 0) {
sta.push(a.top());
kk -= a.top();
a.pop();
} else
break;
}
while (!b.empty() && kk > 0) {
if (kk - b.top() >= 0) {
stb.push(b.top());
kk -= b.top();
b.pop();
} else
break;
}
int taken = sta.size() + stb.size();
int max_taken = taken;
// printStack(sta, stb);
while (!sta.empty()) {
int popped = sta.top();
sta.pop();
kk += popped;
while (!b.empty() && kk > 0) {
if (kk - b.top() >= 0) {
stb.push(b.top());
kk -= b.top();
b.pop();
} else
break;
}
// printStack(sta, stb);
max_taken = max(max_taken, (int)sta.size() + (int)stb.size());
}
cout << max_taken;
return 0;
} | replace | 42 | 43 | 42 | 43 | 0 | |
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;
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
typedef long double ld;
#define pb push_back
#define f(i, a, b) for (int i = a; i < b; i++)
#define fd(i, a, b) for (int i = a - 1; i >= b; i--)
#define pf push_front
#define fi first
#define se second
#define INF 1e10
const double pi = 3.14159265358979323;
const int mod = 998244353;
const int MAX = 1e7 + 5;
int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
void swap(int a, int b) {
int temp = a;
a = b;
b = temp;
}
int binpow(int a, int b) {
int res = 1;
while (b > 0) {
if (b % 2 == 1)
res = (res * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return res;
}
int modinv(int y) { return binpow(y, mod - 2); }
int fact[500000 + 5];
void precal() {
fact[0] = 1;
for (int i = 1; i < 500000 + 5; i++) {
fact[i] = (i * fact[i - 1]) % mod;
}
}
bool isPrime(int n) {
// Corner cases
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
if (fopen("INPUT.txt", "r")) {
freopen("INPUT.txt", "r", stdin);
freopen("OUTPUT.txt", "w", stdout);
}
#endif
// -------------------------------------Code starts
// here---------------------------------------------------------------------
int t = 1;
// cin>>t;
while (t--) {
int n, m, k;
cin >> n >> m >> k;
int a[n], b[n];
f(i, 0, n) cin >> a[i];
f(i, 0, m) cin >> b[i];
vector<int> p1, p2;
p1.pb(0);
p1.pb(a[0]);
f(i, 1, n) {
int x = p1.back();
p1.pb(x + a[i]);
}
p2.pb(0);
p2.pb(b[0]);
f(i, 1, m) {
int x = p2.back();
p2.pb(x + b[i]);
}
int mx = 0;
int j = p2.size() - 1;
f(i, 0, p1.size()) {
if (p1[i] > k)
break;
while (p2[j] > k - p1[i]) {
j -= 1;
}
mx = max(mx, i + j);
}
cout << mx << endl;
}
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
typedef long double ld;
#define pb push_back
#define f(i, a, b) for (int i = a; i < b; i++)
#define fd(i, a, b) for (int i = a - 1; i >= b; i--)
#define pf push_front
#define fi first
#define se second
#define INF 1e10
const double pi = 3.14159265358979323;
const int mod = 998244353;
const int MAX = 1e7 + 5;
int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
void swap(int a, int b) {
int temp = a;
a = b;
b = temp;
}
int binpow(int a, int b) {
int res = 1;
while (b > 0) {
if (b % 2 == 1)
res = (res * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return res;
}
int modinv(int y) { return binpow(y, mod - 2); }
int fact[500000 + 5];
void precal() {
fact[0] = 1;
for (int i = 1; i < 500000 + 5; i++) {
fact[i] = (i * fact[i - 1]) % mod;
}
}
bool isPrime(int n) {
// Corner cases
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
if (fopen("INPUT.txt", "r")) {
freopen("INPUT.txt", "r", stdin);
freopen("OUTPUT.txt", "w", stdout);
}
#endif
// -------------------------------------Code starts
// here---------------------------------------------------------------------
int t = 1;
// cin>>t;
while (t--) {
int n, m, k;
cin >> n >> m >> k;
int a[n + 1], b[m + 1];
f(i, 0, n) cin >> a[i];
f(i, 0, m) cin >> b[i];
vector<int> p1, p2;
p1.pb(0);
p1.pb(a[0]);
f(i, 1, n) {
int x = p1.back();
p1.pb(x + a[i]);
}
p2.pb(0);
p2.pb(b[0]);
f(i, 1, m) {
int x = p2.back();
p2.pb(x + b[i]);
}
int mx = 0;
int j = p2.size() - 1;
f(i, 0, p1.size()) {
if (p1[i] > k)
break;
while (p2[j] > k - p1[i]) {
j -= 1;
}
mx = max(mx, i + j);
}
cout << mx << endl;
}
} | replace | 82 | 83 | 82 | 83 | 0 | |
p02623 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n, m) for (int i = (n); i >= (m); --i)
using namespace std;
using LL = long long;
using LD = long double;
using PLL = pair<long long, long long>;
using PLD = pair<long double, long double>;
using VLL = vector<long long>;
using VLD = vector<long double>;
using VPLD = vector<PLD>;
const int IINF = numeric_limits<int>::max();
int main() {
LL n, m, k;
cin >> n >> m >> k;
VLL a(n + 1, 0), b(m + 1, 0);
REP(i, n) {
LL tmp;
cin >> tmp;
a[i + 1] = a[i] + tmp;
}
REP(i, m) {
LL tmp;
cin >> tmp;
b[i + 1] = b[i] + tmp;
}
LL ans = 0;
LL tmp_j = m;
REP(i, n + 1) {
if (a[i] > k)
break;
LL j = tmp_j;
while (b[j] > k - a[i]) {
j--;
}
ans = max(ans, i + j);
j = tmp_j;
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n, m) for (int i = (n); i >= (m); --i)
using namespace std;
using LL = long long;
using LD = long double;
using PLL = pair<long long, long long>;
using PLD = pair<long double, long double>;
using VLL = vector<long long>;
using VLD = vector<long double>;
using VPLD = vector<PLD>;
const int IINF = numeric_limits<int>::max();
int main() {
LL n, m, k;
cin >> n >> m >> k;
VLL a(n + 1, 0), b(m + 1, 0);
REP(i, n) {
LL tmp;
cin >> tmp;
a[i + 1] = a[i] + tmp;
}
REP(i, m) {
LL tmp;
cin >> tmp;
b[i + 1] = b[i] + tmp;
}
LL ans = 0;
LL tmp_j = m;
REP(i, n + 1) {
if (a[i] > k)
break;
LL j = tmp_j;
while (b[j] > k - a[i]) {
j--;
}
ans = max(ans, i + j);
tmp_j = j;
}
cout << ans << endl;
return 0;
}
| replace | 40 | 41 | 40 | 41 | TLE | |
p02623 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
int N, M, K;
vector<int> A, B;
int main() {
cin >> N >> M >> K;
A.resize(N);
B.resize(N);
for (int i = 0; i < N; i++)
cin >> A[i];
for (int i = 0; i < M; i++)
cin >> B[i];
vector<long long int> Asum(N + 1);
vector<long long int> Bsum(M + 1);
Asum[0] = 0;
for (int i = 1; i <= N; i++)
Asum[i] = A[i - 1] + Asum[i - 1];
Bsum[0] = 0;
for (int i = 1; i <= M; i++)
Bsum[i] = B[i - 1] + Bsum[i - 1];
int res = 0;
for (int i = 0; i <= N; i++) {
if (Asum[i] > K) {
break;
}
long long int rest = K - Asum[i];
auto it = upper_bound(Bsum.cbegin(), Bsum.cend(), rest);
int tmp = i + distance(Bsum.cbegin(), it) - 1;
if (tmp > res)
res = tmp;
}
cout << res << endl;
return 0;
}
| #include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
int N, M, K;
vector<int> A, B;
int main() {
cin >> N >> 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];
vector<long long int> Asum(N + 1);
vector<long long int> Bsum(M + 1);
Asum[0] = 0;
for (int i = 1; i <= N; i++)
Asum[i] = A[i - 1] + Asum[i - 1];
Bsum[0] = 0;
for (int i = 1; i <= M; i++)
Bsum[i] = B[i - 1] + Bsum[i - 1];
int res = 0;
for (int i = 0; i <= N; i++) {
if (Asum[i] > K) {
break;
}
long long int rest = K - Asum[i];
auto it = upper_bound(Bsum.cbegin(), Bsum.cend(), rest);
int tmp = i + distance(Bsum.cbegin(), it) - 1;
if (tmp > res)
res = tmp;
}
cout << res << endl;
return 0;
}
| replace | 17 | 18 | 17 | 18 | 0 | |
p02623 | C++ | Runtime Error | #include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define repi(i, n, iv) for (int i = iv; i < n; i++)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int N, M, K;
cin >> N >> M >> K;
vector<int> A(N);
vector<int> B(M);
rep(i, N) cin >> A[i];
rep(i, M) cin >> B[i];
int AS = A.size();
int BS = B.size();
int ai = 0;
int bi = 0;
int result = 0;
while (true) {
if (ai >= AS)
break;
int a = A[ai];
if (a > K)
break;
K -= a;
result++;
ai++;
}
while (true) {
if (bi >= BS)
break;
int b = B[bi];
if (b > K)
break;
K -= b;
result++;
bi++;
}
cerr << result << endl;
int t = result;
int prev = result;
rep(i, t) {
int tmp = prev;
ai--;
tmp--;
K += A[ai];
while (true) {
if (bi >= BS)
break;
int b = B[bi];
if (b > K)
break;
K -= b;
tmp++;
bi++;
}
cerr << tmp << endl;
result = max(result, tmp);
prev = tmp;
}
cout << result << endl;
}
| #include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define repi(i, n, iv) for (int i = iv; i < n; i++)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int N, M, K;
cin >> N >> M >> K;
vector<int> A(N);
vector<int> B(M);
rep(i, N) cin >> A[i];
rep(i, M) cin >> B[i];
int AS = A.size();
int BS = B.size();
int ai = 0;
int bi = 0;
int result = 0;
while (true) {
if (ai >= AS)
break;
int a = A[ai];
if (a > K)
break;
K -= a;
result++;
ai++;
}
while (true) {
if (bi >= BS)
break;
int b = B[bi];
if (b > K)
break;
K -= b;
result++;
bi++;
}
cerr << result << endl;
int t = result;
int prev = result;
rep(i, t) {
int tmp = prev;
if (ai > 0) {
ai--;
tmp--;
K += A[ai];
}
while (true) {
if (bi >= BS)
break;
int b = B[bi];
if (b > K)
break;
K -= b;
tmp++;
bi++;
}
cerr << tmp << endl;
result = max(result, tmp);
prev = tmp;
}
cout << result << endl;
}
| replace | 79 | 82 | 79 | 84 | 0 | 3
2
2
1
|
p02623 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
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> s(m + 1);
rep(i, m) s[i + 1] = s[i] + a[i];
ll ans = 0;
for (ll i = 0; i <= n; i++) {
if ((i - 1) >= 0)
k -= a[i - 1];
ll left = -1;
ll right = s.size();
while (abs(right - left) > 1) {
ll mid = (right + left) / 2;
if (s[mid] <= k)
left = mid;
else
right = mid;
}
if (k >= 0)
ans = max(ans, left + i);
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
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> s(m + 1);
rep(i, m) s[i + 1] = s[i] + b[i];
ll ans = 0;
for (ll i = 0; i <= n; i++) {
if ((i - 1) >= 0)
k -= a[i - 1];
ll left = -1;
ll right = s.size();
while (abs(right - left) > 1) {
ll mid = (right + left) / 2;
if (s[mid] <= k)
left = mid;
else
right = mid;
}
if (k >= 0)
ans = max(ans, left + i);
}
cout << ans << endl;
}
| replace | 27 | 28 | 27 | 28 | 0 | |
p02623 | C++ | Runtime Error | // よるかつ
// 前に解説ACしたから今度は自力で
// 尺取り解法
#include <bits/stdc++.h>
using namespace std;
#define rep(i, N) for (int i = 0; i < int(N); ++i)
using ll = long long;
const int INF = 2147483647;
const ll MOD = 1000000007;
// const ll INF = 1000000000000000000LL;
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];
// 全てaを読む
ll t = 0;
rep(i, n) t += a[i];
int j = n;
int ans = 0;
rep(i, m + 1) {
// 読めるところまで減らす
while (j > 0 && t > k) {
--j;
t -= a[i];
}
// 0まで減らしても無理だったらあきらめる
if (t > k)
break;
// 最大値を更新
ans = max(ans, i + j);
if (i == m)
break;
// b[i]を足す
t += b[i];
}
cout << ans << endl;
return 0;
}
| // よるかつ
// 前に解説ACしたから今度は自力で
// 尺取り解法
#include <bits/stdc++.h>
using namespace std;
#define rep(i, N) for (int i = 0; i < int(N); ++i)
using ll = long long;
const int INF = 2147483647;
const ll MOD = 1000000007;
// const ll INF = 1000000000000000000LL;
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];
// 全てaを読む
ll t = 0;
rep(i, n) t += a[i];
int j = n;
int ans = 0;
rep(i, m + 1) {
// 読めるところまで減らす
while (j > 0 && t > k) {
--j;
t -= a[j];
}
// 0まで減らしても無理だったらあきらめる
if (t > k)
break;
// 最大値を更新
ans = max(ans, i + j);
if (i == m)
break;
// b[i]を足す
t += b[i];
}
cout << ans << endl;
return 0;
}
| replace | 28 | 29 | 28 | 29 | 0 | |
p02623 | C++ | Time Limit Exceeded | #include <algorithm> // sort
#include <cstring>
#include <fstream>
#include <iostream>
#include <math.h>
#include <queue>
#include <vector>
#define DEBUG 0
#define REP(i, n) for (long long i = 0; i < (n); i++)
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
// 999999997000000003
// 1000000000000000000
using namespace std;
int solve() {
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_l_Sum(N + 1, 0);
for (int i = 0; i < N; ++i) {
a_l_Sum[i + 1] = a[i] + a_l_Sum[i];
}
vector<ll> b_l_Sum(M + 1, 0);
for (int i = 0; i < M; ++i) {
b_l_Sum[i + 1] = b[i] + b_l_Sum[i];
}
// なぜかdequeでつなげてたがそんなはずはなかった
// a[0]~a[n-1] +
// b[0]~b[m-1]の最善をみつける
// a[0]とb[0]は固定
int res = 0;
// Aの机の本を何冊読むか
for (int i = N; i >= 0; --i) {
for (int j = 0; j <= M; ++j) {
if (a_l_Sum[i] + b_l_Sum[j] <= K) {
res = max(res, i + j);
} else {
break;
}
}
}
cout << res << endl;
return 0;
}
int main() {
solve();
return 0;
}
| #include <algorithm> // sort
#include <cstring>
#include <fstream>
#include <iostream>
#include <math.h>
#include <queue>
#include <vector>
#define DEBUG 0
#define REP(i, n) for (long long i = 0; i < (n); i++)
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
// 999999997000000003
// 1000000000000000000
using namespace std;
int solve() {
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_l_Sum(N + 1, 0);
for (int i = 0; i < N; ++i) {
a_l_Sum[i + 1] = a[i] + a_l_Sum[i];
}
vector<ll> b_l_Sum(M + 1, 0);
for (int i = 0; i < M; ++i) {
b_l_Sum[i + 1] = b[i] + b_l_Sum[i];
}
// なぜかdequeでつなげてたがそんなはずはなかった
// a[0]~a[n-1] +
// b[0]~b[m-1]の最善をみつける
// a[0]とb[0]は固定
int res = 0;
// Aの机の本を何冊読むか
for (int i = 0; i <= N; ++i) {
// 0冊のとき
if (a_l_Sum[i] + b_l_Sum[0] <= K) {
res = max(res, i);
}
int l = 0;
int r = M + 1;
while (l + 1 < r) {
int mid = (l + r) / 2;
if (a_l_Sum[i] + b_l_Sum[mid] <= K) {
l = mid;
res = max(res, i + mid);
} else
r = mid;
}
}
cout << res << endl;
return 0;
}
int main() {
solve();
return 0;
}
| replace | 47 | 54 | 47 | 61 | TLE | |
p02623 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-ffloat-store")
#pragma GCC optimize("-fno-defer-pop")
typedef long long int ll;
typedef long double ld;
#define MAX 1000005
#define mod 1000000007
ll add(ll a, ll b) { return (mod + (a + b) % mod) % mod; }
ll mul(ll a, ll b) { return (mod + (a * b) % mod) % mod; }
ll n, m;
unordered_map<ll, vector<ll>> mp;
int main() {
std::ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n, m, k;
cin >> n >> m >> k;
vector<ll> A(n + 1), B(n + 1);
ll sum0 = 0, sum1 = 0;
for (ll i = 0; i < n; i++)
cin >> A[i], sum0 += A[i];
for (ll i = 0; i < m; i++)
cin >> B[i];
ll last = n - 1;
ll ans = 0;
for (ll i = 0; i <= m; i++) {
while (sum0 + sum1 > k && last >= 0) {
sum0 -= A[last];
last--;
}
if (sum0 + sum1 <= k) {
ans = max(ans, i + last + 1);
}
if (i != m)
sum1 += B[i];
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-ffloat-store")
#pragma GCC optimize("-fno-defer-pop")
typedef long long int ll;
typedef long double ld;
#define MAX 1000005
#define mod 1000000007
ll add(ll a, ll b) { return (mod + (a + b) % mod) % mod; }
ll mul(ll a, ll b) { return (mod + (a * b) % mod) % mod; }
ll n, m;
unordered_map<ll, vector<ll>> mp;
int main() {
std::ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n, m, k;
cin >> n >> m >> k;
vector<ll> A(n + 1), B(m + 1);
ll sum0 = 0, sum1 = 0;
for (ll i = 0; i < n; i++)
cin >> A[i], sum0 += A[i];
for (ll i = 0; i < m; i++)
cin >> B[i];
ll last = n - 1;
ll ans = 0;
for (ll i = 0; i <= m; i++) {
while (sum0 + sum1 > k && last >= 0) {
sum0 -= A[last];
last--;
}
if (sum0 + sum1 <= k) {
ans = max(ans, i + last + 1);
}
if (i != m)
sum1 += B[i];
}
cout << ans << endl;
}
| replace | 28 | 29 | 28 | 29 | 0 | |
p02623 | C++ | Time Limit Exceeded | #define _GLIBCXX_DEBUG
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
int main() {
int n, m, k;
cin >> n >> m >> k;
vector<ll> a(n + 1), b(m);
rep(i, n) {
cin >> a[i + 1];
a[i + 1] += a[i];
}
rep(i, m) {
cin >> b[i];
if (i >= 1)
b[i] += b[i - 1];
}
int ans = 0;
rep(i, n + 1) {
if (a[i] > k)
break;
int b_r = upper_bound(b.begin(), b.end(), k - a[i]) - b.begin();
ans = max(ans, i + b_r);
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
int main() {
int n, m, k;
cin >> n >> m >> k;
vector<ll> a(n + 1), b(m);
rep(i, n) {
cin >> a[i + 1];
a[i + 1] += a[i];
}
rep(i, m) {
cin >> b[i];
if (i >= 1)
b[i] += b[i - 1];
}
int ans = 0;
rep(i, n + 1) {
if (a[i] > k)
break;
int b_r = upper_bound(b.begin(), b.end(), k - a[i]) - b.begin();
ans = max(ans, i + b_r);
}
cout << ans << endl;
return 0;
} | delete | 0 | 1 | 0 | 0 | TLE | |
p02623 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define ALLR(v) v.rbegin(), v.rend()
typedef long long ll;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
// isPrime
// modpow modinv
// getDigit
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int main() {
cout << fixed << setprecision(10);
int n, m, k;
cin >> n >> m >> k;
vector<int> a(n), b(m);
rep(i, n) { cin >> a[i]; }
rep(i, m) { cin >> b[i]; }
vector<ll> c(n + 1, 0);
vector<ll> d(m + 1, 0);
rep(i, n) { c[i + 1] = c[i] + a[i]; }
rep(i, m) { d[i + 1] = d[i] + a[i]; }
int ans = 0;
for (int i = 0; i <= n; i++) {
if (c[i] > k) {
continue;
} else {
int p = k - c[i];
// cout << p << endl;
int ok, ng;
ok = 0;
ng = m + 1;
while (ng - ok > 1) {
int mid = (ng + ok) / 2;
if (d[mid] <= p) {
ok = mid;
} else {
ng = mid;
}
}
// cout << ok << endl;
chmax(ans, i + ok);
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define ALLR(v) v.rbegin(), v.rend()
typedef long long ll;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
// isPrime
// modpow modinv
// getDigit
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int main() {
cout << fixed << setprecision(10);
int n, m, k;
cin >> n >> m >> k;
vector<int> a(n), b(m);
rep(i, n) { cin >> a[i]; }
rep(i, m) { cin >> b[i]; }
vector<ll> c(n + 1, 0);
vector<ll> d(m + 1, 0);
rep(i, n) { c[i + 1] = c[i] + a[i]; }
rep(i, m) { d[i + 1] = d[i] + b[i]; }
int ans = 0;
for (int i = 0; i <= n; i++) {
if (c[i] > k) {
continue;
} else {
int p = k - c[i];
// cout << p << endl;
int ok, ng;
ok = 0;
ng = m + 1;
while (ng - ok > 1) {
int mid = (ng + ok) / 2;
if (d[mid] <= p) {
ok = mid;
} else {
ng = mid;
}
}
// cout << ok << endl;
chmax(ans, i + ok);
}
}
cout << ans << endl;
}
| replace | 38 | 39 | 38 | 39 | 0 | |
p02623 | C++ | Runtime Error | /*بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم*/
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
typedef long long ll;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;
// const ll mod = 998244353;
inline void normal(ll &a) {
a %= mod;
(a < 0) && (a += mod);
}
inline ll modMul(ll a, ll b) {
a %= mod, b %= mod;
normal(a), normal(b);
return (a * b) % mod;
}
inline ll modAdd(ll a, ll b) {
a %= mod, b %= mod;
normal(a), normal(b);
return (a + b) % mod;
}
inline ll modSub(ll a, ll b) {
a %= mod, b %= mod;
normal(a), normal(b);
a -= b;
normal(a);
return a;
}
inline ll modPow(ll b, ll p) {
ll r = 1;
while (p) {
if (p & 1)
r = modMul(r, b);
b = modMul(b, b);
p >>= 1;
}
return r;
}
inline ll modInverse(ll a) { return modPow(a, mod - 2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }
#define si(x) scanf("%d", &x)
#define sii(x, y) scanf("%d %d", &x, &y)
#define siii(x, y, z) scanf("%d %d %d", &x, &y, &z)
#define sl(x) scanf("%lld", &x)
#define sll(x, y) scanf("%lld %lld", &x, &y)
#define slll(x, y, z) scanf("%lld %lld %lld", &x, &y, &z)
#define ss(ch) scanf("%s", ch)
#define pi(x) printf("%d", x)
#define pii(x, y) printf("%d %d", x, y)
#define piii(x, y, z) printf("%d %d %d", x, y, z)
#define pl(x) printf("%lld", x)
#define pll(x, y) printf("%lld %lld", x, y)
#define plll(x, y, z) printf("%lld %lld %lld", x, y, z)
#define ps(ch) printf("%s", ch)
#define F(i, a, b) for (int i = a; i <= b; i++)
#define R(i, b, a) for (int i = b; i >= a; i--)
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1, -1, -1, 0, 1, -1, 0, 1};
int kx8[] = {1, 1, 2, 2, -1, -1, -2, -2};
int ky8[] = {2, -2, 1, -1, 2, -2, 1, -1};
/* for Random Number generate
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
*/
///**
template <typename F, typename S>
ostream &operator<<(ostream &os, const pair<F, S> &p) {
return os << "(" << p.first << ", " << p.second << ")";
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << "{";
for (auto it = v.begin(); it != v.end(); ++it) {
if (it != v.begin())
os << ", ";
os << *it;
}
return os << "}";
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &v) {
os << "[";
for (auto it = v.begin(); it != v.end(); ++it) {
if (it != v.begin())
os << ", ";
os << *it;
}
return os << "]";
}
template <typename F, typename S>
ostream &operator<<(ostream &os, const map<F, S> &v) {
os << "[";
for (auto it = v.begin(); it != v.end(); ++it) {
if (it != v.begin())
os << ", ";
os << it->first << " = " << it->second;
}
return os << "]";
}
#define dbg(args...) \
do { \
cerr << #args << " : "; \
faltu(args); \
} while (0)
clock_t tStart = clock();
#define timeStamp \
dbg("Execution Time: ", (double)(clock() - tStart) / CLOCKS_PER_SEC)
void faltu() { cerr << endl; }
template <typename T> void faltu(T a[], int n) {
for (int i = 0; i < n; ++i)
cerr << a[i] << ' ';
cerr << endl;
}
template <typename T, typename... hello>
void faltu(T arg, const hello &...rest) {
cerr << arg << ' ';
faltu(rest...);
}
// Program showing a policy-based data structure.
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
using namespace __gnu_pbds;
// GNU link : https://goo.gl/WVDL6g
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
tree_order_statistics_node_update>
new_data_set;
// find_by_order(k) – ফাংশনটি kth ordered element এর একটা পয়েন্টার রিটার্ন করে।
// অর্থাৎ তুমি চাইলেই kth ইন্ডেক্সে কি আছে, সেটা জেনে ফেলতে পারছো! order_of_key(x) –
// ফাংশনটি x এলিমেন্টটা কোন পজিশনে আছে সেটা বলে দেয়।
//*//**___________________________________________________**/
const int N = 1000006;
int main() {
FASTIO
/*
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
freopen("error.txt", "w", stderr);
#endif
//*/
ll n, m, k;
cin >> n >> m >> k;
vector<ll> a(n + 5), b(n + 5);
ll sm = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
sm += a[i];
}
for (int i = 0; i < m; i++) {
cin >> b[i];
}
// ll lw = upper_bound(b.begin(), b.end(), k) - b.begin();
ll ans = 0;
ll j = 0, i = n;
while (true) {
if (sm <= k) {
ans = max(ans, i + j);
if (j < m) {
sm += b[j];
j++;
} else
break;
} else {
if (i == 0)
break;
i--;
sm -= a[i];
}
}
cout << ans << "\n";
return 0;
} | /*بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم*/
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
typedef long long ll;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;
// const ll mod = 998244353;
inline void normal(ll &a) {
a %= mod;
(a < 0) && (a += mod);
}
inline ll modMul(ll a, ll b) {
a %= mod, b %= mod;
normal(a), normal(b);
return (a * b) % mod;
}
inline ll modAdd(ll a, ll b) {
a %= mod, b %= mod;
normal(a), normal(b);
return (a + b) % mod;
}
inline ll modSub(ll a, ll b) {
a %= mod, b %= mod;
normal(a), normal(b);
a -= b;
normal(a);
return a;
}
inline ll modPow(ll b, ll p) {
ll r = 1;
while (p) {
if (p & 1)
r = modMul(r, b);
b = modMul(b, b);
p >>= 1;
}
return r;
}
inline ll modInverse(ll a) { return modPow(a, mod - 2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }
#define si(x) scanf("%d", &x)
#define sii(x, y) scanf("%d %d", &x, &y)
#define siii(x, y, z) scanf("%d %d %d", &x, &y, &z)
#define sl(x) scanf("%lld", &x)
#define sll(x, y) scanf("%lld %lld", &x, &y)
#define slll(x, y, z) scanf("%lld %lld %lld", &x, &y, &z)
#define ss(ch) scanf("%s", ch)
#define pi(x) printf("%d", x)
#define pii(x, y) printf("%d %d", x, y)
#define piii(x, y, z) printf("%d %d %d", x, y, z)
#define pl(x) printf("%lld", x)
#define pll(x, y) printf("%lld %lld", x, y)
#define plll(x, y, z) printf("%lld %lld %lld", x, y, z)
#define ps(ch) printf("%s", ch)
#define F(i, a, b) for (int i = a; i <= b; i++)
#define R(i, b, a) for (int i = b; i >= a; i--)
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1, -1, -1, 0, 1, -1, 0, 1};
int kx8[] = {1, 1, 2, 2, -1, -1, -2, -2};
int ky8[] = {2, -2, 1, -1, 2, -2, 1, -1};
/* for Random Number generate
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
*/
///**
template <typename F, typename S>
ostream &operator<<(ostream &os, const pair<F, S> &p) {
return os << "(" << p.first << ", " << p.second << ")";
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << "{";
for (auto it = v.begin(); it != v.end(); ++it) {
if (it != v.begin())
os << ", ";
os << *it;
}
return os << "}";
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &v) {
os << "[";
for (auto it = v.begin(); it != v.end(); ++it) {
if (it != v.begin())
os << ", ";
os << *it;
}
return os << "]";
}
template <typename F, typename S>
ostream &operator<<(ostream &os, const map<F, S> &v) {
os << "[";
for (auto it = v.begin(); it != v.end(); ++it) {
if (it != v.begin())
os << ", ";
os << it->first << " = " << it->second;
}
return os << "]";
}
#define dbg(args...) \
do { \
cerr << #args << " : "; \
faltu(args); \
} while (0)
clock_t tStart = clock();
#define timeStamp \
dbg("Execution Time: ", (double)(clock() - tStart) / CLOCKS_PER_SEC)
void faltu() { cerr << endl; }
template <typename T> void faltu(T a[], int n) {
for (int i = 0; i < n; ++i)
cerr << a[i] << ' ';
cerr << endl;
}
template <typename T, typename... hello>
void faltu(T arg, const hello &...rest) {
cerr << arg << ' ';
faltu(rest...);
}
// Program showing a policy-based data structure.
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
using namespace __gnu_pbds;
// GNU link : https://goo.gl/WVDL6g
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
tree_order_statistics_node_update>
new_data_set;
// find_by_order(k) – ফাংশনটি kth ordered element এর একটা পয়েন্টার রিটার্ন করে।
// অর্থাৎ তুমি চাইলেই kth ইন্ডেক্সে কি আছে, সেটা জেনে ফেলতে পারছো! order_of_key(x) –
// ফাংশনটি x এলিমেন্টটা কোন পজিশনে আছে সেটা বলে দেয়।
//*//**___________________________________________________**/
const int N = 1000006;
int main() {
FASTIO
/*
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
freopen("error.txt", "w", stderr);
#endif
//*/
ll n, m, k;
cin >> n >> m >> k;
vector<ll> a(n), b(m);
ll sm = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
sm += a[i];
}
for (int i = 0; i < m; i++) {
cin >> b[i];
}
// ll lw = upper_bound(b.begin(), b.end(), k) - b.begin();
ll ans = 0;
ll j = 0, i = n;
while (true) {
if (sm <= k) {
ans = max(ans, i + j);
if (j < m) {
sm += b[j];
j++;
} else
break;
} else {
if (i == 0)
break;
i--;
sm -= a[i];
}
}
cout << ans << "\n";
return 0;
} | replace | 153 | 154 | 153 | 154 | 0 | |
p02623 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60; // intじゃ扱えないことに注意!
using P = pair<int, int>;
#define rep(i, n) \
for (int i = 0; i < (int)(n); i++) // 範囲外参照とループの初期化に注意!
int main() {
ll N, M, K;
cin >> N >> M >> K;
vector<ll> A(N), 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]; // tがKを超えないようにBを減らす
}
if (t > K)
break;
ans = max(ans, i + j);
if (i == N)
break;
t += A[i];
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60; // intじゃ扱えないことに注意!
using P = pair<int, int>;
#define rep(i, n) \
for (int i = 0; i < (int)(n); i++) // 範囲外参照とループの初期化に注意!
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];
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]; // tがKを超えないようにBを減らす
}
if (t > K)
break;
ans = max(ans, i + j);
if (i == N)
break;
t += A[i];
}
cout << ans << endl;
return 0;
} | replace | 11 | 12 | 11 | 12 | -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 <algorithm>
#include <climits>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
typedef long long int ll;
using namespace std;
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];
vector<ll> as(n + 1), bs(m + 1);
for (int i = 1; i < n + 1; i++)
as[i] = as[i - 1] + a[i - 1];
for (int i = 1; i < m + 1; i++)
bs[i] = bs[i - 1] + b[i - 1];
int val = 0;
for (int i = 0; i < n + 1; i++) {
if (k < as[i])
break;
int j = 0;
for (j = 0; j < m; j++) {
if (bs[j + 1] > k - as[i])
break;
}
val = max(val, i + j);
}
cout << val << endl;
return 0;
} | #include <algorithm>
#include <climits>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
typedef long long int ll;
using namespace std;
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];
vector<ll> as(n + 1), bs(m + 1);
for (int i = 1; i < n + 1; i++)
as[i] = as[i - 1] + a[i - 1];
for (int i = 1; i < m + 1; i++)
bs[i] = bs[i - 1] + b[i - 1];
int val = 0;
for (int i = 0; i < n + 1; i++) {
if (k < as[i])
break;
int j = lower_bound(bs.begin(), bs.end(), k - as[i] + 1) - bs.begin() - 1;
// int j = 0;
// for (j = 0; j < m; j++) {
// if (bs[j + 1] > k - as[i]) break;
// }
val = max(val, i + j);
}
cout << val << endl;
return 0;
} | replace | 33 | 38 | 33 | 39 | TLE | |
p02623 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, k;
cin >> n >> m >> k;
vector<int64_t> a(n + 1, 0), b(m + 1, 0);
for (int i = 1; i <= n; i++) {
int c;
cin >> c;
a.at(i) = a.at(i - 1) + c;
}
for (int i = 1; i <= m; i++) {
int d;
cin >> d;
b.at(i) = b.at(i - 1) + d;
}
int jbest = 0;
bool judge = true;
while (judge) {
if (k >= b.at(jbest + 1)) {
jbest++;
} else {
judge = false;
}
if (jbest == m) {
judge = false;
}
}
// cout << jbest << endl;
int ans = jbest;
for (int i = 1; i <= n; i++) {
if (a.at(i) > k) {
break;
}
int j = jbest;
while (b.at(j) > k - a.at(i)) {
j--;
}
ans = max(ans, i + j);
}
/*for(int j = jbest; j >= 0; j--) {
for(int i = 1; i <= n; i++) {
if(a.at(i) <= k - b.at(j) && ans < i + j) {
ans = i + j;
}
if(a.at(i) > k - b.at(j)) {
break;
}
}
}*/
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, k;
cin >> n >> m >> k;
vector<int64_t> a(n + 1, 0), b(m + 1, 0);
for (int i = 1; i <= n; i++) {
int c;
cin >> c;
a.at(i) = a.at(i - 1) + c;
}
for (int i = 1; i <= m; i++) {
int d;
cin >> d;
b.at(i) = b.at(i - 1) + d;
}
int jbest = 0;
bool judge = true;
while (judge) {
if (k >= b.at(jbest + 1)) {
jbest++;
} else {
judge = false;
}
if (jbest == m) {
judge = false;
}
}
// cout << jbest << endl;
int ans = jbest;
for (int i = 1; i <= n; i++) {
if (a.at(i) > k) {
break;
}
int j = jbest;
while (b.at(j) > k - a.at(i)) {
j--;
}
ans = max(ans, i + j);
jbest = j;
}
/*for(int j = jbest; j >= 0; j--) {
for(int i = 1; i <= n; i++) {
if(a.at(i) <= k - b.at(j) && ans < i + j) {
ans = i + j;
}
if(a.at(i) > k - b.at(j)) {
break;
}
}
}*/
cout << ans << endl;
return 0;
} | insert | 42 | 42 | 42 | 43 | TLE | |
p02623 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
unsigned long long k;
unsigned long long a[200001], b[200001];
cin >> n >> m >> k;
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 mm = 0;
for (int i = 0; i <= n; i++) {
for (int j = mm - i; j <= m; j++) {
if (a[i] + b[j] <= k) {
mm = max(mm, i + j);
} else {
continue;
}
}
}
cout << mm << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
unsigned long long k;
unsigned long long a[200001], b[200001];
cin >> n >> m >> k;
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 mm = 0;
for (int i = 0; i <= n; i++) {
for (int j = mm - i; j <= m; j++) {
if (a[i] + b[j] <= k) {
mm = max(mm, i + j);
} else {
break;
}
}
}
cout << mm << endl;
return 0;
} | replace | 24 | 25 | 24 | 25 | TLE | |
p02623 | C++ | Runtime Error | #pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define pb push_back
#define pf push_front
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define f first
#define s second
#define sz(x) (int)x.size()
#define endl "\n"
#define forn(i, n) for (int i = 0; i < n; ++i)
#define fore(i, l, r) for (int i = int(l); i <= int(r); ++i)
#define rep(i, begin, end) for (__typeof(end) i = (begin); i != (end); i++)
#define fill(a, value) memset(a, value, sizeof(a));
#define gcd(a, b) __gcd((a), (b))
#define watch1(x) cout << (x) << endl
#define watch2(x, y) cout << (x) << " " << (y) << endl
#define watch3(x, y, z) cout << (x) << " " << (y) << " " << (z) << endl
#define fastio \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
oset;
const int INF = 9e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 5;
int i, n, m, k, a[N], b[N], dp1[N], dp2[N];
bool check(int mid) {
int best = INF;
for (i = 0; i <= n; ++i) {
int rem = mid - i, req = dp1[i];
if (rem <= m) {
req += dp2[rem];
best = min(best, req);
}
}
return best <= k;
}
void solve() {
cin >> n >> m >> k;
for (i = 1; i <= n; ++i) {
cin >> a[i];
dp1[i] = a[i];
dp1[i] += dp1[i - 1];
}
for (i = 1; i <= m; ++i) {
cin >> b[i];
dp2[i] = b[i];
dp2[i] += dp2[i - 1];
}
int lo = 0, hi = m + n;
while (lo < hi) {
int mid = (lo + hi + 1) / 2;
if (check(mid))
lo = mid;
else
hi = mid - 1;
}
cout << lo;
}
signed main() {
fastio;
int t;
// cin>>t;
t = 1;
while (t--) {
solve();
}
return 0;
} | #pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define pb push_back
#define pf push_front
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define f first
#define s second
#define sz(x) (int)x.size()
#define endl "\n"
#define forn(i, n) for (int i = 0; i < n; ++i)
#define fore(i, l, r) for (int i = int(l); i <= int(r); ++i)
#define rep(i, begin, end) for (__typeof(end) i = (begin); i != (end); i++)
#define fill(a, value) memset(a, value, sizeof(a));
#define gcd(a, b) __gcd((a), (b))
#define watch1(x) cout << (x) << endl
#define watch2(x, y) cout << (x) << " " << (y) << endl
#define watch3(x, y, z) cout << (x) << " " << (y) << " " << (z) << endl
#define fastio \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
oset;
const int INF = 9e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 5;
int i, n, m, k, a[N], b[N], dp1[N], dp2[N];
bool check(int mid) {
int best = INF;
for (i = 0; i <= n; ++i) {
int rem = mid - i, req = dp1[i];
if (rem <= m && rem >= 0) {
req += dp2[rem];
best = min(best, req);
}
}
return best <= k;
}
void solve() {
cin >> n >> m >> k;
for (i = 1; i <= n; ++i) {
cin >> a[i];
dp1[i] = a[i];
dp1[i] += dp1[i - 1];
}
for (i = 1; i <= m; ++i) {
cin >> b[i];
dp2[i] = b[i];
dp2[i] += dp2[i - 1];
}
int lo = 0, hi = m + n;
while (lo < hi) {
int mid = (lo + hi + 1) / 2;
if (check(mid))
lo = mid;
else
hi = mid - 1;
}
cout << lo;
}
signed main() {
fastio;
int t;
// cin>>t;
t = 1;
while (t--) {
solve();
}
return 0;
} | replace | 55 | 56 | 55 | 56 | 0 | |
p02623 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, k;
cin >> n >> m >> k;
long long int x;
long long int a[n + 1], b[n + 1];
a[0] = b[0] = 0;
for (int i = 1; i <= n; i++) {
cin >> x;
a[i] = a[i - 1] + x;
}
for (int i = 1; i <= m; i++) {
cin >> x;
b[i] = b[i - 1] + x;
}
long long int ans = 0;
int j = m;
for (int i = 0; i <= n; i++) {
if (a[i] > k) {
break;
}
while (b[j] > k - a[i]) {
j--;
}
ans = max(ans, (long long int)i + j);
}
cout << ans;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, k;
cin >> n >> m >> k;
long long int x;
long long int a[n + 1], b[m + 1];
a[0] = b[0] = 0;
for (int i = 1; i <= n; i++) {
cin >> x;
a[i] = a[i - 1] + x;
}
for (int i = 1; i <= m; i++) {
cin >> x;
b[i] = b[i - 1] + x;
}
long long int ans = 0;
int j = m;
for (int i = 0; i <= n; i++) {
if (a[i] > k) {
break;
}
while (b[j] > k - a[i]) {
j--;
}
ans = max(ans, (long long int)i + j);
}
cout << ans;
return 0;
} | replace | 6 | 7 | 6 | 7 | 0 | |
p02623 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
using vi = vector<int>;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n, m, k;
cin >> n >> m >> k;
vi psa(n + 1), psb(m + 1);
for (int i = 1; i <= n; i++) {
int a;
cin >> a;
psa.at(i) = min(k + 1, psa.at(i - 1) + a);
}
for (int i = 1; i <= m; i++) {
int b;
cin >> b;
psb.at(i) = min(k + 1, psb.at(i - 1) + b);
}
int ans = 0;
for (int i = upper_bound(psa.begin(), psa.end(), k) - psa.begin() - 1, j = 0;
i >= 0; i--) {
while (psa.at(i) + psb.at(j) <= k) {
j++;
}
ans = max(ans, i + j - 1);
}
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
using vi = vector<int>;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n, m, k;
cin >> n >> m >> k;
vi psa(n + 1), psb(m + 1);
for (int i = 1; i <= n; i++) {
int a;
cin >> a;
psa.at(i) = min(k + 1, psa.at(i - 1) + a);
}
for (int i = 1; i <= m; i++) {
int b;
cin >> b;
psb.at(i) = min(k + 1, psb.at(i - 1) + b);
}
int ans = 0;
for (int i = upper_bound(psa.begin(), psa.end(), k) - psa.begin() - 1, j = 0;
i >= 0; i--) {
while (j <= m && psa.at(i) + psb.at(j) <= k) {
j++;
}
ans = max(ans, i + j - 1);
}
cout << ans << endl;
return 0;
}
| replace | 29 | 30 | 29 | 30 | 0 | |
p02623 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
bool is_digit(char c) { return c >= '0' && c <= '9'; }
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];
}
vector<long long> sa(n + 1), sb(m + 1);
sa[0] = 0;
for (int i = 0; i < n; i++) {
sa[i + 1] = a[i] + sa[i];
}
sb[0] = 0;
for (int i = 0; i < m; i++) {
sb[i + 1] = a[i] + sb[i];
}
int res = 0;
for (int i = 0; i <= n; i++) {
if (sa[i] > k)
break;
int l = 0, r = m + 1;
while (r - l > 1) {
int mid = (r + l) / 2;
if (sa[i] + sb[mid] > k) {
r = mid;
} else {
l = mid;
}
}
res = max(res, i + l);
}
cout << res;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
bool is_digit(char c) { return c >= '0' && c <= '9'; }
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];
}
vector<long long> sa(n + 1), sb(m + 1);
sa[0] = 0;
for (int i = 0; i < n; i++) {
sa[i + 1] = a[i] + sa[i];
}
sb[0] = 0;
for (int i = 0; i < m; i++) {
sb[i + 1] = b[i] + sb[i];
}
int res = 0;
for (int i = 0; i <= n; i++) {
if (sa[i] > k)
break;
int l = 0, r = m + 1;
while (r - l > 1) {
int mid = (r + l) / 2;
if (sa[i] + sb[mid] > k) {
r = mid;
} else {
l = mid;
}
}
res = max(res, i + l);
}
cout << res;
return 0;
} | replace | 23 | 24 | 23 | 24 | 0 | |
p02623 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <string>
#include <vector>
using namespace std;
vector<string> split(const string &s, char delim) {
vector<string> elems;
string item;
for (char ch : s) {
if (ch == delim) {
if (!item.empty()) {
elems.push_back(item);
}
item.clear();
} else {
item += ch;
}
}
if (!item.empty()) {
elems.push_back(item);
}
return elems;
}
string to_str_with_zero(int i, int w) {
ostringstream sout;
sout << std::setfill('0') << std::setw(w) << i;
string s = sout.str();
return s;
}
int letter_to_int(char c) { return tolower(c) - 'a'; }
bool array_equal(vector<int> a1, vector<int> a2) {
if (a1.size() != a2.size()) {
return false;
}
for (int i = 0; i < a1.size(); i++) {
if (a1.at(i) != a2.at(i)) {
return false;
}
}
return true;
}
int gcd(int a, int b) {
if (a == b) {
return a;
} else if (a > b) {
return gcd(a - b, b);
} else {
return gcd(a, b - a);
}
}
char int_to_char(int a) {
if (a == -1) {
return 'z';
} else {
return 'a' + a;
}
}
long nCr(int n, int r) {
long ans = 1;
for (int i = n; i > n - r; --i) {
ans = ans * i;
}
for (int i = 1; i < r + 1; ++i) {
ans = ans / i;
}
return ans;
}
long long modinv(long long a, long long m) {
long long b = m, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
int main() {
std::cout << std::setprecision(9);
int n, m;
long k;
cin >> n >> m >> k;
vector<long> a_sum(n);
for (int i = 0; i < n; i++) {
long a;
cin >> a;
if (i == 0) {
a_sum.at(i) = a;
} else {
a_sum.at(i) = a_sum.at(i - 1) + a;
}
}
vector<long> b_sum(m);
for (int i = 0; i < m; i++) {
long b;
cin >> b;
if (i == 0) {
b_sum.at(i) = b;
} else {
b_sum.at(i) = b_sum.at(i - 1) + b;
}
}
int ans = 0;
int a_num = 0;
while (a_sum.at(a_num) <= k) {
a_num++;
}
ans = a_num;
for (int i = 0; i < m; i++) {
if (b_sum.at(i) > k) {
break;
}
if (a_num > 0) {
while (a_sum.at(a_num - 1) + b_sum.at(i) > k) {
a_num--;
if (a_num == 0) {
break;
}
}
}
if (ans < a_num + i + 1) {
ans = a_num + i + 1;
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#include <string>
#include <vector>
using namespace std;
vector<string> split(const string &s, char delim) {
vector<string> elems;
string item;
for (char ch : s) {
if (ch == delim) {
if (!item.empty()) {
elems.push_back(item);
}
item.clear();
} else {
item += ch;
}
}
if (!item.empty()) {
elems.push_back(item);
}
return elems;
}
string to_str_with_zero(int i, int w) {
ostringstream sout;
sout << std::setfill('0') << std::setw(w) << i;
string s = sout.str();
return s;
}
int letter_to_int(char c) { return tolower(c) - 'a'; }
bool array_equal(vector<int> a1, vector<int> a2) {
if (a1.size() != a2.size()) {
return false;
}
for (int i = 0; i < a1.size(); i++) {
if (a1.at(i) != a2.at(i)) {
return false;
}
}
return true;
}
int gcd(int a, int b) {
if (a == b) {
return a;
} else if (a > b) {
return gcd(a - b, b);
} else {
return gcd(a, b - a);
}
}
char int_to_char(int a) {
if (a == -1) {
return 'z';
} else {
return 'a' + a;
}
}
long nCr(int n, int r) {
long ans = 1;
for (int i = n; i > n - r; --i) {
ans = ans * i;
}
for (int i = 1; i < r + 1; ++i) {
ans = ans / i;
}
return ans;
}
long long modinv(long long a, long long m) {
long long b = m, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
int main() {
std::cout << std::setprecision(9);
int n, m;
long k;
cin >> n >> m >> k;
vector<long> a_sum(n);
for (int i = 0; i < n; i++) {
long a;
cin >> a;
if (i == 0) {
a_sum.at(i) = a;
} else {
a_sum.at(i) = a_sum.at(i - 1) + a;
}
}
vector<long> b_sum(m);
for (int i = 0; i < m; i++) {
long b;
cin >> b;
if (i == 0) {
b_sum.at(i) = b;
} else {
b_sum.at(i) = b_sum.at(i - 1) + b;
}
}
int ans = 0;
int a_num = 0;
while (a_sum.at(a_num) <= k) {
a_num++;
if (a_num == n) {
break;
}
}
ans = a_num;
for (int i = 0; i < m; i++) {
if (b_sum.at(i) > k) {
break;
}
if (a_num > 0) {
while (a_sum.at(a_num - 1) + b_sum.at(i) > k) {
a_num--;
if (a_num == 0) {
break;
}
}
}
if (ans < a_num + i + 1) {
ans = a_num + i + 1;
}
}
cout << ans << endl;
} | insert | 120 | 120 | 120 | 123 | 0 | |
p02623 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vl = vector<ll>;
using vvl = vector<vl>;
#define mp make_pair
#define pb push_back
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define all(v) v.begin(), v.end()
#define sz(v) (int)((v).size())
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
#define Sort(v) sort(all(v))
#define Rev(v) reverse(all(v))
#define vec(type, name, ...) vector<type> name(__VA_ARGS__)
#define VEC(type, name, size) \
vector<type> name(size); \
in(name)
#define vv(type, name, h, ...) \
vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define VV(type, name, h, w) \
vector<vector<type>> name(h, vector<type>(w)); \
in(name)
void debug_out() { cout << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
cout << H << " ";
debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
template <typename T>
std::ostream &operator<<(std::ostream &os, std::vector<T> vec) {
for (std::size_t i = 0; i < vec.size(); i++)
os << vec[i] << (i + 1 == vec.size() ? "" : " ");
return os;
}
inline void IN(void) { return; }
template <typename First, typename... Rest>
void IN(First &first, Rest &...rest) {
cin >> first;
IN(rest...);
return;
}
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;
}
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
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> sa(n), sb(m);
rep(i, n) sa[i + 1] = sa[i] + a[i];
rep(i, m) sb[i + 1] = sb[i] + b[i];
ll ans = 0;
rep(i, n + 1) {
if (sa[i] > k)
continue;
ll ok = 0, ng = m + 1;
while (abs(ok - ng) > 1) {
ll mid = (ok + ng) / 2;
if (sa[i] + sb[mid] <= k)
ok = mid;
else
ng = mid;
}
chmax(ans, i + ok);
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vl = vector<ll>;
using vvl = vector<vl>;
#define mp make_pair
#define pb push_back
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define all(v) v.begin(), v.end()
#define sz(v) (int)((v).size())
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
#define Sort(v) sort(all(v))
#define Rev(v) reverse(all(v))
#define vec(type, name, ...) vector<type> name(__VA_ARGS__)
#define VEC(type, name, size) \
vector<type> name(size); \
in(name)
#define vv(type, name, h, ...) \
vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define VV(type, name, h, w) \
vector<vector<type>> name(h, vector<type>(w)); \
in(name)
void debug_out() { cout << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
cout << H << " ";
debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
template <typename T>
std::ostream &operator<<(std::ostream &os, std::vector<T> vec) {
for (std::size_t i = 0; i < vec.size(); i++)
os << vec[i] << (i + 1 == vec.size() ? "" : " ");
return os;
}
inline void IN(void) { return; }
template <typename First, typename... Rest>
void IN(First &first, Rest &...rest) {
cin >> first;
IN(rest...);
return;
}
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;
}
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
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> sa(n + 1), sb(m + 1);
rep(i, n) sa[i + 1] = sa[i] + a[i];
rep(i, m) sb[i + 1] = sb[i] + b[i];
ll ans = 0;
rep(i, n + 1) {
if (sa[i] > k)
continue;
ll ok = 0, ng = m + 1;
while (abs(ok - ng) > 1) {
ll mid = (ok + ng) / 2;
if (sa[i] + sb[mid] <= k)
ok = mid;
else
ng = mid;
}
chmax(ans, i + ok);
}
cout << ans << endl;
} | replace | 78 | 79 | 78 | 79 | -6 | munmap_chunk(): invalid pointer
|
p02623 | C++ | Runtime Error | #include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define INF 1234567890
#define pii pair<LL, LL>
#define LL long long
using namespace std;
int main() {
// clock_t start = clock();
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
LL n, m, k;
cin >> n >> m >> k;
LL a[n + 5], b[n + 5];
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
for (LL i = 1; i <= n; i++) {
cin >> a[i];
a[i] += a[i - 1];
}
for (LL i = 1; i <= m; i++) {
cin >> b[i];
b[i] += b[i - 1];
}
LL ansreal = 0;
for (LL i = 0; i <= n; i++) {
LL x = i;
LL rem = k - a[x];
if (rem < 0)
continue;
LL l = 1, r = m, ans = 0;
while (l <= r) {
LL mid = (l + r) / 2;
if (b[mid] <= rem) {
ans = mid;
l = mid + 1;
} else {
r = mid - 1;
}
}
ansreal = max(ansreal, i + ans);
}
cout << ansreal << endl;
// cerr << fixed << setprecision(3) << (clock()-start)*1./CLOCKS_PER_SEC <<
// endl;
return 0;
} | #include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define INF 1234567890
#define pii pair<LL, LL>
#define LL long long
using namespace std;
int main() {
// clock_t start = clock();
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
LL n, m, k;
cin >> n >> m >> k;
LL a[n + 5], b[m + 5];
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
for (LL i = 1; i <= n; i++) {
cin >> a[i];
a[i] += a[i - 1];
}
for (LL i = 1; i <= m; i++) {
cin >> b[i];
b[i] += b[i - 1];
}
LL ansreal = 0;
for (LL i = 0; i <= n; i++) {
LL x = i;
LL rem = k - a[x];
if (rem < 0)
continue;
LL l = 1, r = m, ans = 0;
while (l <= r) {
LL mid = (l + r) / 2;
if (b[mid] <= rem) {
ans = mid;
l = mid + 1;
} else {
r = mid - 1;
}
}
ansreal = max(ansreal, i + ans);
}
cout << ansreal << endl;
// cerr << fixed << setprecision(3) << (clock()-start)*1./CLOCKS_PER_SEC <<
// endl;
return 0;
} | replace | 18 | 19 | 18 | 19 | 0 | |
p02623 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define MP make_pair
#define EACH(i, c) for (auto i : c)
#define SORT(c) sort((c).begin(), (c).end())
#define ALL(a) (a).begin(), (a).end()
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
LL N, M, K;
cin >> N >> M >> K;
vector<LL> A(N), B(N);
REP(i, N) cin >> A[i];
REP(i, M) cin >> B[i];
LL a = 0, b = 0;
REP(j, M) b += B[j];
LL j = M;
LL ret = 0;
REP(i, N + 1) {
if (0 < i)
a += A[i - 1];
while (0 < j && K < a + b) {
b -= B[j - 1];
j--;
}
if (a + b <= K)
ret = max(i + j, ret);
}
cout << ret << endl;
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define MP make_pair
#define EACH(i, c) for (auto i : c)
#define SORT(c) sort((c).begin(), (c).end())
#define ALL(a) (a).begin(), (a).end()
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
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];
LL a = 0, b = 0;
REP(j, M) b += B[j];
LL j = M;
LL ret = 0;
REP(i, N + 1) {
if (0 < i)
a += A[i - 1];
while (0 < j && K < a + b) {
b -= B[j - 1];
j--;
}
if (a + b <= K)
ret = max(i + j, ret);
}
cout << ret << endl;
return 0;
}
| replace | 60 | 61 | 60 | 61 | 0 | |
p02623 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define INF 1000000000
using namespace std;
int main() {
long long n, m, k;
cin >> n >> m >> k;
vector<long long> a(n), b(m);
long long i, j;
for (i = 0; i < n; i++)
cin >> a[i];
for (i = 0; i < m; i++)
cin >> b[i];
vector<long long> aa(n + 1), bb(m + 1);
aa[i] = 0;
bb[i] = 0;
for (i = 1; i <= n; i++) {
aa[i] = aa[i - 1] + a[i - 1];
}
for (j = 1; j <= m; j++) {
bb[j] = bb[j - 1] + b[j - 1];
}
long long cnt = 0;
for (i = 0; i < n + 1; i++) {
if (aa[i] > k)
break;
long long tmp = 0;
tmp += i;
j = lower_bound(bb.begin(), bb.end(), k - aa[i]) - bb.begin();
if (bb[j] == k - aa[i])
tmp += j;
else
tmp += (j - 1);
cnt = max(cnt, tmp);
}
cout << cnt << endl;
} | #include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define INF 1000000000
using namespace std;
int main() {
long long n, m, k;
cin >> n >> m >> k;
vector<long long> a(n), b(m);
long long i, j;
for (i = 0; i < n; i++)
cin >> a[i];
for (i = 0; i < m; i++)
cin >> b[i];
vector<long long> aa(n + 1), bb(m + 1);
aa[0] = 0;
bb[0] = 0;
for (i = 1; i <= n; i++) {
aa[i] = aa[i - 1] + a[i - 1];
}
for (j = 1; j <= m; j++) {
bb[j] = bb[j - 1] + b[j - 1];
}
long long cnt = 0;
for (i = 0; i < n + 1; i++) {
if (aa[i] > k)
break;
long long tmp = 0;
tmp += i;
j = lower_bound(bb.begin(), bb.end(), k - aa[i]) - bb.begin();
if (bb[j] == k - aa[i])
tmp += j;
else
tmp += (j - 1);
cnt = max(cnt, tmp);
}
cout << cnt << endl;
} | replace | 33 | 35 | 33 | 35 | 0 | |
p02623 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
ll k;
cin >> n >> m >> k;
vector<int> a(n + 1, 0);
vector<int> b(m + 1, 0);
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= m; i++)
cin >> b[i];
vector<ll> sum(m + 1, 0);
for (int i = 1; i <= m; i++)
sum[i] = sum[i - 1] + a[i];
int x = m;
int res = 0;
ll now = 0;
for (int i = 0; i <= n; i++) {
now += a[i];
if (now > k)
break;
while (now + sum[x] > k)
x--;
res = max(res, i + x);
}
cout << res << "\n";
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
ll k;
cin >> n >> m >> k;
vector<int> a(n + 1, 0);
vector<int> b(m + 1, 0);
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= m; i++)
cin >> b[i];
vector<ll> sum(m + 1, 0);
for (int i = 1; i <= m; i++)
sum[i] = sum[i - 1] + b[i];
int x = m;
int res = 0;
ll now = 0;
for (int i = 0; i <= n; i++) {
now += a[i];
if (now > k)
break;
while (now + sum[x] > k)
x--;
res = max(res, i + x);
}
cout << res << "\n";
return 0;
}
| replace | 19 | 20 | 19 | 20 | 0 | |
p02623 | C++ | Runtime Error | #pragma GCC optimize("Ofast")
#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;
// smaller names
#define int long long
#define double long double
#define Int signed
#define vi vector<int>
#define vvi vector<vi>
#define vd vector<double>
#define vvd vector<vd>
#define pii pair<int, int>
#define vpii vector<pii>
#define vvpii vector<vpii>
#define mii map<int, int>
#define unordered_map gp_hash_table
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, a, b) for (int i = a; i < b; i++)
#define repd2(i, a, b) for (int i = b - 1; i >= a; i--)
#define repd(i, n) for (int i = n - 1; i >= 0; i--)
#define F first
#define S second
#define fastio \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(v) v.begin(), v.end()
const int INF = 1e9;
const double EPS = 1e-9;
const double PI = acosl(-1);
// order_of_key(k) - number of elements e such that func(e, k) returns true,
// where func is less or less_equal find_by_order(k) - kth element in the set
// counting from 0
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_multiset;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 5;
const int maxa = 1e6 + 5;
const int logmax = 25;
// fast exponentiation
template <typename T> T power(T a, int n = 1, T id = 1) {
T ans = id;
while (n) {
if (n & 1)
ans *= a;
a *= a;
n >>= 1;
}
return ans;
}
// custom hash
struct custom_hash {
// http://xorshift.di.unimi.it/splitmix64.c
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM =
chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
int sumdigs(int n) {
int ans = 0;
while (n) {
ans += n % 10;
n /= 10;
}
return ans;
}
void solve() {
int n, m, k;
cin >> n >> m >> k;
vi a(n);
vi b(m);
vi prea(n + 1), preb(n + 1);
rep(i, n) cin >> a[i];
rep(i, m) cin >> b[i];
rep(i, n) prea[i + 1] = prea[i] + a[i];
rep(i, m) preb[i + 1] = preb[i] + b[i];
int fin = 0;
rep(i, n + 1) {
int tar = k - prea[i];
if (tar < 0)
continue;
int ans = 0;
int left = 0, right = m;
while (left <= right) {
int mid = (left + right) / 2;
if (preb[mid] <= tar) {
ans = mid;
left = mid + 1;
} else
right = mid - 1;
}
fin = max(ans + i, fin);
}
cout << fin << endl;
}
signed main() {
fastio;
cout << setprecision(6) << fixed;
int t = 1;
// cin >> t;
while (t--) {
solve();
}
}
| #pragma GCC optimize("Ofast")
#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;
// smaller names
#define int long long
#define double long double
#define Int signed
#define vi vector<int>
#define vvi vector<vi>
#define vd vector<double>
#define vvd vector<vd>
#define pii pair<int, int>
#define vpii vector<pii>
#define vvpii vector<vpii>
#define mii map<int, int>
#define unordered_map gp_hash_table
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, a, b) for (int i = a; i < b; i++)
#define repd2(i, a, b) for (int i = b - 1; i >= a; i--)
#define repd(i, n) for (int i = n - 1; i >= 0; i--)
#define F first
#define S second
#define fastio \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(v) v.begin(), v.end()
const int INF = 1e9;
const double EPS = 1e-9;
const double PI = acosl(-1);
// order_of_key(k) - number of elements e such that func(e, k) returns true,
// where func is less or less_equal find_by_order(k) - kth element in the set
// counting from 0
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_multiset;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 5;
const int maxa = 1e6 + 5;
const int logmax = 25;
// fast exponentiation
template <typename T> T power(T a, int n = 1, T id = 1) {
T ans = id;
while (n) {
if (n & 1)
ans *= a;
a *= a;
n >>= 1;
}
return ans;
}
// custom hash
struct custom_hash {
// http://xorshift.di.unimi.it/splitmix64.c
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM =
chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
int sumdigs(int n) {
int ans = 0;
while (n) {
ans += n % 10;
n /= 10;
}
return ans;
}
void solve() {
int n, m, k;
cin >> n >> m >> k;
vi a(n);
vi b(m);
vi prea(n + 1), preb(m + 1);
rep(i, n) cin >> a[i];
rep(i, m) cin >> b[i];
rep(i, n) prea[i + 1] = prea[i] + a[i];
rep(i, m) preb[i + 1] = preb[i] + b[i];
int fin = 0;
rep(i, n + 1) {
int tar = k - prea[i];
if (tar < 0)
continue;
int ans = 0;
int left = 0, right = m;
while (left <= right) {
int mid = (left + right) / 2;
if (preb[mid] <= tar) {
ans = mid;
left = mid + 1;
} else
right = mid - 1;
}
fin = max(ans + i, fin);
}
cout << fin << endl;
}
signed main() {
fastio;
cout << setprecision(6) << fixed;
int t = 1;
// cin >> t;
while (t--) {
solve();
}
}
| replace | 105 | 106 | 105 | 106 | 0 | |
p02623 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int, int> PII;
typedef double db;
// mt19937 mrand(random_device{}());
const ll mod = 1000000007;
// int rnd(int x) { return mrand() % x;}
ll powmod(ll a, ll b) {
ll res = 1;
a %= mod;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1)
res = res * a % mod;
a = a * a % mod;
}
return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// head
const int maxx = 1e6 + 10;
ll a[maxx] = {0}, b[maxx] = {0};
int main() {
ll n, m, k;
cin >> n >> m >> k;
rep(i, 1, n + 1) {
cin >> a[i];
a[i] += a[i - 1];
}
rep(i, 1, m + 1) {
cin >> b[i];
b[i] += b[i - 1];
}
ll ans = 0;
for (ll i = 0; i <= n; i++) {
if (a[i] > k)
break;
for (ll j = 0; j <= m; j++) {
if (b[j] > k)
break;
if (a[i] + b[j] > k)
break;
if (a[i] + b[j] <= k)
ans = max(ans, i + j);
}
}
cout << ans;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int, int> PII;
typedef double db;
// mt19937 mrand(random_device{}());
const ll mod = 1000000007;
// int rnd(int x) { return mrand() % x;}
ll powmod(ll a, ll b) {
ll res = 1;
a %= mod;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1)
res = res * a % mod;
a = a * a % mod;
}
return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// head
const int maxx = 1e6 + 10;
ll a[maxx] = {0}, b[maxx] = {0};
int main() {
ll n, m, k;
cin >> n >> m >> k;
rep(i, 1, n + 1) {
cin >> a[i];
a[i] += a[i - 1];
}
rep(i, 1, m + 1) {
cin >> b[i];
b[i] += b[i - 1];
}
int ans = 0;
for (int i = 0, j = m; i <= n; i++) {
while (j && a[i] + b[j] > k)
j--;
if (a[i] + b[j] <= k)
ans = max(ans, i + j);
}
cout << ans;
} | replace | 44 | 56 | 44 | 50 | TLE | |
p02623 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
int bs(vector<ll> b, ll tar) {
int start = 0, end = b.size() - 1;
int ans = -1;
while (start <= end) {
int mid = start + (end - start) / 2;
if (b[mid] <= tar) {
ans = mid;
start = mid + 1;
} else
end = mid - 1;
}
return ans;
}
int solve(vector<ll> a, vector<ll> b, ll k) {
int res = 0;
ll left;
for (int i = 0; i < a.size(); ++i) {
left = k - a[i];
if (left < 0)
break;
int index = bs(b, left);
if (index == -1)
break;
res = max(res, i + index);
}
return res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
ll k, now;
cin >> n >> m;
cin >> k;
vector<ll> a(n + 1), b(m + 1);
a[0] = 0;
b[0] = 0;
rep(i, n) {
cin >> now;
a[i + 1] = now + a[i];
}
rep(i, m) {
cin >> now;
b[i + 1] = now + b[i];
}
int res = max(solve(a, b, k), solve(b, a, k));
cout << res << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
int bs(vector<ll> b, ll tar) {
int start = 0, end = b.size() - 1;
int ans = -1;
while (start <= end) {
int mid = start + (end - start) / 2;
if (b[mid] <= tar) {
ans = mid;
start = mid + 1;
} else
end = mid - 1;
}
return ans;
}
int solve(vector<ll> a, vector<ll> b, ll k) {
int res = 0;
ll left;
for (int i = 0; i < a.size(); ++i) {
left = k - a[i];
if (left < 0)
break;
int index = bs(b, left);
if (index == -1)
break;
res = max(res, i + index);
}
return res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
ll k, now;
cin >> n >> m;
cin >> k;
vector<ll> a(n + 1), b(m + 1);
a[0] = 0;
b[0] = 0;
rep(i, n) {
cin >> now;
a[i + 1] = now + a[i];
}
rep(i, m) {
cin >> now;
b[i + 1] = now + b[i];
}
ll ans = 0;
rep(i, n + 1) {
ll cur = k - a[i];
if (cur >= 0) {
ll cur2 = upper_bound(b.begin(), b.end(), cur) - b.begin() - 1;
ans = max(ans, i + cur2);
}
}
cout << ans << endl;
} | replace | 54 | 57 | 54 | 63 | TLE | |
p02623 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
typedef long long ll;
int main(int argc, char *argv[]) {
ll n, m, k;
std::vector<ll> a, b;
// 入力
std::cin >> n >> m >> k;
a.resize(n);
b.resize(m);
for (int i = 0; i < n; i++) {
std::cin >> a[i];
}
for (int i = 0; i < m; i++) {
std::cin >> b[i];
}
// pre
std::vector<ll> aSum(n + 1), bSum(m + 1);
aSum[0] = 0;
bSum[0] = 0;
for (int i = 0; i < n; i++) {
aSum[i + 1] = aSum[i] + a[i];
}
for (int i = 0; i < m; i++) {
bSum[i + 1] = bSum[i] + a[i];
}
int aPtr, bPtr;
for (aPtr = 0; aPtr < n; aPtr++) {
if (aSum[aPtr + 1] > k) {
break;
}
}
for (bPtr = 0; bPtr < m; bPtr++) {
if (aSum[aPtr] + bSum[bPtr + 1] > k) {
break;
}
}
// solve
int max = aPtr + bPtr;
for (; aPtr >= 0; aPtr--) {
for (; bPtr < m; bPtr++) {
if (aSum[aPtr] + bSum[bPtr + 1] > k) {
break;
}
}
max = std::max(max, aPtr + bPtr);
}
std::cout << max << std::endl;
return 0;
}
| #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
typedef long long ll;
int main(int argc, char *argv[]) {
ll n, m, k;
std::vector<ll> a, b;
// 入力
std::cin >> n >> m >> k;
a.resize(n);
b.resize(m);
for (int i = 0; i < n; i++) {
std::cin >> a[i];
}
for (int i = 0; i < m; i++) {
std::cin >> b[i];
}
// pre
std::vector<ll> aSum(n + 1), bSum(m + 1);
aSum[0] = 0;
bSum[0] = 0;
for (int i = 0; i < n; i++) {
aSum[i + 1] = aSum[i] + a[i];
}
for (int i = 0; i < m; i++) {
bSum[i + 1] = bSum[i] + b[i];
}
int aPtr, bPtr;
for (aPtr = 0; aPtr < n; aPtr++) {
if (aSum[aPtr + 1] > k) {
break;
}
}
for (bPtr = 0; bPtr < m; bPtr++) {
if (aSum[aPtr] + bSum[bPtr + 1] > k) {
break;
}
}
// solve
int max = aPtr + bPtr;
for (; aPtr >= 0; aPtr--) {
for (; bPtr < m; bPtr++) {
if (aSum[aPtr] + bSum[bPtr + 1] > k) {
break;
}
}
max = std::max(max, aPtr + bPtr);
}
std::cout << max << std::endl;
return 0;
}
| replace | 39 | 40 | 39 | 40 | 0 | |
p02623 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define debug(x) \
cerr << endl << "DEBUG: (" << (#x) << " = " << x << ")" << endl;
#define debugArray(v) \
for (auto i : v) \
cerr << i << " "; \
cerr << endl;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const long long INFLL = 0x3f3f3f3f3f3f3f3fLL;
const long double EPS = 1e-9;
const long double PI = acos(-1.0);
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n, m, k;
cin >> n >> m >> k;
vector<long long> a(n + 1), b(n + 1);
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 ans = 0;
for (int i = 0, j = m; i <= n; i++) {
if (a[i] > k)
break;
while (a[i] + b[j] > k && j >= 0)
j--;
ans = max(ans, i + j);
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define debug(x) \
cerr << endl << "DEBUG: (" << (#x) << " = " << x << ")" << endl;
#define debugArray(v) \
for (auto i : v) \
cerr << i << " "; \
cerr << endl;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const long long INFLL = 0x3f3f3f3f3f3f3f3fLL;
const long double EPS = 1e-9;
const long double PI = acos(-1.0);
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n, m, k;
cin >> n >> m >> k;
vector<long long> a(n + 1), b(m + 1);
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 ans = 0;
for (int i = 0, j = m; i <= n; i++) {
if (a[i] > k)
break;
while (a[i] + b[j] > k && j >= 0)
j--;
ans = max(ans, i + j);
}
cout << ans << endl;
return 0;
} | replace | 25 | 26 | 25 | 26 | 0 | |
p02623 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array) / sizeof(array[0]))
#define DEBUG 0
#define LIMIT (LONG_MAX / 10)
#define POSITIVE_LAST_D (LONG_MAX % 10)
using ll = long long;
using namespace std;
using Graph = vector<vector<int>>;
int main() {
ll n, m, k;
cin >> n >> m >> k;
vector<ll> a(n);
rep(i, n) cin >> a[i];
vector<ll> b(m);
rep(i, m) cin >> b[i];
vector<ll> sa(n + 1, 0);
rep(i, n) { sa[i + 1] = sa[i] + a[i]; }
vector<ll> sb(m + 1, 0);
rep(i, m) { sb[i + 1] = sb[i] + b[i]; }
ll ans = 0;
rep(i, n + 1) {
ll j = m;
while (1) {
if (sa[i] + sb[j] <= k) {
ans = max(i + j, ans);
break;
} else {
--j;
--m;
}
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array) / sizeof(array[0]))
#define DEBUG 0
#define LIMIT (LONG_MAX / 10)
#define POSITIVE_LAST_D (LONG_MAX % 10)
using ll = long long;
using namespace std;
using Graph = vector<vector<int>>;
int main() {
ll n, m, k;
cin >> n >> m >> k;
vector<ll> a(n);
rep(i, n) cin >> a[i];
vector<ll> b(m);
rep(i, m) cin >> b[i];
vector<ll> sa(n + 1, 0);
rep(i, n) { sa[i + 1] = sa[i] + a[i]; }
vector<ll> sb(m + 1, 0);
rep(i, m) { sb[i + 1] = sb[i] + b[i]; }
ll ans = 0;
rep(i, n + 1) {
ll j = m;
while (j >= 0) {
if (sa[i] + sb[j] <= k) {
ans = max(i + j, ans);
break;
} else {
--j;
--m;
}
}
}
cout << ans << endl;
} | replace | 25 | 26 | 25 | 26 | -11 | |
p02623 | C++ | Runtime Error | /*
vectorの配列を吐き出す関数はvfillと同じ要領で簡潔に書けそう
だけど面倒
vfillの範囲指定をできるようにしたい
*/
#pragma GCC optimize("Ofast")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <future>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <thread>
#include <tuple>
#include <vector>
using namespace std;
using ll = int_fast64_t;
using u64 = uint_fast64_t;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
using psi = pair<string, int>;
using pis = pair<int, string>;
using psl = pair<string, ll>;
using pls = pair<ll, string>;
using pss = pair<string, string>;
// 辺 fromあり
template <typename T> struct Edge {
int from, to;
T cost;
Edge() = default;
Edge(int _from, int _to, T _cost) : from(_from), to(_to), cost(_cost) {}
inline bool operator<(const Edge p) const noexcept { return cost < p.cost; }
inline bool operator>(const Edge p) const noexcept { return cost > p.cost; }
};
// 辺 fromがない
template <typename T> struct edge {
int to;
T cost;
edge() = default;
edge(int _to, T _cost) : to(_to), cost(_cost) {}
};
template <typename T> using edges = vector<edge<T>>;
template <typename T> using WeightGraph = vector<edges<T>>;
using Graph = vector<vector<int>>;
template <class T, class U> inline constexpr bool chmin(T &a, const U b) {
if (a <= b)
return false;
a = b;
return true;
}
template <class T, class U> inline constexpr bool chmax(T &a, const U b) {
if (a >= b)
return false;
a = b;
return true;
}
#define bit(n, k) (((n) >> (k)) & 1)
inline void bin101() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(20);
}
// 1-indexed vector cin
template <typename T> inline void vin1(vector<T> &v) {
for (size_t i = 1; i < v.size(); i++)
cin >> v[i];
}
// 0-indexed vector cin
template <typename T> inline void vin0(vector<T> &v) {
for (size_t i = 0; i < v.size(); i++)
cin >> v[i];
}
// 1-indexed vector<vector> cin
template <typename T> inline void vin1(vector<vector<T>> &v) {
for (size_t i = 1; i < v.size(); i++) {
for (size_t j = 1; j < v[i].size(); j++)
cin >> v[i][j];
}
}
// 0-indexed vector<vector> cin
template <typename T> inline void vin0(vector<vector<T>> &v) {
for (size_t i = 0; i < v.size(); i++) {
for (size_t j = 0; j < v[i].size(); j++)
cin >> v[i][j];
}
}
bool DEBUG_MODE = false;
#define debug(a) \
if (DEBUG_MODE) { \
cout << #a; \
PRINT(a); \
cout << flush; \
}
#define debug2(a, b) \
if (DEBUG_MODE) { \
debug(a); \
debug(b); \
}
#define debug3(a, b, c) \
if (DEBUG_MODE) { \
debug(a); \
debug(b); \
debug(c); \
}
#define debug4(a, b, c, d) \
if (DEBUG_MODE) { \
debug(a); \
debug(b); \
debug(c); \
debug(d); \
}
#define debug5(a, b, c, d, e) \
if (DEBUG_MODE) { \
debug(a); \
debug(b); \
debug(c); \
debug(d); \
debug(e); \
}
#define gdebug(x) \
if (DEBUG_MODE) { \
cout << #x; \
GPRINT(x); \
}
template <class T> void PRINT(const T x) { cout << ":" << x << "\n"; }
// デバッグ
template <typename T> void PRINT(const vector<T> &v, int a = -1) {
if (!DEBUG_MODE)
return;
cout << ":1d\n";
for (size_t i = 0; i < v.size() and (a < 0 or i <= (size_t)a); i++) {
cout << i << ":" << v[i] << '\n';
}
cout << "\n";
}
// デバッグ
template <typename T>
void PRINT(const vector<vector<T>> &v, int a = -1, int b = -1) {
if (!DEBUG_MODE)
return;
cout << ":2d\n";
for (size_t i = 0; i < v.size() and (a < 0 or i <= (size_t)a); i++) {
for (size_t j = 0; j < v[i].size() and (b < 0 or j <= (size_t)b); j++) {
cout << i << "-" << j << ":" << v[i][j] << "\n";
}
}
cout << "\n";
}
// デバッグ
template <typename T>
void PRINT(const vector<vector<vector<T>>> &v, int a = -1, int b = -1,
int c = -1) {
if (!DEBUG_MODE)
return;
cout << ":3d\n";
for (size_t i = 0; i < v.size() and (a < 0 or i <= (size_t)a); i++) {
for (size_t j = 0; j < v[i].size() and (b < 0 or j <= (size_t)b); j++) {
for (size_t k = 0; k < v[i][j].size() and (c < 0 or k <= (size_t)c);
k++) {
cout << i << "-" << j << "-" << k << ":" << v[i][j][k] << "\n";
}
}
}
cout << "\n";
}
// デバッグ
template <typename T>
void PRINT(const vector<vector<vector<vector<T>>>> &v, int a = -1, int b = -1,
int c = -1, int d = -1) {
if (!DEBUG_MODE)
return;
cout << ":4d\n";
for (size_t i = 0; i < v.size() and (a < 0 or i <= (size_t)a); i++) {
for (size_t j = 0; j < v[i].size() and (b < 0 or j <= (size_t)b); j++) {
for (size_t k = 0; k < v[i][j].size() and (c < 0 or k <= (size_t)c);
k++) {
for (size_t l = 0; l < v[i][j][k].size() and (d < 0 or l <= (size_t)d);
l++) {
cout << i << "-" << j << "-" << k << "-" << l << ":" << v[i][j][k][l]
<< "\n";
}
}
}
}
cout << "\n";
}
// デバッグ
template <typename T>
void PRINT(const vector<vector<vector<vector<vector<T>>>>> &v, int a = -1,
int b = -1, int c = -1, int d = -1, int e = -1) {
if (!DEBUG_MODE)
return;
cout << ":5d\n";
for (size_t i = 0; i < v.size() and (a < 0 or i <= (size_t)a); i++) {
for (size_t j = 0; j < v[i].size() and (b < 0 or j <= (size_t)b); j++) {
for (size_t k = 0; k < v[i][j].size() and (c < 0 or k <= (size_t)c);
k++) {
for (size_t l = 0; l < v[i][j][k].size() and (d < 0 or l <= (size_t)d);
l++) {
for (size_t m = 0;
m < v[i][j][k][l].size() and (e < 0 or m <= (size_t)e); m++) {
cout << i << "-" << j << "-" << k << "-" << l << "-" << m << ":"
<< v[i][j][k][l][m] << "\n";
}
}
}
}
}
cout << "\n";
}
template <typename T> void PRINT(const set<T> &S) {
if (!DEBUG_MODE)
return;
int now = 0;
for (auto x : S) {
cout << now++ << ":" << x << "\n";
}
}
template <typename T, typename U> void PRINT(const map<T, U> &M) {
if (!DEBUG_MODE)
return;
cout << ":map\n";
size_t now = 0;
for (auto &x : M) {
cout << now++ << ":" << x << "\n";
}
}
// デバッグ(グリッド)
template <typename T> void GPRINT(const vector<T> &v, int a = -1) {
if (!DEBUG_MODE)
return;
cout << ":1d\n";
for (size_t i = 0; i < v.size() and (a < 0 or i <= (size_t)a); i++) {
if (i)
cout << ",";
cout << v[i];
}
}
// デバッグ(グリッド)
template <typename T>
void GPRINT(const vector<vector<T>> &v, int a = -1, int b = -1) {
if (!DEBUG_MODE)
return;
cout << ":2d\n";
for (size_t i = 0; i < v.size() and (a < 0 or i <= (size_t)a); i++) {
for (size_t j = 0; j < v[i].size() and (b < 0 or j <= (size_t)b); j++) {
if (j)
cout << ",";
cout << v[i][j];
}
cout << "\n";
}
}
// pair cout
template <typename T, typename U>
inline ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << p.first << " " << p.second;
return os;
}
// pair cin
template <typename T, typename U>
inline istream &operator>>(istream &is, pair<T, U> &p) {
is >> p.first >> p.second;
return is;
}
// ソート
template <typename T> inline void vsort(vector<T> &v) {
sort(v.begin(), v.end());
}
// 逆順ソート
template <typename T> inline void rvsort(vector<T> &v) {
sort(v.rbegin(), v.rend());
}
// 要素数n 初期値x
template <typename T> inline vector<T> vmake(size_t n, T x) {
return vector<T>(n, x);
}
// a,b,c,x data[a][b][c] 初期値x
template <typename... Args> auto vmake(size_t n, Args... args) {
auto v = vmake(args...);
return vector<decltype(v)>(n, move(v));
}
template <typename T, typename... X> inline void vfill(T &t, const X... x) {
t = T(x...);
}
template <typename T, typename... X> void vfill(vector<T> &t, const X... x) {
for (auto &s : t)
vfill(s, x...);
}
// 最後に改行があるので注意
template <typename T>
void vout(const vector<T> &v, string s = " ", size_t f = 0, int t = -1) {
for (size_t i = f; i < v.size() and (t < 0 or i <= (size_t)t); i++) {
if (i != f)
cout << s;
cout << v[i];
}
cout << "\n";
}
// 最後に改行があるので注意
template <typename T>
void vout(const vector<vector<T>> &v, string s = " ", int fh = 0, int th = -1,
int fw = 0, int tw = -1) {
for (size_t i = fh; i < v.size() and (th < 0 or i <= (size_t)th); i++) {
for (size_t j = fw; j < v[i].size() and (tw < 0 or j <= (size_t)tw); j++) {
if (j != fw)
cout << s;
cout << v[i][j];
}
cout << "\n";
}
}
// 1ビットの数を返す
inline int popcount(int x) { return __builtin_popcount(x); }
// 1ビットの数を返す
inline int popcount(ll x) { return __builtin_popcountll(x); }
constexpr int MAX = (1 << 30) - 1;
constexpr ll INF = (1LL << 62) - 1;
constexpr ll MOD = 1e9 + 7;
constexpr int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, -1, 1};
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
int main() {
DEBUG_MODE = true;
bin101();
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
int N, M;
ll K;
cin >> N >> M >> K;
vector<ll> A(N + 1), B(M + 1);
vin1(A);
vin1(B);
vector<ll> SA(N + 1), SB(M + 1);
for (int i = 1; i <= N; i++) {
SA[i] = SA[i - 1] + A[i];
}
for (int i = 1; i <= M; i++) {
SB[i] = SB[i - 1] + B[i];
}
ll ok = -1, ng = N + M + 1;
while (ng - ok != 1) {
ll mid = (ng + ok) / 2;
bool flag = false;
for (int i = 0; i <= N; i++) {
if (mid - i > M)
continue;
if (SA[i] + SB[mid - i] <= K)
flag = true;
}
if (flag)
ok = mid;
else
ng = mid;
}
cout << ok << endl;
} | /*
vectorの配列を吐き出す関数はvfillと同じ要領で簡潔に書けそう
だけど面倒
vfillの範囲指定をできるようにしたい
*/
#pragma GCC optimize("Ofast")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <future>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <thread>
#include <tuple>
#include <vector>
using namespace std;
using ll = int_fast64_t;
using u64 = uint_fast64_t;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
using psi = pair<string, int>;
using pis = pair<int, string>;
using psl = pair<string, ll>;
using pls = pair<ll, string>;
using pss = pair<string, string>;
// 辺 fromあり
template <typename T> struct Edge {
int from, to;
T cost;
Edge() = default;
Edge(int _from, int _to, T _cost) : from(_from), to(_to), cost(_cost) {}
inline bool operator<(const Edge p) const noexcept { return cost < p.cost; }
inline bool operator>(const Edge p) const noexcept { return cost > p.cost; }
};
// 辺 fromがない
template <typename T> struct edge {
int to;
T cost;
edge() = default;
edge(int _to, T _cost) : to(_to), cost(_cost) {}
};
template <typename T> using edges = vector<edge<T>>;
template <typename T> using WeightGraph = vector<edges<T>>;
using Graph = vector<vector<int>>;
template <class T, class U> inline constexpr bool chmin(T &a, const U b) {
if (a <= b)
return false;
a = b;
return true;
}
template <class T, class U> inline constexpr bool chmax(T &a, const U b) {
if (a >= b)
return false;
a = b;
return true;
}
#define bit(n, k) (((n) >> (k)) & 1)
inline void bin101() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(20);
}
// 1-indexed vector cin
template <typename T> inline void vin1(vector<T> &v) {
for (size_t i = 1; i < v.size(); i++)
cin >> v[i];
}
// 0-indexed vector cin
template <typename T> inline void vin0(vector<T> &v) {
for (size_t i = 0; i < v.size(); i++)
cin >> v[i];
}
// 1-indexed vector<vector> cin
template <typename T> inline void vin1(vector<vector<T>> &v) {
for (size_t i = 1; i < v.size(); i++) {
for (size_t j = 1; j < v[i].size(); j++)
cin >> v[i][j];
}
}
// 0-indexed vector<vector> cin
template <typename T> inline void vin0(vector<vector<T>> &v) {
for (size_t i = 0; i < v.size(); i++) {
for (size_t j = 0; j < v[i].size(); j++)
cin >> v[i][j];
}
}
bool DEBUG_MODE = false;
#define debug(a) \
if (DEBUG_MODE) { \
cout << #a; \
PRINT(a); \
cout << flush; \
}
#define debug2(a, b) \
if (DEBUG_MODE) { \
debug(a); \
debug(b); \
}
#define debug3(a, b, c) \
if (DEBUG_MODE) { \
debug(a); \
debug(b); \
debug(c); \
}
#define debug4(a, b, c, d) \
if (DEBUG_MODE) { \
debug(a); \
debug(b); \
debug(c); \
debug(d); \
}
#define debug5(a, b, c, d, e) \
if (DEBUG_MODE) { \
debug(a); \
debug(b); \
debug(c); \
debug(d); \
debug(e); \
}
#define gdebug(x) \
if (DEBUG_MODE) { \
cout << #x; \
GPRINT(x); \
}
template <class T> void PRINT(const T x) { cout << ":" << x << "\n"; }
// デバッグ
template <typename T> void PRINT(const vector<T> &v, int a = -1) {
if (!DEBUG_MODE)
return;
cout << ":1d\n";
for (size_t i = 0; i < v.size() and (a < 0 or i <= (size_t)a); i++) {
cout << i << ":" << v[i] << '\n';
}
cout << "\n";
}
// デバッグ
template <typename T>
void PRINT(const vector<vector<T>> &v, int a = -1, int b = -1) {
if (!DEBUG_MODE)
return;
cout << ":2d\n";
for (size_t i = 0; i < v.size() and (a < 0 or i <= (size_t)a); i++) {
for (size_t j = 0; j < v[i].size() and (b < 0 or j <= (size_t)b); j++) {
cout << i << "-" << j << ":" << v[i][j] << "\n";
}
}
cout << "\n";
}
// デバッグ
template <typename T>
void PRINT(const vector<vector<vector<T>>> &v, int a = -1, int b = -1,
int c = -1) {
if (!DEBUG_MODE)
return;
cout << ":3d\n";
for (size_t i = 0; i < v.size() and (a < 0 or i <= (size_t)a); i++) {
for (size_t j = 0; j < v[i].size() and (b < 0 or j <= (size_t)b); j++) {
for (size_t k = 0; k < v[i][j].size() and (c < 0 or k <= (size_t)c);
k++) {
cout << i << "-" << j << "-" << k << ":" << v[i][j][k] << "\n";
}
}
}
cout << "\n";
}
// デバッグ
template <typename T>
void PRINT(const vector<vector<vector<vector<T>>>> &v, int a = -1, int b = -1,
int c = -1, int d = -1) {
if (!DEBUG_MODE)
return;
cout << ":4d\n";
for (size_t i = 0; i < v.size() and (a < 0 or i <= (size_t)a); i++) {
for (size_t j = 0; j < v[i].size() and (b < 0 or j <= (size_t)b); j++) {
for (size_t k = 0; k < v[i][j].size() and (c < 0 or k <= (size_t)c);
k++) {
for (size_t l = 0; l < v[i][j][k].size() and (d < 0 or l <= (size_t)d);
l++) {
cout << i << "-" << j << "-" << k << "-" << l << ":" << v[i][j][k][l]
<< "\n";
}
}
}
}
cout << "\n";
}
// デバッグ
template <typename T>
void PRINT(const vector<vector<vector<vector<vector<T>>>>> &v, int a = -1,
int b = -1, int c = -1, int d = -1, int e = -1) {
if (!DEBUG_MODE)
return;
cout << ":5d\n";
for (size_t i = 0; i < v.size() and (a < 0 or i <= (size_t)a); i++) {
for (size_t j = 0; j < v[i].size() and (b < 0 or j <= (size_t)b); j++) {
for (size_t k = 0; k < v[i][j].size() and (c < 0 or k <= (size_t)c);
k++) {
for (size_t l = 0; l < v[i][j][k].size() and (d < 0 or l <= (size_t)d);
l++) {
for (size_t m = 0;
m < v[i][j][k][l].size() and (e < 0 or m <= (size_t)e); m++) {
cout << i << "-" << j << "-" << k << "-" << l << "-" << m << ":"
<< v[i][j][k][l][m] << "\n";
}
}
}
}
}
cout << "\n";
}
template <typename T> void PRINT(const set<T> &S) {
if (!DEBUG_MODE)
return;
int now = 0;
for (auto x : S) {
cout << now++ << ":" << x << "\n";
}
}
template <typename T, typename U> void PRINT(const map<T, U> &M) {
if (!DEBUG_MODE)
return;
cout << ":map\n";
size_t now = 0;
for (auto &x : M) {
cout << now++ << ":" << x << "\n";
}
}
// デバッグ(グリッド)
template <typename T> void GPRINT(const vector<T> &v, int a = -1) {
if (!DEBUG_MODE)
return;
cout << ":1d\n";
for (size_t i = 0; i < v.size() and (a < 0 or i <= (size_t)a); i++) {
if (i)
cout << ",";
cout << v[i];
}
}
// デバッグ(グリッド)
template <typename T>
void GPRINT(const vector<vector<T>> &v, int a = -1, int b = -1) {
if (!DEBUG_MODE)
return;
cout << ":2d\n";
for (size_t i = 0; i < v.size() and (a < 0 or i <= (size_t)a); i++) {
for (size_t j = 0; j < v[i].size() and (b < 0 or j <= (size_t)b); j++) {
if (j)
cout << ",";
cout << v[i][j];
}
cout << "\n";
}
}
// pair cout
template <typename T, typename U>
inline ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << p.first << " " << p.second;
return os;
}
// pair cin
template <typename T, typename U>
inline istream &operator>>(istream &is, pair<T, U> &p) {
is >> p.first >> p.second;
return is;
}
// ソート
template <typename T> inline void vsort(vector<T> &v) {
sort(v.begin(), v.end());
}
// 逆順ソート
template <typename T> inline void rvsort(vector<T> &v) {
sort(v.rbegin(), v.rend());
}
// 要素数n 初期値x
template <typename T> inline vector<T> vmake(size_t n, T x) {
return vector<T>(n, x);
}
// a,b,c,x data[a][b][c] 初期値x
template <typename... Args> auto vmake(size_t n, Args... args) {
auto v = vmake(args...);
return vector<decltype(v)>(n, move(v));
}
template <typename T, typename... X> inline void vfill(T &t, const X... x) {
t = T(x...);
}
template <typename T, typename... X> void vfill(vector<T> &t, const X... x) {
for (auto &s : t)
vfill(s, x...);
}
// 最後に改行があるので注意
template <typename T>
void vout(const vector<T> &v, string s = " ", size_t f = 0, int t = -1) {
for (size_t i = f; i < v.size() and (t < 0 or i <= (size_t)t); i++) {
if (i != f)
cout << s;
cout << v[i];
}
cout << "\n";
}
// 最後に改行があるので注意
template <typename T>
void vout(const vector<vector<T>> &v, string s = " ", int fh = 0, int th = -1,
int fw = 0, int tw = -1) {
for (size_t i = fh; i < v.size() and (th < 0 or i <= (size_t)th); i++) {
for (size_t j = fw; j < v[i].size() and (tw < 0 or j <= (size_t)tw); j++) {
if (j != fw)
cout << s;
cout << v[i][j];
}
cout << "\n";
}
}
// 1ビットの数を返す
inline int popcount(int x) { return __builtin_popcount(x); }
// 1ビットの数を返す
inline int popcount(ll x) { return __builtin_popcountll(x); }
constexpr int MAX = (1 << 30) - 1;
constexpr ll INF = (1LL << 62) - 1;
constexpr ll MOD = 1e9 + 7;
constexpr int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, -1, 1};
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
int main() {
DEBUG_MODE = true;
bin101();
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
int N, M;
ll K;
cin >> N >> M >> K;
vector<ll> A(N + 1), B(M + 1);
vin1(A);
vin1(B);
vector<ll> SA(N + 1), SB(M + 1);
for (int i = 1; i <= N; i++) {
SA[i] = SA[i - 1] + A[i];
}
for (int i = 1; i <= M; i++) {
SB[i] = SB[i - 1] + B[i];
}
ll ok = -1, ng = N + M + 1;
while (ng - ok != 1) {
ll mid = (ng + ok) / 2;
bool flag = false;
for (int i = 0; i <= N; i++) {
if (mid - i > M)
continue;
if (i > mid)
continue;
if (SA[i] + SB[mid - i] <= K)
flag = true;
}
if (flag)
ok = mid;
else
ng = mid;
}
cout << ok << endl;
} | insert | 404 | 404 | 404 | 406 | 0 | |
p02623 | C++ | Runtime Error | #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ull B = 100000007;
int mod = 1000000007;
class Solution {
public:
int c(int n, int m, const vector<int> &t1, const vector<int> &t2, int k) {
int res = 0;
vector<ll> s1(n + 1, 0), s2(m + 1, 0);
for (int i = 1; i < n + 1; ++i) {
s1[i] = s1[i - 1] + t1[i - 1];
}
for (int i = 1; i < m + 1; ++i) {
s2[i] = s2[i - 1] + t2[i - 1];
}
ll l = 0, r = n + m;
while (l <= r) {
ll mid = (l + r) / 2;
ll tres = INT64_MAX;
for (int k1 = 0; k1 <= mid; ++k1) {
tres = min(tres, s1[k1] + s2[mid - k1]);
}
if (tres <= k) {
res = mid;
l = mid + 1;
} else {
r = mid - 1;
}
}
return res;
}
};
int main() {
int n, m, k;
cin >> n >> m >> k;
vector<int> t1(n), t2(m);
for (int i = 0; i < n; ++i)
cin >> t1[i];
for (int i = 0; i < m; ++i)
cin >> t2[i];
Solution zhy;
cout << zhy.c(n, m, t1, t2, k) << endl;
return 0;
} | #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ull B = 100000007;
int mod = 1000000007;
class Solution {
public:
int c(int n, int m, const vector<int> &t1, const vector<int> &t2, int k) {
int res = 0;
vector<ll> s1(n + 1, 0), s2(m + 1, 0);
for (int i = 1; i < n + 1; ++i) {
s1[i] = s1[i - 1] + t1[i - 1];
}
for (int i = 1; i < m + 1; ++i) {
s2[i] = s2[i - 1] + t2[i - 1];
}
ll l = 0, r = n + m;
while (l <= r) {
ll mid = (l + r) / 2;
ll tres = INT64_MAX;
for (int k1 = 0; k1 <= mid; ++k1) {
if (k1 > n || mid - k1 > m) {
continue;
}
tres = min(tres, s1[k1] + s2[mid - k1]);
}
if (tres <= k) {
res = mid;
l = mid + 1;
} else {
r = mid - 1;
}
}
return res;
}
};
int main() {
int n, m, k;
cin >> n >> m >> k;
vector<int> t1(n), t2(m);
for (int i = 0; i < n; ++i)
cin >> t1[i];
for (int i = 0; i < m; ++i)
cin >> t2[i];
Solution zhy;
cout << zhy.c(n, m, t1, t2, k) << endl;
return 0;
} | insert | 26 | 26 | 26 | 29 | 0 | |
p02623 | C++ | Runtime Error | #include <bits/stdc++.h>
typedef long long ll;
using namespace std;
string s, t;
ll a[100500], b[100500], pa[100500], pbb[100500];
int main() {
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
int n, m, x, i;
ll tests = 1;
// cin >> tests;
while (tests--) {
cin >> n >> m >> x;
for (i = 0; i < n; i++) {
cin >> a[i];
pa[i + 1] = pa[i] + a[i];
}
for (i = 0; i < m; i++) {
cin >> b[i];
pbb[i + 1] = pbb[i] + b[i];
}
int ans = 0;
for (i = 0; i <= n; i++) {
if (pa[i] <= x)
ans = max(
ans, i + (int)(upper_bound(pbb, pbb + m + 1, x - pa[i]) - pbb - 1));
else
break;
}
cout << ans << endl;
}
return 0;
}
| #include <bits/stdc++.h>
typedef long long ll;
using namespace std;
string s, t;
ll a[200005], b[200005], pa[200005], pbb[200005];
int main() {
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
int n, m, x, i;
ll tests = 1;
// cin >> tests;
while (tests--) {
cin >> n >> m >> x;
for (i = 0; i < n; i++) {
cin >> a[i];
pa[i + 1] = pa[i] + a[i];
}
for (i = 0; i < m; i++) {
cin >> b[i];
pbb[i + 1] = pbb[i] + b[i];
}
int ans = 0;
for (i = 0; i <= n; i++) {
if (pa[i] <= x)
ans = max(
ans, i + (int)(upper_bound(pbb, pbb + m + 1, x - pa[i]) - pbb - 1));
else
break;
}
cout << ans << endl;
}
return 0;
}
| replace | 7 | 8 | 7 | 8 | 0 | |
p02623 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
using p = pair<int, int>;
using ll = long long;
int main() {
int n, m, k;
cin >> n >> m >> k;
vector<int> a(n);
vector<int> b(m);
rep(i, n) cin >> a.at(i);
rep(i, m) cin >> b.at(i);
ll t = 0;
rep(i, m) t += b.at(i);
int j = m;
int ans = 0;
rep(i, n + 1) {
while (j > 0 && t > k) {
--j;
t -= b.at(i);
}
if (t > k)
break;
ans = max(ans, i + j);
if (i == n)
break;
t += a.at(i);
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
using p = pair<int, int>;
using ll = long long;
int main() {
int n, m, k;
cin >> n >> m >> k;
vector<int> a(n);
vector<int> b(m);
rep(i, n) cin >> a.at(i);
rep(i, m) cin >> b.at(i);
ll t = 0;
rep(i, m) t += b.at(i);
int j = m;
int ans = 0;
rep(i, n + 1) {
while (j > 0 && t > k) {
--j;
t -= b.at(j);
}
if (t > k)
break;
ans = max(ans, i + j);
if (i == n)
break;
t += a.at(i);
}
cout << ans << endl;
return 0;
} | replace | 24 | 25 | 24 | 25 | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.