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
p02726
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int N, X, Y; cin >> N >> X >> Y; vector<int> ans(N, 0); for (int k = 1; k < N; k++) { for (int i = 1; i < N + 1; i++) { for (int j = 1; j < N + 1; j++) { if (k == min(abs(j - i), abs(X - i) + 1 + abs(j - Y)) && i < j) { ans.at(k)++; } } } } for (int k = 1; k < N; k++) { cout << ans.at(k) << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int N, X, Y; cin >> N >> X >> Y; vector<int> ans(N, 0); for (int i = 1; i < N + 1; i++) { for (int j = 1; j < N + 1; j++) { if (i < j) { int k = min(abs(j - i), abs(X - i) + 1 + abs(j - Y)); ans.at(k)++; } } } for (int k = 1; k < N; k++) { cout << ans.at(k) << endl; } }
replace
7
13
7
12
TLE
p02726
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; const int MAX_N = 2000; int n, x, y; void solve() { int d[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i <= j) { d[i][j] = min(abs(i - j), abs(i - (x - 1)) + abs(j - (y - 1)) + 1); } else { d[i][j] = d[j][i]; } } } int ans[n - 1]; for (int i = 1; i <= n - 1; i++) { ans[i - 1] = 0; for (int j = 0; j < n - 1; j++) { for (int k = j + 1; k < n; k++) { if (d[j][k] == i) { ans[i - 1]++; } } } } for (int i = 0; i < n - 1; i++) { cout << ans[i] << endl; } } int main() { cin >> n >> x >> y; solve(); }
#include <bits/stdc++.h> using namespace std; const int MAX_N = 2000; int n, x, y; void solve() { int d[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i <= j) { d[i][j] = min(abs(i - j), abs(i - (x - 1)) + abs(j - (y - 1)) + 1); } else { d[i][j] = d[j][i]; } } } int ans[n - 1]; for (int i = 1; i <= n - 1; i++) { ans[i - 1] = 0; } for (int i = 0; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { ans[d[i][j] - 1]++; } } for (int i = 0; i < n - 1; i++) { cout << ans[i] << endl; } } int main() { cin >> n >> x >> y; solve(); }
replace
21
27
21
25
TLE
p02726
C++
Time Limit Exceeded
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(vec) vec.begin(), vec.end() typedef long long ll; typedef pair<ll, ll> pll; typedef pair<int, int> pii; const ll mod = 1e9 + 7; const int inf = 1 << 30; int n; struct edge { int to, cost; }; typedef pair<int, int> P; const int MAX_V = 2010; vector<edge> G[MAX_V]; int d[MAX_V]; void dijkstra(int s) { priority_queue<P, vector<P>, greater<P>> que; fill(d, d + n, inf); d[s] = 0; que.push(P(0, s)); while (!que.empty()) { P p = que.top(); que.pop(); int v = p.second; if (d[v] < p.first) continue; for (int i = 0; i < G[v].size(); i++) { edge e = G[v][i]; if (d[e.to] > d[v] + e.cost) { d[e.to] = d[v] + e.cost; que.push(P(d[e.to], e.to)); } } } } int main() { int x, y; cin >> n >> x >> y; x--; y--; rep(i, n - 1) { G[i].push_back({i + 1, 1}); G[i + 1].push_back({i, 1}); } G[x].push_back({y, 1}); G[y].push_back({x, 1}); vector<int> ans(n); rep(i, n) { dijkstra(i); rep(j, n) { ans[abs(d[i] - d[j])]++; } } for (int i = 1; i < n; i++) { cout << ans[i] / 2 << endl; } }
// #define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(vec) vec.begin(), vec.end() typedef long long ll; typedef pair<ll, ll> pll; typedef pair<int, int> pii; const ll mod = 1e9 + 7; const int inf = 1 << 30; int n; struct edge { int to, cost; }; typedef pair<int, int> P; const int MAX_V = 2010; vector<edge> G[MAX_V]; int d[MAX_V]; void dijkstra(int s) { priority_queue<P, vector<P>, greater<P>> que; fill(d, d + n, inf); d[s] = 0; que.push(P(0, s)); while (!que.empty()) { P p = que.top(); que.pop(); int v = p.second; if (d[v] < p.first) continue; for (int i = 0; i < G[v].size(); i++) { edge e = G[v][i]; if (d[e.to] > d[v] + e.cost) { d[e.to] = d[v] + e.cost; que.push(P(d[e.to], e.to)); } } } } int main() { int x, y; cin >> n >> x >> y; x--; y--; rep(i, n - 1) { G[i].push_back({i + 1, 1}); G[i + 1].push_back({i, 1}); } G[x].push_back({y, 1}); G[y].push_back({x, 1}); vector<int> ans(n); rep(i, n) { dijkstra(i); rep(j, n) { ans[abs(d[i] - d[j])]++; } } for (int i = 1; i < n; i++) { cout << ans[i] / 2 << endl; } }
replace
0
1
0
1
TLE
p02726
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; #define fi first #define se second #define pb push_back #define int long long #define all(x) (x).begin(), (x).end() using LL = long long; using LD = long double; using pii = pair<int, int>; using vii = vector<pii>; const int INF = 1e18; const int MOD = 1e9 + 7; const int N = 1e3 + 3; struct edge { int to; int len; }; vector<edge> g[N]; vector<int> min_dist(N, INF); void dijkstra(int source) { min_dist[source] = 0; set<pii> S; // S is set of active vertices (min_dist, vertex) S.insert({0, source}); while (!S.empty()) { int curr = S.begin()->se; S.erase(S.begin()); for (auto e : g[curr]) { if (min_dist[e.to] > min_dist[curr] + e.len) { S.erase({min_dist[e.to], e.to}); min_dist[e.to] = min_dist[curr] + e.len; S.insert({min_dist[e.to], e.to}); } } } } int32_t main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, x, y; cin >> n >> x >> y; g[x].pb({y, 1}); g[y].pb({x, 1}); for (int i = 1; i < n; i++) { g[i].pb({i + 1, 1}); g[i + 1].pb({i, 1}); } vector<int> cnt(N, 0); for (int i = 1; i <= n; i++) { fill(all(min_dist), INF); dijkstra(i); for (int i = 1; i <= n; i++) { cnt[min_dist[i]]++; } } for (int i = 1; i < n; i++) { cout << cnt[i] / 2 << "\n"; } }
#include "bits/stdc++.h" using namespace std; #define fi first #define se second #define pb push_back #define int long long #define all(x) (x).begin(), (x).end() using LL = long long; using LD = long double; using pii = pair<int, int>; using vii = vector<pii>; const int INF = 1e18; const int MOD = 1e9 + 7; const int N = 2e3 + 3; struct edge { int to; int len; }; vector<edge> g[N]; vector<int> min_dist(N, INF); void dijkstra(int source) { min_dist[source] = 0; set<pii> S; // S is set of active vertices (min_dist, vertex) S.insert({0, source}); while (!S.empty()) { int curr = S.begin()->se; S.erase(S.begin()); for (auto e : g[curr]) { if (min_dist[e.to] > min_dist[curr] + e.len) { S.erase({min_dist[e.to], e.to}); min_dist[e.to] = min_dist[curr] + e.len; S.insert({min_dist[e.to], e.to}); } } } } int32_t main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, x, y; cin >> n >> x >> y; g[x].pb({y, 1}); g[y].pb({x, 1}); for (int i = 1; i < n; i++) { g[i].pb({i + 1, 1}); g[i + 1].pb({i, 1}); } vector<int> cnt(N, 0); for (int i = 1; i <= n; i++) { fill(all(min_dist), INF); dijkstra(i); for (int i = 1; i <= n; i++) { cnt[min_dist[i]]++; } } for (int i = 1; i < n; i++) { cout << cnt[i] / 2 << "\n"; } }
replace
16
17
16
17
0
p02726
C++
Runtime Error
/* In the name of ALLAH Author : Raashid Anwar */ #include <bits/stdc++.h> using namespace std; #define int int64_t const int M = 1000000007; int ans[1001]; int vis[1001]; vector<int> adj[1001]; void solve(int i) { memset(vis, 0, sizeof(vis)); priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q; int d, u; q.push({int(0), i}); while (!q.empty()) { d = q.top().first; u = q.top().second; q.pop(); if (vis[u]) continue; vis[u] = 1; ans[d]++; for (int v : adj[u]) if (!vis[v]) q.push({d + 1, v}); } return; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); // #ifndef ONLINE_JUDGE // freopen("input.txt","r",stdin); // #endif int n, x, y; cin >> n >> x >> y; adj[x].push_back(y); adj[y].push_back(x); for (int i = 1; i <= n - 1; i++) { adj[i].push_back(i + 1); adj[i + 1].push_back(i); } for (int i = 1; i <= n; i++) solve(i); for (int i = 1; i < n; i++) cout << (ans[i] / 2) << " "; }
/* In the name of ALLAH Author : Raashid Anwar */ #include <bits/stdc++.h> using namespace std; #define int int64_t const int M = 1000000007; int ans[2001]; int vis[2001]; vector<int> adj[2001]; void solve(int i) { memset(vis, 0, sizeof(vis)); priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q; int d, u; q.push({int(0), i}); while (!q.empty()) { d = q.top().first; u = q.top().second; q.pop(); if (vis[u]) continue; vis[u] = 1; ans[d]++; for (int v : adj[u]) if (!vis[v]) q.push({d + 1, v}); } return; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); // #ifndef ONLINE_JUDGE // freopen("input.txt","r",stdin); // #endif int n, x, y; cin >> n >> x >> y; adj[x].push_back(y); adj[y].push_back(x); for (int i = 1; i <= n - 1; i++) { adj[i].push_back(i + 1); adj[i + 1].push_back(i); } for (int i = 1; i <= n; i++) solve(i); for (int i = 1; i < n; i++) cout << (ans[i] / 2) << " "; }
replace
11
14
11
14
0
p02726
C++
Time Limit Exceeded
#include <bits/stdc++.h> #include <iostream> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < n; i++) /* 大文字を小文字に変換 */ char tolower(char c) { return (c + 0x20); } /* 小文字を大文字に変換 */ char toupr(char c) { return (c - 0x20); } // if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A'; /* string s = "abcdefg" s.substr(4) "efg" s.substr(0,3) "abc" s.substr(2,4) "cdef" */ const int INF = pow(10, 4); int main() { int N, X, Y; cin >> N >> X >> Y; int d[N][N]; int dis[N]; // 初期化 rep(i, N) { rep(j, N) { d[i][j] = INF; } } rep(i, N) dis[i] = 0; rep(i, N) { // cout << i << endl; if (i != N - 1) { d[i][i + 1] = 1; d[i + 1][i] = 1; } } d[X - 1][Y - 1] = 1; d[Y - 1][X - 1] = 1; for (int k = 0; k < N; k++) { for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { d[i][j] = min(d[i][j], d[i][k] + d[k][j]); } } } for (int i = 0; i < N; i++) { for (int j = i + 1; j < N; j++) { // if(d[i][j] == 5) cout << i << "," << j << endl; dis[d[i][j]]++; } } rep(i, N) { if (i != 0) printf("%d\n", dis[i]); } }
#include <bits/stdc++.h> #include <iostream> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < n; i++) /* 大文字を小文字に変換 */ char tolower(char c) { return (c + 0x20); } /* 小文字を大文字に変換 */ char toupr(char c) { return (c - 0x20); } // if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A'; /* string s = "abcdefg" s.substr(4) "efg" s.substr(0,3) "abc" s.substr(2,4) "cdef" */ const int INF = pow(10, 4); int main() { int N, X, Y; cin >> N >> X >> Y; int d[N][N]; int dis[N]; // 初期化 rep(i, N) { rep(j, N) { d[i][j] = INF; } } rep(i, N) dis[i] = 0; for (int i = 0; i < N; i++) { for (int j = i + 1; j < N; j++) { d[i][j] = min(abs(j - i), abs(X - 1 - i) + 1 + abs(Y - 1 - j)); } } for (int i = 0; i < N; i++) { for (int j = i + 1; j < N; j++) { // if(d[i][j] == 5) cout << i << "," << j << endl; dis[d[i][j]]++; } } rep(i, N) { if (i != 0) printf("%d\n", dis[i]); } }
replace
32
46
32
35
TLE
p02726
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define mp make_pair #define pb push_back #define first fi #define second se #define MOD 1000000007 #define MAXN 1003 #define endl "\n" #define readln(x) getline(cin, x); typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef map<int, int> mii; typedef map<ll, ll> mll; ll fpow(ll x, ll n, ll mod) { if (n == 0) return 1 % mod; ll u = fpow(x, n / 2, mod); u = (u * u) % mod; if (n % 2 == 1) u = (u * x) % mod; return u; } ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } int N, X, Y; vector<int> adj[MAXN]; int dist[MAXN], freq[MAXN]; bool visited[MAXN]; queue<int> q; void BFS(int x) { memset(visited, false, sizeof visited); memset(dist, 0, sizeof dist); visited[x] = true; dist[x] = 0; q.push(x); while (!q.empty()) { int s = q.front(); q.pop(); for (auto u : adj[s]) { if (visited[u]) continue; visited[u] = true; dist[u] = dist[s] + 1; q.push(u); } } } int main() { // freopen("data.txt","r",stdin); cin >> N >> X >> Y; for (int i = 1; i < N; i++) { adj[i].pb(i + 1); adj[i + 1].pb(i); } adj[X].pb(Y); adj[Y].pb(X); for (int i = 1; i <= N; i++) { BFS(i); for (int j = 1; j <= N; j++) { freq[dist[j]]++; } } for (int i = 1; i < N; i++) { cout << freq[i] / 2 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define mp make_pair #define pb push_back #define first fi #define second se #define MOD 1000000007 #define MAXN 2003 #define endl "\n" #define readln(x) getline(cin, x); typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef map<int, int> mii; typedef map<ll, ll> mll; ll fpow(ll x, ll n, ll mod) { if (n == 0) return 1 % mod; ll u = fpow(x, n / 2, mod); u = (u * u) % mod; if (n % 2 == 1) u = (u * x) % mod; return u; } ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } int N, X, Y; vector<int> adj[MAXN]; int dist[MAXN], freq[MAXN]; bool visited[MAXN]; queue<int> q; void BFS(int x) { memset(visited, false, sizeof visited); memset(dist, 0, sizeof dist); visited[x] = true; dist[x] = 0; q.push(x); while (!q.empty()) { int s = q.front(); q.pop(); for (auto u : adj[s]) { if (visited[u]) continue; visited[u] = true; dist[u] = dist[s] + 1; q.push(u); } } } int main() { // freopen("data.txt","r",stdin); cin >> N >> X >> Y; for (int i = 1; i < N; i++) { adj[i].pb(i + 1); adj[i + 1].pb(i); } adj[X].pb(Y); adj[Y].pb(X); for (int i = 1; i <= N; i++) { BFS(i); for (int j = 1; j <= N; j++) { freq[dist[j]]++; } } for (int i = 1; i < N; i++) { cout << freq[i] / 2 << endl; } return 0; }
replace
7
8
7
8
0
p02726
C++
Runtime Error
#include <bits/stdc++.h> #pragma gcc optimize("ofast") using namespace std; #define ll \ long long // data types used often, but you don't want to type them time by // time #define ull unsigned long long #define ui unsigned int #define mod 1000000007 #define us unsigned short #define IOS \ ios_base::sync_with_stdio(0); // to synchronize the input of cin and scanf #define INF LONG_MAX #define PI 3.1415926535897932384626 #define mp make_pair #define fi first #define se second #define pb push_back #define rep(x, j, n) for (int x = j; x < n; x++) #define all(x) (x).begin(), (x).end() typedef vector<pair<ll, ll>> vpi; typedef vector<ll> vi; typedef vector<vi> vvi; bool prime(ll n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (ll i = 5; i * i <= n; i += 6) { if (n % i == 0 || n % (i + 2) == 0) return false; } return true; } ll modexp(ll a, ll b, ll m) { ll r = 1; a = a % m; while (b > 0) { if (b & 1) r = (r * a) % m; b = b >> 1; a = (a * a) % m; } return r % m; } ll addmod(ll a, ll b) { if (a + b < mod) return a + b; else return a + b - mod; } ll mulmod(ll a, ll b) { a %= mod; b %= mod; return (a * b) % mod; } ll modinv(ll a) { return modexp(a, mod - 2, mod); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll n; cin >> n; ll x, y; cin >> x >> y; vi ans(n); ans[1] = n; for (ll len = 2; len <= n - 1; len++) { for (ll i = 1; i + len <= n; i++) { if (i + len <= x) ans[len]++; else if (i + len > x && i + len < y) { ll pos = y - i - len + 1 + x - i; pos = min(pos, len); if (pos == 1) continue; ans[pos]++; } else { ll pos = fabs(i - x) + 1 + fabs(len + i - y); pos = min(pos, len); if (pos == 1) continue; ans[pos]++; } } // for(ll i =1;i<=n-1;i++)cout<<ans[i]<<" "; // cout<<endl; } for (ll i = 1; i <= n - 1; i++) cout << ans[i] << endl; return 0; } /* 6 1 2 3 4 5 -6 */
#include <bits/stdc++.h> #pragma gcc optimize("ofast") using namespace std; #define ll \ long long // data types used often, but you don't want to type them time by // time #define ull unsigned long long #define ui unsigned int #define mod 1000000007 #define us unsigned short #define IOS \ ios_base::sync_with_stdio(0); // to synchronize the input of cin and scanf #define INF LONG_MAX #define PI 3.1415926535897932384626 #define mp make_pair #define fi first #define se second #define pb push_back #define rep(x, j, n) for (int x = j; x < n; x++) #define all(x) (x).begin(), (x).end() typedef vector<pair<ll, ll>> vpi; typedef vector<ll> vi; typedef vector<vi> vvi; bool prime(ll n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (ll i = 5; i * i <= n; i += 6) { if (n % i == 0 || n % (i + 2) == 0) return false; } return true; } ll modexp(ll a, ll b, ll m) { ll r = 1; a = a % m; while (b > 0) { if (b & 1) r = (r * a) % m; b = b >> 1; a = (a * a) % m; } return r % m; } ll addmod(ll a, ll b) { if (a + b < mod) return a + b; else return a + b - mod; } ll mulmod(ll a, ll b) { a %= mod; b %= mod; return (a * b) % mod; } ll modinv(ll a) { return modexp(a, mod - 2, mod); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll n; cin >> n; ll x, y; cin >> x >> y; vi ans(n); ans[1] = n; for (ll len = 2; len <= n - 1; len++) { for (ll i = 1; i + len <= n; i++) { if (i + len <= x) ans[len]++; else if (i + len > x && i + len < y) { ll pos = y - i - len + 1 + fabs(x - i); pos = min(pos, len); if (pos == 1) continue; ans[pos]++; } else { ll pos = fabs(i - x) + 1 + fabs(len + i - y); pos = min(pos, len); if (pos == 1) continue; ans[pos]++; } } // for(ll i =1;i<=n-1;i++)cout<<ans[i]<<" "; // cout<<endl; } for (ll i = 1; i <= n - 1; i++) cout << ans[i] << endl; return 0; } /* 6 1 2 3 4 5 -6 */
replace
80
81
80
81
0
p02726
C++
Runtime Error
// minamoto #include <bits/stdc++.h> #define R register #define fp(i, a, b) for (R int i = (a), I = (b) + 1; i < I; ++i) #define fd(i, a, b) for (R int i = (a), I = (b)-1; i > I; --i) #define go(u) for (int i = head[u], v = e[i].v; i; i = e[i].nx, v = e[i].v) template <class T> inline bool cmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } template <class T> inline bool cmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; } using namespace std; const int N = 2e5 + 5; char s[N]; int a[N], n, x, m, res, y, d; inline int calc(R int i, R int j) { if (i <= x && j >= y) return j - i - (y - x) + 1; if (i <= x && j <= x) return j - i; if (i >= y && j >= y) return j - i; if (i <= x) return min(j - i, y - j + 1 + x - i); return min(j - i, j - y + 1 + i - x); } int main() { // freopen("testdata.in","r",stdin); scanf("%d%d%d", &n, &x, &y); fp(i, 1, n) fp(j, i + 1, n)++ a[calc(i, j)]; fp(i, 1, n - 1) printf("%d\n", a[i]); return 0; }
// minamoto #include <bits/stdc++.h> #define R register #define fp(i, a, b) for (R int i = (a), I = (b) + 1; i < I; ++i) #define fd(i, a, b) for (R int i = (a), I = (b)-1; i > I; --i) #define go(u) for (int i = head[u], v = e[i].v; i; i = e[i].nx, v = e[i].v) template <class T> inline bool cmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } template <class T> inline bool cmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; } using namespace std; const int N = 2e5 + 5; char s[N]; int a[N], n, x, m, res, y, d; inline int calc(R int i, R int j) { if (i <= x && j >= y) return j - i - (y - x) + 1; if (i <= x && j <= x) return j - i; if (i >= y && j >= y) return j - i; if (i <= x) return min(j - i, y - j + 1 + x - i); if (j >= y) return min(j - i, j - y + 1 + i - x); return min(j - i, i - x + y - j + 1); } int main() { // freopen("testdata.in","r",stdin); scanf("%d%d%d", &n, &x, &y); fp(i, 1, n) fp(j, i + 1, n)++ a[calc(i, j)]; fp(i, 1, n - 1) printf("%d\n", a[i]); return 0; }
replace
25
26
25
28
0
p02726
C++
Runtime Error
#include <algorithm> #include <array> #include <cfenv> #include <cmath> #include <deque> #include <forward_list> #include <fstream> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <list> #include <map> #include <numeric> #include <ostream> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <streambuf> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> typedef long long ll; using namespace std; int main() { int N, X, Y; int ans[201]; cin >> N >> X >> Y; for (int i = 1; i <= N - 1; i++) { ans[i] = 0; } for (int i = 1; i <= N; i++) { for (int j = 1 + i; j <= N; j++) { int min = j - i; if (min > abs(i - X) + 1 + abs(j - Y)) { min = abs(i - X) + 1 + abs(j - Y); } if (min > abs(i - Y) + 1 + abs(j - X)) { min = abs(i - Y) + 1 + abs(j - X); } ans[min]++; } } for (int i = 1; i <= N - 1; i++) { cout << ans[i] << endl; } return 0; }
#include <algorithm> #include <array> #include <cfenv> #include <cmath> #include <deque> #include <forward_list> #include <fstream> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <list> #include <map> #include <numeric> #include <ostream> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <streambuf> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> typedef long long ll; using namespace std; int main() { int N, X, Y; int ans[2001]; cin >> N >> X >> Y; for (int i = 1; i <= N - 1; i++) { ans[i] = 0; } for (int i = 1; i <= N; i++) { for (int j = 1 + i; j <= N; j++) { int min = j - i; if (min > abs(i - X) + 1 + abs(j - Y)) { min = abs(i - X) + 1 + abs(j - Y); } if (min > abs(i - Y) + 1 + abs(j - X)) { min = abs(i - Y) + 1 + abs(j - X); } ans[min]++; } } for (int i = 1; i <= N - 1; i++) { cout << ans[i] << endl; } return 0; }
replace
34
35
34
35
0
p02726
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int a[1111]; int main() { int n, x, y; cin >> n >> x >> y; for (int i = 1; i <= n; i++) for (int j = i; j <= n; j++) a[min({abs(i - j), abs(i - x) + 1 + abs(y - j), abs(i - y) + 1 + abs(x - j)})]++; for (int i = 1; i < n; i++) cout << a[i] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int a[2222]; int main() { int n, x, y; cin >> n >> x >> y; for (int i = 1; i <= n; i++) for (int j = i; j <= n; j++) a[min({abs(i - j), abs(i - x) + 1 + abs(y - j), abs(i - y) + 1 + abs(x - j)})]++; for (int i = 1; i < n; i++) cout << a[i] << endl; return 0; }
replace
3
4
3
4
0
p02726
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long LL; #define fi first #define se second #define pb push_back #define forn(i, n) for (int i = 0; i < (n); i++) #define for1(i, n) for (int i = 1; i <= n; i++) #define forr(i, n) for (int i = n; i >= 0; i--) #define all(x) x.begin(), x.end() const int MAXN = 2e3 + 5; void fio() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } LL d[MAXN][MAXN]; LL min(LL a, LL b) { return a > b ? b : a; } int main() { fio(); LL n, x, y; cin >> n >> x >> y; vector<LL> an(n + 1); for1(i, n) { for (int j = i + 1; j <= n; j++) { an[min((i - x) + 1LL + (j - y), (j - i))]++; } } for1(i, n - 1) cout << an[i] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long LL; #define fi first #define se second #define pb push_back #define forn(i, n) for (int i = 0; i < (n); i++) #define for1(i, n) for (int i = 1; i <= n; i++) #define forr(i, n) for (int i = n; i >= 0; i--) #define all(x) x.begin(), x.end() const int MAXN = 2e3 + 5; void fio() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } LL d[MAXN][MAXN]; LL min(LL a, LL b) { return a > b ? b : a; } int main() { fio(); LL n, x, y; cin >> n >> x >> y; vector<LL> an(n + 1); for1(i, n) { for (int j = i + 1; j <= n; j++) { an[min(abs(i - x) + 1LL + abs(j - y), (j - i))]++; } } for1(i, n - 1) cout << an[i] << endl; return 0; }
replace
28
29
28
29
-6
munmap_chunk(): invalid pointer
p02726
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define all(x) (x).begin(), (x).end() using ll = long long; int main() { ll n, x, y, ans, i, j; cin >> n >> x >> y; vector<ll> k(n - 1); for (i = 0; i < n - 1; i++) { for (j = 0; j < i; j++) { k[min({i - j, abs(x - i) + abs(y - j), abs(x - j) + abs(y - i)}) - 1]++; } } for (i = 0; i < n - 1; i++) cout << k[i] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define all(x) (x).begin(), (x).end() using ll = long long; int main() { ll n, x, y, ans, i, j; cin >> n >> x >> y; vector<ll> k(n - 1, 0); for (i = 2; i <= n; i++) { for (j = 1; j < i; j++) { k[min({i - j, abs(x - i) + abs(y - j) + 1, abs(x - j) + abs(y - i) + 1}) - 1]++; // cout<<i<<"_"<<j<<"_"<<min({i-j,abs(x-i)+abs(y-j)+1,abs(x-j)+abs(y-i)+1})<<endl; } } for (i = 0; i < n - 1; i++) cout << k[i] << endl; return 0; }
replace
8
12
8
14
0
p02726
C++
Runtime Error
#include <iostream> #include <vector> using namespace std; int n, x, y; void solve() { vector<int> cnt(n + 1); for (int i = 1; i < n; i++) { for (int j = 2; j <= n; j++) { int dist = min(j - i, min(abs(x - i) + abs(y - j), abs(x - j) + abs(y - i)) + 1); cnt[dist]++; } } for (int i = 1; i < n; i++) { cout << cnt[i] << endl; } } int main() { cin >> n >> x >> y; solve(); }
#include <iostream> #include <vector> using namespace std; int n, x, y; void solve() { vector<int> cnt(n + 1); for (int i = 1; i < n; i++) { for (int j = i + 1; j <= n; j++) { int dist = min(j - i, min(abs(x - i) + abs(y - j), abs(x - j) + abs(y - i)) + 1); cnt[dist]++; } } for (int i = 1; i < n; i++) { cout << cnt[i] << endl; } } int main() { cin >> n >> x >> y; solve(); }
replace
10
11
10
11
-6
munmap_chunk(): invalid pointer
p02726
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define F first #define S second #define PB push_back #define MP make_pair #define REP(i, a, b) for (int i = a; i < b; i++) typedef long long ll; #define int ll typedef vector<int> vi; typedef vector<long long> vl; typedef pair<int, int> pi; #define trace(x) cout << #x << "=" << x << "\n"; #define sz(x) (int)(x.size()) #define mod 1000000007 #define endl "\n" template <typename F, typename S> ostream &operator<<(ostream &os, const pair<F, S> &p) { return os << "(" << p.first << ", " << p.second << ")"; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "{"; typename vector<T>::const_iterator it; for (it = v.begin(); it != v.end(); it++) { if (it != v.begin()) os << ", "; os << *it; } return os << "}"; } template <typename T> ostream &operator<<(ostream &os, const set<T> &v) { os << "["; typename set<T>::const_iterator it; for (it = v.begin(); it != v.end(); it++) { if (it != v.begin()) os << ", "; os << *it; } return os << "]"; } template <typename F, typename S> ostream &operator<<(ostream &os, const map<F, S> &v) { os << "["; typename map<F, S>::const_iterator it; for (it = v.begin(); it != v.end(); it++) { if (it != v.begin()) os << ", "; os << it->first << " = " << it->second; } return os << "]"; } #define deb(x) cerr << #x << " = " << x << endl; // map<pair<int, int>, int>dis; int a[1005][1005]; int32_t main() { ios::sync_with_stdio(false); int n, x, y; cin >> n >> x >> y; memset(a, 0, sizeof(a)); REP(i, 1, n + 1) { REP(j, i + 1, n + 1) { int dis = min(j - i, abs(i - x) + 1 + abs(j - y)); a[i][j] = dis; } } vi ans(n + 1); REP(i, 1, n + 1) { REP(j, i + 1, n + 1) { // int dis=min(j-i,ans(i-x)+1+abs(j-y)); // a[i][j]=dis; if (a[i][j] >= 0 && a[i][j] <= n - 1) ans[a[i][j]]++; } } // // ans[1]=n; // // ans[2]=n-2+1+1+1+1;'' // // REP(i,1,n){ // // ans[i]=n-i; // // } // //LL // for(int i=1;i<=x;i++){ // for(int j=i+1;j<=x;j++){ // ans[abs(j-i)]++; // if(abs(j-1)==1){ // cout<<"("<<i<<" "<<j<<")\n"; // } // } // } // deb(ans); // //RR // for(int i=y+1;i<=n;i++){ // for(int j=i+1;j<=n;j++){ // ans[abs(j-i)]++; // if(abs(j-1)==1){ // cout<<"("<<i<<" "<<j<<")\n"; // } // } // } // deb(ans); // //LR // for(int i=1;i<x;i++){ // for(int j=y;j<=n;j++){ // ans[x-i+j-y+1]++; // if(x-i+j-y+1==1){ // cout<<"("<<i<<" "<<j<<")\n"; // } // } // } // deb(ans); // for(int i=1;i<x;i++){ // for(int j=x+1;j<y;j++){ // ans[j-i]++; // } // } // for(int i=x;i<=y;i++){ // for(int j=i+1;j<=n;j++){ // if(abs(i-x+1+abs(j-y))<(abs(j-i))){ // if(abs(i-x+1+abs(j-y))==1){ // cout<<"("<<i<<" "<<j<<")\n"; // } // ans[abs(i-x+1+abs(j-y))]++; // } // else{ // ans[abs(j-i)]++; // if(abs(j-i)==1){ // cout<<"("<<i<<" "<<j<<")\n"; // } // } // } // } // // for(int i=x;i<=y;i++){ // // for() // // } // deb(ans); // // ans[1]-=2; REP(i, 1, n) { cout << ans[i] << "\n"; } // // cout<<"\n"; // // if(x+1!=y) return 0; }
#include <bits/stdc++.h> using namespace std; #define F first #define S second #define PB push_back #define MP make_pair #define REP(i, a, b) for (int i = a; i < b; i++) typedef long long ll; #define int ll typedef vector<int> vi; typedef vector<long long> vl; typedef pair<int, int> pi; #define trace(x) cout << #x << "=" << x << "\n"; #define sz(x) (int)(x.size()) #define mod 1000000007 #define endl "\n" template <typename F, typename S> ostream &operator<<(ostream &os, const pair<F, S> &p) { return os << "(" << p.first << ", " << p.second << ")"; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "{"; typename vector<T>::const_iterator it; for (it = v.begin(); it != v.end(); it++) { if (it != v.begin()) os << ", "; os << *it; } return os << "}"; } template <typename T> ostream &operator<<(ostream &os, const set<T> &v) { os << "["; typename set<T>::const_iterator it; for (it = v.begin(); it != v.end(); it++) { if (it != v.begin()) os << ", "; os << *it; } return os << "]"; } template <typename F, typename S> ostream &operator<<(ostream &os, const map<F, S> &v) { os << "["; typename map<F, S>::const_iterator it; for (it = v.begin(); it != v.end(); it++) { if (it != v.begin()) os << ", "; os << it->first << " = " << it->second; } return os << "]"; } #define deb(x) cerr << #x << " = " << x << endl; // map<pair<int, int>, int>dis; int a[2005][2005]; int32_t main() { ios::sync_with_stdio(false); int n, x, y; cin >> n >> x >> y; memset(a, 0, sizeof(a)); REP(i, 1, n + 1) { REP(j, i + 1, n + 1) { int dis = min(j - i, abs(i - x) + 1 + abs(j - y)); a[i][j] = dis; } } vi ans(n + 1); REP(i, 1, n + 1) { REP(j, i + 1, n + 1) { // int dis=min(j-i,ans(i-x)+1+abs(j-y)); // a[i][j]=dis; if (a[i][j] >= 0 && a[i][j] <= n - 1) ans[a[i][j]]++; } } // // ans[1]=n; // // ans[2]=n-2+1+1+1+1;'' // // REP(i,1,n){ // // ans[i]=n-i; // // } // //LL // for(int i=1;i<=x;i++){ // for(int j=i+1;j<=x;j++){ // ans[abs(j-i)]++; // if(abs(j-1)==1){ // cout<<"("<<i<<" "<<j<<")\n"; // } // } // } // deb(ans); // //RR // for(int i=y+1;i<=n;i++){ // for(int j=i+1;j<=n;j++){ // ans[abs(j-i)]++; // if(abs(j-1)==1){ // cout<<"("<<i<<" "<<j<<")\n"; // } // } // } // deb(ans); // //LR // for(int i=1;i<x;i++){ // for(int j=y;j<=n;j++){ // ans[x-i+j-y+1]++; // if(x-i+j-y+1==1){ // cout<<"("<<i<<" "<<j<<")\n"; // } // } // } // deb(ans); // for(int i=1;i<x;i++){ // for(int j=x+1;j<y;j++){ // ans[j-i]++; // } // } // for(int i=x;i<=y;i++){ // for(int j=i+1;j<=n;j++){ // if(abs(i-x+1+abs(j-y))<(abs(j-i))){ // if(abs(i-x+1+abs(j-y))==1){ // cout<<"("<<i<<" "<<j<<")\n"; // } // ans[abs(i-x+1+abs(j-y))]++; // } // else{ // ans[abs(j-i)]++; // if(abs(j-i)==1){ // cout<<"("<<i<<" "<<j<<")\n"; // } // } // } // } // // for(int i=x;i<=y;i++){ // // for() // // } // deb(ans); // // ans[1]-=2; REP(i, 1, n) { cout << ans[i] << "\n"; } // // cout<<"\n"; // // if(x+1!=y) return 0; }
replace
58
59
58
59
0
p02726
C++
Runtime Error
#include <algorithm> #include <iostream> using namespace std; const int N = 1e3 + 5; int e[N][N], ans[N]; int main() { int n, x, y; cin >> n >> x >> y; for (int i = 1; i <= n; ++i) { for (int j = i + 1; j <= n; ++j) { e[j][i] = e[i][j] = j - i; } } for (int i = 1; i <= n; ++i) { for (int j = i + 1; j <= n; ++j) { e[i][j] = e[j][i] = min(e[i][x] + e[y][j] + 1, e[i][j]); } } for (int i = 1; i <= n; ++i) for (int j = i + 1; j <= n; ++j) ans[e[i][j]]++; for (int i = 1; i < n; ++i) cout << ans[i] << endl; return 0; }
#include <algorithm> #include <iostream> using namespace std; const int N = 2e3 + 5; int e[N][N], ans[N]; int main() { int n, x, y; cin >> n >> x >> y; for (int i = 1; i <= n; ++i) { for (int j = i + 1; j <= n; ++j) { e[j][i] = e[i][j] = j - i; } } for (int i = 1; i <= n; ++i) { for (int j = i + 1; j <= n; ++j) { e[i][j] = e[j][i] = min(e[i][x] + e[y][j] + 1, e[i][j]); } } for (int i = 1; i <= n; ++i) for (int j = i + 1; j <= n; ++j) ans[e[i][j]]++; for (int i = 1; i < n; ++i) cout << ans[i] << endl; return 0; }
replace
5
6
5
6
0
p02726
C++
Runtime Error
#include <bits/stdc++.h> #define pii pair<int, int> #define ll long long #define cl(x, y) memset(x, y, sizeof(x)) #define ct cerr << "Time elapsed:" << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n"; const int N = 1e3 + 10; const int mod = 1e9 + 7; const int inf = 0x3f3f3f3f; using namespace std; int a[N]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, x, y, i, j; cin >> n >> x >> y; for (i = 1; i < n; i++) a[i] = n - i; int p = y - (y - x) / 2; for (i = 1; i < p; i++) for (j = p + 1; j <= n; j++) { if (abs(j - i) > abs(x - i) + 1 + abs(j - y)) { a[abs(j - i)]--; a[abs(x - i) + 1 + abs(j - y)]++; } } for (i = 1; i < n; i++) cout << a[i] << endl; return 0; }
#include <bits/stdc++.h> #define pii pair<int, int> #define ll long long #define cl(x, y) memset(x, y, sizeof(x)) #define ct cerr << "Time elapsed:" << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n"; const int N = 2e3 + 10; const int mod = 1e9 + 7; const int inf = 0x3f3f3f3f; using namespace std; int a[N]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, x, y, i, j; cin >> n >> x >> y; for (i = 1; i < n; i++) a[i] = n - i; int p = y - (y - x) / 2; for (i = 1; i < p; i++) for (j = p + 1; j <= n; j++) { if (abs(j - i) > abs(x - i) + 1 + abs(j - y)) { a[abs(j - i)]--; a[abs(x - i) + 1 + abs(j - y)]++; } } for (i = 1; i < n; i++) cout << a[i] << endl; return 0; }
replace
5
6
5
6
0
p02726
C++
Time Limit Exceeded
#include "bits/stdc++.h" using namespace std; const int MAX = 700000; const int MOD = 1000000007; long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } /*第二引数で第一引数を割ったときの切り上げの計算*/ long long int maxtime(long long int x, long long int y) { return (x + y - 1) / y; } /*最大公約数*/ long long int lcm(long long int number1, long long int number2) { long long int m = number1; long long int n = number2; if (number2 > number1) { m = number2; n = number1; } long long int s = -1; while (s != 0) { s = m % n; m = n; n = s; } return m; } /*最大公倍数*/ long long int gcd(long long int number1, long long int number2) { long long int m = number1; long long int n = number2; return m / lcm(m, n) * n; } /*逆元計算*/ long long int modinv(long long a, long long m) { long long int b = m, u = 1, v = 0; while (b) { long long int t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } // index が条件を満たすかどうか vector<long long int> meguru; bool isOK(int index, int key) { if (meguru[index] >= key) return true; else return false; } // 汎用的な二分探索のテンプレ int binary_search(int key) { int left = -1; // 「index = 0」が条件を満たすこともあるので、初期値は -1 int right = (int)meguru.size(); // 「index = // a.size()-1」が条件を満たさないこともあるので、初期値は // a.size() /* どんな二分探索でもここの書き方を変えずにできる! */ while (right - left > 1) { int mid = left + (right - left) / 2; if (isOK(mid, key)) right = mid; else left = mid; } /* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */ return right; } 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; } int dp[3000][3000] = {}; int main() { long long int n, x, y; cin >> n >> x >> y; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { if (i == x && j == y) { dp[i][j] = 1; } else if (i == y && j == x) { dp[j][i] = 1; } else { dp[i][j] = abs(i - j); } } } for (int k = 1; k <= n; k++) { for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]); } } } int ans[3000] = {}; for (int i = 1; i <= n; i++) { for (int j = i; j <= n; j++) { ans[dp[i][j]]++; } } for (int i = 1; i <= n - 1; i++) { cout << ans[i] << endl; } }
#include "bits/stdc++.h" using namespace std; const int MAX = 700000; const int MOD = 1000000007; long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } /*第二引数で第一引数を割ったときの切り上げの計算*/ long long int maxtime(long long int x, long long int y) { return (x + y - 1) / y; } /*最大公約数*/ long long int lcm(long long int number1, long long int number2) { long long int m = number1; long long int n = number2; if (number2 > number1) { m = number2; n = number1; } long long int s = -1; while (s != 0) { s = m % n; m = n; n = s; } return m; } /*最大公倍数*/ long long int gcd(long long int number1, long long int number2) { long long int m = number1; long long int n = number2; return m / lcm(m, n) * n; } /*逆元計算*/ long long int modinv(long long a, long long m) { long long int b = m, u = 1, v = 0; while (b) { long long int t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } // index が条件を満たすかどうか vector<long long int> meguru; bool isOK(int index, int key) { if (meguru[index] >= key) return true; else return false; } // 汎用的な二分探索のテンプレ int binary_search(int key) { int left = -1; // 「index = 0」が条件を満たすこともあるので、初期値は -1 int right = (int)meguru.size(); // 「index = // a.size()-1」が条件を満たさないこともあるので、初期値は // a.size() /* どんな二分探索でもここの書き方を変えずにできる! */ while (right - left > 1) { int mid = left + (right - left) / 2; if (isOK(mid, key)) right = mid; else left = mid; } /* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */ return right; } 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; } int dp[3000][3000] = {}; int main() { long long int n, x, y; cin >> n >> x >> y; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { if (i == x && j == y) { dp[i][j] = 1; } else if (i == y && j == x) { dp[j][i] = 1; } else { dp[i][j] = abs(i - j); } } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { int t = abs(i - x) + abs(j - y) + 1; dp[i][j] = min(t, abs(i - j)); } } int ans[3000] = {}; for (int i = 1; i <= n; i++) { for (int j = i; j <= n; j++) { ans[dp[i][j]]++; } } for (int i = 1; i <= n - 1; i++) { cout << ans[i] << endl; } }
replace
121
126
121
125
TLE
p02726
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; #define x_ real() #define y_ imag() #define cross(a, b) (conj(a) * (b)).imag() #define dot(a, b) (conj(a) * (b)).real() #define PI acos(-1) #define F first #define S second #define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL) #define fileIO \ freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout) #define ordered_set \ tree<int, null_type, less_equal<int>, rb_tree_tag, \ tree_order_statistics_node_update> typedef long double ld; typedef long long ll; typedef unsigned long long ull; typedef complex<ld> point; typedef tuple<int, int, int> line; typedef vector<point> polygon; typedef pair<double, double> pd; pair<int, int> dirs[] = {{1, 2}, {-1, 2}, {2, 1}, {2, -1}, {-2, 1}, {-2, -1}, {1, -2}, {-1, -2}}; int N = 1e3 + 7; vector<int> conn[1007]; bool vis[1007]; int dist[1007]; void bfs(int src) { queue<int> q; q.push(src); dist[src] = 0; vis[src] = 1; while (q.size()) { int node = q.front(); q.pop(); for (auto i : conn[node]) { if (!vis[i]) { vis[i] = 1; q.push(i); dist[i] = dist[node] + 1; } } } } int main() { fastIO; int n, x, y; cin >> n >> x >> y; for (int i = 1; i < n; i++) { conn[i].push_back(i + 1); conn[i + 1].push_back(i); } conn[x].push_back(y); conn[y].push_back(x); map<int, int> count; for (int i = 1; i <= n; i++) { memset(vis, 0, sizeof vis); bfs(i); for (int j = i + 1; j <= n; j++) { count[dist[j]]++; } } for (int i = 1; i < n; i++) { cout << count[i] << endl; } }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; #define x_ real() #define y_ imag() #define cross(a, b) (conj(a) * (b)).imag() #define dot(a, b) (conj(a) * (b)).real() #define PI acos(-1) #define F first #define S second #define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL) #define fileIO \ freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout) #define ordered_set \ tree<int, null_type, less_equal<int>, rb_tree_tag, \ tree_order_statistics_node_update> typedef long double ld; typedef long long ll; typedef unsigned long long ull; typedef complex<ld> point; typedef tuple<int, int, int> line; typedef vector<point> polygon; typedef pair<double, double> pd; pair<int, int> dirs[] = {{1, 2}, {-1, 2}, {2, 1}, {2, -1}, {-2, 1}, {-2, -1}, {1, -2}, {-1, -2}}; int N = 1e3 + 7; vector<int> conn[2007]; bool vis[2007]; int dist[2007]; void bfs(int src) { queue<int> q; q.push(src); dist[src] = 0; vis[src] = 1; while (q.size()) { int node = q.front(); q.pop(); for (auto i : conn[node]) { if (!vis[i]) { vis[i] = 1; q.push(i); dist[i] = dist[node] + 1; } } } } int main() { fastIO; int n, x, y; cin >> n >> x >> y; for (int i = 1; i < n; i++) { conn[i].push_back(i + 1); conn[i + 1].push_back(i); } conn[x].push_back(y); conn[y].push_back(x); map<int, int> count; for (int i = 1; i <= n; i++) { memset(vis, 0, sizeof vis); bfs(i); for (int j = i + 1; j <= n; j++) { count[dist[j]]++; } } for (int i = 1; i < n; i++) { cout << count[i] << endl; } }
replace
29
32
29
32
0
p02726
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() using ll = long long; const int INF = 1001001001; int main() { int n, x, y; cin >> n >> x >> y; --x, --y; vector<int> ans(n); rep(sv, n) { vector<int> dist(n, INF); queue<int> q; auto push = [&](int v, int d) { if (dist[v] != INF) return; dist[v] = d; q.push(v); }; push(sv, 0); while (!q.empty()) { int v = q.front(); q.pop(); int d = dist[v]; if (v - 1 >= 0) push(v - 1, d + 1); if (v + 1 < 0) push(v + 1, d + 1); if (v == x) push(y, d + 1); if (v == y) push(x, d + 1); } rep(i, n) ans[dist[i]]++; } rep(i, n) ans[i] /= 2; for (int i = 1; i <= n - 1; ++i) { cout << ans[i] << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() using ll = long long; const int INF = 1001001001; int main() { int n, x, y; cin >> n >> x >> y; --x, --y; vector<int> ans(n); rep(sv, n) { vector<int> dist(n, INF); queue<int> q; auto push = [&](int v, int d) { if (dist[v] != INF) return; dist[v] = d; q.push(v); }; push(sv, 0); while (!q.empty()) { int v = q.front(); q.pop(); int d = dist[v]; if (v - 1 >= 0) push(v - 1, d + 1); if (v + 1 < n) push(v + 1, d + 1); if (v == x) push(y, d + 1); if (v == y) push(x, d + 1); } rep(i, n) ans[dist[i]]++; } rep(i, n) ans[i] /= 2; for (int i = 1; i <= n - 1; ++i) { cout << ans[i] << endl; } return 0; }
replace
30
31
30
31
-11
p02726
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; long long p[10004]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, x, y, k; cin >> n >> x >> y; for (long long i = 1; i < n; ++i) { for (long long j = 2; j <= n; ++j) { k = min(j - i, abs(x - i) + 1 + abs(y - j)); ++p[k]; } } for (long long i = 1; i < n; ++i) cout << p[i] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; long long p[10004]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, x, y, k; cin >> n >> x >> y; for (long long i = 1; i < n; ++i) { for (long long j = i + 1; j <= n; ++j) { k = min(j - i, abs(x - i) + 1 + abs(y - j)); ++p[k]; } } for (long long i = 1; i < n; ++i) cout << p[i] << endl; return 0; }
replace
14
15
14
15
0
p02726
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define ll long long using namespace std; ll arr[2020][2020], n, x, y, cnt[2020]; int main() { memset(arr, 1, sizeof(arr)); cin >> n >> x >> y; for (int i = 1; i <= n; ++i) { for (int j = i; j <= n; ++j) arr[i][j] = arr[j][i] = j - i; } arr[x][y] = 1; for (int k = 1; k <= n; ++k) { for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) if (arr[i][k] + arr[k][j] < arr[i][j]) arr[i][j] = arr[i][k] + arr[k][j]; } } for (int i = 1; i <= n; ++i) { for (int j = i + 1; j <= n; ++j) cnt[arr[i][j]]++; } for (int i = 1; i <= n - 1; ++i) printf("%lld\n", cnt[i]); return 0; }
#include <bits/stdc++.h> #define ll long long using namespace std; ll arr[2020][2020], n, x, y, cnt[2020]; int main() { memset(arr, 1, sizeof(arr)); cin >> n >> x >> y; for (int i = 1; i <= n; ++i) { for (int j = i; j <= n; ++j) arr[i][j] = arr[j][i] = j - i; } arr[x][y] = 1; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { if (arr[i][x] + arr[x][j] < arr[i][j]) arr[i][j] = arr[j][i] = arr[i][x] + arr[x][j]; if (arr[i][y] + arr[y][j] < arr[i][j]) arr[i][j] = arr[j][i] = arr[i][y] + arr[y][j]; } } for (int i = 1; i <= n; ++i) { for (int j = i + 1; j <= n; ++j) cnt[arr[i][j]]++; } for (int i = 1; i <= n - 1; ++i) printf("%lld\n", cnt[i]); return 0; }
replace
12
17
12
18
TLE
p02726
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int maxn = 1e3 + 10; typedef long long ll; int x, n, y, cnt[maxn]; int dis(int a, int b) { return min(b - a, abs(a - x) + abs(b - y) + 1); } int main() { scanf("%d%d%d", &n, &x, &y); if (x > y) swap(x, y); for (int i = 1; i <= n; i++) { for (int j = i + 1; j <= n; j++) { cnt[dis(i, j)]++; } } for (int i = 1; i < n; i++) printf("%d\n", cnt[i]); return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; typedef long long ll; int x, n, y, cnt[maxn]; int dis(int a, int b) { return min(b - a, abs(a - x) + abs(b - y) + 1); } int main() { scanf("%d%d%d", &n, &x, &y); if (x > y) swap(x, y); for (int i = 1; i <= n; i++) { for (int j = i + 1; j <= n; j++) { cnt[dis(i, j)]++; } } for (int i = 1; i < n; i++) printf("%d\n", cnt[i]); return 0; }
replace
2
3
2
3
0
p02726
C++
Runtime Error
/*** ** A S M Atikur Rahman ** Update: 26-03-2020 ***/ // #include <bits/stdc++.h> #include <algorithm> #include <bitset> #include <cassert> #include <cstring> #include <iomanip> ///setprecision #include <iostream> #include <iterator> #include <limits.h> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string> #include <time.h> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define IOS \ ios_base::sync_with_stdio(false); \ cin.tie(nullptr); \ cout.tie(nullptr); #define sci(x) scanf("%d%*c", &(x)) #define scll(x) scanf("%lld%*c", &(x)) #define scd(x) scanf("%lf%*c", &(x)) #define scstr(x) scanf("%s", x) #define pfi(x) printf("%d", (x)) #define pfll(x) printf("%lld", (x)) #define pfd(x) printf("%f", (x)) #define pfstr(x) printf("%s", (x)) #define ps printf(" ") #define pn printf("\n") #define pfdot printf("..") #define For(a, n) for (int i = (a); i < (n); i++) #define rFor(n, a) for (int i = n - 1; i >= 0; i--) #define trav(a, x) for (auto &a : x) #define Mset(ara, val) memset(ara, val, sizeof(ara)) #define mkp make_pair #define pb push_back #define ff first #define ss second #define lb lower_bound #define ub upper_bound #define pi (2 * acos(0)) using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<long long, long long>; using pcc = pair<char, char>; using pdd = pair<double, double>; #define V(a) vector<a> using vi = vector<int>; using vs = vector<string>; using vll = vector<ll>; using vpii = vector<pii>; using vc = vector<char>; using vd = vector<double>; // ll POW(ll a,ll b){if(b==0)return 1;ll // x=POW(a,b/2);x=(x*x);if(b&1)x=(x*a);return x;} ll Sqrt(ll a) { ll // x=(ll)sqrt(a); if((x+1)*(x+1)==a) x++; return x; } int main(int argc, char *argv[]) { // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stout); int x, y, n, ans = 0, ara[1100]{0}, i, j; cin >> n >> x >> y; // for(int k=1; k<n; k++) { for (i = 1; i < n; i++) { for (j = i + 1; j <= n; j++) { int tmp; // printf("%d %d..", i, j); if (x >= i && y <= j) { tmp = (j - i) - (y - x) + 1; } else if (i >= x && j <= y) { tmp = min(j - i, i - x + y - j + 1); } else if (j >= x && j <= y) { tmp = x - i; tmp += min(j - x, y - j + 1); } else if (i >= x && i <= y) { tmp = j - y; tmp += min(y - i, i - x + 1); } else tmp = j - i; ara[tmp]++; // printf("%d..\n", tmp); } } } for (i = 1; i < n; i++) { printf("%d\n", ara[i]); } return 0; }
/*** ** A S M Atikur Rahman ** Update: 26-03-2020 ***/ // #include <bits/stdc++.h> #include <algorithm> #include <bitset> #include <cassert> #include <cstring> #include <iomanip> ///setprecision #include <iostream> #include <iterator> #include <limits.h> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string> #include <time.h> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define IOS \ ios_base::sync_with_stdio(false); \ cin.tie(nullptr); \ cout.tie(nullptr); #define sci(x) scanf("%d%*c", &(x)) #define scll(x) scanf("%lld%*c", &(x)) #define scd(x) scanf("%lf%*c", &(x)) #define scstr(x) scanf("%s", x) #define pfi(x) printf("%d", (x)) #define pfll(x) printf("%lld", (x)) #define pfd(x) printf("%f", (x)) #define pfstr(x) printf("%s", (x)) #define ps printf(" ") #define pn printf("\n") #define pfdot printf("..") #define For(a, n) for (int i = (a); i < (n); i++) #define rFor(n, a) for (int i = n - 1; i >= 0; i--) #define trav(a, x) for (auto &a : x) #define Mset(ara, val) memset(ara, val, sizeof(ara)) #define mkp make_pair #define pb push_back #define ff first #define ss second #define lb lower_bound #define ub upper_bound #define pi (2 * acos(0)) using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<long long, long long>; using pcc = pair<char, char>; using pdd = pair<double, double>; #define V(a) vector<a> using vi = vector<int>; using vs = vector<string>; using vll = vector<ll>; using vpii = vector<pii>; using vc = vector<char>; using vd = vector<double>; // ll POW(ll a,ll b){if(b==0)return 1;ll // x=POW(a,b/2);x=(x*x);if(b&1)x=(x*a);return x;} ll Sqrt(ll a) { ll // x=(ll)sqrt(a); if((x+1)*(x+1)==a) x++; return x; } int main(int argc, char *argv[]) { // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stout); int x, y, n, ans = 0, ara[2100]{0}, i, j; cin >> n >> x >> y; // for(int k=1; k<n; k++) { for (i = 1; i < n; i++) { for (j = i + 1; j <= n; j++) { int tmp; // printf("%d %d..", i, j); if (x >= i && y <= j) { tmp = (j - i) - (y - x) + 1; } else if (i >= x && j <= y) { tmp = min(j - i, i - x + y - j + 1); } else if (j >= x && j <= y) { tmp = x - i; tmp += min(j - x, y - j + 1); } else if (i >= x && i <= y) { tmp = j - y; tmp += min(y - i, i - x + 1); } else tmp = j - i; ara[tmp]++; // printf("%d..\n", tmp); } } } for (i = 1; i < n; i++) { printf("%d\n", ara[i]); } return 0; }
replace
81
82
81
82
0
p02726
C++
Runtime Error
#include <bits/stdc++.h> #define int long long #define endl '\n' #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define bug1(x) \ { cerr << (#x) << "=" << x << endl; } #define bug2(x, y) \ { cerr << (#x) << "=" << (x) << " " << (#y) << "=" << (y) << endl; } #define bug3(x, y, z) \ { \ cerr << (#x) << "=" << (x) << " " << (#y) << "=" << (y) << " " \ << (#z) << "=" << (z) << endl; \ } #define bug4(x, y, z, w) \ { \ cerr << (#x) << "=" << (x) << " " << (#y) << "=" << (y) << " " \ << (#z) << "=" << (z) << " " << (#w) << "=" << w << endl; \ } #define bug5(x, y, z, w, p) \ { \ cerr << (#x) << "=" << (x) << " " << (#y) << "=" << (y) << " " \ << (#z) << "=" << (z) << " " << (#w) << "=" << w << " " << (#p) \ << "=" << p << endl; \ } #define bug6(x, y, z, w, p, q) \ { \ cerr << (#x) << "=" << (x) << " " << (#y) << "=" << (y) << " " \ << (#z) << "=" << (z) << " " << (#w) << "=" << w << " " << (#p) \ << "=" << p << " " << (#q) << "=" << q << endl; \ } #define bugn(x, n) \ { \ cerr << (#x) << ":"; \ for (int i = 0; i < n; i++) \ cerr << x[i] << " "; \ cerr << endl; \ } #define bugnm(x, n, m) \ { \ cerr << (#x) << endl; \ for (int i = 0; i < n; i++) { \ cerr << "Row #" << i << ":"; \ for (int j = 0; j < m; j++) \ cerr << x[i][j] << " "; \ cerr << endl; \ } \ } typedef long long ll; typedef long double ld; using namespace std; const int maxn = 1005; vector<int> g[maxn], dis(maxn); int n; void spfa(int s) { fill(dis.begin(), dis.end(), 1e6); vector<int> inq(n + 1); queue<int> q; dis[s] = 0; q.push(s); inq[s] = 1; while (q.size()) { int u = q.front(); q.pop(); inq[u] = 0; for (auto v : g[u]) { if (dis[v] > dis[u] + 1) { dis[v] = dis[u] + 1; if (!inq[v]) { inq[v] = 1; q.push(v); } } } } } int32_t main() { IOS int x, y; cin >> n >> x >> y; for (int i = 1; i < n; i++) { g[i].push_back(i + 1); g[i + 1].push_back(i); } g[x].push_back(y); g[y].push_back(x); vector<int> ans(n + 1); for (int i = 1; i <= n; i++) { spfa(i); for (int j = 1; j <= n; j++) { ans[dis[j]]++; // bug3(i,j,dis[j]); } } for (int i = 1; i < n; i++) { cout << ans[i] / 2 << " "; } cout << endl; } /* * long long or int? * index out of bound? * Tested on own test case?corner? * Make more general solution. * Read Read Read Read .... */
#include <bits/stdc++.h> #define int long long #define endl '\n' #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define bug1(x) \ { cerr << (#x) << "=" << x << endl; } #define bug2(x, y) \ { cerr << (#x) << "=" << (x) << " " << (#y) << "=" << (y) << endl; } #define bug3(x, y, z) \ { \ cerr << (#x) << "=" << (x) << " " << (#y) << "=" << (y) << " " \ << (#z) << "=" << (z) << endl; \ } #define bug4(x, y, z, w) \ { \ cerr << (#x) << "=" << (x) << " " << (#y) << "=" << (y) << " " \ << (#z) << "=" << (z) << " " << (#w) << "=" << w << endl; \ } #define bug5(x, y, z, w, p) \ { \ cerr << (#x) << "=" << (x) << " " << (#y) << "=" << (y) << " " \ << (#z) << "=" << (z) << " " << (#w) << "=" << w << " " << (#p) \ << "=" << p << endl; \ } #define bug6(x, y, z, w, p, q) \ { \ cerr << (#x) << "=" << (x) << " " << (#y) << "=" << (y) << " " \ << (#z) << "=" << (z) << " " << (#w) << "=" << w << " " << (#p) \ << "=" << p << " " << (#q) << "=" << q << endl; \ } #define bugn(x, n) \ { \ cerr << (#x) << ":"; \ for (int i = 0; i < n; i++) \ cerr << x[i] << " "; \ cerr << endl; \ } #define bugnm(x, n, m) \ { \ cerr << (#x) << endl; \ for (int i = 0; i < n; i++) { \ cerr << "Row #" << i << ":"; \ for (int j = 0; j < m; j++) \ cerr << x[i][j] << " "; \ cerr << endl; \ } \ } typedef long long ll; typedef long double ld; using namespace std; const int maxn = 2005; vector<int> g[maxn], dis(maxn); int n; void spfa(int s) { fill(dis.begin(), dis.end(), 1e6); vector<int> inq(n + 1); queue<int> q; dis[s] = 0; q.push(s); inq[s] = 1; while (q.size()) { int u = q.front(); q.pop(); inq[u] = 0; for (auto v : g[u]) { if (dis[v] > dis[u] + 1) { dis[v] = dis[u] + 1; if (!inq[v]) { inq[v] = 1; q.push(v); } } } } } int32_t main() { IOS int x, y; cin >> n >> x >> y; for (int i = 1; i < n; i++) { g[i].push_back(i + 1); g[i + 1].push_back(i); } g[x].push_back(y); g[y].push_back(x); vector<int> ans(n + 1); for (int i = 1; i <= n; i++) { spfa(i); for (int j = 1; j <= n; j++) { ans[dis[j]]++; // bug3(i,j,dis[j]); } } for (int i = 1; i < n; i++) { cout << ans[i] / 2 << " "; } cout << endl; } /* * long long or int? * index out of bound? * Tested on own test case?corner? * Make more general solution. * Read Read Read Read .... */
replace
54
55
54
55
0
p02726
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int x, n, y; string s; cin >> n >> x >> y; // map<int, int> cnt; int cnt[1000] = {}; for (int i = 1; i < n; i++) { int dis = 0; for (int j = i + 1; j <= n; j++) { dis = min(j - i, abs(x - i) + 1 + abs(y - j)); cnt[dis]++; // cout << i << " " << dis << " " << j << endl; } } for (int i = 1; i < n; i++) { cout << cnt[i] << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int x, n, y; string s; cin >> n >> x >> y; // map<int, int> cnt; int cnt[2000] = {}; for (int i = 1; i < n; i++) { int dis = 0; for (int j = i + 1; j <= n; j++) { dis = min(j - i, abs(x - i) + 1 + abs(y - j)); cnt[dis]++; // cout << i << " " << dis << " " << j << endl; } } for (int i = 1; i < n; i++) { cout << cnt[i] << endl; } }
replace
8
9
8
9
0
p02726
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define mp make_pair #define all(x) (x).begin(), (x).end() #define endl '\n' typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int mod = 1e9 + 7; // const int mod=998244353; const double eps = 1e-10; const double pi = acos(-1.0); const int maxn = 2e3 + 10; const ll inf = 0x3f3f3f3f; const int dir[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}}; int ans[maxn]; // Dijstra struct Edge { int u, v, w, next; } e[maxn]; int head[maxn], cnt, n, m, s, vis[maxn], dis[maxn]; struct node { int w, now; inline bool operator<(const node &x) const // 重载运算符把最小的元素放在堆顶(大根堆) { return w > x.w; // 这里注意符号要为'>' } }; priority_queue<node> q; // 优先队列,其实这里一般使用一个pair,但为了方便理解所以用的结构体 inline void add(int u, int v, int w) { e[++cnt].u = u; // 这句话对于此题不需要,但在缩点之类的问题还是有用的 e[cnt].v = v; e[cnt].w = w; e[cnt].next = head[u]; // 存储该点的下一条边 head[u] = cnt; // 更新目前该点的最后一条边(就是这一条边) } // 链式前向星加边 void dijkstra() { for (int i = 1; i <= n; i++) { dis[i] = inf; } dis[s] = 0; // 赋初值 q.push((node){0, s}); while (!q.empty()) // 堆为空即为所有点都更新 { node x = q.top(); q.pop(); int u = x.now; if (dis[u] < x.w) continue; for (int i = head[u]; i; i = e[i].next) // 搜索堆顶所有连边 { int v = e[i].v; if (dis[v] > dis[u] + e[i].w) { dis[v] = dis[u] + e[i].w; // 松弛操作 q.push((node){dis[v], v}); // 把新遍历到的点加入堆中 } } } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); // freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); int x, y; cin >> n >> x >> y; for (int i = 1; i < n; i++) { add(i, i + 1, 1); add(i + 1, i, 1); } add(x, y, 1); add(y, x, 1); for (int i = 1; i <= n; i++) { s = i; dijkstra(); for (int j = i + 1; j <= n; j++) ans[dis[j]]++; } for (int i = 1; i < n; i++) cout << ans[i] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define mp make_pair #define all(x) (x).begin(), (x).end() #define endl '\n' typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int mod = 1e9 + 7; // const int mod=998244353; const double eps = 1e-10; const double pi = acos(-1.0); const int maxn = 2e4 + 10; const ll inf = 0x3f3f3f3f; const int dir[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}}; int ans[maxn]; // Dijstra struct Edge { int u, v, w, next; } e[maxn]; int head[maxn], cnt, n, m, s, vis[maxn], dis[maxn]; struct node { int w, now; inline bool operator<(const node &x) const // 重载运算符把最小的元素放在堆顶(大根堆) { return w > x.w; // 这里注意符号要为'>' } }; priority_queue<node> q; // 优先队列,其实这里一般使用一个pair,但为了方便理解所以用的结构体 inline void add(int u, int v, int w) { e[++cnt].u = u; // 这句话对于此题不需要,但在缩点之类的问题还是有用的 e[cnt].v = v; e[cnt].w = w; e[cnt].next = head[u]; // 存储该点的下一条边 head[u] = cnt; // 更新目前该点的最后一条边(就是这一条边) } // 链式前向星加边 void dijkstra() { for (int i = 1; i <= n; i++) { dis[i] = inf; } dis[s] = 0; // 赋初值 q.push((node){0, s}); while (!q.empty()) // 堆为空即为所有点都更新 { node x = q.top(); q.pop(); int u = x.now; if (dis[u] < x.w) continue; for (int i = head[u]; i; i = e[i].next) // 搜索堆顶所有连边 { int v = e[i].v; if (dis[v] > dis[u] + e[i].w) { dis[v] = dis[u] + e[i].w; // 松弛操作 q.push((node){dis[v], v}); // 把新遍历到的点加入堆中 } } } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); // freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); int x, y; cin >> n >> x >> y; for (int i = 1; i < n; i++) { add(i, i + 1, 1); add(i + 1, i, 1); } add(x, y, 1); add(y, x, 1); for (int i = 1; i <= n; i++) { s = i; dijkstra(); for (int j = i + 1; j <= n; j++) ans[dis[j]]++; } for (int i = 1; i < n; i++) cout << ans[i] << endl; return 0; }
replace
15
16
15
16
0
p02727
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int x, y, a, b, c; cin >> x >> y >> a >> b >> c; vector<int> red(a), green(b), white(c); for (int i = 0; i < a; i++) cin >> red[i]; for (int i = 0; i < b; i++) cin >> green[i]; for (int i = 0; i < c; i++) cin >> white[i]; sort(red.rbegin(), red.rend()); sort(green.rbegin(), green.rend()); sort(white.rbegin(), white.rend()); long long ans = 0; for (int i = 0; i < x; i++) ans += red[i]; for (int i = 0; i < y; i++) ans += green[i]; int last_r = x - 1, last_g = y - 1; int idx = 0; auto upd_red = [&]() { ans -= red[last_r]; last_r--; ans += white[idx]; idx++; }; auto upd_green = [&]() { ans -= green[last_g]; last_g--; ans += white[idx]; idx++; }; while (1) { if (last_r < 0 && last_g < 0) break; if (idx == c) break; if (last_r < 0) { // greenを交換 if (green[last_g] >= white[idx]) break; upd_green(); continue; } if (last_g < 0) { // redを交換 if (red[last_r] >= white[idx]) break; upd_red(); continue; } if (red[last_r] < green[last_g]) { // redを交換 if (red[last_r] >= white[idx]) break; upd_red(); continue; } if (green[last_g] < red[last_r]) { // greenを交換 if (green[last_g] >= white[idx]) break; upd_green(); continue; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int x, y, a, b, c; cin >> x >> y >> a >> b >> c; vector<int> red(a), green(b), white(c); for (int i = 0; i < a; i++) cin >> red[i]; for (int i = 0; i < b; i++) cin >> green[i]; for (int i = 0; i < c; i++) cin >> white[i]; sort(red.rbegin(), red.rend()); sort(green.rbegin(), green.rend()); sort(white.rbegin(), white.rend()); long long ans = 0; for (int i = 0; i < x; i++) ans += red[i]; for (int i = 0; i < y; i++) ans += green[i]; int last_r = x - 1, last_g = y - 1; int idx = 0; auto upd_red = [&]() { ans -= red[last_r]; last_r--; ans += white[idx]; idx++; }; auto upd_green = [&]() { ans -= green[last_g]; last_g--; ans += white[idx]; idx++; }; while (1) { if (last_r < 0 && last_g < 0) break; if (idx == c) break; if (last_r < 0) { // greenを交換 if (green[last_g] >= white[idx]) break; upd_green(); continue; } if (last_g < 0) { // redを交換 if (red[last_r] >= white[idx]) break; upd_red(); continue; } if (red[last_r] < green[last_g]) { // redを交換 if (red[last_r] >= white[idx]) break; upd_red(); continue; } // greenを交換 if (green[last_g] >= white[idx]) break; upd_green(); } cout << ans << endl; }
replace
64
71
64
68
TLE
p02727
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long #define rep(i, n) for (int i = 0; i < (n); i++) int X, Y, A, B, C; priority_queue<int, vector<int>, greater<int>> pq; vector<int> a, b, c; int ans; int max_ans = 0; void update(int x) { if (pq.size() != Y) { ans += x; pq.push(x); } else { int v = pq.top(); pq.pop(); ans -= v; x = max(x, v); pq.push(x); ans += x; } } signed main() { cin >> X >> Y >> A >> B >> C; int v; rep(i, A) { cin >> v; a.push_back(v); } rep(i, B) { cin >> v; b.push_back(v); } rep(i, C) { cin >> v; c.push_back(v); } sort(a.rbegin(), a.rend()); sort(b.rbegin(), b.rend()); sort(c.rbegin(), c.rend()); int aa = max(X - C, 0ll), cc = min(X, C); rep(i, B) update(b[i]); rep(i, C) { if (i < cc) ans += c[i]; else update(c[i]); } rep(i, A) { if (i < aa) ans += a[i]; else { ans += a[i]; ans -= c[cc - 1 - (i - aa)]; update(c[cc - 1 - (i - aa)]); } max_ans = max(ans, max_ans); } cout << max_ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define rep(i, n) for (int i = 0; i < (n); i++) int X, Y, A, B, C; priority_queue<int, vector<int>, greater<int>> pq; vector<int> a, b, c; int ans; int max_ans = 0; void update(int x) { if (pq.size() != Y) { ans += x; pq.push(x); } else { int v = pq.top(); pq.pop(); ans -= v; x = max(x, v); pq.push(x); ans += x; } } signed main() { cin >> X >> Y >> A >> B >> C; int v; rep(i, A) { cin >> v; a.push_back(v); } rep(i, B) { cin >> v; b.push_back(v); } rep(i, C) { cin >> v; c.push_back(v); } sort(a.rbegin(), a.rend()); sort(b.rbegin(), b.rend()); sort(c.rbegin(), c.rend()); int aa = max(X - C, 0ll), cc = min(X, C); rep(i, B) update(b[i]); rep(i, C) { if (i < cc) ans += c[i]; else update(c[i]); } max_ans = ans; rep(i, min(X, A)) { if (i < aa) ans += a[i]; else { ans += a[i]; ans -= c[cc - 1 - (i - aa)]; update(c[cc - 1 - (i - aa)]); } max_ans = max(ans, max_ans); } cout << max_ans << endl; return 0; }
replace
57
58
57
59
0
p02727
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (long long i = 0; i < (long long)(n); i++) #define REP(i, k, n) for (long long i = k; i < (long long)(n); i++) #define all(a) a.begin(), a.end() #define eb emplace_back #define lb(v, k) (lower_bound(all(v), k) - v.begin()) #define ub(v, k) (upper_bound(all(v), k) - v.begin()) #define fi first #define se second #define pi M_PI #define PQ(T) priority_queue<T> #define SPQ(T) priority_queue<T, vector<T>, greater<T>> using ll = long long; using P = pair<ll, ll>; using PP = tuple<ll, ll, ll>; using S = multiset<ll>; using vi = vector<ll>; using vvi = vector<vi>; using vvvi = vector<vvi>; const ll inf = 1001001001001001; const int INF = 1001001001; const int mod = 1000000007; const double eps = 1e-10; template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> void out(T a) { cout << a << '\n'; } template <class T> void outp(T a) { cout << '(' << a.fi << ',' << a.se << ')' << '\n'; } template <class T> void outvp(T v) { rep(i, v.size()) cout << '(' << v[i].fi << ',' << v[i].se << ')'; cout << '\n'; } template <class T> void outv(T v) { rep(i, v.size()) { if (i) cout << ' '; cout << v[i]; } cout << '\n'; } template <class T> void outvv(T v) { rep(i, v.size()) outv(v[i]); } template <class T> bool isin(T x, T l, T r) { return (l) <= (x) && (x) <= (r); } template <class T> void YesNo(T b) { if (b) out("Yes"); else out("No"); } void decimal(int x) { cout << fixed << setprecision(x); } ll GCD(ll a, ll b) { if (b == 0) return a; return GCD(b, a % b); } ll LCM(ll a, ll b) { return (a / GCD(a, b)) * (b / GCD(a, b)) * GCD(a, b); } ll POW(ll a, ll b) { a %= mod; if (b == 0) return 1; if (b & 1) return a * POW(a, b - 1) % mod; ll k = POW(a, b / 2); return k * k % mod; } vi calc(ll x) { vi res; while (x > 0) { res.eb(x % 10); x /= 10; } reverse(all(res)); return res; } void solve() { ll x, y, a, b, c; cin >> x >> y >> a >> b >> c; vi p(a), q(a), r(a); rep(i, a) cin >> p[i]; rep(i, b) cin >> q[i]; rep(i, c) cin >> r[i]; sort(all(p)); reverse(all(p)); sort(all(q)); reverse(all(q)); vi v; rep(i, x) v.eb(p[i]); rep(i, y) v.eb(q[i]); rep(i, c) v.eb(r[i]); sort(all(v)); reverse(all(v)); ll ans = 0; rep(i, x + y) ans += v[i]; out(ans); } signed main() { cin.tie(0); ios::sync_with_stdio(false); solve(); }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (long long i = 0; i < (long long)(n); i++) #define REP(i, k, n) for (long long i = k; i < (long long)(n); i++) #define all(a) a.begin(), a.end() #define eb emplace_back #define lb(v, k) (lower_bound(all(v), k) - v.begin()) #define ub(v, k) (upper_bound(all(v), k) - v.begin()) #define fi first #define se second #define pi M_PI #define PQ(T) priority_queue<T> #define SPQ(T) priority_queue<T, vector<T>, greater<T>> using ll = long long; using P = pair<ll, ll>; using PP = tuple<ll, ll, ll>; using S = multiset<ll>; using vi = vector<ll>; using vvi = vector<vi>; using vvvi = vector<vvi>; const ll inf = 1001001001001001; const int INF = 1001001001; const int mod = 1000000007; const double eps = 1e-10; template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> void out(T a) { cout << a << '\n'; } template <class T> void outp(T a) { cout << '(' << a.fi << ',' << a.se << ')' << '\n'; } template <class T> void outvp(T v) { rep(i, v.size()) cout << '(' << v[i].fi << ',' << v[i].se << ')'; cout << '\n'; } template <class T> void outv(T v) { rep(i, v.size()) { if (i) cout << ' '; cout << v[i]; } cout << '\n'; } template <class T> void outvv(T v) { rep(i, v.size()) outv(v[i]); } template <class T> bool isin(T x, T l, T r) { return (l) <= (x) && (x) <= (r); } template <class T> void YesNo(T b) { if (b) out("Yes"); else out("No"); } void decimal(int x) { cout << fixed << setprecision(x); } ll GCD(ll a, ll b) { if (b == 0) return a; return GCD(b, a % b); } ll LCM(ll a, ll b) { return (a / GCD(a, b)) * (b / GCD(a, b)) * GCD(a, b); } ll POW(ll a, ll b) { a %= mod; if (b == 0) return 1; if (b & 1) return a * POW(a, b - 1) % mod; ll k = POW(a, b / 2); return k * k % mod; } vi calc(ll x) { vi res; while (x > 0) { res.eb(x % 10); x /= 10; } reverse(all(res)); return res; } void solve() { ll x, y, a, b, c; cin >> x >> y >> a >> b >> c; vi p(a), q(b), r(c); rep(i, a) cin >> p[i]; rep(i, b) cin >> q[i]; rep(i, c) cin >> r[i]; sort(all(p)); reverse(all(p)); sort(all(q)); reverse(all(q)); vi v; rep(i, x) v.eb(p[i]); rep(i, y) v.eb(q[i]); rep(i, c) v.eb(r[i]); sort(all(v)); reverse(all(v)); ll ans = 0; rep(i, x + y) ans += v[i]; out(ans); } signed main() { cin.tie(0); ios::sync_with_stdio(false); solve(); }
replace
91
92
91
92
0
p02727
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll X, Y, A, B, C; cin >> X >> Y >> A >> B >> C; vector<ll> red(A), green(B), none(C); for (ll i = 0; i < A; ++i) cin >> red[i]; for (ll i = 0; i < B; ++i) cin >> green[i]; for (ll i = 0; i < C; ++i) cin >> none[i]; sort(red.begin(), red.end(), greater<ll>()); sort(green.begin(), green.end(), greater<ll>()); sort(none.begin(), none.end(), greater<ll>()); ll r_idx = X - 1, g_idx = Y - 1; ll t_idx = 0; while (true) { // true -> red // false -> green ll min_in_two = min(red[r_idx], green[g_idx]); if (min_in_two >= none[t_idx]) break; // red if (min_in_two == red[r_idx]) { red[r_idx] = none[t_idx]; t_idx++; r_idx--; } else { green[g_idx] = none[t_idx]; t_idx++; g_idx--; } } cout << accumulate(red.begin(), red.begin() + X, 0) + accumulate(green.begin(), green.begin() + Y, 0) << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll X, Y, A, B, C; cin >> X >> Y >> A >> B >> C; vector<ll> red(A), green(B), none(C); for (ll i = 0; i < A; ++i) cin >> red[i]; for (ll i = 0; i < B; ++i) cin >> green[i]; for (ll i = 0; i < C; ++i) cin >> none[i]; sort(red.begin(), red.end(), greater<ll>()); sort(green.begin(), green.end(), greater<ll>()); sort(none.begin(), none.end(), greater<ll>()); vector<ll> v(X + Y + C); for (int i = 0; i < X; ++i) v[i] = red[i]; for (int i = 0; i < Y; ++i) v[i + X] = green[i]; for (int i = 0; i < C; ++i) v[i + X + Y] = none[i]; sort(v.begin(), v.end(), greater<ll>()); ll ans = 0; for (ll i = 0; i < X + Y; ++i) ans += v[i]; cout << ans << endl; }
replace
17
39
17
29
0
p02727
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long struct apple { int color; // 0 is X 1 is Y 2 is ALL ll value; }; apple t[222222]; bool cmp(apple a, apple b) { return a.value > b.value; } int main() { int n, b, i, j, k, x, y, z, s0, s1, s2; cin >> x >> y >> s0 >> s1 >> s2; for (i = 0; i < s0; i++) { cin >> t[i].value; t[i].color = 0; } for (; i < s0 + s1; i++) { cin >> t[i].value; t[i].color = 1; } for (; i < s0 + s1 + s2; i++) { cin >> t[i].value; t[i].color = 2; } sort(t, t + s0 + s1 + s2, cmp); ll c3 = 0, c1 = 0, c2 = 0, res = 0; for (i = 0; i < s0 + s1 + s2; i++) { if (c1 + c2 + c3 == x + y) break; if (t[i].color == 0) { if (c1 == x) continue; c1++; res += t[i].value; } if (t[i].color == 1) { if (c2 == y) continue; c2++; res += t[i].value; } if (t[i].color == 2) { c3++; res += t[i].value; } } cout << res; }
#include <bits/stdc++.h> using namespace std; #define ll long long struct apple { int color; // 0 is X 1 is Y 2 is ALL ll value; }; apple t[333333]; bool cmp(apple a, apple b) { return a.value > b.value; } int main() { int n, b, i, j, k, x, y, z, s0, s1, s2; cin >> x >> y >> s0 >> s1 >> s2; for (i = 0; i < s0; i++) { cin >> t[i].value; t[i].color = 0; } for (; i < s0 + s1; i++) { cin >> t[i].value; t[i].color = 1; } for (; i < s0 + s1 + s2; i++) { cin >> t[i].value; t[i].color = 2; } sort(t, t + s0 + s1 + s2, cmp); ll c3 = 0, c1 = 0, c2 = 0, res = 0; for (i = 0; i < s0 + s1 + s2; i++) { if (c1 + c2 + c3 == x + y) break; if (t[i].color == 0) { if (c1 == x) continue; c1++; res += t[i].value; } if (t[i].color == 1) { if (c2 == y) continue; c2++; res += t[i].value; } if (t[i].color == 2) { c3++; res += t[i].value; } } cout << res; }
replace
7
8
7
8
0
p02727
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define fastio() \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define test() \ int t; \ cin >> t; \ for (int test = 1; test <= t; test++) #define pb push_back #define nl cout << "\n" #define F first #define S second #define all(x) x.begin(), x.end() template <class C> void min_self(C &a, C b) { a = min(a, b); } template <class C> void max_self(C &a, C b) { a = max(a, b); } const ll MOD = 1000000007; ll mod(ll n, ll m = MOD) { n %= m, n += m, n %= m; return n; } const int MAXN = 1e5 + 5; const int LOGN = 21; const ll INF = 1e14; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; template <class T1, class T2, class T3> void add(T1 &x, T2 y, T3 m = MOD) { x += y; if (x >= m) x -= m; } template <class T1, class T2, class T3> void sub(T1 &x, T2 y, T3 m = MOD) { x -= y; if (x < 0) x += m; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif fastio(); ll x, y, a, b, c; cin >> x >> y >> a >> b >> c; vector<ll> p(a), q(b), r(c); for (int i = 0; i < a; i++) cin >> p[i]; for (int i = 0; i < b; i++) cin >> q[i]; for (int i = 0; i < c; i++) cin >> r[i]; sort(p.rbegin(), p.rend()); sort(q.rbegin(), q.rend()); sort(r.rbegin(), r.rend()); int i = 0, j = 0, k = 0, red = 0, green = 0, ambiguous = 0; ll ans = 0; while (red < x || green < y) { ll red_apple = ((i < a && red < x) ? p[i] : 0); ll green_apple = ((j < b && green < y) ? q[j] : 0); ll other = (k < c ? r[k] : 0); // cout<<red<<" "<<green<<" "<<ambiguous,nl; // cout<<red_apple<<" "<<green_apple<<" "<<other,nl;nl; if (red + green + ambiguous >= x + y) break; if (red < x && red_apple >= green_apple && red_apple >= other) { ans += red_apple; i++; red++; } else if (green < y && green_apple >= red_apple && green_apple >= other) { ans += green_apple; j++; green++; } else if (red + green + ambiguous < x + y) { ans += other; k++; ambiguous++; } } cout << ans, nl; cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; return 0; }
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define fastio() \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define test() \ int t; \ cin >> t; \ for (int test = 1; test <= t; test++) #define pb push_back #define nl cout << "\n" #define F first #define S second #define all(x) x.begin(), x.end() template <class C> void min_self(C &a, C b) { a = min(a, b); } template <class C> void max_self(C &a, C b) { a = max(a, b); } const ll MOD = 1000000007; ll mod(ll n, ll m = MOD) { n %= m, n += m, n %= m; return n; } const int MAXN = 1e5 + 5; const int LOGN = 21; const ll INF = 1e14; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; template <class T1, class T2, class T3> void add(T1 &x, T2 y, T3 m = MOD) { x += y; if (x >= m) x -= m; } template <class T1, class T2, class T3> void sub(T1 &x, T2 y, T3 m = MOD) { x -= y; if (x < 0) x += m; } int main() { fastio(); ll x, y, a, b, c; cin >> x >> y >> a >> b >> c; vector<ll> p(a), q(b), r(c); for (int i = 0; i < a; i++) cin >> p[i]; for (int i = 0; i < b; i++) cin >> q[i]; for (int i = 0; i < c; i++) cin >> r[i]; sort(p.rbegin(), p.rend()); sort(q.rbegin(), q.rend()); sort(r.rbegin(), r.rend()); int i = 0, j = 0, k = 0, red = 0, green = 0, ambiguous = 0; ll ans = 0; while (red < x || green < y) { ll red_apple = ((i < a && red < x) ? p[i] : 0); ll green_apple = ((j < b && green < y) ? q[j] : 0); ll other = (k < c ? r[k] : 0); // cout<<red<<" "<<green<<" "<<ambiguous,nl; // cout<<red_apple<<" "<<green_apple<<" "<<other,nl;nl; if (red + green + ambiguous >= x + y) break; if (red < x && red_apple >= green_apple && red_apple >= other) { ans += red_apple; i++; red++; } else if (green < y && green_apple >= red_apple && green_apple >= other) { ans += green_apple; j++; green++; } else if (red + green + ambiguous < x + y) { ans += other; k++; ambiguous++; } } cout << ans, nl; cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; return 0; }
delete
51
55
51
51
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p02727
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; typedef vector<ll> vl; typedef vector<vector<ll>> vvl; typedef vector<vector<vector<ll>>> vvvl; struct edge { ll to, cost; }; const int inf = 1 << 28; const ll INF = 1LL << 53; const int COMBMAX = 500005; const ll MOD = 1e9 + 7; #define _GLIBCXX_DEBUG #define rep(i, n) for (int i = 0; i < n; ++i) #define repf(i, n) for (int i = 0; i <= n; ++i) #define rep1(i, n) for (int i = 1; i <= n; ++i) #define eachdo(v, e) for (const auto &e : v) #define all(v) (v).begin(), (v).end() #define lower_index(v, e) \ (ll) distance(v.begin(), lower_bound((v).begin(), (v).end(), e)) #define upper_index(v, e) \ (ll) distance(v.begin(), upper_bound((v).begin(), (v).end(), e)) ll mpow(ll a, ll n, ll mod = MOD) { ll res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } template <class T1, class T2> ll bcount(T1 v, T2 a) { return upper_index(v, a) - lower_index(v, a); } template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> void debug(T v) { rep(i, v.size()) cout << v[i] << " "; cout << endl; } template <class T> void debug2(T v) { rep(i, v.size()) { rep(j, v[i].size()) cout << v[i][j] << " "; cout << endl; } } template <class T> void rdv(T &v) { rep(i, v.size()) cin >> v[i]; } template <class T> void rdvv(T &v) { rep(i, v.size()) { rep(j, v[i].size()) cin >> v[i][j]; } } // multimap // mmap.emplace(key,value); // auto ngw = list.equal_range(""); // for(auto e = ngw.first; it != ngw.second ; ++e) int main() { ll X, Y, A, B, C; cin >> X >> Y >> A >> B >> C; vl p(A); rdv(p); vl q(B); rdv(q); vl r(C); rdv(r); sort(all(p)); sort(all(q)); sort(all(r)); reverse(all(p)); reverse(all(q)); reverse(all(r)); vl cont(X + Y + 1, 0); ll atep = 0, ateq = 0; rep1(i, X + Y) { cont[i] += cont[i - 1]; if (X <= atep || (p[atep] <= q[ateq] && ateq < Y)) { cont[i] += q[ateq]; ateq++; } else { cont[i] += p[atep]; atep++; } // cout << atep << " " << ateq << endl; } // debug(cont); vl cr(C + 1, 0); rep1(i, C) { cr[i] = cr[i - 1] + r[i - 1]; } ll ans = 0; rep(i, C + 1) { chmax(ans, cr[i] + cont[X + Y - i]); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; typedef vector<ll> vl; typedef vector<vector<ll>> vvl; typedef vector<vector<vector<ll>>> vvvl; struct edge { ll to, cost; }; const int inf = 1 << 28; const ll INF = 1LL << 53; const int COMBMAX = 500005; const ll MOD = 1e9 + 7; #define _GLIBCXX_DEBUG #define rep(i, n) for (int i = 0; i < n; ++i) #define repf(i, n) for (int i = 0; i <= n; ++i) #define rep1(i, n) for (int i = 1; i <= n; ++i) #define eachdo(v, e) for (const auto &e : v) #define all(v) (v).begin(), (v).end() #define lower_index(v, e) \ (ll) distance(v.begin(), lower_bound((v).begin(), (v).end(), e)) #define upper_index(v, e) \ (ll) distance(v.begin(), upper_bound((v).begin(), (v).end(), e)) ll mpow(ll a, ll n, ll mod = MOD) { ll res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } template <class T1, class T2> ll bcount(T1 v, T2 a) { return upper_index(v, a) - lower_index(v, a); } template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> void debug(T v) { rep(i, v.size()) cout << v[i] << " "; cout << endl; } template <class T> void debug2(T v) { rep(i, v.size()) { rep(j, v[i].size()) cout << v[i][j] << " "; cout << endl; } } template <class T> void rdv(T &v) { rep(i, v.size()) cin >> v[i]; } template <class T> void rdvv(T &v) { rep(i, v.size()) { rep(j, v[i].size()) cin >> v[i][j]; } } // multimap // mmap.emplace(key,value); // auto ngw = list.equal_range(""); // for(auto e = ngw.first; it != ngw.second ; ++e) int main() { ll X, Y, A, B, C; cin >> X >> Y >> A >> B >> C; vl p(A); rdv(p); vl q(B); rdv(q); vl r(C); rdv(r); sort(all(p)); sort(all(q)); sort(all(r)); reverse(all(p)); reverse(all(q)); reverse(all(r)); vl cont(X + Y + 1, 0); ll atep = 0, ateq = 0; rep1(i, X + Y) { cont[i] += cont[i - 1]; if (X <= atep || (p[atep] <= q[ateq] && ateq < Y)) { cont[i] += q[ateq]; ateq++; } else { cont[i] += p[atep]; atep++; } // cout << atep << " " << ateq << endl; } // debug(cont); vl cr(C + 1, 0); rep1(i, C) { cr[i] = cr[i - 1] + r[i - 1]; } ll ans = 0; rep(i, min(C + 1, X + Y + 1)) { chmax(ans, cr[i] + cont[X + Y - i]); } cout << ans << endl; return 0; }
replace
102
103
102
103
0
p02727
C++
Runtime Error
#define ll long long #define pub push_back #define pob pop_back #define puf push_front #define pof pop_front #define mp make_pair #define fo(i, n) for (ll i = 0; i < n; i++) // #include<bits/stdc++.h> #include <algorithm> #include <cmath> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> ll pi = acos(-1); ll z = 1000000007; ll inf = 100000000000000000; ll p1 = 37; ll p2 = 53; ll mod1 = 202976689; ll mod2 = 203034253; ll gcd(ll a, ll b) { if (b > a) return gcd(b, a); if (b == 0) return a; return gcd(b, a % b); } ll power(ll a, ll b, ll p) { if (b == 0) return 1; ll c = power(a, b / 2, p); if (b % 2 == 0) return ((c * c) % p); else return ((((c * c) % p) * a) % p); } ll inverse(ll a, ll n) { return power(a, n - 2, n); } ll max(ll a, ll b) { if (a > b) return a; return b; } ll left(ll i) { return ((2 * i) + 1); } ll right(ll i) { return (2 * (i + 1)); } // ios_base::sync_with_stdio(0); // cin.tie(0); cout.tie(0); using namespace std; void solve() { ll x, y, a, b, c; cin >> x >> y >> a >> b >> c; ll p[a], q[b], r[c]; fo(i, a) { cin >> p[i]; } fo(i, b) { cin >> q[i]; } fo(i, c) { cin >> r[i]; } sort(p, p + a); sort(q, q + b); sort(r, r + c); reverse(p, p + a); reverse(q, q + b); reverse(r, r + c); /*fo(i , a) { cout << p[i] << ' '; } cout << endl ;*/ multiset<ll> red, green; fo(i, x) { red.insert(p[i]); } fo(i, y) { green.insert(q[i]); } fo(i, c) { ll curr = r[i]; ll curr_r = (*(red.begin())); ll curr_g = (*(green.begin())); if (curr_r < curr_g) { if (curr_r < curr) { red.erase(red.begin()); red.insert(curr); } } else { if (curr_g < curr) { green.erase(green.begin()); green.insert(curr); } } } ll ans = 0; auto itr = red.begin(); for (; itr != red.end(); itr++) { ans += (*itr); } for (auto itrg = green.begin(); itrg != green.end(); itrg++) { ans += (*itrg); } cout << ans << endl; return; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("inputf.txt", "r", stdin); freopen("outputf.txt", "w", stdout); freopen("error.txt", "w", stderr); #endif ll t; // cin >> t ; t = 1; while (t--) { solve(); } return 0; }
#define ll long long #define pub push_back #define pob pop_back #define puf push_front #define pof pop_front #define mp make_pair #define fo(i, n) for (ll i = 0; i < n; i++) // #include<bits/stdc++.h> #include <algorithm> #include <cmath> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> ll pi = acos(-1); ll z = 1000000007; ll inf = 100000000000000000; ll p1 = 37; ll p2 = 53; ll mod1 = 202976689; ll mod2 = 203034253; ll gcd(ll a, ll b) { if (b > a) return gcd(b, a); if (b == 0) return a; return gcd(b, a % b); } ll power(ll a, ll b, ll p) { if (b == 0) return 1; ll c = power(a, b / 2, p); if (b % 2 == 0) return ((c * c) % p); else return ((((c * c) % p) * a) % p); } ll inverse(ll a, ll n) { return power(a, n - 2, n); } ll max(ll a, ll b) { if (a > b) return a; return b; } ll left(ll i) { return ((2 * i) + 1); } ll right(ll i) { return (2 * (i + 1)); } // ios_base::sync_with_stdio(0); // cin.tie(0); cout.tie(0); using namespace std; void solve() { ll x, y, a, b, c; cin >> x >> y >> a >> b >> c; ll p[a], q[b], r[c]; fo(i, a) { cin >> p[i]; } fo(i, b) { cin >> q[i]; } fo(i, c) { cin >> r[i]; } sort(p, p + a); sort(q, q + b); sort(r, r + c); reverse(p, p + a); reverse(q, q + b); reverse(r, r + c); /*fo(i , a) { cout << p[i] << ' '; } cout << endl ;*/ multiset<ll> red, green; fo(i, x) { red.insert(p[i]); } fo(i, y) { green.insert(q[i]); } fo(i, c) { ll curr = r[i]; ll curr_r = (*(red.begin())); ll curr_g = (*(green.begin())); if (curr_r < curr_g) { if (curr_r < curr) { red.erase(red.begin()); red.insert(curr); } } else { if (curr_g < curr) { green.erase(green.begin()); green.insert(curr); } } } ll ans = 0; auto itr = red.begin(); for (; itr != red.end(); itr++) { ans += (*itr); } for (auto itrg = green.begin(); itrg != green.end(); itrg++) { ans += (*itrg); } cout << ans << endl; return; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); /*#ifndef ONLINE_JUDGE freopen("inputf.txt" , "r" , stdin) ; freopen("outputf.txt" , "w" , stdout) ; freopen("error.txt" , "w" , stderr) ; #endif*/ ll t; // cin >> t ; t = 1; while (t--) { solve(); } return 0; }
replace
112
117
112
117
-11
p02727
C++
Time Limit Exceeded
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pp; const int INF = 1e9; const int MOD = 1000000007; const double pi = 3.141592653589793238; ll gcd(ll a, ll b) { return __gcd(a, b); } // 最大公約数 ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } // 最大公倍数 void printV(vector<int> &v); void printVV(vector<vector<int>> &vv); void printPQ(priority_queue<int> pq); int main() { int X, Y, A, B, C; cin >> X >> Y >> A >> B >> C; vector<int> QA(A); vector<int> QB(B); vector<int> QC; for (int i = 0; i < A; i++) cin >> QA.at(i); for (int i = 0; i < B; i++) cin >> QB.at(i); for (int i = 0; i < C; i++) { int q; cin >> q; QC.push_back(q); }; sort(QA.begin(), QA.end(), greater<int>()); sort(QB.begin(), QB.end(), greater<int>()); sort(QC.begin(), QC.end(), greater<int>()); for (int i = 0; i < X; i++) { QC.push_back(QA.at(i)); } for (int i = 0; i < Y; i++) { QC.push_back(QB.at(i)); } sort(QC.begin(), QC.end(), greater<int>()); int64_t sum = 0; for (int i = 0; i < X + Y; i++) { sum += QC.at(i); } cout << sum << endl; } // ベクターの中身を全部出力 void printV(vector<int> &v) { cout << " [ "; for (int i = 0; i < (int)v.size(); i++) { cout << v.at(i) << " "; } cout << "]" << endl; } void printVV(vector<vector<int>> &vv) { cout << "{" << endl; for (int i = 0; i < (int)vv.size(); i++) { cout << " [ "; for (int j = 0; j < (int)vv.at(i).size(); j++) { cout << vv.at(i).at(j) << " "; } cout << "]," << endl; } cout << "}" << endl; } void printPQ(priority_queue<int> pq) { cout << "---------- QA ----------" << endl; while (!pq.empty()) { cout << pq.top() << endl; pq.pop(); } }
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pp; const int INF = 1e9; const int MOD = 1000000007; const double pi = 3.141592653589793238; ll gcd(ll a, ll b) { return __gcd(a, b); } // 最大公約数 ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } // 最大公倍数 void printV(vector<int> &v); void printVV(vector<vector<int>> &vv); void printPQ(priority_queue<int> pq); int main() { int X, Y, A, B, C; cin >> X >> Y >> A >> B >> C; vector<int> QA(A); vector<int> QB(B); vector<int> QC; for (int i = 0; i < A; i++) cin >> QA.at(i); for (int i = 0; i < B; i++) cin >> QB.at(i); for (int i = 0; i < C; i++) { int q; cin >> q; QC.push_back(q); }; sort(QA.begin(), QA.end(), greater<int>()); sort(QB.begin(), QB.end(), greater<int>()); // sort(QC.begin(), QC.end(), greater<int>()); for (int i = 0; i < X; i++) { QC.push_back(QA.at(i)); } for (int i = 0; i < Y; i++) { QC.push_back(QB.at(i)); } sort(QC.begin(), QC.end(), greater<int>()); int64_t sum = 0; for (int i = 0; i < X + Y; i++) { sum += QC.at(i); } cout << sum << endl; } // ベクターの中身を全部出力 void printV(vector<int> &v) { cout << " [ "; for (int i = 0; i < (int)v.size(); i++) { cout << v.at(i) << " "; } cout << "]" << endl; } void printVV(vector<vector<int>> &vv) { cout << "{" << endl; for (int i = 0; i < (int)vv.size(); i++) { cout << " [ "; for (int j = 0; j < (int)vv.at(i).size(); j++) { cout << vv.at(i).at(j) << " "; } cout << "]," << endl; } cout << "}" << endl; } void printPQ(priority_queue<int> pq) { cout << "---------- QA ----------" << endl; while (!pq.empty()) { cout << pq.top() << endl; pq.pop(); } }
replace
38
39
38
39
TLE
p02727
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> #define PB push_back #define MP make_pair #define YES cout << "YES" << endl #define Yes cout << "Yes" << endl #define NO cout << "NO" << endl #define No cout << "No" << endl #define INF (1 << 28) #define LLINF (1LL << 60) #define MOD 1000000007 #define REP(i, n) for (int i = 0; i < n; i++) using ll = long long; using namespace std; typedef pair<int, int> P; int main() { int x, y, a, b, c, p[10000], q[10000], r[10000], rg[30000]; cin >> x >> y >> a >> b >> c; for (int i = 0; i < a; i++) cin >> p[i]; for (int i = 0; i < b; i++) cin >> q[i]; for (int i = 0; i < c; i++) cin >> r[i]; sort(p, p + a, greater<>()); sort(q, q + b, greater<>()); sort(r, r + c, greater<>()); for (int i = 0; i < x; i++) rg[i] = p[i]; for (int i = 0; i < y; i++) rg[i + x] = q[i]; for (int i = 0; i < c; i++) rg[i + x + y] = r[i]; sort(rg, rg + x + y + c, greater<>()); ll ans = 0; for (int i = 0; i < x + y; i++) ans += rg[i]; cout << ans; return 0; }
#include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> #define PB push_back #define MP make_pair #define YES cout << "YES" << endl #define Yes cout << "Yes" << endl #define NO cout << "NO" << endl #define No cout << "No" << endl #define INF (1 << 28) #define LLINF (1LL << 60) #define MOD 1000000007 #define REP(i, n) for (int i = 0; i < n; i++) using ll = long long; using namespace std; typedef pair<int, int> P; int main() { int x, y, a, b, c, p[100000], q[100000], r[100000], rg[300000]; cin >> x >> y >> a >> b >> c; for (int i = 0; i < a; i++) cin >> p[i]; for (int i = 0; i < b; i++) cin >> q[i]; for (int i = 0; i < c; i++) cin >> r[i]; sort(p, p + a, greater<>()); sort(q, q + b, greater<>()); sort(r, r + c, greater<>()); for (int i = 0; i < x; i++) rg[i] = p[i]; for (int i = 0; i < y; i++) rg[i + x] = q[i]; for (int i = 0; i < c; i++) rg[i + x + y] = r[i]; sort(rg, rg + x + y + c, greater<>()); ll ans = 0; for (int i = 0; i < x + y; i++) ans += rg[i]; cout << ans; return 0; }
replace
32
33
32
33
0
p02727
C++
Time Limit Exceeded
#include <bits/stdc++.h> int main() { std::size_t X, Y, A, B, C; std::cin >> X >> Y >> A >> B >> C; std::vector<std::uint64_t> ps(A); std::vector<std::uint64_t> qs(B); std::vector<std::uint64_t> rs(C); for (auto &p : ps) { std::cin >> p; } for (auto &q : qs) { std::cin >> q; } for (auto &r : rs) { std::cin >> r; } const auto gt = [](const std::uint64_t lhs, const std::uint64_t rhs) noexcept -> bool { return lhs > rhs; }; std::sort(ps.begin(), ps.end(), gt); std::sort(qs.begin(), qs.end(), gt); std::sort(rs.begin(), rs.end()); ps.erase(ps.begin() + X, ps.end()); qs.erase(qs.begin() + Y, qs.end()); while (!rs.empty()) { std::cerr << "current status:" << std::endl; std::cerr << "red : "; for (const auto p : ps) { std::cerr << p << ' '; } std::cerr << std::endl; std::cerr << "green: "; for (const auto q : qs) { std::cerr << q << ' '; } std::cerr << std::endl; std::cerr << "cless: "; for (const auto r : rs) { std::cerr << r << ' '; } std::cerr << std::endl; if (std::min(ps.back(), qs.back()) < rs.back()) { if (ps.back() < qs.back()) { ps.pop_back(); ps.insert(std::lower_bound(ps.begin(), ps.end(), rs.back(), gt), rs.back()); } else // qs.back() <= ps.back() { qs.pop_back(); qs.insert(std::lower_bound(qs.begin(), qs.end(), rs.back(), gt), rs.back()); } rs.pop_back(); } else { break; } } std::size_t ans = 0; for (const auto &p : ps) { ans += p; } for (const auto &q : qs) { ans += q; } std::cout << ans << std::endl; return 0; }
#include <bits/stdc++.h> int main() { std::size_t X, Y, A, B, C; std::cin >> X >> Y >> A >> B >> C; std::vector<std::uint64_t> ps(A); std::vector<std::uint64_t> qs(B); std::vector<std::uint64_t> rs(C); for (auto &p : ps) { std::cin >> p; } for (auto &q : qs) { std::cin >> q; } for (auto &r : rs) { std::cin >> r; } const auto gt = [](const std::uint64_t lhs, const std::uint64_t rhs) noexcept -> bool { return lhs > rhs; }; std::sort(ps.begin(), ps.end(), gt); std::sort(qs.begin(), qs.end(), gt); std::sort(rs.begin(), rs.end()); ps.erase(ps.begin() + X, ps.end()); qs.erase(qs.begin() + Y, qs.end()); while (!rs.empty()) { if (std::min(ps.back(), qs.back()) < rs.back()) { if (ps.back() < qs.back()) { ps.pop_back(); ps.insert(std::lower_bound(ps.begin(), ps.end(), rs.back(), gt), rs.back()); } else // qs.back() <= ps.back() { qs.pop_back(); qs.insert(std::lower_bound(qs.begin(), qs.end(), rs.back(), gt), rs.back()); } rs.pop_back(); } else { break; } } std::size_t ans = 0; for (const auto &p : ps) { ans += p; } for (const auto &q : qs) { ans += q; } std::cout << ans << std::endl; return 0; }
delete
33
50
33
33
TLE
p02727
C++
Runtime Error
/* author : Aryan Agarwal, IIT KGP created : 29-June-2020 19:14:58 */ #include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef unsigned long long ull; #define int ll const int INF = (int)2e18; const int MOD = 1000000007; /*more than (10)^9*/ /*7 + 1e9*/ const int PEG = 998244353; /*less than (10)^9*/ /*1 + 7*17*(2)^23*/ long double pie = acos(-1); typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> pii; typedef vector<pii> vpii; #define X first #define Y second #define pb push_back #define sz(a) (ll)(a).size() #define all(a) (a).begin(), (a).end() #define F(i, a, b) for (ll i = a; i <= b; i++) #define RF(i, a, b) for (ll i = a; i >= b; i--) #define Fo(i, a, b, j) for (ll i = a; i <= b; i += j) #define RFo(i, a, b, j) for (ll i = a; i >= b; i -= j) #define in(a, n) F(i, 0, n - 1) cin >> a[i] #define in1(a, n) F(i, 1, n) cin >> a[i] #define out(a, n) F(i, 0, n - 1) cout << a[i] << " " #define out1(a, n) F(i, 1, n) cout << a[i] << " " #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) #define popcount __builtin_popcountll #define pfy cout << "YES" #define pfn cout << "NO" #define pfn1 cout << "-1" // printf negative 1 #define pf1 cout << "1" #define nl cout << "\n" #define watch(x) cout << #x << " is " << x << "\n" #define dbg(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1); template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args); ll binpow(ll x, ll y, ll p); signed main() { #ifndef ONLINE_JUDGE // freopen("input.txt","r",stdin); #endif fast; int x, y, a, b, c; cin >> x >> y >> a >> b >> c; int p[a], q[b], r[c]; in(p, a); in(q, b); in(r, c); sort(p, p + a, greater<int>()); sort(q, p + b, greater<int>()); sort(r, r + c, greater<int>()); vi ans(x + y); F(i, 0, x - 1) { ans[i] = p[i]; } F(i, x, y + x - 1) { ans[i] = q[i - x]; } sort(all(ans)); F(i, 0, min(c, x + y) - 1) { ans[i] = max(ans[i], r[i]); } int anss = 0; F(i, 0, x + y - 1) { anss += ans[i]; } cout << anss; return 0; } /* ########## TIPS ########## # # mod_inverse(n,p) is binpow(n,p-2,p) # # while using ceil() function,always type cast the parameters to double like ceil((1.0*a)/b) # # for creating a 2d vector "vec" with n rows & m columns then initialise it with it 0 # vvi vec(n,vi(m,0)) # vector<vector<int> > vec( n , vector<int> (m, 0)) # # if you want to insert an integer and a pair in a set then, # set <pair<int,int>,int> is wrong # set< pair < pii,int> > is correct // according to my macros # set < pair<pair<int,int> , int> > is correct // pair of a pair & a integer # # if you want just the sum of smallest k elements of a array # use nth_element(arr,arr+n) , # use nth_element(arr,arr+n,greater <int> ()) if you want largest k elements # then take sum of first k elements ,it works in O(n) , # rather than first sorting then taking sum of first k elements, which works in O(n*logn) # # if you want to check that a given no. 'N' is power of 2 # use N&(N-1)==0 , rather than log2(N)==ceil(log2(N)) # # upper_bound is > val in a non-decreasing array # lower_bound is >= val in a non-decreasing array # upper_bound is < val in a non-increasing array (use greater <int> () in 4th parameter) # lower_bound is <= val in a non-increasing array (use greater <int> () in 4th parameter) # # don't use stoi() , it doesn't works for large strings # use stoi() to convert string to integer, (2nd & 3rd parameter are optional) # 1st parameter is string (address of char array) # 2nd parameter is starting index, 0 most of the times # 3rd parameter is base of integer, like 2 (for binary no.s), 10 (for decimel no.s) etc. # # for creating a string 'S' of length 'len' , having each character 'c' # type string S(len,c); while creating the string # # gcd(x-y,x)=gcd(x,y)=gcd(x+y,y) (for all x and y) # gcd(a,b)=gcd(b,a) (for all a and b) # # a+b = a|b + a&b # a+b = a^b + 2*(a&b) # x<<y = x*(2^y) # x>>y = x/(2^y) # */ ll binpow(ll x, ll y, ll p) /* (x^y)%p in O(log y) */ { ll res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { std::cout << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); std::cout.write(names, comma - names) << " : " << arg1 << "\n"; __f(comma + 1, args...); }
/* author : Aryan Agarwal, IIT KGP created : 29-June-2020 19:14:58 */ #include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef unsigned long long ull; #define int ll const int INF = (int)2e18; const int MOD = 1000000007; /*more than (10)^9*/ /*7 + 1e9*/ const int PEG = 998244353; /*less than (10)^9*/ /*1 + 7*17*(2)^23*/ long double pie = acos(-1); typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> pii; typedef vector<pii> vpii; #define X first #define Y second #define pb push_back #define sz(a) (ll)(a).size() #define all(a) (a).begin(), (a).end() #define F(i, a, b) for (ll i = a; i <= b; i++) #define RF(i, a, b) for (ll i = a; i >= b; i--) #define Fo(i, a, b, j) for (ll i = a; i <= b; i += j) #define RFo(i, a, b, j) for (ll i = a; i >= b; i -= j) #define in(a, n) F(i, 0, n - 1) cin >> a[i] #define in1(a, n) F(i, 1, n) cin >> a[i] #define out(a, n) F(i, 0, n - 1) cout << a[i] << " " #define out1(a, n) F(i, 1, n) cout << a[i] << " " #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) #define popcount __builtin_popcountll #define pfy cout << "YES" #define pfn cout << "NO" #define pfn1 cout << "-1" // printf negative 1 #define pf1 cout << "1" #define nl cout << "\n" #define watch(x) cout << #x << " is " << x << "\n" #define dbg(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1); template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args); ll binpow(ll x, ll y, ll p); signed main() { #ifndef ONLINE_JUDGE // freopen("input.txt","r",stdin); #endif fast; int x, y, a, b, c; cin >> x >> y >> a >> b >> c; int p[a], q[b], r[c]; in(p, a); in(q, b); in(r, c); sort(p, p + a, greater<int>()); sort(q, q + b, greater<int>()); sort(r, r + c, greater<int>()); vi ans(x + y); F(i, 0, x - 1) { ans[i] = p[i]; } F(i, x, y + x - 1) { ans[i] = q[i - x]; } sort(all(ans)); F(i, 0, min(c, x + y) - 1) { ans[i] = max(ans[i], r[i]); } int anss = 0; F(i, 0, x + y - 1) { anss += ans[i]; } cout << anss; return 0; } /* ########## TIPS ########## # # mod_inverse(n,p) is binpow(n,p-2,p) # # while using ceil() function,always type cast the parameters to double like ceil((1.0*a)/b) # # for creating a 2d vector "vec" with n rows & m columns then initialise it with it 0 # vvi vec(n,vi(m,0)) # vector<vector<int> > vec( n , vector<int> (m, 0)) # # if you want to insert an integer and a pair in a set then, # set <pair<int,int>,int> is wrong # set< pair < pii,int> > is correct // according to my macros # set < pair<pair<int,int> , int> > is correct // pair of a pair & a integer # # if you want just the sum of smallest k elements of a array # use nth_element(arr,arr+n) , # use nth_element(arr,arr+n,greater <int> ()) if you want largest k elements # then take sum of first k elements ,it works in O(n) , # rather than first sorting then taking sum of first k elements, which works in O(n*logn) # # if you want to check that a given no. 'N' is power of 2 # use N&(N-1)==0 , rather than log2(N)==ceil(log2(N)) # # upper_bound is > val in a non-decreasing array # lower_bound is >= val in a non-decreasing array # upper_bound is < val in a non-increasing array (use greater <int> () in 4th parameter) # lower_bound is <= val in a non-increasing array (use greater <int> () in 4th parameter) # # don't use stoi() , it doesn't works for large strings # use stoi() to convert string to integer, (2nd & 3rd parameter are optional) # 1st parameter is string (address of char array) # 2nd parameter is starting index, 0 most of the times # 3rd parameter is base of integer, like 2 (for binary no.s), 10 (for decimel no.s) etc. # # for creating a string 'S' of length 'len' , having each character 'c' # type string S(len,c); while creating the string # # gcd(x-y,x)=gcd(x,y)=gcd(x+y,y) (for all x and y) # gcd(a,b)=gcd(b,a) (for all a and b) # # a+b = a|b + a&b # a+b = a^b + 2*(a&b) # x<<y = x*(2^y) # x>>y = x/(2^y) # */ ll binpow(ll x, ll y, ll p) /* (x^y)%p in O(log y) */ { ll res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { std::cout << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); std::cout.write(names, comma - names) << " : " << arg1 << "\n"; __f(comma + 1, args...); }
replace
71
72
71
72
0
p02727
C++
Runtime Error
// Nihal Mittal - nihal_47 // Strike First , Strike Hard , No Mercy !! /**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀⠀⠀⠀⠀ ⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀⠀⠀⠀ ⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀ ⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿⠀⠀ ⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧⠀⠀ ⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄⠀⠀ ⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰⠀ ⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧⠀⠀⠀ ⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃⠀⠀⠀ ⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀⠀⠀⠀ ⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁ ⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸⠀ **/ #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define ll long long #define ld long double #define mk make_pair #define pb push_back #define in insert #define se second #define fi first #define mod 1000000007 #define watch(x) cout << (#x) << " is " << (x) << "\n" #define all(v) (v).begin(), (v).end() #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(0); #define pii pair<ll, ll> #define vi(x) vector<x> #define maxn 100005 #define ordered_set \ tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> using namespace std; using namespace __gnu_pbds; signed main() { fast; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ll x, y, a, b, c, i; cin >> x >> y >> a >> b >> c; priority_queue<ll> pq; vector<ll> v1(a), v2(b), v3(c); for (i = 0; i < a; i++) cin >> v1[i]; for (i = 0; i < b; i++) cin >> v2[i]; for (i = 0; i < c; i++) cin >> v3[i]; sort(v1.begin(), v1.end(), greater<ll>()); sort(v2.begin(), v2.end(), greater<ll>()); for (i = 0; i < x; i++) pq.push(v1[i]); for (i = 0; i < y; i++) pq.push(v2[i]); for (i = 0; i < c; i++) pq.push(v3[i]); ll cn = 0, ans = 0; while (cn < x + y) { ans += pq.top(); pq.pop(); cn++; } cout << ans; }
// Nihal Mittal - nihal_47 // Strike First , Strike Hard , No Mercy !! /**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀⠀⠀⠀⠀ ⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀⠀⠀⠀ ⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀ ⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿⠀⠀ ⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧⠀⠀ ⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄⠀⠀ ⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰⠀ ⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧⠀⠀⠀ ⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃⠀⠀⠀ ⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀⠀⠀⠀ ⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁ ⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸⠀ **/ #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define ll long long #define ld long double #define mk make_pair #define pb push_back #define in insert #define se second #define fi first #define mod 1000000007 #define watch(x) cout << (#x) << " is " << (x) << "\n" #define all(v) (v).begin(), (v).end() #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(0); #define pii pair<ll, ll> #define vi(x) vector<x> #define maxn 100005 #define ordered_set \ tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> using namespace std; using namespace __gnu_pbds; signed main() { fast; ll x, y, a, b, c, i; cin >> x >> y >> a >> b >> c; priority_queue<ll> pq; vector<ll> v1(a), v2(b), v3(c); for (i = 0; i < a; i++) cin >> v1[i]; for (i = 0; i < b; i++) cin >> v2[i]; for (i = 0; i < c; i++) cin >> v3[i]; sort(v1.begin(), v1.end(), greater<ll>()); sort(v2.begin(), v2.end(), greater<ll>()); for (i = 0; i < x; i++) pq.push(v1[i]); for (i = 0; i < y; i++) pq.push(v2[i]); for (i = 0; i < c; i++) pq.push(v3[i]); ll cn = 0, ans = 0; while (cn < x + y) { ans += pq.top(); pq.pop(); cn++; } cout << ans; }
replace
47
51
47
48
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p02727
C++
Runtime Error
/* بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ */ // codeforces #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; #define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); #define mp make_pair #define pb push_back #define sz(v) ((int)v.size()) #define all(v) v.begin(), v.end() void parseArray(ll *A, ll n) { for (ll K = 0; K < n; K++) { cin >> A[K]; } } ll modInverse(ll a, ll b) { return 1 < a ? b - modInverse(b % a, a) * b / a : 1; } ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); } ld dist(ld x, ld y, ld a, ld b) { return sqrt((x - a) * (x - a) + (y - b) * (y - b)); } void debug(ll *a, ll n) { for (ll k = 0; k < n; k++) { cerr << a[k] << " "; } cerr << "\n"; } #define PI 3.14159265358979323846 int main() { FASTIO; ll x, y, n, m, p; cin >> x >> y >> n >> m >> p; ll a[n]; parseArray(a, n); ll b[n]; parseArray(b, m); ll c[p]; parseArray(c, p); sort(a, a + n); reverse(a, a + n); sort(b, b + m); reverse(b, b + m); sort(c, c + p); reverse(c, c + p); ll ans = 0; priority_queue<ll> pq; for (int k = 0; k < x; k++) pq.push(-a[k]), ans += a[k]; for (int k = 0; k < y; k++) pq.push(-b[k]), ans += b[k]; for (int k = 0; k < p; k++) { if (c[k] > -pq.top()) { ans -= -pq.top(); pq.pop(); pq.push(-c[k]); ans += c[k]; } } cout << ans << endl; return 0; }
/* بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ */ // codeforces #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; #define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); #define mp make_pair #define pb push_back #define sz(v) ((int)v.size()) #define all(v) v.begin(), v.end() void parseArray(ll *A, ll n) { for (ll K = 0; K < n; K++) { cin >> A[K]; } } ll modInverse(ll a, ll b) { return 1 < a ? b - modInverse(b % a, a) * b / a : 1; } ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); } ld dist(ld x, ld y, ld a, ld b) { return sqrt((x - a) * (x - a) + (y - b) * (y - b)); } void debug(ll *a, ll n) { for (ll k = 0; k < n; k++) { cerr << a[k] << " "; } cerr << "\n"; } #define PI 3.14159265358979323846 int main() { FASTIO; ll x, y, n, m, p; cin >> x >> y >> n >> m >> p; ll a[n]; parseArray(a, n); ll b[m]; parseArray(b, m); ll c[p]; parseArray(c, p); sort(a, a + n); reverse(a, a + n); sort(b, b + m); reverse(b, b + m); sort(c, c + p); reverse(c, c + p); ll ans = 0; priority_queue<ll> pq; for (int k = 0; k < x; k++) pq.push(-a[k]), ans += a[k]; for (int k = 0; k < y; k++) pq.push(-b[k]), ans += b[k]; for (int k = 0; k < p; k++) { if (c[k] > -pq.top()) { ans -= -pq.top(); pq.pop(); pq.push(-c[k]); ans += c[k]; } } cout << ans << endl; return 0; }
replace
39
40
39
40
0
p02727
C++
Runtime Error
#include <bits/stdc++.h> #include <unordered_map> #include <unordered_set> #define endl '\n' #define PI acos(-1) typedef long long ll; using namespace std; // Table is the complete reverse of dp int main() { cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(false); #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); #endif int x, y, a, b, c, z; priority_queue<pair<int, char>> p; cin >> x >> y >> a >> b >> c; for (int i = 0; i < a; i++) { cin >> z; p.push(pair<int, char>(z, 1)); } for (int i = 0; i < b; i++) { cin >> z; p.push(pair<int, char>(z, 2)); } for (int i = 0; i < c; i++) { cin >> z; p.push(pair<int, char>(z, 0)); } z = 0; ll ans = 0; while (x + y > z) { if (!p.top().second || (p.top().second == 1 && x) || (p.top().second == 2 && y)) { ans = ans + p.top().first; if (!p.top().second) z++; else if (p.top().second == 1) x--; else y--; } p.pop(); } cout << ans; }
#include <bits/stdc++.h> #include <unordered_map> #include <unordered_set> #define endl '\n' #define PI acos(-1) typedef long long ll; using namespace std; // Table is the complete reverse of dp int main() { cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(false); #ifndef ONLINE_JUDGE // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); #endif int x, y, a, b, c, z; priority_queue<pair<int, char>> p; cin >> x >> y >> a >> b >> c; for (int i = 0; i < a; i++) { cin >> z; p.push(pair<int, char>(z, 1)); } for (int i = 0; i < b; i++) { cin >> z; p.push(pair<int, char>(z, 2)); } for (int i = 0; i < c; i++) { cin >> z; p.push(pair<int, char>(z, 0)); } z = 0; ll ans = 0; while (x + y > z) { if (!p.top().second || (p.top().second == 1 && x) || (p.top().second == 2 && y)) { ans = ans + p.top().first; if (!p.top().second) z++; else if (p.top().second == 1) x--; else y--; } p.pop(); } cout << ans; }
replace
14
15
14
15
0
p02727
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; using ll = long long; #define rep(i, j) for (int i = 0; i < (int)(j); i++) #define repeat(i, j, k) for (int i = (j); i < (int)(k); i++) #define all(v) v.begin(), v.end() #define debug(x) cerr << #x << " : " << x << endl template <class T> bool set_min(T &a, const T &b) { return a > b ? a = b, true : false; } template <class T> bool set_max(T &a, const T &b) { return a < b ? a = b, true : false; } // vector template <class T> istream &operator>>(istream &is, vector<T> &v) { for (T &a : v) is >> a; return is; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) os << "\t" << t; return os << endl; } // pair template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; } const int INF = 1 << 30; const ll INFL = 1LL << 60; int main() { cin.tie(0); ios::sync_with_stdio(false); ll X, Y, A, B, C; cin >> X >> Y >> A >> B >> C; vector<ll> P(A), Q(B), R(C); cin >> P >> Q >> R; sort(all(P)); reverse(all(P)); sort(all(Q)); reverse(all(Q)); sort(all(R)); reverse(all(R)); ll ans = 0; vector<ll> p, q; p.push_back(0); q.push_back(0); rep(i, X) { p.push_back(P[i]); ans += P[i]; } rep(i, Y) { q.push_back(Q[i]); ans += Q[i]; } for (ll r : R) { if (p.back() < q.back()) { if (r > p.back()) { ans -= p.back(); ans += r; p.pop_back(); } } else { if (r > q.back()) { ans -= q.back(); ans += r; q.pop_back(); } } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; using ll = long long; #define rep(i, j) for (int i = 0; i < (int)(j); i++) #define repeat(i, j, k) for (int i = (j); i < (int)(k); i++) #define all(v) v.begin(), v.end() #define debug(x) cerr << #x << " : " << x << endl template <class T> bool set_min(T &a, const T &b) { return a > b ? a = b, true : false; } template <class T> bool set_max(T &a, const T &b) { return a < b ? a = b, true : false; } // vector template <class T> istream &operator>>(istream &is, vector<T> &v) { for (T &a : v) is >> a; return is; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) os << "\t" << t; return os << endl; } // pair template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; } const int INF = 1 << 30; const ll INFL = 1LL << 60; int main() { cin.tie(0); ios::sync_with_stdio(false); ll X, Y, A, B, C; cin >> X >> Y >> A >> B >> C; vector<ll> P(A), Q(B), R(C); cin >> P >> Q >> R; sort(all(P)); reverse(all(P)); sort(all(Q)); reverse(all(Q)); sort(all(R)); reverse(all(R)); ll ans = 0; vector<ll> p, q; p.push_back(INFL); q.push_back(INFL); rep(i, X) { p.push_back(P[i]); ans += P[i]; } rep(i, Y) { q.push_back(Q[i]); ans += Q[i]; } for (ll r : R) { if (p.back() < q.back()) { if (r > p.back()) { ans -= p.back(); ans += r; p.pop_back(); } } else { if (r > q.back()) { ans -= q.back(); ans += r; q.pop_back(); } } } cout << ans << endl; return 0; }
replace
53
55
53
55
0
p02727
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define mem(a, b) memset(a, b, sizeof(a)) #define pii pair<int, int> #define int long long const int inf = 0x3f3f3f3f; const int maxn = 201110; const int M = 1e9 + 7; int p[maxn], q[maxn], r[maxn]; int sum[maxn]; int ans[maxn]; signed main() { #ifdef ONLINE_JUDGE #else freopen("data.in", "r", stdin); #endif int x, y, a, b, c; cin >> x >> y >> a >> b >> c; int n = x + y; for (int i = 1; i <= a; i++) { cin >> p[i]; } sort(p + 1, p + 1 + a, greater<int>()); for (int i = 1; i <= b; i++) { cin >> q[i]; } sort(q + 1, q + 1 + b, greater<int>()); for (int i = 1; i <= c; i++) { cin >> r[i]; } sort(r + 1, r + 1 + c, greater<int>()); for (int i = 1; i <= c; i++) { sum[i] = sum[i - 1] + r[i]; } int red = 0, green = 0, pos = 1; while (red < x && green < y) { if (p[red + 1] > q[green + 1]) { red++; ans[pos] = ans[pos - 1] + p[red]; } else { green++; ans[pos] = ans[pos - 1] + q[green]; } pos++; } while (red < x) { red++; ans[pos] = ans[pos - 1] + p[red]; pos++; } while (green < y) { green++; ans[pos] = ans[pos - 1] + q[green]; pos++; } int res = 0; for (int i = 0; i <= min(c, n); i++) { res = max(res, sum[i] + ans[n - i]); } cout << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define mem(a, b) memset(a, b, sizeof(a)) #define pii pair<int, int> #define int long long const int inf = 0x3f3f3f3f; const int maxn = 201110; const int M = 1e9 + 7; int p[maxn], q[maxn], r[maxn]; int sum[maxn]; int ans[maxn]; signed main() { int x, y, a, b, c; cin >> x >> y >> a >> b >> c; int n = x + y; for (int i = 1; i <= a; i++) { cin >> p[i]; } sort(p + 1, p + 1 + a, greater<int>()); for (int i = 1; i <= b; i++) { cin >> q[i]; } sort(q + 1, q + 1 + b, greater<int>()); for (int i = 1; i <= c; i++) { cin >> r[i]; } sort(r + 1, r + 1 + c, greater<int>()); for (int i = 1; i <= c; i++) { sum[i] = sum[i - 1] + r[i]; } int red = 0, green = 0, pos = 1; while (red < x && green < y) { if (p[red + 1] > q[green + 1]) { red++; ans[pos] = ans[pos - 1] + p[red]; } else { green++; ans[pos] = ans[pos - 1] + q[green]; } pos++; } while (red < x) { red++; ans[pos] = ans[pos - 1] + p[red]; pos++; } while (green < y) { green++; ans[pos] = ans[pos - 1] + q[green]; pos++; } int res = 0; for (int i = 0; i <= min(c, n); i++) { res = max(res, sum[i] + ans[n - i]); } cout << res << endl; return 0; }
delete
15
19
15
15
TLE
p02727
C++
Runtime Error
#include <bits/stdc++.h> #define mod ((int)1e9 + 7) using namespace std; typedef pair<int, int> pi; typedef long long int ll; const int N = (int)2e3 + 5; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int x, y, a, b, c; cin >> x >> y >> a >> b >> c; vector<ll> p(a + 1), q(b), r(c + 1); for (int i = 1; i <= a; i++) { cin >> p[i]; } sort(p.begin(), p.end()); for (int i = 0; i < b; i++) { cin >> q[i]; } sort(q.begin(), q.end()); for (int i = 1; i <= c; i++) { cin >> r[i]; } sort(r.begin(), r.end()); vector<ll> temp_r(c + 1); priority_queue<ll, vector<ll>, greater<ll>> pq; ll sum = 0; for (auto it : q) { pq.push(it); sum += it; } for (int i = 0; i <= c; i++) { if (i > 0) { pq.push(r[i]); sum += r[i]; } while (pq.size() > y) { sum -= pq.top(); pq.pop(); } temp_r[i] = sum; } for (int i = 1; i <= a; i++) { p[i] += p[i - 1]; } for (int i = 1; i <= c; i++) { r[i] += r[i - 1]; } ll ans = 0; for (int i = 0; i <= x; i++) { ans = max(ans, temp_r[c - (x - i)] + r[c] - r[c - (x - i)] + p[a] - p[a - i]); } cout << ans; }
#include <bits/stdc++.h> #define mod ((int)1e9 + 7) using namespace std; typedef pair<int, int> pi; typedef long long int ll; const int N = (int)2e3 + 5; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int x, y, a, b, c; cin >> x >> y >> a >> b >> c; vector<ll> p(a + 1), q(b), r(c + 1); for (int i = 1; i <= a; i++) { cin >> p[i]; } sort(p.begin(), p.end()); for (int i = 0; i < b; i++) { cin >> q[i]; } sort(q.begin(), q.end()); for (int i = 1; i <= c; i++) { cin >> r[i]; } sort(r.begin(), r.end()); vector<ll> temp_r(c + 1); priority_queue<ll, vector<ll>, greater<ll>> pq; ll sum = 0; for (auto it : q) { pq.push(it); sum += it; } for (int i = 0; i <= c; i++) { if (i > 0) { pq.push(r[i]); sum += r[i]; } while (pq.size() > y) { sum -= pq.top(); pq.pop(); } temp_r[i] = sum; } for (int i = 1; i <= a; i++) { p[i] += p[i - 1]; } for (int i = 1; i <= c; i++) { r[i] += r[i - 1]; } ll ans = 0; for (int i = 0; i <= x; i++) { if ((c - (x - i)) >= 0 && ((c - (x - i)) <= c)) ans = max(ans, temp_r[c - (x - i)] + r[c] - r[c - (x - i)] + p[a] - p[a - i]); } cout << ans; }
replace
54
56
54
57
0
p02727
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i) #define fi first #define se second #define INF 1000000009 #define LLINF 1000000000000000009LL using ll = long long; int main() { int x, y, a, b, c; cin >> x >> y >> a >> b >> c; vector<ll> p(a); vector<ll> q(b); vector<ll> r(c); rep(i, a) cin >> p[i]; rep(i, b) cin >> q[i]; rep(i, c) cin >> r[i]; sort(p.begin(), p.end(), greater<>()); sort(q.begin(), q.end(), greater<>()); sort(r.begin(), r.end(), greater<>()); vector<ll> s(x); vector<ll> t(y); rep(i, x) s[i] = p[i]; rep(i, y) t[i] = q[i]; ll ans = 0; rep(i, x) ans += s[i]; rep(i, y) ans += t[i]; vector<ll> z; rep(i, x) z.push_back(s[i]); rep(i, y) z.push_back(t[i]); sort(z.begin(), z.end()); rep(i, c) { if (z[i] < r[i]) { ans -= z[i]; ans += r[i]; } } cout << ans << endl; return (0); }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i) #define fi first #define se second #define INF 1000000009 #define LLINF 1000000000000000009LL using ll = long long; int main() { int x, y, a, b, c; cin >> x >> y >> a >> b >> c; vector<ll> p(a); vector<ll> q(b); vector<ll> r(c); rep(i, a) cin >> p[i]; rep(i, b) cin >> q[i]; rep(i, c) cin >> r[i]; sort(p.begin(), p.end(), greater<>()); sort(q.begin(), q.end(), greater<>()); sort(r.begin(), r.end(), greater<>()); vector<ll> s(x); vector<ll> t(y); rep(i, x) s[i] = p[i]; rep(i, y) t[i] = q[i]; ll ans = 0; rep(i, x) ans += s[i]; rep(i, y) ans += t[i]; vector<ll> z; rep(i, x) z.push_back(s[i]); rep(i, y) z.push_back(t[i]); sort(z.begin(), z.end()); rep(i, min(c, (int)z.size())) { if (z[i] < r[i]) { ans -= z[i]; ans += r[i]; } } cout << ans << endl; return (0); }
replace
33
34
33
34
0
p02727
C++
Runtime Error
#include <algorithm> #include <cctype> #include <cmath> #include <cstring> #include <fstream> #include <iomanip> #include <iostream> #include <iterator> #include <map> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string> #include <time.h> #include <tuple> #include <vector> using namespace std; const double PI = 3.14159265358979323846; const long long int MOD = 1000000000 + 7; struct UnionFind { vector<int> parent; UnionFind(int N) : parent(N) { for (int i = 0; i < N; i++) { parent[i] = -1; } } int root(int i) { if (parent[i] < 0) { return i; } return (parent[i] = root(parent[i])); } bool unite(int from, int to) { int rx = root(from); int ry = root(to); if (rx != ry) { parent[ry] += parent[rx]; parent[rx] = ry; return true; } else { return false; } } bool same(int x, int y) { return root(x) == root(y); } int treeSize(int x) { return -parent[root(x)]; } }; long long int modpow(long long int base, long long int pow, long long int mod) { if (pow == 1) { return base; } else if (pow == 0) { return 1; } if (pow % 2 == 0) { auto temp = modpow(base, pow / 2, mod); return (temp * temp) % mod; } else { return (base * modpow(base, pow - 1, mod)) % mod; } } long long int moddiv(long long int X, long long int Y, long long int mod) { auto fermatDiv = modpow(Y, mod - 2, mod); return (X * fermatDiv) % mod; } long long modCombination(long long left, long long right, long long int mod) { long long answer = 1; if (left > right) { for (long long i = 0; i < right; i++) { answer = (answer * (left - i)) % mod; answer = moddiv(answer, (i + 1), mod); } } return answer; } bool IsPrime(long long N) { if (N == 1) { return false; } for (long long i = 2; i * i <= N; i++) { if (N % i == 0) { return false; } } return true; } vector<pair<long long, long long>> prime_factorize(long long N) { vector<pair<long long, long long>> res; for (long long a = 2; a * a <= N; ++a) { if (N % a != 0) continue; long long ex = 0; // 指数 // 割れる限り割り続ける while (N % a == 0) { ++ex; N /= a; } // その結果を push res.push_back({a, ex}); } // 最後に残った数について if (N != 1) res.push_back({N, 1}); return res; } long long euclid(long long a, long long b) { if (a > b) { long long temp = b; b = a; a = temp; } if (b % a == 0) { return a; } else { return euclid(a, b - a); } } long long gcd(long long a, long long b) { if (b > a) { long long temp = b; b = a; a = temp; } // cout << "a:" << a << "b:" << b << endl; long long c = a % b; if (c == 0) { return b; } else { return gcd(b, c); } } int main() { int X, Y, A, B, C; cin >> X >> Y >> A >> B >> C; vector<int> p(A), q(B), r(C); for (int i = 0; i < A; i++) { int temp; cin >> temp; p[i] = temp; } for (int i = 0; i < B; i++) { int temp; cin >> temp; q[i] = temp; } for (int i = 0; i < C; i++) { int temp; cin >> temp; r[i] = temp; } sort(p.begin(), p.end(), greater<int>()); sort(q.begin(), q.end(), greater<int>()); sort(r.begin(), r.end(), greater<int>()); vector<int> eats(X + Y); for (int i = 0; i < X; i++) { eats[i] = p[i]; } for (int i = 0; i < Y; i++) { eats[X + i] = q[i]; } sort(eats.begin(), eats.end()); for (int i = 0; i < C; i++) { if (eats[i] <= r[i]) { eats[i] = r[i]; } else { break; } } long long total = 0; for (auto e : eats) { total += e; } cout << total << endl; return 0; }
#include <algorithm> #include <cctype> #include <cmath> #include <cstring> #include <fstream> #include <iomanip> #include <iostream> #include <iterator> #include <map> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string> #include <time.h> #include <tuple> #include <vector> using namespace std; const double PI = 3.14159265358979323846; const long long int MOD = 1000000000 + 7; struct UnionFind { vector<int> parent; UnionFind(int N) : parent(N) { for (int i = 0; i < N; i++) { parent[i] = -1; } } int root(int i) { if (parent[i] < 0) { return i; } return (parent[i] = root(parent[i])); } bool unite(int from, int to) { int rx = root(from); int ry = root(to); if (rx != ry) { parent[ry] += parent[rx]; parent[rx] = ry; return true; } else { return false; } } bool same(int x, int y) { return root(x) == root(y); } int treeSize(int x) { return -parent[root(x)]; } }; long long int modpow(long long int base, long long int pow, long long int mod) { if (pow == 1) { return base; } else if (pow == 0) { return 1; } if (pow % 2 == 0) { auto temp = modpow(base, pow / 2, mod); return (temp * temp) % mod; } else { return (base * modpow(base, pow - 1, mod)) % mod; } } long long int moddiv(long long int X, long long int Y, long long int mod) { auto fermatDiv = modpow(Y, mod - 2, mod); return (X * fermatDiv) % mod; } long long modCombination(long long left, long long right, long long int mod) { long long answer = 1; if (left > right) { for (long long i = 0; i < right; i++) { answer = (answer * (left - i)) % mod; answer = moddiv(answer, (i + 1), mod); } } return answer; } bool IsPrime(long long N) { if (N == 1) { return false; } for (long long i = 2; i * i <= N; i++) { if (N % i == 0) { return false; } } return true; } vector<pair<long long, long long>> prime_factorize(long long N) { vector<pair<long long, long long>> res; for (long long a = 2; a * a <= N; ++a) { if (N % a != 0) continue; long long ex = 0; // 指数 // 割れる限り割り続ける while (N % a == 0) { ++ex; N /= a; } // その結果を push res.push_back({a, ex}); } // 最後に残った数について if (N != 1) res.push_back({N, 1}); return res; } long long euclid(long long a, long long b) { if (a > b) { long long temp = b; b = a; a = temp; } if (b % a == 0) { return a; } else { return euclid(a, b - a); } } long long gcd(long long a, long long b) { if (b > a) { long long temp = b; b = a; a = temp; } // cout << "a:" << a << "b:" << b << endl; long long c = a % b; if (c == 0) { return b; } else { return gcd(b, c); } } int main() { int X, Y, A, B, C; cin >> X >> Y >> A >> B >> C; vector<int> p(A), q(B), r(C); for (int i = 0; i < A; i++) { int temp; cin >> temp; p[i] = temp; } for (int i = 0; i < B; i++) { int temp; cin >> temp; q[i] = temp; } for (int i = 0; i < C; i++) { int temp; cin >> temp; r[i] = temp; } sort(p.begin(), p.end(), greater<int>()); sort(q.begin(), q.end(), greater<int>()); sort(r.begin(), r.end(), greater<int>()); vector<int> eats(X + Y); for (int i = 0; i < X; i++) { eats[i] = p[i]; } for (int i = 0; i < Y; i++) { eats[X + i] = q[i]; } sort(eats.begin(), eats.end()); for (int i = 0; i < min(C, X + Y); i++) { if (eats[i] <= r[i]) { eats[i] = r[i]; } else { break; } } long long total = 0; for (auto e : eats) { total += e; } cout << total << endl; return 0; }
replace
189
190
189
190
0
p02727
C++
Runtime Error
#define _CRT_SECURE_NO_WARNINGS #include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <deque> #include <iostream> #include <map> #include <math.h> #include <queue> #include <random> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> // #define int long long #define mp(a, b) make_pair(a, b) #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define endl '\n' using namespace std; typedef long long ll; typedef long double ld; mt19937 mrand(random_device{}()); double PI = acos((double)-1); const ld eps = 1e-7; const ll inf0 = 1023 * 1024 * 1024; const ll inf = inf0 * inf0; // const ll mod = 1e9 + 9; const ll mod = 998244353; void solve(); void scan(); signed main() { #ifdef _DEBUG freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); #endif cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); cout << fixed; cout.precision(15); solve(); return 0; } const int N = 2e5 + 7; ll cnt[N]; void solve() { fill(cnt, cnt + N, -inf); int x, y; cin >> x >> y; int a, b, c; cin >> a >> b >> c; vector<int> a1(a), b1(b), c1(c); for (int &i : a1) cin >> i; for (int &i : b1) cin >> i; for (int &i : c1) cin >> i; vector<pair<int, int>> kek; for (int i : a1) kek.push_back({i, 0}); for (int i : b1) kek.push_back({i, 1}); sort(rall(kek)); int c0 = x; int cc = y; int cn = 0; ll su = 0; cnt[0] = 0; for (auto u : kek) { if (u.second == 0) { if (c0) { c0--; su += u.first; cn++; } } else { if (cc) { cc--; su += u.first; cn++; } } cnt[cn] = su; } ll ans = cnt[x + y]; sort(rall(c1)); su = 0; for (int i = 0; i < c; i++) { ; su += c1[i]; ans = max(ans, cnt[x + y - i - 1] + su); } cout << ans << endl; return; }
#define _CRT_SECURE_NO_WARNINGS #include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <deque> #include <iostream> #include <map> #include <math.h> #include <queue> #include <random> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> // #define int long long #define mp(a, b) make_pair(a, b) #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define endl '\n' using namespace std; typedef long long ll; typedef long double ld; mt19937 mrand(random_device{}()); double PI = acos((double)-1); const ld eps = 1e-7; const ll inf0 = 1023 * 1024 * 1024; const ll inf = inf0 * inf0; // const ll mod = 1e9 + 9; const ll mod = 998244353; void solve(); void scan(); signed main() { #ifdef _DEBUG freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); #endif cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); cout << fixed; cout.precision(15); solve(); return 0; } const int N = 2e5 + 7; ll cnt[N]; void solve() { fill(cnt, cnt + N, -inf); int x, y; cin >> x >> y; int a, b, c; cin >> a >> b >> c; vector<int> a1(a), b1(b), c1(c); for (int &i : a1) cin >> i; for (int &i : b1) cin >> i; for (int &i : c1) cin >> i; vector<pair<int, int>> kek; for (int i : a1) kek.push_back({i, 0}); for (int i : b1) kek.push_back({i, 1}); sort(rall(kek)); int c0 = x; int cc = y; int cn = 0; ll su = 0; cnt[0] = 0; for (auto u : kek) { if (u.second == 0) { if (c0) { c0--; su += u.first; cn++; } } else { if (cc) { cc--; su += u.first; cn++; } } cnt[cn] = su; } ll ans = cnt[x + y]; sort(rall(c1)); su = 0; for (int i = 0; i < c; i++) { ; if ((i + 1) > x + y) break; su += c1[i]; ans = max(ans, cnt[x + y - i - 1] + su); } cout << ans << endl; return; }
insert
105
105
105
107
0
p02727
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define int long long #define ALL(x) (x).begin(), (x).end() #define MAX(x) *max_element(ALL(x)) #define MIN(x) *min_element(ALL(x)) typedef pair<int, int> PI; typedef pair<int, pair<int, int>> PII; static const int INF = 1010000000000000017LL; static const double eps = 1e-12; static const double pi = 3.14159265358979323846; static const int dx[4] = {1, -1, 0, 0}; static const int dy[4] = {0, 0, 1, -1}; static const int ddx[8] = {1, -1, 0, 0, 1, 1, -1, -1}; static const int ddy[8] = {0, 0, 1, -1, 1, -1, 1, -1}; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } const int mod = 1000000007; int X, Y, A, B, C; int p[100005], q[100005], r[100005]; int sum_p[100005], sum_q[100005], sum_r[100005]; int ans; signed main() { cin >> X >> Y >> A >> B >> C; for (int i = 0; i < A; ++i) cin >> p[i]; for (int i = 0; i < B; ++i) cin >> q[i]; for (int i = 0; i < C; ++i) cin >> r[i]; sort(p, p + A, greater<int>()); sort(q, q + B, greater<int>()); sort(r, r + C, greater<int>()); priority_queue<int, vector<int>, greater<int>> pq; int ph = 0, qh = 0, rh = 0; while (pq.size() < X + Y) { if (qh >= Y || (p[ph] >= q[qh] && ph < X)) { pq.push(p[ph]); ph++; } else { pq.push(q[qh]); qh++; } } while (true) { int v = pq.top(); if (v > r[rh]) break; pq.pop(); ans += r[rh]; rh++; } while (pq.size()) { ans += pq.top(); pq.pop(); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define int long long #define ALL(x) (x).begin(), (x).end() #define MAX(x) *max_element(ALL(x)) #define MIN(x) *min_element(ALL(x)) typedef pair<int, int> PI; typedef pair<int, pair<int, int>> PII; static const int INF = 1010000000000000017LL; static const double eps = 1e-12; static const double pi = 3.14159265358979323846; static const int dx[4] = {1, -1, 0, 0}; static const int dy[4] = {0, 0, 1, -1}; static const int ddx[8] = {1, -1, 0, 0, 1, 1, -1, -1}; static const int ddy[8] = {0, 0, 1, -1, 1, -1, 1, -1}; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } const int mod = 1000000007; int X, Y, A, B, C; int p[100005], q[100005], r[100005]; int sum_p[100005], sum_q[100005], sum_r[100005]; int ans; signed main() { cin >> X >> Y >> A >> B >> C; for (int i = 0; i < A; ++i) cin >> p[i]; for (int i = 0; i < B; ++i) cin >> q[i]; for (int i = 0; i < C; ++i) cin >> r[i]; sort(p, p + A, greater<int>()); sort(q, q + B, greater<int>()); sort(r, r + C, greater<int>()); priority_queue<int, vector<int>, greater<int>> pq; int ph = 0, qh = 0, rh = 0; while (pq.size() < X + Y) { if (qh >= Y || (p[ph] >= q[qh] && ph < X)) { pq.push(p[ph]); ph++; } else { pq.push(q[qh]); qh++; } } while (pq.size()) { int v = pq.top(); if (v > r[rh]) break; pq.pop(); ans += r[rh]; rh++; } while (pq.size()) { ans += pq.top(); pq.pop(); } cout << ans << endl; }
replace
63
64
63
64
TLE
p02727
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define int long long #define MOD 1000000007 #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--) #define rep(i, n) for (int i = 0; i < (n); i++) #define rep1(i, n) for (int i = 1; i < (n); i++) #define rrep(i, n) for (int i = (n)-1; i >= 0; i--) #define all(i) (i).begin(), (i).end() #define rall(i) (i).begin(), (i).end(), greater<int>() #define elif else if #define eb emplace_back #define pb push_back #define mp make_pair #define fst first #define sec second template <typename T> void print(T x) { std::cout << x << '\n'; } // typedef long long ll; #define TENNINE 1000000005 #define TENFIVE 100005 // #define int long long int x, y, a, b, c; signed main() { cin >> x >> y >> a >> b >> c; vector<int> p(a), q(b), r(c); rep(i, a) { cin >> p[i]; } rep(i, b) { cin >> q[i]; } rep(i, c) { cin >> r[i]; } sort(rall(p)); sort(rall(q)); sort(rall(r)); deque<int> a2, b2; rep(i, x) { a2.pb(p[i]); } rep(i, y) { b2.pb(q[i]); } int k = 0; while (1) { int ta = a2.back(); int tb = b2.back(); if (ta <= tb) { if (ta < r[k]) { a2.push_front(r[k]); a2.pop_back(); k++; } else { break; } } else { if (tb < r[k]) { b2.push_front(r[k]); b2.pop_back(); k++; } } } int ans = 0; for (auto temp : a2) { ans += temp; } for (auto temp : b2) { ans += temp; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define MOD 1000000007 #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--) #define rep(i, n) for (int i = 0; i < (n); i++) #define rep1(i, n) for (int i = 1; i < (n); i++) #define rrep(i, n) for (int i = (n)-1; i >= 0; i--) #define all(i) (i).begin(), (i).end() #define rall(i) (i).begin(), (i).end(), greater<int>() #define elif else if #define eb emplace_back #define pb push_back #define mp make_pair #define fst first #define sec second template <typename T> void print(T x) { std::cout << x << '\n'; } // typedef long long ll; #define TENNINE 1000000005 #define TENFIVE 100005 // #define int long long int x, y, a, b, c; signed main() { cin >> x >> y >> a >> b >> c; vector<int> p(a), q(b), r(c); rep(i, a) { cin >> p[i]; } rep(i, b) { cin >> q[i]; } rep(i, c) { cin >> r[i]; } sort(rall(p)); sort(rall(q)); sort(rall(r)); deque<int> a2, b2; rep(i, x) { a2.pb(p[i]); } rep(i, y) { b2.pb(q[i]); } int k = 0; while (1) { int ta = a2.back(); int tb = b2.back(); if (ta <= tb) { if (ta < r[k]) { a2.push_front(r[k]); a2.pop_back(); k++; } else { break; } } else { if (tb < r[k]) { b2.push_front(r[k]); b2.pop_back(); k++; } else { break; } } } int ans = 0; for (auto temp : a2) { ans += temp; } for (auto temp : b2) { ans += temp; } cout << ans << endl; return 0; }
insert
65
65
65
67
TLE
p02727
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long using namespace std; const ll N = 1e5 + 10; typedef struct node { ll r, type; bool operator<(const node &t) const { return r > t.r; } } node; node a[N]; int main() { ll x, y, A, B, C, tot = 0, m; cin >> x >> y >> A >> B >> C; for (ll i = 0; i < A; i++) scanf("%lld", &m), a[tot].r = m, a[tot].type = 0, tot++; for (ll i = 0; i < B; i++) scanf("%lld", &m), a[tot].r = m, a[tot].type = 1, tot++; for (ll i = 0; i < C; i++) scanf("%lld", &m), a[tot].r = m, a[tot].type = 2, tot++; sort(a, a + tot); ll aa = 0, bb = 0, cc = 0, ans = 0; for (ll i = 0; i < tot; i++) { if (a[i].type == 2) cc++, ans += a[i].r; else if (a[i].type == 0 && aa < x) aa++, ans += a[i].r; else if (a[i].type == 1 && bb < y) bb++, ans += a[i].r; if (aa + bb + cc == x + y) break; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define ll long long using namespace std; const ll N = 3e5 + 10; typedef struct node { ll r, type; bool operator<(const node &t) const { return r > t.r; } } node; node a[N]; int main() { ll x, y, A, B, C, tot = 0, m; cin >> x >> y >> A >> B >> C; for (ll i = 0; i < A; i++) scanf("%lld", &m), a[tot].r = m, a[tot].type = 0, tot++; for (ll i = 0; i < B; i++) scanf("%lld", &m), a[tot].r = m, a[tot].type = 1, tot++; for (ll i = 0; i < C; i++) scanf("%lld", &m), a[tot].r = m, a[tot].type = 2, tot++; sort(a, a + tot); ll aa = 0, bb = 0, cc = 0, ans = 0; for (ll i = 0; i < tot; i++) { if (a[i].type == 2) cc++, ans += a[i].r; else if (a[i].type == 0 && aa < x) aa++, ans += a[i].r; else if (a[i].type == 1 && bb < y) bb++, ans += a[i].r; if (aa + bb + cc == x + y) break; } cout << ans << endl; return 0; }
replace
3
4
3
4
0
p02727
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int x, y, a, b, c; cin >> x >> y >> a >> b >> c; vector<int> va(a); vector<int> vb(b); vector<int> vc(c); for (int i = 0; i < a; i++) { cin >> va[i]; } for (int i = 0; i < b; i++) { cin >> vb[i]; } for (int i = 0; i < c; i++) { cin >> vc[i]; } sort(va.begin(), va.end()); reverse(va.begin(), va.end()); sort(vb.begin(), vb.end()); reverse(vb.begin(), vb.end()); sort(vc.begin(), vc.end()); reverse(vc.begin(), vc.end()); int qa = x - 1; int qb = y - 1; int qc = 0; while (true) { if (qc == c) { qc--; break; } long long ca = qa == -1 ? 1e10 : va[qa]; long long cb = qb == -1 ? 1e10 : vb[qb]; long long cc = vc[cc]; if (cc > ca || cc > cb) { if (ca <= cb) { qa--; } else { qb--; } qc++; } else { qc--; break; } } long long ans = 0; for (int i = 0; i <= qa; i++) { ans += va[i]; } for (int i = 0; i <= qb; i++) { ans += vb[i]; } for (int i = 0; i <= qc; i++) { ans += vc[i]; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int x, y, a, b, c; cin >> x >> y >> a >> b >> c; vector<int> va(a); vector<int> vb(b); vector<int> vc(c); for (int i = 0; i < a; i++) { cin >> va[i]; } for (int i = 0; i < b; i++) { cin >> vb[i]; } for (int i = 0; i < c; i++) { cin >> vc[i]; } sort(va.begin(), va.end()); reverse(va.begin(), va.end()); sort(vb.begin(), vb.end()); reverse(vb.begin(), vb.end()); sort(vc.begin(), vc.end()); reverse(vc.begin(), vc.end()); int qa = x - 1; int qb = y - 1; int qc = 0; while (true) { if (qc == c) { qc--; break; } long long ca = qa == -1 ? 1e10 : va[qa]; long long cb = qb == -1 ? 1e10 : vb[qb]; long long cc = vc[qc]; if (cc > ca || cc > cb) { if (ca <= cb) { qa--; } else { qb--; } qc++; } else { qc--; break; } } long long ans = 0; for (int i = 0; i <= qa; i++) { ans += va[i]; } for (int i = 0; i <= qb; i++) { ans += vb[i]; } for (int i = 0; i <= qc; i++) { ans += vc[i]; } cout << ans << endl; return 0; }
replace
39
40
39
40
-11
p02727
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll, ll> pp; typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> super_set; typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> multi_set; #define x1 dfds #define y1 dsfdsfe #define pb push_back #define forn(i, n) for (ll i = 1; i <= n; ++i) #define fi first #define sc second #define endl '\n' #define po(x) (1ll << x) const ll DIM = 2E3 + 7; ll A[DIM], B[DIM], C[DIM]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll x, a, y, b; cin >> x >> y >> a >> b; ll c; cin >> c; forn(i, a) cin >> A[i]; forn(i, b) cin >> B[i]; forn(i, c) cin >> C[i]; priority_queue<ll, vector<ll>, greater<ll>> R, G; ll rsum = 0, gsum = 0; forn(i, a) { R.push(A[i]); rsum += A[i]; } forn(i, b) { G.push(B[i]); gsum += B[i]; } while (R.size() > x) { rsum -= R.top(); R.pop(); } while (G.size() > y) { gsum -= G.top(); G.pop(); } sort(C + 1, C + 1 + c, greater<ll>()); for (ll i = c; i >= 1; --i) { if (R.top() < G.top()) { ll nl = max(R.top(), C[i]); rsum -= R.top(); R.pop(); R.push(nl); rsum += nl; } else { ll nl = max(G.top(), C[i]); gsum -= G.top(); G.pop(); G.push(nl); gsum += nl; } } cout << rsum + gsum << endl; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll, ll> pp; typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> super_set; typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> multi_set; #define x1 dfds #define y1 dsfdsfe #define pb push_back #define forn(i, n) for (ll i = 1; i <= n; ++i) #define fi first #define sc second #define endl '\n' #define po(x) (1ll << x) const ll DIM = 1E5 + 7; ll A[DIM], B[DIM], C[DIM]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll x, a, y, b; cin >> x >> y >> a >> b; ll c; cin >> c; forn(i, a) cin >> A[i]; forn(i, b) cin >> B[i]; forn(i, c) cin >> C[i]; priority_queue<ll, vector<ll>, greater<ll>> R, G; ll rsum = 0, gsum = 0; forn(i, a) { R.push(A[i]); rsum += A[i]; } forn(i, b) { G.push(B[i]); gsum += B[i]; } while (R.size() > x) { rsum -= R.top(); R.pop(); } while (G.size() > y) { gsum -= G.top(); G.pop(); } sort(C + 1, C + 1 + c, greater<ll>()); for (ll i = c; i >= 1; --i) { if (R.top() < G.top()) { ll nl = max(R.top(), C[i]); rsum -= R.top(); R.pop(); R.push(nl); rsum += nl; } else { ll nl = max(G.top(), C[i]); gsum -= G.top(); G.pop(); G.push(nl); gsum += nl; } } cout << rsum + gsum << endl; return 0; }
replace
23
24
23
24
0
p02727
Python
Runtime Error
x, y, a, b, c = map(int, input().split()) P = sorted(list(map(int, input().split())), reverse=True) Q = sorted(list(map(int, input().split())), reverse=True) R = sorted(list(map(int, input().split()))) A = sorted(P[:x] + Q[:y]) ans = sum(A) for i in range(c): if A[i] < R[-1]: ans = ans + R[-1] - A[i] R.pop(-1) print(ans)
x, y, a, b, c = map(int, input().split()) P = sorted(list(map(int, input().split())), reverse=True) Q = sorted(list(map(int, input().split())), reverse=True) R = sorted(list(map(int, input().split()))) A = sorted(P[:x] + Q[:y]) ans = sum(A) for i in range(min(c, len(A))): if A[i] < R[-1]: ans = ans + R[-1] - A[i] R.pop(-1) print(ans)
replace
8
9
8
9
0
p02727
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { size_t X, Y, A, B, C; cin >> X >> Y >> A >> B >> C; vector<size_t> p(A); vector<size_t> red(X, 0); for (int i = 0; i < A; ++i) { size_t p; cin >> p; red.at(0) = max(red.at(0), p); sort(red.begin(), red.end()); } vector<size_t> q(B); vector<size_t> green(Y, 0); for (int i = 0; i < B; ++i) { size_t q; cin >> q; green.at(0) = max(green.at(0), q); sort(green.begin(), green.end()); } vector<size_t> r(C); for (int i = 0; i < C; ++i) { size_t r; cin >> r; if (red.at(0) < green.at(0)) { if (r > red.at(0)) { red.at(0) = r; sort(red.begin(), red.end()); } } else { if (r > green.at(0)) { green.at(0) = r; sort(green.begin(), green.end()); } } } cout << accumulate(red.begin(), red.end(), 0ll) + accumulate(green.begin(), green.end(), 0ll) << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int x, y; cin >> x >> y; int a, b, c; cin >> a >> b >> c; vector<int> p(a), q(b), r(c); for (int i = 0; i < a; ++i) cin >> p.at(i); for (int i = 0; i < b; ++i) cin >> q.at(i); for (int i = 0; i < c; ++i) cin >> r.at(i); sort(p.rbegin(), p.rend()); sort(q.rbegin(), q.rend()); vector<int> d; for (int i = 0; i < x; ++i) d.push_back(p.at(i)); for (int i = 0; i < y; ++i) d.push_back(q.at(i)); for (int i = 0; i < c; ++i) d.push_back(r.at(i)); sort(d.rbegin(), d.rend()); ll ans = 0; for (int i = 0; i < x + y; ++i) ans += d.at(i); cout << ans << endl; return 0; }
replace
6
43
6
32
TLE
p02727
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) typedef long long ll; typedef pair<ll, int> P; int main() { int X, Y, a, b, c; cin >> X >> Y >> c >> b >> a; vector<ll> A, B, C; rep(i, a) { ll t; cin >> t; A.push_back(t); } rep(i, b) { ll t; cin >> t; B.push_back(t); } rep(i, c) { ll t; cin >> t; C.push_back(t); } sort(A.begin(), A.end()); reverse(A.begin(), A.end()); sort(B.begin(), B.end()); reverse(B.begin(), B.end()); rep(i, X) { C.push_back(A[i]); } rep(i, Y) { C.push_back(B[i]); } sort(C.begin(), C.end()); reverse(C.begin(), C.end()); ll ans = 0; rep(i, X + Y) { ans += C[i]; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) typedef long long ll; typedef pair<ll, int> P; int main() { int X, Y, a, b, c; cin >> X >> Y >> a >> b >> c; vector<ll> A, B, C; rep(i, a) { ll t; cin >> t; A.push_back(t); } rep(i, b) { ll t; cin >> t; B.push_back(t); } rep(i, c) { ll t; cin >> t; C.push_back(t); } sort(A.begin(), A.end()); reverse(A.begin(), A.end()); sort(B.begin(), B.end()); reverse(B.begin(), B.end()); rep(i, X) { C.push_back(A[i]); } rep(i, Y) { C.push_back(B[i]); } sort(C.begin(), C.end()); reverse(C.begin(), C.end()); ll ans = 0; rep(i, X + Y) { ans += C[i]; } cout << ans << endl; return 0; }
replace
9
10
9
10
0
p02727
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define pan(i, n) for (int i = 0; i < n; i++) #define pans(i, n, a) for (int i = a; i < n; i++) #define ll long long int #define vi vector<int> #define vl vector<ll> #define pb push_back #define INF INT_MAX #define PI 3.141592653 #define inf 1000007 #define pll pair<ll, ll> #define pii pair<int, int> ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); } ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; } int main() { ll x, y, A, B, C, ans = 0; cin >> x >> y >> A >> B >> C; vector<ll> a(A), b(B), c(C), f; pan(i, A) cin >> a[i]; pan(i, B) cin >> b[i]; pan(i, C) cin >> c[i]; sort(a.begin(), a.end(), greater<ll>()); sort(b.begin(), b.end(), greater<ll>()); sort(c.begin(), c.end(), greater<ll>()); pan(i, x) f.pb(a[i]); pan(i, y) f.pb(b[i]); sort(f.begin(), f.end()); int n = (C > f.size()) ? C : f.size(); pan(i, n) { if (c[i] - f[i] > 0) f[i] = c[i]; } pan(i, (int)f.size()) ans += f[i]; cout << ans; }
#include <bits/stdc++.h> using namespace std; #define pan(i, n) for (int i = 0; i < n; i++) #define pans(i, n, a) for (int i = a; i < n; i++) #define ll long long int #define vi vector<int> #define vl vector<ll> #define pb push_back #define INF INT_MAX #define PI 3.141592653 #define inf 1000007 #define pll pair<ll, ll> #define pii pair<int, int> ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); } ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; } int main() { ll x, y, A, B, C, ans = 0; cin >> x >> y >> A >> B >> C; vector<ll> a(A), b(B), c(C), f; pan(i, A) cin >> a[i]; pan(i, B) cin >> b[i]; pan(i, C) cin >> c[i]; sort(a.begin(), a.end(), greater<ll>()); sort(b.begin(), b.end(), greater<ll>()); sort(c.begin(), c.end(), greater<ll>()); pan(i, x) f.pb(a[i]); pan(i, y) f.pb(b[i]); sort(f.begin(), f.end()); int n = (C > f.size()) ? f.size() : C; pan(i, n) { if (c[i] - f[i] > 0) f[i] = c[i]; } pan(i, (int)f.size()) ans += f[i]; cout << ans; }
replace
31
32
31
32
0
p02727
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long #define maxn 2005 using namespace std; const ll inf = 1e9 + 7; ll a[maxn], b[maxn], c[maxn]; vector<ll> v; int main() { // freopen("input.txt","r",stdin); int X, Y, A, B, C; cin >> X >> Y >> A >> B >> C; for (int i = 0; i < A; i++) cin >> a[i]; for (int i = 0; i < B; i++) cin >> b[i]; for (int i = 0; i < C; i++) cin >> c[i]; sort(a, a + A); sort(b, b + B); sort(c, c + C); ll sum = 0; for (int i = 0; i < X; i++) v.push_back(a[A - 1 - i]); for (int i = 0; i < Y; i++) v.push_back(b[B - 1 - i]); for (int i = 0; i < C; i++) v.push_back(c[i]); sort(v.begin(), v.end()); int len = v.size(); for (int i = 0; i < X + Y; i++) sum += v[len - i - 1]; cout << sum << endl; return 0; }
#include <bits/stdc++.h> #define ll long long #define maxn 100005 using namespace std; const ll inf = 1e9 + 7; ll a[maxn], b[maxn], c[maxn]; vector<ll> v; int main() { // freopen("input.txt","r",stdin); int X, Y, A, B, C; cin >> X >> Y >> A >> B >> C; for (int i = 0; i < A; i++) cin >> a[i]; for (int i = 0; i < B; i++) cin >> b[i]; for (int i = 0; i < C; i++) cin >> c[i]; sort(a, a + A); sort(b, b + B); sort(c, c + C); ll sum = 0; for (int i = 0; i < X; i++) v.push_back(a[A - 1 - i]); for (int i = 0; i < Y; i++) v.push_back(b[B - 1 - i]); for (int i = 0; i < C; i++) v.push_back(c[i]); sort(v.begin(), v.end()); int len = v.size(); for (int i = 0; i < X + Y; i++) sum += v[len - i - 1]; cout << sum << endl; return 0; }
replace
2
3
2
3
0
p02727
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { ll X, Y, A, B, C; cin >> X >> Y >> A >> B >> C; vector<ll> p(A); vector<ll> q(B); vector<ll> r(C); for (ll i = 0; i < A; ++i) { cin >> p.at(i); } for (ll i = 0; i < B; ++i) { cin >> q.at(i); } for (ll i = 0; i < C; ++i) { cin >> r.at(i); } sort(p.begin(), p.end()); sort(q.begin(), q.end()); sort(r.begin(), r.end()); vector<ll> ans(0); ll answer = 0; for (ll i = 0; i < X; ++i) { ans.push_back(p.at(A - i - 1)); answer += p.at(A - i - 1); } for (ll i = 0; i < Y; ++i) { ans.push_back(q.at(B - i - 1)); answer += q.at(B - i - 1); } sort(ans.begin(), ans.end()); for (ll i = 0; i < C; ++i) { if (ans.at(i) < r.at(C - i - 1)) { answer += r.at(C - i - 1); answer -= ans.at(i); } } cout << answer << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { ll X, Y, A, B, C; cin >> X >> Y >> A >> B >> C; vector<ll> p(A); vector<ll> q(B); vector<ll> r(C); for (ll i = 0; i < A; ++i) { cin >> p.at(i); } for (ll i = 0; i < B; ++i) { cin >> q.at(i); } for (ll i = 0; i < C; ++i) { cin >> r.at(i); } sort(p.begin(), p.end()); sort(q.begin(), q.end()); sort(r.begin(), r.end()); vector<ll> ans(0); ll answer = 0; for (ll i = 0; i < X; ++i) { ans.push_back(p.at(A - i - 1)); answer += p.at(A - i - 1); } for (ll i = 0; i < Y; ++i) { ans.push_back(q.at(B - i - 1)); answer += q.at(B - i - 1); } sort(ans.begin(), ans.end()); for (ll i = 0; i < C; ++i) { if (i < X + Y) { if (ans.at(i) < r.at(C - i - 1)) { answer += r.at(C - i - 1); answer -= ans.at(i); } } } cout << answer << endl; }
replace
33
36
33
38
0
p02727
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define pi 3.14159265359 #define inf 2147483647 #define INF 9223372036854775807 #define mod 1000000007 #define mod2 998244353 #define Graph vector<vector<int>> int main() { ll X, Y, A, B, C; cin >> X >> Y >> A >> B >> C; vector<ll> p(A), q(B), r(C); for (int i = 0; i < A; i++) { cin >> p.at(i); } for (int i = 0; i < B; i++) { cin >> q.at(i); } for (int i = 0; i < C; i++) { cin >> r.at(i); } sort(p.begin(), p.end()); sort(q.begin(), q.end()); sort(r.begin(), r.end()); ll psum = 0, qsum = 0; ll pk = A - X, qk = B - Y, rk = C - 1; for (int i = 0; i < C; i++) { ll P, Q, R = r.at(rk); if (pk < A) P = p.at(pk); else P = inf; if (rk < B) Q = q.at(qk); else Q = inf; ll low = min(P, Q); if (low == P && P < R && pk < A) { swap(p.at(pk), r.at(rk)); pk++; rk--; } else if (low == Q && Q < R && qk < B) { swap(q.at(qk), r.at(rk)); qk++; rk--; } if (rk < 0) break; } for (int i = A - 1; i >= A - X; i--) { psum += p.at(i); } for (int i = B - 1; i >= B - Y; i--) { qsum += q.at(i); } cout << psum + qsum << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define pi 3.14159265359 #define inf 2147483647 #define INF 9223372036854775807 #define mod 1000000007 #define mod2 998244353 #define Graph vector<vector<int>> int main() { ll X, Y, A, B, C; cin >> X >> Y >> A >> B >> C; vector<ll> p(A), q(B), r(C); for (int i = 0; i < A; i++) { cin >> p.at(i); } for (int i = 0; i < B; i++) { cin >> q.at(i); } for (int i = 0; i < C; i++) { cin >> r.at(i); } sort(p.begin(), p.end()); sort(q.begin(), q.end()); sort(r.begin(), r.end()); ll psum = 0, qsum = 0; ll pk = A - X, qk = B - Y, rk = C - 1; for (int i = 0; i < C; i++) { ll P, Q, R = r.at(rk); if (pk < A) P = p.at(pk); else P = inf; if (qk < B) Q = q.at(qk); else Q = inf; ll low = min(P, Q); if (low == P && P < R && pk < A) { swap(p.at(pk), r.at(rk)); pk++; rk--; } else if (low == Q && Q < R && qk < B) { swap(q.at(qk), r.at(rk)); qk++; rk--; } if (rk < 0) break; } for (int i = A - 1; i >= A - X; i--) { psum += p.at(i); } for (int i = B - 1; i >= B - Y; i--) { qsum += q.at(i); } cout << psum + qsum << endl; }
replace
36
37
36
37
0
p02727
C++
Runtime Error
/* Sviatoslav Bidzilia 2020 CF: anakib1 */ #include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdarg.h> #include <stdio.h> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; #define pb push_back #define mp make_pair #define ll long long #define ull unsigned long long #define ld long double #define all(a) a.begin(), a.end() #define SORT(a) sort(all(a), [](int x, int y) { return x > y; }) #define pii pair<int, int> #define tii triple<int, int, int> #define sz(x) (int)(x.size()) #define e 1e-7 #define PI acos(-1) #define inf 1e17 #define vi vector<int> #define F first #define S second #define rng(x) for (int _ = 0; _ < (x); _++) #define rngi(i, x) for (int i = 0; i < (x); i++) #define rngsi(s, i, x) for (int i = (s); i < (x); i++) #define int long long template <typename A, typename B, typename C> struct triple { A X; B Y; C Z; triple(A a = 0, B b = 0, C c = 0) : X(a), Y(b), Z(c) {} }; template <typename A, typename B, typename C> triple<A, B, C> make_triple(A a = 0, B b = 0, C c = 0) { return triple<A, B, C>(a, b, c); } template <typename A, typename B, typename C> bool operator<(const triple<A, B, C> &a, const triple<A, B, C> &b) { if (a.X != b.X) return a.X < b.X; if (a.Y != b.Y) return a.Y < b.Y; return a.Z < b.Z; } template <typename T, typename SS> ostream &operator<<(ostream &ofs, const pair<T, SS> &p) { ofs << "( " << p.F << " , " << p.S << " )"; return ofs; } template <typename T> void print(T a) { for (auto i : a) cout << i << ' '; cout << '\n'; } template <typename T> T max(T a, T b, T c) { return max(a, max(b, c)); } template <typename T> T min(T a, T b, T c) { return min(a, min(b, c)); } struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; signed main() { // freopen(".in", "r", stdin);a // freopen(".out", "w", stdout); srand(time(NULL)); cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); int x, a, y, b, c; cin >> x >> a >> y >> b >> c; vi f(a); rngi(i, a) cin >> f[i]; vi s(b); rngi(i, b) cin >> s[i]; vi r(c); rngi(i, c) cin >> r[i]; SORT(f); SORT(s); rngi(i, x) r.pb(f[i]); rngi(i, y) r.pb(s[i]); SORT(r); cout << accumulate(r.begin(), r.begin() + x + y, 0LL) << '\n'; } // check corner case (interactives!) // check n=1 or n=2 // check size of arrays // more asserts // scanf printf // read everything normaly
/* Sviatoslav Bidzilia 2020 CF: anakib1 */ #include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdarg.h> #include <stdio.h> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; #define pb push_back #define mp make_pair #define ll long long #define ull unsigned long long #define ld long double #define all(a) a.begin(), a.end() #define SORT(a) sort(all(a), [](int x, int y) { return x > y; }) #define pii pair<int, int> #define tii triple<int, int, int> #define sz(x) (int)(x.size()) #define e 1e-7 #define PI acos(-1) #define inf 1e17 #define vi vector<int> #define F first #define S second #define rng(x) for (int _ = 0; _ < (x); _++) #define rngi(i, x) for (int i = 0; i < (x); i++) #define rngsi(s, i, x) for (int i = (s); i < (x); i++) #define int long long template <typename A, typename B, typename C> struct triple { A X; B Y; C Z; triple(A a = 0, B b = 0, C c = 0) : X(a), Y(b), Z(c) {} }; template <typename A, typename B, typename C> triple<A, B, C> make_triple(A a = 0, B b = 0, C c = 0) { return triple<A, B, C>(a, b, c); } template <typename A, typename B, typename C> bool operator<(const triple<A, B, C> &a, const triple<A, B, C> &b) { if (a.X != b.X) return a.X < b.X; if (a.Y != b.Y) return a.Y < b.Y; return a.Z < b.Z; } template <typename T, typename SS> ostream &operator<<(ostream &ofs, const pair<T, SS> &p) { ofs << "( " << p.F << " , " << p.S << " )"; return ofs; } template <typename T> void print(T a) { for (auto i : a) cout << i << ' '; cout << '\n'; } template <typename T> T max(T a, T b, T c) { return max(a, max(b, c)); } template <typename T> T min(T a, T b, T c) { return min(a, min(b, c)); } struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; signed main() { // freopen(".in", "r", stdin);a // freopen(".out", "w", stdout); srand(time(NULL)); cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); int x, a, y, b, c; cin >> x >> y >> a >> b >> c; vi f(a); rngi(i, a) cin >> f[i]; vi s(b); rngi(i, b) cin >> s[i]; vi r(c); rngi(i, c) cin >> r[i]; SORT(f); SORT(s); rngi(i, x) r.pb(f[i]); rngi(i, y) r.pb(s[i]); SORT(r); cout << accumulate(r.begin(), r.begin() + x + y, 0LL) << '\n'; } // check corner case (interactives!) // check n=1 or n=2 // check size of arrays // more asserts // scanf printf // read everything normaly
replace
110
111
110
111
0
p02727
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int x, y, a, b, c; cin >> x >> y >> a >> b >> c; priority_queue<int> r; priority_queue<int> g; priority_queue<int> C; for (int i = 0; i < a; i++) { int X; cin >> X; r.push(X); } for (int i = 0; i < b; i++) { int X; cin >> X; g.push(X); } for (int i = 0; i < c; i++) { int X; cin >> X; C.push(X); } // cout<<r.size()<<endl; priority_queue<int, vector<int>, greater<int>> A; while (x--) { A.push(r.top()); r.pop(); } while (y--) { A.push(g.top()); g.pop(); } while (A.top() <= C.top()) { A.pop(); A.push(C.top()); C.pop(); } long long ans = 0; while (!A.empty()) { ans += A.top(); A.pop(); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int x, y, a, b, c; cin >> x >> y >> a >> b >> c; priority_queue<int> r; priority_queue<int> g; priority_queue<int> C; for (int i = 0; i < a; i++) { int X; cin >> X; r.push(X); } for (int i = 0; i < b; i++) { int X; cin >> X; g.push(X); } for (int i = 0; i < c; i++) { int X; cin >> X; C.push(X); } // cout<<r.size()<<endl; priority_queue<int, vector<int>, greater<int>> A; while (x--) { A.push(r.top()); r.pop(); } while (y--) { A.push(g.top()); g.pop(); } while (A.top() <= C.top()) { A.pop(); A.push(C.top()); C.pop(); if (C.empty()) break; } long long ans = 0; while (!A.empty()) { ans += A.top(); A.pop(); } cout << ans << endl; return 0; }
insert
37
37
37
39
TLE
p02727
C++
Runtime Error
/* g++ -ggdb -fsanitize=address -std=c++14 E.cpp && ./a.out <<< "1 2 2 2 1 2 4 5 1 3" */ #include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i = a; i < (b); i++) #define trav(a, x) for (auto &a : x) #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; template <typename A> string to_string(A v) { int cnt = 0; string res; for (const auto &x : v) { if (cnt++) res += " "; res += to_string(x); } return "[" + res + "]"; } string to_string(const string &s) { return '"' + s + '"'; } string to_string(const char *s) { return to_string((string)s); } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) int main() { cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit); int X, Y, A, B, C; cin >> X >> Y >> A >> B >> C; vi CostA(A); rep(i, 0, A) cin >> CostA[i]; vi CostB(B); rep(i, 0, B) cin >> CostB[i]; vi CostC(C); rep(i, 0, C) cin >> CostC[i]; sort(all(CostA), [&](int a, int b) { return a > b; }); sort(all(CostB), [&](int a, int b) { return a > b; }); sort(all(CostC), [&](int a, int b) { return a > b; }); vector<int> RG; rep(i, 0, X) RG.push_back(CostA[i]); rep(i, 0, Y) RG.push_back(CostB[i]); sort(all(RG), [&](int a, int b) { return a > b; }); vector<ll> PreRG(sz(RG) + 1); // PreRG[i] = sum(RG[0..i)) PreRG[0] = 0; for (int i = 1; i <= sz(RG); i++) PreRG[i] = PreRG[i - 1] + RG[i - 1]; // debug(CostA); // debug(CostB); // debug(CostC); // debug(RG); // debug(PreRG); ll ans = 0; ll sumC = 0; for (int c = 0; c <= C; c++) { ll cand = sumC + PreRG[X + Y - c]; // debug(c, sumC, cand); ans = max(ans, cand); if (c < C) sumC += CostC[c]; } cout << ans << endl; }
/* g++ -ggdb -fsanitize=address -std=c++14 E.cpp && ./a.out <<< "1 2 2 2 1 2 4 5 1 3" */ #include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i = a; i < (b); i++) #define trav(a, x) for (auto &a : x) #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; template <typename A> string to_string(A v) { int cnt = 0; string res; for (const auto &x : v) { if (cnt++) res += " "; res += to_string(x); } return "[" + res + "]"; } string to_string(const string &s) { return '"' + s + '"'; } string to_string(const char *s) { return to_string((string)s); } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) int main() { cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit); int X, Y, A, B, C; cin >> X >> Y >> A >> B >> C; vi CostA(A); rep(i, 0, A) cin >> CostA[i]; vi CostB(B); rep(i, 0, B) cin >> CostB[i]; vi CostC(C); rep(i, 0, C) cin >> CostC[i]; sort(all(CostA), [&](int a, int b) { return a > b; }); sort(all(CostB), [&](int a, int b) { return a > b; }); sort(all(CostC), [&](int a, int b) { return a > b; }); vector<int> RG; rep(i, 0, X) RG.push_back(CostA[i]); rep(i, 0, Y) RG.push_back(CostB[i]); sort(all(RG), [&](int a, int b) { return a > b; }); vector<ll> PreRG(sz(RG) + 1); // PreRG[i] = sum(RG[0..i)) PreRG[0] = 0; for (int i = 1; i <= sz(RG); i++) PreRG[i] = PreRG[i - 1] + RG[i - 1]; // debug(CostA); // debug(CostB); // debug(CostC); // debug(RG); // debug(PreRG); ll ans = 0; ll sumC = 0; for (int c = 0; c <= C; c++) { int take = X + Y - c; if (take < 0 || take >= sz(PreRG)) continue; ll cand = sumC + PreRG[take]; // debug(c, sumC, cand); ans = max(ans, cand); if (c < C) sumC += CostC[c]; } cout << ans << endl; }
replace
75
76
75
80
0
p02727
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 1e6 + 7; const int inf = INT_MAX; const ll inff = 1e18; const ll mod = 1e9 + 7; #define pii pair<int, int> #define mkp make_pair #define F first #define S second #define pb push_back #define sz(v) ((int)(v).size()) #define all(v) (v).begin(), (v).end() #define int ll #ifdef HNO2 #define IOS #else #define endl '\n' #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); #endif // HNO2 int x, y, a, b, c; vector<int> v1, v2, v3; vector<int> v; int32_t main() { IOS cin >> x >> y >> a >> b >> c; for (int i = 1; i <= a; i++) { int z; cin >> z; v1.pb(z); } for (int i = 1; i <= b; i++) { int z; cin >> z; v2.pb(z); } for (int i = 1; i <= c; i++) { int z; cin >> z; v3.pb(z); } sort(all(v1)); sort(all(v2)); sort(all(v3)); reverse(all(v1)); reverse(all(v2)); reverse(all(v3)); int ans = -1, sum = 0; for (int i = 0; i < x; i++) { sum += v1[i]; v.pb(v1[i]); } for (int i = 0; i < y; i++) { sum += v2[i]; v.pb(v2[i]); } sort(all(v)); reverse(all(v)); ans = max(ans, sum); for (int i = 0; i < min(c, a + b); i++) { sum -= v.back(); v.pop_back(); sum += v3[i]; ans = max(ans, sum); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 1e6 + 7; const int inf = INT_MAX; const ll inff = 1e18; const ll mod = 1e9 + 7; #define pii pair<int, int> #define mkp make_pair #define F first #define S second #define pb push_back #define sz(v) ((int)(v).size()) #define all(v) (v).begin(), (v).end() #define int ll #ifdef HNO2 #define IOS #else #define endl '\n' #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); #endif // HNO2 int x, y, a, b, c; vector<int> v1, v2, v3; vector<int> v; int32_t main() { IOS cin >> x >> y >> a >> b >> c; for (int i = 1; i <= a; i++) { int z; cin >> z; v1.pb(z); } for (int i = 1; i <= b; i++) { int z; cin >> z; v2.pb(z); } for (int i = 1; i <= c; i++) { int z; cin >> z; v3.pb(z); } sort(all(v1)); sort(all(v2)); sort(all(v3)); reverse(all(v1)); reverse(all(v2)); reverse(all(v3)); int ans = -1, sum = 0; for (int i = 0; i < x; i++) { sum += v1[i]; v.pb(v1[i]); } for (int i = 0; i < y; i++) { sum += v2[i]; v.pb(v2[i]); } sort(all(v)); reverse(all(v)); ans = max(ans, sum); for (int i = 0; i < min(c, x + y); i++) { sum -= v.back(); v.pop_back(); sum += v3[i]; ans = max(ans, sum); } cout << ans << endl; }
replace
68
69
68
69
0
p02727
Python
Runtime Error
X, Y, A, B, C = map(int, input().split()) p = sorted([int(i) for i in input().split()], reverse=True) q = sorted([int(i) for i in input().split()], reverse=True) r = sorted([int(i) for i in input().split()]) p = p[:X] q = q[:Y] plus_r = [] while r != [] and (p != [] and r[-1] > p[-1]) or (q != [] and r[-1] > q[-1]): if p[-1] < q[-1]: p.pop() else: q.pop() plus_r.append(r.pop()) print(sum(p) + sum(q) + sum(plus_r))
X, Y, A, B, C = map(int, input().split()) p = sorted([int(i) for i in input().split()], reverse=True) q = sorted([int(i) for i in input().split()], reverse=True) r = sorted([int(i) for i in input().split()]) p = p[:X] q = q[:Y] plus_r = [] while r != [] and ((p != [] and r[-1] > p[-1]) or (q != [] and r[-1] > q[-1])): if p == []: q.pop() plus_r.append(r.pop()) continue elif q == []: p.pop() plus_r.append(r.pop()) continue if p[-1] < q[-1]: p.pop() else: q.pop() plus_r.append(r.pop()) print(sum(p) + sum(q) + sum(plus_r))
replace
9
10
9
19
IndexError: list index out of range
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02727/Python/s816996261.py", line 10, in <module> while r != [] and (p != [] and r[-1] > p[-1]) or (q != [] and r[-1] > q[-1]): IndexError: list index out of range
p02727
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 7; typedef long long ll; ll ans, a[N], b[N], c[N], d[N], A[N], B[N], C[N], x, y, q, w, e; bool cmp(int x, int y) { return x > y; } int main() { cin >> x >> y >> q >> w >> e; for (int i = 1; i <= q; i++) cin >> a[i]; sort(a + 1, a + q + 1, cmp); int cnt = 0; for (int i = 1; i <= x; i++) { d[++cnt] = a[i]; } for (int i = 1; i <= w; i++) cin >> b[i]; sort(b + 1, b + w + 1, cmp); for (int i = 1; i <= y; i++) { d[++cnt] = b[i]; } for (int i = 1; i <= e; i++) { cin >> c[i]; } for (int i = 1; i <= x + y + e; i++) { d[++cnt] = c[i]; } sort(d + 1, d + x + y + e + 1, cmp); for (int i = 1; i <= x + y; i++) { ans += d[i]; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 7; typedef long long ll; ll ans, a[N], b[N], c[N], d[N * 4], A[N], B[N], C[N], x, y, q, w, e; bool cmp(int x, int y) { return x > y; } int main() { cin >> x >> y >> q >> w >> e; for (int i = 1; i <= q; i++) cin >> a[i]; sort(a + 1, a + q + 1, cmp); int cnt = 0; for (int i = 1; i <= x; i++) { d[++cnt] = a[i]; } for (int i = 1; i <= w; i++) cin >> b[i]; sort(b + 1, b + w + 1, cmp); for (int i = 1; i <= y; i++) { d[++cnt] = b[i]; } for (int i = 1; i <= e; i++) { cin >> c[i]; } for (int i = 1; i <= x + y + e; i++) { d[++cnt] = c[i]; } sort(d + 1, d + x + y + e + 1, cmp); for (int i = 1; i <= x + y; i++) { ans += d[i]; } cout << ans << endl; }
replace
4
5
4
5
0
p02727
C++
Runtime Error
#include <algorithm> #include <iostream> using namespace std; const int MAXN = 1e5 + 5; typedef long long ll; int nums1[MAXN], nums2[MAXN], nums3[MAXN]; bool cmp(int a, int b) { return a >= b; } int main() { ios::sync_with_stdio(0); cin.tie(0); int x, y, a, b, c; cin >> x >> y >> a >> b >> c; for (int i = 0; i < a; ++i) cin >> nums1[i]; for (int i = 0; i < b; ++i) cin >> nums2[i]; for (int i = 0; i < c; ++i) cin >> nums3[i]; sort(nums1, nums1 + a, cmp); sort(nums2, nums2 + b, cmp); sort(nums3, nums3 + c, cmp); nums1[x] = 0; nums2[y] = 0; nums3[c] = 0; int p1 = 0, p2 = 0, p3 = 0; ll ans = 0; int cnt = 0; while (cnt < x + y) { if (nums1[p1] >= nums2[p2] && nums1[p1] >= nums3[p3]) { ans += nums1[p1++]; } else if (nums2[p2] >= nums1[p1] && nums2[p2] >= nums3[p3]) { ans += nums2[p2++]; } else ans += nums3[p3++]; ++cnt; } cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> using namespace std; const int MAXN = 1e5 + 5; typedef long long ll; int nums1[MAXN], nums2[MAXN], nums3[MAXN]; bool cmp(int a, int b) { return a > b; } int main() { ios::sync_with_stdio(0); cin.tie(0); int x, y, a, b, c; cin >> x >> y >> a >> b >> c; for (int i = 0; i < a; ++i) cin >> nums1[i]; for (int i = 0; i < b; ++i) cin >> nums2[i]; for (int i = 0; i < c; ++i) cin >> nums3[i]; sort(nums1, nums1 + a, cmp); sort(nums2, nums2 + b, cmp); sort(nums3, nums3 + c, cmp); nums1[x] = 0; nums2[y] = 0; nums3[c] = 0; int p1 = 0, p2 = 0, p3 = 0; ll ans = 0; int cnt = 0; while (cnt < x + y) { if (nums1[p1] >= nums2[p2] && nums1[p1] >= nums3[p3]) { ans += nums1[p1++]; } else if (nums2[p2] >= nums1[p1] && nums2[p2] >= nums3[p3]) { ans += nums2[p2++]; } else ans += nums3[p3++]; ++cnt; } cout << ans << endl; return 0; }
replace
6
7
6
7
0
p02727
C++
Runtime Error
#pragma GCC optimize("O3") #pragma GCC target("avx") // #include<bits/stdc++.h> #include <algorithm> #include <cstdio> #include <cstring> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (n); i++) #define rep1(i, n) for (int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define Would #define you #define please const int cm = 1 << 17; char cn[cm], *ci = cn + cm, ct; inline char getcha() { if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; } return *ci++; } inline int getint() { int A = 0; if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0'; else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0'; return A; } int main() { // cin.tie(0); // ios::sync_with_stdio(false); int X = getint(), Y = getint(), A = getint(), B = getint(), C = getint(); int abc[300000]; auto a = abc; auto b = abc + A; auto c = abc + A + B; rep(i, A + B + C) a[i] = getint(); nth_element(a, b - X, b); nth_element(b, c - Y, c); memcpy(c + C, b - X, X * sizeof(int)); if (B - Y) for (auto i = b - 1; i >= b - X; i--) *(i + B - Y) = *i; nth_element(c - X - Y, c + C - X - Y, c + C); ll kotae = 0; for (auto kari = c + C - X - Y; kari < c + C; kari++) kotae += *kari; printf("%lld", kotae); Would you please return 0; }
#pragma GCC optimize("O3") #pragma GCC target("avx") // #include<bits/stdc++.h> #include <algorithm> #include <cstdio> #include <cstring> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (n); i++) #define rep1(i, n) for (int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define Would #define you #define please const int cm = 1 << 17; char cn[cm], *ci = cn + cm, ct; inline char getcha() { if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; } return *ci++; } inline int getint() { int A = 0; if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0'; else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0'; return A; } int main() { // cin.tie(0); // ios::sync_with_stdio(false); int X = getint(), Y = getint(), A = getint(), B = getint(), C = getint(); int abc[300000]; auto a = abc; auto b = abc + A; auto c = abc + A + B; rep(i, A + B + C) a[i] = getint(); nth_element(a, b - X, b); nth_element(b, c - Y, c); if (B - Y) for (auto i = b - 1; i >= b - X; i--) *(i + B - Y) = *i; nth_element(c - X - Y, c + C - X - Y, c + C); ll kotae = 0; for (auto kari = c + C - X - Y; kari < c + C; kari++) kotae += *kari; printf("%lld", kotae); Would you please return 0; }
delete
57
58
57
57
0
p02727
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll a[100005], b[100005], c[100005]; vector<ll> p; int main() { ll x, y, n, m, k, sum = 0; cin >> x >> y >> n >> m >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = 1; i <= m; i++) { cin >> b[i]; } for (int i = 1; i <= k; i++) { cin >> c[i]; } sort(a + 1, a + 1 + n); reverse(a + 1, a + 1 + n); sort(b + 1, b + 1 + m); reverse(b + 1, b + 1 + m); sort(c + 1, c + 1 + k); reverse(c + 1, c + 1 + k); p.push_back(0); for (int i = 1; i <= x; i++) p.push_back(a[i]); for (int i = 1; i <= y; i++) p.push_back(b[i]); sort(p.begin(), p.end()); for (int i = 1; i <= x + y; i++) { sum += p[i]; } ll ans = sum, num = sum; for (ll i = 1; i <= k; i++) { num -= p[i]; num += c[i]; ans = max(ans, num); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll a[100005], b[100005], c[100005]; vector<ll> p; int main() { ll x, y, n, m, k, sum = 0; cin >> x >> y >> n >> m >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = 1; i <= m; i++) { cin >> b[i]; } for (int i = 1; i <= k; i++) { cin >> c[i]; } sort(a + 1, a + 1 + n); reverse(a + 1, a + 1 + n); sort(b + 1, b + 1 + m); reverse(b + 1, b + 1 + m); sort(c + 1, c + 1 + k); reverse(c + 1, c + 1 + k); p.push_back(0); for (int i = 1; i <= x; i++) p.push_back(a[i]); for (int i = 1; i <= y; i++) p.push_back(b[i]); sort(p.begin(), p.end()); for (int i = 1; i <= x + y; i++) { sum += p[i]; } ll ans = sum, num = sum; for (ll i = 1; i <= min(k, x + y); i++) { num -= p[i]; num += c[i]; ans = max(ans, num); } cout << ans << endl; }
replace
33
34
33
34
0
p02727
C++
Runtime Error
#include <bits/stdc++.h> #pragma GCC optimize("O3") #define ll long long #define ull unsigned long long #define dd double #define oo 1001007000 #define ff float #define ooo 1000000100000000000 #define iii pair<ll, ll> #define vii vector<ll> #define viii vector<iii> #define sss pair<str, str> #define str string #define sii set<ll> #define siii set<iii> #define st size_t #define r0 return 0 #define pb push_back #define sz size using namespace std; const char E = '\n'; const int N = 10005; const int NN = 1000001; const ll md = 998244353; int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); int x, y, a, b, c; cin >> x >> y >> a >> b >> c; ll A[N] = {0}; ll B[N] = {0}; ll C[N] = {0}; for (int i = 1; i <= a; i++) { cin >> A[i]; } for (int i = 1; i <= b; i++) { cin >> B[i]; } for (int i = 1; i <= c; i++) { cin >> C[i]; } sort(A + 1, A + a + 1); sort(B + 1, B + b + 1); sort(C + 1, C + c + 1); vii all; for (int i = 1; i <= x; i++) { all.pb(A[a - i + 1]); } for (int i = 1; i <= y; i++) { all.pb(B[b - i + 1]); } for (int i = 1; i <= min(c, x + y); i++) { all.pb(C[c - i + 1]); } sort(all.rbegin(), all.rend()); ll s = 0; for (int i = 0; i < x + y; i++) { s += all[i]; } cout << s << E; r0; }
#include <bits/stdc++.h> #pragma GCC optimize("O3") #define ll long long #define ull unsigned long long #define dd double #define oo 1001007000 #define ff float #define ooo 1000000100000000000 #define iii pair<ll, ll> #define vii vector<ll> #define viii vector<iii> #define sss pair<str, str> #define str string #define sii set<ll> #define siii set<iii> #define st size_t #define r0 return 0 #define pb push_back #define sz size using namespace std; const char E = '\n'; const int N = 300005; const int NN = 1000001; const ll md = 998244353; int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); int x, y, a, b, c; cin >> x >> y >> a >> b >> c; ll A[N] = {0}; ll B[N] = {0}; ll C[N] = {0}; for (int i = 1; i <= a; i++) { cin >> A[i]; } for (int i = 1; i <= b; i++) { cin >> B[i]; } for (int i = 1; i <= c; i++) { cin >> C[i]; } sort(A + 1, A + a + 1); sort(B + 1, B + b + 1); sort(C + 1, C + c + 1); vii all; for (int i = 1; i <= x; i++) { all.pb(A[a - i + 1]); } for (int i = 1; i <= y; i++) { all.pb(B[b - i + 1]); } for (int i = 1; i <= min(c, x + y); i++) { all.pb(C[c - i + 1]); } sort(all.rbegin(), all.rend()); ll s = 0; for (int i = 0; i < x + y; i++) { s += all[i]; } cout << s << E; r0; }
replace
22
23
22
23
0
p02727
Python
Time Limit Exceeded
def main(): X, Y, A, B, C = tuple(map(int, input().split())) P = tuple(map(int, input().split())) Q = tuple(map(int, input().split())) R = tuple(map(int, input().split())) P = sorted(P, reverse=True) Q = sorted(Q, reverse=True) R = sorted(R, reverse=True) x = P[:X] y = Q[:Y] for r_i in R: if r_i < min(x[-1], y[-1]): break else: if x[-1] < y[-1]: x[-1] = r_i # x = sorted(x, reverse=True) x.sort(reverse=True) else: y[-1] = r_i # y = sorted(y, reverse=True) y.sort(reverse=True) print(sum(x) + sum(y)) if __name__ == "__main__": main()
def main(): X, Y, A, B, C = tuple(map(int, input().split())) P = tuple(map(int, input().split())) Q = tuple(map(int, input().split())) R = tuple(map(int, input().split())) P = sorted(P, reverse=True) Q = sorted(Q, reverse=True) R = sorted(R, reverse=True) x = P[:X] y = Q[:Y] saikyo = sorted(x + y + R, reverse=True) print(sum(saikyo[: (X + Y)])) if __name__ == "__main__": main()
replace
13
27
13
15
TLE
p02727
Python
Runtime Error
x, y, a, b, c = map(int, input().split()) ps = list(map(int, input().split())) qs = list(map(int, input().split())) rs = list(map(int, input().split())) ps.sort() ps = ps[-x:] qs.sort() qs = qs[-y:] pqs = ps + qs pqs.sort() rs.sort(reverse=True) answer = sum(pqs) for i in range(c): diff = rs[i] - pqs[i] if diff < 0: break answer += diff print(answer)
x, y, a, b, c = map(int, input().split()) ps = list(map(int, input().split())) qs = list(map(int, input().split())) rs = list(map(int, input().split())) ps.sort() ps = ps[-x:] qs.sort() qs = qs[-y:] pqs = ps + qs pqs.sort() rs.sort(reverse=True) answer = sum(pqs) for i in range(min(x + y, c)): diff = rs[i] - pqs[i] if diff < 0: break answer += diff print(answer)
replace
13
14
13
14
0
p02727
Python
Runtime Error
from collections import deque def main(): X, Y, A, B, C = map(int, input().split(" ")) a_list = list(map(int, input().split(" "))) b_list = list(map(int, input().split(" "))) c_list = list(map(int, input().split(" "))) a_deq = deque(sorted(a_list, reverse=True)[:X]) b_deq = deque(sorted(b_list, reverse=True)[:Y]) c_deq = deque(sorted(c_list, reverse=True)) result = sum(a_deq) + sum(b_deq) while len(c_deq) != 0: min_ab = 0 if a_deq[-1] < b_deq[-1]: min_ab = a_deq.pop() else: min_ab = b_deq.pop() if min_ab >= c_deq[0]: break result += c_deq.popleft() - min_ab print(result) if __name__ == "__main__": main()
from collections import deque def main(): X, Y, A, B, C = map(int, input().split(" ")) a_list = list(map(int, input().split(" "))) b_list = list(map(int, input().split(" "))) c_list = list(map(int, input().split(" "))) a_deq = deque(sorted(a_list, reverse=True)[:X]) b_deq = deque(sorted(b_list, reverse=True)[:Y]) c_deq = deque(sorted(c_list, reverse=True)) result = sum(a_deq) + sum(b_deq) while len(c_deq) > 0: try: if a_deq[-1] < b_deq[-1]: min_ab = a_deq.pop() else: min_ab = b_deq.pop() except IndexError: if len(a_deq) > 0: min_ab = a_deq.pop() elif len(b_deq) > 0: min_ab = b_deq.pop() else: break if min_ab >= c_deq[0]: break result += c_deq.popleft() - min_ab print(result) if __name__ == "__main__": main()
replace
12
18
12
26
0
p02727
Python
Runtime Error
# -*- coding: utf-8 -*- X, Y, A, B, C = map(int, input().split()) p = list(map(int, input().split())) q = list(map(int, input().split())) r = list(map(int, input().split())) # all_apples = sorted(p + q + r, key=lambda x: -x) p_rest = sorted(p) q_rest = sorted(q) r_rest = sorted(r) ans = 0 p_count = 0 q_count = 0 r_count = 0 while (p_count + q_count + r_count) < (X + Y): if p_count < X and q_count < Y: candidates = [p_rest[-1], q_rest[-1], r_rest[-1]] elif p_count < X and q_count == Y: candidates = [p_rest[-1], 0, r_rest[-1]] elif p_count == X and q_count < Y: candidates = [0, q_rest[-1], r_rest[-1]] wanna_eat = max(candidates) eat_idx = candidates.index(wanna_eat) if eat_idx == 0: p_count += 1 ans += p_rest.pop() elif eat_idx == 1: q_count += 1 ans += q_rest.pop() else: r_count += 1 ans += r_rest.pop() # print(candidates, eat_idx, wanna_eat, p_count, q_count, r_count) print(ans)
# -*- coding: utf-8 -*- X, Y, A, B, C = map(int, input().split()) p = list(map(int, input().split())) q = list(map(int, input().split())) r = list(map(int, input().split())) # all_apples = sorted(p + q + r, key=lambda x: -x) p_rest = sorted(p + [0]) q_rest = sorted(q + [0]) r_rest = sorted(r + [0]) ans = 0 p_count = 0 q_count = 0 r_count = 0 while (p_count + q_count + r_count) < (X + Y): if p_count < X and q_count < Y: candidates = [p_rest[-1], q_rest[-1], r_rest[-1]] elif p_count < X and q_count == Y: candidates = [p_rest[-1], 0, r_rest[-1]] elif p_count == X and q_count < Y: candidates = [0, q_rest[-1], r_rest[-1]] wanna_eat = max(candidates) eat_idx = candidates.index(wanna_eat) if eat_idx == 0: p_count += 1 ans += p_rest.pop() elif eat_idx == 1: q_count += 1 ans += q_rest.pop() else: r_count += 1 ans += r_rest.pop() # print(candidates, eat_idx, wanna_eat, p_count, q_count, r_count) print(ans)
replace
9
12
9
12
0
p02727
Python
Time Limit Exceeded
X, Y, A, B, C = map(int, input().split()) p, pi = sorted(list(map(int, input().split())), reverse=True)[:X] + [-1], 0 q, qi = sorted(list(map(int, input().split())), reverse=True)[:Y] + [-1], 0 r, ri = sorted(list(map(int, input().split())), reverse=True) + [-1], 0 ans, nX, nY = 0, 0, 0 while nX < X or nY < Y: if r[ri] >= p[pi] and r[ri] >= q[qi]: if nX < X and nY < Y: if p[pi] >= q[qi]: nX += 1 else: nY += 1 elif nX < X: nX += 1 elif nY < Y: nY += 1 ans += r[ri] ri += 1 elif p[pi] >= q[qi] and p[pi] >= r[ri]: if nX < X: nX += 1 ans += p[pi] pi += 1 elif q[qi] >= r[ri] and q[qi] >= p[pi]: if nY < Y: nY += 1 ans += q[qi] qi += 1 print(ans)
X, Y, A, B, C = map(int, input().split()) p = sorted(list(map(int, input().split())))[-X:] q = sorted(list(map(int, input().split())))[-Y:] r = list(map(int, input().split())) print(sum(sorted(p + q + r)[-(X + Y) :]))
replace
1
30
1
5
TLE
p02727
Python
Runtime Error
X, Y, A, B, C = map(int, input().split()) P = list(map(int, input().split())) Q = list(map(int, input().split())) R = list(map(int, input().split())) P.sort(reverse=True) Q.sort(reverse=True) R.sort(reverse=True) S = P[:X] + Q[:Y] S.sort(reverse=True) S_wa = [] wa = 0 for s in S[::-1]: wa += s S_wa.append(wa) # print(S_wa) big = S_wa[-1] ans = S_wa[-1] R_wa = [] wa = 0 for r in R: wa += r R_wa.append(wa) # print(R_wa) for i in range(len(R_wa)): ans = max(ans, big + R_wa[i] - S_wa[i]) print(ans)
X, Y, A, B, C = map(int, input().split()) P = list(map(int, input().split())) Q = list(map(int, input().split())) R = list(map(int, input().split())) P.sort(reverse=True) Q.sort(reverse=True) R.sort(reverse=True) S = P[:X] + Q[:Y] S.sort(reverse=True) S_wa = [] wa = 0 for s in S[::-1]: wa += s S_wa.append(wa) # print(S_wa) big = S_wa[-1] ans = S_wa[-1] R_wa = [] wa = 0 for r in R: wa += r R_wa.append(wa) # print(R_wa) kazu = min(len(R_wa), len(S_wa)) for i in range(kazu): ans = max(ans, big + R_wa[i] - S_wa[i]) print(ans)
replace
28
29
28
31
0
p02727
C++
Runtime Error
#include <algorithm> #include <functional> #include <iostream> #include <vector> using namespace std; const int INF = 10010001; int main() { int x, y, a, b, c; cin >> x >> y >> a >> b >> c; pair<long long, int> apple[100009]; for (int i = 0; i < a; ++i) { cin >> apple[i].first; apple[i].second = 1; } for (int i = 0; i < b; ++i) { cin >> apple[a + i].first; apple[a + i].second = 2; } for (int i = 0; i < c; ++i) { cin >> apple[a + b + i].first; apple[a + b + i].second = 0; } sort(apple, apple + a + b + c, greater<pair<long long, int>>()); // for(int i=0;i<a+b+c;++i) cout<<apple[i].first<<" "<<apple[i].second<<endl; long long ans = 0; bool endx = false, endy = false; vector<int> count(4, 0); for (int i = 0; i < a + b + c; ++i) { if (apple[i].second == 1 && endx) continue; if (apple[i].second == 2 && endy) continue; ans += apple[i].first; count[apple[i].second]++; count[3]++; if (count[1] == x) endx = true; if (count[2] == y) endy = true; if (count[3] == x + y) break; } cout << ans << endl; }
#include <algorithm> #include <functional> #include <iostream> #include <vector> using namespace std; const int INF = 10010001; int main() { int x, y, a, b, c; cin >> x >> y >> a >> b >> c; pair<long long, int> apple[300009]; for (int i = 0; i < a; ++i) { cin >> apple[i].first; apple[i].second = 1; } for (int i = 0; i < b; ++i) { cin >> apple[a + i].first; apple[a + i].second = 2; } for (int i = 0; i < c; ++i) { cin >> apple[a + b + i].first; apple[a + b + i].second = 0; } sort(apple, apple + a + b + c, greater<pair<long long, int>>()); // for(int i=0;i<a+b+c;++i) cout<<apple[i].first<<" "<<apple[i].second<<endl; long long ans = 0; bool endx = false, endy = false; vector<int> count(4, 0); for (int i = 0; i < a + b + c; ++i) { if (apple[i].second == 1 && endx) continue; if (apple[i].second == 2 && endy) continue; ans += apple[i].first; count[apple[i].second]++; count[3]++; if (count[1] == x) endx = true; if (count[2] == y) endy = true; if (count[3] == x + y) break; } cout << ans << endl; }
replace
10
11
10
11
0
p02727
C++
Runtime Error
#include <bits/stdc++.h> #define forr(i, a, b) for (int i = (a); i < (b); i++) #define rep(i, n) for (int i = 0; i < (n); i++) #define rrep(i, n) for (int i = 1; i <= (n); i++) #define ALL(a) (a.begin()), (a.end()) using namespace std; typedef long long ll; typedef pair<int, int> P; typedef pair<ll, ll> LP; const ll LINF = 1LL << 60; const int INF = 1001001001; const int MOD = 1000000007; /* --------------------------------------------------- */ int main() { int x, y, a, b, c; cin >> x >> y >> a >> b >> c; vector<int> p(a), q(b), r(c); rep(i, a) cin >> p[i]; rep(i, b) cin >> q[i]; rep(i, c) cin >> r[i]; sort(ALL(p), greater<int>()); sort(ALL(q), greater<int>()); sort(ALL(r), greater<int>()); vector<int> ans; rep(i, x) ans.push_back(p[i]); rep(i, y) ans.push_back(q[i]); sort(ALL(ans)); int rcnt = 0; rep(i, c) { if (r[rcnt] >= ans[i]) { ans[i] = r[rcnt]; rcnt++; } else break; } ll res = 0; for (auto x : ans) res += x; cout << res << endl; return 0; }
#include <bits/stdc++.h> #define forr(i, a, b) for (int i = (a); i < (b); i++) #define rep(i, n) for (int i = 0; i < (n); i++) #define rrep(i, n) for (int i = 1; i <= (n); i++) #define ALL(a) (a.begin()), (a.end()) using namespace std; typedef long long ll; typedef pair<int, int> P; typedef pair<ll, ll> LP; const ll LINF = 1LL << 60; const int INF = 1001001001; const int MOD = 1000000007; /* --------------------------------------------------- */ int main() { int x, y, a, b, c; cin >> x >> y >> a >> b >> c; vector<int> p(a), q(b), r(c); rep(i, a) cin >> p[i]; rep(i, b) cin >> q[i]; rep(i, c) cin >> r[i]; sort(ALL(p), greater<int>()); sort(ALL(q), greater<int>()); sort(ALL(r), greater<int>()); vector<int> ans; rep(i, x) ans.push_back(p[i]); rep(i, y) ans.push_back(q[i]); sort(ALL(ans)); int rcnt = 0; int n = min(c, (int)ans.size()); rep(i, n) { if (r[rcnt] >= ans[i]) { ans[i] = r[rcnt]; rcnt++; } else break; } ll res = 0; for (auto x : ans) res += x; cout << res << endl; return 0; }
replace
31
32
31
33
0
p02727
C++
Runtime Error
#include <bits/stdc++.h> #define mes(a, b) memset(a, b, sizeof a) #define pb push_back typedef unsigned long long int ull; typedef long long int ll; const int maxn = 2e5 + 20; const int maxm = 1e5 + 10; const ll mod = 1e9 + 7; const ll INF = 1e18 + 100; const int inf = 0x3f3f3f3f; const double pi = acos(-1.0); const double eps = 1e-8; using namespace std; struct node { ll val, id; bool operator<(const node &a) const { return val > a.val; } } a[maxn]; int main() { int x, y, n, m, k; scanf("%d %d %d %d %d", &x, &y, &n, &m, &k); int tot = 0; for (int i = 1; i <= n; i++) scanf("%lld", &a[++tot].val), a[tot].id = 1; for (int i = 1; i <= m; i++) scanf("%lld", &a[++tot].val), a[tot].id = 2; for (int i = 1; i <= k; i++) scanf("%lld", &a[++tot].val), a[tot].id = 3; sort(a + 1, a + 1 + tot); int sum = x + y; ll ans = 0; for (int i = 1; i <= tot; i++) { if (sum == 0) break; if (a[i].id == 3) ans += a[i].val, sum--; else if (a[i].id == 2 && y) y--, sum--, ans += a[i].val; else if (a[i].id == 1 && x) x--, sum--, ans += a[i].val; } cout << ans << "\n"; }
#include <bits/stdc++.h> #define mes(a, b) memset(a, b, sizeof a) #define pb push_back typedef unsigned long long int ull; typedef long long int ll; const int maxn = 1e6 + 20; const int maxm = 1e5 + 10; const ll mod = 1e9 + 7; const ll INF = 1e18 + 100; const int inf = 0x3f3f3f3f; const double pi = acos(-1.0); const double eps = 1e-8; using namespace std; struct node { ll val, id; bool operator<(const node &a) const { return val > a.val; } } a[maxn]; int main() { int x, y, n, m, k; scanf("%d %d %d %d %d", &x, &y, &n, &m, &k); int tot = 0; for (int i = 1; i <= n; i++) scanf("%lld", &a[++tot].val), a[tot].id = 1; for (int i = 1; i <= m; i++) scanf("%lld", &a[++tot].val), a[tot].id = 2; for (int i = 1; i <= k; i++) scanf("%lld", &a[++tot].val), a[tot].id = 3; sort(a + 1, a + 1 + tot); int sum = x + y; ll ans = 0; for (int i = 1; i <= tot; i++) { if (sum == 0) break; if (a[i].id == 3) ans += a[i].val, sum--; else if (a[i].id == 2 && y) y--, sum--, ans += a[i].val; else if (a[i].id == 1 && x) x--, sum--, ans += a[i].val; } cout << ans << "\n"; }
replace
5
6
5
6
0
p02727
Python
Runtime Error
X, Y, A, B, C = map(int, input().split()) P = sorted(map(int, input().split())) Q = sorted(map(int, input().split())) R = sorted(map(int, input().split())) ans = 0 for _ in range(X): if P[-1] > R[-1]: ans += P.pop() else: ans += R.pop() for _ in range(Y): if Q[-1] > R[-1]: ans += Q.pop() else: ans += R.pop() print(ans)
X, Y, A, B, C = map(int, input().split()) P = sorted(map(int, input().split())) Q = sorted(map(int, input().split())) R = sorted(map(int, input().split())) cand = sorted(P[-X:] + Q[-Y:] + R) print(sum(cand[-X - Y :]))
replace
5
19
5
7
0
p02727
C++
Runtime Error
#pragma GCC optimize( \ "Ofast") // Comment optimisations for interactive problems (use endl) #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") #include <bits/stdc++.h> using namespace std; #define fastio \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); \ cout << fixed; \ cout << setprecision(10); #define randomINIT \ mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); #define foo(i, a, n) for (ll i = (a); i <= n; i++) #define frr(i, a, n) for (ll i = (a); i >= n; i--) #define fo(i, n) for (ll i = 0; i < n; i++) #define all(x) (x).begin(), (x).end() #define mset(x, val) memset(x, val, sizeof(x)) #define newl cout << "\n" #define pb push_back #define mp make_pair #define s second #define f first #define dline cerr << "///REACHED///\n"; #define deb1(x) cerr << #x << " = " << x << '\n'; #define deb2(x, y) \ cerr << '[' << #x << ',' << #y << "] = " << '[' << x << ',' << y << ']' \ << '\n'; #define deb3(x, y, z) \ cerr << '[' << #x << ',' << #y << ',' << #z << "] = " << '[' << x << ',' \ << y << ',' << z << ']' << '\n'; typedef long long ll; typedef long double ld; typedef pair<ll, ll> pll; typedef vector<ll> vll; typedef vector<pll> vpll; const ll MOD = 1e+9 + 7; const ll INF = 0x7f7f7f7f7f7f7f7f; const int INFi = 0x7f7f7f7f; const ll MAXN = 1e+5 + 7; vll adj[MAXN]; ll visit[MAXN] = {}; int dx8[] = {0, 1, 1, 1, 0, -1, -1, -1}, dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}; int dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0}; //<<-----Declare Variable Here------->>// int t = 1; ll x, y, a, b, c, h; vll v1, v2, v3, v4; //<<-----Implement Functions Here---->>// //<<-----Start of Main--------------->>// void MAIN() { cin >> x >> y >> a >> b >> c; for (ll i = 0; i < a; i++) cin >> h, v1.pb(h); for (ll i = 0; i < b; i++) cin >> h, v2.pb(h); for (ll i = 0; i < c; i++) cin >> h, v3.pb(h); sort(all(v1)); reverse(all(v1)); sort(all(v2)); reverse(all(v2)); sort(all(v3)); reverse(all(v3)); for (ll i = 0; i < x; i++) v4.pb(v1[i]); for (ll i = 0; i < y; i++) v4.pb(v2[i]); sort(all(v4)); ll len = min(x + y, c); for (ll i = 0; i < len; i++) { if (v3[i] > v4[i]) v4[i] = v3[i]; else break; } ll sum1 = 0; for (ll i = 0; i < x + y; i++) sum1 += v4[i]; cout << sum1; } int main() { fastio; randomINIT; // cin>>t; while (t--) { MAIN(); } }
#include <bits/stdc++.h> using namespace std; #define fastio \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); \ cout << fixed; \ cout << setprecision(10); #define randomINIT \ mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); #define foo(i, a, n) for (ll i = (a); i <= n; i++) #define frr(i, a, n) for (ll i = (a); i >= n; i--) #define fo(i, n) for (ll i = 0; i < n; i++) #define all(x) (x).begin(), (x).end() #define mset(x, val) memset(x, val, sizeof(x)) #define newl cout << "\n" #define pb push_back #define mp make_pair #define s second #define f first #define dline cerr << "///REACHED///\n"; #define deb1(x) cerr << #x << " = " << x << '\n'; #define deb2(x, y) \ cerr << '[' << #x << ',' << #y << "] = " << '[' << x << ',' << y << ']' \ << '\n'; #define deb3(x, y, z) \ cerr << '[' << #x << ',' << #y << ',' << #z << "] = " << '[' << x << ',' \ << y << ',' << z << ']' << '\n'; typedef long long ll; typedef long double ld; typedef pair<ll, ll> pll; typedef vector<ll> vll; typedef vector<pll> vpll; const ll MOD = 1e+9 + 7; const ll INF = 0x7f7f7f7f7f7f7f7f; const int INFi = 0x7f7f7f7f; const ll MAXN = 1e+5 + 7; vll adj[MAXN]; ll visit[MAXN] = {}; int dx8[] = {0, 1, 1, 1, 0, -1, -1, -1}, dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}; int dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0}; //<<-----Declare Variable Here------->>// int t = 1; ll x, y, a, b, c, h; vll v1, v2, v3, v4; //<<-----Implement Functions Here---->>// //<<-----Start of Main--------------->>// void MAIN() { cin >> x >> y >> a >> b >> c; for (ll i = 0; i < a; i++) cin >> h, v1.pb(h); for (ll i = 0; i < b; i++) cin >> h, v2.pb(h); for (ll i = 0; i < c; i++) cin >> h, v3.pb(h); sort(all(v1)); reverse(all(v1)); sort(all(v2)); reverse(all(v2)); sort(all(v3)); reverse(all(v3)); for (ll i = 0; i < x; i++) v4.pb(v1[i]); for (ll i = 0; i < y; i++) v4.pb(v2[i]); sort(all(v4)); ll len = min(x + y, c); for (ll i = 0; i < len; i++) { if (v3[i] > v4[i]) v4[i] = v3[i]; else break; } ll sum1 = 0; for (ll i = 0; i < x + y; i++) sum1 += v4[i]; cout << sum1; } int main() { fastio; randomINIT; // cin>>t; while (t--) { MAIN(); } }
replace
0
4
0
1
0
p02727
C++
Runtime Error
// #pragma GCC diagnostic error "-std=c++11" #include <bits/stdc++.h> #define pb push_back #define rep(i, a, b) for (int i = a; i <= b; ++i) #define per(i, b, a) for (int i = b; i >= a; --i) #define gcd(a, b) __gcd(a, b) #define MEM(a, x) memset(a, x, sizeof(a)) #define VI vector<int> #define ll long long #define INF 0x3f3f3f3f using namespace std; const int N = 2e5 + 5; template <class T> inline void read(T &res) { char c; T flag = 1; while ((c = getchar()) < '0' || c > '9') if (c == '-') flag = -1; res = c - '0'; while ((c = getchar()) >= '0' && c <= '9') res = res * 10 + c - '0'; res *= flag; } int x, y, a, b, c; ll p[N], q[N], r[N]; bool cmp(int a, int b) { return a > b; } vector<ll> v; int main() { cin >> x >> y >> a >> b >> c; rep(i, 1, a) read(p[i]); rep(i, 1, b) read(q[i]); rep(i, 1, c) read(r[i]); sort(p + 1, p + 1 + a, cmp); sort(q + 1, q + 1 + b, cmp); sort(r + 1, r + 1 + c, cmp); ll ans = 0; rep(i, 1, x) v.pb(p[i]); rep(i, 1, y) v.pb(q[i]); sort(v.begin(), v.end()); int now = 0; rep(i, 1, c) { if (r[i] > v[now]) v[now] = r[i]; now++; } rep(i, 0, v.size() - 1) ans += v[i]; cout << ans << '\n'; return 0; }
// #pragma GCC diagnostic error "-std=c++11" #include <bits/stdc++.h> #define pb push_back #define rep(i, a, b) for (int i = a; i <= b; ++i) #define per(i, b, a) for (int i = b; i >= a; --i) #define gcd(a, b) __gcd(a, b) #define MEM(a, x) memset(a, x, sizeof(a)) #define VI vector<int> #define ll long long #define INF 0x3f3f3f3f using namespace std; const int N = 2e5 + 5; template <class T> inline void read(T &res) { char c; T flag = 1; while ((c = getchar()) < '0' || c > '9') if (c == '-') flag = -1; res = c - '0'; while ((c = getchar()) >= '0' && c <= '9') res = res * 10 + c - '0'; res *= flag; } int x, y, a, b, c; ll p[N], q[N], r[N]; bool cmp(int a, int b) { return a > b; } vector<ll> v; int main() { cin >> x >> y >> a >> b >> c; rep(i, 1, a) read(p[i]); rep(i, 1, b) read(q[i]); rep(i, 1, c) read(r[i]); sort(p + 1, p + 1 + a, cmp); sort(q + 1, q + 1 + b, cmp); sort(r + 1, r + 1 + c, cmp); ll ans = 0; rep(i, 1, x) v.pb(p[i]); rep(i, 1, y) v.pb(q[i]); sort(v.begin(), v.end()); int now = 0; rep(i, 1, c) { if (now < v.size() && r[i] > v[now]) v[now] = r[i]; now++; } rep(i, 0, v.size() - 1) ans += v[i]; cout << ans << '\n'; return 0; }
replace
41
42
41
42
0
p02727
C++
Runtime Error
// _____ ---===-- _____ // . '' `` -. // . ' ` // . // .' _ _ _ ` . // / ' ' '' -- . `\ // | ` -. /\ // \ ______ ----- ____ ` -. .'|_ // \\mmmNNNNNNNNNNNNmm==____` - . _ `.` - // ....... - ' . ' | // |"""""""""""""MNNNNNNNNNNNNNNNm==___ ` - . _ // \ .---====-- .. ' | // -''''''''''' ` - __ '"""MMNNNNNNNNNNNmm===______ "| __ // | | NN) ( // / ::::::::::::::::::::::::::` - . __ // '"""MNNNNNNNNNNNNN\ (NNN* | |__...J // / ::::::::::::::::::::::::::::::::::::::::::` - . __ '"""\ // . ''| ` . // / ::::::::::::::::::::::::::::::::::::::::::::::::::: '''' / // -- ' / |::\ \ ,) `. // / ::' ':::::::::/:::::::::::::::::::::'':: ::: ::::::::/ // ( / |:::\ "" _. '' // / ::' :/:' :: / ::::: ::: :. .::\:::::::::::::< _ // /::::::\ /\ // / .:::::::::/::...:. / :::::....:::::::::::::::\:::::::::::::::\:`:- // /::::\::::`:N\ // / // ::/:::::::/::::::::/::::::::::::::::::::::::::::::::\:::::::\::::::|::::|::::::|::::::N\ // | ::|:::::::|:::::::/ // |:::::::::/|:::::::::/:::::\::::::\:::::::\:::::|::::|:::::::|::::::N| // | ::|:::::::|::::::/ |:|::::::| |::::::::| // |:::::\::::::\:::::::|:::/:::::]::::::::::::::N\ | ::|:::::::|:::::/ // |:|::::::| |::::::::| \:::::\\:::::\::::::|::/:::::/:::::::/:::::::NN| // | ::|:::::::|::::| \:\:::::| // \::::::::\ --\::::\_\::::|:::::|:/:::::/:::::::/::::::::NN| // |::|:::::::|::::|-'""""\:\:::| // \::\-::::\ `-|\:\ `-:|:::::|:::::::::::::/:::::|:::::N| // |::|::::\::\::\::| ___ \ `-_:\ "-\ `-__ --'''___;_ // |::::|:::::::::.m'\:::::::|::::N| // \::\::::|:::\:\--\___ `- ` '" "" ggmm@@@@@@@@@m // ):::/:::::::. @@XXL|:::::::\:::N| // \::\::::\:::\mN**@@@@@mm \ |::TT:::/::::/N:::::/ // @@@@XXL|::::::::\::NN\ // \N:NN\:::-.::\ |::TT::| ` . _\:::::/ // /::7NN:::/::|@@@@XXL|:::::::::\::NN\ // \NNN\\'n-:`N\ - \::::/ / / // /NN::::/:::|@@@XXL/:::::::::::\::NN\ // `"NN\ `-NN''\ _7 " // \:::::\::|LXXXLL/:::::::::::::`.NNN\ // `-NN\ \NNNN\ |\::::\:|<LLLL/\:::::::::::::\::`NN\ // ` '|NNNN\ ' /NNN`m- // >NN|::\NN\:::::\:::::::\:::::`. // |NNNNNN\ .i'/:::::::/NN|:::\NN\::::::\:::::::\::::::`;-. // |NNNNNN/:/`. .__. . ' // |/::/::::/NNN|:::::\N\:::::::`.:::::`Nn::::::::`m-. // /NNNNN/:n/:::|` . . ' // /::y::::/NN::N|:::\::\|:::::::::`.:::::"-.::::::::::`m. // /NNN.':://::::|NNNN/` . . ' // /:::/:::/"""">NN\::::\:::`.:::::.:::::::::::`-.:::::::::) // /."':::.'N::::::|NNN/::\::__`'''\ /::::::::|@@@@||NN\::::::::::`.::::` // .::::::::::::`.-.::/ // -'::::::m':/:::::::/NN/:::::|ffffrrrrmmmmmmmm@@@@@|:::::::\N|@@@| // \:\N\::::::::::::`.:::::`.::::::::::::::::`.. // /::::::m'::.':::::/::/"':::::/ // /\fffffffffffff@@@@@@@|::::::::\|@@@| // N`.\NN`.::::::::::::`.:::::`-.::::::::.:::::::` . // \::::mT:':::::::/:.':::::::,'/MMM\N. ffffffff @@|:::::::::\@@/. // NNNNNNNNN`m.:::::::::"=::::::"Nn:::::::`.::::::::`. // -':':::::::::::.':/:::::::://MMM. ""*fffffffffffffffff@\:::::::::\" // gg` - . NNNN\`n.::::::".::::::"N:::::::"n::::::::| // .- ':::.:::::::.':.':::/::::::::/- ' Mng """""""""" // `\::|::::::\M*",,,,,,,,,,,,` .\\N`.::::|:::::::|::::::::|:::::::/ // /':::::.'::::::.'::/::::n/::::::::|,,,,,, // "**++g,,________,,,,,,mmm\::\:::::::\,,,,,,,,,,,,gnNN" ` // .N)::/::.:::|::::::|::N|:::.'' //|:::. '::::::n":::/":::N" //\:\::::::|,,,,,,,,,,,,,**/NN/*******,,,,,,,,`.|`.:::::|,,,,,, gnN*."' //\:.:::|::::\::::::\nN::/ //.|::::::::,n":::,":::,N \:\:::::\,,,,,,,,,,,,,,/NN/,,,,,,,,,,,,,,,,,,| `. //|ggnN**" / |::::|::::::::::::\Nm:| #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; #define p_ary(ary, a, b) \ do { \ cout << "["; \ for (int count = (a); count < (b); ++count) \ cout << ary[count] << ((b)-1 == count ? "" : ", "); \ cout << "]\n"; \ } while (0) #define p_map(map, it) \ do { \ cout << "{"; \ for (auto(it) = map.begin();; ++(it)) { \ if ((it) == map.end()) { \ cout << "}\n"; \ break; \ } else \ cout << "" << (it)->first << "=>" << (it)->second << ", "; \ } \ } while (0) template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { os << "(" << a.first << ", " << a.second << ")"; return os; } const char newl = '\n'; int main() { int x, y, a, b, c; cin >> x >> y >> a >> b >> c; vector<int> p(a), q(b), r(c); for (int i = 0; i < a; ++i) cin >> p[i]; for (int i = 0; i < b; ++i) cin >> q[i]; for (int i = 0; i < c; ++i) cin >> r[i]; sort(p.begin(), p.end()); sort(q.begin(), q.end()); sort(r.begin(), r.end()); reverse(p.begin(), p.end()); reverse(q.begin(), q.end()); reverse(r.begin(), r.end()); p.push_back(0); q.push_back(0); int i = 0, j = 0, k = 0; ll ans = 0; while (x || y) { if (x && (k == c || (k < c && p[i] >= r[k]))) { ans += p[i++]; x--; } else if (y && (k == c || (k < c && q[j] >= r[k]))) { ans += q[j++]; y--; } else { ans += r[k++]; (p[i + x] < q[j + y] ? x-- : y--); } } cout << ans << endl; }
// _____ ---===-- _____ // . '' `` -. // . ' ` // . // .' _ _ _ ` . // / ' ' '' -- . `\ // | ` -. /\ // \ ______ ----- ____ ` -. .'|_ // \\mmmNNNNNNNNNNNNmm==____` - . _ `.` - // ....... - ' . ' | // |"""""""""""""MNNNNNNNNNNNNNNNm==___ ` - . _ // \ .---====-- .. ' | // -''''''''''' ` - __ '"""MMNNNNNNNNNNNmm===______ "| __ // | | NN) ( // / ::::::::::::::::::::::::::` - . __ // '"""MNNNNNNNNNNNNN\ (NNN* | |__...J // / ::::::::::::::::::::::::::::::::::::::::::` - . __ '"""\ // . ''| ` . // / ::::::::::::::::::::::::::::::::::::::::::::::::::: '''' / // -- ' / |::\ \ ,) `. // / ::' ':::::::::/:::::::::::::::::::::'':: ::: ::::::::/ // ( / |:::\ "" _. '' // / ::' :/:' :: / ::::: ::: :. .::\:::::::::::::< _ // /::::::\ /\ // / .:::::::::/::...:. / :::::....:::::::::::::::\:::::::::::::::\:`:- // /::::\::::`:N\ // / // ::/:::::::/::::::::/::::::::::::::::::::::::::::::::\:::::::\::::::|::::|::::::|::::::N\ // | ::|:::::::|:::::::/ // |:::::::::/|:::::::::/:::::\::::::\:::::::\:::::|::::|:::::::|::::::N| // | ::|:::::::|::::::/ |:|::::::| |::::::::| // |:::::\::::::\:::::::|:::/:::::]::::::::::::::N\ | ::|:::::::|:::::/ // |:|::::::| |::::::::| \:::::\\:::::\::::::|::/:::::/:::::::/:::::::NN| // | ::|:::::::|::::| \:\:::::| // \::::::::\ --\::::\_\::::|:::::|:/:::::/:::::::/::::::::NN| // |::|:::::::|::::|-'""""\:\:::| // \::\-::::\ `-|\:\ `-:|:::::|:::::::::::::/:::::|:::::N| // |::|::::\::\::\::| ___ \ `-_:\ "-\ `-__ --'''___;_ // |::::|:::::::::.m'\:::::::|::::N| // \::\::::|:::\:\--\___ `- ` '" "" ggmm@@@@@@@@@m // ):::/:::::::. @@XXL|:::::::\:::N| // \::\::::\:::\mN**@@@@@mm \ |::TT:::/::::/N:::::/ // @@@@XXL|::::::::\::NN\ // \N:NN\:::-.::\ |::TT::| ` . _\:::::/ // /::7NN:::/::|@@@@XXL|:::::::::\::NN\ // \NNN\\'n-:`N\ - \::::/ / / // /NN::::/:::|@@@XXL/:::::::::::\::NN\ // `"NN\ `-NN''\ _7 " // \:::::\::|LXXXLL/:::::::::::::`.NNN\ // `-NN\ \NNNN\ |\::::\:|<LLLL/\:::::::::::::\::`NN\ // ` '|NNNN\ ' /NNN`m- // >NN|::\NN\:::::\:::::::\:::::`. // |NNNNNN\ .i'/:::::::/NN|:::\NN\::::::\:::::::\::::::`;-. // |NNNNNN/:/`. .__. . ' // |/::/::::/NNN|:::::\N\:::::::`.:::::`Nn::::::::`m-. // /NNNNN/:n/:::|` . . ' // /::y::::/NN::N|:::\::\|:::::::::`.:::::"-.::::::::::`m. // /NNN.':://::::|NNNN/` . . ' // /:::/:::/"""">NN\::::\:::`.:::::.:::::::::::`-.:::::::::) // /."':::.'N::::::|NNN/::\::__`'''\ /::::::::|@@@@||NN\::::::::::`.::::` // .::::::::::::`.-.::/ // -'::::::m':/:::::::/NN/:::::|ffffrrrrmmmmmmmm@@@@@|:::::::\N|@@@| // \:\N\::::::::::::`.:::::`.::::::::::::::::`.. // /::::::m'::.':::::/::/"':::::/ // /\fffffffffffff@@@@@@@|::::::::\|@@@| // N`.\NN`.::::::::::::`.:::::`-.::::::::.:::::::` . // \::::mT:':::::::/:.':::::::,'/MMM\N. ffffffff @@|:::::::::\@@/. // NNNNNNNNN`m.:::::::::"=::::::"Nn:::::::`.::::::::`. // -':':::::::::::.':/:::::::://MMM. ""*fffffffffffffffff@\:::::::::\" // gg` - . NNNN\`n.::::::".::::::"N:::::::"n::::::::| // .- ':::.:::::::.':.':::/::::::::/- ' Mng """""""""" // `\::|::::::\M*",,,,,,,,,,,,` .\\N`.::::|:::::::|::::::::|:::::::/ // /':::::.'::::::.'::/::::n/::::::::|,,,,,, // "**++g,,________,,,,,,mmm\::\:::::::\,,,,,,,,,,,,gnNN" ` // .N)::/::.:::|::::::|::N|:::.'' //|:::. '::::::n":::/":::N" //\:\::::::|,,,,,,,,,,,,,**/NN/*******,,,,,,,,`.|`.:::::|,,,,,, gnN*."' //\:.:::|::::\::::::\nN::/ //.|::::::::,n":::,":::,N \:\:::::\,,,,,,,,,,,,,,/NN/,,,,,,,,,,,,,,,,,,| `. //|ggnN**" / |::::|::::::::::::\Nm:| #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; #define p_ary(ary, a, b) \ do { \ cout << "["; \ for (int count = (a); count < (b); ++count) \ cout << ary[count] << ((b)-1 == count ? "" : ", "); \ cout << "]\n"; \ } while (0) #define p_map(map, it) \ do { \ cout << "{"; \ for (auto(it) = map.begin();; ++(it)) { \ if ((it) == map.end()) { \ cout << "}\n"; \ break; \ } else \ cout << "" << (it)->first << "=>" << (it)->second << ", "; \ } \ } while (0) template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { os << "(" << a.first << ", " << a.second << ")"; return os; } const char newl = '\n'; int main() { int x, y, a, b, c; cin >> x >> y >> a >> b >> c; vector<int> p(a), q(b), r(c); for (int i = 0; i < a; ++i) cin >> p[i]; for (int i = 0; i < b; ++i) cin >> q[i]; for (int i = 0; i < c; ++i) cin >> r[i]; sort(p.begin(), p.end()); sort(q.begin(), q.end()); sort(r.begin(), r.end()); reverse(p.begin(), p.end()); reverse(q.begin(), q.end()); reverse(r.begin(), r.end()); p.push_back(0); q.push_back(0); int i = 0, j = 0, k = 0; ll ans = 0; while (x || y) { if (x && (k == c || (k < c && p[i] >= r[k]))) { ans += p[i++]; x--; } else if (y && (k == c || (k < c && q[j] >= r[k]))) { ans += q[j++]; y--; } else { ans += r[k++]; if (x) { if (y) (p[i + x - 1] < q[j + y - 1] ? x-- : y--); else x--; } else y--; } } cout << ans << endl; }
replace
142
143
142
149
0
p02727
C++
Runtime Error
#include <algorithm> #include <functional> #include <iostream> #include <vector> #define ll long long using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll x, y, a, b, c, ans = 0; cin >> x >> y >> a >> b >> c; vector<ll> p(a), q(b), r(c); for (int i = 0; i < a; i++) cin >> p[i]; for (int i = 0; i < b; i++) cin >> q[i]; for (int i = 0; i < c; i++) cin >> r[i]; sort(p.begin(), p.end(), greater<ll>()); sort(q.begin(), q.end(), greater<ll>()); sort(r.begin(), r.end()); while (p.size() != x) p.pop_back(); while (q.size() != y) q.pop_back(); for (int i = 0; i < p.size(); i++) ans += p[i]; for (int i = 0; i < q.size(); i++) ans += q[i]; while (1) { int pcom = r.back() - p.back(); int qcom = r.back() - q.back(); if (pcom <= 0 && qcom <= 0) break; if (pcom > qcom) { ans -= p.back(); p.pop_back(); } else { ans -= q.back(); q.pop_back(); } ans += r.back(); r.pop_back(); } cout << ans << '\n'; }
#include <algorithm> #include <functional> #include <iostream> #include <vector> #define ll long long using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll x, y, a, b, c, ans = 0; cin >> x >> y >> a >> b >> c; vector<ll> p(a), q(b), r(c); for (int i = 0; i < a; i++) cin >> p[i]; for (int i = 0; i < b; i++) cin >> q[i]; for (int i = 0; i < c; i++) cin >> r[i]; sort(p.begin(), p.end(), greater<ll>()); sort(q.begin(), q.end(), greater<ll>()); sort(r.begin(), r.end()); while (p.size() != x) p.pop_back(); while (q.size() != y) q.pop_back(); for (int i = 0; i < p.size(); i++) ans += p[i]; for (int i = 0; i < q.size(); i++) ans += q[i]; while (1) { if (r.empty()) break; int pcom = (p.size() ? r.back() - p.back() : -1); int qcom = (q.size() ? r.back() - q.back() : -1); if (pcom <= 0 && qcom <= 0) break; if (pcom > qcom) { ans -= p.back(); p.pop_back(); } else { ans -= q.back(); q.pop_back(); } ans += r.back(); r.pop_back(); } cout << ans << '\n'; }
replace
30
32
30
34
0
p02727
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const long long inf = 1e18; typedef long long ll; typedef vector<ll> vl; #define rp(i, f, t) for (int i = f; i < t; i++) #define pr(i, f, t) for (int i = t - 1; i >= f; i--) #define ca(n, a) \ rp(ca_i, 0, n) cout << a[ca_i] << ((ca_i == n - 1) ? "\n" : " ") #define za(n, a) rp(za_i, 0, n) a[za_i] = 0 #define be(a) a.begin(), a.end() int main() { ll x, y, a, b, c; cin >> x >> y >> a >> b >> c; ll p[a], q[b], r[c]; rp(i, 0, a) cin >> p[i]; rp(i, 0, b) cin >> q[i]; rp(i, 0, c) cin >> r[i]; sort(p, p + a); sort(q, q + b); sort(r, r + c); reverse(p, p + a); reverse(q, q + b); reverse(r, r + c); vl ans; rp(i, 0, x) ans.push_back(p[i]); rp(i, 0, y) ans.push_back(q[i]); sort(be(ans)); // reverse(be(ans)); ll co = 0; rp(i, 0, c) { if (r[i] > ans[i]) co++; } ll aa = 0; rp(i, 0, co) { aa += r[i]; } rp(i, co, x + y) { aa += ans[i]; } cout << aa << endl; }
#include <bits/stdc++.h> using namespace std; const long long inf = 1e18; typedef long long ll; typedef vector<ll> vl; #define rp(i, f, t) for (int i = f; i < t; i++) #define pr(i, f, t) for (int i = t - 1; i >= f; i--) #define ca(n, a) \ rp(ca_i, 0, n) cout << a[ca_i] << ((ca_i == n - 1) ? "\n" : " ") #define za(n, a) rp(za_i, 0, n) a[za_i] = 0 #define be(a) a.begin(), a.end() int main() { ll x, y, a, b, c; cin >> x >> y >> a >> b >> c; ll p[a], q[b], r[c]; rp(i, 0, a) cin >> p[i]; rp(i, 0, b) cin >> q[i]; rp(i, 0, c) cin >> r[i]; sort(p, p + a); sort(q, q + b); sort(r, r + c); reverse(p, p + a); reverse(q, q + b); reverse(r, r + c); vl ans; rp(i, 0, x) ans.push_back(p[i]); rp(i, 0, y) ans.push_back(q[i]); sort(be(ans)); // reverse(be(ans)); ll co = 0; rp(i, 0, c) { if (r[i] > ans[i]) co++; else break; } ll aa = 0; rp(i, 0, co) { aa += r[i]; } rp(i, co, x + y) { aa += ans[i]; } cout << aa << endl; }
insert
33
33
33
35
0
p02727
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using large = long long; int main() { int x, y, a, b, c; cin >> x >> y >> a >> b >> c; auto p = vector<int>(a); for (auto &p_i : p) cin >> p_i; auto q = vector<int>(b); for (auto &q_i : q) cin >> q_i; auto r = vector<int>(c); for (auto &r_i : r) cin >> r_i; sort(p.begin(), p.end()); if (p.size() > x) { auto discard = p.size() - x; p.erase(p.begin(), p.begin() + discard); } sort(q.begin(), q.end()); if (q.size() > y) { auto discard = q.size() - y; q.erase(q.begin(), q.begin() + discard); } q.insert(q.end(), p.begin(), p.end()); sort(q.begin(), q.end()); sort(r.begin(), r.end()); if (r.size() > x + y) { auto discard = r.size() - (x + y); r.erase(r.begin(), q.begin() + discard); } for (int i = 0; i < q.size(); ++i) { if (r.empty()) break; if (q[i] >= r.back()) break; q[i] = r.back(); r.pop_back(); } cout << accumulate(q.begin(), q.end(), 0LL); return 0; }
#include <bits/stdc++.h> using namespace std; using large = long long; int main() { int x, y, a, b, c; cin >> x >> y >> a >> b >> c; auto p = vector<int>(a); for (auto &p_i : p) cin >> p_i; auto q = vector<int>(b); for (auto &q_i : q) cin >> q_i; auto r = vector<int>(c); for (auto &r_i : r) cin >> r_i; sort(p.begin(), p.end()); if (p.size() > x) { auto discard = p.size() - x; p.erase(p.begin(), p.begin() + discard); } sort(q.begin(), q.end()); if (q.size() > y) { auto discard = q.size() - y; q.erase(q.begin(), q.begin() + discard); } q.insert(q.end(), p.begin(), p.end()); sort(q.begin(), q.end()); sort(r.begin(), r.end()); if (r.size() > x + y) { auto discard = r.size() - (x + y); r.erase(r.begin(), r.begin() + discard); } for (int i = 0; i < q.size(); ++i) { if (r.empty()) break; if (q[i] >= r.back()) break; q[i] = r.back(); r.pop_back(); } cout << accumulate(q.begin(), q.end(), 0LL); return 0; }
replace
36
37
36
37
0
p02727
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; #define x_ real() #define y_ imag() #define cross(a, b) (conj(a) * (b)).imag() #define dot(a, b) (conj(a) * (b)).real() #define PI acos(-1) #define F first #define S second #define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL) #define fileIO \ freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout) #define ordered_set \ tree<int, null_type, less_equal<int>, rb_tree_tag, \ tree_order_statistics_node_update> typedef long double ld; typedef long long ll; typedef unsigned long long ull; typedef complex<ld> point; typedef tuple<int, int, int> line; typedef vector<point> polygon; typedef pair<double, double> pd; pair<int, int> dirs[] = {{1, 2}, {-1, 2}, {2, 1}, {2, -1}, {-2, 1}, {-2, -1}, {1, -2}, {-1, -2}}; int N = 1e3 + 7; int main() { fastIO; int x, y, a, b, c; cin >> x >> y >> a >> b >> c; vector<ll> red, green, colorless; for (int i = 0; i < a; i++) { ll tmp; cin >> tmp; red.push_back(tmp); } for (int i = 0; i < b; i++) { ll tmp; cin >> tmp; green.push_back(tmp); } for (int i = 0; i < c; i++) { ll tmp; cin >> tmp; colorless.push_back(tmp); } sort(red.rbegin(), red.rend()); sort(green.rbegin(), green.rend()); sort(colorless.begin(), colorless.end()); for (int i = 0; i < a - x; i++) red.pop_back(); for (int i = 0; i < b - y; i++) red.pop_back(); ll total = 0; for (int i = 0; i < x; i++) total += red[i]; for (int i = 0; i < y; i++) total += green[i]; while ((red.size() || green.size()) && colorless.size()) { if (red.size() && green.size()) { if (red.back() < colorless.back() && green.back() < colorless.back()) { if (red.back() < green.back()) { total -= red.back(); total += colorless.back(); red.pop_back(); colorless.pop_back(); } else { total -= green.back(); total += colorless.back(); green.pop_back(); colorless.pop_back(); } } else if (red.back() < colorless.back()) { total -= red.back(); total += colorless.back(); red.pop_back(); colorless.pop_back(); } else if (green.back() < colorless.back()) { total -= green.back(); total += colorless.back(); green.pop_back(); colorless.pop_back(); } else { break; } } else if (red.size()) { if (red.back() < colorless.back()) { total -= red.back(); total += colorless.back(); red.pop_back(); colorless.pop_back(); } else { break; } } else if (green.size()) { if (green.back() < colorless.back()) { total -= green.back(); total += colorless.back(); green.pop_back(); colorless.pop_back(); } else { break; } } } cout << total; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; #define x_ real() #define y_ imag() #define cross(a, b) (conj(a) * (b)).imag() #define dot(a, b) (conj(a) * (b)).real() #define PI acos(-1) #define F first #define S second #define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL) #define fileIO \ freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout) #define ordered_set \ tree<int, null_type, less_equal<int>, rb_tree_tag, \ tree_order_statistics_node_update> typedef long double ld; typedef long long ll; typedef unsigned long long ull; typedef complex<ld> point; typedef tuple<int, int, int> line; typedef vector<point> polygon; typedef pair<double, double> pd; pair<int, int> dirs[] = {{1, 2}, {-1, 2}, {2, 1}, {2, -1}, {-2, 1}, {-2, -1}, {1, -2}, {-1, -2}}; int N = 1e3 + 7; int main() { fastIO; int x, y, a, b, c; cin >> x >> y >> a >> b >> c; vector<ll> red, green, colorless; for (int i = 0; i < a; i++) { ll tmp; cin >> tmp; red.push_back(tmp); } for (int i = 0; i < b; i++) { ll tmp; cin >> tmp; green.push_back(tmp); } for (int i = 0; i < c; i++) { ll tmp; cin >> tmp; colorless.push_back(tmp); } sort(red.rbegin(), red.rend()); sort(green.rbegin(), green.rend()); sort(colorless.begin(), colorless.end()); for (int i = 0; i < a - x; i++) red.pop_back(); for (int i = 0; i < b - y; i++) green.pop_back(); ll total = 0; for (int i = 0; i < x; i++) total += red[i]; for (int i = 0; i < y; i++) total += green[i]; while ((red.size() || green.size()) && colorless.size()) { if (red.size() && green.size()) { if (red.back() < colorless.back() && green.back() < colorless.back()) { if (red.back() < green.back()) { total -= red.back(); total += colorless.back(); red.pop_back(); colorless.pop_back(); } else { total -= green.back(); total += colorless.back(); green.pop_back(); colorless.pop_back(); } } else if (red.back() < colorless.back()) { total -= red.back(); total += colorless.back(); red.pop_back(); colorless.pop_back(); } else if (green.back() < colorless.back()) { total -= green.back(); total += colorless.back(); green.pop_back(); colorless.pop_back(); } else { break; } } else if (red.size()) { if (red.back() < colorless.back()) { total -= red.back(); total += colorless.back(); red.pop_back(); colorless.pop_back(); } else { break; } } else if (green.size()) { if (green.back() < colorless.back()) { total -= green.back(); total += colorless.back(); green.pop_back(); colorless.pop_back(); } else { break; } } } cout << total; }
replace
59
60
59
60
0
p02727
C++
Runtime Error
#include <algorithm> #include <iostream> #include <iterator> #include <numeric> #include <vector> using namespace std; using ll = long long; int main() { int x, y, a, b, c; cin >> x >> y >> a >> b >> c; vector<int> p(a), q(b), r(c); for (auto &i : p) { cin >> i; } for (auto &i : q) { cin >> i; } for (auto &i : r) { cin >> i; } sort(p.begin(), p.end(), greater<>()); sort(q.begin(), q.end(), greater<>()); sort(r.begin(), r.end(), greater<>()); vector<int> m; copy(p.begin(), p.begin() + x, back_inserter(m)); copy(q.begin(), q.begin() + y, back_inserter(m)); sort(m.begin(), m.end()); for (auto i = 0; i != c; ++i) { m[i] = max(r[i], m[i]); } cout << accumulate(m.begin(), m.end(), 0ll) << endl; return 0; }
#include <algorithm> #include <iostream> #include <iterator> #include <numeric> #include <vector> using namespace std; using ll = long long; int main() { int x, y, a, b, c; cin >> x >> y >> a >> b >> c; vector<int> p(a), q(b), r(c); for (auto &i : p) { cin >> i; } for (auto &i : q) { cin >> i; } for (auto &i : r) { cin >> i; } sort(p.begin(), p.end(), greater<>()); sort(q.begin(), q.end(), greater<>()); sort(r.begin(), r.end(), greater<>()); vector<int> m; copy(p.begin(), p.begin() + x, back_inserter(m)); copy(q.begin(), q.begin() + y, back_inserter(m)); sort(m.begin(), m.end()); auto n = min(c, (int)m.size()); for (auto i = 0; i != n; ++i) { m[i] = max(r[i], m[i]); } cout << accumulate(m.begin(), m.end(), 0ll) << endl; return 0; }
replace
33
34
33
35
0
p02727
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define REP(i, n) FOR(i, 0, (n)) #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define LAR(a, b) ((a) = max((a), (b))) #define SML(a, b) ((a) = min((a), (b))) using ll = long long; using ld = long double; using vi = vector<int>; using vl = vector<ll>; using pii = pair<int, int>; using vpii = vector<pair<int, int>>; template <typename T> using pque = priority_queue<T, vector<T>, greater<T>>; #define PB push_back #define EB emplace_back #define MP make_pair #define ALL(a) (a).begin(), (a).end() #ifdef LOCAL_DEBUG #define DEBUG(...) printf(__VA_ARGS__) #else #define DEBUG(...) #endif #define N 112345 ll p[N] = {}, q[N] = {}, r[N] = {}, s[2 * N]; int main() { int x, y, a, b, c; scanf("%d%d%d%d%d", &x, &y, &a, &b, &c); REP(i, a) scanf("%lld", p + i + 1); REP(i, b) scanf("%lld", q + i + 1); REP(i, c) scanf("%lld", r + i + 1); sort(p + 1, p + a + 1, greater<ll>()); sort(q + 1, q + b + 1, greater<ll>()); sort(r + 1, r + c + 1, greater<ll>()); REP(i, y) p[1 + x + i] = q[1 + i]; sort(p + 1, p + x + y + 1, greater<ll>()); REP(i, x + y) DEBUG("%lld ", p[i + 1]); DEBUG("\n"); REP(i, c) DEBUG("%lld ", r[i + 1]); DEBUG("\n"); REP(i, x + y) p[i + 1] += p[i]; REP(i, c) r[i + 1] += r[i]; ll ans = 0; REP(i, min(x + y, c) + 1) { LAR(ans, p[x + y - i] + r[i]); } printf("%lld\n", ans); }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) FOR(i, 0, (n)) #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define LAR(a, b) ((a) = max((a), (b))) #define SML(a, b) ((a) = min((a), (b))) using ll = long long; using ld = long double; using vi = vector<int>; using vl = vector<ll>; using pii = pair<int, int>; using vpii = vector<pair<int, int>>; template <typename T> using pque = priority_queue<T, vector<T>, greater<T>>; #define PB push_back #define EB emplace_back #define MP make_pair #define ALL(a) (a).begin(), (a).end() #ifdef LOCAL_DEBUG #define DEBUG(...) printf(__VA_ARGS__) #else #define DEBUG(...) #endif #define N 112345 ll p[2 * N] = {}, q[N] = {}, r[N] = {}; int main() { int x, y, a, b, c; scanf("%d%d%d%d%d", &x, &y, &a, &b, &c); REP(i, a) scanf("%lld", p + i + 1); REP(i, b) scanf("%lld", q + i + 1); REP(i, c) scanf("%lld", r + i + 1); sort(p + 1, p + a + 1, greater<ll>()); sort(q + 1, q + b + 1, greater<ll>()); sort(r + 1, r + c + 1, greater<ll>()); REP(i, y) p[1 + x + i] = q[1 + i]; sort(p + 1, p + x + y + 1, greater<ll>()); REP(i, x + y) DEBUG("%lld ", p[i + 1]); DEBUG("\n"); REP(i, c) DEBUG("%lld ", r[i + 1]); DEBUG("\n"); REP(i, x + y) p[i + 1] += p[i]; REP(i, c) r[i + 1] += r[i]; ll ans = 0; REP(i, min(x + y, c) + 1) { LAR(ans, p[x + y - i] + r[i]); } printf("%lld\n", ans); }
replace
24
25
24
25
0
p02727
C++
Runtime Error
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <bitset> // bitset #include <cctype> // isupper, islower, isdigit, toupper, tolower #include <cstdint> // int64_t, int*_t #include <cstdio> // printf #include <deque> // deque #include <iostream> // cout, endl, cin #include <map> // map #include <math.h> #include <queue> // queue, priority_queue #include <set> // set #include <stack> // stack #include <string> // string, to_string, stoi #include <tuple> // tuple, make_tuple #include <unordered_map> // unordered_map #include <unordered_set> // unordered_set #include <utility> // pair, make_pair #include <vector> // vector using namespace std; #define int long long signed main() { cin.tie(nullptr); ios::sync_with_stdio(false); int x, y, a, b, c; cin >> x >> y >> a >> b >> c; vector<int> p(a), q(b), r(c); for (int i = 0; i < a; i++) cin >> p.at(i); for (int i = 0; i < b; i++) cin >> q.at(i); for (int i = 0; i < c; i++) cin >> r.at(i); sort(p.begin(), p.end(), greater<int>()); sort(q.begin(), q.end(), greater<int>()); sort(r.begin(), r.end(), greater<int>()); vector<int> all(x + y); for (int i = 0; i < x; i++) { all.at(i) = p.at(i); } for (int i = 0; i < y; i++) { all.at(i + x) = q.at(i); } sort(all.begin(), all.end()); for (int i = 0; i < c; i++) { if (all.at(i) < r.at(i)) all.at(i) = r.at(i); } int ans = 0; for (int i = 0; i < x + y; i++) ans += all.at(i); cout << ans << endl; }
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <bitset> // bitset #include <cctype> // isupper, islower, isdigit, toupper, tolower #include <cstdint> // int64_t, int*_t #include <cstdio> // printf #include <deque> // deque #include <iostream> // cout, endl, cin #include <map> // map #include <math.h> #include <queue> // queue, priority_queue #include <set> // set #include <stack> // stack #include <string> // string, to_string, stoi #include <tuple> // tuple, make_tuple #include <unordered_map> // unordered_map #include <unordered_set> // unordered_set #include <utility> // pair, make_pair #include <vector> // vector using namespace std; #define int long long signed main() { cin.tie(nullptr); ios::sync_with_stdio(false); int x, y, a, b, c; cin >> x >> y >> a >> b >> c; vector<int> p(a), q(b), r(c); for (int i = 0; i < a; i++) cin >> p.at(i); for (int i = 0; i < b; i++) cin >> q.at(i); for (int i = 0; i < c; i++) cin >> r.at(i); sort(p.begin(), p.end(), greater<int>()); sort(q.begin(), q.end(), greater<int>()); sort(r.begin(), r.end(), greater<int>()); vector<int> all(x + y); for (int i = 0; i < x; i++) { all.at(i) = p.at(i); } for (int i = 0; i < y; i++) { all.at(i + x) = q.at(i); } sort(all.begin(), all.end()); for (int i = 0; i < c; i++) { if (i >= x + y) break; if (all.at(i) < r.at(i)) all.at(i) = r.at(i); } int ans = 0; for (int i = 0; i < x + y; i++) ans += all.at(i); cout << ans << endl; }
insert
51
51
51
55
0
p02727
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define all(x) (x).begin(), (x).end() #define endl '\n' typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<double, int> pdi; const int INF = 1e9; const int MAXN = 2e3 + 5; const int MOD = 1e9 + 7; ll n, m, k, x, y; ll A[MAXN], B[MAXN], C[MAXN], sum; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> x >> y >> n >> m >> k; for (int i = 1; i <= n; i++) cin >> A[i]; for (int i = 1; i <= m; i++) cin >> B[i]; for (int i = 1; i <= k; i++) cin >> C[i]; sort(A + 1, A + 1 + n, greater<ll>()); sort(B + 1, B + 1 + m, greater<ll>()); sort(C + 1, C + 1 + k, greater<ll>()); for (int i = 1; i <= x; i++) sum += A[i]; for (int i = 1; i <= y; i++) sum += B[i]; for (int i = 1; i <= k; i++) { if (x && y) { if (A[x] < B[y]) { if (A[x] < C[i]) sum -= A[x--], sum += C[i]; } else { if (B[y] < C[i]) sum -= B[y--], sum += C[i]; } } else if (x) { if (A[x] < C[i]) sum -= A[x--], sum += C[i]; } else if (y) { if (B[y] < C[i]) sum -= B[y--], sum += C[i]; } } cout << sum; }
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define all(x) (x).begin(), (x).end() #define endl '\n' typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<double, int> pdi; const int INF = 1e9; const int MAXN = 2e5 + 5; const int MOD = 1e9 + 7; ll n, m, k, x, y; ll A[MAXN], B[MAXN], C[MAXN], sum; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> x >> y >> n >> m >> k; for (int i = 1; i <= n; i++) cin >> A[i]; for (int i = 1; i <= m; i++) cin >> B[i]; for (int i = 1; i <= k; i++) cin >> C[i]; sort(A + 1, A + 1 + n, greater<ll>()); sort(B + 1, B + 1 + m, greater<ll>()); sort(C + 1, C + 1 + k, greater<ll>()); for (int i = 1; i <= x; i++) sum += A[i]; for (int i = 1; i <= y; i++) sum += B[i]; for (int i = 1; i <= k; i++) { if (x && y) { if (A[x] < B[y]) { if (A[x] < C[i]) sum -= A[x--], sum += C[i]; } else { if (B[y] < C[i]) sum -= B[y--], sum += C[i]; } } else if (x) { if (A[x] < C[i]) sum -= A[x--], sum += C[i]; } else if (y) { if (B[y] < C[i]) sum -= B[y--], sum += C[i]; } } cout << sum; }
replace
14
15
14
15
0
p02727
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using vl = vector<ll>; template <class T> using vc = vector<T>; template <class T> using vvc = vector<vector<T>>; const ll MOD = 1e9 + 7; // const ll MOD = 998244353; const ll INF = 1e16; const ld EPS = 1e-11; const ld PI = acos(-1.0L); #define eb emplace_back #define all(x) (x).begin(), (x).end() #define rep(i, n) for (ll i = 0; i < (n); i++) #define repr(i, n) for (ll i = (n)-1; i >= 0; i--) #define repe(i, l, r) for (ll i = (l); i < (r); i++) #define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--) 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; } void init() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } //--------------------------------------------------------------------------------// int main() { init(); ll X, Y, A, B, C; cin >> X >> Y >> A >> B >> C; vl a(A), b(B), c(C); rep(i, A) cin >> a[i]; rep(i, B) cin >> b[i]; rep(i, C) cin >> c[i]; sort(all(a), greater<ll>()), sort(all(b), greater<ll>()), sort(all(c), greater<ll>()); ll ai = X - 1, bi = Y - 1, ci = 0; ll ans = 0; rep(i, X) ans += a[i]; rep(i, Y) ans += b[i]; while (ci < C) { if (c[ci] < a[ai] and c[ci] < b[bi]) break; if (a[ai] < b[bi]) { ans += c[ci] - a[ai]; ai--, ci++; } else { ans += c[ci] - b[bi]; bi--, ci++; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using vl = vector<ll>; template <class T> using vc = vector<T>; template <class T> using vvc = vector<vector<T>>; const ll MOD = 1e9 + 7; // const ll MOD = 998244353; const ll INF = 1e16; const ld EPS = 1e-11; const ld PI = acos(-1.0L); #define eb emplace_back #define all(x) (x).begin(), (x).end() #define rep(i, n) for (ll i = 0; i < (n); i++) #define repr(i, n) for (ll i = (n)-1; i >= 0; i--) #define repe(i, l, r) for (ll i = (l); i < (r); i++) #define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--) 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; } void init() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } //--------------------------------------------------------------------------------// int main() { init(); ll X, Y, A, B, C; cin >> X >> Y >> A >> B >> C; vl a(A), b(B), c(C); rep(i, A) cin >> a[i]; rep(i, B) cin >> b[i]; rep(i, C) cin >> c[i]; sort(all(a), greater<ll>()), sort(all(b), greater<ll>()), sort(all(c), greater<ll>()); ll ai = X - 1, bi = Y - 1, ci = 0; ll ans = 0; rep(i, X) ans += a[i]; rep(i, Y) ans += b[i]; while (ci < C) { if (ai < 0 && bi < 0) break; else if (ai < 0) { if (c[ci] <= b[bi]) break; ans += c[ci] - b[bi]; bi--, ci++; continue; } else if (bi < 0) { if (c[ci] <= a[ai]) break; ans += c[ci] - a[ai]; ai--, ci++; continue; } if (c[ci] < a[ai] and c[ci] < b[bi]) break; if (a[ai] < b[bi]) { ans += c[ci] - a[ai]; ai--, ci++; } else { ans += c[ci] - b[bi]; bi--, ci++; } } cout << ans << endl; }
insert
59
59
59
75
0
p02727
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (int)(n); i++) template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>; const ll INF = 1LL << 60; const ll MOD = 1e9 + 7; int main() { ll X, Y, A, B, C; cin >> X >> Y >> A >> B >> C; vector<ll> r(A); vector<ll> g(B); vector<ll> m(C); for (ll i = 0; i < A; i++) { ll a; cin >> a; r.at(i) = a; } for (ll i = 0; i < B; i++) { ll a; cin >> a; g.at(i) = a; } for (ll i = 0; i < C; i++) { ll a; cin >> a; m.at(i) = a; } sort(r.begin(), r.end()); sort(g.begin(), g.end()); sort(m.begin(), m.end()); reverse(r.begin(), r.end()); reverse(g.begin(), g.end()); reverse(m.begin(), m.end()); ll rsum = 0; ll gsum = 0; for (ll i = 0; i < X; i++) { rsum += r.at(i); } for (ll i = 0; i < Y; i++) { gsum += g.at(i); } ll current_r = X - 1; ll current_g = Y - 1; for (ll i = 0; i < C; i++) { ll dr, dg; dr = m.at(i) - r.at(current_r); dg = m.at(i) - g.at(current_g); if ((dr <= 0) && (dg <= 0)) break; else if (dr >= dg) { rsum += dr; current_r--; } else if (dr <= dg) { gsum += dg; current_g--; } } cout << rsum + gsum << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (int)(n); i++) template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>; const ll INF = 1LL << 60; const ll MOD = 1e9 + 7; int main() { ll X, Y, A, B, C; cin >> X >> Y >> A >> B >> C; vector<ll> r(A); vector<ll> g(B); vector<ll> m(C); for (ll i = 0; i < A; i++) { ll a; cin >> a; r.at(i) = a; } for (ll i = 0; i < B; i++) { ll a; cin >> a; g.at(i) = a; } for (ll i = 0; i < C; i++) { ll a; cin >> a; m.at(i) = a; } sort(r.begin(), r.end()); sort(g.begin(), g.end()); sort(m.begin(), m.end()); reverse(r.begin(), r.end()); reverse(g.begin(), g.end()); reverse(m.begin(), m.end()); ll rsum = 0; ll gsum = 0; for (ll i = 0; i < X; i++) { rsum += r.at(i); } for (ll i = 0; i < Y; i++) { gsum += g.at(i); } ll current_r = X - 1; ll current_g = Y - 1; for (ll i = 0; i < C; i++) { if ((current_r >= 0) && (current_g >= 0)) { ll dr, dg; dr = m.at(i) - r.at(current_r); dg = m.at(i) - g.at(current_g); if ((dr <= 0) && (dg <= 0)) break; else if (dr >= dg) { rsum += dr; current_r--; } else if (dr <= dg) { gsum += dg; current_g--; } } else if (current_r >= 0) { ll dr; dr = m.at(i) - r.at(current_r); if (dr <= 0) break; else { rsum += dr; current_r--; } } else if (current_g >= 0) { ll dg; dg = m.at(i) - g.at(current_g); if (dg <= 0) break; else { gsum += dg; current_g--; } } } cout << rsum + gsum << endl; }
replace
63
74
63
94
0
p02727
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long LL; const int N = 100000 + 10; int x, y, a, b, c; int p[N], q[N], r[N]; int main() { scanf("%d%d%d%d%d", &x, &y, &a, &b, &c); for (int i = 1; i <= a; i++) scanf("%d", &p[i]); for (int i = 1; i <= b; i++) scanf("%d", &q[i]); for (int i = 1; i <= c; i++) scanf("%d", &r[i]); multiset<LL> s1, s2, s3; sort(p + 1, p + 1 + a); LL ans = 0; for (int i = a; i > a - x; i--) { s1.insert(p[i]); ans += p[i]; } sort(q + 1, q + 1 + b); for (int i = b; i > b - y; i--) { s2.insert(q[i]); ans += q[i]; } for (int i = 1; i <= c; i++) s3.insert(r[i]); // printf("%lld\n", ans); while (s3.size() && (s1.size() > 0 || s2.size() > 0)) { int v1 = s1.size() ? (*s1.begin()) : 0; int v2 = s2.size() ? (*s2.begin()) : 0; int v3 = *s3.rbegin(); if (v3 < min(v1, v2)) break; // printf("# %d %d\n", v3,min(v1,v2)); if (v1 < v2) { s1.erase(s1.begin()); ans -= v1; } else { s2.erase(s2.begin()); ans -= v2; } s3.erase(s3.find(v3)); ans += v3; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long LL; const int N = 100000 + 10; int x, y, a, b, c; int p[N], q[N], r[N]; int main() { scanf("%d%d%d%d%d", &x, &y, &a, &b, &c); for (int i = 1; i <= a; i++) scanf("%d", &p[i]); for (int i = 1; i <= b; i++) scanf("%d", &q[i]); for (int i = 1; i <= c; i++) scanf("%d", &r[i]); multiset<LL> s1, s2, s3; sort(p + 1, p + 1 + a); LL ans = 0; for (int i = a; i > a - x; i--) { s1.insert(p[i]); ans += p[i]; } sort(q + 1, q + 1 + b); for (int i = b; i > b - y; i--) { s2.insert(q[i]); ans += q[i]; } for (int i = 1; i <= c; i++) s3.insert(r[i]); // printf("%lld\n", ans); while ((s3.size() > 0) && (s1.size() > 0 || s2.size() > 0)) { int v1 = s1.size() ? (*s1.begin()) : 1e9 + 1; int v2 = s2.size() ? (*s2.begin()) : 1e9 + 1; int v3 = *s3.rbegin(); if (v3 < min(v1, v2)) break; // printf("# %d %d\n", v3,min(v1,v2)); if (v1 < v2) { s1.erase(s1.begin()); ans -= v1; } else { s2.erase(s2.begin()); ans -= v2; } s3.erase(s3.find(v3)); ans += v3; } cout << ans << endl; }
replace
30
33
30
33
TLE
p02727
C++
Runtime Error
#include <algorithm> #include <cmath> #include <fstream> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <vector> using namespace std; #define I_MAX 2147483647 #define LL_MAX 9223372036854775807 #define ll long long #define ld long double struct XX { ll a; int iro; }; class xxGreater { public: bool operator()(const XX &riLeft, const XX &riRight) const { // 第2条件 if ((riLeft.a) == (riRight.a)) { return riLeft.iro < riRight .iro; //<:昇順(小さいものから順番)、>:降順(大きいものから順番) // プライオリティキューの場合は > で、top()すると値の小さいものがとれる } // 第1条件 return (riLeft.a) > (riRight.a); } }; // map<long long,long long> prime_f(long long n){ // map<long long,long long>res; // for(int i=2;i*i<=n;i++){ // while(n%i==0){ // ++res[i]; // n/=i; // } // } // if(n!=1)res[n]=1; // return res; // } // int n; ////int dat[2*10000000]; ////int dat2[2*10000000]; // int dat[10]; // int dat2[10]; // // void init(int n_){ // n=1; // while(n<n_)n*=2; // for(int i=0;i<2*n-1;i++){ // dat[i]=0; // dat2[i]=0; // } // } // // void initset(int k,int a){ // k+=n-1; // dat[k]=a; // while(k>0){ // k=(k-1)/2; // dat[k]=dat[k*2+1]+dat[k*2+2]; // } // } // ////[a,b)の間を[l,r]区間で比較しアップデート ////引数のindexに注意 ////nは固定。initで計算すみ ////update2(L[i],R[i]+1,0,0,n,D[i]); // void update2(int a,int b,int k,int l,int r,int v){//v更新値、区間は0-index // if(r<=a || b<=l)return; // if(a<=l && r<=b){ // dat[k]+=dat2[k]; // if(r-l>1){ // dat2[k*2+1]+=dat2[k]/2; // dat2[k*2+1]+=dat2[k]/2; // } // dat2[k]=v*(r-l); // return; // }else{ // update2(a,b,k*2+1,l,(l+r)/2,v); // update2(a,b,k*2+2,(l+r)/2,r,v); // return; // } // } // // int query(int a,int b,int k,int l,int r){ // if(r<=a || b<=l)return 0; // if(a<=l && r<=b){ // dat[k]+=dat2[k]; // if(r-l>1){ // dat2[k*2+1]+=dat2[k]/2; // dat2[k*2+1]+=dat2[k]/2; // } // dat2[k]=0; // return dat[k]; // } // else{ // int vl=query(a,b,k*2+1,l,(l+r)/2); // int vr=query(a,b,k*2+2,(l+r)/2,r); // return vl+vr; // } // } // void printb(unsigned int v) { // unsigned int mask = (int)1 << (sizeof(v) * CHAR_BIT - 1); // do putchar(mask & v ? '1' : '0'); // while (mask >>= 1); // } #ifdef DEBUG XX a[100]; #else XX a[100000]; #endif int main(int argc, const char *argv[]) { // scanf("%s",S); // scanf("%d",&N); // scanf("%lld %lld",&target1,&target2); // sscanf(tmp.c_str(),"%dd%d%d",&time[i], &dice[i], &z[i]); // getline(cin, target); // ifstream ifs("01");//テスト用 // ifs >> a; // ここから // 入力高速化 ios::sync_with_stdio(false); cin.tie(0); int X, Y, A, B, C; cin >> X >> Y >> A >> B >> C; for (int i = 0; i < A + B + C; i++) { if (i < A) { cin >> a[i].a; a[i].iro = 3; } else if (i < A + B) { cin >> a[i].a; a[i].iro = 2; } else { cin >> a[i].a; a[i].iro = 1; } } sort(a, a + A + B + C, xxGreater()); ll ans = 0; int lim = X + Y; int ind = 0; while (0 < lim) { if (a[ind].iro == 1) { ans += a[ind].a; } else if (a[ind].iro == 2) { if (Y != 0) { ans += a[ind].a; Y--; } else { lim++; } } else { if (X != 0) { ans += a[ind].a; X--; } else { lim++; } } lim--; ind++; } cout << ans << endl; // ここまで // cout << "ans" << endl; // cout << " " << "ans" << endl; // printf("%.0f\n",ans);//小数点以下表示なし // printf("%.7f\n",p); return 0; }
#include <algorithm> #include <cmath> #include <fstream> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <vector> using namespace std; #define I_MAX 2147483647 #define LL_MAX 9223372036854775807 #define ll long long #define ld long double struct XX { ll a; int iro; }; class xxGreater { public: bool operator()(const XX &riLeft, const XX &riRight) const { // 第2条件 if ((riLeft.a) == (riRight.a)) { return riLeft.iro < riRight .iro; //<:昇順(小さいものから順番)、>:降順(大きいものから順番) // プライオリティキューの場合は > で、top()すると値の小さいものがとれる } // 第1条件 return (riLeft.a) > (riRight.a); } }; // map<long long,long long> prime_f(long long n){ // map<long long,long long>res; // for(int i=2;i*i<=n;i++){ // while(n%i==0){ // ++res[i]; // n/=i; // } // } // if(n!=1)res[n]=1; // return res; // } // int n; ////int dat[2*10000000]; ////int dat2[2*10000000]; // int dat[10]; // int dat2[10]; // // void init(int n_){ // n=1; // while(n<n_)n*=2; // for(int i=0;i<2*n-1;i++){ // dat[i]=0; // dat2[i]=0; // } // } // // void initset(int k,int a){ // k+=n-1; // dat[k]=a; // while(k>0){ // k=(k-1)/2; // dat[k]=dat[k*2+1]+dat[k*2+2]; // } // } // ////[a,b)の間を[l,r]区間で比較しアップデート ////引数のindexに注意 ////nは固定。initで計算すみ ////update2(L[i],R[i]+1,0,0,n,D[i]); // void update2(int a,int b,int k,int l,int r,int v){//v更新値、区間は0-index // if(r<=a || b<=l)return; // if(a<=l && r<=b){ // dat[k]+=dat2[k]; // if(r-l>1){ // dat2[k*2+1]+=dat2[k]/2; // dat2[k*2+1]+=dat2[k]/2; // } // dat2[k]=v*(r-l); // return; // }else{ // update2(a,b,k*2+1,l,(l+r)/2,v); // update2(a,b,k*2+2,(l+r)/2,r,v); // return; // } // } // // int query(int a,int b,int k,int l,int r){ // if(r<=a || b<=l)return 0; // if(a<=l && r<=b){ // dat[k]+=dat2[k]; // if(r-l>1){ // dat2[k*2+1]+=dat2[k]/2; // dat2[k*2+1]+=dat2[k]/2; // } // dat2[k]=0; // return dat[k]; // } // else{ // int vl=query(a,b,k*2+1,l,(l+r)/2); // int vr=query(a,b,k*2+2,(l+r)/2,r); // return vl+vr; // } // } // void printb(unsigned int v) { // unsigned int mask = (int)1 << (sizeof(v) * CHAR_BIT - 1); // do putchar(mask & v ? '1' : '0'); // while (mask >>= 1); // } #ifdef DEBUG XX a[100]; #else XX a[300000]; #endif int main(int argc, const char *argv[]) { // scanf("%s",S); // scanf("%d",&N); // scanf("%lld %lld",&target1,&target2); // sscanf(tmp.c_str(),"%dd%d%d",&time[i], &dice[i], &z[i]); // getline(cin, target); // ifstream ifs("01");//テスト用 // ifs >> a; // ここから // 入力高速化 ios::sync_with_stdio(false); cin.tie(0); int X, Y, A, B, C; cin >> X >> Y >> A >> B >> C; for (int i = 0; i < A + B + C; i++) { if (i < A) { cin >> a[i].a; a[i].iro = 3; } else if (i < A + B) { cin >> a[i].a; a[i].iro = 2; } else { cin >> a[i].a; a[i].iro = 1; } } sort(a, a + A + B + C, xxGreater()); ll ans = 0; int lim = X + Y; int ind = 0; while (0 < lim) { if (a[ind].iro == 1) { ans += a[ind].a; } else if (a[ind].iro == 2) { if (Y != 0) { ans += a[ind].a; Y--; } else { lim++; } } else { if (X != 0) { ans += a[ind].a; X--; } else { lim++; } } lim--; ind++; } cout << ans << endl; // ここまで // cout << "ans" << endl; // cout << " " << "ans" << endl; // printf("%.0f\n",ans);//小数点以下表示なし // printf("%.7f\n",p); return 0; }
replace
128
129
128
129
0
p02727
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef pair<int, int> pii; #define pb push_back #define ff first #define ss second #define SIZE 2001 #define INF 2e9 + 9 #define BIG_INF 1e18 + 9 #define acmpIN "input.txt" #define acmpOUT "output.txt" // #pragma GCC optimize("Ofast") // int x, y, n, m, k, r[SIZE], g[SIZE], c[SIZE]; bool comp(const int &x, const int &y) { return x > y; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); // freopen(acmpIN, "r", stdin); // freopen(acmpOUT, "w", stdout); cin >> x >> y >> n >> m >> k; for (int i = 0; i < n; i++) cin >> r[i]; for (int i = 0; i < m; i++) cin >> g[i]; for (int i = 0; i < k; i++) cin >> c[i]; sort(c, c + k, comp); sort(r, r + n, comp); sort(g, g + m, comp); multiset<int> red, green; ll sumRed = 0, sumGreen = 0; for (int i = 0; i < x; i++) { red.insert(r[i]); sumRed += r[i]; } for (int i = 0; i < y; i++) { green.insert(g[i]); sumGreen += g[i]; } for (int i = 0; i < k; i++) { int rb = red.size() ? *red.begin() : 0, gb = green.size() ? *green.begin() : 0; // cout << rb << ' ' << gb << endl; if (c[i] > rb && c[i] > gb) { if (rb < gb) { sumRed -= ll(rb); if (red.size()) red.erase(red.begin()); red.insert(c[i]); sumRed += ll(c[i]); } else { sumGreen -= ll(gb); if (green.size()) green.erase(green.begin()); green.insert(c[i]); sumGreen += ll(c[i]); } } else if (c[i] > rb) { sumRed -= ll(rb); if (red.size()) red.erase(red.begin()); red.insert(c[i]); sumRed += ll(c[i]); } else if (c[i] > gb) { sumGreen -= ll(gb); if (green.size()) green.erase(green.begin()); green.insert(c[i]); sumGreen += ll(c[i]); } } cout << sumRed + sumGreen; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef pair<int, int> pii; #define pb push_back #define ff first #define ss second #define SIZE 200001 #define INF 2e9 + 9 #define BIG_INF 1e18 + 9 #define acmpIN "input.txt" #define acmpOUT "output.txt" // #pragma GCC optimize("Ofast") // int x, y, n, m, k, r[SIZE], g[SIZE], c[SIZE]; bool comp(const int &x, const int &y) { return x > y; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); // freopen(acmpIN, "r", stdin); // freopen(acmpOUT, "w", stdout); cin >> x >> y >> n >> m >> k; for (int i = 0; i < n; i++) cin >> r[i]; for (int i = 0; i < m; i++) cin >> g[i]; for (int i = 0; i < k; i++) cin >> c[i]; sort(c, c + k, comp); sort(r, r + n, comp); sort(g, g + m, comp); multiset<int> red, green; ll sumRed = 0, sumGreen = 0; for (int i = 0; i < x; i++) { red.insert(r[i]); sumRed += r[i]; } for (int i = 0; i < y; i++) { green.insert(g[i]); sumGreen += g[i]; } for (int i = 0; i < k; i++) { int rb = red.size() ? *red.begin() : 0, gb = green.size() ? *green.begin() : 0; // cout << rb << ' ' << gb << endl; if (c[i] > rb && c[i] > gb) { if (rb < gb) { sumRed -= ll(rb); if (red.size()) red.erase(red.begin()); red.insert(c[i]); sumRed += ll(c[i]); } else { sumGreen -= ll(gb); if (green.size()) green.erase(green.begin()); green.insert(c[i]); sumGreen += ll(c[i]); } } else if (c[i] > rb) { sumRed -= ll(rb); if (red.size()) red.erase(red.begin()); red.insert(c[i]); sumRed += ll(c[i]); } else if (c[i] > gb) { sumGreen -= ll(gb); if (green.size()) green.erase(green.begin()); green.insert(c[i]); sumGreen += ll(c[i]); } } cout << sumRed + sumGreen; return 0; }
replace
11
12
11
12
0
p02727
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 2e3 + 5; int a1[N], a2[N], a3[N]; priority_queue<int, vector<int>, greater<int>> q; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int x, y, a, b, c; cin >> x >> y >> a >> b >> c; for (int i = 0; i < a; i++) cin >> a1[i]; for (int i = 0; i < b; i++) cin >> a2[i]; for (int i = 0; i < c; i++) cin >> a3[i]; sort(a1, a1 + a); sort(a2, a2 + b); sort(a3, a3 + c); ll sum = 0; if (a >= x) { for (int i = a - 1; i >= a - x; i--) { q.push(a1[i]); } x = 0; } else { for (int i = 0; i < a; i++) { q.push(a1[i]); } x -= a; } if (b >= y) { for (int i = b - 1; i >= b - y; i--) { q.push(a2[i]); } y = 0; } else { for (int i = 0; i < b; i++) { q.push(a2[i]); } y -= b; } int idx = c - 1; int minn = 0x3f3f3f3f; while (x > 0) { q.push(a3[idx--]); x--; } while (y > 0) { q.push(a3[idx--]); y--; } for (; idx >= 0; idx--) { int t = q.top(); if (t < a3[idx]) { q.pop(); q.push(a3[idx]); } else break; } while (!q.empty()) { sum += q.top(); q.pop(); } cout << sum << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1e5 + 5; int a1[N], a2[N], a3[N]; priority_queue<int, vector<int>, greater<int>> q; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int x, y, a, b, c; cin >> x >> y >> a >> b >> c; for (int i = 0; i < a; i++) cin >> a1[i]; for (int i = 0; i < b; i++) cin >> a2[i]; for (int i = 0; i < c; i++) cin >> a3[i]; sort(a1, a1 + a); sort(a2, a2 + b); sort(a3, a3 + c); ll sum = 0; if (a >= x) { for (int i = a - 1; i >= a - x; i--) { q.push(a1[i]); } x = 0; } else { for (int i = 0; i < a; i++) { q.push(a1[i]); } x -= a; } if (b >= y) { for (int i = b - 1; i >= b - y; i--) { q.push(a2[i]); } y = 0; } else { for (int i = 0; i < b; i++) { q.push(a2[i]); } y -= b; } int idx = c - 1; int minn = 0x3f3f3f3f; while (x > 0) { q.push(a3[idx--]); x--; } while (y > 0) { q.push(a3[idx--]); y--; } for (; idx >= 0; idx--) { int t = q.top(); if (t < a3[idx]) { q.pop(); q.push(a3[idx]); } else break; } while (!q.empty()) { sum += q.top(); q.pop(); } cout << sum << endl; return 0; }
replace
3
4
3
4
0
p02727
C++
Runtime Error
#include <bits/stdc++.h> #include <math.h> using namespace std; typedef long long ll; typedef long double ld; #define rep(i, n) for (int i = 0; i < (int)(n); i++) const ll mod = 1000000007; const int INF = 1001001001; const ll LINF = 1001001001001001001; int main() { ll x, y, a, b, c; cin >> x >> y >> a >> b >> c; vector<ll> p(a), q(b), r(c); rep(i, a) cin >> p.at(i); rep(i, b) cin >> q.at(i); rep(i, c) cin >> r.at(i); sort(p.rbegin(), p.rend()); sort(q.rbegin(), q.rend()); sort(r.rbegin(), r.rend()); vector<ll> applelist(0); rep(i, x) { applelist.push_back(p.at(i)); } rep(i, y) { applelist.push_back(q.at(i)); } sort(applelist.begin(), applelist.end()); for (int i = 0; i < c; i++) { if (r.at(i) > applelist.at(i)) { applelist.at(i) = r.at(i); } } ll ans = 0; rep(i, x + y) { ans += applelist.at(i); } cout << ans << endl; }
#include <bits/stdc++.h> #include <math.h> using namespace std; typedef long long ll; typedef long double ld; #define rep(i, n) for (int i = 0; i < (int)(n); i++) const ll mod = 1000000007; const int INF = 1001001001; const ll LINF = 1001001001001001001; int main() { ll x, y, a, b, c; cin >> x >> y >> a >> b >> c; vector<ll> p(a), q(b), r(c); rep(i, a) cin >> p.at(i); rep(i, b) cin >> q.at(i); rep(i, c) cin >> r.at(i); sort(p.rbegin(), p.rend()); sort(q.rbegin(), q.rend()); sort(r.rbegin(), r.rend()); vector<ll> applelist(0); rep(i, x) { applelist.push_back(p.at(i)); } rep(i, y) { applelist.push_back(q.at(i)); } sort(applelist.begin(), applelist.end()); for (int i = 0; i < c; i++) { if (x + y <= i) break; if (r.at(i) > applelist.at(i)) { applelist.at(i) = r.at(i); } } ll ans = 0; rep(i, x + y) { ans += applelist.at(i); } cout << ans << endl; }
insert
27
27
27
29
0
p02727
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (ll i = 0; i < (n); i++) #define REP(i, n) for (ll i = 1; i <= (n); i++) typedef long long ll; int main() { ll x, y, a, b, c; cin >> x >> y >> a >> b >> c; vector<ll> p(a), q(b), r(c); rep(i, a) cin >> p[i]; rep(i, b) cin >> q[i]; rep(i, c) cin >> r[i]; sort(p.rbegin(), p.rend()); sort(q.rbegin(), q.rend()); sort(r.rbegin(), r.rend()); ll ans = 0; rep(i, x) ans += p[i]; rep(i, y) ans += q[i]; ll z = 0; while (1) { if (p[x - 1] >= q[y - 1]) { if (q[y - 1] < r[z]) { ans -= q[y - 1]; ans += r[z]; y--; z++; } else { break; } } else { if (p[x - 1] < r[z]) { ans -= p[x - 1]; ans += r[z]; x--; z++; } else { break; } } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (ll i = 0; i < (n); i++) #define REP(i, n) for (ll i = 1; i <= (n); i++) typedef long long ll; int main() { ll x, y, a, b, c; cin >> x >> y >> a >> b >> c; vector<ll> p(a), q(b), r(c); rep(i, a) cin >> p[i]; rep(i, b) cin >> q[i]; rep(i, c) cin >> r[i]; sort(p.rbegin(), p.rend()); sort(q.rbegin(), q.rend()); sort(r.rbegin(), r.rend()); ll ans = 0; rep(i, x) ans += p[i]; rep(i, y) ans += q[i]; ll z = 0; while (1) { if (x == 0 && y == 0) { break; } else if (x == 0) { if (q[y - 1] < r[z]) { ans -= q[y - 1]; ans += r[z]; y--; z++; continue; } else { break; } } else if (y == 0) { if (p[x - 1] < r[z]) { ans -= p[x - 1]; ans += r[z]; x--; z++; continue; } else { break; } } if (z == c) break; if (p[x - 1] >= q[y - 1]) { if (q[y - 1] < r[z]) { ans -= q[y - 1]; ans += r[z]; y--; z++; } else { break; } } else { if (p[x - 1] < r[z]) { ans -= p[x - 1]; ans += r[z]; x--; z++; } else { break; } } } cout << ans << endl; }
insert
21
21
21
46
0
p02727
C++
Runtime Error
#include <algorithm> #include <iostream> #include <stack> using namespace std; int64_t X, Y, A, B, C, ans = 0LL; int main(void) { cin >> X >> Y >> A >> B >> C; int p[A], q[B], r[C]; for (int i = 0; i < A; i++) cin >> p[i]; for (int i = 0; i < B; i++) cin >> q[i]; for (int i = 0; i < C; i++) cin >> r[i]; sort(p, p + A, std::greater<int64_t>()); sort(q, q + B, std::greater<int64_t>()); sort(r, r + C, std::greater<int64_t>()); stack<int64_t> red, blue; for (int i = 0; i < X; i++) ans += p[i], red.push(p[i]); for (int i = 0; i < Y; i++) ans += q[i], blue.push(q[i]); for (int i = 0; i < C; i++) { if (min(red.top(), blue.top()) < r[i]) { if (red.top() < blue.top()) ans += r[i] - red.top(), red.pop(); else ans += r[i] - blue.top(), blue.pop(); } else break; } cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> #include <stack> using namespace std; int64_t X, Y, A, B, C, ans = 0LL; int main(void) { cin >> X >> Y >> A >> B >> C; int p[A], q[B], r[C]; for (int i = 0; i < A; i++) cin >> p[i]; for (int i = 0; i < B; i++) cin >> q[i]; for (int i = 0; i < C; i++) cin >> r[i]; sort(p, p + A, std::greater<int64_t>()); sort(q, q + B, std::greater<int64_t>()); sort(r, r + C, std::greater<int64_t>()); stack<int64_t> red, blue; for (int i = 0; i < X; i++) ans += p[i], red.push(p[i]); for (int i = 0; i < Y; i++) ans += q[i], blue.push(q[i]); for (int i = 0; i < C; i++) { if (min((red.empty() ? 1000000001 : red.top()), (blue.empty() ? 1000000001 : blue.top())) < r[i]) { if ((red.empty() ? 1000000001 : red.top()) < (blue.empty() ? 1000000001 : blue.top())) ans += r[i] - red.top(), red.pop(); else ans += r[i] - blue.top(), blue.pop(); } else break; } cout << ans << endl; return 0; }
replace
23
25
23
27
0