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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
p03077 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
int main() {
long long A, B, C, D, E, N;
std::cin >> N >> A >> B >> C >> D >> E;
long long M[6] = {A, B, C, D, E, 0};
long long T[6] = {N, 0, 0, 0, 0, 0};
long long time = 0;
while (true) {
if (T[5] == N)
break;
time++;
for (int i = 4; i >= 0; i--) {
if (T[i] == 0)
continue;
long long m = std::min(T[i], M[i]);
T[i] -= m;
T[i + 1] += m;
}
}
std::cout << time << std::endl;
return 0;
}
| #include <algorithm>
#include <iostream>
int main() {
long long A, B, C, D, E, N;
std::cin >> N >> A >> B >> C >> D >> E;
long long ans = std::max({(N + A - 1) / A, (N + B - 1) / B, (N + C - 1) / C,
(N + D - 1) / D, (N + E - 1) / E});
std::cout << (ans + 4) << std::endl;
return 0;
}
| replace | 6 | 25 | 6 | 9 | TLE | |
p03077 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define debug(x) \
cout << "DEBUG" \
<< " " << #x << ":" << x << '\n'
// n回繰り返し
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++) // 0-indexed昇順
#define rep1(i, n) for (int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--) // 0-indexed降順
#define rrep1(i, n) for (int i = ((int)(n)); i >= 1; i--) // 1-indexed降順
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; // 2次元配列
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> PII;
template <typename T> using vec = vector<T>;
template <class T> using maxheap = std::priority_queue<T>;
template <class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template <class T, class U> inline bool chmax(T &a, const U &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T, class U> inline bool chmin(T &a, const U &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const ld Pi = std::acos(-1.0L);
const ll infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;
const int mod = 1000000007;
// const int mod = 998244353;
/*FUNCs=================================================*/
long long GCD(long long a, long long b) { return (b ? GCD(b, a % b) : a); }
long long LCM(long long a, long long b) { return a * b / GCD(a, b); }
/*MAIN==================================================*/
signed main() {
int _StartTime_ = clock();
cin.tie(nullptr);
ios::sync_with_stdio(false); // cin cout 高速化
// cout << fixed << setprecision(15);
ll n;
cin >> n;
vll a(5);
rep(i, 5) cin >> a[i];
ll idx, p = inf, time = 0;
for (int i = 0; i < 5; ++i) {
if (chmin(p, a[i]))
idx = i;
}
time = idx;
time += (n - a[idx] + 1) / a[idx];
time += 5 - idx;
cout << time << '\n';
// printf("ExcutionTime: %d
// /ms\n",1000*(int)((clock()-_StartTime_)/CLOCKS_PER_SEC));
} | #include <bits/stdc++.h>
using namespace std;
#define debug(x) \
cout << "DEBUG" \
<< " " << #x << ":" << x << '\n'
// n回繰り返し
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++) // 0-indexed昇順
#define rep1(i, n) for (int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--) // 0-indexed降順
#define rrep1(i, n) for (int i = ((int)(n)); i >= 1; i--) // 1-indexed降順
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; // 2次元配列
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> PII;
template <typename T> using vec = vector<T>;
template <class T> using maxheap = std::priority_queue<T>;
template <class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template <class T, class U> inline bool chmax(T &a, const U &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T, class U> inline bool chmin(T &a, const U &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const ld Pi = std::acos(-1.0L);
const ll infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;
const int mod = 1000000007;
// const int mod = 998244353;
/*FUNCs=================================================*/
long long GCD(long long a, long long b) { return (b ? GCD(b, a % b) : a); }
long long LCM(long long a, long long b) { return a * b / GCD(a, b); }
/*MAIN==================================================*/
signed main() {
int _StartTime_ = clock();
cin.tie(nullptr);
ios::sync_with_stdio(false); // cin cout 高速化
// cout << fixed << setprecision(15);
ll n;
cin >> n;
vll a(5);
rep(i, 5) cin >> a[i];
ll p = infll, Time = 0;
rep(i, 5) { chmin(p, a[i]); }
Time = (n + p - 1) / p + 4;
cout << Time << '\n';
// printf("ExcutionTime: %d
// /ms\n",1000*(int)((clock()-_StartTime_)/CLOCKS_PER_SEC));
} | replace | 64 | 73 | 64 | 68 | 0 | |
p03077 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
long long N, A, B, C, D, E, F;
cin >> N >> A >> B >> C >> E >> F;
long long shrt = min({A, B, C, D, E, F});
long long ans = (N + shrt - 1) / shrt + 4;
cout << ans << endl;
} | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
long long N, A, B, C, D, E;
cin >> N >> A >> B >> C >> D >> E;
long long shrt = min({A, B, C, D, E});
long long ans = (N + shrt - 1) / shrt + 4;
cout << ans << endl;
} | replace | 5 | 8 | 5 | 8 | 0 | |
p03077 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int64_t N, A, B, C, D, E;
cin >> N >> A >> B >> C >> D >> E;
int64_t F = min(A, min(B, min(C, min(D, min(E, F)))));
if (N % F == 0) {
cout << N / F + 4 << endl;
} else {
cout << N / F + 5 << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int64_t N, A, B, C, D, E;
cin >> N >> A >> B >> C >> D >> E;
int64_t F = min(A, min(B, min(C, min(D, E))));
if (N % F == 0) {
cout << N / F + 4 << endl;
} else {
cout << N / F + 5 << endl;
}
return 0;
}
| replace | 7 | 8 | 7 | 8 | 0 | |
p03077 | C++ | Runtime Error | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>
#define MOD (long long)1000000007
using namespace std;
int main(void) {
vector<int> a(6, 0);
long long n, ans = 0, rem = 0;
cin >> n;
for (int i = 0; i < 5; i++) {
cin >> a[i];
ans = max(ans, (n + a[i] - 1) / a[i] + 4);
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>
#define MOD (long long)1000000007
using namespace std;
int main(void) {
vector<long long> a(5);
long long n, ans = 0;
cin >> n;
for (int i = 0; i < 5; i++) {
cin >> a[i];
ans = max(ans, (n + a[i] - 1) / a[i] + 4);
}
cout << ans << endl;
return 0;
} | replace | 12 | 14 | 12 | 14 | 0 | |
p03077 | C++ | Time Limit Exceeded | #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() {
ll n, a, b, c, d, e;
cin >> n >> a >> b >> c >> d >> e;
vector<ll> box(6);
rep(i, 6) box[i] = 0;
box[0] = n;
ll cnt = 0;
while (true) {
if (box[5] == n)
break;
if (box[4] >= 0) {
// cnt++;
box[5] += min(e, box[4]);
box[4] -= min(e, box[4]);
}
if (box[3] >= 0) {
// cnt++;
box[4] += min(d, box[3]);
box[3] -= min(d, box[3]);
}
if (box[2] >= 0) {
// cnt++;
box[3] += min(c, box[2]);
box[2] -= min(c, box[2]);
}
if (box[1] > 0) {
// cnt++;
box[2] += min(b, box[1]);
box[1] -= min(b, box[1]);
}
if (box[0] > 0) {
// cnt++;
box[1] += min(a, box[0]);
box[0] -= min(a, box[0]);
}
cnt++;
// rep(i,6)cout<<box[i]<<" ";
// cout << endl;
}
cout << cnt << 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() {
ll n, a, b, c, d, e;
cin >> n >> a >> b >> c >> d >> e;
vector<ll> box(6);
rep(i, 6) box[i] = 0;
box[0] = n;
ll cnt = 0;
cout << (ll)ceil((double)n / min({a, b, c, d, e})) + 4 << endl;
return 0;
}
| replace | 30 | 65 | 30 | 31 | TLE | |
p03077 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
ll n;
cin >> n;
vector<ll> a(5), b(6, 0);
for (int i = 0; i < 5; i++)
cin >> a.at(i);
b.at(0) = n;
ll t = 0;
while (b.at(5) != n) {
for (int i = 4; i >= 0; i--) {
b.at(i + 1) += min(b.at(i), a.at(i));
b.at(i) -= min(b.at(i), a.at(i));
}
t++;
}
cout << t << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
ll n, a, b, c, d, e;
cin >> n >> a >> b >> c >> d >> e;
ll ans = ceil((double)n / min({a, b, c, d, e})) + 4;
cout << ans << endl;
} | replace | 6 | 21 | 6 | 10 | TLE | |
p03077 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
long long N, A, B, C, D, E;
int main() {
cin >> N >> A >> B >> C >> D >> E;
long long m = min({A, B, C, D, E});
long long ans = (N / (m - 1)) + 4;
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
long long N, A, B, C, D, E;
int main() {
cin >> N >> A >> B >> C >> D >> E;
long long m = min({A, B, C, D, E});
long long ans;
if (N % m == 0) {
ans = N / m + 4;
} else {
ans = N / m + 5;
}
cout << ans << endl;
} | replace | 7 | 8 | 7 | 13 | 0 | |
p03077 | C++ | Runtime Error | #include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int> a(5);
long long min;
long long time;
long long n;
cin >> n;
for (int i = 0; i < a.size(); i++) {
cin >> a[i];
if (i == 0) {
min = a[i];
} else {
if (min > a[i]) {
min = a[i];
}
}
}
time = (n + (min - 1)) / min + 4;
cout << time << endl;
} | #include <iostream>
#include <vector>
using namespace std;
int main() {
vector<long long> a(5);
long long min;
long long time;
long long n;
cin >> n;
for (int i = 0; i < a.size(); i++) {
cin >> a[i];
if (i == 0) {
min = a[i];
} else {
if (min > a[i]) {
min = a[i];
}
}
}
time = (n + (min - 1)) / min + 4;
cout << time << endl;
} | replace | 6 | 7 | 6 | 7 | 0 | |
p03077 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
signed main() {
int n, a, b, c, d, e;
cin >> n >> a >> b >> c >> d >> e;
int MIN = min({a, b, c, d, e});
cout << 5 + (n - 1) / MIN;
}
| #include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
int n, a, b, c, d, e;
cin >> n >> a >> b >> c >> d >> e;
int MIN = min({a, b, c, d, e});
cout << 5 + (n - 1) / MIN;
}
| insert | 1 | 1 | 1 | 2 | 0 | |
p03077 | C++ | Time Limit Exceeded | #include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;
typedef long long ll;
int main(void) {
ll N, A, B, C, D, E;
cin >> N >> A >> B >> C >> D >> E;
vector<ll> moves = {-1, A, B, C, D, E};
vector<ll> nums(6, 0);
nums[0] = N;
// for (auto v : nums) { cout << v << " "; } cout << endl;
int time = 0;
while (true) {
vector<int> indices;
// cout << "time " << time << endl;
for (int i = 5; i >= 1; i--) {
int mv = min(moves[i], nums[i - 1]);
// cout << "\t" << i << " " << mv << endl;
nums[i] += mv;
nums[i - 1] -= mv;
}
// for (auto v : nums) { cout << v << " "; } cout << endl;
// for (int i = 0; i < 5; i++) { nums[i] = nums2[i]; }
if (nums[5] == N) {
break;
}
time++;
// if (time == 15) break;
}
cout << (time + 1) << endl;
}
| #include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;
typedef long long ll;
int main(void) {
ll N, A, B, C, D, E;
cin >> N >> A >> B >> C >> D >> E;
vector<ll> v = {A, B, C, D, E};
sort(v.begin(), v.end());
ll ans = ceil((double)N / (double)v[0]) + 4LL;
cout << ans << endl;
}
| replace | 16 | 41 | 16 | 20 | TLE | |
p03077 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
vector<long long int> t(5);
for (long long int i = 0; i < 5; i++) {
cin >> t[i];
}
vector<long long int> p(6, 0);
p[0] = n;
long long int ans = 0;
while (p[5] < n) {
for (long long int i = 5; i > 0; i--) {
p[i] += min(t[i - 1], p[i - 1]);
p[i - 1] -= min(t[i - 1], p[i - 1]);
}
ans++;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
vector<long long int> t(5);
for (long long int i = 0; i < 5; i++) {
cin >> t[i];
}
sort(t.begin(), t.end());
cout << (n + t[0] - 1) / t[0] + 4 << endl;
} | replace | 10 | 21 | 10 | 12 | TLE | |
p03077 | C++ | Runtime Error | #include <iostream>
using namespace std;
int MinIndex(const unsigned long long int *const array, const int size);
int main() {
unsigned long long int N;
unsigned long long int board[5];
cin >> N;
for (int i = 0; i < 5; i++)
cin >> board[i];
int bottleNeckIndex = MinIndex(board, sizeof(board));
unsigned long long int ans =
(unsigned long long int)(N / board[bottleNeckIndex]) + 4;
if ((N % board[bottleNeckIndex]) != 0)
ans++;
cout << ans;
return 0;
}
int MinIndex(const unsigned long long int *const array, const int size) {
int minIndex = 0;
unsigned long long int minValue = array[0];
for (int i = 1; i < size; i++) {
if (array[i] < minValue) {
minIndex = i;
minValue = array[i];
}
}
return minIndex;
} | #include <iostream>
using namespace std;
int MinIndex(const unsigned long long int *const array, const int size);
int main() {
unsigned long long int N;
unsigned long long int board[5];
cin >> N;
for (int i = 0; i < 5; i++)
cin >> board[i];
int bottleNeckIndex = MinIndex(board, 5);
unsigned long long int ans =
(unsigned long long int)(N / board[bottleNeckIndex]) + 4;
if ((N % board[bottleNeckIndex]) != 0)
ans++;
cout << ans;
return 0;
}
int MinIndex(const unsigned long long int *const array, const int size) {
int minIndex = 0;
unsigned long long int minValue = array[0];
for (int i = 1; i < size; i++) {
if (array[i] < minValue) {
minIndex = i;
minValue = array[i];
}
}
return minIndex;
} | replace | 14 | 15 | 14 | 15 | -8 | |
p03077 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef map<int, int> mi;
typedef set<int> si;
#define VV(T) vector<vector<T>>
#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define rep(i, n) REP(i, 0, n) // 0, 1, ..., n-1
#define REP(i, x, n) for (int i = x; i < n; i++) // x, x + 1, ..., n-1
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define pb push_back
#define pu push
#define mp make_pair
#define fi first
#define sc second
#define COUT(x) cout << (x) << endl
#define VECCIN(x) \
for (auto &youso_ : (x)) \
cin >> youso_
#define VECCOUT(x) \
for (auto &youso_ : (x)) \
cout << youso_ << " "; \
cout << endl
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n;
cin >> n;
ll MIN = 1000000000000001;
rep(i, n) {
ll a;
cin >> a;
MIN = min(MIN, a);
}
ll ans = ((n + (MIN - 1)) / MIN) + 4;
COUT(ans);
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef map<int, int> mi;
typedef set<int> si;
#define VV(T) vector<vector<T>>
#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define rep(i, n) REP(i, 0, n) // 0, 1, ..., n-1
#define REP(i, x, n) for (int i = x; i < n; i++) // x, x + 1, ..., n-1
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define pb push_back
#define pu push
#define mp make_pair
#define fi first
#define sc second
#define COUT(x) cout << (x) << endl
#define VECCIN(x) \
for (auto &youso_ : (x)) \
cin >> youso_
#define VECCOUT(x) \
for (auto &youso_ : (x)) \
cout << youso_ << " "; \
cout << endl
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n;
cin >> n;
ll MIN = 1000000000000001;
rep(i, 5) {
ll a;
cin >> a;
MIN = min(MIN, a);
}
ll ans = ((n + (MIN - 1)) / MIN) + 4;
COUT(ans);
}
| replace | 64 | 65 | 64 | 65 | TLE | |
p03077 | C++ | Runtime Error | #include <iostream>
using namespace std;
#define MAX(X, Y) ((X) > (Y) ? (X) : (Y))
int main(void) {
int a[5];
long long n, fa[10], fd[10], la[10], ld[10];
cin >> n;
fa[0] = la[0] = 0;
for (int i = 0; i < 5; i++) {
cin >> a[i];
fd[i] = fa[i];
ld[i] = MAX(la[i], fa[i] + (n - 1) / a[i]);
// cout << fd[i] << " " << ld[i] << endl;
fa[i + 1] = fd[i] + 1;
la[i + 1] = ld[i] + 1;
}
cout << la[5] << endl;
return 0;
}
| #include <iostream>
using namespace std;
#define MAX(X, Y) ((X) > (Y) ? (X) : (Y))
int main(void) {
long long a[5];
long long n, fa[10], fd[10], la[10], ld[10];
cin >> n;
fa[0] = la[0] = 0;
for (int i = 0; i < 5; i++) {
cin >> a[i];
fd[i] = fa[i];
ld[i] = MAX(la[i], fa[i] + (n - 1) / a[i]);
// cout << fd[i] << " " << ld[i] << endl;
fa[i + 1] = fd[i] + 1;
la[i + 1] = ld[i] + 1;
}
cout << la[5] << endl;
return 0;
}
| replace | 6 | 7 | 6 | 7 | 0 | |
p03077 | C++ | Runtime Error | #include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define ALL(obj) (v.begin(obj), v.end(obj))
#define COUT(x) cout << (x) << endl;
int main() {
ll n, a, b, c, d, e;
cin >> n;
ll min1 = min({a, b, c, d, e});
COUT((n + min1 - 1) / min1 + 4)
return 0;
}
| #include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define ALL(obj) (v.begin(obj), v.end(obj))
#define COUT(x) cout << (x) << endl;
int main() {
ll n, a, b, c, d, e;
cin >> n;
cin >> a >> b >> c >> d >> e;
ll min1 = min({a, b, c, d, e});
COUT((n + min1 - 1) / min1 + 4)
return 0;
}
| insert | 17 | 17 | 17 | 18 | 0 | |
p03077 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return
// true; } return false; } template<class T> inline bool chmin(T& a, T b) { if
// (a > b) { a = b; return true; } return false; }
/* attention
long longのシフト演算には気をつけよう
タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/
int main() {
ll N;
cin >> N;
vector<int> a(5);
for (int i = 0; i < 5; i++)
cin >> a[i];
sort(a.begin(), a.end());
ll minv = a[0];
ll turn;
if (a[0] == 1)
turn = N;
else
turn = (N - 1) / minv + 1;
cout << turn + 4 << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return
// true; } return false; } template<class T> inline bool chmin(T& a, T b) { if
// (a > b) { a = b; return true; } return false; }
/* attention
long longのシフト演算には気をつけよう
タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/
int main() {
ll N;
cin >> N;
vector<ll> a(5);
for (int i = 0; i < 5; i++)
cin >> a[i];
sort(a.begin(), a.end());
ll minv = a[0];
ll turn;
if (a[0] == 1)
turn = N;
else
turn = (N - 1) / minv + 1;
cout << turn + 4 << endl;
} | replace | 15 | 16 | 15 | 16 | 0 | |
p03077 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;
using ll = long long;
const ll INF = pow(10, 18) + 1;
#define FOR(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define pb(a) push_back(a)
#define all(x) (x).begin(), (x).end()
template <typename T> bool chmin(T &a, T b) {
return a > b ? a = b, true : false;
}
template <typename T> bool chmax(T &a, T b) {
return a < b ? a = b, true : false;
}
int main() {
ll N, A[10];
cin >> N;
ll mn = INF;
int mn_place = 0;
REP(i, 5) {
cin >> A[i];
if (A[i] < mn) {
mn = A[i];
mn_place = i;
}
}
ll B[6] = {N, 0, 0, 0, 0, 0};
ll res = 0;
/*if(mn < N){
if(mn_place!=0) res = (N / mn) + 1 + (5-mn_place);
else res = (N / mn) + 5;
} else {
res = 5;
}*/
while (B[5] != N) {
if (B[4] != 0) {
if (B[4] > A[4]) {
B[5] += A[4];
B[4] -= A[4];
} else {
B[5] += B[4];
B[4] -= B[4];
}
}
if (B[3] != 0) {
if (B[3] > A[3]) {
B[4] += A[3];
B[3] -= A[3];
} else {
B[4] += B[3];
B[3] -= B[3];
}
}
if (B[2] != 0) {
if (B[2] > A[2]) {
B[3] += A[2];
B[2] -= A[2];
} else {
B[3] += B[2];
B[2] -= B[2];
}
}
if (B[1] != 0) {
if (B[1] > A[1]) {
B[2] += A[1];
B[1] -= A[1];
} else {
B[2] += B[1];
B[1] -= B[1];
}
}
if (B[0] != 0) {
if (B[0] > A[0]) {
B[1] += A[0];
B[0] -= A[0];
} else {
B[1] += B[0];
B[0] -= B[0];
}
}
res++;
}
cout << res << endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;
using ll = long long;
const ll INF = pow(10, 18) + 1;
#define FOR(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define pb(a) push_back(a)
#define all(x) (x).begin(), (x).end()
template <typename T> bool chmin(T &a, T b) {
return a > b ? a = b, true : false;
}
template <typename T> bool chmax(T &a, T b) {
return a < b ? a = b, true : false;
}
int main() {
ll N, A[10];
cin >> N;
REP(i, 5) { cin >> A[i]; }
ll mn = min(A[0], min(A[1], min(A[2], min(A[3], A[4]))));
ll res = ceil((N - 1) / mn) + 5;
cout << res << endl;
return 0;
} | replace | 24 | 89 | 24 | 27 | TLE | |
p03077 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
int N, A, B, C, D, E;
cin >> N, A, B, C, D, E;
int MIN = min({A, B, C, D, E});
cout << 5 + (N - 1) / MIN << endl;
return 0;
}
| #include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
long N, A, B, C, D, E;
cin >> N >> A >> B >> C >> D >> E;
long MIN = min({A, B, C, D, E});
cout << 5 + (N - 1) / MIN << endl;
return 0;
}
| replace | 5 | 8 | 5 | 8 | 0 | |
p03077 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <string.h>
#include <vector>
#define INF 100000000
using namespace std;
int main(void) {
long N;
long trans1[5], trans2[5];
cin >> N;
for (int i = 0; i < 5; i++) {
cin >> trans1[i];
if (N % trans1[i] != 0) {
trans2[i] = N / trans1[i] + 1;
} else
trans2[i] = N / trans1[i];
}
sort(trans2, trans2 + N);
cout << trans2[0] + 4;
return 0;
}
| #include <algorithm>
#include <iostream>
#include <string.h>
#include <vector>
#define INF 100000000
using namespace std;
int main(void) {
long N;
long trans1[5], trans2[5];
cin >> N;
for (int i = 0; i < 5; i++) {
cin >> trans1[i];
if (N % trans1[i] != 0) {
trans2[i] = N / trans1[i] + 1;
} else
trans2[i] = N / trans1[i];
}
sort(trans2, trans2 + 5);
cout << trans2[4] + 4;
return 0;
}
| replace | 17 | 19 | 17 | 19 | 0 | |
p03077 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
int main() {
ll n;
vector<int> a(5);
cin >> n;
rep(i, 5) cin >> a[i];
ll minmove = *std::min_element(a.begin(), a.end());
ll ans = ((n + minmove - 1) / minmove) + 4;
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
int main() {
ll n;
vector<ll> a(5);
cin >> n;
rep(i, 5) cin >> a[i];
ll minmove = *std::min_element(a.begin(), a.end());
ll ans = ((n + minmove - 1) / minmove) + 4;
cout << ans << endl;
return 0;
} | replace | 8 | 9 | 8 | 9 | 0 | |
p03077 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
long long int min(long long int a, long long int b) {
if (a < b) {
return a;
} else {
return b;
}
}
long long int fivemin(long long int a, long long int b, long long int c,
long long int d, long long int e) {
return min(min(min(a, b), min(c, d)), e);
}
int main() {
long long int N, A, B, C, D, E;
cin >> N >> A >> B >> C >> D >> E;
long long int output = 0;
// output = 5;
// output += N / fivemin(A, B, C, D, E);
long long int city1 = N;
long long int city2 = 0;
long long int city3 = 0;
long long int city4 = 0;
long long int city5 = 0;
long long int city6 = 0;
while (1) {
if (city6 == N) {
break;
}
if (city5 >= E) {
city5 -= E;
city6 += E;
} else if (city5 > 0) {
city6 += city5;
city5 = 0;
}
if (city4 >= D) {
city4 -= D;
city5 += D;
} else if (city4 > 0) {
city5 += city4;
city4 = 0;
}
if (city3 >= C) {
city3 -= C;
city4 += C;
} else if (city3 > 0) {
city4 += city3;
city3 = 0;
}
if (city2 >= B) {
city2 -= B;
city3 += B;
} else if (city2 > 0) {
city3 += city2;
city2 = 0;
}
if (city1 >= A) {
city1 -= A;
city2 += A;
} else if (city1 > 0) {
city2 += city1;
city1 = 0;
}
output++;
}
cout << output << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
long long int min(long long int a, long long int b) {
if (a < b) {
return a;
} else {
return b;
}
}
long long int fivemin(long long int a, long long int b, long long int c,
long long int d, long long int e) {
return min(min(min(a, b), min(c, d)), e);
}
int main() {
long long int N, A, B, C, D, E;
cin >> N >> A >> B >> C >> D >> E;
long long int output = 0;
// output = 5;
// output += N / fivemin(A, B, C, D, E);
output = 4;
output += N / fivemin(A, B, C, D, E);
if (N % fivemin(A, B, C, D, E) != 0) {
output++;
}
cout << output << endl;
return 0;
}
| replace | 23 | 72 | 23 | 26 | TLE | |
p03077 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[5];
cin >> n >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
sort(a, a + 5);
cout << (n - 1) / a[0] + 5 << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
long long n, a[5];
cin >> n >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
sort(a, a + 5);
cout << (n - 1) / a[0] + 5 << endl;
}
| replace | 4 | 5 | 4 | 5 | 0 | |
p03077 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
int a[5]; // cout<<"unko"<<endl;
for (int i = 0; i < 5; i++) {
cin >> a[i]; // cout<<a[i]<<endl;
}
sort(a, a + 5);
if (n % a[0] != 0)
cout << n / a[0] + 5 << endl;
else
cout << n / a[0] + 4 << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
long long int a[5]; // cout<<"unko"<<endl;
for (int i = 0; i < 5; i++) {
cin >> a[i]; // cout<<a[i]<<endl;
}
sort(a, a + 5);
if (n % a[0] != 0)
cout << n / a[0] + 5 << endl;
else
cout << n / a[0] + 4 << endl;
}
| replace | 6 | 7 | 6 | 7 | 0 | |
p03077 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
constexpr long long MOD = 1000000007;
using ll = long long;
int main() {
ll n, a, b, c, d, e;
cin >> n >> a >> b >> c >> d;
cout << (n / min({a, b, c, d, e})) + 4 << endl;
}
| #include <bits/stdc++.h>
using namespace std;
constexpr long long MOD = 1000000007;
using ll = long long;
int main() {
ll n, a, b, c, d, e;
cin >> n >> a >> b >> c >> d >> e;
cout << (n + min({a, b, c, d, e}) - 1) / min({a, b, c, d, e}) + 4 << endl;
}
| replace | 6 | 8 | 6 | 8 | 0 | |
p03077 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
ll n;
cin >> n;
ll a, b, c, d, e;
cin >> a, b, c, d, e;
ll m = min(a, min(b, min(c, min(d, e))));
ll ans = 4 + (n + m - 1) / m;
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
ll n;
cin >> n;
ll a, b, c, d, e;
cin >> a >> b >> c >> d >> e;
ll m = min(a, min(b, min(c, min(d, e))));
ll ans = 4 + (n + m - 1) / m;
cout << ans << endl;
return 0;
} | replace | 7 | 8 | 7 | 8 | 0 | |
p03077 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
typedef long long ll;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};
const int INF = 1e9;
#define FOR(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
int guki(int a) {
if (a % 2 == 0)
return 0;
else
return 1;
}
int gcd(int a, int b) {
if (a % b == 0) {
return b;
} else {
return (gcd(b, a % b));
}
}
int lcm(int a, int b) {
int x = gcd(a, b);
return (a * b / x);
}
using namespace std;
int main() {
ll n, ans = 0;
cin >> n;
vector<pair<ll, ll>> vec(6);
REP(i, 5) {
ll a;
cin >> a;
vec[i].first = a;
vec[i].second = 0;
}
vec[0].second = n;
vec[5].second = 0;
while (vec[5].second != n) {
for (int i = 5; 0 < i; i--) {
if (vec[i - 1].second == 0) {
continue;
} else if (vec[i - 1].second >= vec[i - 1].first) {
vec[i].second += vec[i - 1].first;
vec[i - 1].second -= vec[i - 1].first;
} else {
vec[i].second += vec[i - 1].second;
vec[i - 1].second = 0;
}
}
ans++;
}
cout << ans << endl;
} | #include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
typedef long long ll;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};
const int INF = 1e9;
#define FOR(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
int guki(int a) {
if (a % 2 == 0)
return 0;
else
return 1;
}
int gcd(int a, int b) {
if (a % b == 0) {
return b;
} else {
return (gcd(b, a % b));
}
}
int lcm(int a, int b) {
int x = gcd(a, b);
return (a * b / x);
}
using namespace std;
int main() {
ll n, a, b, c, d, e;
cin >> n >> a >> b >> c >> d >> e;
cout << max({(n - 1) / a, (n - 1) / b, (n - 1) / c, (n - 1) / d,
(n - 1) / e}) +
5
<< endl;
} | replace | 41 | 69 | 41 | 47 | TLE | |
p03077 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ld = long double;
using VI = vector<ll>;
using VD = vector<ld>;
using VVI = vector<VI>;
using VC = vector<char>;
using VVC = vector<VC>;
using VS = vector<string>;
using PLL = pair<ll, ll>;
using PLD = pair<ld, ld>;
using VPLL = vector<PLL>;
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end()
#define ALLR(x) (x).rbegin(), (x).rend()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element((x).begin(), (x).end())
#define MIN(x) *min_element((x).begin(), (x).end())
#define SORTR(x) sort((x).rbegin(), (x).rend())
#define SORT(x) sort((x).begin(), (x).end())
#define SUM(x) accumulate((x).begin(), (x).end(), 0)
#define FILL(x, a) fill(x.begin(), x.end(), a)
#define EACH(i, x) \
for (typeof((x).begin()) i = (x).begin(); i != (x).end(); ++i)
const long long int INF = 1e18;
const ld EPS = 1e-10;
const int MOD = int(1e9) + 7;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
template <class BidirectionalIterator>
bool next_partial_permutation(BidirectionalIterator first,
BidirectionalIterator middle,
BidirectionalIterator last) {
reverse(middle, last);
return next_permutation(first, last);
}
#define COUT(x) cout << x << "\n"
// ll ceil(ll val) return
void Main() {
ll N, A, B, C, D, E;
ll result = 0;
cin >> N >> A >> B >> C >> D >> E;
VI pos(N);
result = 1 + ((N - 1) / min({A, B, C, D, E})) + 4;
cout << result << "\n";
return;
}
int main() {
std::cin.tie(0);
std::ios_base::sync_with_stdio(false);
std::cout << std::fixed << std::setprecision(15);
Main();
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ld = long double;
using VI = vector<ll>;
using VD = vector<ld>;
using VVI = vector<VI>;
using VC = vector<char>;
using VVC = vector<VC>;
using VS = vector<string>;
using PLL = pair<ll, ll>;
using PLD = pair<ld, ld>;
using VPLL = vector<PLL>;
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end()
#define ALLR(x) (x).rbegin(), (x).rend()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element((x).begin(), (x).end())
#define MIN(x) *min_element((x).begin(), (x).end())
#define SORTR(x) sort((x).rbegin(), (x).rend())
#define SORT(x) sort((x).begin(), (x).end())
#define SUM(x) accumulate((x).begin(), (x).end(), 0)
#define FILL(x, a) fill(x.begin(), x.end(), a)
#define EACH(i, x) \
for (typeof((x).begin()) i = (x).begin(); i != (x).end(); ++i)
const long long int INF = 1e18;
const ld EPS = 1e-10;
const int MOD = int(1e9) + 7;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
template <class BidirectionalIterator>
bool next_partial_permutation(BidirectionalIterator first,
BidirectionalIterator middle,
BidirectionalIterator last) {
reverse(middle, last);
return next_permutation(first, last);
}
#define COUT(x) cout << x << "\n"
// ll ceil(ll val) return
void Main() {
ll N, A, B, C, D, E;
ll result = 0;
cin >> N >> A >> B >> C >> D >> E;
result = 1 + ((N - 1) / min({A, B, C, D, E})) + 4;
cout << result << "\n";
return;
}
int main() {
std::cin.tie(0);
std::ios_base::sync_with_stdio(false);
std::cout << std::fixed << std::setprecision(15);
Main();
}
| delete | 61 | 62 | 61 | 61 | 0 | |
p03077 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
#define ll long long
const ll MOD = 1e9 + 7;
const ll INF = 1 << 29;
int main() {
ll N;
std::cin >> N;
std::vector<int> capacities(5);
auto min = 10000000000000000;
for (auto i = 0; i < 5; ++i) {
std::cin >> capacities[i];
if (capacities[i] < min)
min = capacities[i];
}
ll result = N / min + 4;
auto mod = N % min;
if (mod != 0)
result++;
std::cout << result << std::endl;
} | #include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
#define ll long long
const ll MOD = 1e9 + 7;
const ll INF = 1 << 29;
int main() {
ll N;
std::cin >> N;
std::vector<ll> capacities(5);
auto min = 10000000000000000;
for (auto i = 0; i < 5; ++i) {
std::cin >> capacities[i];
if (capacities[i] < min)
min = capacities[i];
}
ll result = N / min + 4;
auto mod = N % min;
if (mod != 0)
result++;
std::cout << result << std::endl;
} | replace | 17 | 19 | 17 | 18 | 0 | |
p03077 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long llint;
typedef long double ld;
#define inf 1e18
#define mod 1000000007
priority_queue<llint, vector<llint>, greater<llint>> que;
priority_queue<llint> Que;
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
void solve() {
llint n;
vector<llint> a(5);
cin >> n;
llint mn = inf;
for (int i = 0; i < 5; i++) {
cin >> a[i];
mn = min(a[i], mn);
}
llint ans = 5;
n -= mn;
while (n > 0) {
ans += 1;
n -= mn;
}
cout << ans << endl;
}
int main() {
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long llint;
typedef long double ld;
#define inf 1e18
#define mod 1000000007
priority_queue<llint, vector<llint>, greater<llint>> que;
priority_queue<llint> Que;
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
void solve() {
llint n;
vector<llint> a(5);
cin >> n;
llint mn = inf;
for (int i = 0; i < 5; i++) {
cin >> a[i];
mn = min(a[i], mn);
}
llint ans = 0;
if (n % mn == 0) {
ans += 5 + n / mn;
} else
ans += 6 + n / mn;
cout << ans - 1 << endl;
}
int main() {
solve();
return 0;
}
| replace | 27 | 34 | 27 | 34 | TLE | |
p03077 | 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 ALL(v) (v).begin(), (v).end()
int main() {
ll n;
cin >> n;
vector<int> a(5);
rep(i, 5) cin >> a[i];
ll mina = *min_element(ALL(a));
cout << ((n + mina - 1) / mina) + 4 << endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
int main() {
ll n;
cin >> n;
vector<ll> a(5);
rep(i, 5) cin >> a[i];
ll mina = *min_element(ALL(a));
cout << ((n + mina - 1) / mina) + 4 << endl;
} | replace | 10 | 11 | 10 | 11 | 0 | |
p03077 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> T GCD(T a, T b) {
if (b == 0)
return a;
else
return GCD(b, a % b);
}
template <class T> inline T LCM(T a, T b) { return (a * b) / GCD(a, b); }
int main() {
ll n;
cin >> n;
vector<ll> v(5);
int r;
ll m = INF;
rep(i, 5) {
cin >> v[i];
if (chmin(m, v[i]))
r = i;
}
ll ans = 4;
if (n % v[r])
ans += n / v[r] + 1;
else
ans += n / v[r];
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e18
#define PIE 3.14159265358979323
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> T GCD(T a, T b) {
if (b == 0)
return a;
else
return GCD(b, a % b);
}
template <class T> inline T LCM(T a, T b) { return (a * b) / GCD(a, b); }
int main() {
ll n;
cin >> n;
vector<ll> v(5);
int r;
ll m = INF;
rep(i, 5) {
cin >> v[i];
if (chmin(m, v[i]))
r = i;
}
ll ans = 4;
if (n % v[r])
ans += n / v[r] + 1;
else
ans += n / v[r];
cout << ans << endl;
return 0;
} | replace | 18 | 19 | 18 | 19 | 0 | |
p03077 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int64_t n, a, b, c, d, e;
cin >> n >> a >> b >> c >> d >> e;
int64_t cntn = n, cnta = 0, cntb = 0, cntc = 0, cntd = 0, cnte = 0, ans = 0;
while (cnte < n) {
cnte += min(cntd, e);
cntd -= min(cntd, e);
cntd += min(cntc, d);
cntc -= min(cntc, d);
cntc += min(cntb, c);
cntb -= min(cntb, c);
cntb += min(cnta, b);
cnta -= min(cnta, b);
cnta += min(cntn, a);
cntn -= min(cntn, a);
ans++;
}
cout << ans;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int64_t n, a, b, c, d, e;
cin >> n >> a >> b >> c >> d >> e;
cout << (int64_t)ceil((double)n / min(a, min(b, min(c, min(d, e))))) + 4;
} | replace | 6 | 21 | 6 | 7 | TLE | |
p03077 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
int main() {
long long a[10];
long long b[10];
long long count = 0;
memset(b, 0, sizeof(b));
long long n;
scanf("%lld", &n);
for (int i = 0; i < 5; i++) {
scanf("%lld", &a[i]);
}
b[0] = n;
while (b[0] + b[1] + b[2] + b[3] + b[4] != 0) {
count++;
for (int i = 5; i > 0; i--) {
if (b[i - 1] != 0) {
if (b[i - 1] > a[i - 1]) {
b[i] += a[i - 1];
b[i - 1] -= a[i - 1];
} else {
b[i] += b[i - 1];
b[i - 1] = 0;
}
}
}
}
printf("%lld", count);
return 0;
} | #include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
int main() {
long long N, A, B, C, D, E;
cin >> N >> A >> B >> C >> D >> E;
cout << max({(N - 1) / A, (N - 1) / B, (N - 1) / C, (N - 1) / D,
(N - 1) / E}) +
5
<< endl;
return 0;
}
| replace | 5 | 30 | 5 | 13 | TLE | |
p03077 | C++ | Runtime Error | /*Function Template*/
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
#define rep(i, n) for (long long int i = 0; i < (n); i++)
int Len(int n) {
int s = 0;
while (n != 0)
s++, n /= 10;
return s;
}
int Sint(int n) {
int m = 0, s = 0, a = n;
while (a != 0)
s++, a /= 10;
for (int i = s - 1; i >= 0; i--)
m += n / ((int)pow(10, i)) - (n / ((int)pow(10, i + 1))) * 10;
return m;
}
int Svec(vector<int> v) {
int n = 0;
for (int i = 0; i < v.size(); i++)
n += v[i];
return n;
}
int GCD(int a, int b) {
int r, tmp;
/*自然数 a > b を確認・入替*/
if (a < b) {
tmp = a, a = b, b = tmp;
}
/*ユークリッドの互除法*/
r = a % b;
while (r != 0) {
a = b, b = r, r = a % b;
}
return b;
}
int LCM(int a, int b) {
int c = a, d = b, r, tmp;
/*自然数 a > b を確認・入替*/
if (a < b) {
tmp = a, a = b, b = tmp;
}
/*ユークリッドの互除法*/
r = a % b;
while (r != 0) {
a = b, b = r, r = a % b;
}
return c / b * d;
}
int Factorial(int n) {
int m = 1;
while (n >= 1)
m *= n, n--;
return m;
}
/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
long long int n;
cin >> n;
vector<long long int> v(n);
rep(i, n) cin >> v[i];
sort(v.begin(), v.end());
cout << (n + v[0] - 1) / v[0] + 4 << endl;
} | /*Function Template*/
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
#define rep(i, n) for (long long int i = 0; i < (n); i++)
int Len(int n) {
int s = 0;
while (n != 0)
s++, n /= 10;
return s;
}
int Sint(int n) {
int m = 0, s = 0, a = n;
while (a != 0)
s++, a /= 10;
for (int i = s - 1; i >= 0; i--)
m += n / ((int)pow(10, i)) - (n / ((int)pow(10, i + 1))) * 10;
return m;
}
int Svec(vector<int> v) {
int n = 0;
for (int i = 0; i < v.size(); i++)
n += v[i];
return n;
}
int GCD(int a, int b) {
int r, tmp;
/*自然数 a > b を確認・入替*/
if (a < b) {
tmp = a, a = b, b = tmp;
}
/*ユークリッドの互除法*/
r = a % b;
while (r != 0) {
a = b, b = r, r = a % b;
}
return b;
}
int LCM(int a, int b) {
int c = a, d = b, r, tmp;
/*自然数 a > b を確認・入替*/
if (a < b) {
tmp = a, a = b, b = tmp;
}
/*ユークリッドの互除法*/
r = a % b;
while (r != 0) {
a = b, b = r, r = a % b;
}
return c / b * d;
}
int Factorial(int n) {
int m = 1;
while (n >= 1)
m *= n, n--;
return m;
}
/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
long long int n;
cin >> n;
vector<long long int> v(5);
rep(i, 5) cin >> v[i];
sort(v.begin(), v.end());
cout << (n + v[0] - 1) / v[0] + 4 << endl;
} | replace | 68 | 70 | 68 | 70 | 0 | |
p03077 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<long long> city(5, 0);
int n;
cin >> n;
for (int i = 0; i < 5; i++)
cin >> city[i];
sort(city.begin(), city.end());
long long rtn = 0;
if (n % city[0] == 0) {
rtn += n / city[0];
} else {
rtn += n / city[0] + 1;
}
rtn += 4;
cout << rtn << endl;
}
| #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<long long> city(5, 0);
long long n;
cin >> n;
for (int i = 0; i < 5; i++)
cin >> city[i];
sort(city.begin(), city.end());
long long rtn = 0;
if (n % city[0] == 0) {
rtn += n / city[0];
} else {
rtn += n / city[0] + 1;
}
rtn += 4;
cout << rtn << endl;
}
| replace | 7 | 8 | 7 | 8 | 0 | |
p03078 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define pb emplace_back
typedef long long ll;
typedef pair<int, int> pint;
ll a[1001], b[1001], c[1001];
int x, y, z, k;
ll st1[1000001], st2[1000001];
int main() {
cin >> x >> y >> z >> k;
rep(i, x) cin >> a[i];
rep(i, y) cin >> b[i];
rep(i, z) cin >> c[i];
rep(i, x) rep(j, y) st1[i * y + j] = a[i] + b[j];
sort(st1, st1 + x * y, greater<ll>());
int p = min(k, x * y);
rep(i, p) rep(j, z) { st2[i * z + j] = st1[i] + c[j]; }
sort(st2, st2 + p * z, greater<ll>());
rep(i, k) { cout << st2[i] << endl; }
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define pb emplace_back
typedef long long ll;
typedef pair<int, int> pint;
ll a[1001], b[1001], c[1001];
int x, y, z, k;
ll st1[3000001], st2[3000001];
int main() {
cin >> x >> y >> z >> k;
rep(i, x) cin >> a[i];
rep(i, y) cin >> b[i];
rep(i, z) cin >> c[i];
rep(i, x) rep(j, y) st1[i * y + j] = a[i] + b[j];
sort(st1, st1 + x * y, greater<ll>());
int p = min(k, x * y);
rep(i, p) rep(j, z) { st2[i * z + j] = st1[i] + c[j]; }
sort(st2, st2 + p * z, greater<ll>());
rep(i, k) { cout << st2[i] << endl; }
return 0;
}
| replace | 10 | 11 | 10 | 11 | 0 | |
p03078 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
#define pq priority_queue
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vvvi = vector<vvi>;
using ll = long long; // long longをllだけにした
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using mii = map<int, int>;
using pqls = priority_queue<long long>;
using pqlg = priority_queue<long long, vector<long long>, greater<long long>>;
long long divup(long long a, long long b);
long long kaijou(long long i);
long long P(long long n, long long k);
long long C(long long n, long long k);
long long GCD(long long a, long long b);
long long LCM(long long a, long long b);
bool prime(long long N);
double distance(vector<long long> p, vector<long long> q, long long n);
void press(vector<long long> &v);
void ranking(vector<long long> &v);
void erase(vector<long long> &v, long long i);
void unique(vector<long long> &v);
void printv(vector<long long> v);
vector<ll> keta(ll x);
long long modpow(long long a, long long n, long long mod);
long long modinv(long long a, long long mod);
// 20200416
vector<long long> inputv(long long n);
// 20200417
vector<long long> yakusuu(int n);
map<long long, long long> soinsuu(long long n);
vector<vector<long long>> maze(long long i, long long j, vector<string> &s);
// 20200423
vector<long long> eratos(long long n);
set<long long> eraset(long long n);
//////////////////////////////////////////////////////
// 端数繰りあがり割り算(検証済)
// a÷bの端数繰り上げ
// b!=0のデバグはしてないので分母に0を入れないように
// 負数対応
long long divup(long long a, long long b) {
long long x = abs(a);
long long y = abs(b);
long long z = (x + y - 1) / y;
if ((a < 0 && b > 0) || (a > 0 && b < 0))
return -z;
else if (a == 0)
return 0;
else
return z;
}
// 階乗
// 検証済み
long long kaijou(long long i) {
if (i == 0)
return 1;
long long j = 1;
for (long long k = 1; k <= i; k++) {
j *= k;
}
return j;
}
// 順列nPk(完成)
// n個の異なる要素から、取り出す順序を区別してk個取り出す場合の数
// n<kなら0を返す
// 敢えて負数時のデバグはしてない
long long P(long long n, long long k) {
if (n < k)
return 0;
long long y = 1;
for (long long i = 0; i < k; i++) {
y *= (n - i);
}
return y;
}
// 組み合わせnCk(検証済み)
// P,kaijouと併用
long long C(long long n, long long k) {
if (n < k)
return 0;
return P(n, k) / kaijou(k);
}
// nHk
// 区別しないn個の要素を、区別するk個のグループに分ける
// 0個のグループがあっ
// て良い
// C必須
// 最大公約数GCD,最小公倍数LCM
// LCMを使うときはGCDをセットで
// 検証済み
long long GCD(long long a, long long b) {
if (a < b)
swap(a, b);
long long d = a % b;
if (d == 0) {
return b;
}
return GCD(b, d);
}
long long LCM(long long a, long long b) { return (a / GCD(a, b)) * b; }
// 素数判定
// 素数ならばtrue、素数以外の整数にはfalse
// 負数は全てfalse
// 検証済み
bool prime(long long N) {
if (N == 1) {
return false;
}
if (N < 0)
return false;
long long p = sqrt(N);
for (long long i = 2; i <= p; i++) {
if (N % i == 0) {
return false;
}
}
return true;
}
// ユークリッド距離
// 検証済み
// 位置ベクトル1,位置ベクトル2,ベクトルの次元(2または3が一般的)
double distance(vector<long long> p, vector<long long> q, long long n) {
double x = 0;
for (long long i = 0; i < n; i++) {
x += pow((p.at(i) - q.at(i)), 2);
}
return sqrt(x);
}
// 配列圧縮(検証済)
//{1,36,1,3,8,-2,-92}を
//{2, 5,2,3,4, 1, 0}にする
void press(vector<long long> &v) {
long long n = v.size();
vector<long long> w(n);
map<long long, long long> m;
for (auto &p : v) {
m[p] = 0;
}
long long i = 0;
for (auto &p : m) {
p.second = i;
i++;
}
for (long long i = 0; i < n; i++) {
w.at(i) = m[v.at(i)];
}
v = w;
return;
}
// 配列のi番目の要素がj番目に小さいとき、j番目の数がiであるベクトルを返す関数
// 配列の要素が全て異なるときにしか正常に動作しない
// 配列の要素に同じものが含まれても見かけ上動作はするが意味のない値を戻し、
// エラーも起きないので注意
// 検証済
//{2,4,1,6,0,3,8,9,5}を
//{4,2,0,5,1,8,3,6,7}にして返す
//"rank"という名前にするとSTLの関数(配列の次元を返す関数)になるので注意
void ranking(vector<long long> &v) {
long long n = v.size();
map<long long, long long> m;
long long i;
for (i = 0; i < n; i++) {
m[v.at(i)] = i;
}
vector<long long> w(n);
i = 0;
for (auto &p : m) {
v.at(i) = p.second;
i++;
}
return;
}
// 部分削除(未検証)
// ベクトルのi番目(i=0,1,2,...,n-1)の要素を削除し、
// 以降の要素を全て前に1ずらして参照返し
// ベクトル長は1小さくなって返る
// i>n-1の時は変化しない
void erase(vector<long long> &v, long long i) {
long long n = v.size();
if (i > n - 1)
return;
for (long long j = i; j < n - 1; j++) {
v.at(j) = v.at(j + 1);
}
v.pop_back();
return;
}
// 重複削除(未完成)
// 引数ベクトルに同一要素が複数あるとき、先頭を残し他は削除
// 参照返し
// ベクトル長も変化する
// O(logn)くらい
void unique(vector<long long> &v) {
long long n = v.size();
set<long long> s;
long long i = 0;
while (i < n) {
if (s.count(v.at(i))) {
erase(v, i);
n--;
} else {
s.insert(v.at(i));
i++;
}
}
return;
}
// ベクトルの出力(検証済)
// debug用にvectorの中身を出力する
void printv(vector<long long> v) {
cout << "{ ";
for (auto &p : v) {
cout << p << ",";
}
cout << "}" << endl;
}
// 10進法でn桁の整数xに対して、大きい方の位から、その位の1桁の数字を
// 収納した長さnのベクトルを返す
// 0に対しては{0}を返す
// 検証済み
vector<ll> keta(ll x) {
if (x == 0)
return {0};
ll n = log10(x) + 1; // xの桁数
vll w(n, 0);
for (ll i = 0; i < n; i++) {
ll p;
p = x % 10;
x = x / 10;
w[n - 1 - i] = p;
}
return w;
}
// 20200415
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
long long res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
// a^{-1} mod を計算する
// modとaが互いに素のときのみ有効(数学的に逆元が一意に定まるのがそのときのみ)
long long modinv(long long a, long long mod) { return modpow(a, mod - 2, mod); }
// 整数n個の入力を受け取ってベクトルに突っ込んで返す
// チェック済み
vector<long long> inputv(long long n) {
vector<long long> v(n);
for (long long i = 0; i < n; i++) {
cin >> v[i];
}
return v;
}
vector<long long> yakusuu(long long n) // nの約数を列挙
{
vector<long long> ret;
for (long long i = 1; i <= sqrt(n); ++i) {
if (n % i == 0) {
ret.push_back(i);
if (i * i != n) {
ret.push_back(n / i);
}
}
}
sort(ret.begin(), ret.end());
return ret;
}
map<long long, long long> soinsuu(long long n) {
map<long long, long long> m;
long long p = sqrt(n);
while (n % 2 == 0) {
n /= 2;
if (m.count(2)) {
m[2]++;
} else {
m[2] = 1;
}
}
for (long long i = 3; i * i <= n; i += 2) {
while (n % i == 0) {
n /= i;
if (m.count(i)) {
m[i]++;
} else {
m[i] = 1;
}
}
}
if (n != 1)
m[n] = 1;
return m;
}
// スタートが(i,j)の迷路の全ての地点までの距離を幅優先探索で解く
// スタートから何マス離れているか(辿り着けない場合は-1)を入れたベクトルを返す
// 壁からスタートしても正常に動作するので注意(この関数の外で処理が必要)
// 検証済み 一応O(地図の広さ)くらい
vector<vector<long long>> maze(ll i, ll j, vector<string> &s) {
ll h = s.size();
ll w = s[0].size();
queue<vector<long long>> q;
vector<vector<long long>> dis(h, vll(w, -1));
q.push({i, j});
dis[i][j] = 0;
while (!q.empty()) {
auto v = q.front();
q.pop();
if (v[0] > 0 && s[v[0] - 1][v[1]] == '.' && dis[v[0] - 1][v[1]] == -1) {
dis[v[0] - 1][v[1]] = dis[v[0]][v[1]] + 1;
q.push({v[0] - 1, v[1]});
}
if (v[1] > 0 && s[v[0]][v[1] - 1] == '.' && dis[v[0]][v[1] - 1] == -1) {
dis[v[0]][v[1] - 1] = dis[v[0]][v[1]] + 1;
q.push({v[0], v[1] - 1});
}
if (v[0] < h - 1 && s[v[0] + 1][v[1]] == '.' && dis[v[0] + 1][v[1]] == -1) {
dis[v[0] + 1][v[1]] = dis[v[0]][v[1]] + 1;
q.push({v[0] + 1, v[1]});
}
if (v[1] < w - 1 && s[v[0]][v[1] + 1] == '.' && dis[v[0]][v[1] + 1] == -1) {
dis[v[0]][v[1] + 1] = dis[v[0]][v[1]] + 1;
q.push({v[0], v[1] + 1});
}
}
return dis; // スタートから何マス離れているか(辿り着けない場合は-1)
}
// エラトステネスのふるいによりn以下の素数を全てベクトルに入れて返す
// vector<long long> eratos(long long n){
// }
// 二項係数の剰余を求める
// 引数は剰余の形ではなくもとの数そのものである
// 未検証(検証サンプルがない)
long long modC(long long n, long long k, long long mod) {
if (n < k)
return 0;
long long p = 1, q = 1;
for (long long i = 0; i < k; i++) {
p = p * (n - i - 1) % mod;
q = q * (i + 1) % mod;
}
return p * modinv(q, mod) % mod;
}
// 20200418
// 整数のとき限定の普通のPOW関数
// 標準機能のpow(a,n)は整数だとバグるのでこちらを使う
long long POW(long long a, long long n) {
long long res = 1;
while (n > 0) {
if (n & 1)
res = res * a;
a = a * a;
n >>= 1;
}
return res;
}
// 20200423
// エラトステネスのふるいによりn以下の素数を全てベクトルに入れて返す
vector<long long> eratos(long long n) {
if (n < 2)
return {};
vll v(n - 1);
rep(i, n - 1) {
v[i] = i + 2; // 2からnまで
}
ll i = 0;
while (i < n - 1) {
ll p = v[i];
for (ll j = i + 1; j < n - 1; j++) {
if (v[j] % p == 0) {
v.erase(v.begin() + j);
n--;
}
}
i++;
}
v.resize(n - 1);
return v;
}
// n以下の素数を全て詰めたset
set<long long> eraset(long long n) {
set<long long> s;
vll v = eratos(n);
for (auto &t : v) {
s.insert(t);
}
return s;
}
// cout<<fixed<<setprecision(10);
//////////////////////////////////////////////////
int main() {
ll x, y, z, k;
cin >> x >> y >> z >> k;
auto a = inputv(x);
auto b = inputv(y);
auto c = inputv(z);
sort(all(a));
sort(all(b));
sort(all(c));
reverse(all(c));
ll w = x * y;
vll d(w);
rep(i, x) {
rep(j, y) { d[i + j * x] = a[i] + b[j]; }
}
sort(all(d));
reverse(all(d));
vvll v(w, vll(z, 1));
pq<vll> g;
g.push({c[0] + d[0], 0, 0});
rep(i, k) {
vll t = g.top();
g.pop();
cout << t[0] << endl;
ll r1 = t[1], r2 = t[2];
if (r1 != w - 1 && v[r1 + 1][r2]) {
g.push({d[r1 + 1] + c[r2], r1 + 1, r2});
v[r1 + 1][r2] = 0;
}
if (r2 != z - 1 && v[r1][r2 + 1]) {
g.push({d[r1] + c[r2 + 1], r1, 1 + r2});
v[r1][r2 + 1] = 0;
}
}
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
#define pq priority_queue
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vvvi = vector<vvi>;
using ll = long long; // long longをllだけにした
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using mii = map<int, int>;
using pqls = priority_queue<long long>;
using pqlg = priority_queue<long long, vector<long long>, greater<long long>>;
long long divup(long long a, long long b);
long long kaijou(long long i);
long long P(long long n, long long k);
long long C(long long n, long long k);
long long GCD(long long a, long long b);
long long LCM(long long a, long long b);
bool prime(long long N);
double distance(vector<long long> p, vector<long long> q, long long n);
void press(vector<long long> &v);
void ranking(vector<long long> &v);
void erase(vector<long long> &v, long long i);
void unique(vector<long long> &v);
void printv(vector<long long> v);
vector<ll> keta(ll x);
long long modpow(long long a, long long n, long long mod);
long long modinv(long long a, long long mod);
// 20200416
vector<long long> inputv(long long n);
// 20200417
vector<long long> yakusuu(int n);
map<long long, long long> soinsuu(long long n);
vector<vector<long long>> maze(long long i, long long j, vector<string> &s);
// 20200423
vector<long long> eratos(long long n);
set<long long> eraset(long long n);
//////////////////////////////////////////////////////
// 端数繰りあがり割り算(検証済)
// a÷bの端数繰り上げ
// b!=0のデバグはしてないので分母に0を入れないように
// 負数対応
long long divup(long long a, long long b) {
long long x = abs(a);
long long y = abs(b);
long long z = (x + y - 1) / y;
if ((a < 0 && b > 0) || (a > 0 && b < 0))
return -z;
else if (a == 0)
return 0;
else
return z;
}
// 階乗
// 検証済み
long long kaijou(long long i) {
if (i == 0)
return 1;
long long j = 1;
for (long long k = 1; k <= i; k++) {
j *= k;
}
return j;
}
// 順列nPk(完成)
// n個の異なる要素から、取り出す順序を区別してk個取り出す場合の数
// n<kなら0を返す
// 敢えて負数時のデバグはしてない
long long P(long long n, long long k) {
if (n < k)
return 0;
long long y = 1;
for (long long i = 0; i < k; i++) {
y *= (n - i);
}
return y;
}
// 組み合わせnCk(検証済み)
// P,kaijouと併用
long long C(long long n, long long k) {
if (n < k)
return 0;
return P(n, k) / kaijou(k);
}
// nHk
// 区別しないn個の要素を、区別するk個のグループに分ける
// 0個のグループがあっ
// て良い
// C必須
// 最大公約数GCD,最小公倍数LCM
// LCMを使うときはGCDをセットで
// 検証済み
long long GCD(long long a, long long b) {
if (a < b)
swap(a, b);
long long d = a % b;
if (d == 0) {
return b;
}
return GCD(b, d);
}
long long LCM(long long a, long long b) { return (a / GCD(a, b)) * b; }
// 素数判定
// 素数ならばtrue、素数以外の整数にはfalse
// 負数は全てfalse
// 検証済み
bool prime(long long N) {
if (N == 1) {
return false;
}
if (N < 0)
return false;
long long p = sqrt(N);
for (long long i = 2; i <= p; i++) {
if (N % i == 0) {
return false;
}
}
return true;
}
// ユークリッド距離
// 検証済み
// 位置ベクトル1,位置ベクトル2,ベクトルの次元(2または3が一般的)
double distance(vector<long long> p, vector<long long> q, long long n) {
double x = 0;
for (long long i = 0; i < n; i++) {
x += pow((p.at(i) - q.at(i)), 2);
}
return sqrt(x);
}
// 配列圧縮(検証済)
//{1,36,1,3,8,-2,-92}を
//{2, 5,2,3,4, 1, 0}にする
void press(vector<long long> &v) {
long long n = v.size();
vector<long long> w(n);
map<long long, long long> m;
for (auto &p : v) {
m[p] = 0;
}
long long i = 0;
for (auto &p : m) {
p.second = i;
i++;
}
for (long long i = 0; i < n; i++) {
w.at(i) = m[v.at(i)];
}
v = w;
return;
}
// 配列のi番目の要素がj番目に小さいとき、j番目の数がiであるベクトルを返す関数
// 配列の要素が全て異なるときにしか正常に動作しない
// 配列の要素に同じものが含まれても見かけ上動作はするが意味のない値を戻し、
// エラーも起きないので注意
// 検証済
//{2,4,1,6,0,3,8,9,5}を
//{4,2,0,5,1,8,3,6,7}にして返す
//"rank"という名前にするとSTLの関数(配列の次元を返す関数)になるので注意
void ranking(vector<long long> &v) {
long long n = v.size();
map<long long, long long> m;
long long i;
for (i = 0; i < n; i++) {
m[v.at(i)] = i;
}
vector<long long> w(n);
i = 0;
for (auto &p : m) {
v.at(i) = p.second;
i++;
}
return;
}
// 部分削除(未検証)
// ベクトルのi番目(i=0,1,2,...,n-1)の要素を削除し、
// 以降の要素を全て前に1ずらして参照返し
// ベクトル長は1小さくなって返る
// i>n-1の時は変化しない
void erase(vector<long long> &v, long long i) {
long long n = v.size();
if (i > n - 1)
return;
for (long long j = i; j < n - 1; j++) {
v.at(j) = v.at(j + 1);
}
v.pop_back();
return;
}
// 重複削除(未完成)
// 引数ベクトルに同一要素が複数あるとき、先頭を残し他は削除
// 参照返し
// ベクトル長も変化する
// O(logn)くらい
void unique(vector<long long> &v) {
long long n = v.size();
set<long long> s;
long long i = 0;
while (i < n) {
if (s.count(v.at(i))) {
erase(v, i);
n--;
} else {
s.insert(v.at(i));
i++;
}
}
return;
}
// ベクトルの出力(検証済)
// debug用にvectorの中身を出力する
void printv(vector<long long> v) {
cout << "{ ";
for (auto &p : v) {
cout << p << ",";
}
cout << "}" << endl;
}
// 10進法でn桁の整数xに対して、大きい方の位から、その位の1桁の数字を
// 収納した長さnのベクトルを返す
// 0に対しては{0}を返す
// 検証済み
vector<ll> keta(ll x) {
if (x == 0)
return {0};
ll n = log10(x) + 1; // xの桁数
vll w(n, 0);
for (ll i = 0; i < n; i++) {
ll p;
p = x % 10;
x = x / 10;
w[n - 1 - i] = p;
}
return w;
}
// 20200415
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
long long res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
// a^{-1} mod を計算する
// modとaが互いに素のときのみ有効(数学的に逆元が一意に定まるのがそのときのみ)
long long modinv(long long a, long long mod) { return modpow(a, mod - 2, mod); }
// 整数n個の入力を受け取ってベクトルに突っ込んで返す
// チェック済み
vector<long long> inputv(long long n) {
vector<long long> v(n);
for (long long i = 0; i < n; i++) {
cin >> v[i];
}
return v;
}
vector<long long> yakusuu(long long n) // nの約数を列挙
{
vector<long long> ret;
for (long long i = 1; i <= sqrt(n); ++i) {
if (n % i == 0) {
ret.push_back(i);
if (i * i != n) {
ret.push_back(n / i);
}
}
}
sort(ret.begin(), ret.end());
return ret;
}
map<long long, long long> soinsuu(long long n) {
map<long long, long long> m;
long long p = sqrt(n);
while (n % 2 == 0) {
n /= 2;
if (m.count(2)) {
m[2]++;
} else {
m[2] = 1;
}
}
for (long long i = 3; i * i <= n; i += 2) {
while (n % i == 0) {
n /= i;
if (m.count(i)) {
m[i]++;
} else {
m[i] = 1;
}
}
}
if (n != 1)
m[n] = 1;
return m;
}
// スタートが(i,j)の迷路の全ての地点までの距離を幅優先探索で解く
// スタートから何マス離れているか(辿り着けない場合は-1)を入れたベクトルを返す
// 壁からスタートしても正常に動作するので注意(この関数の外で処理が必要)
// 検証済み 一応O(地図の広さ)くらい
vector<vector<long long>> maze(ll i, ll j, vector<string> &s) {
ll h = s.size();
ll w = s[0].size();
queue<vector<long long>> q;
vector<vector<long long>> dis(h, vll(w, -1));
q.push({i, j});
dis[i][j] = 0;
while (!q.empty()) {
auto v = q.front();
q.pop();
if (v[0] > 0 && s[v[0] - 1][v[1]] == '.' && dis[v[0] - 1][v[1]] == -1) {
dis[v[0] - 1][v[1]] = dis[v[0]][v[1]] + 1;
q.push({v[0] - 1, v[1]});
}
if (v[1] > 0 && s[v[0]][v[1] - 1] == '.' && dis[v[0]][v[1] - 1] == -1) {
dis[v[0]][v[1] - 1] = dis[v[0]][v[1]] + 1;
q.push({v[0], v[1] - 1});
}
if (v[0] < h - 1 && s[v[0] + 1][v[1]] == '.' && dis[v[0] + 1][v[1]] == -1) {
dis[v[0] + 1][v[1]] = dis[v[0]][v[1]] + 1;
q.push({v[0] + 1, v[1]});
}
if (v[1] < w - 1 && s[v[0]][v[1] + 1] == '.' && dis[v[0]][v[1] + 1] == -1) {
dis[v[0]][v[1] + 1] = dis[v[0]][v[1]] + 1;
q.push({v[0], v[1] + 1});
}
}
return dis; // スタートから何マス離れているか(辿り着けない場合は-1)
}
// エラトステネスのふるいによりn以下の素数を全てベクトルに入れて返す
// vector<long long> eratos(long long n){
// }
// 二項係数の剰余を求める
// 引数は剰余の形ではなくもとの数そのものである
// 未検証(検証サンプルがない)
long long modC(long long n, long long k, long long mod) {
if (n < k)
return 0;
long long p = 1, q = 1;
for (long long i = 0; i < k; i++) {
p = p * (n - i - 1) % mod;
q = q * (i + 1) % mod;
}
return p * modinv(q, mod) % mod;
}
// 20200418
// 整数のとき限定の普通のPOW関数
// 標準機能のpow(a,n)は整数だとバグるのでこちらを使う
long long POW(long long a, long long n) {
long long res = 1;
while (n > 0) {
if (n & 1)
res = res * a;
a = a * a;
n >>= 1;
}
return res;
}
// 20200423
// エラトステネスのふるいによりn以下の素数を全てベクトルに入れて返す
vector<long long> eratos(long long n) {
if (n < 2)
return {};
vll v(n - 1);
rep(i, n - 1) {
v[i] = i + 2; // 2からnまで
}
ll i = 0;
while (i < n - 1) {
ll p = v[i];
for (ll j = i + 1; j < n - 1; j++) {
if (v[j] % p == 0) {
v.erase(v.begin() + j);
n--;
}
}
i++;
}
v.resize(n - 1);
return v;
}
// n以下の素数を全て詰めたset
set<long long> eraset(long long n) {
set<long long> s;
vll v = eratos(n);
for (auto &t : v) {
s.insert(t);
}
return s;
}
// cout<<fixed<<setprecision(10);
//////////////////////////////////////////////////
int main() {
ll x, y, z, k;
cin >> x >> y >> z >> k;
auto a = inputv(x);
auto b = inputv(y);
auto c = inputv(z);
sort(all(a));
sort(all(b));
sort(all(c));
reverse(all(c));
ll w = x * y;
vll d(w);
rep(i, x) {
rep(j, y) { d[i + j * x] = a[i] + b[j]; }
}
sort(all(d));
reverse(all(d));
if (w > k) {
d.resize(k);
w = k;
}
vvll v(w, vll(z, 1));
pq<vll> g;
g.push({c[0] + d[0], 0, 0});
rep(i, k) {
vll t = g.top();
g.pop();
cout << t[0] << endl;
ll r1 = t[1], r2 = t[2];
if (r1 != w - 1 && v[r1 + 1][r2]) {
g.push({d[r1 + 1] + c[r2], r1 + 1, r2});
v[r1 + 1][r2] = 0;
}
if (r2 != z - 1 && v[r1][r2 + 1]) {
g.push({d[r1] + c[r2 + 1], r1, 1 + r2});
v[r1][r2 + 1] = 0;
}
}
}
| insert | 443 | 443 | 443 | 447 | 0 | |
p03078 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, k, n) for (int i = (k); i < (int)(n); i++)
#define all(i, n) (i), (i + n)
int dx4[4] = {1, 0, -1, 0};
int dy4[4] = {0, -1, 0, 1};
int dx8[8] = {1, 0, -1, 1, -1, 1, 0, -1};
int dy8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6 + 1;
const ll mod = 1000000007;
// --------------------------------------
int x, y, z, k;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> x >> y >> z >> k;
vector<ll> a(x);
vector<ll> b(y);
vector<ll> c(z);
REP(i, x) cin >> a[i];
REP(i, y) cin >> b[i];
REP(i, z) cin >> c[i];
vector<ll> ab(x + y);
REP(i, x) {
REP(j, y) { ab.push_back(a[i] + b[j]); }
}
sort(ab.begin(), ab.end(), greater<ll>());
vector<ll> abc((x + y) * z);
REP(i, ab.size()) {
REP(j, z) { abc.push_back(ab[i] + c[j]); }
}
sort(abc.begin(), abc.end(), greater<ll>());
REP(i, k) { cout << abc[i] << endl; }
}
| #include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, k, n) for (int i = (k); i < (int)(n); i++)
#define all(i, n) (i), (i + n)
int dx4[4] = {1, 0, -1, 0};
int dy4[4] = {0, -1, 0, 1};
int dx8[8] = {1, 0, -1, 1, -1, 1, 0, -1};
int dy8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6 + 1;
const ll mod = 1000000007;
// --------------------------------------
int x, y, z, k;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> x >> y >> z >> k;
vector<ll> a(x);
vector<ll> b(y);
vector<ll> c(z);
REP(i, x) cin >> a[i];
REP(i, y) cin >> b[i];
REP(i, z) cin >> c[i];
vector<ll> ab(x + y);
REP(i, x) {
REP(j, y) { ab.push_back(a[i] + b[j]); }
}
sort(ab.begin(), ab.end(), greater<ll>());
vector<ll> abc((x + y) * z);
REP(i, min((int)ab.size(), k)) {
REP(j, z) { abc.push_back(ab[i] + c[j]); }
}
sort(abc.begin(), abc.end(), greater<ll>());
REP(i, k) { cout << abc[i] << endl; }
}
| replace | 58 | 59 | 58 | 59 | 0 | |
p03078 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
struct edge {
int to; // 辺の行き先
int weight; // 辺の重み
edge(int t, int w) : to(t), weight(w){};
};
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define brep(n) for (int bit = 0; bit < (1 << n); bit++)
#define erep(i, container) for (auto i : container)
#define irep(i, n) for (int i = n - 1; i >= (int)0; i--)
#define rrep(i, m, n) for (int i = m; i < (int)(n); i++)
#define reprep(i, j, h, w) rep(i, h) rep(j, w)
#define all(x) (x).begin(), (x).end()
#define aall(x, n) (x).begin(), (x).begin() + (n)
#define VEC(type, name, n) \
std::vector<type> name(n); \
rep(i, n) std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define res resize
#define as assign
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum accumulate
#define keta fixed << setprecision
#define vvector(name, typ, m, n, a) \
vector<vector<typ>> name(m, vector<typ>(n, a))
#define vvvector(name, t, l, m, n, a) \
vector<vector<vector<t>>> name(l, vector<vector<t>>(m, vector<t>(n, a)));
#define vvvvector(name, t, k, l, m, n, a) \
vector<vector<vector<vector<t>>>> name( \
k, vector<vector<vector<t>>>(l, vector<vector<t>>(m, vector<t>(n, a))));
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 9223372036854775806ll;
const int mod = 1000000007ll;
const ll MOD = 1000000007LL;
//-0.4620981203755741
std::vector<ll> aa;
ll x, y, z;
bool cn(const std::vector<ll> &c, ll k,
ll mi) { // 下のルーチンと併せてめぐる式二分探索
int cnt = 0;
rep(i, z) { cnt += int(aa.size() - (ub(all(aa), mi - c[i]) - aa.begin())); }
// std::cout << cnt << std::endl;
if (cnt <= k)
return false;
else
return true;
}
// 汎用的な二分探索のテンプレ
ll binary_search(const std::vector<ll> &c, ll key) {
ll ng = -1; // 「index = 0」が条件を満たすこともあるので、初期値は -1
ll ok =
INF64; // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は
// a.size()
/* ok と ng のどちらが大きいかわからないことを考慮 */
while (abs(ok - ng) > 1) {
ll mid = (ok + ng) / 2;
if (cn(c, key, mid))
ok = mid;
else
ng = mid;
}
return ok;
}
int main() {
ll k;
std::cin >> x >> y >> z >> k;
VEC(ll, a, x);
VEC(ll, b, y);
VEC(ll, c, z);
rep(i, x) rep(j, y) { aa.pb(a[i] + b[j]); }
sort(all(aa));
ll in = binary_search(c, k);
// std::cout << in << std::endl;
// std::cout << 123 << std::endl;
std::vector<ll> ans;
sort(all(aa), greater<ll>());
rep(i, z) {
rep(j, aa.size()) {
if (c[i] + aa[j] >= in)
ans.pb(c[i] + aa[j]);
else
break;
}
}
// std::cout << ans.size() << std::endl;
sort(all(ans), greater<ll>());
rep(i, k) { std::cout << ans[i] << std::endl; }
} | #include <bits/stdc++.h>
using namespace std;
struct edge {
int to; // 辺の行き先
int weight; // 辺の重み
edge(int t, int w) : to(t), weight(w){};
};
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define brep(n) for (int bit = 0; bit < (1 << n); bit++)
#define erep(i, container) for (auto i : container)
#define irep(i, n) for (int i = n - 1; i >= (int)0; i--)
#define rrep(i, m, n) for (int i = m; i < (int)(n); i++)
#define reprep(i, j, h, w) rep(i, h) rep(j, w)
#define all(x) (x).begin(), (x).end()
#define aall(x, n) (x).begin(), (x).begin() + (n)
#define VEC(type, name, n) \
std::vector<type> name(n); \
rep(i, n) std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define res resize
#define as assign
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum accumulate
#define keta fixed << setprecision
#define vvector(name, typ, m, n, a) \
vector<vector<typ>> name(m, vector<typ>(n, a))
#define vvvector(name, t, l, m, n, a) \
vector<vector<vector<t>>> name(l, vector<vector<t>>(m, vector<t>(n, a)));
#define vvvvector(name, t, k, l, m, n, a) \
vector<vector<vector<vector<t>>>> name( \
k, vector<vector<vector<t>>>(l, vector<vector<t>>(m, vector<t>(n, a))));
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 9223372036854775806ll;
const int mod = 1000000007ll;
const ll MOD = 1000000007LL;
//-0.4620981203755741
std::vector<ll> aa;
ll x, y, z;
bool cn(const std::vector<ll> &c, ll k,
ll mi) { // 下のルーチンと併せてめぐる式二分探索
int cnt = 0;
rep(i, z) { cnt += int(aa.size() - (ub(all(aa), mi - c[i]) - aa.begin())); }
// std::cout << cnt << std::endl;
if (cnt < k)
return false;
else
return true;
}
// 汎用的な二分探索のテンプレ
ll binary_search(const std::vector<ll> &c, ll key) {
ll ng = -1; // 「index = 0」が条件を満たすこともあるので、初期値は -1
ll ok =
INF64; // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は
// a.size()
/* ok と ng のどちらが大きいかわからないことを考慮 */
while (abs(ok - ng) > 1) {
ll mid = (ok + ng) / 2;
if (cn(c, key, mid))
ok = mid;
else
ng = mid;
}
return ok;
}
int main() {
ll k;
std::cin >> x >> y >> z >> k;
VEC(ll, a, x);
VEC(ll, b, y);
VEC(ll, c, z);
rep(i, x) rep(j, y) { aa.pb(a[i] + b[j]); }
sort(all(aa));
ll in = binary_search(c, k);
// std::cout << in << std::endl;
// std::cout << 123 << std::endl;
std::vector<ll> ans;
sort(all(aa), greater<ll>());
rep(i, z) {
rep(j, aa.size()) {
if (c[i] + aa[j] >= in)
ans.pb(c[i] + aa[j]);
else
break;
}
}
// std::cout << ans.size() << std::endl;
sort(all(ans), greater<ll>());
rep(i, k) { std::cout << ans[i] << std::endl; }
} | replace | 51 | 53 | 51 | 53 | TLE | |
p03078 | C++ | Runtime Error | #define _CRT_SECURE_NO_WARNINGS
/* include ***********************/
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* define *************************/
// for
#define REP(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define REPS(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define RREP(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define RREPS(i, n) for (int i = (int)(n); i > 0; i--)
#define FOR(i, s, n) \
for (int i = (int)(s), i##_len = (int)(n); i < i##_len; i++)
#define RFOR(i, s, n) \
for (int i = (int)(s)-1, i##_len = (int)(n); i >= i##_len; i--)
// printf
#define PRINTD(d) printf("%d\n", (d))
#define PRINTL(d) printf("%lld\n", (d))
// memset
#define m0(s) memset(s, 0, sizeof(s))
#define ml(s) memset(s, 63, sizeof(s))
#define fill(s, c) memset(s, c, sizeof(s))
#define INF 1e9
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;
int diff[4][2] = {
{0, -1},
{-1, 0},
{1, 0},
{0, 1},
};
// 今回の変数
ll d[1000000];
ll e[1000000];
int Min(int a, int b) { return (a) < (b) ? (a) : (b); }
int Max(int a, int b) { return (a) > (b) ? (a) : (b); }
ll Minl(ll a, ll b) { return (a) < (b) ? (a) : (b); }
ll Maxl(ll a, ll b) { return (a) > (b) ? (a) : (b); }
void Swap(int *a, int *b) {
int tmp = *a;
*a = *b;
*b = tmp;
}
void hSwap(ll x[], int i, int j) {
ll temp;
temp = x[i];
x[i] = x[j];
x[j] = temp;
}
void ShowData(ll x[], int left, int right) {
int i;
for (i = left; i <= right; i++)
printf("%lld ", x[i]);
printf("\n");
}
void QSort(ll x[], int left, int right, int n) {
int i, j; // 左端,右端
ll pivot; // 軸
i = left;
j = right;
pivot = x[(left + right) / 2];
while (1) {
if (n > 0) { // n>0なら昇順、n<=0なら降順
while ((x[i] < pivot) && (i <= right))
i++; // 軸値より大きい要素
while ((pivot < x[j]) && (i <= right))
j--; // 軸値より小さい要素
} else {
while ((x[i] > pivot) && (i <= right))
i++; // 軸値より小さい要素
while ((pivot > x[j]) && (i <= right))
j--; // 軸値より大きい要素
}
if (i >= j)
break;
hSwap(x, i, j);
i++;
j--;
}
// ShowData(x, left, right);
if (left < i - 1)
QSort(x, left, i - 1, n);
if (j + 1 < right)
QSort(x, j + 1, right, n);
}
int main() {
int x, y, z, k;
ll a[1000], b[1000], c[1000];
scanf("%d%d%d%d", &x, &y, &z, &k);
REP(i, x) { scanf("%lld", &a[i]); }
REP(i, y) { scanf("%lld", &b[i]); }
REP(i, z) { scanf("%lld", &c[i]); }
int cnt = 0;
REP(i, x) {
REP(j, y) { d[cnt++] = a[i] + b[j]; }
}
cnt = 0;
QSort(d, 0, x * y - 1, 0);
REP(i, Min(k, x * y)) {
REP(j, z) { e[cnt++] = d[i] + c[j]; }
}
QSort(e, 0, Min(k, x * y) * z - 1, 0);
REP(i, k) { PRINTL(e[i]); }
} | #define _CRT_SECURE_NO_WARNINGS
/* include ***********************/
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* define *************************/
// for
#define REP(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define REPS(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define RREP(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define RREPS(i, n) for (int i = (int)(n); i > 0; i--)
#define FOR(i, s, n) \
for (int i = (int)(s), i##_len = (int)(n); i < i##_len; i++)
#define RFOR(i, s, n) \
for (int i = (int)(s)-1, i##_len = (int)(n); i >= i##_len; i--)
// printf
#define PRINTD(d) printf("%d\n", (d))
#define PRINTL(d) printf("%lld\n", (d))
// memset
#define m0(s) memset(s, 0, sizeof(s))
#define ml(s) memset(s, 63, sizeof(s))
#define fill(s, c) memset(s, c, sizeof(s))
#define INF 1e9
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;
int diff[4][2] = {
{0, -1},
{-1, 0},
{1, 0},
{0, 1},
};
// 今回の変数
ll d[1000000];
ll e[3000000];
int Min(int a, int b) { return (a) < (b) ? (a) : (b); }
int Max(int a, int b) { return (a) > (b) ? (a) : (b); }
ll Minl(ll a, ll b) { return (a) < (b) ? (a) : (b); }
ll Maxl(ll a, ll b) { return (a) > (b) ? (a) : (b); }
void Swap(int *a, int *b) {
int tmp = *a;
*a = *b;
*b = tmp;
}
void hSwap(ll x[], int i, int j) {
ll temp;
temp = x[i];
x[i] = x[j];
x[j] = temp;
}
void ShowData(ll x[], int left, int right) {
int i;
for (i = left; i <= right; i++)
printf("%lld ", x[i]);
printf("\n");
}
void QSort(ll x[], int left, int right, int n) {
int i, j; // 左端,右端
ll pivot; // 軸
i = left;
j = right;
pivot = x[(left + right) / 2];
while (1) {
if (n > 0) { // n>0なら昇順、n<=0なら降順
while ((x[i] < pivot) && (i <= right))
i++; // 軸値より大きい要素
while ((pivot < x[j]) && (i <= right))
j--; // 軸値より小さい要素
} else {
while ((x[i] > pivot) && (i <= right))
i++; // 軸値より小さい要素
while ((pivot > x[j]) && (i <= right))
j--; // 軸値より大きい要素
}
if (i >= j)
break;
hSwap(x, i, j);
i++;
j--;
}
// ShowData(x, left, right);
if (left < i - 1)
QSort(x, left, i - 1, n);
if (j + 1 < right)
QSort(x, j + 1, right, n);
}
int main() {
int x, y, z, k;
ll a[1000], b[1000], c[1000];
scanf("%d%d%d%d", &x, &y, &z, &k);
REP(i, x) { scanf("%lld", &a[i]); }
REP(i, y) { scanf("%lld", &b[i]); }
REP(i, z) { scanf("%lld", &c[i]); }
int cnt = 0;
REP(i, x) {
REP(j, y) { d[cnt++] = a[i] + b[j]; }
}
cnt = 0;
QSort(d, 0, x * y - 1, 0);
REP(i, Min(k, x * y)) {
REP(j, z) { e[cnt++] = d[i] + c[j]; }
}
QSort(e, 0, Min(k, x * y) * z - 1, 0);
REP(i, k) { PRINTL(e[i]); }
} | replace | 42 | 43 | 42 | 43 | 0 | |
p03078 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); ++i)
inline char tc() {
static char fl[100], *A = fl, *B = fl;
return A == B && (B = (A = fl) + fread(fl, 1, 100, stdin), A == B) ? EOF
: *A++;
}
inline int intread() {
int a = 0;
static char c;
c = tc();
while (c & 16)
a = a * 10 + c - 48, c = tc();
return a;
}
inline ll llread() {
ll a = 0;
static char c;
c = tc();
while (c & 16)
a = a * 10 + c - 48, c = tc();
return a;
}
static const int buf_size = 4096;
static int write_pos = 0;
static char write_buf[buf_size];
inline void writeChar(ll x) {
if (write_pos == buf_size)
fwrite(write_buf, 1, buf_size, stdout), write_pos = 0;
write_buf[write_pos++] = x;
}
inline void write(ll x, char end) {
char s[24];
int n = 0;
while (x || !n)
s[n++] = '0' + x % 10, x /= 10;
while (n--)
writeChar(s[n]);
if (end)
writeChar(end);
}
struct Flusher {
~Flusher() {
if (write_pos)
fwrite(write_buf, 1, write_pos, stdout), write_pos = 0;
}
} flusher;
int X, Y, Z, K;
ll A[1000], B[1000], C[1000], ABC[10000];
int main() {
X = intread(), Y = intread(), Z = intread(), K = intread();
rep(i, X) A[i] = llread();
rep(i, Y) B[i] = llread();
rep(i, Z) C[i] = llread();
sort(A, A + X, greater<ll>());
sort(B, B + Y, greater<ll>());
sort(C, C + Z, greater<ll>());
int cnt = 0;
rep(a, X) {
rep(b, Y) {
if ((a + 1) * (b + 1) > K)
break;
rep(c, Z) {
if ((a + 1) * (b + 1) * (c + 1) > K)
break;
ABC[cnt++] = (A[a] + B[b] + C[c]);
}
}
}
sort(ABC, ABC + cnt, greater<ll>());
rep(i, K) { write(ABC[i], '\n'); }
return 0;
} | #include <algorithm>
#include <bitset>
#include <cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); ++i)
inline char tc() {
static char fl[100], *A = fl, *B = fl;
return A == B && (B = (A = fl) + fread(fl, 1, 100, stdin), A == B) ? EOF
: *A++;
}
inline int intread() {
int a = 0;
static char c;
c = tc();
while (c & 16)
a = a * 10 + c - 48, c = tc();
return a;
}
inline ll llread() {
ll a = 0;
static char c;
c = tc();
while (c & 16)
a = a * 10 + c - 48, c = tc();
return a;
}
static const int buf_size = 4096;
static int write_pos = 0;
static char write_buf[buf_size];
inline void writeChar(ll x) {
if (write_pos == buf_size)
fwrite(write_buf, 1, buf_size, stdout), write_pos = 0;
write_buf[write_pos++] = x;
}
inline void write(ll x, char end) {
char s[24];
int n = 0;
while (x || !n)
s[n++] = '0' + x % 10, x /= 10;
while (n--)
writeChar(s[n]);
if (end)
writeChar(end);
}
struct Flusher {
~Flusher() {
if (write_pos)
fwrite(write_buf, 1, write_pos, stdout), write_pos = 0;
}
} flusher;
int X, Y, Z, K;
ll A[1000], B[1000], C[1000], ABC[1000000];
int main() {
X = intread(), Y = intread(), Z = intread(), K = intread();
rep(i, X) A[i] = llread();
rep(i, Y) B[i] = llread();
rep(i, Z) C[i] = llread();
sort(A, A + X, greater<ll>());
sort(B, B + Y, greater<ll>());
sort(C, C + Z, greater<ll>());
int cnt = 0;
rep(a, X) {
rep(b, Y) {
if ((a + 1) * (b + 1) > K)
break;
rep(c, Z) {
if ((a + 1) * (b + 1) * (c + 1) > K)
break;
ABC[cnt++] = (A[a] + B[b] + C[c]);
}
}
}
sort(ABC, ABC + cnt, greater<ll>());
rep(i, K) { write(ABC[i], '\n'); }
return 0;
} | replace | 55 | 56 | 55 | 56 | 0 | |
p03078 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
// #include <boost/multiprecision/cpp_int.hpp>
const double EPS = (1e-10);
using namespace std;
using Int = long long;
// using namespace boost::multiprecision;
const Int MOD = 1000000007;
Int mod_pow(Int x, Int n) {
Int res = 1;
while (n > 0) {
if (n & 1)
res = (res * x) % MOD; // ビット演算(最下位ビットが1のとき)
x = (x * x) % MOD;
n >>= 1; // 右シフト(n = n >> 1)
}
return res;
}
// 最大公約数
template <typename T> T gcd(T a, T b) { return b != 0 ? gcd(b, a % b) : a; }
// 最小公倍数
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
long long ABC[3][1001];
vector<long long> AB_best;
vector<long long> ans;
int main() {
int xyzk[4];
for (int i = 0; i < 4; i++) {
cin >> xyzk[i];
}
for (int i = 0; i < 3; i++) {
for (int j = 0; j < xyzk[i]; j++) {
cin >> ABC[i][j];
}
}
AB_best = vector<long long>(xyzk[0] * xyzk[1]);
int cnt = 0;
for (int i = 0; i < xyzk[0]; i++) {
for (int j = 0; j < xyzk[1]; j++) {
AB_best[cnt++] = ABC[0][i] + ABC[1][j];
}
}
sort(AB_best.begin(), AB_best.end(), greater<long long>());
cnt = 0;
ans = vector<long long>(max(3000, xyzk[0] * xyzk[1]) * xyzk[2]);
for (int i = 0; i < AB_best.size() && i < 3000; i++) {
for (int j = 0; j < xyzk[2]; j++) {
ans[cnt++] = AB_best[i] + ABC[2][j];
}
}
sort(ans.begin(), ans.end(), greater<long long>());
for (int i = 0; i < xyzk[3]; i++) {
cout << ans[i] << endl;
}
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
// #include <boost/multiprecision/cpp_int.hpp>
const double EPS = (1e-10);
using namespace std;
using Int = long long;
// using namespace boost::multiprecision;
const Int MOD = 1000000007;
Int mod_pow(Int x, Int n) {
Int res = 1;
while (n > 0) {
if (n & 1)
res = (res * x) % MOD; // ビット演算(最下位ビットが1のとき)
x = (x * x) % MOD;
n >>= 1; // 右シフト(n = n >> 1)
}
return res;
}
// 最大公約数
template <typename T> T gcd(T a, T b) { return b != 0 ? gcd(b, a % b) : a; }
// 最小公倍数
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
long long ABC[3][1001];
vector<long long> AB_best;
vector<long long> ans;
int main() {
int xyzk[4];
for (int i = 0; i < 4; i++) {
cin >> xyzk[i];
}
for (int i = 0; i < 3; i++) {
for (int j = 0; j < xyzk[i]; j++) {
cin >> ABC[i][j];
}
}
AB_best = vector<long long>(xyzk[0] * xyzk[1]);
int cnt = 0;
for (int i = 0; i < xyzk[0]; i++) {
for (int j = 0; j < xyzk[1]; j++) {
AB_best[cnt++] = ABC[0][i] + ABC[1][j];
}
}
sort(AB_best.begin(), AB_best.end(), greater<long long>());
cnt = 0;
ans = vector<long long>(3000 * xyzk[2]);
for (int i = 0; i < AB_best.size() && i < 3000; i++) {
for (int j = 0; j < xyzk[2]; j++) {
ans[cnt++] = AB_best[i] + ABC[2][j];
}
}
sort(ans.begin(), ans.end(), greater<long long>());
for (int i = 0; i < xyzk[3]; i++) {
cout << ans[i] << endl;
}
return 0;
}
| replace | 70 | 71 | 70 | 71 | 0 | |
p03078 | C++ | Runtime Error | #include <algorithm>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
long long f(vector<vector<long long>> cake, vector<int> pos) {
long long sum = 0;
for (int i = 0; i < 3; i++) {
sum += cake[i][pos[i]];
}
return sum;
}
bool fflag(set<vector<int>> flag, vector<int> pos) {
if (flag.find(pos) == flag.end()) {
return false;
}
return true;
}
int main() {
vector<int> size(3);
for (int i = 0; i < 3; i++) {
cin >> size[i];
}
set<vector<int>> flag;
int K;
cin >> K;
vector<vector<long long>> cake;
cake.resize(3);
for (int i = 0; i < 3; i++) {
cake[i].resize(size[i]);
for (int j = 0; j < size[i]; j++) {
cin >> cake[i][j];
}
}
for (int i = 0; i < 3; i++) {
sort(cake[i].begin(), cake[i].end(), greater<long long>());
}
priority_queue<pair<long long, vector<int>>> q;
vector<int> initial{0, 0, 0};
q.push(make_pair(f(cake, initial), initial));
flag.insert(initial);
for (int k = 0; k < K; k++) {
cout << q.top().first << endl;
vector<int> list = q.top().second;
q.pop();
if (k == K - 1) {
break;
}
vector<vector<int>> next(3);
next[0] = {list[0] + 1, list[1], list[2]};
next[1] = {list[0], list[1] + 1, list[2]};
next[2] = {list[0], list[1], list[2] + 1};
for (int i = 0; i < 3; i++) {
if (list[i] + 1 >= size[i] || flag.find(next[i]) != flag.end() ||
*flag.end() == next[i]) {
continue;
}
q.push(make_pair(f(cake, next[i]), next[i]));
flag.insert(next[i]);
}
}
return 0;
} | #include <algorithm>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
long long f(vector<vector<long long>> cake, vector<int> pos) {
long long sum = 0;
for (int i = 0; i < 3; i++) {
sum += cake[i][pos[i]];
}
return sum;
}
bool fflag(set<vector<int>> flag, vector<int> pos) {
if (flag.find(pos) == flag.end()) {
return false;
}
return true;
}
int main() {
vector<int> size(3);
for (int i = 0; i < 3; i++) {
cin >> size[i];
}
set<vector<int>> flag;
int K;
cin >> K;
vector<vector<long long>> cake;
cake.resize(3);
for (int i = 0; i < 3; i++) {
cake[i].resize(size[i]);
for (int j = 0; j < size[i]; j++) {
cin >> cake[i][j];
}
}
for (int i = 0; i < 3; i++) {
sort(cake[i].begin(), cake[i].end(), greater<long long>());
}
priority_queue<pair<long long, vector<int>>> q;
vector<int> initial{0, 0, 0};
q.push(make_pair(f(cake, initial), initial));
flag.insert(initial);
for (int k = 0; k < K; k++) {
cout << q.top().first << endl;
vector<int> list = q.top().second;
q.pop();
if (k == K - 1) {
break;
}
vector<vector<int>> next(3);
next[0] = {list[0] + 1, list[1], list[2]};
next[1] = {list[0], list[1] + 1, list[2]};
next[2] = {list[0], list[1], list[2] + 1};
for (int i = 0; i < 3; i++) {
if (list[i] + 1 >= size[i] || flag.find(next[i]) != flag.end()) {
continue;
}
q.push(make_pair(f(cake, next[i]), next[i]));
flag.insert(next[i]);
}
}
return 0;
} | replace | 68 | 70 | 68 | 69 | 0 | |
p03078 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define LL long long
LL a[1005], b[1005], c[1005];
vector<LL> ans;
int main() {
LL x, y, z, k;
while (cin >> x >> y >> z >> k) {
for (int i = 0; i < x; i++)
cin >> a[i];
for (int i = 0; i < y; i++)
cin >> b[i];
for (int i = 0; i < z; i++)
cin >> c[i];
sort(a, a + x, greater<LL>());
sort(b, b + y, greater<LL>());
sort(c, c + z, greater<LL>());
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
for (int l = 0; l < z; l++) {
ans.push_back(a[i] + b[j] + c[l]);
}
}
}
sort(ans.begin(), ans.end(), greater<LL>());
for (int i = 0; i < k; i++) {
cout << ans[i] << endl;
}
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define LL long long
LL a[1005], b[1005], c[1005];
vector<LL> ans;
int main() {
LL x, y, z, k;
while (cin >> x >> y >> z >> k) {
for (int i = 0; i < x; i++)
cin >> a[i];
for (int i = 0; i < y; i++)
cin >> b[i];
for (int i = 0; i < z; i++)
cin >> c[i];
sort(a, a + x, greater<LL>());
sort(b, b + y, greater<LL>());
sort(c, c + z, greater<LL>());
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
for (int l = 0; l < z; l++) {
if ((i + 1) * (j + 1) * (l + 1) <= k)
ans.push_back(a[i] + b[j] + c[l]);
else
break;
}
}
}
sort(ans.begin(), ans.end(), greater<LL>());
for (int i = 0; i < k; i++) {
cout << ans[i] << endl;
}
}
return 0;
}
| replace | 23 | 24 | 23 | 27 | 0 | |
p03078 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define all(x) (x).begin(), (x).end()
// ** Solution Number 1
// int main()
// {
// int x,y,z,k;
// cin >> x >> y >> z >> k;
// ll a[x],b[y],c[z];
// for(int i=0;i<x;i++)cin >> a[i];
// for(int i=0;i<y;i++)cin >> b[i];
// for(int i=0;i<z;i++)cin >> c[i];
// sort(a,a+x,greater<ll>());
// sort(b,b+y,greater<ll>());
// sort(c,c+z,greater<ll>());
// vector<ll> ans;
// for(int i=0;i<x;i++)
// {
// for(int j=0;j<y;j++)
// {
// for(int t=0;t<z;t++)
// {
// if((i+1)*(j+1)*(t+1)<=k)ans.push_back(a[i]+b[j]+c[t]);
// else break;
// }
// }
// }
// sort(ans.begin(),ans.end(),greater<ll>());
// //for(int i=0;i<k;i++)cout << ans[i] << endl;
// //cout << k << " " << ans.size();
// }
// Solution Number 2
int main() {
int x, y, z, k;
cin >> x >> y >> z >> k;
ll a[x], b[y], c[z];
for (int i = 0; i < x; i++)
cin >> a[i];
for (int i = 0; i < y; i++)
cin >> b[i];
for (int i = 0; i < z; i++)
cin >> c[i];
vector<ll> xy, xyz;
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
xy.push_back(a[i] + b[j]);
}
}
sort(all(xy), greater<ll>());
for (int i = 0; i < (int)xy.size(); i++) {
for (int j = 0; j < z; j++) {
xyz.push_back(xy[i] + c[j]);
}
}
sort(all(xyz), greater<ll>());
for (int i = 0; i < k; i++)
cout << xyz[i] << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define all(x) (x).begin(), (x).end()
// ** Solution Number 1
// int main()
// {
// int x,y,z,k;
// cin >> x >> y >> z >> k;
// ll a[x],b[y],c[z];
// for(int i=0;i<x;i++)cin >> a[i];
// for(int i=0;i<y;i++)cin >> b[i];
// for(int i=0;i<z;i++)cin >> c[i];
// sort(a,a+x,greater<ll>());
// sort(b,b+y,greater<ll>());
// sort(c,c+z,greater<ll>());
// vector<ll> ans;
// for(int i=0;i<x;i++)
// {
// for(int j=0;j<y;j++)
// {
// for(int t=0;t<z;t++)
// {
// if((i+1)*(j+1)*(t+1)<=k)ans.push_back(a[i]+b[j]+c[t]);
// else break;
// }
// }
// }
// sort(ans.begin(),ans.end(),greater<ll>());
// //for(int i=0;i<k;i++)cout << ans[i] << endl;
// //cout << k << " " << ans.size();
// }
// Solution Number 2
int main() {
int x, y, z, k;
cin >> x >> y >> z >> k;
ll a[x], b[y], c[z];
for (int i = 0; i < x; i++)
cin >> a[i];
for (int i = 0; i < y; i++)
cin >> b[i];
for (int i = 0; i < z; i++)
cin >> c[i];
vector<ll> xy, xyz;
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
xy.push_back(a[i] + b[j]);
}
}
sort(all(xy), greater<ll>());
sort(c, c + z, greater<ll>());
ll cnt = 0;
bool ok = true;
for (int i = 0; i < min(k, (int)xy.size()); i++) {
for (int j = 0; j < z; j++) {
xyz.push_back(xy[i] + c[j]);
}
}
sort(all(xyz), greater<ll>());
for (int i = 0; i < k; i++)
cout << xyz[i] << endl;
}
| replace | 58 | 60 | 58 | 62 | TLE | |
p03078 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, int(n) + 1)
#define rrep(i, n) RFOR(i, 0, n)
#define rrep1(i, n) RFOR(i, 1, int(n) + 1)
#define all(c) begin(c), end(c)
#define al(d) d.begin(), d.end()
#define fill(n) std::setfill('0') << std::right << std::setw(n)
#define intmax 2147483647
#define llmax 9223372036854775807
#define mod 1000000007
template <typename T> using vec = std::vector<T>;
using vi = vec<int>;
using vvi = vec<vi>;
using pii = std::pair<int, int>;
using ll = long long;
using vll = vec<ll>;
using ld = long double;
#define pair(a, b) "(" << a << "," << b << ")"
#define pairr(a, b, c) "(" << a << "," << b << "," << c << ")"
template <typename T> void putv(vector<T> &V) {
// cout << "The elements in the vector are: " << endl;
for (auto x : V)
cout << x << " ";
cout << endl;
}
template <class T> vector<T> getv(int n) {
vector<T> vec;
rep(i, n) {
T input;
cin >> input;
vec.emplace_back(input);
}
return vec;
}
////Graph
using Weight = ll;
using Flow = int;
struct Edge {
int src, dst;
Weight weight;
Flow cap;
Edge() : src(0), dst(0), weight(0) {}
Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {}
};
using Edges = std::vector<Edge>;
using Graph = std::vector<Edges>;
using Array = std::vector<Weight>;
using Matrix = std::vector<Array>;
void add_edge(Graph &g, int a, int b, Weight w = 1) {
g[a].emplace_back(a, b, w);
g[b].emplace_back(b, a, w);
}
void add_arc(Graph &g, int a, int b, Weight w = 1) {
g[a].emplace_back(a, b, w);
}
void init_weighted_graph(Graph &g, int N, int M) {
vector<Edge> empty_Edges;
g = Graph(N, empty_Edges);
rep(i, M) {
int a, b, w;
cin >> a >> b >> w;
add_edge(g, a - 1, b - 1, w);
}
// 例えば
//// 3 3
//// 1 2 1
//// 1 3 1
//// 2 3 3
// から
//// The Adjacency List of
//// G=(V,E) (n=3,m=6)
//// 0: (1,1)(2,1)
//// 1: (0,1)(2,3)
//// 2: (0,1)(1,3)
// を得る.
}
void init_weighted_directed_graph(Graph &g, int N, int M) {
vector<Edge> empty_Edges;
g = Graph(N, empty_Edges);
rep(i, M) {
int a, b, w;
cin >> a >> b >> w;
add_arc(g, a - 1, b - 1, w);
}
}
void show_weighted_graph(const Graph &g) {
int N = g.size();
int M = 0;
rep(s, N) M += g[s].size();
cout << "///////////////////////" << endl;
cout << "The Adjacency List of" << endl
<< "G=(V,E) (n=" << N << ","
<< "m=" << M << ")" << endl;
rep(s, N) {
cout << s << ": ";
int size = g[s].size();
rep(t, size) cout << pair(g[s][t].dst, g[s][t].weight);
cout << endl;
}
cout << "////////////////////////" << endl << endl;
}
// a->bが存在するか
bool is_adj(Graph &g, int a, int b) {
for (auto e : g[a])
if (b == e.dst)
return true;
return false;
}
// O(V^3)
Matrix warshallFloyd(const Graph &g) {
auto const inf = numeric_limits<Weight>::max() / 8;
int n = g.size();
Matrix d(n, Array(n, inf));
rep(i, n) d[i][i] = 0;
rep(i, n) for (auto &e : g[i]) d[e.src][e.dst] =
min(d[e.src][e.dst], e.weight);
rep(k, n) rep(i, n) rep(j, n) if (d[i][k] != inf && d[k][j] != inf) d[i][j] =
min(d[i][j], d[i][k] + d[k][j]);
return d;
}
//////////
void out(bool ans) {
if (ans == true)
cout << "yes" << endl;
else
cout << "no" << endl;
}
void Out(bool ans) {
if (ans == true)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
void OUT(bool ans) {
if (ans == true)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
//// Mathematical functions
ll gcd(const ll a, const ll b) { return (b == 0) ? a : gcd(b, a % b); }
ll lcm(const ll a, const ll b) { return a * (b / gcd(a, b)); }
ll Manhattan_dist(ll x1, ll y1, ll x2, ll y2) {
return abs(x1 - x2) + abs(y1 - y2);
}
// nをpで何回割れるか
ll hmt_p_divide_n(ll p, ll n) {
ll s = 0;
while (n % p == 0) {
n /= p;
s++;
}
return s;
}
int digit(ll n) {
int cntr = 0;
while (n > 0) {
n /= 10;
cntr++;
}
return cntr;
}
// generarized absolute value
template <class T> T gabs(const T &x) { return max(x, -x); }
#define abs gabs
// unsigned long long nCr(int n, int r){
// unsigned long long ans = 1;
// for(int i=n; i>n-r; --i) ans*=i;
// for(int i=1; i<r+1; ++i) ans/=i;
// return ans;
// }
unsigned long long memo[100][100] = {};
unsigned long long nCr(const int n, const int r) {
if (n < r)
return 0;
if (r == 0 || n == r)
return 1;
if (memo[n][r] > 0)
return memo[n][r];
else
return memo[n][r] = nCr(n - 1, r) + nCr(n - 1, r - 1);
}
ll pw(ll x, int y) {
ll a = 1;
while (y) {
if (y & 1)
a = (a * x) % mod;
x = (x * x) % mod;
y >>= 1;
}
return a;
}
ll modinv(ll x) { return pw(x, mod - 2); }
//////////////////////////////////////////////////
//////////////////////////////////////////////////
//////////////////////////////////////////////////
int x, y, z;
ll k;
vll a;
vll b;
vll c;
ll pa = 0, pb = 0, pc = 0;
void solve() {
cout << pairr(pa, pb, pc) << endl;
cout << a[pa] + b[pb] + c[pc] << endl;
}
int main() {
cin >> x >> y >> z >> k;
ll M = 1e5;
a = getv<ll>(x);
b = getv<ll>(y);
c = getv<ll>(z);
sort(a.rbegin(), a.rend());
sort(b.rbegin(), b.rend());
sort(c.rbegin(), c.rend());
vll nums;
rep(i, x) rep(j, y) rep(l, z) nums.emplace_back(a[i] + b[j] + c[l]);
sort(nums.rbegin(), nums.rend());
rep(i, k) cout << nums[i] << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, int(n) + 1)
#define rrep(i, n) RFOR(i, 0, n)
#define rrep1(i, n) RFOR(i, 1, int(n) + 1)
#define all(c) begin(c), end(c)
#define al(d) d.begin(), d.end()
#define fill(n) std::setfill('0') << std::right << std::setw(n)
#define intmax 2147483647
#define llmax 9223372036854775807
#define mod 1000000007
template <typename T> using vec = std::vector<T>;
using vi = vec<int>;
using vvi = vec<vi>;
using pii = std::pair<int, int>;
using ll = long long;
using vll = vec<ll>;
using ld = long double;
#define pair(a, b) "(" << a << "," << b << ")"
#define pairr(a, b, c) "(" << a << "," << b << "," << c << ")"
template <typename T> void putv(vector<T> &V) {
// cout << "The elements in the vector are: " << endl;
for (auto x : V)
cout << x << " ";
cout << endl;
}
template <class T> vector<T> getv(int n) {
vector<T> vec;
rep(i, n) {
T input;
cin >> input;
vec.emplace_back(input);
}
return vec;
}
////Graph
using Weight = ll;
using Flow = int;
struct Edge {
int src, dst;
Weight weight;
Flow cap;
Edge() : src(0), dst(0), weight(0) {}
Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {}
};
using Edges = std::vector<Edge>;
using Graph = std::vector<Edges>;
using Array = std::vector<Weight>;
using Matrix = std::vector<Array>;
void add_edge(Graph &g, int a, int b, Weight w = 1) {
g[a].emplace_back(a, b, w);
g[b].emplace_back(b, a, w);
}
void add_arc(Graph &g, int a, int b, Weight w = 1) {
g[a].emplace_back(a, b, w);
}
void init_weighted_graph(Graph &g, int N, int M) {
vector<Edge> empty_Edges;
g = Graph(N, empty_Edges);
rep(i, M) {
int a, b, w;
cin >> a >> b >> w;
add_edge(g, a - 1, b - 1, w);
}
// 例えば
//// 3 3
//// 1 2 1
//// 1 3 1
//// 2 3 3
// から
//// The Adjacency List of
//// G=(V,E) (n=3,m=6)
//// 0: (1,1)(2,1)
//// 1: (0,1)(2,3)
//// 2: (0,1)(1,3)
// を得る.
}
void init_weighted_directed_graph(Graph &g, int N, int M) {
vector<Edge> empty_Edges;
g = Graph(N, empty_Edges);
rep(i, M) {
int a, b, w;
cin >> a >> b >> w;
add_arc(g, a - 1, b - 1, w);
}
}
void show_weighted_graph(const Graph &g) {
int N = g.size();
int M = 0;
rep(s, N) M += g[s].size();
cout << "///////////////////////" << endl;
cout << "The Adjacency List of" << endl
<< "G=(V,E) (n=" << N << ","
<< "m=" << M << ")" << endl;
rep(s, N) {
cout << s << ": ";
int size = g[s].size();
rep(t, size) cout << pair(g[s][t].dst, g[s][t].weight);
cout << endl;
}
cout << "////////////////////////" << endl << endl;
}
// a->bが存在するか
bool is_adj(Graph &g, int a, int b) {
for (auto e : g[a])
if (b == e.dst)
return true;
return false;
}
// O(V^3)
Matrix warshallFloyd(const Graph &g) {
auto const inf = numeric_limits<Weight>::max() / 8;
int n = g.size();
Matrix d(n, Array(n, inf));
rep(i, n) d[i][i] = 0;
rep(i, n) for (auto &e : g[i]) d[e.src][e.dst] =
min(d[e.src][e.dst], e.weight);
rep(k, n) rep(i, n) rep(j, n) if (d[i][k] != inf && d[k][j] != inf) d[i][j] =
min(d[i][j], d[i][k] + d[k][j]);
return d;
}
//////////
void out(bool ans) {
if (ans == true)
cout << "yes" << endl;
else
cout << "no" << endl;
}
void Out(bool ans) {
if (ans == true)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
void OUT(bool ans) {
if (ans == true)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
//// Mathematical functions
ll gcd(const ll a, const ll b) { return (b == 0) ? a : gcd(b, a % b); }
ll lcm(const ll a, const ll b) { return a * (b / gcd(a, b)); }
ll Manhattan_dist(ll x1, ll y1, ll x2, ll y2) {
return abs(x1 - x2) + abs(y1 - y2);
}
// nをpで何回割れるか
ll hmt_p_divide_n(ll p, ll n) {
ll s = 0;
while (n % p == 0) {
n /= p;
s++;
}
return s;
}
int digit(ll n) {
int cntr = 0;
while (n > 0) {
n /= 10;
cntr++;
}
return cntr;
}
// generarized absolute value
template <class T> T gabs(const T &x) { return max(x, -x); }
#define abs gabs
// unsigned long long nCr(int n, int r){
// unsigned long long ans = 1;
// for(int i=n; i>n-r; --i) ans*=i;
// for(int i=1; i<r+1; ++i) ans/=i;
// return ans;
// }
unsigned long long memo[100][100] = {};
unsigned long long nCr(const int n, const int r) {
if (n < r)
return 0;
if (r == 0 || n == r)
return 1;
if (memo[n][r] > 0)
return memo[n][r];
else
return memo[n][r] = nCr(n - 1, r) + nCr(n - 1, r - 1);
}
ll pw(ll x, int y) {
ll a = 1;
while (y) {
if (y & 1)
a = (a * x) % mod;
x = (x * x) % mod;
y >>= 1;
}
return a;
}
ll modinv(ll x) { return pw(x, mod - 2); }
//////////////////////////////////////////////////
//////////////////////////////////////////////////
//////////////////////////////////////////////////
int x, y, z;
ll k;
vll a;
vll b;
vll c;
ll pa = 0, pb = 0, pc = 0;
void solve() {
cout << pairr(pa, pb, pc) << endl;
cout << a[pa] + b[pb] + c[pc] << endl;
}
int main() {
cin >> x >> y >> z >> k;
ll M = 1e5;
a = getv<ll>(x);
b = getv<ll>(y);
c = getv<ll>(z);
sort(a.rbegin(), a.rend());
sort(b.rbegin(), b.rend());
sort(c.rbegin(), c.rend());
vll nums;
rep(i, x) rep(j, y) rep(l, z) if (i * j * l < k)
nums.emplace_back(a[i] + b[j] + c[l]);
sort(nums.rbegin(), nums.rend());
rep(i, k) cout << nums[i] << endl;
} | replace | 232 | 233 | 232 | 234 | TLE | |
p03078 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int main() {
long long X, Y, Z, K;
cin >> X >> Y >> Z >> K;
long long A[X], B[Y], C[Z];
for (int i = 0; i < X; i++)
cin >> A[i];
for (int i = 0; i < Y; i++)
cin >> B[i];
for (int i = 0; i < Z; i++)
cin >> C[i];
sort(A, A + X, greater<long long>());
sort(B, B + Y, greater<long long>());
sort(C, C + Z, greater<long long>());
vector<long long> ans;
for (int x = 0; x < X; x++) {
for (int y = 0; y < Y; y++) {
for (int z = 0; z < Z; z++) {
ans.push_back(A[x] + B[y] + C[z]);
// if (x * y * z > K) break;
}
}
}
sort(ans.begin(), ans.end(), greater<long long>());
for (int i = 0; i < K; i++) {
cout << ans[i] << endl;
}
return 0;
}
| #include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int main() {
long long X, Y, Z, K;
cin >> X >> Y >> Z >> K;
long long A[X], B[Y], C[Z];
for (int i = 0; i < X; i++)
cin >> A[i];
for (int i = 0; i < Y; i++)
cin >> B[i];
for (int i = 0; i < Z; i++)
cin >> C[i];
sort(A, A + X, greater<long long>());
sort(B, B + Y, greater<long long>());
sort(C, C + Z, greater<long long>());
vector<long long> ans;
for (int x = 0; x < X; x++) {
for (int y = 0; y < Y; y++) {
for (int z = 0; z < Z; z++) {
ans.push_back(A[x] + B[y] + C[z]);
if (x * y * z > K)
break;
}
}
}
sort(ans.begin(), ans.end(), greater<long long>());
for (int i = 0; i < K; i++) {
cout << ans[i] << endl;
}
return 0;
}
| replace | 28 | 29 | 28 | 30 | TLE | |
p03078 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 99999999999
#define rep(i, m, n) for (lli i = m; i < n; i++)
#define rrep(i, m, n) for (lli i = m - 1; i >= n; i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(), N.end()), N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(), n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(150) << S << endl
#define Vec(K, L, N, S) vector<L> K(N, S)
#define DV(K, L, N, M, S) vector<vector<L>> K(N, vector<L>(M, S))
#define TV(K, L, N, M, R, S) \
vector<vector<vector<L>>> K(N, vector<vector<L>>(M, vector<L>(R, S)))
#define pint pair<lli, lli>
#define paf(L, R) pair<L, R>
#define mod 1000000007
#define MAX 5100000
#define chmax(a, b) a = (((a) < (b)) ? (b) : (a))
#define chmin(a, b) a = (((a) > (b)) ? (b) : (a))
int main() {
lli A, B, C, D, E, F, N, M, K, L, R, X, Y, H, W, sum = 0, num = 0, flag = 0;
string S, T;
cin >> A >> B >> C >> K;
Vec(P, lli, A, 0);
Vec(Q, lli, B, 0);
Vec(O, lli, C, 0);
rep(i, 0, A) cin >> P[i];
rep(i, 0, B) cin >> Q[i];
rep(i, 0, C) cin >> O[i];
priority_queue<lli> que;
rep(i, 0, A) rep(j, 0, B) rep(k, 0, C) {
if ((i + 1) * (j + 1) * (k + 1) < K)
break;
que.push(P[i] + Q[j] + O[k]);
}
rep(i, 0, K) {
Out(que.top());
que.pop();
}
}
| #include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 99999999999
#define rep(i, m, n) for (lli i = m; i < n; i++)
#define rrep(i, m, n) for (lli i = m - 1; i >= n; i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(), N.end()), N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(), n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(150) << S << endl
#define Vec(K, L, N, S) vector<L> K(N, S)
#define DV(K, L, N, M, S) vector<vector<L>> K(N, vector<L>(M, S))
#define TV(K, L, N, M, R, S) \
vector<vector<vector<L>>> K(N, vector<vector<L>>(M, vector<L>(R, S)))
#define pint pair<lli, lli>
#define paf(L, R) pair<L, R>
#define mod 1000000007
#define MAX 5100000
#define chmax(a, b) a = (((a) < (b)) ? (b) : (a))
#define chmin(a, b) a = (((a) > (b)) ? (b) : (a))
int main() {
lli A, B, C, D, E, F, N, M, K, L, R, X, Y, H, W, sum = 0, num = 0, flag = 0;
string S, T;
cin >> A >> B >> C >> K;
Vec(P, lli, A, 0);
Vec(Q, lli, B, 0);
Vec(O, lli, C, 0);
rep(i, 0, A) cin >> P[i];
rep(i, 0, B) cin >> Q[i];
rep(i, 0, C) cin >> O[i];
priority_queue<lli> que;
Sort(P);
Sort(Q);
Sort(O);
Rev(P);
Rev(Q);
Rev(O);
rep(i, 0, A) rep(j, 0, B)
rep(k, 0, C) if ((i + 1) * (j + 1) * (k + 1) < K + 1)
que.push(P[i] + Q[j] + O[k]);
rep(i, 0, K) {
Out(que.top());
que.pop();
}
}
| replace | 35 | 40 | 35 | 44 | -11 | |
p03078 | C++ | Runtime Error | #include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main() {
ll x, y, z, k, a[1005], b[1005], c[1005];
cin >> x >> y >> z >> k;
for (int i = 0; i < x; i++)
cin >> a[i];
for (int i = 0; i < y; i++)
cin >> b[i];
for (int i = 0; i < z; i++)
cin >> c[i];
ll ab[1000005];
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
ab[y * i + j] = (a[i] + b[j]);
}
}
sort(ab, ab + (x * y));
reverse(ab, ab + (x * y));
ll abc[3005];
int l = min(x * y, k);
for (int i = 0; i < l; i++) {
for (int j = 0; j < z; j++) {
abc[z * i + j] = ab[i] + c[j];
}
}
sort(abc, abc + l * z);
reverse(abc, abc + l * z);
for (int i = 0; i < k; i++) {
cout << abc[i] << endl;
}
return 0;
} | #include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main() {
ll x, y, z, k, a[1005], b[1005], c[1005];
cin >> x >> y >> z >> k;
for (int i = 0; i < x; i++)
cin >> a[i];
for (int i = 0; i < y; i++)
cin >> b[i];
for (int i = 0; i < z; i++)
cin >> c[i];
ll ab[1000005];
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
ab[y * i + j] = (a[i] + b[j]);
}
}
sort(ab, ab + (x * y));
reverse(ab, ab + (x * y));
ll abc[3000005];
int l = min(x * y, k);
for (int i = 0; i < l; i++) {
for (int j = 0; j < z; j++) {
abc[z * i + j] = ab[i] + c[j];
}
}
sort(abc, abc + l * z);
reverse(abc, abc + l * z);
for (int i = 0; i < k; i++) {
cout << abc[i] << endl;
}
return 0;
} | replace | 21 | 22 | 21 | 22 | 0 | |
p03078 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
// #define cerr if(false) cerr
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> a) {
os << '(' << a.first << ',' << a.second << ')';
return os;
}
template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
for (auto x : v)
os << x << ' ';
return os;
}
void debug() { cerr << '\n'; }
template <typename H, typename... T> void debug(H a, T... b) {
cerr << a;
if (sizeof...(b))
cerr << ", ";
debug(b...);
}
int main() {
int x, y, z, k;
cin >> x >> y >> z >> k;
vector<ll> a(x), b(y), c(z);
rep(i, x) cin >> a[i];
rep(i, y) cin >> b[i];
rep(i, z) cin >> c[i];
multiset<ll> st;
rep(i, x) {
rep(j, y) { st.insert(a[i] + b[j]); }
if (st.size() > k) {
st.erase(st.begin());
}
}
multiset<ll> st2;
rep(i, z) {
for (auto x : st) {
st2.insert(x + c[i]);
if (st2.size() > k) {
st2.erase(st2.begin());
}
}
}
auto it = st2.end();
rep(i, st2.size()) {
it--;
cout << *it << "\n";
}
} | #include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
// #define cerr if(false) cerr
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> a) {
os << '(' << a.first << ',' << a.second << ')';
return os;
}
template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
for (auto x : v)
os << x << ' ';
return os;
}
void debug() { cerr << '\n'; }
template <typename H, typename... T> void debug(H a, T... b) {
cerr << a;
if (sizeof...(b))
cerr << ", ";
debug(b...);
}
int main() {
int x, y, z, k;
cin >> x >> y >> z >> k;
vector<ll> a(x), b(y), c(z);
rep(i, x) cin >> a[i];
rep(i, y) cin >> b[i];
rep(i, z) cin >> c[i];
multiset<ll> st;
rep(i, x) {
rep(j, y) {
st.insert(a[i] + b[j]);
if (st.size() > k) {
st.erase(st.begin());
}
}
}
multiset<ll> st2;
rep(i, z) {
for (auto x : st) {
st2.insert(x + c[i]);
if (st2.size() > k) {
st2.erase(st2.begin());
}
}
}
auto it = st2.end();
rep(i, st2.size()) {
it--;
cout << *it << "\n";
}
} | replace | 53 | 56 | 53 | 58 | TLE | |
p03078 | C++ | Runtime Error | #include <bits/stdc++.h>
using ll = long long;
constexpr ll inf = static_cast<ll>(1e17);
constexpr ll mod = static_cast<ll>(1e9 + 7);
int x, y, z, k;
ll a[1005], b[1005], c[1005];
ll sum1[1000005], sum2[1000005];
int num1, num2;
int main() {
std::cin >> x >> y >> z >> k;
for (int i = 0; i < x; ++i)
std::cin >> a[i];
for (int i = 0; i < y; ++i)
std::cin >> b[i];
for (int i = 0; i < z; ++i)
std::cin >> c[i];
std::sort(a, a + x, std::greater<ll>());
std::sort(b, b + y, std::greater<ll>());
std::sort(c, c + z, std::greater<ll>());
for (int i = 0; i < x; ++i)
for (int j = 0; j < y; ++j)
sum1[num1++] = a[i] + b[j];
std::sort(sum1, sum1 + num1, std::greater<ll>());
for (int i = 0; i < k; ++i)
for (int j = 0; j < z; ++j)
sum2[num2++] = sum1[i] + c[j];
std::sort(sum2, sum2 + num2, std::greater<ll>());
for (int i = 0; i < k; ++i)
std::cout << sum2[i] << std::endl;
return 0;
}
| #include <bits/stdc++.h>
using ll = long long;
constexpr ll inf = static_cast<ll>(1e17);
constexpr ll mod = static_cast<ll>(1e9 + 7);
int x, y, z, k;
ll a[1005], b[1005], c[1005];
ll sum1[10000005], sum2[10000005];
int num1, num2;
int main() {
std::cin >> x >> y >> z >> k;
for (int i = 0; i < x; ++i)
std::cin >> a[i];
for (int i = 0; i < y; ++i)
std::cin >> b[i];
for (int i = 0; i < z; ++i)
std::cin >> c[i];
std::sort(a, a + x, std::greater<ll>());
std::sort(b, b + y, std::greater<ll>());
std::sort(c, c + z, std::greater<ll>());
for (int i = 0; i < x; ++i)
for (int j = 0; j < y; ++j)
sum1[num1++] = a[i] + b[j];
std::sort(sum1, sum1 + num1, std::greater<ll>());
for (int i = 0; i < k; ++i)
for (int j = 0; j < z; ++j)
sum2[num2++] = sum1[i] + c[j];
std::sort(sum2, sum2 + num2, std::greater<ll>());
for (int i = 0; i < k; ++i)
std::cout << sum2[i] << std::endl;
return 0;
}
| replace | 8 | 9 | 8 | 9 | 0 | |
p03078 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>
#define pi acos(-1.0)
#define INF 0x3f3f3f3f
#define SIZE 200005
#define read(a, n) \
for (i = 0; i < n; i++) \
cin >> a[i];
#define pii pair<int, int>
#define pb push_back
#define forn for (i = 0; i < n; i++)
using namespace std;
typedef long long ll;
ll n, m, i, j, k, h, t, maxn, ttt, t1, t2, sig = 0;
multiset<ll> st;
ll a[1005], b[1005], c[1005];
bool cmp(ll a, ll b) { return a > b; }
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int x, y, z;
cin >> x >> y >> z >> t;
read(a, x);
read(b, y);
read(c, z);
sort(a, a + x, cmp);
sort(b, b + y, cmp);
sort(c, c + z, cmp);
priority_queue<ll, vector<ll>, greater<ll>> q;
for (i = 0; i < x; i++) {
for (j = 0; j < y; j++) {
for (k = 0; k < z; k++) {
if (q.size() < t)
q.push(a[i] + b[j] + c[k]);
else {
if (q.top() < a[i] + b[j] + c[k]) {
q.pop();
q.push(a[i] + b[j] + c[k]);
}
}
}
}
}
vector<ll> s(t + 1);
j = 0;
for (i = 0; i < t; i++) {
s[j++] = q.top();
q.pop();
}
for (i = 0; i < j; i++) {
cout << s[j - i - 1] << endl;
}
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>
#define pi acos(-1.0)
#define INF 0x3f3f3f3f
#define SIZE 200005
#define read(a, n) \
for (i = 0; i < n; i++) \
cin >> a[i];
#define pii pair<int, int>
#define pb push_back
#define forn for (i = 0; i < n; i++)
using namespace std;
typedef long long ll;
ll n, m, i, j, k, h, t, maxn, ttt, t1, t2, sig = 0;
multiset<ll> st;
ll a[1005], b[1005], c[1005];
bool cmp(ll a, ll b) { return a > b; }
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int x, y, z;
cin >> x >> y >> z >> t;
read(a, x);
read(b, y);
read(c, z);
sort(a, a + x, cmp);
sort(b, b + y, cmp);
sort(c, c + z, cmp);
priority_queue<ll, vector<ll>, greater<ll>> q;
for (i = 0; i < x; i++) {
for (j = 0; j < y; j++) {
for (k = 0; k < z; k++) {
if (q.size() < t)
q.push(a[i] + b[j] + c[k]);
else {
if (q.top() < a[i] + b[j] + c[k]) {
q.pop();
q.push(a[i] + b[j] + c[k]);
} else
break;
}
}
}
}
vector<ll> s(t + 1);
j = 0;
for (i = 0; i < t; i++) {
s[j++] = q.top();
q.pop();
}
for (i = 0; i < j; i++) {
cout << s[j - i - 1] << endl;
}
return 0;
} | replace | 50 | 51 | 50 | 52 | TLE | |
p03078 | C++ | Time Limit Exceeded | #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() {
int x, y, z, k;
cin >> x >> y >> z >> k;
vector<ll> a(x), b(y), c(z);
rep(i, x) cin >> a[i];
rep(i, y) cin >> b[i];
rep(i, z) cin >> c[i];
vector<ll> e;
rep(i, x) {
rep(j, y) { e.push_back(a[i] + b[j]); }
}
sort(e.rbegin(), e.rend());
// rep(i,x*y) cout << e[i] << endl;
vector<ll> ans;
rep(i, x * y) {
rep(j, z) { ans.push_back(e[i] + c[j]); }
}
sort(ans.rbegin(), ans.rend());
rep(i, k) cout << ans[i] << 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() {
int x, y, z, k;
cin >> x >> y >> z >> k;
vector<ll> a(x), b(y), c(z);
rep(i, x) cin >> a[i];
rep(i, y) cin >> b[i];
rep(i, z) cin >> c[i];
vector<ll> e;
rep(i, x) {
rep(j, y) { e.push_back(a[i] + b[j]); }
}
sort(e.rbegin(), e.rend());
// rep(i,x*y) cout << e[i] << endl;
vector<ll> ans;
rep(i, min(x * y, k)) {
rep(j, min(z, k)) { ans.push_back(e[i] + c[j]); }
}
sort(ans.rbegin(), ans.rend());
rep(i, k) cout << ans[i] << endl;
} | replace | 34 | 36 | 34 | 36 | TLE | |
p03078 | C++ | Runtime Error | #include <algorithm>
#include <assert.h>
#include <iostream>
using namespace std;
long long t[100000];
int ti = 0;
int main() {
long long x, y, z, k;
cin >> x >> y >> z >> k;
long long a[x], b[y], c[z];
for (long long i = 0; i < x; ++i)
cin >> a[i];
for (long long i = 0; i < y; ++i)
cin >> b[i];
for (long long i = 0; i < z; ++i)
cin >> c[i];
sort(a, a + x, greater<long long>());
sort(b, b + y, greater<long long>());
sort(c, c + z, greater<long long>());
for (long long i = 0; i < x; ++i)
for (long long j = 0; j < y; ++j)
for (long long l = 0; l < z; ++l) {
if ((i + 1) * (j + 1) * (l + 1) <= k) {
t[ti] = a[i] + b[j] + c[l];
++ti;
continue;
} else
break;
}
sort(t, t + ti, greater<long long>());
for (long long i = 0; i < k; ++i)
cout << t[i] << endl;
return 0;
} | #include <algorithm>
#include <assert.h>
#include <iostream>
using namespace std;
long long t[100000000];
int ti = 0;
int main() {
long long x, y, z, k;
cin >> x >> y >> z >> k;
long long a[x], b[y], c[z];
for (long long i = 0; i < x; ++i)
cin >> a[i];
for (long long i = 0; i < y; ++i)
cin >> b[i];
for (long long i = 0; i < z; ++i)
cin >> c[i];
sort(a, a + x, greater<long long>());
sort(b, b + y, greater<long long>());
sort(c, c + z, greater<long long>());
for (long long i = 0; i < x; ++i)
for (long long j = 0; j < y; ++j)
for (long long l = 0; l < z; ++l) {
if ((i + 1) * (j + 1) * (l + 1) <= k) {
t[ti] = a[i] + b[j] + c[l];
++ti;
continue;
} else
break;
}
sort(t, t + ti, greater<long long>());
for (long long i = 0; i < k; ++i)
cout << t[i] << endl;
return 0;
} | replace | 5 | 6 | 5 | 6 | 0 | |
p03078 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n - 1; i >= 0; i--)
#define repone(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for (auto i : mp)
#define eb emplace_back
#define F first
#define S second
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> mpll;
typedef unordered_map<char, ll> mpcl;
typedef pair<ll, ll> P;
typedef vector<ll> vll;
int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
while (true) {
#pragma clang diagnostic pop
#endif
ll x, y, z, k;
cin >> x >> y >> z >> k;
vll a(x), b(y), c(z);
ll tmp;
rep(i, x) {
scanf("%lli", &tmp);
a[i] = tmp;
}
rep(i, y) {
scanf("%lli", &tmp);
b[i] = tmp;
}
rep(i, z) {
scanf("%lli", &tmp);
c[i] = tmp;
}
priority_queue<ll, vector<ll>, greater<>> que;
rep(i, x) {
rep(j, y) {
rep(l, z) {
if (que.size() < k)
que.push(a[i] + b[j] + c[l]);
else if (a[i] + b[j] + c[l] > que.top()) {
que.pop();
que.push(a[i] + b[j] + c[l]);
}
}
}
}
vll ans(k);
rep(i, k) {
ans[k - i - 1] = que.top();
que.pop();
}
rep(i, k) printf("%lli\n", ans[i]);
#ifdef MY_DEBUG
}
#endif
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n - 1; i >= 0; i--)
#define repone(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for (auto i : mp)
#define eb emplace_back
#define F first
#define S second
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> mpll;
typedef unordered_map<char, ll> mpcl;
typedef pair<ll, ll> P;
typedef vector<ll> vll;
int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
while (true) {
#pragma clang diagnostic pop
#endif
ll x, y, z, k;
cin >> x >> y >> z >> k;
vll a(x), b(y), c(z);
ll tmp;
rep(i, x) {
scanf("%lli", &tmp);
a[i] = tmp;
}
rep(i, y) {
scanf("%lli", &tmp);
b[i] = tmp;
}
rep(i, z) {
scanf("%lli", &tmp);
c[i] = tmp;
}
priority_queue<ll, vector<ll>, greater<>> que;
sort(a.begin(), a.end(), greater<>());
sort(b.begin(), b.end(), greater<>());
sort(c.begin(), c.end(), greater<>());
rep(i, x) {
rep(j, y) {
rep(l, z) {
if (que.size() < k)
que.push(a[i] + b[j] + c[l]);
else if (a[i] + b[j] + c[l] > que.top()) {
que.pop();
que.push(a[i] + b[j] + c[l]);
}
}
}
}
vll ans(k);
rep(i, k) {
ans[k - i - 1] = que.top();
que.pop();
}
rep(i, k) printf("%lli\n", ans[i]);
#ifdef MY_DEBUG
}
#endif
return 0;
} | insert | 59 | 59 | 59 | 62 | TLE | |
p03078 | C++ | Time Limit Exceeded | #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
struct __INIT {
__INIT() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
}
} __init;
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define MOD 1000000007
#define INF (1 << 30)
#define LINF (lint)(1LL << 56)
#define endl "\n"
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define reprev(i, n) for (int(i) = (n - 1); (i) >= 0; (i)--)
#define Flag(x) (1 << (x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int, int>
#define pdouble pair<double, double>
#define plint pair<lint, lint>
#define fi first
#define se second
typedef long long lint;
int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int main(void) {
lint X, Y, Z, K;
cin >> X >> Y >> Z >> K;
lint A[X], B[Y], C[Z];
rep(i, X) cin >> A[i];
rep(i, Y) cin >> B[i];
rep(i, Z) cin >> C[i];
lint N = X * Y;
lint cake[N];
rep(i, X) rep(j, Y) cake[i * Y + j] = A[i] + B[j];
sort(cake, cake + N, greater<lint>());
lint n = min(3000LL, X * Y);
lint nw[n];
rep(i, n) nw[i] = cake[i];
sort(nw, nw + n);
rep(i, K) {
lint cnt = 0;
lint hi = 4e10, lo = 0;
while (hi - lo > 1) {
cnt = 0;
lint mid = (hi + lo) / 2;
rep(j, Z) {
auto itr = upper_bound(nw, nw + n, mid - C[j]);
cnt += n - (itr - nw);
}
(cnt > i ? lo : hi) = mid;
}
cout << hi << endl;
}
} | #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
struct __INIT {
__INIT() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
}
} __init;
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define MOD 1000000007
#define INF (1 << 30)
#define LINF (lint)(1LL << 56)
#define endl "\n"
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define reprev(i, n) for (int(i) = (n - 1); (i) >= 0; (i)--)
#define Flag(x) (1 << (x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int, int>
#define pdouble pair<double, double>
#define plint pair<lint, lint>
#define fi first
#define se second
typedef long long lint;
int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int main(void) {
lint X, Y, Z, K;
cin >> X >> Y >> Z >> K;
lint A[X], B[Y], C[Z];
rep(i, X) cin >> A[i];
rep(i, Y) cin >> B[i];
rep(i, Z) cin >> C[i];
lint N = X * Y;
lint cake[N];
rep(i, X) rep(j, Y) cake[i * Y + j] = A[i] + B[j];
sort(cake, cake + N, greater<lint>());
lint n = min(3000LL, X * Y);
lint nw[n];
rep(i, n) nw[i] = cake[i];
lint ans[n * Z];
rep(i, n) rep(j, Z) ans[i * Z + j] = nw[i] + C[j];
sort(ans, ans + n * Z, greater<lint>());
rep(i, K) cout << ans[i] << endl;
} | replace | 43 | 58 | 43 | 47 | TLE | |
p03078 | C++ | Runtime Error | #include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
ld EPS = 1e-12;
int INF = numeric_limits<int>::max() / 2;
ll LINF = numeric_limits<ll>::max() / 2;
int MOD = 1e9 + 7;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'
bool dp[1000][1000][1000];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll x, y, z, k;
cin >> x >> y >> z >> k;
vector<ll> a(x), b(y), c(z);
rep(i, x) cin >> a[i];
rep(i, y) cin >> b[i];
rep(i, z) cin >> c[i];
sort(a.begin(), a.end(), greater<ll>());
sort(b.begin(), b.end(), greater<ll>());
sort(c.begin(), c.end(), greater<ll>());
a.push_back(-1 * LINF);
b.push_back(-1 * LINF);
c.push_back(-1 * LINF);
priority_queue<pair<ll, pair<ll, pair<ll, ll>>>> q;
ll ma = a[0] + b[0] + c[0];
q.push(make_pair(ma, make_pair(0, make_pair(0, 0))));
dp[0][0][0] = true;
for (ll i = 0; i < k; i++) {
auto p = q.top();
q.pop();
ll res = p.first;
cout << res << endl;
ll ai = p.second.first;
ll bi = p.second.second.first;
ll ci = p.second.second.second;
ll nexta = a[ai + 1] + b[bi] + c[ci];
if (!dp[ai + 1][bi][ci]) {
q.push(make_pair(nexta, make_pair(ai + 1, make_pair(bi, ci))));
dp[ai + 1][bi][ci] = true;
}
ll nextb = a[ai] + b[bi + 1] + c[ci];
if (!dp[ai][bi + 1][ci]) {
q.push(make_pair(nextb, make_pair(ai, make_pair(bi + 1, ci))));
dp[ai][bi + 1][ci] = true;
}
ll nextc = a[ai] + b[bi] + c[ci + 1];
if (!dp[ai][bi][ci + 1]) {
q.push(make_pair(nextc, make_pair(ai, make_pair(bi, ci + 1))));
dp[ai][bi][ci + 1] = true;
}
}
}
| #include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
ld EPS = 1e-12;
int INF = numeric_limits<int>::max() / 2;
ll LINF = numeric_limits<ll>::max() / 2;
int MOD = 1e9 + 7;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'
bool dp[1005][1005][1005];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll x, y, z, k;
cin >> x >> y >> z >> k;
vector<ll> a(x), b(y), c(z);
rep(i, x) cin >> a[i];
rep(i, y) cin >> b[i];
rep(i, z) cin >> c[i];
sort(a.begin(), a.end(), greater<ll>());
sort(b.begin(), b.end(), greater<ll>());
sort(c.begin(), c.end(), greater<ll>());
a.push_back(-1 * LINF);
b.push_back(-1 * LINF);
c.push_back(-1 * LINF);
priority_queue<pair<ll, pair<ll, pair<ll, ll>>>> q;
ll ma = a[0] + b[0] + c[0];
q.push(make_pair(ma, make_pair(0, make_pair(0, 0))));
dp[0][0][0] = true;
for (ll i = 0; i < k; i++) {
auto p = q.top();
q.pop();
ll res = p.first;
cout << res << endl;
ll ai = p.second.first;
ll bi = p.second.second.first;
ll ci = p.second.second.second;
ll nexta = a[ai + 1] + b[bi] + c[ci];
if (!dp[ai + 1][bi][ci]) {
q.push(make_pair(nexta, make_pair(ai + 1, make_pair(bi, ci))));
dp[ai + 1][bi][ci] = true;
}
ll nextb = a[ai] + b[bi + 1] + c[ci];
if (!dp[ai][bi + 1][ci]) {
q.push(make_pair(nextb, make_pair(ai, make_pair(bi + 1, ci))));
dp[ai][bi + 1][ci] = true;
}
ll nextc = a[ai] + b[bi] + c[ci + 1];
if (!dp[ai][bi][ci + 1]) {
q.push(make_pair(nextc, make_pair(ai, make_pair(bi, ci + 1))));
dp[ai][bi][ci + 1] = true;
}
}
}
| replace | 16 | 17 | 16 | 17 | -11 | |
p03078 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
using Graph = vector<vector<int>>;
#define INF (1 << 21);
typedef long long ll;
int main() {
int X, Y, Z, K;
cin >> X >> Y >> Z >> K;
ll A[1000], B[1000], C[1000];
vector<ll> x;
vector<ll> y;
for (int i = 0; i < X; ++i)
cin >> A[i];
for (int i = 0; i < Y; ++i)
cin >> B[i];
for (int i = 0; i < Z; ++i)
cin >> C[i];
sort(A, A + X, greater<>());
sort(B, B + Y, greater<>());
sort(C, C + Z, greater<>());
for (int i = 0; i < X; ++i) {
for (int j = 0; j < Y; ++j) {
x.push_back(A[i] + B[j]);
}
}
sort(x.begin(), x.end(), greater<>());
for (int i = 0; i < X * Y; ++i) {
for (int j = 0; j < Z; ++j) {
y.push_back(x[i] + C[j]);
}
}
sort(y.begin(), y.end(), greater<>());
for (int i = 0; i < K; ++i)
cout << y[i] << endl;
}
| #include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
using Graph = vector<vector<int>>;
#define INF (1 << 21);
typedef long long ll;
int main() {
int X, Y, Z, K;
cin >> X >> Y >> Z >> K;
ll A[1000], B[1000], C[1000];
vector<ll> x;
vector<ll> y;
for (int i = 0; i < X; ++i)
cin >> A[i];
for (int i = 0; i < Y; ++i)
cin >> B[i];
for (int i = 0; i < Z; ++i)
cin >> C[i];
sort(A, A + X, greater<>());
sort(B, B + Y, greater<>());
sort(C, C + Z, greater<>());
for (int i = 0; i < X; ++i) {
for (int j = 0; j < Y; ++j) {
x.push_back(A[i] + B[j]);
}
}
sort(x.begin(), x.end(), greater<>());
for (int i = 0; i < K && i < X * Y; ++i) {
for (int j = 0; j < Z; ++j) {
y.push_back(x[i] + C[j]);
}
}
sort(y.begin(), y.end(), greater<>());
for (int i = 0; i < K; ++i)
cout << y[i] << endl;
}
| replace | 33 | 34 | 33 | 34 | TLE | |
p03078 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
vector<long long> A, B, C, AB, ABC;
int X, Y, Z, K;
int main() {
cin >> X >> Y >> Z >> K;
A.resize(X);
B.resize(Y);
C.resize(Z);
for (int i = 0; i < X; i++) {
cin >> A[i];
}
for (int i = 0; i < Y; i++) {
cin >> B[i];
}
for (int i = 0; i < Z; i++) {
cin >> C[i];
}
for (int i = 0; i < X; i++) {
for (int j = 0; j < Y; j++) {
AB.push_back(A[i] + B[j]);
}
}
sort(AB.begin(), AB.end(), greater<long long>());
for (int i = 0; i < AB.size(); i++) {
for (int j = 0; j < Z; j++) {
ABC.push_back(AB[i] + C[j]);
}
}
sort(ABC.begin(), ABC.end(), greater<long long>());
for (int i = 0; i < K; i++) {
cout << ABC[i] << endl;
}
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
vector<long long> A, B, C, AB, ABC;
int X, Y, Z, K;
int main() {
cin >> X >> Y >> Z >> K;
A.resize(X);
B.resize(Y);
C.resize(Z);
for (int i = 0; i < X; i++) {
cin >> A[i];
}
for (int i = 0; i < Y; i++) {
cin >> B[i];
}
for (int i = 0; i < Z; i++) {
cin >> C[i];
}
for (int i = 0; i < X; i++) {
for (int j = 0; j < Y; j++) {
AB.push_back(A[i] + B[j]);
}
}
sort(AB.begin(), AB.end(), greater<long long>());
int len = min((int)AB.size(), K);
for (int i = 0; i < len; i++) {
for (int j = 0; j < Z; j++) {
ABC.push_back(AB[i] + C[j]);
}
}
sort(ABC.begin(), ABC.end(), greater<long long>());
for (int i = 0; i < K; i++) {
cout << ABC[i] << endl;
}
return 0;
} | replace | 35 | 36 | 35 | 37 | 0 | |
p03078 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
long long int X, Y, Z, K;
vector<long long int> A, B, C, ansList;
cin >> X >> Y >> Z >> K;
for (int i = 0; i < X; i++) {
long long int x;
cin >> x;
A.push_back(x);
}
for (int i = 0; i < Y; i++) {
long long int x;
cin >> x;
B.push_back(x);
}
for (int i = 0; i < Z; i++) {
long long int x;
cin >> x;
C.push_back(x);
}
sort(A.begin(), A.end(), greater<long long int>());
sort(B.begin(), B.end(), greater<long long int>());
sort(C.begin(), C.end(), greater<long long int>());
long int loopNum = 0;
for (int i = 0; (i < X); i++) {
for (int j = 0; (j < Y); j++) {
for (int k = 0; (k < Z); k++) {
ansList.push_back(A[i] + B[j] + C[k]);
}
}
}
sort(ansList.begin(), ansList.end(), greater<long long int>());
for (int i = 0; i < K; i++) {
cout << ansList[i] << endl;
}
return 0;
} | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
long long int X, Y, Z, K;
vector<long long int> A, B, C, ansList;
cin >> X >> Y >> Z >> K;
for (int i = 0; i < X; i++) {
long long int x;
cin >> x;
A.push_back(x);
}
for (int i = 0; i < Y; i++) {
long long int x;
cin >> x;
B.push_back(x);
}
for (int i = 0; i < Z; i++) {
long long int x;
cin >> x;
C.push_back(x);
}
sort(A.begin(), A.end(), greater<long long int>());
sort(B.begin(), B.end(), greater<long long int>());
sort(C.begin(), C.end(), greater<long long int>());
long int loopNum = 0;
for (int i = 0; (i < X); i++) {
for (int j = 0; (j < Y); j++) {
for (int k = 0; (k < Z); k++) {
if ((i + 1) * (j + 1) * (k + 1) <= 3000)
ansList.push_back(A[i] + B[j] + C[k]);
else
break;
}
}
}
sort(ansList.begin(), ansList.end(), greater<long long int>());
for (int i = 0; i < K; i++) {
cout << ansList[i] << endl;
}
return 0;
} | replace | 37 | 38 | 37 | 41 | 0 | |
p03078 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long llong;
int main(int argc, const char *argv[]) {
int X, Y, Z, K;
cin >> X >> Y >> Z >> K;
vector<llong> A(X);
vector<llong> B(Y);
vector<llong> C(Z);
for (int i = 0; i < X; i++) {
cin >> A[i];
}
for (int i = 0; i < Y; i++) {
cin >> B[i];
}
for (int i = 0; i < Z; i++) {
cin >> C[i];
}
vector<llong> AB;
for (int i = 0; i < X; i++) {
for (int j = 0; j < Y; j++) {
AB.push_back(A[i] + B[j]);
}
}
sort(AB.begin(), AB.end(), greater<llong>());
vector<llong> ABC;
for (int i = 0; i < (int)AB.size(); i++) {
for (int j = 0; j < Z; j++) {
ABC.push_back(AB[i] + C[j]);
}
}
sort(ABC.begin(), ABC.end(), greater<llong>());
for (int i = 0; i < K; i++) {
cout << ABC[i] << endl;
}
return 0;
} | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long llong;
int main(int argc, const char *argv[]) {
int X, Y, Z, K;
cin >> X >> Y >> Z >> K;
vector<llong> A(X);
vector<llong> B(Y);
vector<llong> C(Z);
for (int i = 0; i < X; i++) {
cin >> A[i];
}
for (int i = 0; i < Y; i++) {
cin >> B[i];
}
for (int i = 0; i < Z; i++) {
cin >> C[i];
}
vector<llong> AB;
for (int i = 0; i < X; i++) {
for (int j = 0; j < Y; j++) {
AB.push_back(A[i] + B[j]);
}
}
sort(AB.begin(), AB.end(), greater<llong>());
vector<llong> ABC;
for (int i = 0; i < min(K, (int)AB.size()); i++) {
for (int j = 0; j < Z; j++) {
ABC.push_back(AB[i] + C[j]);
}
}
sort(ABC.begin(), ABC.end(), greater<llong>());
for (int i = 0; i < K; i++) {
cout << ABC[i] << endl;
}
return 0;
} | replace | 35 | 36 | 35 | 36 | TLE | |
p03078 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define debug(a) cout << #a << ": " << a << endl;
int main() {
int X, Y, Z, K;
cin >> X >> Y >> Z >> K;
vector<ll> A(X);
rep(i, X) { cin >> A[i]; }
sort(A.begin(), A.end(), greater<ll>());
vector<ll> B(X);
rep(i, Y) { cin >> B[i]; }
sort(B.begin(), B.end(), greater<ll>());
vector<ll> C(X);
rep(i, Z) { cin >> C[i]; }
sort(C.begin(), C.end(), greater<ll>());
vector<ll> AB;
rep(x, X) rep(y, Y) { AB.push_back(A[x] + B[y]); }
sort(AB.begin(), AB.end(), greater<ll>());
vector<ll> ABC;
rep(xy, (int)AB.size()) rep(z, Z) { ABC.push_back(AB[xy] + C[z]); }
sort(ABC.begin(), ABC.end(), greater<ll>());
for (int i = 0; i < (int)ABC.size() && i < K; i++) {
cout << ABC[i] << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define debug(a) cout << #a << ": " << a << endl;
int main() {
int X, Y, Z, K;
cin >> X >> Y >> Z >> K;
vector<ll> A(X);
rep(i, X) { cin >> A[i]; }
sort(A.begin(), A.end(), greater<ll>());
vector<ll> B(X);
rep(i, Y) { cin >> B[i]; }
sort(B.begin(), B.end(), greater<ll>());
vector<ll> C(X);
rep(i, Z) { cin >> C[i]; }
sort(C.begin(), C.end(), greater<ll>());
vector<ll> AB;
rep(x, X) rep(y, Y) { AB.push_back(A[x] + B[y]); }
sort(AB.begin(), AB.end(), greater<ll>());
vector<ll> ABC;
rep(xy, min(K, (int)AB.size())) rep(z, Z) { ABC.push_back(AB[xy] + C[z]); }
sort(ABC.begin(), ABC.end(), greater<ll>());
for (int i = 0; i < (int)ABC.size() && i < K; i++) {
cout << ABC[i] << endl;
}
}
| replace | 26 | 27 | 26 | 27 | TLE | |
p03078 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int x, y, z, K;
cin >> x >> y >> z >> K;
vector<long long> as(x), bs(y), cs(z);
for (int i = 0; i < x; i++)
cin >> as[i];
for (int i = 0; i < y; i++)
cin >> bs[i];
for (int i = 0; i < z; i++)
cin >> cs[i];
vector<long long> yz;
yz.reserve(y * z);
for (int i = 0; i < y; i++) {
for (int j = 0; j < z; j++) {
yz.push_back(bs[i] + cs[j]);
}
}
sort(yz.begin(), yz.end());
auto num_gex = [&](long long k) {
long long ret = 0;
for (int i = 0; i < x; i++) {
long long rem = k - as[i];
ret += yz.size() - (lower_bound(yz.begin(), yz.end(), rem) - yz.begin());
}
return ret;
};
long long l = 0, r = 1e18;
while (l < r - 1) {
long long m = (l + r) / 2;
if (num_gex(m) >= K) {
l = m;
} else {
r = m;
}
}
long long nax = l;
vector<long long> ans;
ans.reserve(3000);
cerr << "nax: " << nax << endl;
for (int i = 0; i < x; i++) {
long long rem = nax - 1 - as[i];
int lt = lower_bound(yz.begin(), yz.end(), rem) - yz.begin();
for (int j = lt; j < yz.size(); j++) {
ans.push_back(as[i] + yz[j]);
}
}
assert(ans.size() <= K);
while (ans.size() < K) {
ans.push_back(nax);
}
sort(ans.rbegin(), ans.rend());
for (long long a : ans) {
cout << a << '\n';
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int x, y, z, K;
cin >> x >> y >> z >> K;
vector<long long> as(x), bs(y), cs(z);
for (int i = 0; i < x; i++)
cin >> as[i];
for (int i = 0; i < y; i++)
cin >> bs[i];
for (int i = 0; i < z; i++)
cin >> cs[i];
vector<long long> yz;
yz.reserve(y * z);
for (int i = 0; i < y; i++) {
for (int j = 0; j < z; j++) {
yz.push_back(bs[i] + cs[j]);
}
}
sort(yz.begin(), yz.end());
auto num_gex = [&](long long k) {
long long ret = 0;
for (int i = 0; i < x; i++) {
long long rem = k - as[i];
ret += yz.size() - (lower_bound(yz.begin(), yz.end(), rem) - yz.begin());
}
return ret;
};
long long l = 0, r = 1e18;
while (l < r - 1) {
long long m = (l + r) / 2;
if (num_gex(m) >= K) {
l = m;
} else {
r = m;
}
}
long long nax = l;
vector<long long> ans;
ans.reserve(3000);
cerr << "nax: " << nax << endl;
for (int i = 0; i < x; i++) {
long long rem = nax + 1 - as[i];
int lt = lower_bound(yz.begin(), yz.end(), rem) - yz.begin();
for (int j = lt; j < yz.size(); j++) {
ans.push_back(as[i] + yz[j]);
}
}
assert(ans.size() <= K);
while (ans.size() < K) {
ans.push_back(nax);
}
sort(ans.rbegin(), ans.rend());
for (long long a : ans) {
cout << a << '\n';
}
} | replace | 45 | 46 | 45 | 46 | 0 | nax: 8
|
p03078 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <vector>
int main(int, char **) {
int x, y, z, K;
std::cin >> x >> y >> z >> K;
std::vector<long long> as(x), bs(y), cs(z);
for (int i{}; i < x; ++i) {
std::cin >> as[i];
}
for (int i{}; i < y; ++i) {
std::cin >> bs[i];
}
for (int i{}; i < z; ++i) {
std::cin >> cs[i];
}
std::sort(begin(as), end(as), std::greater<long long>());
std::sort(begin(bs), end(bs), std::greater<long long>());
std::sort(begin(cs), end(cs), std::greater<long long>());
std::vector<long long> ans;
for (int i{}; i < x; ++i) {
for (int j{}; j < y; ++j) {
for (int k{}; k < z; ++k) {
if (i + j + k <= K) {
ans.push_back(as[i] + bs[j] + cs[k]);
} else {
break;
}
}
}
}
std::sort(begin(ans), end(ans), std::greater<long long>());
for (int i{}; i < K; ++i) {
std::cout << ans[i] << std::endl;
}
return 0;
}
| #include <algorithm>
#include <iostream>
#include <vector>
int main(int, char **) {
int x, y, z, K;
std::cin >> x >> y >> z >> K;
std::vector<long long> as(x), bs(y), cs(z);
for (int i{}; i < x; ++i) {
std::cin >> as[i];
}
for (int i{}; i < y; ++i) {
std::cin >> bs[i];
}
for (int i{}; i < z; ++i) {
std::cin >> cs[i];
}
std::sort(begin(as), end(as), std::greater<long long>());
std::sort(begin(bs), end(bs), std::greater<long long>());
std::sort(begin(cs), end(cs), std::greater<long long>());
std::vector<long long> ans;
for (int i{}; i < x; ++i) {
for (int j{}; j < y; ++j) {
for (int k{}; k < z; ++k) {
if ((i + 1) * (j + 1) * (k + 1) <= K) {
ans.push_back(as[i] + bs[j] + cs[k]);
} else {
break;
}
}
}
}
std::sort(begin(ans), end(ans), std::greater<long long>());
for (int i{}; i < K; ++i) {
std::cout << ans[i] << std::endl;
}
return 0;
}
| replace | 27 | 28 | 27 | 28 | 0 | |
p03078 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORR(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define CHMIN(a, b) (a) = min((a), (b))
#define CHMAX(a, b) (a) = max((a), (b))
#define DEBUG(x) cout << #x << ": " << (x) << endl
int main() {
int X, Y, Z, K;
cin >> X >> Y >> Z >> K;
vl A(X);
vl B(Y);
vl C(Z);
FOR(i, 0, X) { cin >> A[i]; }
FOR(i, 0, Y) { cin >> B[i]; }
FOR(i, 0, Z) { cin >> C[i]; }
sort(A.begin(), A.end());
reverse(A.begin(), A.end()); // 降順ソート
sort(B.begin(), B.end());
reverse(B.begin(), B.end()); // 降順ソート
sort(C.begin(), C.end());
reverse(C.begin(), C.end()); // 降順ソート
int a, b, c;
ll rep = A[0] + B[0] + C[0];
priority_queue<ll> PQ;
FOR(i, 0, min(X, K)) {
FOR(j, 0, min(Y, K)) {
FOR(k, 0, min(Z, K)) { PQ.push(A[i] + B[j] + C[k]); }
}
}
FOR(i, 0, K) {
cout << PQ.top() << endl;
PQ.pop();
}
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORR(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define CHMIN(a, b) (a) = min((a), (b))
#define CHMAX(a, b) (a) = max((a), (b))
#define DEBUG(x) cout << #x << ": " << (x) << endl
int main() {
int X, Y, Z, K;
cin >> X >> Y >> Z >> K;
vl A(X);
vl B(Y);
vl C(Z);
FOR(i, 0, X) { cin >> A[i]; }
FOR(i, 0, Y) { cin >> B[i]; }
FOR(i, 0, Z) { cin >> C[i]; }
sort(A.begin(), A.end());
reverse(A.begin(), A.end()); // 降順ソート
sort(B.begin(), B.end());
reverse(B.begin(), B.end()); // 降順ソート
sort(C.begin(), C.end());
reverse(C.begin(), C.end()); // 降順ソート
int a, b, c;
ll rep = A[0] + B[0] + C[0];
priority_queue<ll> PQ;
FOR(i, 0, min(X, K)) {
FOR(j, 0, min(Z, Y)) {
FOR(k, 0, min(Z, K)) {
if ((i + 1) * (j * 1) * (k * 1) <= K)
PQ.push(A[i] + B[j] + C[k]);
else
break;
}
}
}
FOR(i, 0, K) {
cout << PQ.top() << endl;
PQ.pop();
}
} | replace | 43 | 45 | 43 | 50 | TLE | |
p03078 | C++ | Runtime Error | #include <cmath>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
using namespace std;
typedef long long ll;
int main(void) {
int x, y, z, K;
cin >> x >> y >> z >> K;
vector<ll> a(x);
vector<ll> b(y);
vector<ll> c(z);
rep(i, x) { cin >> a[i]; }
rep(j, y) { cin >> b[j]; }
rep(l, z) { cin >> c[l]; }
sort(a.begin(), a.end(), greater<ll>());
sort(b.begin(), b.end(), greater<ll>());
sort(c.begin(), c.end(), greater<ll>());
priority_queue<ll> q;
rep(i, x) {
rep(j, y) {
int tmp_z = min(z, K / (i + 1) / (j + 1) - 1);
rep(l, tmp_z) { q.push(a[i] + b[j] + c[l]); }
}
}
rep(i, K) {
cout << q.top() << endl;
q.pop();
}
return 0;
} | #include <cmath>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
using namespace std;
typedef long long ll;
int main(void) {
int x, y, z, K;
cin >> x >> y >> z >> K;
vector<ll> a(x);
vector<ll> b(y);
vector<ll> c(z);
rep(i, x) { cin >> a[i]; }
rep(j, y) { cin >> b[j]; }
rep(l, z) { cin >> c[l]; }
sort(a.begin(), a.end(), greater<ll>());
sort(b.begin(), b.end(), greater<ll>());
sort(c.begin(), c.end(), greater<ll>());
priority_queue<ll> q;
rep(i, x) {
rep(j, y) {
int tmp_z = min(z, K / (i + 1) / (j + 1));
rep(l, tmp_z) { q.push(a[i] + b[j] + c[l]); }
}
}
rep(i, K) {
cout << q.top() << endl;
q.pop();
}
return 0;
} | replace | 34 | 35 | 34 | 35 | 0 | |
p03078 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;
const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int dx8[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
const int dy8[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
#define p_queue(i) priority_queue<i>
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>>
#define umap(i, j) unordered_map<i, j>
#define P(p) cout << (p) << endl
#define PS(p) cout << (p) << " "
#define IN cin >>
#define rep(i, m, n) for (int i = (m); i < (int)(n); i++)
#define rrep(i, m, n) for (int i = (m - 1); i >= (int)(n); i--)
#define inrep(n, a) \
for (int i = 0; i < (int)(n); i++) \
cin >> a[i];
#define mod(i) ((i) % (ll)(1e9 + 7))
#define divm(a, b) (mod(a * modpow((ll)b, (ll)(1e9 + 5))))
#define rsort(a, b, c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v, c) sort(v.begin(), v.end(), greater<c>())
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a, n, k) (lower_bound(a, a + n, k) - a)
#define vlb(a, k) (lower_bound(a.begin(), a.end(), k) - a.begin())
#define ub(a, n, k) (upper_bound(a, a + n, k) - a)
#define vub(a, k) (upper_bound(a.begin(), a.end(), k) - a.begin())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl
#define no cout << "no" << endl
#define ret return
ll modpow(ll i, ll j) {
ll tmp = 1;
while (j) {
if (j % 2)
tmp = mod(tmp * i);
i = mod(i * i);
j /= 2;
}
return tmp;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
vector<string> split(const string &str, char sep) {
vector<string> v;
stringstream ss(str);
string buffer;
while (getline(ss, buffer, sep)) {
v.push_back(buffer);
}
return v;
}
// ll ncr[100][100];
// ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1;
// if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] =
// nCr(n-1,r) + nCr(n-1,r-1);}
// ll npr[100][100]={};
// ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] =
// 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}
// ll nHr(int n,int r){ret nCr(n+r-1,r);}
///////////////////////////////////////////////////////////////////////////
ll x, y, z, k;
int main() {
cin >> x >> y >> z >> k;
ll a[1005], b[1005], c[1005];
inrep(x, a);
inrep(y, b);
inrep(z, c);
vector<ll> v;
rep(i, 0, x) {
rep(j, 0, y) { v.pb(a[i] + b[j]); }
}
rvsort(v, ll);
vector<ll> v2;
rep(i, 0, sz(v)) {
rep(j, 0, z) { v2.pb(v[i] + c[j]); }
}
rvsort(v2, ll);
rep(i, 0, k) { P(v2[i]); }
return 0;
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;
const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int dx8[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
const int dy8[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
#define p_queue(i) priority_queue<i>
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>>
#define umap(i, j) unordered_map<i, j>
#define P(p) cout << (p) << endl
#define PS(p) cout << (p) << " "
#define IN cin >>
#define rep(i, m, n) for (int i = (m); i < (int)(n); i++)
#define rrep(i, m, n) for (int i = (m - 1); i >= (int)(n); i--)
#define inrep(n, a) \
for (int i = 0; i < (int)(n); i++) \
cin >> a[i];
#define mod(i) ((i) % (ll)(1e9 + 7))
#define divm(a, b) (mod(a * modpow((ll)b, (ll)(1e9 + 5))))
#define rsort(a, b, c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v, c) sort(v.begin(), v.end(), greater<c>())
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a, n, k) (lower_bound(a, a + n, k) - a)
#define vlb(a, k) (lower_bound(a.begin(), a.end(), k) - a.begin())
#define ub(a, n, k) (upper_bound(a, a + n, k) - a)
#define vub(a, k) (upper_bound(a.begin(), a.end(), k) - a.begin())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl
#define no cout << "no" << endl
#define ret return
ll modpow(ll i, ll j) {
ll tmp = 1;
while (j) {
if (j % 2)
tmp = mod(tmp * i);
i = mod(i * i);
j /= 2;
}
return tmp;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
vector<string> split(const string &str, char sep) {
vector<string> v;
stringstream ss(str);
string buffer;
while (getline(ss, buffer, sep)) {
v.push_back(buffer);
}
return v;
}
// ll ncr[100][100];
// ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1;
// if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] =
// nCr(n-1,r) + nCr(n-1,r-1);}
// ll npr[100][100]={};
// ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] =
// 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}
// ll nHr(int n,int r){ret nCr(n+r-1,r);}
///////////////////////////////////////////////////////////////////////////
ll x, y, z, k;
int main() {
cin >> x >> y >> z >> k;
ll a[1005], b[1005], c[1005];
inrep(x, a);
inrep(y, b);
inrep(z, c);
vector<ll> v;
rep(i, 0, x) {
rep(j, 0, y) { v.pb(a[i] + b[j]); }
}
rvsort(v, ll);
vector<ll> v2;
rep(i, 0, min(k, x * y)) {
rep(j, 0, z) { v2.pb(v[i] + c[j]); }
}
rvsort(v2, ll);
rep(i, 0, k) { P(v2[i]); }
return 0;
} | replace | 117 | 118 | 117 | 118 | TLE | |
p03078 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll unsigned long long
using namespace std;
int cmp(ll a, ll b) { return a > b; }
ll bc[1000001], ans[1000001];
int main() {
int x, y, z, k, n = 0;
ll a[1001], b[1001], c[1001];
cin >> x >> y >> z >> k;
for (int i = 0; i < x; i++)
scanf("%lld", &a[i]);
for (int i = 0; i < y; i++)
scanf("%lld", &b[i]);
for (int i = 0; i < z; i++)
scanf("%lld", &c[i]);
sort(a, a + x, cmp);
sort(b, b + y, cmp);
sort(c, c + z, cmp);
for (int i = 0; i < y; i++) {
for (int j = 0; j < z; j++) {
bc[n] = b[i] + c[j];
n++;
}
}
sort(bc, bc + (y * z), cmp);
n = 0;
for (int i = 0; i < x; i++) {
for (int j = 0; j < k; j++) {
ans[n] = a[i] + bc[j];
n++;
}
}
sort(ans, ans + (x * k), cmp);
for (int i = 0; i < k; i++)
cout << ans[i] << endl;
return 0;
}
| #include <bits/stdc++.h>
#define ll unsigned long long
using namespace std;
int cmp(ll a, ll b) { return a > b; }
ll bc[1000001], ans[3000001];
int main() {
int x, y, z, k, n = 0;
ll a[1001], b[1001], c[1001];
cin >> x >> y >> z >> k;
for (int i = 0; i < x; i++)
scanf("%lld", &a[i]);
for (int i = 0; i < y; i++)
scanf("%lld", &b[i]);
for (int i = 0; i < z; i++)
scanf("%lld", &c[i]);
sort(a, a + x, cmp);
sort(b, b + y, cmp);
sort(c, c + z, cmp);
for (int i = 0; i < y; i++) {
for (int j = 0; j < z; j++) {
bc[n] = b[i] + c[j];
n++;
}
}
sort(bc, bc + (y * z), cmp);
n = 0;
for (int i = 0; i < x; i++) {
for (int j = 0; j < k; j++) {
ans[n] = a[i] + bc[j];
n++;
}
}
sort(ans, ans + (x * k), cmp);
for (int i = 0; i < k; i++)
cout << ans[i] << endl;
return 0;
}
| replace | 4 | 5 | 4 | 5 | 0 | |
p03078 | C++ | Time Limit Exceeded | #define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
using namespace std;
using Graph = vector<vector<Int>>;
const double pi = M_PI;
const Int MOD = 1000000007;
int main() {
int x, y, z, K;
cin >> x >> y >> z >> K;
vector<Int> a(x), b(y), c(z);
for (int i = 0; i < x; i++) {
cin >> a[i];
}
for (int i = 0; i < y; i++) {
cin >> b[i];
}
for (int i = 0; i < z; i++) {
cin >> c[i];
}
vector<Int> d;
for (int i = 0; i < x; i++) {
for (int k = 0; k < y; k++) {
d.push_back(a[i] + b[k]);
}
}
sort(d.begin(), d.end(), greater<>());
sort(c.begin(), c.end(), greater<>());
vector<Int> ans;
for (int i = 0; i < x * y; i++) {
for (int k = 0; k < z; k++) {
ans.push_back(d[i] + c[k]);
}
}
sort(ans.begin(), ans.end(), greater<>());
for (int i = 0; i < K; i++) {
cout << ans[i] << endl;
}
return 0;
}
| #define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
using namespace std;
using Graph = vector<vector<Int>>;
const double pi = M_PI;
const Int MOD = 1000000007;
int main() {
int x, y, z, K;
cin >> x >> y >> z >> K;
vector<Int> a(x), b(y), c(z);
for (int i = 0; i < x; i++) {
cin >> a[i];
}
for (int i = 0; i < y; i++) {
cin >> b[i];
}
for (int i = 0; i < z; i++) {
cin >> c[i];
}
vector<Int> d;
for (int i = 0; i < x; i++) {
for (int k = 0; k < y; k++) {
d.push_back(a[i] + b[k]);
}
}
sort(d.begin(), d.end(), greater<>());
sort(c.begin(), c.end(), greater<>());
vector<Int> ans;
int ro = min(3000, x * y);
for (int i = 0; i < ro; i++) {
for (int k = 0; k < z; k++) {
ans.push_back(d[i] + c[k]);
}
}
sort(ans.begin(), ans.end(), greater<>());
for (int i = 0; i < K; i++) {
cout << ans[i] << endl;
}
return 0;
}
| replace | 36 | 37 | 36 | 38 | TLE | |
p03078 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <ctype.h>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <time.h>
#include <tuple>
#include <vector>
using namespace std;
#define int long long
#define rep(i, s, n) for (int i = s; i < n; i++)
#define repe(i, s, n) for (int i = s; i <= n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a, b) a = min((a), (b))
#define chmax(a, b) a = max((a), (b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i, j) ((i < 0 && j < 0) || (i > 0 && j > 0)) ? true : false
typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
int ca[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
signed main() {
ll x, y, z, n, k, cnt = 0, pp, h, l;
string s, s1, s2;
vector<ll> listx, listy, listz;
vector<ll> list1, list2;
int sum = 0, maxn = -9999, minn = 199999999999999;
cin >> x >> y >> z >> k;
for (ll i = 0; i < x; i++) {
ll num;
cin >> num;
listx.push_back(num);
}
for (int i = 0; i < y; i++) {
int num;
cin >> num;
listy.push_back(num);
}
for (int i = 0; i < z; i++) {
int num;
cin >> num;
listz.push_back(num);
}
/*sort(listx.begin(), listx.end(), greater<int>());
sort(listy.begin(), listy.end(), greater<int>());
sort(listz.begin(), listz.end(), greater<int>());*/
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
list1.push_back(listx[i] + listy[j]);
}
}
sort(list1.begin(), list1.end(), greater<int>());
for (int i = 0; i < list1.size(); i++) {
for (int j = 0; j < z; j++) {
list2.push_back(list1[i] + listz[j]);
}
}
sort(list2.begin(), list2.end(), greater<int>());
for (int i = 0; i < k; i++) {
cout << list2[i] << endl;
}
getchar();
getchar();
return 0;
} | #include <algorithm>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <ctype.h>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <time.h>
#include <tuple>
#include <vector>
using namespace std;
#define int long long
#define rep(i, s, n) for (int i = s; i < n; i++)
#define repe(i, s, n) for (int i = s; i <= n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a, b) a = min((a), (b))
#define chmax(a, b) a = max((a), (b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i, j) ((i < 0 && j < 0) || (i > 0 && j > 0)) ? true : false
typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
int ca[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
signed main() {
ll x, y, z, n, k, cnt = 0, pp, h, l;
string s, s1, s2;
vector<ll> listx, listy, listz;
vector<ll> list1, list2;
int sum = 0, maxn = -9999, minn = 199999999999999;
cin >> x >> y >> z >> k;
for (ll i = 0; i < x; i++) {
ll num;
cin >> num;
listx.push_back(num);
}
for (int i = 0; i < y; i++) {
int num;
cin >> num;
listy.push_back(num);
}
for (int i = 0; i < z; i++) {
int num;
cin >> num;
listz.push_back(num);
}
/*sort(listx.begin(), listx.end(), greater<int>());
sort(listy.begin(), listy.end(), greater<int>());
sort(listz.begin(), listz.end(), greater<int>());*/
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
list1.push_back(listx[i] + listy[j]);
}
}
sort(list1.begin(), list1.end(), greater<int>());
for (int i = 0; i < list1.size() && i < k; i++) {
for (int j = 0; j < z; j++) {
list2.push_back(list1[i] + listz[j]);
}
}
sort(list2.begin(), list2.end(), greater<int>());
for (int i = 0; i < k; i++) {
cout << list2[i] << endl;
}
getchar();
getchar();
return 0;
} | replace | 86 | 87 | 86 | 87 | TLE | |
p03078 | C++ | Time Limit Exceeded | #include <algorithm> // sort
#include <cstring>
#include <fstream>
#include <iostream>
#include <map> // sort
#include <vector>
#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;
using namespace std;
// abc123d cake
// 1,2,3のケーキをそれぞれ降順ソート
// 3つを比較して最も大きいものの次を参照
// Kのmaxが3000だから
// X,Y,Zの使わない下半分くらいは取り除いていい?
// abc > K
int main() {
int x, y, z, k;
cin >> x >> y >> z >> k;
vector<ll> a(x);
vector<ll> b(y);
vector<ll> c(z);
REP(i, x) { cin >> a[i]; }
REP(i, y) { cin >> b[i]; }
REP(i, z) { cin >> c[i]; }
sort(a.begin(), a.end(), greater<ll>());
sort(b.begin(), b.end(), greater<ll>());
sort(c.begin(), c.end(), greater<ll>());
// a + b の結果
vector<ll> vec;
REP(i, x) {
REP(j, y) { vec.push_back(a[i] + b[j]); }
}
vector<ll> res;
sort(vec.begin(), vec.end(), greater<ll>());
REP(i, vec.size()) {
REP(j, z) { res.push_back(vec[i] + c[j]); }
}
sort(res.begin(), res.end(), greater<ll>());
for (int i = 0; i < k; ++i) {
cout << res[i] << endl;
}
return 0;
}
| #include <algorithm> // sort
#include <cstring>
#include <fstream>
#include <iostream>
#include <map> // sort
#include <vector>
#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;
using namespace std;
// abc123d cake
// 1,2,3のケーキをそれぞれ降順ソート
// 3つを比較して最も大きいものの次を参照
// Kのmaxが3000だから
// X,Y,Zの使わない下半分くらいは取り除いていい?
// abc > K
int main() {
int x, y, z, k;
cin >> x >> y >> z >> k;
vector<ll> a(x);
vector<ll> b(y);
vector<ll> c(z);
REP(i, x) { cin >> a[i]; }
REP(i, y) { cin >> b[i]; }
REP(i, z) { cin >> c[i]; }
sort(a.begin(), a.end(), greater<ll>());
sort(b.begin(), b.end(), greater<ll>());
sort(c.begin(), c.end(), greater<ll>());
// a + b の結果
vector<ll> vec;
REP(i, x) {
REP(j, y) { vec.push_back(a[i] + b[j]); }
}
vector<ll> res;
sort(vec.begin(), vec.end(), greater<ll>());
int tmp = min(k + 1, (int)vec.size());
REP(i, tmp) {
REP(j, z) { res.push_back(vec[i] + c[j]); }
}
sort(res.begin(), res.end(), greater<ll>());
for (int i = 0; i < k; ++i) {
cout << res[i] << endl;
}
return 0;
}
| replace | 44 | 45 | 44 | 47 | TLE | |
p03078 | C++ | Runtime Error | #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define endl '\n'
#define ll long long
#define mod 1000000007
#define NCONS 1000000000
// #define NCONS 100001
// #define NCONS 1001
// #define NCONS 101
#define MCONS 2001
#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0
using namespace std;
int main(void) {
cin.tie(NULL);
ios_base::sync_with_stdio(false);
int x, y, z, k;
cin >> x >> y >> z >> k;
vector<ll> a(x, 0), b(y, 0), c(z, 0);
for (int i = 0; i < x; i++)
cin >> a[i];
for (int i = 0; i < y; i++)
cin >> b[i];
for (int i = 0; i < z; i++)
cin >> c[i];
vector<ll> ab, ret;
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
ab.push_back(a[i] + b[j]);
}
}
sort(ab.begin(), ab.end(), greater<ll>());
while (ab.size() <= k) {
ab.pop_back();
}
for (int i = 0; i < ab.size(); i++) {
for (int j = 0; j < z; j++) {
ret.push_back(ab[i] + c[j]);
}
}
sort(ret.begin(), ret.end());
while (k--) {
cout << ret.back() << endl;
ret.pop_back();
}
return 0;
}
| #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define endl '\n'
#define ll long long
#define mod 1000000007
#define NCONS 1000000000
// #define NCONS 100001
// #define NCONS 1001
// #define NCONS 101
#define MCONS 2001
#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0
using namespace std;
int main(void) {
cin.tie(NULL);
ios_base::sync_with_stdio(false);
int x, y, z, k;
cin >> x >> y >> z >> k;
vector<ll> a(x, 0), b(y, 0), c(z, 0);
for (int i = 0; i < x; i++)
cin >> a[i];
for (int i = 0; i < y; i++)
cin >> b[i];
for (int i = 0; i < z; i++)
cin >> c[i];
vector<ll> ab, ret;
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
ab.push_back(a[i] + b[j]);
}
}
sort(ab.begin(), ab.end(), greater<ll>());
while (ab.size() > k) {
ab.pop_back();
}
for (int i = 0; i < ab.size(); i++) {
for (int j = 0; j < z; j++) {
ret.push_back(ab[i] + c[j]);
}
}
sort(ret.begin(), ret.end());
while (k--) {
cout << ret.back() << endl;
ret.pop_back();
}
return 0;
}
| replace | 49 | 50 | 49 | 50 | -11 | |
p03078 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using ll = long long;
#define int ll
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define erep(e, v) for (auto &&e : v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9 : (int)1e18)
#define EPS 0.0000000001
using namespace std;
template <class T, class S> void cmin(T &a, const S &b) {
if (a > b)
a = b;
}
template <class T, class S> void cmax(T &a, const S &b) {
if (a < b)
a = b;
}
template <typename Head, typename Value>
auto vectors(const Head &head, const Value &v) {
return vector<Value>(head, v);
}
template <typename Head, typename... Tail> auto vectors(Head x, Tail... tail) {
auto inner = vectors(tail...);
return vector<decltype(inner)>(x, inner);
}
template <class T> void join(T &a) {
int t = 0;
for (auto itr : a) {
if (t++)
cout << " ";
cout << itr;
}
cout << endl;
}
using ld = long double;
using pii = pair<int, int>;
using piii = pair<int, pii>;
int W, H;
int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
bool valid(int x, int y) { return (0 <= x && x < W) && (0 <= y && y < H); }
signed main() {
// std::ios_base::sync_with_stdio(false);
// cin.tie(NULL);
int x, y, z, k;
cin >> x >> y >> z >> k;
vector<int> vx(x), vy(y), vz(z);
for (auto &e : vx)
cin >> e;
for (auto &e : vy)
cin >> e;
for (auto &e : vz)
cin >> e;
sort(all(vx), greater<>());
sort(all(vy), greater<>());
sort(all(vz), greater<>());
// vector<int>nx,ny,nz;
// nx.push_back(vx.front());
// ny.push_back(vy.front());
// nz.push_back(vz.front());
// priority_queue<int,vector<int>>xque,yque,zque;
// rep(i,x)if(i)xque.push(vx[i]);
// rep(i,y)if(i)yque.push(vy[i]);
// rep(i,z)if(i)zque.push(vz[i]);
// xque.push(-10000000000);
// yque.push(-10000000000);
// zque.push(-10000000000);
//
// while((int)nx.size() * (int)ny.size() * (int)nz.size() < k){
// int xdif = nx.back() - xque.top();
// int ydif = ny.back() - yque.top();
// int zdif = nz.back() - zque.top();
// if(xdif <= ydif and xdif <= zdif and !xque.empty()){
// nx.push_back(xque.top());
// xque.pop();
// } else if(ydif <= xdif and ydif <= zdif and !yque.empty()){
// ny.push_back(yque.top());
// yque.pop();
// } else {
// nz.push_back(zque.top());
// zque.pop();
// }
// }
vector<int> ans;
// rep(i,nx.size())rep(j,ny.size())rep(k,nz.size()){
// ans.push_back(nx[i] + ny[j] + nz[k]);
// }
vector<int> sum;
rep(i, vy.size()) rep(j, vz.size()) sum.push_back(vy[i] + vz[j]);
sort(all(sum));
rep(i, vx.size()) rep(j, (int)sum.size()) ans.push_back(vx[i] + sum[j]);
sort(all(ans), greater<>());
rep(i, k) cout << ans[i] << endl;
}
| #include <bits/stdc++.h>
using ll = long long;
#define int ll
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define erep(e, v) for (auto &&e : v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9 : (int)1e18)
#define EPS 0.0000000001
using namespace std;
template <class T, class S> void cmin(T &a, const S &b) {
if (a > b)
a = b;
}
template <class T, class S> void cmax(T &a, const S &b) {
if (a < b)
a = b;
}
template <typename Head, typename Value>
auto vectors(const Head &head, const Value &v) {
return vector<Value>(head, v);
}
template <typename Head, typename... Tail> auto vectors(Head x, Tail... tail) {
auto inner = vectors(tail...);
return vector<decltype(inner)>(x, inner);
}
template <class T> void join(T &a) {
int t = 0;
for (auto itr : a) {
if (t++)
cout << " ";
cout << itr;
}
cout << endl;
}
using ld = long double;
using pii = pair<int, int>;
using piii = pair<int, pii>;
int W, H;
int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
bool valid(int x, int y) { return (0 <= x && x < W) && (0 <= y && y < H); }
signed main() {
// std::ios_base::sync_with_stdio(false);
// cin.tie(NULL);
int x, y, z, k;
cin >> x >> y >> z >> k;
vector<int> vx(x), vy(y), vz(z);
for (auto &e : vx)
cin >> e;
for (auto &e : vy)
cin >> e;
for (auto &e : vz)
cin >> e;
sort(all(vx), greater<>());
sort(all(vy), greater<>());
sort(all(vz), greater<>());
// vector<int>nx,ny,nz;
// nx.push_back(vx.front());
// ny.push_back(vy.front());
// nz.push_back(vz.front());
// priority_queue<int,vector<int>>xque,yque,zque;
// rep(i,x)if(i)xque.push(vx[i]);
// rep(i,y)if(i)yque.push(vy[i]);
// rep(i,z)if(i)zque.push(vz[i]);
// xque.push(-10000000000);
// yque.push(-10000000000);
// zque.push(-10000000000);
//
// while((int)nx.size() * (int)ny.size() * (int)nz.size() < k){
// int xdif = nx.back() - xque.top();
// int ydif = ny.back() - yque.top();
// int zdif = nz.back() - zque.top();
// if(xdif <= ydif and xdif <= zdif and !xque.empty()){
// nx.push_back(xque.top());
// xque.pop();
// } else if(ydif <= xdif and ydif <= zdif and !yque.empty()){
// ny.push_back(yque.top());
// yque.pop();
// } else {
// nz.push_back(zque.top());
// zque.pop();
// }
// }
vector<int> ans;
// rep(i,nx.size())rep(j,ny.size())rep(k,nz.size()){
// ans.push_back(nx[i] + ny[j] + nz[k]);
// }
vector<int> sum;
rep(i, vy.size()) rep(j, vz.size()) sum.push_back(vy[i] + vz[j]);
sort(all(sum), greater<>());
rep(i, vx.size()) rep(j, min(3000LL, (int)sum.size()))
ans.push_back(vx[i] + sum[j]);
sort(all(ans), greater<>());
rep(i, k) cout << ans[i] << endl;
}
| replace | 91 | 93 | 91 | 94 | TLE | |
p03078 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
long long x, y, z, k;
long long cnt, cnt2;
long long a[1005], b[1005], c[1005], w[1000005], p[1000005];
bool cmp(long long x, long long y) { return x > y; }
int main() {
ios_base::sync_with_stdio(false);
cin.tie();
cout.tie();
cin >> x >> y >> z >> k;
for (long long i = 1; i <= x; ++i)
cin >> a[i];
for (long long i = 1; i <= y; ++i)
cin >> b[i];
for (long long i = 1; i <= z; ++i)
cin >> c[i];
for (long long i = 1; i <= x; ++i) {
for (long long j = 1; j <= y; ++j) {
w[++cnt] = a[i] + b[j];
}
}
sort(w + 1, w + cnt + 1, cmp);
for (long long i = 1; i <= min(k, cnt); ++i) {
for (long long j = 1; j <= min(k, z); ++j) {
p[++cnt2] = w[i] + c[j];
}
}
sort(p + 1, p + cnt2 + 1, cmp);
for (long long i = 1; i <= k; ++i)
cout << p[i] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
long long x, y, z, k;
long long cnt, cnt2;
long long a[10005], b[10005], c[10005], w[10000005], p[10000005];
bool cmp(long long x, long long y) { return x > y; }
int main() {
ios_base::sync_with_stdio(false);
cin.tie();
cout.tie();
cin >> x >> y >> z >> k;
for (long long i = 1; i <= x; ++i)
cin >> a[i];
for (long long i = 1; i <= y; ++i)
cin >> b[i];
for (long long i = 1; i <= z; ++i)
cin >> c[i];
for (long long i = 1; i <= x; ++i) {
for (long long j = 1; j <= y; ++j) {
w[++cnt] = a[i] + b[j];
}
}
sort(w + 1, w + cnt + 1, cmp);
for (long long i = 1; i <= min(k, cnt); ++i) {
for (long long j = 1; j <= min(k, z); ++j) {
p[++cnt2] = w[i] + c[j];
}
}
sort(p + 1, p + cnt2 + 1, cmp);
for (long long i = 1; i <= k; ++i)
cout << p[i] << endl;
return 0;
} | replace | 4 | 5 | 4 | 5 | 0 | |
p03078 | C++ | Runtime Error | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define SORT(c) sort((c).begin(), (c).end())
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();
}
// sort(v.rbegin(), v.rend(), [](auto& x, auto& y){return x[1] < y[1];});
// cout << fixed << setprecision(10) << ans << defaultfloat << endl;
typedef long long ll;
typedef vector<int> Vi;
typedef vector<ll> Vl;
typedef vector<double> Vd;
typedef vector<string> Vs;
ll mod = 1e9 + 7;
int main() {
int X, Y, Z, K;
cin >> X >> Y >> Z >> K;
Vl A(X), B(Y), C(Z), tmp(X * Y), ans;
REP(i, X) cin >> A[i];
REP(i, Y) cin >> B[i];
REP(i, Z) cin >> C[i];
sort(A.rbegin(), A.rend());
sort(B.rbegin(), B.rend());
sort(C.rbegin(), C.rend());
REP(i, X) {
REP(j, Y) { tmp[i * Y + j] = A[i] + B[j]; }
}
sort(tmp.rbegin(), tmp.rend());
ll m = 0, count = 0;
REP(i, Z) {
REP(j, X * Y) {
ll t = C[i] + tmp[j];
if (count >= K && m > t) {
break;
}
count++;
m = min(t, m);
ans.push_back(t);
}
}
sort(ans.rbegin(), ans.rend());
REP(i, K) cout << ans[i] << endl;
} | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define SORT(c) sort((c).begin(), (c).end())
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();
}
// sort(v.rbegin(), v.rend(), [](auto& x, auto& y){return x[1] < y[1];});
// cout << fixed << setprecision(10) << ans << defaultfloat << endl;
typedef long long ll;
typedef vector<int> Vi;
typedef vector<ll> Vl;
typedef vector<double> Vd;
typedef vector<string> Vs;
ll mod = 1e9 + 7;
int main() {
int X, Y, Z, K;
cin >> X >> Y >> Z >> K;
Vl A(X), B(Y), C(Z), tmp(X * Y), ans;
REP(i, X) cin >> A[i];
REP(i, Y) cin >> B[i];
REP(i, Z) cin >> C[i];
sort(A.rbegin(), A.rend());
sort(B.rbegin(), B.rend());
sort(C.rbegin(), C.rend());
REP(i, X) {
REP(j, Y) { tmp[i * Y + j] = A[i] + B[j]; }
}
sort(tmp.rbegin(), tmp.rend());
ll m = 0, count = 0;
REP(i, Z) {
REP(j, min(K, X * Y)) {
ll t = C[i] + tmp[j];
if (count >= K && m > t) {
break;
}
count++;
m = min(t, m);
ans.push_back(t);
}
}
sort(ans.rbegin(), ans.rend());
REP(i, K) cout << ans[i] << endl;
} | replace | 48 | 49 | 48 | 49 | 0 | |
p03078 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
long a[3333], d[1111111];
int main() {
int x, y, z, k;
cin >> x >> y >> z >> k;
for (int i = 0; i < x; i++)
cin >> a[i];
for (int i = 0; i < y; i++) {
long b;
cin >> b;
for (int j = 0; j < x; j++)
d[i * x + j] = a[j] + b;
}
int l = min(k, x * y);
nth_element(d, d + l, d + x * y, greater<long>());
copy(d, d + l, a);
for (int i = 0; i < z; i++) {
long b;
cin >> b;
for (int j = 0; j < l; j++)
d[i * l + j] = a[j] + b;
}
nth_element(d, d + k, d + l * z, greater<long>());
sort(d, d + k, greater<long>());
for (int i = 0; i < k; i++)
cout << d[i] << '\n';
cout << flush;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
long a[3333], d[3333333];
int main() {
int x, y, z, k;
cin >> x >> y >> z >> k;
for (int i = 0; i < x; i++)
cin >> a[i];
for (int i = 0; i < y; i++) {
long b;
cin >> b;
for (int j = 0; j < x; j++)
d[i * x + j] = a[j] + b;
}
int l = min(k, x * y);
nth_element(d, d + l, d + x * y, greater<long>());
copy(d, d + l, a);
for (int i = 0; i < z; i++) {
long b;
cin >> b;
for (int j = 0; j < l; j++)
d[i * l + j] = a[j] + b;
}
nth_element(d, d + k, d + l * z, greater<long>());
sort(d, d + k, greater<long>());
for (int i = 0; i < k; i++)
cout << d[i] << '\n';
cout << flush;
return 0;
}
| replace | 4 | 5 | 4 | 5 | 0 | |
p03078 | C++ | Memory Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
int x, y, z, k;
ll a[2000], b[2000], c[2000];
priority_queue<pair<ll, ll>> temp;
priority_queue<ll> q;
int main() {
cin >> x >> y >> z >> k;
for (int i = 1; i <= x; i++)
cin >> a[i];
for (int i = 1; i <= y; i++)
cin >> b[i];
for (int i = 1; i <= z; i++)
cin >> c[i];
sort(a + 1, a + 1 + x, greater<ll>());
sort(b + 1, b + 1 + y, greater<ll>());
sort(c + 1, c + 1 + z, greater<ll>());
int A, B, C;
A = 1;
B = 1;
C = 1;
while (A * B * C <= 90000000) {
if (A == x && B == y && C == z) {
break;
} else {
if (A < x) {
temp.push(make_pair(-1 * (a[A] - a[A + 1]), 1));
}
if (B < y) {
temp.push(make_pair(-1 * (b[B] - b[B + 1]), 2));
}
if (C < z) {
temp.push(make_pair(-1 * (c[C] - c[C + 1]), 3));
}
}
ll top = temp.top().second;
if (top == 1) {
A++;
} else if (top == 2) {
B++;
} else {
C++;
}
while (!temp.empty())
temp.pop();
}
for (int i = 1; i <= A; i++) {
for (int j = 1; j <= B; j++) {
for (int l = 1; l <= C; l++) {
q.push(a[i] + b[j] + c[l]);
}
}
}
for (int i = 0; i < k; i++) {
cout << q.top() << endl;
q.pop();
}
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
int x, y, z, k;
ll a[2000], b[2000], c[2000];
priority_queue<pair<ll, ll>> temp;
priority_queue<ll> q;
int main() {
cin >> x >> y >> z >> k;
for (int i = 1; i <= x; i++)
cin >> a[i];
for (int i = 1; i <= y; i++)
cin >> b[i];
for (int i = 1; i <= z; i++)
cin >> c[i];
sort(a + 1, a + 1 + x, greater<ll>());
sort(b + 1, b + 1 + y, greater<ll>());
sort(c + 1, c + 1 + z, greater<ll>());
int A, B, C;
A = 1;
B = 1;
C = 1;
while (A * B * C <= 10000000) {
if (A == x && B == y && C == z) {
break;
} else {
if (A < x) {
temp.push(make_pair(-1 * (a[A] - a[A + 1]), 1));
}
if (B < y) {
temp.push(make_pair(-1 * (b[B] - b[B + 1]), 2));
}
if (C < z) {
temp.push(make_pair(-1 * (c[C] - c[C + 1]), 3));
}
}
ll top = temp.top().second;
if (top == 1) {
A++;
} else if (top == 2) {
B++;
} else {
C++;
}
while (!temp.empty())
temp.pop();
}
for (int i = 1; i <= A; i++) {
for (int j = 1; j <= B; j++) {
for (int l = 1; l <= C; l++) {
q.push(a[i] + b[j] + c[l]);
}
}
}
for (int i = 0; i < k; i++) {
cout << q.top() << endl;
q.pop();
}
}
| replace | 25 | 26 | 25 | 26 | MLE | |
p03078 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)
const ll MOD = 1000000007;
const ll INF = (ll)1e15;
ll X, Y, Z, K;
ll A[1005];
ll B[1005];
ll C[1005];
vector<ll> v;
int main() {
cin >> X >> Y >> Z >> K;
REP(i, X) { cin >> A[i]; }
REP(i, Y) { cin >> B[i]; }
REP(i, Z) { cin >> C[i]; }
sort(A, A + X, [](ll a, ll b) { return a > b; });
sort(B, B + Y, [](ll a, ll b) { return a > b; });
sort(C, C + Z, [](ll a, ll b) { return a > b; });
ll m = INF;
REP(a, X) {
REP(b, Y) {
REP(c, Z) {
ll s = A[a] + B[b] + C[c];
if (v.size() >= K && s <= m)
break;
m = std::min(m, s);
v.push_back(s);
}
}
}
sort(v.begin(), v.end(), [](ll a, ll b) { return a > b; });
REP(i, K) { cout << v[i] << endl; }
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)
const ll MOD = 1000000007;
const ll INF = (ll)1e15;
ll X, Y, Z, K;
ll A[1005];
ll B[1005];
ll C[1005];
vector<ll> v;
int main() {
cin >> X >> Y >> Z >> K;
REP(i, X) { cin >> A[i]; }
REP(i, Y) { cin >> B[i]; }
REP(i, Z) { cin >> C[i]; }
sort(A, A + X, [](ll a, ll b) { return a > b; });
sort(B, B + Y, [](ll a, ll b) { return a > b; });
sort(C, C + Z, [](ll a, ll b) { return a > b; });
vector<ll> vv;
REP(i, X) {
REP(j, Y) { vv.push_back(A[i] + B[j]); }
}
sort(vv.begin(), vv.end(), [](ll a, ll b) { return a > b; });
REP(i, std::min(K, (ll)vv.size())) {
REP(j, Z) { v.push_back(vv[i] + C[j]); }
}
sort(v.begin(), v.end(), [](ll a, ll b) { return a > b; });
REP(i, K) { cout << v[i] << endl; }
return 0;
} | replace | 30 | 41 | 30 | 37 | 0 | |
p03078 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
#define P pair<int, int>
#define LL long long
#define LD long double
#define PLL pair<LL, LL>
#define mset(a, b) memset(a, b, sizeof(a))
#define rep(i, n) for (int i = 0; i < n; i++)
#define PI acos(-1.0)
#define random(x) rand() % x
using namespace std;
const int inf = 0x3f3f3f3f;
const LL __64inf = 0x3f3f3f3f3f3f3f3f;
const int MAX = 1e5 + 5;
const int Mod = 1e9 + 7;
LL E[1005 * 1005];
LL D[1005 * 1005];
LL cnt;
int main() {
int x, y, z, k;
cin >> x >> y >> z >> k;
vector<LL> A(x), B(y), C(z);
for (int i = 0; i < x; i++)
cin >> A[i];
for (int i = 0; i < y; i++)
cin >> B[i];
for (int i = 0; i < z; i++)
cin >> C[i];
sort(A.rbegin(), A.rend());
sort(B.rbegin(), B.rend());
sort(C.rbegin(), C.rend());
rep(i, x) { rep(j, y) D[cnt++] = A[i] + B[j]; }
sort(D, D + cnt, greater<LL>());
cnt = 0;
rep(i, k) {
rep(j, z) { E[cnt++] = D[i] + C[j]; }
}
sort(E, E + cnt, greater<LL>());
rep(i, k) cout << E[i] << "\n";
return 0;
}; | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
#define P pair<int, int>
#define LL long long
#define LD long double
#define PLL pair<LL, LL>
#define mset(a, b) memset(a, b, sizeof(a))
#define rep(i, n) for (int i = 0; i < n; i++)
#define PI acos(-1.0)
#define random(x) rand() % x
using namespace std;
const int inf = 0x3f3f3f3f;
const LL __64inf = 0x3f3f3f3f3f3f3f3f;
const int MAX = 1e5 + 5;
const int Mod = 1e9 + 7;
LL E[3005 * 1005];
LL D[1005 * 1005];
LL cnt;
int main() {
int x, y, z, k;
cin >> x >> y >> z >> k;
vector<LL> A(x), B(y), C(z);
for (int i = 0; i < x; i++)
cin >> A[i];
for (int i = 0; i < y; i++)
cin >> B[i];
for (int i = 0; i < z; i++)
cin >> C[i];
sort(A.rbegin(), A.rend());
sort(B.rbegin(), B.rend());
sort(C.rbegin(), C.rend());
rep(i, x) { rep(j, y) D[cnt++] = A[i] + B[j]; }
sort(D, D + cnt, greater<LL>());
cnt = 0;
rep(i, k) {
rep(j, z) { E[cnt++] = D[i] + C[j]; }
}
sort(E, E + cnt, greater<LL>());
rep(i, k) cout << E[i] << "\n";
return 0;
}; | replace | 28 | 29 | 28 | 29 | 0 | |
p03078 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define MOD 1000000007
int main() {
fast;
ll x, y, z, k, flag = 0;
cin >> x >> y >> z >> k;
vector<ll> a(x);
vector<ll> b(y);
vector<ll> c(z);
for (int i = 0; i < x; i++)
cin >> a[i];
for (int i = 0; i < y; i++)
cin >> b[i];
for (int i = 0; i < z; i++)
cin >> c[i];
sort(a.begin(), a.end(), greater<ll>());
sort(b.begin(), b.end(), greater<ll>());
sort(c.begin(), c.end(), greater<ll>());
vector<ll> ans;
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
for (int m = 0; m < z; m++) {
ans.push_back(a[i] + b[j] + c[m]);
}
}
}
sort(ans.begin(), ans.end(), greater<ll>());
for (int i = 0; i < k; i++)
cout << ans[i] << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define MOD 1000000007
int main() {
fast;
ll x, y, z, k, flag = 0;
cin >> x >> y >> z >> k;
vector<ll> a(x);
vector<ll> b(y);
vector<ll> c(z);
for (int i = 0; i < x; i++)
cin >> a[i];
for (int i = 0; i < y; i++)
cin >> b[i];
for (int i = 0; i < z; i++)
cin >> c[i];
sort(a.begin(), a.end(), greater<ll>());
sort(b.begin(), b.end(), greater<ll>());
sort(c.begin(), c.end(), greater<ll>());
vector<ll> ans;
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
for (int m = 0; m < z; m++) {
if ((i + 1) * (j + 1) * (m + 1) <= k)
ans.push_back(a[i] + b[j] + c[m]);
else
break;
}
}
}
sort(ans.begin(), ans.end(), greater<ll>());
for (int i = 0; i < k; i++)
cout << ans[i] << endl;
return 0;
}
| replace | 29 | 30 | 29 | 33 | TLE | |
p03078 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
#define INF 1000000007
#define LINF (1LL << 62)
typedef long long i64;
typedef pair<i64, i64> P;
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;
}
int x, y, z, k;
i64 a[1010], b[1010], c[1010];
i64 d[1010 * 1010], e[1010 * 1010];
int main() {
cin >> x >> y >> z >> k;
for (int i = 0; i < x; i++) {
cin >> a[i];
}
for (int i = 0; i < y; i++) {
cin >> b[i];
}
for (int i = 0; i < z; i++) {
cin >> c[i];
}
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
d[i * y + j] = a[i] + b[j];
}
}
sort(d, d + x * y, greater<i64>());
for (int i = 0; i < min(k, x * y); i++) {
for (int j = 0; j < z; j++) {
e[i * z + j] = d[i] + c[j];
}
}
sort(e, e + min(k, x * y) * z, greater<i64>());
for (int i = 0; i < k; i++) {
cout << e[i] << endl;
}
return 0;
} | #include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
#define INF 1000000007
#define LINF (1LL << 62)
typedef long long i64;
typedef pair<i64, i64> P;
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;
}
int x, y, z, k;
i64 a[1010], b[1010], c[1010];
i64 d[1010 * 1010], e[3030 * 1010];
int main() {
cin >> x >> y >> z >> k;
for (int i = 0; i < x; i++) {
cin >> a[i];
}
for (int i = 0; i < y; i++) {
cin >> b[i];
}
for (int i = 0; i < z; i++) {
cin >> c[i];
}
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
d[i * y + j] = a[i] + b[j];
}
}
sort(d, d + x * y, greater<i64>());
for (int i = 0; i < min(k, x * y); i++) {
for (int j = 0; j < z; j++) {
e[i * z + j] = d[i] + c[j];
}
}
sort(e, e + min(k, x * y) * z, greater<i64>());
for (int i = 0; i < k; i++) {
cout << e[i] << endl;
}
return 0;
} | replace | 35 | 36 | 35 | 36 | 0 | |
p03078 | C++ | Runtime Error | #include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define dame \
{ \
puts("-1"); \
return 0; \
}
#define show(x) cerr << #x << " = " << x << endl;
using namespace std;
using ll = long long;
using ld = long double;
using pl = pair<ll, ll>;
typedef vector<ll> vl;
typedef vector<pl> vp;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const ll mod = 1000000007;
struct mint {
ll x; // typedef long long ll;
mint(ll x = 0) : x((x % mod + mod) % mod) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint a) {
if ((x += a.x) >= mod)
x -= mod;
return *this;
}
mint &operator-=(const mint a) {
if ((x += mod - a.x) >= mod)
x -= mod;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const { return mint(*this) += a; }
mint operator-(const mint a) const { return mint(*this) -= a; }
mint operator*(const mint a) const { return mint(*this) *= a; }
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(mod - 2); }
mint &operator/=(const mint a) { return *this *= a.inv(); }
mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
vector<mint> fact, ifact;
combination(int n) : fact(n + 1), ifact(n + 1) {
assert(n < mod);
fact[0] = 1;
for (int i = 1; i <= n; ++i)
fact[i] = fact[i - 1] * i;
ifact[n] = fact[n].inv();
for (int i = n; i >= 1; --i)
ifact[i - 1] = ifact[i] * i;
}
mint operator()(int n, int k) {
if (k < 0 || k > n)
return 0;
return fact[n] * ifact[k] * ifact[n - k];
}
} c(200005);
// Sieve of Eratosthenes
// https://youtu.be/UTVg7wzMWQc?t=2774
struct Sieve {
int n;
vector<int> f, primes;
Sieve(int n = 1) : n(n), f(n + 1) {
f[0] = f[1] = -1;
for (ll i = 2; i <= n; ++i) {
if (f[i])
continue;
primes.push_back(i);
f[i] = i;
for (ll j = i * i; j <= n; j += i) {
if (!f[j])
f[j] = i;
}
}
}
bool isPrime(int x) { return f[x] == x; }
vector<int> factorList(int x) {
vector<int> res;
while (x != 1) {
res.push_back(f[x]);
x /= f[x];
}
return res;
}
vector<pl> factor(int x) {
vector<int> fl = factorList(x);
if (fl.size() == 0)
return {};
vector<pl> res(1, pl(fl[0], 0));
for (int p : fl) {
if (res.back().first == p) {
res.back().second++;
} else {
res.emplace_back(p, 1);
}
}
return res;
}
vector<pair<ll, int>> factor(ll x) {
vector<pair<ll, int>> res;
for (int p : primes) {
int y = 0;
while (x % p == 0)
x /= p, ++y;
if (y != 0)
res.emplace_back(p, y);
}
if (x != 1)
res.emplace_back(x, 1);
return res;
}
};
ll LINF = 1000000000000000000;
int main() {
ll x, y, z, k;
cin >> x >> y >> z >> k;
vector<ll> a(x);
vector<ll> b(y);
vector<ll> c(z);
rep(i, x) cin >> a[i];
rep(i, y) cin >> b[i];
rep(i, z) cin >> c[i];
sort(ALL(a));
sort(ALL(b));
sort(ALL(c));
reverse(ALL(a));
reverse(ALL(b));
reverse(ALL(c));
vector<ll> s;
for (ll i = 0; i + 1 <= min(x, k); i++) {
for (ll j = 0; i + j + 2 <= min(y, k); j++) {
for (ll l = 0; i + j + l + 3 <= min(z, k); l++) {
s.pb(a[i] + b[j] + c[l]);
}
}
}
sort(ALL(s));
reverse(ALL(s));
rep(i, k) cout << s[i] << endl;
return 0;
}
| #include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define dame \
{ \
puts("-1"); \
return 0; \
}
#define show(x) cerr << #x << " = " << x << endl;
using namespace std;
using ll = long long;
using ld = long double;
using pl = pair<ll, ll>;
typedef vector<ll> vl;
typedef vector<pl> vp;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const ll mod = 1000000007;
struct mint {
ll x; // typedef long long ll;
mint(ll x = 0) : x((x % mod + mod) % mod) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint a) {
if ((x += a.x) >= mod)
x -= mod;
return *this;
}
mint &operator-=(const mint a) {
if ((x += mod - a.x) >= mod)
x -= mod;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const { return mint(*this) += a; }
mint operator-(const mint a) const { return mint(*this) -= a; }
mint operator*(const mint a) const { return mint(*this) *= a; }
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(mod - 2); }
mint &operator/=(const mint a) { return *this *= a.inv(); }
mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
vector<mint> fact, ifact;
combination(int n) : fact(n + 1), ifact(n + 1) {
assert(n < mod);
fact[0] = 1;
for (int i = 1; i <= n; ++i)
fact[i] = fact[i - 1] * i;
ifact[n] = fact[n].inv();
for (int i = n; i >= 1; --i)
ifact[i - 1] = ifact[i] * i;
}
mint operator()(int n, int k) {
if (k < 0 || k > n)
return 0;
return fact[n] * ifact[k] * ifact[n - k];
}
} c(200005);
// Sieve of Eratosthenes
// https://youtu.be/UTVg7wzMWQc?t=2774
struct Sieve {
int n;
vector<int> f, primes;
Sieve(int n = 1) : n(n), f(n + 1) {
f[0] = f[1] = -1;
for (ll i = 2; i <= n; ++i) {
if (f[i])
continue;
primes.push_back(i);
f[i] = i;
for (ll j = i * i; j <= n; j += i) {
if (!f[j])
f[j] = i;
}
}
}
bool isPrime(int x) { return f[x] == x; }
vector<int> factorList(int x) {
vector<int> res;
while (x != 1) {
res.push_back(f[x]);
x /= f[x];
}
return res;
}
vector<pl> factor(int x) {
vector<int> fl = factorList(x);
if (fl.size() == 0)
return {};
vector<pl> res(1, pl(fl[0], 0));
for (int p : fl) {
if (res.back().first == p) {
res.back().second++;
} else {
res.emplace_back(p, 1);
}
}
return res;
}
vector<pair<ll, int>> factor(ll x) {
vector<pair<ll, int>> res;
for (int p : primes) {
int y = 0;
while (x % p == 0)
x /= p, ++y;
if (y != 0)
res.emplace_back(p, y);
}
if (x != 1)
res.emplace_back(x, 1);
return res;
}
};
ll LINF = 1000000000000000000;
int main() {
ll x, y, z, k;
cin >> x >> y >> z >> k;
vector<ll> a(x);
vector<ll> b(y);
vector<ll> c(z);
rep(i, x) cin >> a[i];
rep(i, y) cin >> b[i];
rep(i, z) cin >> c[i];
sort(ALL(a));
sort(ALL(b));
sort(ALL(c));
reverse(ALL(a));
reverse(ALL(b));
reverse(ALL(c));
vector<ll> s;
for (ll i = 0; i < x; i++) {
for (ll j = 0; j < y; j++) {
for (ll l = 0; l < z; l++) {
if ((i + 1) * (j + 1) * (l + 1) <= k)
s.pb(a[i] + b[j] + c[l]);
else
break;
}
}
}
sort(ALL(s));
reverse(ALL(s));
rep(i, k) cout << s[i] << endl;
return 0;
}
| replace | 179 | 183 | 179 | 186 | -11 | |
p03078 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
int main() {
int X, Y, Z;
long K;
long A[1000];
long B[1000];
long C[1000];
multiset<long> ansSet;
scanf("%d %d %d %ld", &X, &Y, &Z, &K);
for (int i = 0; i < X; i++)
scanf("%ld", &A[i]);
for (int i = 0; i < Y; i++)
scanf("%ld", &B[i]);
for (int i = 0; i < Z; i++)
scanf("%ld", &C[i]);
for (int i = 0; i < X; i++)
for (int j = 0; j < Y; j++)
for (int k = 0; k < Z; k++) {
ansSet.insert(A[i] + B[j] + C[k]);
}
long a = 0;
for (auto itr = ansSet.rbegin(); itr != ansSet.rend(); itr++) {
printf("%ld\n", *itr);
a++;
if (a >= K)
break;
}
return 0;
}
| #include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
int main() {
int X, Y, Z;
long K;
long A[1000];
long B[1000];
long C[1000];
multiset<long> ansSet;
scanf("%d %d %d %ld", &X, &Y, &Z, &K);
for (int i = 0; i < X; i++)
scanf("%ld", &A[i]);
for (int i = 0; i < Y; i++)
scanf("%ld", &B[i]);
for (int i = 0; i < Z; i++)
scanf("%ld", &C[i]);
for (int i = 0; i < X; i++)
for (int j = 0; j < Y; j++)
for (int k = 0; k < Z; k++) {
long sum = A[i] + B[j] + C[k];
if (ansSet.size() < K) {
ansSet.insert(sum);
} else {
if (*ansSet.begin() < sum) {
ansSet.erase(ansSet.begin());
ansSet.insert(sum);
}
}
}
long a = 0;
for (auto itr = ansSet.rbegin(); itr != ansSet.rend(); itr++) {
printf("%ld\n", *itr);
a++;
if (a >= K)
break;
}
return 0;
}
| replace | 31 | 32 | 31 | 40 | TLE | |
p03078 | C++ | Time Limit Exceeded | #include <algorithm>
#include <fstream>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
static ull tenq = 1000000000;
static ull mod = tenq + 7;
using namespace std;
int main() {
ll K;
vector<ll> num(3, 0);
for (auto i = 0; i < 3; i++) {
cin >> num[i];
}
cin >> K;
vector<vector<ll>> cakes(num.size());
for (auto i = 0; i < 3; i++) {
cakes[i] = vector<ll>(num[i]);
for (auto j = 0; j < num[i]; j++)
cin >> cakes[i][j];
// sort(cakes[i].begin(), cakes[i].end(), std::greater<ll>());
}
vector<ll> current(num[2], 0);
current.push_back(0);
vector<ll> best(K + 1, 0);
vector<ll> best_new(K + 1, 0);
for (auto i = 0; i < num[0]; i++)
for (auto j = 0; j < num[1]; j++) {
for (auto k = 0; k < num[2]; k++) {
ll value = cakes[0][i] + cakes[1][j] + cakes[2][k];
current[k] = value;
}
sort(current.begin(), current.end(), greater<ll>());
for (auto k = 0, i1 = 0, i2 = 0; k < best.size(); k++) {
if (best[i1] == 0 && current[i2] == 0)
break;
if (best[i1] > current[i2]) {
best_new[k] = best[i1];
i1++;
} else {
best_new[k] = current[i2];
i2++;
}
}
best = best_new;
}
best.pop_back();
for (auto x : best)
cout << x << endl;
return 0;
}
| #include <algorithm>
#include <fstream>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
static ull tenq = 1000000000;
static ull mod = tenq + 7;
using namespace std;
int main() {
ll K;
vector<ll> num(3, 0);
for (auto i = 0; i < 3; i++) {
cin >> num[i];
}
cin >> K;
vector<vector<ll>> cakes(num.size());
for (auto i = 0; i < 3; i++) {
cakes[i] = vector<ll>(num[i]);
for (auto j = 0; j < num[i]; j++)
cin >> cakes[i][j];
// sort(cakes[i].begin(), cakes[i].end(), std::greater<ll>());
}
vector<ll> best;
vector<ll> bestXY;
for (auto x : cakes[0])
for (auto y : cakes[1])
bestXY.push_back(x + y);
sort(bestXY.begin(), bestXY.end(), greater<ll>());
for (auto i = 0; i < min((ll)bestXY.size(), K); i++) {
for (auto z : cakes[2])
best.push_back(bestXY[i] + z);
}
sort(best.begin(), best.end(), greater<ll>());
for (auto i = 0; i < min((ll)best.size(), K); i++)
cout << best[i] << endl;
return 0;
}
| replace | 34 | 61 | 34 | 48 | TLE | |
p03078 | Python | Runtime Error | X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
ans = []
for x in range(X):
for y in range(Y):
for z in range(Z):
if (x + 1) * (y + 1) * (z + 1) <= K:
ans.append(A[x] + B[y] + C[z])
else:
break
ans.sort(revere=True)
print(*ans[:K], sep="\n")
| X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
ans = []
for x in range(X):
for y in range(Y):
for z in range(Z):
if (x + 1) * (y + 1) * (z + 1) <= K:
ans.append(A[x] + B[y] + C[z])
else:
break
ans.sort(reverse=True)
print(*ans[:K], sep="\n")
| replace | 17 | 18 | 17 | 18 | TypeError: 'revere' is an invalid keyword argument for sort() | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03078/Python/s322698667.py", line 18, in <module>
ans.sort(revere=True)
TypeError: 'revere' is an invalid keyword argument for sort()
|
p03078 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
int main() {
int x, y, z, k;
cin >> x >> y >> z >> k;
vector<ll> a(x), b(y), c(z);
for (int i = 0; i < x; i++)
cin >> a[i];
for (int i = 0; i < y; i++)
cin >> b[i];
for (int i = 0; i < z; i++)
cin >> c[i];
sort(a.begin(), a.end());
sort(b.begin(), b.end());
sort(c.begin(), c.end());
int pa = x - 1, pb = y - 1, pc = z - 1, ca = 1, cb = 1, cc = 1;
while (ca * cb * cc < k) {
if (pa >= 1 && pb >= 1 && pc >= 1) {
if (a[pa - 1] + b[pb] + c[pc] >= a[pa] + b[pb - 1] + c[pc] &&
a[pa - 1] + b[pb] + c[pc] >= a[pa] + b[pb] + c[pc - 1])
pa--, ca++;
else if (a[pa] + b[pb - 1] + c[pc] >= a[pa - 1] + b[pb] + c[pc] &&
a[pa] + b[pb - 1] + c[pc] >= a[pa] + b[pb] + c[pc - 1])
pb--, cb++;
else if (a[pa] + b[pb] + c[pc - 1] >= a[pa - 1] + b[pb] + c[pc] &&
a[pa] + b[pb] + c[pc - 1] >= a[pa] + b[pb - 1] + c[pc])
pc--, cc++;
} else if (pa >= 1 && pb >= 1) {
if (a[pa - 1] + b[pb] + c[pc] >= a[pa] + b[pb - 1] + c[pc])
pa--, ca++;
else
pb--, cb++;
} else if (pb >= 1 && pc >= 1) {
if (a[pa] + b[pb - 1] + c[pc] >= a[pa] + b[pb] + c[pc - 1])
pb--, cb++;
else
pc--, cc++;
} else if (pc >= 1 && pa >= 1) {
if (a[pa] + b[pb] + c[pc - 1] >= a[pa - 1] + b[pb] + c[pc])
pc--, cc++;
else
pa--, ca++;
} else if (pa >= 1) {
pa--, ca++;
} else if (pb >= 1) {
pb--, cb++;
} else if (pc >= 1) {
pc--, cc++;
}
}
ca = min(x, ca + 150);
cb = min(y, cb + 150);
cc = min(z, cc + 150);
vector<ll> sum;
for (ll i = 1; i <= ca; i++) {
for (ll j = 1; j <= cb; j++) {
for (ll k = 1; k <= cc; k++) {
sum.push_back(a[x - i] + b[y - j] + c[z - k]);
}
}
}
sort(sum.begin(), sum.end());
ll cnt = 0;
for (ll i = sum.size() - 1;; i--) {
cout << sum[i] << endl;
cnt++;
if (cnt == k)
break;
}
return 0;
} | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
int main() {
int x, y, z, k;
cin >> x >> y >> z >> k;
vector<ll> a(x), b(y), c(z);
for (int i = 0; i < x; i++)
cin >> a[i];
for (int i = 0; i < y; i++)
cin >> b[i];
for (int i = 0; i < z; i++)
cin >> c[i];
sort(a.begin(), a.end());
sort(b.begin(), b.end());
sort(c.begin(), c.end());
int pa = x - 1, pb = y - 1, pc = z - 1, ca = 1, cb = 1, cc = 1;
while (ca * cb * cc < k) {
if (pa >= 1 && pb >= 1 && pc >= 1) {
if (a[pa - 1] + b[pb] + c[pc] >= a[pa] + b[pb - 1] + c[pc] &&
a[pa - 1] + b[pb] + c[pc] >= a[pa] + b[pb] + c[pc - 1])
pa--, ca++;
else if (a[pa] + b[pb - 1] + c[pc] >= a[pa - 1] + b[pb] + c[pc] &&
a[pa] + b[pb - 1] + c[pc] >= a[pa] + b[pb] + c[pc - 1])
pb--, cb++;
else if (a[pa] + b[pb] + c[pc - 1] >= a[pa - 1] + b[pb] + c[pc] &&
a[pa] + b[pb] + c[pc - 1] >= a[pa] + b[pb - 1] + c[pc])
pc--, cc++;
} else if (pa >= 1 && pb >= 1) {
if (a[pa - 1] + b[pb] + c[pc] >= a[pa] + b[pb - 1] + c[pc])
pa--, ca++;
else
pb--, cb++;
} else if (pb >= 1 && pc >= 1) {
if (a[pa] + b[pb - 1] + c[pc] >= a[pa] + b[pb] + c[pc - 1])
pb--, cb++;
else
pc--, cc++;
} else if (pc >= 1 && pa >= 1) {
if (a[pa] + b[pb] + c[pc - 1] >= a[pa - 1] + b[pb] + c[pc])
pc--, cc++;
else
pa--, ca++;
} else if (pa >= 1) {
pa--, ca++;
} else if (pb >= 1) {
pb--, cb++;
} else if (pc >= 1) {
pc--, cc++;
}
}
ca = min(x, ca + 100);
cb = min(y, cb + 100);
cc = min(z, cc + 100);
vector<ll> sum;
for (ll i = 1; i <= ca; i++) {
for (ll j = 1; j <= cb; j++) {
for (ll k = 1; k <= cc; k++) {
sum.push_back(a[x - i] + b[y - j] + c[z - k]);
}
}
}
sort(sum.begin(), sum.end());
ll cnt = 0;
for (ll i = sum.size() - 1;; i--) {
cout << sum[i] << endl;
cnt++;
if (cnt == k)
break;
}
return 0;
} | replace | 53 | 56 | 53 | 56 | TLE | |
p03078 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rg register
#define ll long long
using namespace std;
const int N = 1e3 + 5, mod = 1e9 + 7;
int n, m, T, k, ans, len;
ll a[N], b[N], c[N], d[N], t[N];
bool cmp(ll x, ll y) { return x > y; }
int main() {
ll ans = 0;
priority_queue<pair<ll, ll>> q;
int x, y, z, k, temp = 0;
cin >> x >> y >> z >> k;
for (rg int i = 1; i <= x; ++i)
scanf("%lld", &a[i]);
for (rg int i = 1; i <= y; ++i)
scanf("%lld", &b[i]);
sort(a + 1, a + x + 1, cmp);
sort(b + 1, b + y + 1, cmp);
for (rg int i = 1; i <= x; i++)
for (rg int j = 1; j <= y; j++)
c[++temp] = a[i] + b[j];
sort(c + 1, c + temp + 1, cmp);
for (rg int i = 1; i <= z; ++i)
scanf("%lld", &d[i]);
sort(d + 1, d + z + 1, cmp);
for (rg int i = 1; i <= z; ++i) {
t[i] = 1;
q.push(pair<ll, ll>(c[1] + d[i], i));
}
ll i;
while (k--) {
cout << q.top().first << endl;
i = q.top().second;
q.pop();
q.push(pair<ll, ll>(c[++t[i]] + d[i], i));
}
// cout<<ans;
return 0;
} | #include <bits/stdc++.h>
#define rg register
#define ll long long
using namespace std;
const int N = 1e3 + 5, mod = 1e9 + 7;
int n, m, T, k, ans, len;
ll a[N], b[N], d[N], t[N];
ll c[1000005];
bool cmp(ll x, ll y) { return x > y; }
int main() {
ll ans = 0;
priority_queue<pair<ll, ll>> q;
int x, y, z, k, temp = 0;
cin >> x >> y >> z >> k;
for (rg int i = 1; i <= x; ++i)
scanf("%lld", &a[i]);
for (rg int i = 1; i <= y; ++i)
scanf("%lld", &b[i]);
sort(a + 1, a + x + 1, cmp);
sort(b + 1, b + y + 1, cmp);
for (rg int i = 1; i <= x; i++)
for (rg int j = 1; j <= y; j++)
c[++temp] = a[i] + b[j];
sort(c + 1, c + temp + 1, cmp);
for (rg int i = 1; i <= z; ++i)
scanf("%lld", &d[i]);
sort(d + 1, d + z + 1, cmp);
for (rg int i = 1; i <= z; ++i) {
t[i] = 1;
q.push(pair<ll, ll>(c[1] + d[i], i));
}
ll i;
while (k--) {
cout << q.top().first << endl;
i = q.top().second;
q.pop();
q.push(pair<ll, ll>(c[++t[i]] + d[i], i));
}
// cout<<ans;
return 0;
} | replace | 6 | 7 | 6 | 8 | 0 | |
p03078 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define ll long long
using namespace std;
ll a[1000], b[1000], c[1000];
int main() {
int x, y, z, k;
cin >> x >> y >> z >> k;
for (int i = 0; i < x; i++)
cin >> a[i];
for (int i = 0; i < y; i++)
cin >> b[i];
for (int i = 0; i < z; i++)
cin >> c[i];
sort(a, a + x);
sort(b, b + y);
sort(c, c + z);
reverse(a, a + x);
reverse(b, b + x);
reverse(c, c + x);
vector<ll> ab;
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
ab.push_back(a[i] + b[j]);
}
}
sort(ab.begin(), ab.end());
reverse(ab.begin(), ab.end());
vector<ll> abc;
for (int i = 0; i < ab.size(); i++) {
for (int j = 0; j < z; j++) {
abc.push_back(ab[i] + c[j]);
}
}
sort(abc.begin(), abc.end());
reverse(abc.begin(), abc.end());
for (int i = 0; i < k; i++)
cout << abc[i] << endl;
return 0;
}
| #include <bits/stdc++.h>
#define ll long long
using namespace std;
ll a[1000], b[1000], c[1000];
int main() {
int x, y, z, k;
cin >> x >> y >> z >> k;
for (int i = 0; i < x; i++)
cin >> a[i];
for (int i = 0; i < y; i++)
cin >> b[i];
for (int i = 0; i < z; i++)
cin >> c[i];
sort(a, a + x);
sort(b, b + y);
sort(c, c + z);
reverse(a, a + x);
reverse(b, b + x);
reverse(c, c + x);
vector<ll> ab;
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
ab.push_back(a[i] + b[j]);
}
}
sort(ab.begin(), ab.end());
reverse(ab.begin(), ab.end());
vector<ll> abc;
for (int i = 0; i < min(k, (int)ab.size()); i++) {
for (int j = 0; j < z; j++) {
abc.push_back(ab[i] + c[j]);
}
}
sort(abc.begin(), abc.end());
reverse(abc.begin(), abc.end());
for (int i = 0; i < k; i++)
cout << abc[i] << endl;
return 0;
}
| replace | 30 | 31 | 30 | 31 | TLE | |
p03078 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
ll a[1005], b[1005], c[1005];
int x, y, z, k;
cin >> x >> y >> z >> k;
for (int i = 0; i < x; i++)
cin >> a[i];
for (int i = 0; i < y; i++)
cin >> b[i];
for (int i = 0; i < z; i++)
cin >> c[i];
sort(a, a + x);
reverse(a, a + x);
sort(b, b + y);
reverse(b, b + y);
sort(c, c + z);
reverse(c, c + z);
vector<ll> abc;
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
if ((i + 1) * (j + 1) > k)
break;
for (int l = 0; l < z; l++) {
if ((i + 1) + (j + 1) + (l + 1) > k)
break;
abc.push_back(a[i] + b[j] + c[l]);
}
}
}
sort(abc.begin(), abc.end());
reverse(abc.begin(), abc.end());
for (int i = 0; i < k; i++)
cout << abc[i] << endl;
return 0;
}
| #include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
ll a[1005], b[1005], c[1005];
int x, y, z, k;
cin >> x >> y >> z >> k;
for (int i = 0; i < x; i++)
cin >> a[i];
for (int i = 0; i < y; i++)
cin >> b[i];
for (int i = 0; i < z; i++)
cin >> c[i];
sort(a, a + x);
reverse(a, a + x);
sort(b, b + y);
reverse(b, b + y);
sort(c, c + z);
reverse(c, c + z);
vector<ll> abc;
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
if ((i + 1) * (j + 1) > k)
break;
for (int l = 0; l < z; l++) {
if ((i + 1) * (j + 1) * (l + 1) > k)
break;
abc.push_back(a[i] + b[j] + c[l]);
}
}
}
sort(abc.begin(), abc.end());
reverse(abc.begin(), abc.end());
for (int i = 0; i < k; i++)
cout << abc[i] << endl;
return 0;
}
| replace | 28 | 29 | 28 | 29 | 0 | |
p03078 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <forward_list>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);
int main(void) {
int x, y, z, k;
cin >> x >> y >> z >> k;
vector<ll> a(x), b(y), c(z), ab, abc;
for (int i = 0; i < x; i++) {
cin >> a[i];
}
for (int i = 0; i < y; i++) {
cin >> b[i];
}
for (int i = 0; i < z; i++) {
cin >> c[i];
}
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
ab.push_back(a[i] + b[j]);
}
}
for (auto i : ab) {
for (auto j : c) {
abc.push_back(i + j);
}
}
sort(abc.begin(), abc.end(), greater<ll>());
for (int i = 0; i < k; i++) {
cout << abc[i] << endl;
}
} | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <forward_list>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);
int main(void) {
int x, y, z, k;
cin >> x >> y >> z >> k;
vector<ll> a(x), b(y), c(z), ab, abc;
for (int i = 0; i < x; i++) {
cin >> a[i];
}
for (int i = 0; i < y; i++) {
cin >> b[i];
}
for (int i = 0; i < z; i++) {
cin >> c[i];
}
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
ab.push_back(a[i] + b[j]);
}
}
sort(ab.begin(), ab.end(), greater<ll>());
for (int i = 0; i < min(k, x * y); i++) {
for (int j = 0; j < z; j++) {
abc.push_back(ab[i] + c[j]);
}
}
sort(abc.begin(), abc.end(), greater<ll>());
for (int i = 0; i < k; i++) {
cout << abc[i] << endl;
}
} | replace | 48 | 51 | 48 | 53 | 0 | |
p03078 | C++ | Runtime Error | #include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
using namespace std;
int main() {
int X, Y, Z, K;
cin >> X >> Y >> Z >> K;
vector<long long> xx(X), yy(Y), zz(Z);
for (int i = 0; i < X; ++i)
cin >> xx[i];
sort(all(xx), greater<long long>());
for (int i = 0; i < Y; ++i)
cin >> yy[i];
sort(all(yy), greater<long long>());
for (int i = 0; i < Z; ++i)
cin >> zz[i];
sort(all(zz), greater<long long>());
vector<long long> res;
for (int i = 0; i < X; ++i) {
for (int j = 0; j < Y; ++j) {
for (int k = 0; k < Z; ++k) {
if ((i + 1) * (j + 1) * (k + 1) >= K)
break;
res.push_back(xx[i] + yy[j] + zz[k]);
}
}
}
sort(all(res), greater<long long>());
for (int i = 0; i < K; ++i)
cout << res[i] << "\n";
return 0;
}
| #include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
using namespace std;
int main() {
int X, Y, Z, K;
cin >> X >> Y >> Z >> K;
vector<long long> xx(X), yy(Y), zz(Z);
for (int i = 0; i < X; ++i)
cin >> xx[i];
sort(all(xx), greater<long long>());
for (int i = 0; i < Y; ++i)
cin >> yy[i];
sort(all(yy), greater<long long>());
for (int i = 0; i < Z; ++i)
cin >> zz[i];
sort(all(zz), greater<long long>());
vector<long long> res;
for (int i = 0; i < X; ++i) {
for (int j = 0; j < Y; ++j) {
for (int k = 0; k < Z; ++k) {
if ((i + 1) * (j + 1) * (k + 1) > K)
break;
res.push_back(xx[i] + yy[j] + zz[k]);
}
}
}
sort(all(res), greater<long long>());
for (int i = 0; i < K; ++i)
cout << res[i] << "\n";
return 0;
}
| replace | 22 | 23 | 22 | 23 | 0 | |
p03078 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = (a); i < int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))
using namespace std;
using i32 = int;
using i64 = long long;
using f64 = double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf64 = vector<f64>;
using vstr = vector<string>;
template <typename T, typename S> void amax(T &x, S y) {
if (x < y)
x = y;
}
template <typename T, typename S> void amin(T &x, S y) {
if (y < x)
x = y;
}
class cake {
public:
i64 sum;
i32 a, b, c;
bool operator<(const cake &that) const {
if (sum == that.sum) {
if (a == that.a) {
if (b == that.b) {
return c < that.c;
} else {
return b < that.b;
}
} else {
return a < that.a;
}
} else {
return sum < that.sum;
}
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(16);
i32 x, y, z, k;
cin >> x >> y >> z >> k;
vi64 a(x), b(y), c(z);
rep(i, x) cin >> a[i];
rep(i, y) cin >> b[i];
rep(i, z) cin >> c[i];
sort(all(a), greater<i64>());
sort(all(b), greater<i64>());
sort(all(c), greater<i64>());
priority_queue<cake> que;
set<cake> s;
que.push({a[0] + b[0] + c[0], 0, 0, 0});
rep(_, k) {
auto q = que.top();
que.pop();
if (s.find(q) == s.end()) {
cout << q.sum << endl;
s.insert(q);
} else {
_--;
}
if (q.a < x - 1) {
que.push({a[q.a + 1] + b[q.b] + c[q.c], q.a + 1, q.b, q.c});
}
if (q.b < y - 1) {
que.push({a[q.a] + b[q.b + 1] + c[q.c], q.a, q.b + 1, q.c});
}
if (q.c < z - 1) {
que.push({a[q.a] + b[q.b] + c[q.c + 1], q.a, q.b, q.c + 1});
}
}
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = (a); i < int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))
using namespace std;
using i32 = int;
using i64 = long long;
using f64 = double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf64 = vector<f64>;
using vstr = vector<string>;
template <typename T, typename S> void amax(T &x, S y) {
if (x < y)
x = y;
}
template <typename T, typename S> void amin(T &x, S y) {
if (y < x)
x = y;
}
class cake {
public:
i64 sum;
i32 a, b, c;
bool operator<(const cake &that) const {
if (sum == that.sum) {
if (a == that.a) {
if (b == that.b) {
return c < that.c;
} else {
return b < that.b;
}
} else {
return a < that.a;
}
} else {
return sum < that.sum;
}
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(16);
i32 x, y, z, k;
cin >> x >> y >> z >> k;
vi64 a(x), b(y), c(z);
rep(i, x) cin >> a[i];
rep(i, y) cin >> b[i];
rep(i, z) cin >> c[i];
sort(all(a), greater<i64>());
sort(all(b), greater<i64>());
sort(all(c), greater<i64>());
priority_queue<cake> que;
set<cake> s;
que.push({a[0] + b[0] + c[0], 0, 0, 0});
rep(_, k) {
auto q = que.top();
que.pop();
if (s.find(q) == s.end()) {
cout << q.sum << endl;
s.insert(q);
} else {
_--;
continue;
}
if (q.a < x - 1) {
que.push({a[q.a + 1] + b[q.b] + c[q.c], q.a + 1, q.b, q.c});
}
if (q.b < y - 1) {
que.push({a[q.a] + b[q.b + 1] + c[q.c], q.a, q.b + 1, q.c});
}
if (q.c < z - 1) {
que.push({a[q.a] + b[q.b] + c[q.c + 1], q.a, q.b, q.c + 1});
}
}
return 0;
}
| insert | 73 | 73 | 73 | 74 | TLE | |
p03078 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
//**関数リスト**//
int ctoi(char c) {
switch (c) {
case '0':
return 0;
case '1':
return 1;
case '2':
return 2;
case '3':
return 3;
case '4':
return 4;
case '5':
return 5;
case '6':
return 6;
case '7':
return 7;
case '8':
return 8;
case '9':
return 9;
default:
return 0;
}
}
bool pairCompare(const pll firstElof, pll secondElof) {
return firstElof.first > secondElof.first;
}
ll nod(ll F) {
ll keta = 1;
while (F / 10 > 0) {
keta++;
F /= 10;
}
return keta;
}
ll gcd(ll x, ll y) {
ll r;
if (x < y) {
swap(x, y);
}
while (y > 0) {
r = x % y;
x = y;
y = r;
}
return x;
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }
ll isPrime(ll x) {
ll i;
if (x < 2) {
return 0;
} else if (x == 2) {
return 1;
} else if (x % 2 == 0) {
return 0;
} else {
for (i = 3; i * i <= x; i += 2) {
if (x % i == 0) {
return 0;
}
}
return 1;
}
}
void eratos(vl isPrime) {
//(注)isPrimeのサイズはN+1にする!実際にはmain内に配置して使用
ll i, j;
for (i = 0; i < isPrime.size(); i++) {
isPrime[i] = 1;
}
isPrime[0] = 0;
isPrime[1] = 0;
for (i = 2; i * i <= isPrime.size() - 1; i++) {
if (isPrime[i] == 1) {
j = i * 2;
while (j <= isPrime.size() - 1) {
isPrime[j] = 0;
j = j + i;
}
}
}
}
ll modinv(ll a, ll m) {
ll b = m, u = 1, v = 0;
while (b) {
ll t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
ll alphabet(char C) {
ll b = 0;
ll key = 0;
if (C == 'a') {
return b;
}
b++;
if (C == 'b') {
return b;
}
b++;
if (C == 'c') {
return b;
}
b++;
if (C == 'd') {
return b;
}
b++;
if (C == 'e') {
return b;
}
b++;
if (C == 'f') {
return b;
}
b++;
if (C == 'g') {
return b;
}
b++;
if (C == 'h') {
return b;
}
b++;
if (C == 'i') {
return b;
}
b++;
if (C == 'j') {
return b;
}
b++;
if (C == 'k') {
return b;
}
b++;
if (C == 'l') {
return b;
}
b++;
if (C == 'm') {
return b;
}
b++;
if (C == 'n') {
return b;
}
b++;
if (C == 'o') {
return b;
}
b++;
if (C == 'p') {
return b;
}
b++;
if (C == 'q') {
return b;
}
b++;
if (C == 'r') {
return b;
}
b++;
if (C == 's') {
return b;
}
b++;
if (C == 't') {
return b;
}
b++;
if (C == 'u') {
return b;
}
b++;
if (C == 'v') {
return b;
}
b++;
if (C == 'w') {
return b;
}
b++;
if (C == 'x') {
return b;
}
b++;
if (C == 'y') {
return b;
}
b++;
if (C == 'z') {
return b;
}
return -1;
}
void bitSearch(ll n) {
// 実際にはコピーして中身を改変して使う
ll i, j;
for (i = 0; i < pow(2, n); i++) {
ll p = i;
for (j = 0; j < n; j++) {
cout << p % 2;
p /= 2;
}
cout << endl;
}
}
void dfsx(ll now, ll C) {
stack<ll> S;
S.push(now);
// color[now] = C;
// while (!S.empty()) {
ll u = S.top();
S.pop();
// for (ll i = 0; i < road[u].size(); i++) {
// ll v = road[u][i];
// if (color[v] == 0) {
// dfs(v, C);
//}
//}
//}
}
void bfs(ll now) {
// 中身は毎回書き換えて使用
queue<ll> Q;
Q.push(now);
ll u;
while (!Q.empty()) {
u = Q.front();
Q.pop();
// ll v=;
// Q.push(v);
}
}
void dijkstra(ll s) {
priority_queue<pll> PQ;
// vl D(N), color(N);
// for (i = 0; i < N; i++) {
// D[i] = INF;
// color[i] = 0;
// }
// D[s] = 0;
PQ.push(make_pair(0, s));
// color[0] = 1;
ll q = -1;
while (!PQ.empty()) {
pll f = PQ.top();
PQ.pop();
ll u = f.second;
// color[u] = 2;
// if (D[u] < f.first * q) {
// continue;
// }
// for (j = 0; j < path[u].size(); j++) {
// ll v = path[u][j].first;
// if (color[v] == 2) {
// continue;
// }
// if (D[v] > D[u] + path[u][j].second) {
// D[v] = D[u] + path[u][j].second;
// color[v] = 1;
// PQ.push(make_pair(D[v] * q, v));
// }
//}
}
// cout << (D[N - 1] == INF ? -1 : D[N - 1]);
}
//**定義場所**//
ll i, j, k, l, m, n, N, M, K, H, W, L;
string S, T;
ll MOD = 1000000007;
ll ans = 0;
ll INF = 9999999999999999;
//***********//
int main() {
ll X, Y, Z;
cin >> X >> Y >> Z >> K;
vl A(X), B(Y), C(Z);
for (i = 0; i < X; i++) {
cin >> A[i];
}
sort(A.begin(), A.end());
reverse(A.begin(), A.end());
for (i = 0; i < Y; i++) {
cin >> B[i];
}
sort(B.begin(), B.end());
reverse(B.begin(), B.end());
for (i = 0; i < Z; i++) {
cin >> C[i];
}
sort(C.begin(), C.end());
reverse(C.begin(), C.end());
vl YZ;
for (i = 0; i < Y; i++) {
for (j = 0; j < Z; j++) {
YZ.push_back(B[i] + C[j]);
}
sort(YZ.begin(), YZ.end());
reverse(YZ.begin(), YZ.end());
}
vl XYZ;
for (i = 0; i < X; i++) {
for (j = 0; j < min(K, Y * Z); j++) {
XYZ.push_back(A[i] + YZ[j]);
}
}
sort(XYZ.begin(), XYZ.end());
reverse(XYZ.begin(), XYZ.end());
for (i = 0; i < K; i++) {
cout << XYZ[i] << endl;
}
} | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
//**関数リスト**//
int ctoi(char c) {
switch (c) {
case '0':
return 0;
case '1':
return 1;
case '2':
return 2;
case '3':
return 3;
case '4':
return 4;
case '5':
return 5;
case '6':
return 6;
case '7':
return 7;
case '8':
return 8;
case '9':
return 9;
default:
return 0;
}
}
bool pairCompare(const pll firstElof, pll secondElof) {
return firstElof.first > secondElof.first;
}
ll nod(ll F) {
ll keta = 1;
while (F / 10 > 0) {
keta++;
F /= 10;
}
return keta;
}
ll gcd(ll x, ll y) {
ll r;
if (x < y) {
swap(x, y);
}
while (y > 0) {
r = x % y;
x = y;
y = r;
}
return x;
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }
ll isPrime(ll x) {
ll i;
if (x < 2) {
return 0;
} else if (x == 2) {
return 1;
} else if (x % 2 == 0) {
return 0;
} else {
for (i = 3; i * i <= x; i += 2) {
if (x % i == 0) {
return 0;
}
}
return 1;
}
}
void eratos(vl isPrime) {
//(注)isPrimeのサイズはN+1にする!実際にはmain内に配置して使用
ll i, j;
for (i = 0; i < isPrime.size(); i++) {
isPrime[i] = 1;
}
isPrime[0] = 0;
isPrime[1] = 0;
for (i = 2; i * i <= isPrime.size() - 1; i++) {
if (isPrime[i] == 1) {
j = i * 2;
while (j <= isPrime.size() - 1) {
isPrime[j] = 0;
j = j + i;
}
}
}
}
ll modinv(ll a, ll m) {
ll b = m, u = 1, v = 0;
while (b) {
ll t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
ll alphabet(char C) {
ll b = 0;
ll key = 0;
if (C == 'a') {
return b;
}
b++;
if (C == 'b') {
return b;
}
b++;
if (C == 'c') {
return b;
}
b++;
if (C == 'd') {
return b;
}
b++;
if (C == 'e') {
return b;
}
b++;
if (C == 'f') {
return b;
}
b++;
if (C == 'g') {
return b;
}
b++;
if (C == 'h') {
return b;
}
b++;
if (C == 'i') {
return b;
}
b++;
if (C == 'j') {
return b;
}
b++;
if (C == 'k') {
return b;
}
b++;
if (C == 'l') {
return b;
}
b++;
if (C == 'm') {
return b;
}
b++;
if (C == 'n') {
return b;
}
b++;
if (C == 'o') {
return b;
}
b++;
if (C == 'p') {
return b;
}
b++;
if (C == 'q') {
return b;
}
b++;
if (C == 'r') {
return b;
}
b++;
if (C == 's') {
return b;
}
b++;
if (C == 't') {
return b;
}
b++;
if (C == 'u') {
return b;
}
b++;
if (C == 'v') {
return b;
}
b++;
if (C == 'w') {
return b;
}
b++;
if (C == 'x') {
return b;
}
b++;
if (C == 'y') {
return b;
}
b++;
if (C == 'z') {
return b;
}
return -1;
}
void bitSearch(ll n) {
// 実際にはコピーして中身を改変して使う
ll i, j;
for (i = 0; i < pow(2, n); i++) {
ll p = i;
for (j = 0; j < n; j++) {
cout << p % 2;
p /= 2;
}
cout << endl;
}
}
void dfsx(ll now, ll C) {
stack<ll> S;
S.push(now);
// color[now] = C;
// while (!S.empty()) {
ll u = S.top();
S.pop();
// for (ll i = 0; i < road[u].size(); i++) {
// ll v = road[u][i];
// if (color[v] == 0) {
// dfs(v, C);
//}
//}
//}
}
void bfs(ll now) {
// 中身は毎回書き換えて使用
queue<ll> Q;
Q.push(now);
ll u;
while (!Q.empty()) {
u = Q.front();
Q.pop();
// ll v=;
// Q.push(v);
}
}
void dijkstra(ll s) {
priority_queue<pll> PQ;
// vl D(N), color(N);
// for (i = 0; i < N; i++) {
// D[i] = INF;
// color[i] = 0;
// }
// D[s] = 0;
PQ.push(make_pair(0, s));
// color[0] = 1;
ll q = -1;
while (!PQ.empty()) {
pll f = PQ.top();
PQ.pop();
ll u = f.second;
// color[u] = 2;
// if (D[u] < f.first * q) {
// continue;
// }
// for (j = 0; j < path[u].size(); j++) {
// ll v = path[u][j].first;
// if (color[v] == 2) {
// continue;
// }
// if (D[v] > D[u] + path[u][j].second) {
// D[v] = D[u] + path[u][j].second;
// color[v] = 1;
// PQ.push(make_pair(D[v] * q, v));
// }
//}
}
// cout << (D[N - 1] == INF ? -1 : D[N - 1]);
}
//**定義場所**//
ll i, j, k, l, m, n, N, M, K, H, W, L;
string S, T;
ll MOD = 1000000007;
ll ans = 0;
ll INF = 9999999999999999;
//***********//
int main() {
ll X, Y, Z;
cin >> X >> Y >> Z >> K;
vl A(X), B(Y), C(Z);
for (i = 0; i < X; i++) {
cin >> A[i];
}
sort(A.begin(), A.end());
reverse(A.begin(), A.end());
for (i = 0; i < Y; i++) {
cin >> B[i];
}
sort(B.begin(), B.end());
reverse(B.begin(), B.end());
for (i = 0; i < Z; i++) {
cin >> C[i];
}
sort(C.begin(), C.end());
reverse(C.begin(), C.end());
vl YZ;
for (i = 0; i < Y; i++) {
for (j = 0; j < Z; j++) {
YZ.push_back(B[i] + C[j]);
}
}
sort(YZ.begin(), YZ.end());
reverse(YZ.begin(), YZ.end());
vl XYZ;
for (i = 0; i < X; i++) {
for (j = 0; j < min(K, Y * Z); j++) {
XYZ.push_back(A[i] + YZ[j]);
}
}
sort(XYZ.begin(), XYZ.end());
reverse(XYZ.begin(), XYZ.end());
for (i = 0; i < K; i++) {
cout << XYZ[i] << endl;
}
} | replace | 328 | 331 | 328 | 331 | TLE | |
p03078 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(), (c).end())
#define SZ(x) ((int)(x).size())
// vvintを作る マクロで #define vvint(N,M) vector<vector<int>>
int MIN(int a, int b) { return a < b ? a : b; }
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll xyz[3], K;
cin >> xyz[0] >> xyz[1] >> xyz[2] >> K;
vector<ll> A(xyz[0], 0), B(xyz[1], 0), C(xyz[2], 0);
ll tmp;
for (int i = 0; i < xyz[0]; i++) {
cin >> A[i];
}
for (int i = 0; i < xyz[1]; i++) {
cin >> B[i];
}
for (int i = 0; i < xyz[2]; i++) {
cin >> C[i];
}
vector<ll> ans(K), AB(xyz[0] * xyz[1]);
ll wa = 0;
for (int i = 0; i < xyz[0]; i++) {
for (int j = 0; j < xyz[1]; j++) {
AB[wa] = A[i] + B[j];
wa++;
}
}
VSORT(AB);
reverse(ALL(AB));
wa = 0;
for (int i = 0; i < MIN(K, xyz[0] * xyz[1]); i++) {
for (int j = 0; j < xyz[2]; j++) {
ans[wa] = AB[i] + C[j];
wa++;
}
}
VSORT(ans);
reverse(ALL(ans));
for (int i = 0; i < K; i++) {
cout << ans[i] << endl;
}
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(), (c).end())
#define SZ(x) ((int)(x).size())
// vvintを作る マクロで #define vvint(N,M) vector<vector<int>>
int MIN(int a, int b) { return a < b ? a : b; }
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll xyz[3], K;
cin >> xyz[0] >> xyz[1] >> xyz[2] >> K;
vector<ll> A(xyz[0], 0), B(xyz[1], 0), C(xyz[2], 0);
ll tmp;
for (int i = 0; i < xyz[0]; i++) {
cin >> A[i];
}
for (int i = 0; i < xyz[1]; i++) {
cin >> B[i];
}
for (int i = 0; i < xyz[2]; i++) {
cin >> C[i];
}
vector<ll> ans(MIN(K, xyz[0] * xyz[1]) * xyz[2], 0), AB(xyz[0] * xyz[1], 0);
ll wa = 0;
for (int i = 0; i < xyz[0]; i++) {
for (int j = 0; j < xyz[1]; j++) {
AB[wa] = A[i] + B[j];
wa++;
}
}
VSORT(AB);
reverse(ALL(AB));
wa = 0;
for (int i = 0; i < MIN(K, xyz[0] * xyz[1]); i++) {
for (int j = 0; j < xyz[2]; j++) {
ans[wa] = AB[i] + C[j];
wa++;
}
}
VSORT(ans);
reverse(ALL(ans));
for (int i = 0; i < K; i++) {
cout << ans[i] << endl;
}
return 0;
} | replace | 46 | 47 | 46 | 47 | 0 | |
p03078 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <stdio.h>
#include <vector>
using namespace std;
#define int long long
#define double long double
#define rep(s, i, n) for (int i = s; i < n; i++)
#define c(n) cout << n << endl;
#define ic(n) \
int n; \
cin >> n;
#define sc(s) \
string s; \
cin >> s;
#define mod 1000000007
#define inf 1000000000000000007
#define f first
#define s second
#define mini(c, a, b) *min_element(c + a, c + b)
#define maxi(c, a, b) *max_element(c + a, c + b)
#define P pair<int, int>
// printf("%.12Lf\n",);
int keta(int x) {
rep(0, i, 30) {
if (x < 10) {
return i + 1;
}
x = x / 10;
}
}
int gcd(int x, int y) {
int aa = x, bb = y;
rep(0, i, 1000) {
aa = aa % bb;
if (aa == 0) {
return bb;
}
bb = bb % aa;
if (bb == 0) {
return aa;
}
}
}
int lcm(int x, int y) {
int aa = x, bb = y;
rep(0, i, 1000) {
aa = aa % bb;
if (aa == 0) {
return x / bb * y;
}
bb = bb % aa;
if (bb == 0) {
return x / aa * y;
}
}
}
bool p(int x) {
if (x == 1)
return false;
rep(2, i, sqrt(x) + 1) {
if (x % i == 0 && x != i) {
return false;
}
}
return true;
}
int max(int a, int b) {
if (a >= b)
return a;
else
return b;
}
int min(int a, int b) {
if (a >= b)
return b;
else
return a;
}
int n2[41];
int nis[41];
int nia[41];
int mody[41];
int nn;
int com(int n, int y) {
int ni = 1;
for (int i = 0; i < 41; i++) {
n2[i] = ni;
ni *= 2;
}
int bunsi = 1, bunbo = 1;
rep(0, i, y) bunsi = (bunsi * (n - i)) % mod;
rep(0, i, y) bunbo = (bunbo * (i + 1)) % mod;
mody[0] = bunbo;
rep(1, i, 41) {
bunbo = (bunbo * bunbo) % mod;
mody[i] = bunbo;
}
rep(0, i, 41) nis[i] = 0;
nn = mod - 2;
for (int i = 40; i >= 0; i -= 1) {
if (nn > n2[i]) {
nis[i]++;
nn -= n2[i];
}
}
nis[0]++;
rep(0, i, 41) {
if (nis[i] == 1) {
bunsi = (bunsi * mody[i]) % mod;
}
}
return bunsi;
}
int gyakugen(int n, int y) {
int ni = 1;
for (int i = 0; i < 41; i++) {
n2[i] = ni;
ni *= 2;
}
mody[0] = y;
rep(1, i, 41) {
y = (y * y) % mod;
mody[i] = y;
}
rep(0, i, 41) nis[i] = 0;
nn = mod - 2;
for (int i = 40; i >= 0; i -= 1) {
if (nn > n2[i]) {
nis[i]++;
nn -= n2[i];
}
}
nis[0]++;
rep(0, i, 41) {
if (nis[i] == 1) {
n = (n * mody[i]) % mod;
}
}
return n;
}
int yakuwa(int n) {
int sum = 0;
rep(1, i, sqrt(n + 1)) {
if (n % i == 0)
sum += i + n / i;
if (i * i == n)
sum -= i;
}
return sum;
}
bool integer(double n) {
if (n == long(n))
return true;
else
return false;
}
int poow(int y, int n) {
n -= 1;
int ni = 1;
for (int i = 0; i < 41; i++) {
n2[i] = ni;
ni *= 2;
}
int yy = y;
mody[0] = yy;
rep(1, i, 41) {
yy = (yy * yy) % mod;
mody[i] = yy;
}
rep(0, i, 41) nis[i] = 0;
nn = n;
for (int i = 40; i >= 0; i -= 1) {
if (nn >= n2[i]) {
nis[i]++;
nn -= n2[i];
}
}
rep(0, i, 41) {
if (nis[i] == 1) {
y = (y * mody[i]) % mod;
}
}
return y;
}
int ketawa(int x, int sinsuu) {
int sum = 0;
rep(0, i, 100) sum += (x % poow(sinsuu, i + 1)) / (poow(sinsuu, i));
return sum;
}
int sankaku(int a) { return a * (a + 1) / 2; }
bool search(int x) {
int n;
int a[n];
int l = 0, r = n;
while (r - l >= 1) {
int i = (l + r) / 2;
if (a[i] == x)
return true;
else if (a[i] < x)
l = i + 1;
else
r = i;
}
return false;
}
using Graph = vector<vector<int>>;
/*int oya[114514];
int depth[114514];
void dfs(const Graph &G, int v, int p, int d) {
depth[v] = d;
oya[v]=p;
for (auto nv : G[v]) {
if (nv == p) continue; // nv が親 p だったらダメ
dfs(G, nv, v, d+1); // d を 1 増やして子ノードへ
}
}*/
/*int H=10,W=10;
char field[10][10];
char memo[10][10];
void dfs(int h, int w) {
memo[h][w] = 'x';
// 八方向を探索
for (int dh = -1; dh <= 1; ++dh) {
for (int dw = -1; dw <= 1; ++dw) {
if(abs(0-dh)+abs(0-dw)==2)continue;
int nh = h + dh, nw = w + dw;
// 場外アウトしたり、0 だったりはスルー
if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
if (memo[nh][nw] == 'x') continue;
// 再帰的に探索
dfs(nh, nw);
}
}
}*/
int XOR(int a, int b) {
int ni = 1;
rep(0, i, 41) {
n2[i] = ni;
ni *= 2;
}
rep(0, i, 41) nis[i] = 0;
for (int i = 40; i >= 0; i -= 1) {
if (a >= n2[i]) {
nis[i]++;
a -= n2[i];
}
if (b >= n2[i]) {
nis[i]++;
b -= n2[i];
}
}
int sum = 0;
rep(0, i, 41) sum += (nis[i] % 2 * n2[i]);
return sum;
}
// int ma[1024577][21];
// for(int bit=0;bit<(1<<n);bit++)rep(0,i,n)if(bit&(1<<i))ma[bit][i]=1;
int a[1145], b[1145], c[1145];
int ab[1145810];
int abmax[3145];
int bc[1145810];
signed main() {
ic(x) ic(y) ic(z) ic(n) rep(0, i, x) cin >> a[i];
rep(0, i, y) cin >> b[i];
rep(0, i, z) cin >> c[i];
rep(0, i, x) rep(0, j, y) ab[i * y + j] = a[i] + b[j];
sort(ab, ab + x * y);
reverse(ab, ab + x * y);
rep(0, i, n) abmax[i] = ab[i];
rep(0, i, n) rep(0, j, z) bc[i * z + j] = abmax[i] + c[j];
sort(bc, bc + n * z);
reverse(bc, bc + n * z);
rep(0, i, n) c(bc[i])
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <stdio.h>
#include <vector>
using namespace std;
#define int long long
#define double long double
#define rep(s, i, n) for (int i = s; i < n; i++)
#define c(n) cout << n << endl;
#define ic(n) \
int n; \
cin >> n;
#define sc(s) \
string s; \
cin >> s;
#define mod 1000000007
#define inf 1000000000000000007
#define f first
#define s second
#define mini(c, a, b) *min_element(c + a, c + b)
#define maxi(c, a, b) *max_element(c + a, c + b)
#define P pair<int, int>
// printf("%.12Lf\n",);
int keta(int x) {
rep(0, i, 30) {
if (x < 10) {
return i + 1;
}
x = x / 10;
}
}
int gcd(int x, int y) {
int aa = x, bb = y;
rep(0, i, 1000) {
aa = aa % bb;
if (aa == 0) {
return bb;
}
bb = bb % aa;
if (bb == 0) {
return aa;
}
}
}
int lcm(int x, int y) {
int aa = x, bb = y;
rep(0, i, 1000) {
aa = aa % bb;
if (aa == 0) {
return x / bb * y;
}
bb = bb % aa;
if (bb == 0) {
return x / aa * y;
}
}
}
bool p(int x) {
if (x == 1)
return false;
rep(2, i, sqrt(x) + 1) {
if (x % i == 0 && x != i) {
return false;
}
}
return true;
}
int max(int a, int b) {
if (a >= b)
return a;
else
return b;
}
int min(int a, int b) {
if (a >= b)
return b;
else
return a;
}
int n2[41];
int nis[41];
int nia[41];
int mody[41];
int nn;
int com(int n, int y) {
int ni = 1;
for (int i = 0; i < 41; i++) {
n2[i] = ni;
ni *= 2;
}
int bunsi = 1, bunbo = 1;
rep(0, i, y) bunsi = (bunsi * (n - i)) % mod;
rep(0, i, y) bunbo = (bunbo * (i + 1)) % mod;
mody[0] = bunbo;
rep(1, i, 41) {
bunbo = (bunbo * bunbo) % mod;
mody[i] = bunbo;
}
rep(0, i, 41) nis[i] = 0;
nn = mod - 2;
for (int i = 40; i >= 0; i -= 1) {
if (nn > n2[i]) {
nis[i]++;
nn -= n2[i];
}
}
nis[0]++;
rep(0, i, 41) {
if (nis[i] == 1) {
bunsi = (bunsi * mody[i]) % mod;
}
}
return bunsi;
}
int gyakugen(int n, int y) {
int ni = 1;
for (int i = 0; i < 41; i++) {
n2[i] = ni;
ni *= 2;
}
mody[0] = y;
rep(1, i, 41) {
y = (y * y) % mod;
mody[i] = y;
}
rep(0, i, 41) nis[i] = 0;
nn = mod - 2;
for (int i = 40; i >= 0; i -= 1) {
if (nn > n2[i]) {
nis[i]++;
nn -= n2[i];
}
}
nis[0]++;
rep(0, i, 41) {
if (nis[i] == 1) {
n = (n * mody[i]) % mod;
}
}
return n;
}
int yakuwa(int n) {
int sum = 0;
rep(1, i, sqrt(n + 1)) {
if (n % i == 0)
sum += i + n / i;
if (i * i == n)
sum -= i;
}
return sum;
}
bool integer(double n) {
if (n == long(n))
return true;
else
return false;
}
int poow(int y, int n) {
n -= 1;
int ni = 1;
for (int i = 0; i < 41; i++) {
n2[i] = ni;
ni *= 2;
}
int yy = y;
mody[0] = yy;
rep(1, i, 41) {
yy = (yy * yy) % mod;
mody[i] = yy;
}
rep(0, i, 41) nis[i] = 0;
nn = n;
for (int i = 40; i >= 0; i -= 1) {
if (nn >= n2[i]) {
nis[i]++;
nn -= n2[i];
}
}
rep(0, i, 41) {
if (nis[i] == 1) {
y = (y * mody[i]) % mod;
}
}
return y;
}
int ketawa(int x, int sinsuu) {
int sum = 0;
rep(0, i, 100) sum += (x % poow(sinsuu, i + 1)) / (poow(sinsuu, i));
return sum;
}
int sankaku(int a) { return a * (a + 1) / 2; }
bool search(int x) {
int n;
int a[n];
int l = 0, r = n;
while (r - l >= 1) {
int i = (l + r) / 2;
if (a[i] == x)
return true;
else if (a[i] < x)
l = i + 1;
else
r = i;
}
return false;
}
using Graph = vector<vector<int>>;
/*int oya[114514];
int depth[114514];
void dfs(const Graph &G, int v, int p, int d) {
depth[v] = d;
oya[v]=p;
for (auto nv : G[v]) {
if (nv == p) continue; // nv が親 p だったらダメ
dfs(G, nv, v, d+1); // d を 1 増やして子ノードへ
}
}*/
/*int H=10,W=10;
char field[10][10];
char memo[10][10];
void dfs(int h, int w) {
memo[h][w] = 'x';
// 八方向を探索
for (int dh = -1; dh <= 1; ++dh) {
for (int dw = -1; dw <= 1; ++dw) {
if(abs(0-dh)+abs(0-dw)==2)continue;
int nh = h + dh, nw = w + dw;
// 場外アウトしたり、0 だったりはスルー
if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
if (memo[nh][nw] == 'x') continue;
// 再帰的に探索
dfs(nh, nw);
}
}
}*/
int XOR(int a, int b) {
int ni = 1;
rep(0, i, 41) {
n2[i] = ni;
ni *= 2;
}
rep(0, i, 41) nis[i] = 0;
for (int i = 40; i >= 0; i -= 1) {
if (a >= n2[i]) {
nis[i]++;
a -= n2[i];
}
if (b >= n2[i]) {
nis[i]++;
b -= n2[i];
}
}
int sum = 0;
rep(0, i, 41) sum += (nis[i] % 2 * n2[i]);
return sum;
}
// int ma[1024577][21];
// for(int bit=0;bit<(1<<n);bit++)rep(0,i,n)if(bit&(1<<i))ma[bit][i]=1;
int a[1145], b[1145], c[1145];
int ab[1145810];
int abmax[3145];
int bc[3145810];
signed main() {
ic(x) ic(y) ic(z) ic(n) rep(0, i, x) cin >> a[i];
rep(0, i, y) cin >> b[i];
rep(0, i, z) cin >> c[i];
rep(0, i, x) rep(0, j, y) ab[i * y + j] = a[i] + b[j];
sort(ab, ab + x * y);
reverse(ab, ab + x * y);
rep(0, i, n) abmax[i] = ab[i];
rep(0, i, n) rep(0, j, z) bc[i * z + j] = abmax[i] + c[j];
sort(bc, bc + n * z);
reverse(bc, bc + n * z);
rep(0, i, n) c(bc[i])
} | replace | 267 | 268 | 267 | 268 | 0 | |
p03078 | C++ | Memory Limit Exceeded | #include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, s, e) for (int i = s; i < e; i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define reprs(i, s, e) for (int i = s - 1; i >= s; i--)
int main() {
int x, y, z, k;
cin >> x >> y >> z >> k;
ll a[x], b[y], c[z];
priority_queue<ll> pq;
rep(i, x) { cin >> a[i]; }
rep(i, y) { cin >> b[i]; }
rep(i, z) { cin >> c[i]; }
sort(a, a + x, greater<ll>());
sort(b, b + y, greater<ll>());
sort(c, c + z, greater<ll>());
rep(ia, min(x, 500)) {
rep(ib, min(y, 500)) {
rep(ic, min(z, 500)) { pq.push(a[ia] + b[ib] + c[ic]); }
}
}
rep(i, k) {
cout << pq.top() << endl;
pq.pop();
}
return 0;
} | #include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, s, e) for (int i = s; i < e; i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define reprs(i, s, e) for (int i = s - 1; i >= s; i--)
int main() {
int x, y, z, k;
cin >> x >> y >> z >> k;
ll a[x], b[y], c[z];
priority_queue<ll> pq;
rep(i, x) { cin >> a[i]; }
rep(i, y) { cin >> b[i]; }
rep(i, z) { cin >> c[i]; }
sort(a, a + x, greater<ll>());
sort(b, b + y, greater<ll>());
sort(c, c + z, greater<ll>());
vector<ll> vab;
rep(ia, x) {
rep(ib, y) { vab.push_back(a[ia] + b[ib]); }
}
sort(vab.begin(), vab.end(), greater<ll>());
rep(iab, min(k, (int)vab.size())) {
rep(ic, z) { pq.push(vab[iab] + c[ic]); }
}
rep(i, k) {
cout << pq.top() << endl;
pq.pop();
}
return 0;
} | replace | 36 | 40 | 36 | 45 | MLE | |
p03078 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
// Your code here!
int x, y, z, k;
cin >> x >> y >> z >> k;
vector<long long> vecx(x, 0), vecy(y, 0), vecz(z, 0), vectemp(x * y, 0),
ans(max(x * y, 3000) * z, 0);
for (int i = 0; i < x; i++) {
cin >> vecx[i];
}
for (int i = 0; i < y; i++) {
cin >> vecy[i];
}
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
vectemp[i + x * j] = vecx[i] + vecy[j];
}
}
sort(vectemp.rbegin(), vectemp.rend());
for (int i = 0; i < y; i++) {
cin >> vecz[i];
}
for (int i = 0; i < min(x * y, 3000); i++) {
for (int j = 0; j < z; j++) {
ans[i + min(x * y, 3000) * j] = vectemp[i] + vecz[j];
}
}
sort(ans.rbegin(), ans.rend());
for (int i = 0; i < k; i++) {
cout << ans[i] << endl;
}
}
| #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
// Your code here!
int x, y, z, k;
cin >> x >> y >> z >> k;
vector<long long> vecx(x, 0), vecy(y, 0), vecz(z, 0), vectemp(x * y, 0),
ans(min(x * y, 3000) * z, 0);
for (int i = 0; i < x; i++) {
cin >> vecx[i];
}
for (int i = 0; i < y; i++) {
cin >> vecy[i];
}
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
vectemp[i + x * j] = vecx[i] + vecy[j];
}
}
sort(vectemp.rbegin(), vectemp.rend());
for (int i = 0; i < y; i++) {
cin >> vecz[i];
}
for (int i = 0; i < min(x * y, 3000); i++) {
for (int j = 0; j < z; j++) {
ans[i + min(x * y, 3000) * j] = vectemp[i] + vecz[j];
}
}
sort(ans.rbegin(), ans.rend());
for (int i = 0; i < k; i++) {
cout << ans[i] << endl;
}
}
| replace | 10 | 11 | 10 | 11 | 0 | |
p03078 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
long long x[1005], y[1005], z[1005], xyz[3010], X, Y, Z, K;
bool cmp(const long long &x, const long long &y) { return x > y; }
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> X >> Y >> Z >> K;
for (int i = 1; i <= X; i++)
cin >> x[i];
for (int i = 1; i <= Y; i++)
cin >> y[i];
for (int i = 1; i <= Z; i++)
cin >> z[i];
sort(x + 1, x + X + 1, cmp);
sort(y + 1, y + Y + 1, cmp);
sort(z + 1, z + Z + 1, cmp);
int cnt = 0;
for (int i = 1; i <= X; i++)
for (int j = 1; j <= Y; j++)
for (int k = 1; k <= Z; k++) {
if (i * j * k > K)
break;
cnt++;
xyz[cnt] = x[i] + y[j] + z[k];
}
sort(xyz + 1, xyz + cnt + 1, cmp);
for (int l = 1; l <= K; l++)
cout << xyz[l] << "\n";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
long long x[1005], y[1005], z[1005], xyz[3000010], X, Y, Z, K;
bool cmp(const long long &x, const long long &y) { return x > y; }
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> X >> Y >> Z >> K;
for (int i = 1; i <= X; i++)
cin >> x[i];
for (int i = 1; i <= Y; i++)
cin >> y[i];
for (int i = 1; i <= Z; i++)
cin >> z[i];
sort(x + 1, x + X + 1, cmp);
sort(y + 1, y + Y + 1, cmp);
sort(z + 1, z + Z + 1, cmp);
int cnt = 0;
for (int i = 1; i <= X; i++)
for (int j = 1; j <= Y; j++)
for (int k = 1; k <= Z; k++) {
if (i * j * k > K)
break;
cnt++;
xyz[cnt] = x[i] + y[j] + z[k];
}
sort(xyz + 1, xyz + cnt + 1, cmp);
for (int l = 1; l <= K; l++)
cout << xyz[l] << "\n";
return 0;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p03078 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <vector>
typedef long long ll;
int X, Y, Z, K;
std::vector<ll> A, B, C;
bool judge(ll P) {
ll rtn = 0;
for (int i = 0; i < X; i++) {
for (int j = 0; j < Y; j++) {
for (int k = 0; k < Z; k++) {
if (A[i] + B[j] + C[k] < P)
break;
rtn++;
if (rtn > K)
return true;
}
}
}
return false;
}
ll binary_search(ll P1, ll P2) {
if (P1 == P2)
return P1;
ll center = std::floor((double)(P1 + P2) / 2);
if (judge(center))
return binary_search(P1, center + 1);
else
return binary_search(center, P2);
}
void sol_4() {
ll boarder =
binary_search(A[0] + B[0] + C[0], A[X - 1] + B[Y - 1] + C[Z - 1]);
std::vector<ll> ABCsum;
for (int i = 0; i < X; i++) {
for (int j = 0; j < Y; j++) {
for (int k = 0; k < Z; k++) {
if (A[i] + B[j] + C[k] < boarder)
break;
ABCsum.push_back(A[i] + B[j] + C[k]);
}
}
}
std::sort(ABCsum.begin(), ABCsum.end(), std::greater<ll>());
for (int i = 0; i < K; i++)
std::cout << ABCsum.at(i) << std::endl;
}
int main(void) {
std::cin >> X >> Y >> Z >> K;
for (int i = 0; i < X; i++) {
ll t_;
std::cin >> t_;
A.push_back(t_);
}
for (int i = 0; i < Y; i++) {
ll t_;
std::cin >> t_;
B.push_back(t_);
}
for (int i = 0; i < Z; i++) {
ll t_;
std::cin >> t_;
C.push_back(t_);
}
std::sort(A.begin(), A.end(), std::greater<ll>());
std::sort(B.begin(), B.end(), std::greater<ll>());
std::sort(C.begin(), C.end(), std::greater<ll>());
sol_4();
return 0;
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <vector>
typedef long long ll;
int X, Y, Z, K;
std::vector<ll> A, B, C;
bool judge(ll P) {
ll rtn = 0;
for (int i = 0; i < X; i++) {
for (int j = 0; j < Y; j++) {
for (int k = 0; k < Z; k++) {
if (A[i] + B[j] + C[k] < P)
break;
rtn++;
if (rtn > K)
return true;
}
}
}
return false;
}
ll binary_search(ll P1, ll P2) {
if (P1 == P2)
return P1;
ll center = std::floor((double)(P1 + P2) / 2);
if (judge(center))
return binary_search(P1, center + 1);
else
return binary_search(center, P2);
}
void sol_4() {
ll boarder =
binary_search(A[0] + B[0] + C[0], A[X - 1] + B[Y - 1] + C[Z - 1]);
std::vector<ll> ABCsum;
for (int i = 0; i < X; i++) {
for (int j = 0; j < Y; j++) {
for (int k = 0; k < Z; k++) {
if (A[i] + B[j] + C[k] < boarder - 1)
break;
ABCsum.push_back(A[i] + B[j] + C[k]);
}
}
}
std::sort(ABCsum.begin(), ABCsum.end(), std::greater<ll>());
for (int i = 0; i < K; i++)
std::cout << ABCsum.at(i) << std::endl;
}
int main(void) {
std::cin >> X >> Y >> Z >> K;
for (int i = 0; i < X; i++) {
ll t_;
std::cin >> t_;
A.push_back(t_);
}
for (int i = 0; i < Y; i++) {
ll t_;
std::cin >> t_;
B.push_back(t_);
}
for (int i = 0; i < Z; i++) {
ll t_;
std::cin >> t_;
C.push_back(t_);
}
std::sort(A.begin(), A.end(), std::greater<ll>());
std::sort(B.begin(), B.end(), std::greater<ll>());
std::sort(C.begin(), C.end(), std::greater<ll>());
sol_4();
return 0;
} | replace | 44 | 45 | 44 | 45 | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.