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
p02948
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define PI 3.14159265359 #define INF 1000100100 #define all(x) (x).begin(), (x).end() typedef long long ll; using namespace std; int main() { int n, m; cin >> n >> m; vector<vector<int>> job(m); rep(i, n) { int a, b; cin >> a >> b; job[m - a].push_back(b); } priority_queue<int> p; ll ans = 0; for (int i = m - 1; i >= 0; i--) { rep(j, job[i].size()) p.push(job[i][j]); if (!p.empty()) { ans += p.top(); p.pop(); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define PI 3.14159265359 #define INF 1000100100 #define all(x) (x).begin(), (x).end() typedef long long ll; using namespace std; int main() { int n, m; cin >> n >> m; vector<vector<int>> job(m); rep(i, n) { int a, b; cin >> a >> b; if (a > m) continue; job[m - a].push_back(b); } priority_queue<int> p; ll ans = 0; for (int i = m - 1; i >= 0; i--) { rep(j, job[i].size()) p.push(job[i][j]); if (!p.empty()) { ans += p.top(); p.pop(); } } cout << ans << endl; return 0; }
insert
15
15
15
17
0
p02948
C++
Time Limit Exceeded
#include <algorithm> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <vector> using namespace std; // マクロ&定数&関数 ================================================ typedef unsigned int uint; typedef long long ll; typedef pair<ll, ll> pll; typedef vector<int> vint; typedef vector<ll> vll; typedef vector<double> vdouble; typedef vector<bool> vbool; typedef vector<string> vstring; typedef vector<pair<int, int>> vpint; typedef vector<pair<ll, ll>> vpll; typedef vector<pair<double, double>> vpdouble; typedef vector<vector<int>> vvint; typedef vector<vector<ll>> vvll; typedef vector<vpint> vvpint; typedef vector<vpll> vvpll; typedef vector<vector<double>> vvdouble; typedef vector<vector<string>> vvstring; typedef vector<vector<bool>> vvbool; typedef vector<vector<vector<ll>>> vvvll; const int INF = 1e9 + 1; const ll LLINF = 1e17 + 1; const int DX[9] = {0, 0, 1, -1, 1, 1, -1, -1, 0}; // 4;4近傍 const int DY[9] = {1, -1, 0, 0, 1, -1, 1, -1, 0}; // 8:8近傍 9:(0,0)を含む const ll MOD = 1e9 + 7; // 10^9 + 7 const ll MAX = 1e9; const double PI = 3.14159265358979323846264338327950288; //--------------------------------------------------------------- // オーバーフローチェック //--------------------------------------------------------------- bool is_overflow(ll a, ll b) { return ((a * b) / b != a); } //--------------------------------------------------------------- // 約数列挙 //--------------------------------------------------------------- vll divisor(ll n) { vll ret; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(begin(ret), end(ret)); return (ret); } //--------------------------------------------------------------- // N以下のすべての素数を列挙する(エラトステネスの篩) //--------------------------------------------------------------- vbool searchSosuu(ll N) { vbool sosuu; // ←これをグローバル変数にして1度だけ実行する for (ll i = 0; i < N; i++) { sosuu.emplace_back(true); } sosuu[0] = false; sosuu[1] = false; for (ll i = 2; i < N; i++) { if (sosuu[i]) { for (ll j = 2; i * j < N; j++) { sosuu[i * j] = false; } } } return sosuu; } //--------------------------------------------------------------- // 素因数分解 O(√N) //--------------------------------------------------------------- vpll div_prime(ll n) { vpll prime_factor; for (ll i = 2; i * i <= n; i++) { ll count = 0; while (n % i == 0) { count++; n /= i; } if (count) { pair<ll, ll> temp = {i, count}; prime_factor.emplace_back(temp); } } if (n != 1) { pair<ll, ll> temp = {n, 1}; prime_factor.emplace_back(temp); } return prime_factor; } //--------------------------------------------------------------- // 素数判定 //--------------------------------------------------------------- bool is_sosuu(ll N) { if (N < 2) { return false; } else if (N == 2) { return true; } else if (N % 2 == 0) { return false; } for (ll i = 3; i <= sqrt(N); i += 2) { if (N % i == 0) { return false; } } return true; } //--------------------------------------------------------------- // 最大公約数(ユークリッドの互除法) //--------------------------------------------------------------- ll gcd(ll a, ll b) { if (a < b) { ll tmp = a; a = b; b = tmp; } ll r = a % b; while (r != 0) { a = b; b = r; r = a % b; } return b; } //--------------------------------------------------------------- // 最小公倍数 //--------------------------------------------------------------- ll lcm(ll a, ll b) { ll temp = gcd(a, b); return temp * (a / temp) * (b / temp); } //--------------------------------------------------------------- // 階乗 //--------------------------------------------------------------- ll factorial(ll n) { if (n <= 1) { return 1; } return (n * (factorial(n - 1))) % MOD; } //--------------------------------------------------------------- // 高速コンビネーション計算(前処理:O(N) 計算:O(1)) //--------------------------------------------------------------- // テーブルを作る前処理 ll comb_const = 200005; vll fac(comb_const), finv(comb_const), inv(comb_const); bool COMineted = false; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < comb_const; 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; } COMineted = true; } // 二項係数計算 ll COM(ll n, ll k) { if (COMineted == false) COMinit(); if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } //--------------------------------------------------------------- // 繰り返し2乗法 base^sisuu //--------------------------------------------------------------- ll RepeatSquaring(ll base, ll sisuu) { if (sisuu < 0) { cout << "RepeatSquaring: 指数が負です!" << endl; return 0; } if (sisuu == 0) return 1; if (sisuu % 2 == 0) { ll t = RepeatSquaring(base, sisuu / 2) % MOD; return (t * t) % MOD; } return base * RepeatSquaring(base, sisuu - 1) % MOD; } //--------------------------------------------------------------- // 高速単発コンビネーション計算(O(logN)) //--------------------------------------------------------------- ll fast_com(ll a, ll b) { ll bunshi = 1; ll bunbo = 1; for (ll i = 1; i <= b; i++) { bunbo *= i; bunbo %= MOD; bunshi *= (a - i + 1); bunshi %= MOD; } ll ret = bunshi * RepeatSquaring(bunbo, MOD - 2); ret %= MOD; while (ret < 0) { ret += MOD; } return ret; } //--------------------------------------------------------------- // 2直線の交差判定(直線(x1, y1)->(x2, y2) と 直線(X1, Y1)->(X2, Y2)) //--------------------------------------------------------------- bool is_cross(ll x1, ll y1, ll x2, ll y2, ll X1, ll Y1, ll X2, ll Y2) { ll dx_ai = X1 - x1; ll dy_ai = Y1 - y1; ll dx_bi = X1 - x2; ll dy_bi = Y1 - y2; ll dx_ai2 = X2 - x1; ll dy_ai2 = Y2 - y1; ll dx_bi2 = X2 - x2; ll dy_bi2 = Y2 - y2; ll si = dx_ai * dy_bi - dy_ai * dx_bi; ll si2 = dx_ai2 * dy_bi2 - dy_ai2 * dx_bi2; ll si3 = dx_ai * dy_ai2 - dy_ai * dx_ai2; ll si4 = dx_bi * dy_bi2 - dy_bi * dx_bi2; return (si * si2 < 0 && si3 * si4 < 0); } //--------------------------------------------------------------- // 最長増加部分列の長さ(O(NlogN)) //--------------------------------------------------------------- ll LSI(vll vec, ll size) { vll lsi(size + 1); // 長さjを作った時の右端の最小値 for (ll i = 0; i <= size; i++) { lsi[i] = LLINF; } lsi[0] = 0; lsi[1] = vec[0]; for (ll i = 1; i < size; i++) { // 初めてvec[i]の方が小さくなるところを探す auto Iter = lower_bound(lsi.begin(), lsi.end(), vec[i]); ll idx = Iter - lsi.begin(); if (idx > 0 && lsi[idx - 1] < vec[i]) // 条件文の前半怪しい { lsi[idx] = vec[i]; } } for (ll i = size; i >= 0; i--) { if (lsi[i] < LLINF) { return i; } } } //--------------------------------------------------------------- // 木の根からの深さ //--------------------------------------------------------------- vll tree_depth(vvll edge, ll start_node, ll n_node) { vll dist(n_node, LLINF); dist[start_node] = 0; stack<pll> S; S.push({start_node, 0}); while (!S.empty()) { ll node = S.top().first; ll d = S.top().second; dist[node] = d; S.pop(); for (int i = 0; i < edge[node].size(); i++) { if (dist[edge[node][i]] == LLINF) { S.push({edge[node][i], d + 1}); } } } return dist; } //--------------------------------------------------------------- // ワーシャルフロイド法(O(N^3)) 任意の2点間の最短距離 //--------------------------------------------------------------- vvll warshall_floyd(ll n, vvll d) { 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]); } } } return d; } //--------------------------------------------------------------- // Union Find //--------------------------------------------------------------- /* UnionFind uf(要素の個数); for(int i = 0;i < 関係の個数; i++) { uf.merge(A[i], B[i]); } nを含む集合の大きさ = uf.size(n) nを含む集合の代表者 = uf.root(n) 集合の個数 = uf.n_group */ class UnionFind { public: vector<ll> par; // 各元の親を表す配列 vector<ll> siz; // 素集合のサイズを表す配列(1 で初期化) ll n_group; // 集合の数 // Constructor UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) { for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身 n_group = sz_; } void init(ll sz_) { par.resize(sz_); siz.assign(sz_, 1LL); // resize だとなぜか初期化されなかった for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身 } // Member Function // Find ll root(ll x) { // 根の検索 while (par[x] != x) { x = par[x] = par[par[x]]; // x の親の親を x の親とする } return x; } // Union(Unite, Merge) bool merge(ll x, ll y) { x = root(x); y = root(y); if (x == y) return false; // merge technique(データ構造をマージするテク.小を大にくっつける) if (siz[x] < siz[y]) swap(x, y); siz[x] += siz[y]; par[y] = x; n_group--; return true; } bool issame(ll x, ll y) { // 連結判定 return root(x) == root(y); } ll size(ll x) { // 素集合のサイズ return siz[root(x)]; } }; //======================================================================== int main() { ////================================== cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(30); ////================================== ll N, M; cin >> N >> M; vpll AB(N); for (int i = 0; i < N; i++) { cin >> AB[i].first >> AB[i].second; } sort(AB.begin(), AB.end()); priority_queue<ll> q; ll begin = 0; ll ans = 0; for (int i = 1; i <= M; i++) { for (int j = begin; j < N; j++) { if (AB[j].first <= i) { q.push(AB[j].second); begin++; } } if (!q.empty()) { ans += q.top(); q.pop(); } } cout << ans; }
#include <algorithm> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <vector> using namespace std; // マクロ&定数&関数 ================================================ typedef unsigned int uint; typedef long long ll; typedef pair<ll, ll> pll; typedef vector<int> vint; typedef vector<ll> vll; typedef vector<double> vdouble; typedef vector<bool> vbool; typedef vector<string> vstring; typedef vector<pair<int, int>> vpint; typedef vector<pair<ll, ll>> vpll; typedef vector<pair<double, double>> vpdouble; typedef vector<vector<int>> vvint; typedef vector<vector<ll>> vvll; typedef vector<vpint> vvpint; typedef vector<vpll> vvpll; typedef vector<vector<double>> vvdouble; typedef vector<vector<string>> vvstring; typedef vector<vector<bool>> vvbool; typedef vector<vector<vector<ll>>> vvvll; const int INF = 1e9 + 1; const ll LLINF = 1e17 + 1; const int DX[9] = {0, 0, 1, -1, 1, 1, -1, -1, 0}; // 4;4近傍 const int DY[9] = {1, -1, 0, 0, 1, -1, 1, -1, 0}; // 8:8近傍 9:(0,0)を含む const ll MOD = 1e9 + 7; // 10^9 + 7 const ll MAX = 1e9; const double PI = 3.14159265358979323846264338327950288; //--------------------------------------------------------------- // オーバーフローチェック //--------------------------------------------------------------- bool is_overflow(ll a, ll b) { return ((a * b) / b != a); } //--------------------------------------------------------------- // 約数列挙 //--------------------------------------------------------------- vll divisor(ll n) { vll ret; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(begin(ret), end(ret)); return (ret); } //--------------------------------------------------------------- // N以下のすべての素数を列挙する(エラトステネスの篩) //--------------------------------------------------------------- vbool searchSosuu(ll N) { vbool sosuu; // ←これをグローバル変数にして1度だけ実行する for (ll i = 0; i < N; i++) { sosuu.emplace_back(true); } sosuu[0] = false; sosuu[1] = false; for (ll i = 2; i < N; i++) { if (sosuu[i]) { for (ll j = 2; i * j < N; j++) { sosuu[i * j] = false; } } } return sosuu; } //--------------------------------------------------------------- // 素因数分解 O(√N) //--------------------------------------------------------------- vpll div_prime(ll n) { vpll prime_factor; for (ll i = 2; i * i <= n; i++) { ll count = 0; while (n % i == 0) { count++; n /= i; } if (count) { pair<ll, ll> temp = {i, count}; prime_factor.emplace_back(temp); } } if (n != 1) { pair<ll, ll> temp = {n, 1}; prime_factor.emplace_back(temp); } return prime_factor; } //--------------------------------------------------------------- // 素数判定 //--------------------------------------------------------------- bool is_sosuu(ll N) { if (N < 2) { return false; } else if (N == 2) { return true; } else if (N % 2 == 0) { return false; } for (ll i = 3; i <= sqrt(N); i += 2) { if (N % i == 0) { return false; } } return true; } //--------------------------------------------------------------- // 最大公約数(ユークリッドの互除法) //--------------------------------------------------------------- ll gcd(ll a, ll b) { if (a < b) { ll tmp = a; a = b; b = tmp; } ll r = a % b; while (r != 0) { a = b; b = r; r = a % b; } return b; } //--------------------------------------------------------------- // 最小公倍数 //--------------------------------------------------------------- ll lcm(ll a, ll b) { ll temp = gcd(a, b); return temp * (a / temp) * (b / temp); } //--------------------------------------------------------------- // 階乗 //--------------------------------------------------------------- ll factorial(ll n) { if (n <= 1) { return 1; } return (n * (factorial(n - 1))) % MOD; } //--------------------------------------------------------------- // 高速コンビネーション計算(前処理:O(N) 計算:O(1)) //--------------------------------------------------------------- // テーブルを作る前処理 ll comb_const = 200005; vll fac(comb_const), finv(comb_const), inv(comb_const); bool COMineted = false; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < comb_const; 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; } COMineted = true; } // 二項係数計算 ll COM(ll n, ll k) { if (COMineted == false) COMinit(); if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } //--------------------------------------------------------------- // 繰り返し2乗法 base^sisuu //--------------------------------------------------------------- ll RepeatSquaring(ll base, ll sisuu) { if (sisuu < 0) { cout << "RepeatSquaring: 指数が負です!" << endl; return 0; } if (sisuu == 0) return 1; if (sisuu % 2 == 0) { ll t = RepeatSquaring(base, sisuu / 2) % MOD; return (t * t) % MOD; } return base * RepeatSquaring(base, sisuu - 1) % MOD; } //--------------------------------------------------------------- // 高速単発コンビネーション計算(O(logN)) //--------------------------------------------------------------- ll fast_com(ll a, ll b) { ll bunshi = 1; ll bunbo = 1; for (ll i = 1; i <= b; i++) { bunbo *= i; bunbo %= MOD; bunshi *= (a - i + 1); bunshi %= MOD; } ll ret = bunshi * RepeatSquaring(bunbo, MOD - 2); ret %= MOD; while (ret < 0) { ret += MOD; } return ret; } //--------------------------------------------------------------- // 2直線の交差判定(直線(x1, y1)->(x2, y2) と 直線(X1, Y1)->(X2, Y2)) //--------------------------------------------------------------- bool is_cross(ll x1, ll y1, ll x2, ll y2, ll X1, ll Y1, ll X2, ll Y2) { ll dx_ai = X1 - x1; ll dy_ai = Y1 - y1; ll dx_bi = X1 - x2; ll dy_bi = Y1 - y2; ll dx_ai2 = X2 - x1; ll dy_ai2 = Y2 - y1; ll dx_bi2 = X2 - x2; ll dy_bi2 = Y2 - y2; ll si = dx_ai * dy_bi - dy_ai * dx_bi; ll si2 = dx_ai2 * dy_bi2 - dy_ai2 * dx_bi2; ll si3 = dx_ai * dy_ai2 - dy_ai * dx_ai2; ll si4 = dx_bi * dy_bi2 - dy_bi * dx_bi2; return (si * si2 < 0 && si3 * si4 < 0); } //--------------------------------------------------------------- // 最長増加部分列の長さ(O(NlogN)) //--------------------------------------------------------------- ll LSI(vll vec, ll size) { vll lsi(size + 1); // 長さjを作った時の右端の最小値 for (ll i = 0; i <= size; i++) { lsi[i] = LLINF; } lsi[0] = 0; lsi[1] = vec[0]; for (ll i = 1; i < size; i++) { // 初めてvec[i]の方が小さくなるところを探す auto Iter = lower_bound(lsi.begin(), lsi.end(), vec[i]); ll idx = Iter - lsi.begin(); if (idx > 0 && lsi[idx - 1] < vec[i]) // 条件文の前半怪しい { lsi[idx] = vec[i]; } } for (ll i = size; i >= 0; i--) { if (lsi[i] < LLINF) { return i; } } } //--------------------------------------------------------------- // 木の根からの深さ //--------------------------------------------------------------- vll tree_depth(vvll edge, ll start_node, ll n_node) { vll dist(n_node, LLINF); dist[start_node] = 0; stack<pll> S; S.push({start_node, 0}); while (!S.empty()) { ll node = S.top().first; ll d = S.top().second; dist[node] = d; S.pop(); for (int i = 0; i < edge[node].size(); i++) { if (dist[edge[node][i]] == LLINF) { S.push({edge[node][i], d + 1}); } } } return dist; } //--------------------------------------------------------------- // ワーシャルフロイド法(O(N^3)) 任意の2点間の最短距離 //--------------------------------------------------------------- vvll warshall_floyd(ll n, vvll d) { 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]); } } } return d; } //--------------------------------------------------------------- // Union Find //--------------------------------------------------------------- /* UnionFind uf(要素の個数); for(int i = 0;i < 関係の個数; i++) { uf.merge(A[i], B[i]); } nを含む集合の大きさ = uf.size(n) nを含む集合の代表者 = uf.root(n) 集合の個数 = uf.n_group */ class UnionFind { public: vector<ll> par; // 各元の親を表す配列 vector<ll> siz; // 素集合のサイズを表す配列(1 で初期化) ll n_group; // 集合の数 // Constructor UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) { for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身 n_group = sz_; } void init(ll sz_) { par.resize(sz_); siz.assign(sz_, 1LL); // resize だとなぜか初期化されなかった for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身 } // Member Function // Find ll root(ll x) { // 根の検索 while (par[x] != x) { x = par[x] = par[par[x]]; // x の親の親を x の親とする } return x; } // Union(Unite, Merge) bool merge(ll x, ll y) { x = root(x); y = root(y); if (x == y) return false; // merge technique(データ構造をマージするテク.小を大にくっつける) if (siz[x] < siz[y]) swap(x, y); siz[x] += siz[y]; par[y] = x; n_group--; return true; } bool issame(ll x, ll y) { // 連結判定 return root(x) == root(y); } ll size(ll x) { // 素集合のサイズ return siz[root(x)]; } }; //======================================================================== int main() { ////================================== cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(30); ////================================== ll N, M; cin >> N >> M; vpll AB(N); for (int i = 0; i < N; i++) { cin >> AB[i].first >> AB[i].second; } sort(AB.begin(), AB.end()); priority_queue<ll> q; ll begin = 0; ll ans = 0; for (int i = 1; i <= M; i++) { for (int j = begin; j < N; j++) { if (AB[j].first <= i) { q.push(AB[j].second); begin++; } else { break; } } if (!q.empty()) { ans += q.top(); q.pop(); } } cout << ans; }
insert
443
443
443
445
TLE
p02948
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N, M; cin >> N >> M; vector<vector<int>> W(M); for (int i = 0; i < N; i++) { int A, B; cin >> A >> B; W[M - A].push_back(B); } int ans = 0; priority_queue<int> pq; for (int i = M - 1; i >= 0; i--) { for (int j : W[i]) { pq.push(j); } if (!pq.empty()) { ans += pq.top(); pq.pop(); } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N, M; cin >> N >> M; vector<vector<int>> W(M); for (int i = 0; i < N; i++) { int A, B; cin >> A >> B; if (M - A >= 0) { W[M - A].push_back(B); } } int ans = 0; priority_queue<int> pq; for (int i = M - 1; i >= 0; i--) { for (int j : W[i]) { pq.push(j); } if (!pq.empty()) { ans += pq.top(); pq.pop(); } } cout << ans << endl; }
replace
9
10
9
12
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long signed main() { cin.tie(0); ios_base::sync_with_stdio(0); cout << fixed << setprecision(12); int N, M; cin >> N >> M; using P = pair<int, int>; priority_queue<P> Q; vector<int> v[100000]; for (int i = 0; i < N; i++) { int a, b; cin >> a >> b; // Q.push(P(b, a)); v[a].push_back(b); } int ans = 0; for (int i = 1; i <= M; i++) { for (int j : v[i]) { Q.push(P(j, i)); } if (Q.size()) { int j = Q.top().first; Q.pop(); ans += j; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long signed main() { cin.tie(0); ios_base::sync_with_stdio(0); cout << fixed << setprecision(12); int N, M; cin >> N >> M; using P = pair<int, int>; priority_queue<P> Q; vector<int> v[100010]; for (int i = 0; i < N; i++) { int a, b; cin >> a >> b; // Q.push(P(b, a)); v[a].push_back(b); } int ans = 0; for (int i = 1; i <= M; i++) { for (int j : v[i]) { Q.push(P(j, i)); } if (Q.size()) { int j = Q.top().first; Q.pop(); ans += j; } } cout << ans << endl; return 0; }
replace
15
16
15
16
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int M = 100005; int n, m; struct node { int yc, val; } A[M]; bool comp(node a, node b) { return a.val > b.val; } bool mark[M]; set<int> s; set<int>::iterator it; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) scanf("%d%d", &A[i].yc, &A[i].val); sort(A + 1, A + n + 1, comp); int ans = 0; for (int i = 0; i <= m; i++) s.insert(-i); for (int i = 1; i <= n; i++) { int t = m - A[i].yc; if (t < 0) continue; it = s.lower_bound(-t); if (it == s.end()) continue; int k = -(*it); mark[-k] = 1; s.erase(-k); ans += A[i].val; } printf("%d\n", ans); }
#include <bits/stdc++.h> using namespace std; const int M = 100005; int n, m; struct node { int yc, val; } A[M]; bool comp(node a, node b) { return a.val > b.val; } bool mark[M]; set<int> s; set<int>::iterator it; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) scanf("%d%d", &A[i].yc, &A[i].val); sort(A + 1, A + n + 1, comp); int ans = 0; for (int i = 0; i <= m; i++) s.insert(-i); for (int i = 1; i <= n; i++) { int t = m - A[i].yc; if (t < 0) continue; it = s.lower_bound(-t); if (it == s.end()) continue; int k = -(*it); mark[k] = 1; s.erase(-k); ans += A[i].val; } printf("%d\n", ans); }
replace
27
28
27
28
0
p02948
C++
Time Limit Exceeded
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; typedef long long ll; const int INF = 1e9; const ll MOD = 1e9 + 7; const ll LINF = 1e18; #define y0 y3487465 #define y1 y8687969 #define j0 j1347829 #define j1 j234892 #define next asdnext #define prev asdprev #define MP make_pair // pairのコンストラクタ #define F first // pairの一つ目の要素 #define S second // pairの二つ目の要素 #define dump(x) cout << #x << " = " << (x) << endl; // debug #define SZ(x) ((ll)(x).size()) #define FOR(i, a, b) for (ll i = (a); i <= (b); i++) #define RFOR(i, a, b) for (ll i = (a); i >= (b); i--) #define ps(s) cout << #s << endl; #define pv(v) cout << (v) << endl; #define pvd(v) cout << setprecision(16) << (v) << endl; #define ALL(a) (a).begin(), (a).end() #define RANGE(a, start_index, num) \ (a).begin() + (start_index), (a).begin() + (num) int main() { vector<pair<int, int>> ab; int n, m; cin >> n >> m; FOR(i, 1, n) { int a, b; cin >> a >> b; ab.push_back(MP(a, b)); } sort(ALL(ab)); priority_queue<int> pq; int starti = 0; int now = 1; ll res = 0; while (1) { FOR(i, starti, n - 1) { if (ab[i].F == now) { pq.push(ab[i].S); starti = i + 1; } } if (!pq.empty()) { res += pq.top(); pq.pop(); } now++; if (now == m + 1) break; } pv(res); }
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; typedef long long ll; const int INF = 1e9; const ll MOD = 1e9 + 7; const ll LINF = 1e18; #define y0 y3487465 #define y1 y8687969 #define j0 j1347829 #define j1 j234892 #define next asdnext #define prev asdprev #define MP make_pair // pairのコンストラクタ #define F first // pairの一つ目の要素 #define S second // pairの二つ目の要素 #define dump(x) cout << #x << " = " << (x) << endl; // debug #define SZ(x) ((ll)(x).size()) #define FOR(i, a, b) for (ll i = (a); i <= (b); i++) #define RFOR(i, a, b) for (ll i = (a); i >= (b); i--) #define ps(s) cout << #s << endl; #define pv(v) cout << (v) << endl; #define pvd(v) cout << setprecision(16) << (v) << endl; #define ALL(a) (a).begin(), (a).end() #define RANGE(a, start_index, num) \ (a).begin() + (start_index), (a).begin() + (num) int main() { vector<pair<int, int>> ab; int n, m; cin >> n >> m; FOR(i, 1, n) { int a, b; cin >> a >> b; ab.push_back(MP(a, b)); } sort(ALL(ab)); priority_queue<int> pq; int starti = 0; int now = 1; ll res = 0; while (1) { FOR(i, starti, n - 1) { if (ab[i].F == now) { pq.push(ab[i].S); } else { starti = i; break; } } if (!pq.empty()) { res += pq.top(); pq.pop(); } now++; if (now == m + 1) break; } pv(res); }
replace
47
48
47
50
TLE
p02948
C++
Time Limit Exceeded
#include <iostream> #include <queue> #include <vector> using namespace std; typedef long long ll; int main() { int n, m; cin >> n >> m; vector<vector<int>> jobs(m); // 二次元配列に詰め込む for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; if (a > m) continue; jobs[m - a].push_back(b); } priority_queue<int> q; ll ans = 0; for (int i = m - 1; i >= 0; i--) { // pythonでいうfor i in hoge みたいなimage for (int b : jobs[i]) { q.push(b); } if (!q.empty()) { ans += q.top(); q.pop(); } } cout << ans << endl; return 0; }
#include <iostream> #include <queue> #include <vector> using namespace std; typedef long long ll; int main() { int n, m; cin >> n >> m; vector<vector<int>> jobs(m); // 二次元配列に詰め込む for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; if (a > m) continue; jobs[m - a].push_back(b); } priority_queue<int> q; ll ans = 0; for (int i = m - 1; i >= 0; i--) { // pythonでいうfor i in hoge みたいなimage for (int j = 0; j < jobs[i].size(); j++) { int b = jobs[i][j]; q.push(b); } if (!q.empty()) { ans += q.top(); q.pop(); } } cout << ans << endl; return 0; }
replace
24
25
24
26
TLE
p02948
C++
Runtime Error
#include <bits/stdc++.h> #define REP(i, N) for (ll i = 0; i < (N); ++i) #define ALL(x) (x).begin(), (x).end() #define MOD 1000000007 #define PB push_back #define MP make_pair using namespace std; typedef long long ll; ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } //++時計回り --反時計回り // int dx[4] = {1, 0, -1, 0}; // int dy[4] = {0, 1, 0, -1}; int main() { ll N, M; cin >> N >> M; vector<vector<ll>> v(M + 1); REP(i, N) { ll a, b; cin >> a >> b; v[a].PB(b); } ll ans = 0; priority_queue<ll> pq; for (ll i = 1; i <= M; i++) { for (auto e : v[i]) pq.push(e); if (pq.size() != 0) { ans += pq.top(); pq.pop(); } } cout << ans << '\n'; }
#include <bits/stdc++.h> #define REP(i, N) for (ll i = 0; i < (N); ++i) #define ALL(x) (x).begin(), (x).end() #define MOD 1000000007 #define PB push_back #define MP make_pair using namespace std; typedef long long ll; ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } //++時計回り --反時計回り // int dx[4] = {1, 0, -1, 0}; // int dy[4] = {0, 1, 0, -1}; int main() { ll N, M; cin >> N >> M; vector<vector<ll>> v(1e5 + 1); REP(i, N) { ll a, b; cin >> a >> b; v[a].PB(b); } ll ans = 0; priority_queue<ll> pq; for (ll i = 1; i <= M; i++) { for (auto e : v[i]) pq.push(e); if (pq.size() != 0) { ans += pq.top(); pq.pop(); } } cout << ans << '\n'; }
replace
17
18
17
18
0
p02948
C++
Runtime Error
#include <algorithm> #include <iostream> #include <map> #include <queue> #include <vector> using namespace std; int main() { int n, m, a, b, ans = 0; cin >> n >> m; priority_queue<int> que; vector<int> v[100000]; for (int i = 0; i < n; i++) { cin >> a >> b; v[a].push_back(b); } for (int i = 1; i <= m; i++) { for (auto p : v[i]) { que.push(p); } if (que.size()) { ans += que.top(); que.pop(); } } cout << ans << endl; }
#include <algorithm> #include <iostream> #include <map> #include <queue> #include <vector> using namespace std; int main() { int n, m, a, b, ans = 0; cin >> n >> m; priority_queue<int> que; vector<int> v[100005]; for (int i = 0; i < n; i++) { cin >> a >> b; v[a].push_back(b); } for (int i = 1; i <= m; i++) { for (auto p : v[i]) { que.push(p); } if (que.size()) { ans += que.top(); que.pop(); } } cout << ans << endl; }
replace
10
11
10
11
0
p02948
C++
Runtime Error
#include <algorithm> #include <iostream> #include <queue> #include <utility> using namespace std; int n, m, a, b; pair<int, int> p[100000]; priority_queue<int> que; int ans; int main() { cin >> n >> m; for (int i = 0; i < n; i++) cin >> a >> b, p[i] = make_pair(a, b); sort(p, p + n); int x = 0; for (int i = 1; i <= m; i++) { for (; p[x].first <= i; x++) que.push(p[x].second); if (!que.empty()) ans += que.top(), que.pop(); } cout << ans << endl; }
#include <algorithm> #include <iostream> #include <queue> #include <utility> using namespace std; int n, m, a, b; pair<int, int> p[100000]; priority_queue<int> que; int ans; int main() { cin >> n >> m; for (int i = 0; i < n; i++) cin >> a >> b, p[i] = make_pair(a, b); sort(p, p + n); int x = 0; for (int i = 1; i <= m; i++) { for (; x < n && p[x].first <= i; x++) que.push(p[x].second); if (!que.empty()) ans += que.top(), que.pop(); } cout << ans << endl; }
replace
16
17
16
17
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> #define int long long const int maxn = (int)1e6 + 6; using namespace std; signed main() { priority_queue<int> pq; int n, m, sum = 0; cin >> n >> m; vector<int> vec[n]; for (int i = 0; i < n; i++) { int days, score; cin >> days >> score; vec[days].push_back(score); } for (int i = 1; i <= m; i++) { for (int j = 0; j < (int)vec[i].size(); j++) { pq.push(vec[i][j]); } if (!pq.empty()) { sum += pq.top(); pq.pop(); } } cout << sum; }
#include <bits/stdc++.h> #define int long long const int maxn = (int)1e6 + 6; using namespace std; signed main() { priority_queue<int> pq; int n, m, sum = 0; cin >> n >> m; vector<int> vec[maxn]; for (int i = 0; i < n; i++) { int days, score; cin >> days >> score; vec[days].push_back(score); } for (int i = 1; i <= m; i++) { for (int j = 0; j < (int)vec[i].size(); j++) { pq.push(vec[i][j]); } if (!pq.empty()) { sum += pq.top(); pq.pop(); } } cout << sum; }
replace
8
9
8
9
-11
p02948
C++
Runtime Error
#include <algorithm> #include <iostream> #include <queue> #include <vector> typedef long long ll; int main() { int N, M; std::cin >> N >> M; int A, B; std::vector<std::vector<int>> AB(M); for (int i = 0; i < N; ++i) { std::cin >> A >> B; AB[M - A].push_back(B); } ll ans = 0; std::priority_queue<int> que; for (int i = M - 1; i >= 0; --i) { for (int b : AB[i]) que.push(b); if (!que.empty()) { ans += que.top(); que.pop(); } } std::cout << ans << std::endl; return 0; }
#include <algorithm> #include <iostream> #include <queue> #include <vector> typedef long long ll; int main() { int N, M; std::cin >> N >> M; int A, B; std::vector<std::vector<int>> AB(M); for (int i = 0; i < N; ++i) { std::cin >> A >> B; if (A > M) continue; AB[M - A].push_back(B); } ll ans = 0; std::priority_queue<int> que; for (int i = M - 1; i >= 0; --i) { for (int b : AB[i]) que.push(b); if (!que.empty()) { ans += que.top(); que.pop(); } } std::cout << ans << std::endl; return 0; }
insert
14
14
14
16
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, m, x, y, p = 0, i, k, j; cin >> n >> m; vector<int> v[m]; for (i = 0; i < n; i++) { cin >> x >> y; if (x <= m) { v[x].push_back(y); } } priority_queue<int> pq; for (i = 1; i <= m; i++) { for (j = 0; j < v[i].size(); j++) { k = v[i][j]; pq.push(k); } if (!pq.empty()) { p = p + pq.top(); pq.pop(); } } cout << p << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, m, x, y, p = 0, i, k, j; cin >> n >> m; vector<int> v[m + 1]; for (i = 0; i < n; i++) { cin >> x >> y; if (x <= m) { v[x].push_back(y); } } priority_queue<int> pq; for (i = 1; i <= m; i++) { for (j = 0; j < v[i].size(); j++) { k = v[i][j]; pq.push(k); } if (!pq.empty()) { p = p + pq.top(); pq.pop(); } } cout << p << endl; return 0; }
replace
6
7
6
7
-11
p02948
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, m, x, y, p = 0, i, k, j; cin >> n >> m; vector<int> v[n + 1]; for (i = 0; i < n; i++) { cin >> x >> y; if (x <= m) { v[x].push_back(y); } } priority_queue<int> pq; for (i = 1; i <= m; i++) { for (j = 0; j < v[i].size(); j++) { k = v[i][j]; pq.push(k); } if (!pq.empty()) { p = p + pq.top(); pq.pop(); } } cout << p << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, m, x, y, p = 0, i, k, j; cin >> n >> m; vector<int> v[m + 1]; for (i = 0; i < n; i++) { cin >> x >> y; if (x <= m) { v[x].push_back(y); } } priority_queue<int> pq; for (i = 1; i <= m; i++) { for (j = 0; j < v[i].size(); j++) { k = v[i][j]; pq.push(k); } if (!pq.empty()) { p = p + pq.top(); pq.pop(); } } cout << p << endl; return 0; }
replace
6
7
6
7
-11
p02948
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; using Graph = vector<vector<ll>>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { int N, M; cin >> N >> M; Graph G(M); rep(i, N) { int A, B; cin >> A >> B; A--; G[A].push_back(B); } ll sum = 0; priority_queue<ll> list; rep(i, M) { if (G[i].size() > 0) { rep(j, G[i].size()) { list.push(G[i][j]); } } if (list.size() > 0) { sum = sum + list.top(); list.pop(); } } cout << sum << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; using Graph = vector<vector<ll>>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { int N, M; cin >> N >> M; Graph G(M); rep(i, N) { int A, B; cin >> A >> B; if (A <= M) { A--; G[A].push_back(B); } } ll sum = 0; priority_queue<ll> list; rep(i, M) { if (G[i].size() > 0) { rep(j, G[i].size()) { list.push(G[i][j]); } } if (list.size() > 0) { sum = sum + list.top(); list.pop(); } } cout << sum << endl; }
replace
13
15
13
17
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rng(i, a, b) for (int i = int(a); i < int(b); i++) #define rep(i, b) rng(i, 0, b) #define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--) #define per(i, b) gnr(i, 0, b) #define ALL(x) (x).begin(), (x).end() #define RALL(x) (x).rbegin(), (x).rend() #define IDX(vec, element_iter) distance((vec).begin(), element_iter) #define print(x) cout << (x) << '\n' #define pe(x) cout << (x) << " " #define DEBUG(x) cout << #x << ": " << x << endl #define pb push_back #define mp make_pair #define MOD 1000000007 // 10^9+7 #define fi first #define sc second using ll = long long; using pll = pair<ll, ll>; using vi = vector<int>; using vll = vector<ll>; using vstr = vector<string>; void yes(bool c) { if (c) print("Yes"); else print("No"); }; int N, M; ll ans = 0; void solve() { cin >> N >> M; vector<vector<int>> d(51); rep(i, N) { int a, b; cin >> a >> b; d[a].pb(b); } priority_queue<int> pq; per(i, M) { for (auto t : d[M - i]) { pq.push(t); } if (!pq.empty()) { ans += pq.top(); pq.pop(); } } print(ans); } int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(20); // int q; cin >> q; // while (q--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define rng(i, a, b) for (int i = int(a); i < int(b); i++) #define rep(i, b) rng(i, 0, b) #define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--) #define per(i, b) gnr(i, 0, b) #define ALL(x) (x).begin(), (x).end() #define RALL(x) (x).rbegin(), (x).rend() #define IDX(vec, element_iter) distance((vec).begin(), element_iter) #define print(x) cout << (x) << '\n' #define pe(x) cout << (x) << " " #define DEBUG(x) cout << #x << ": " << x << endl #define pb push_back #define mp make_pair #define MOD 1000000007 // 10^9+7 #define fi first #define sc second using ll = long long; using pll = pair<ll, ll>; using vi = vector<int>; using vll = vector<ll>; using vstr = vector<string>; void yes(bool c) { if (c) print("Yes"); else print("No"); }; int N, M; ll ans = 0; void solve() { cin >> N >> M; vector<vector<int>> d(100000); rep(i, N) { int a, b; cin >> a >> b; d[a].pb(b); } priority_queue<int> pq; per(i, M) { for (auto t : d[M - i]) { pq.push(t); } if (!pq.empty()) { ans += pq.top(); pq.pop(); } } print(ans); } int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(20); // int q; cin >> q; // while (q--) solve(); return 0; }
replace
34
35
34
35
0
p02948
C++
Runtime Error
#include <algorithm> #include <array> #include <bitset> #include <cmath> #include <complex> #include <cstdio> #include <deque> #include <fstream> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define REP(i, n) for (int i = 0; i < n; ++i) #define FOR(i, a, b) for (int i = a; i <= b; ++i) #define FORR(i, a, b) for (int i = a; i >= b; --i) #define ALL(c) (c).begin(), (c).end() typedef long long ll; typedef vector<int> VI; typedef vector<ll> VL; typedef vector<long double> VD; typedef vector<VI> VVI; typedef vector<VL> VVL; typedef vector<VD> VVD; typedef pair<int, int> P; typedef pair<ll, ll> PL; template <typename T> void chmin(T &a, T b) { if (a > b) a = b; } template <typename T> void chmax(T &a, T b) { if (a < b) a = b; } int in() { int x; scanf("%d", &x); return x; } ll lin() { ll x; scanf("%lld", &x); return x; } int main() { ll n, m; cin >> n >> m; VVL b(m); REP(i, n) { ll x = in() - 1, y = in(); b[x].push_back(y); } priority_queue<ll> que; ll ans = 0; REP(i, m) { for (ll x : b[i]) que.push(x); if (!que.empty()) { ans += que.top(); que.pop(); } } cout << ans << endl; return 0; }
#include <algorithm> #include <array> #include <bitset> #include <cmath> #include <complex> #include <cstdio> #include <deque> #include <fstream> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define REP(i, n) for (int i = 0; i < n; ++i) #define FOR(i, a, b) for (int i = a; i <= b; ++i) #define FORR(i, a, b) for (int i = a; i >= b; --i) #define ALL(c) (c).begin(), (c).end() typedef long long ll; typedef vector<int> VI; typedef vector<ll> VL; typedef vector<long double> VD; typedef vector<VI> VVI; typedef vector<VL> VVL; typedef vector<VD> VVD; typedef pair<int, int> P; typedef pair<ll, ll> PL; template <typename T> void chmin(T &a, T b) { if (a > b) a = b; } template <typename T> void chmax(T &a, T b) { if (a < b) a = b; } int in() { int x; scanf("%d", &x); return x; } ll lin() { ll x; scanf("%lld", &x); return x; } int main() { ll n, m; cin >> n >> m; VVL b(m); REP(i, n) { ll x = in() - 1, y = in(); if (x < m) b[x].push_back(y); } priority_queue<ll> que; ll ans = 0; REP(i, m) { for (ll x : b[i]) que.push(x); if (!que.empty()) { ans += que.top(); que.pop(); } } cout << ans << endl; return 0; }
replace
58
59
58
60
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> #define int long long using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) typedef pair<int, int> pii; const int INF = 1l << 60; #define u_b upper_bound #define l_b lower_bound int N, M; pii AB[100100]; signed main() { cin >> N >> M; rep(i, N) { cin >> AB[i].first >> AB[i].second; } sort(AB, AB + N); priority_queue<int> pque; int k = 0; int ans = 0; for (int i = 1; i <= M; ++i) { // i日前 while (AB[k].first <= i) { pque.push(AB[k].second); k++; } if (!pque.empty()) { ans += pque.top(); pque.pop(); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define int long long using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) typedef pair<int, int> pii; const int INF = 1l << 60; #define u_b upper_bound #define l_b lower_bound int N, M; pii AB[100100]; signed main() { cin >> N >> M; rep(i, N) { cin >> AB[i].first >> AB[i].second; } sort(AB, AB + N); priority_queue<int> pque; int k = 0; int ans = 0; for (int i = 1; i <= M; ++i) { // i日前 while (k < N && AB[k].first <= i) { pque.push(AB[k].second); k++; } if (!pque.empty()) { ans += pque.top(); pque.pop(); } } cout << ans << endl; return 0; }
replace
22
23
22
23
-11
p02948
C++
Runtime Error
#include <bits/stdc++.h> typedef long long ll; using namespace std; int main() { int n, m, a, b; vector<pair<int, int>> p; priority_queue<int> q; cin >> n >> m; for (int i = 0; i < n; i++) { cin >> a >> b; p.push_back(make_pair(a, b)); } sort(p.begin(), p.end()); auto itr = p.begin(); ll ans = 0; for (int i = 1; i <= m; i++) { while ((*itr).first <= i) { q.push((*itr).second); itr++; } if (!q.empty()) { ans += q.top(); q.pop(); } } cout << ans << endl; }
#include <bits/stdc++.h> typedef long long ll; using namespace std; int main() { int n, m, a, b; vector<pair<int, int>> p; priority_queue<int> q; cin >> n >> m; for (int i = 0; i < n; i++) { cin >> a >> b; p.push_back(make_pair(a, b)); } sort(p.begin(), p.end()); auto itr = p.begin(); ll ans = 0; for (int i = 1; i <= m; i++) { while ((*itr).first <= i && itr != p.end()) { q.push((*itr).second); itr++; } if (!q.empty()) { ans += q.top(); q.pop(); } } cout << ans << endl; }
replace
17
18
17
18
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int maxn = 510; typedef long long ll; typedef pair<int, int> P; P a[maxn]; priority_queue<int> q; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; ll ans = 0; for (int i = 0; i < n; i++) { cin >> a[i].first >> a[i].second; } sort(a, a + n); int j = 0; for (int i = 1; i <= m; i++) { for (; j < n; j++) { if (a[j].first > i) { break; } q.push(a[j].second); } if (!q.empty()) { ans += q.top(); q.pop(); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; typedef long long ll; typedef pair<int, int> P; P a[maxn]; priority_queue<int> q; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; ll ans = 0; for (int i = 0; i < n; i++) { cin >> a[i].first >> a[i].second; } sort(a, a + n); int j = 0; for (int i = 1; i <= m; i++) { for (; j < n; j++) { if (a[j].first > i) { break; } q.push(a[j].second); } if (!q.empty()) { ans += q.top(); q.pop(); } } cout << ans << endl; return 0; }
replace
4
5
4
5
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; #define chmax(x, y) x = max(x, y); int main() { int n, m; cin >> n >> m; vector<vector<int>> jobs(m); rep(i, n) { int a, b; cin >> a >> b; jobs[m - a].push_back(b); } priority_queue<int> q; ll ans = 0; for (int i = m - 1; i >= 0; i--) { for (int b : jobs[i]) { q.push(b); } if (!q.empty()) { ans += q.top(); q.pop(); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; #define chmax(x, y) x = max(x, y); int main() { int n, m; cin >> n >> m; vector<vector<int>> jobs(m); rep(i, n) { int a, b; cin >> a >> b; if (a > m) continue; jobs[m - a].push_back(b); } priority_queue<int> q; ll ans = 0; for (int i = m - 1; i >= 0; i--) { for (int b : jobs[i]) { q.push(b); } if (!q.empty()) { ans += q.top(); q.pop(); } } cout << ans << endl; return 0; }
insert
14
14
14
16
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; int main() { int n, m; cin >> n >> m; vector<int> work[m + 1]; rep(i, n) { int a, b; cin >> a >> b; if (m + 1 < a) continue; work[a].push_back(b); } priority_queue<int> q; ll ans = 0; rep(i, m + 1) { for (int b : work[i]) { q.push(b); } if (!q.empty()) { ans += q.top(); q.pop(); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; int main() { int n, m; cin >> n >> m; vector<int> work[m + 2]; rep(i, n) { int a, b; cin >> a >> b; if (m + 1 < a) continue; work[a].push_back(b); } priority_queue<int> q; ll ans = 0; rep(i, m + 1) { for (int b : work[i]) { q.push(b); } if (!q.empty()) { ans += q.top(); q.pop(); } } cout << ans << endl; return 0; }
replace
8
9
8
9
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define sz(x) int(x.size()) using namespace std; typedef long long ll; int main() { int n, m; cin >> n >> m; vector<vector<int>> jobs(m + 1); int a, b; rep(i, n) { cin >> a >> b; jobs[m - a].push_back(b); } ll ans = 0; priority_queue<int> q; for (int i = m - 1; i >= 0; i--) { for (auto &&job : jobs[i]) { q.push(job); } if (!q.empty()) { ans += q.top(); q.pop(); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define sz(x) int(x.size()) using namespace std; typedef long long ll; int main() { int n, m; cin >> n >> m; vector<vector<int>> jobs(m + 1); int a, b; rep(i, n) { cin >> a >> b; if (a > m) continue; jobs[m - a].push_back(b); } ll ans = 0; priority_queue<int> q; for (int i = m - 1; i >= 0; i--) { for (auto &&job : jobs[i]) { q.push(job); } if (!q.empty()) { ans += q.top(); q.pop(); } } cout << ans << endl; return 0; }
insert
13
13
13
15
0
p02948
C++
Runtime Error
#define _CRT_SECURE_NO_WARNINGS #include <algorithm> #include <functional> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <vector> #define _USE_MATH_DEFINES #include <bitset> #include <deque> #include <iostream> #include <list> #include <map> #include <math.h> #include <queue> #include <set> using namespace std; typedef long long ll; #define rep(i, a, b) for (auto i = a; i < b; i++) #define rep2(i, a) for (auto i : a) #define all(_x) _x.begin(), _x.end() #define r_sort(_x) sort(_x, std::greater<int>()) #define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n)) #define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end()); #define vvec vector<vector<ll>> 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; } #define INF 1 << 30 const int mod = 1000000007; ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } } return a; } ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } } return a; } ll ac(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; } return a; } ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; } int main() { int n, m, a, b; cin >> n >> m; vector<vector<int>> work(m + 1); rep(i, 0, n) { cin >> a >> b; work[a].push_back(b); } priority_queue<int> temp; ll ans = 0; rep(i, 0, m) { rep2(v, work[i + 1]) temp.push(v); if (temp.size()) { ans += (ll)temp.top(); temp.pop(); } } printf("%lld\n", ans); return 0; }
#define _CRT_SECURE_NO_WARNINGS #include <algorithm> #include <functional> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <vector> #define _USE_MATH_DEFINES #include <bitset> #include <deque> #include <iostream> #include <list> #include <map> #include <math.h> #include <queue> #include <set> using namespace std; typedef long long ll; #define rep(i, a, b) for (auto i = a; i < b; i++) #define rep2(i, a) for (auto i : a) #define all(_x) _x.begin(), _x.end() #define r_sort(_x) sort(_x, std::greater<int>()) #define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n)) #define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end()); #define vvec vector<vector<ll>> 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; } #define INF 1 << 30 const int mod = 1000000007; ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } } return a; } ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } } return a; } ll ac(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; } return a; } ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; } int main() { int n, m, a, b; cin >> n >> m; vector<vector<int>> work(m + 1); rep(i, 0, n) { cin >> a >> b; if (a > m) continue; work[a].push_back(b); } priority_queue<int> temp; ll ans = 0; rep(i, 0, m) { rep2(v, work[i + 1]) temp.push(v); if (temp.size()) { ans += (ll)temp.top(); temp.pop(); } } printf("%lld\n", ans); return 0; }
insert
78
78
78
80
0
p02948
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iostream> #include <numeric> #include <string> #include <vector> using namespace std; using ll = long long; #define REP(i, n) for (ll i = 0; i < (ll)(n); i++) #define REPD(i, n) for (ll i = n - 1; i >= 0; i--) #define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++) #define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--) #define input(...) \ __VA_ARGS__; \ in(__VA_ARGS__) template <class T> void print(vector<T> a) { cout << "[ "; REP(i, a.size()) cout << a[i] << " "; cout << "]" << endl; } void print() { std::cout << std::endl; } template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) { std::cout << head << " "; print(std::forward<Tail>(tail)...); } void in() {} template <class Head, class... Tail> void in(Head &&head, Tail &&...tail) { cin >> head; in(std::forward<Tail>(tail)...); } ll n, m; vector<pair<ll, ll>> ab; int main() { cin >> n >> m; ab = vector<pair<ll, ll>>(n); REP(i, n) { ll input(a, b); ab[i] = {a, b}; } sort(ab.begin(), ab.end(), [](auto v1, auto v2) { return v1.second > v2.second; }); // sort(ab.begin(), ab.end(), [](auto v1, auto v2){ // if (v1.first == v2.first) { // return v1.second > v2.second; // } // return v1.first > v2.first; // }); vector<ll> plan(m + 1, 0); vector<ll> shift(m + 1); REP(i, n) { if (plan[ab[i].first] == 0) { plan[ab[i].first] = ab[i].second; shift[ab[i].first] = ab[i].first + 1; } else { vector<ll> visited; for (ll nxt = shift[ab[i].first];; nxt = shift[nxt]) { if (nxt > m) break; visited.push_back(nxt); if (plan[nxt] == 0) { for (auto v : visited) { shift[v] = nxt + 1; } plan[nxt] = ab[i].second; break; } } } } cout << accumulate(plan.begin(), plan.end(), 0ll) << endl; }
#include <algorithm> #include <cmath> #include <iostream> #include <numeric> #include <string> #include <vector> using namespace std; using ll = long long; #define REP(i, n) for (ll i = 0; i < (ll)(n); i++) #define REPD(i, n) for (ll i = n - 1; i >= 0; i--) #define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++) #define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--) #define input(...) \ __VA_ARGS__; \ in(__VA_ARGS__) template <class T> void print(vector<T> a) { cout << "[ "; REP(i, a.size()) cout << a[i] << " "; cout << "]" << endl; } void print() { std::cout << std::endl; } template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) { std::cout << head << " "; print(std::forward<Tail>(tail)...); } void in() {} template <class Head, class... Tail> void in(Head &&head, Tail &&...tail) { cin >> head; in(std::forward<Tail>(tail)...); } ll n, m; vector<pair<ll, ll>> ab; int main() { cin >> n >> m; ab = vector<pair<ll, ll>>(n); REP(i, n) { ll input(a, b); ab[i] = {a, b}; } sort(ab.begin(), ab.end(), [](auto v1, auto v2) { return v1.second > v2.second; }); // sort(ab.begin(), ab.end(), [](auto v1, auto v2){ // if (v1.first == v2.first) { // return v1.second > v2.second; // } // return v1.first > v2.first; // }); vector<ll> plan(m + 1, 0); vector<ll> shift(m + 1); REP(i, n) { if (ab[i].first > m) continue; if (plan[ab[i].first] == 0) { plan[ab[i].first] = ab[i].second; shift[ab[i].first] = ab[i].first + 1; } else { vector<ll> visited; for (ll nxt = shift[ab[i].first];; nxt = shift[nxt]) { if (nxt > m) break; visited.push_back(nxt); if (plan[nxt] == 0) { for (auto v : visited) { shift[v] = nxt + 1; } plan[nxt] = ab[i].second; break; } } } } cout << accumulate(plan.begin(), plan.end(), 0ll) << endl; }
insert
64
64
64
66
0
p02948
C++
Runtime Error
#include <algorithm> #include <iostream> #include <queue> #include <stdio.h> #include <string.h> using namespace std; using pii = pair<int, int>; const int N = 1e5 + 1; pii arr[N]; int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < n; ++i) scanf("%d%d", &(arr[i].first), &(arr[i].second)); sort(arr, arr + n); priority_queue<int> q; int ans = 0; for (int i = 1, j = 0; i <= m; ++i) { while (j < n && arr[j].first <= i) q.push(arr[j++].second); ans += q.top(); q.pop(); } printf("%d\n", ans); return 0; }
#include <algorithm> #include <iostream> #include <queue> #include <stdio.h> #include <string.h> using namespace std; using pii = pair<int, int>; const int N = 1e5 + 1; pii arr[N]; int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < n; ++i) scanf("%d%d", &(arr[i].first), &(arr[i].second)); sort(arr, arr + n); priority_queue<int> q; int ans = 0; for (int i = 1, j = 0; i <= m; ++i) { while (j < n && arr[j].first <= i) q.push(arr[j++].second); if (!q.empty()) { ans += q.top(); q.pop(); } } printf("%d\n", ans); return 0; }
replace
21
23
21
25
-11
p02948
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <iostream> #include <queue> #include <string> #include <vector> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, n) FOR(i, 0, n) #define ASC(c) sort((c).begin(), (c).end()) #define DESC(c) sort((c).begin(), (c).end(), greater<int>()) #define DUMP(x) cerr << #x << " = " << (x) << endl; #define DEBUG(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; typedef long long ll; typedef unsigned long long ull; struct edge { int u, v; ll w; }; ll MOD = 1000000007; ll _MOD = 1000000009; double EPS = 1e-10; int main() { int n, m; cin >> n >> m; vector<pair<int, int>> p(n); priority_queue<int> q; REP(i, n) { int a, b; cin >> a >> b; p[i] = make_pair(a, b); } ASC(p); int ans = 0; int idx = 0; FOR(i, 1, m + 1) { for (int l = idx; l < n; l++) { if (p[l].first <= i) { q.push(p[l].second); idx++; } } if (!q.empty()) { ans += q.top(); q.pop(); } } cout << ans << endl; }
#include <algorithm> #include <cmath> #include <iostream> #include <queue> #include <string> #include <vector> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, n) FOR(i, 0, n) #define ASC(c) sort((c).begin(), (c).end()) #define DESC(c) sort((c).begin(), (c).end(), greater<int>()) #define DUMP(x) cerr << #x << " = " << (x) << endl; #define DEBUG(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; typedef long long ll; typedef unsigned long long ull; struct edge { int u, v; ll w; }; ll MOD = 1000000007; ll _MOD = 1000000009; double EPS = 1e-10; int main() { int n, m; cin >> n >> m; vector<pair<int, int>> p(n); priority_queue<int> q; REP(i, n) { int a, b; cin >> a >> b; p[i] = make_pair(a, b); } ASC(p); int ans = 0; int idx = 0; FOR(i, 1, m + 1) { for (int l = idx; l < n; l++) { if (p[l].first > i) break; q.push(p[l].second); idx++; } if (!q.empty()) { ans += q.top(); q.pop(); } } cout << ans << endl; }
replace
45
49
45
49
TLE
p02948
C++
Runtime Error
#include <algorithm> #include <iostream> #include <queue> #include <vector> using namespace std; int main() { int n, m, a, b; cin >> n >> m; vector<int> v[m + 9]; int mx[m + 9]; for (int i = 0; i < n; i++) { cin >> a >> b; v[a].push_back(b); } long long cnt = 0; priority_queue<long long> Q; for (int i = 1; i <= m; i++) { if (!v[i].empty()) { for (int j = 0; j < v[i].size(); j++) { Q.push(v[i][j]); } } if (!Q.empty()) { cnt += Q.top(); Q.pop(); } } cout << cnt << endl; }
#include <algorithm> #include <iostream> #include <queue> #include <vector> using namespace std; int main() { int n, m, a, b; cin >> n >> m; vector<int> v[100009]; for (int i = 0; i < n; i++) { cin >> a >> b; v[a].push_back(b); } long long cnt = 0; priority_queue<long long> Q; for (int i = 1; i <= m; i++) { if (!v[i].empty()) { for (int j = 0; j < v[i].size(); j++) { Q.push(v[i][j]); } } if (!Q.empty()) { cnt += Q.top(); Q.pop(); } } cout << cnt << endl; }
replace
10
12
10
11
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<vector<int>> job(m + 1); for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; job[a].push_back(b); } int ans = 0; priority_queue<int, vector<int>, less<int>> work; for (int i = 1; i <= m; i++) { for (int next : job[i]) { work.push(next); } if (!work.empty()) { ans += work.top(); work.pop(); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<vector<int>> job(100001); for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; job[a].push_back(b); } int ans = 0; priority_queue<int, vector<int>, less<int>> work; for (int i = 1; i <= m; i++) { for (int next : job[i]) { work.push(next); } if (!work.empty()) { ans += work.top(); work.pop(); } } cout << ans << endl; return 0; }
replace
7
8
7
8
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> using namespace ::std; #define all(x) (x).begin(), (x).end() typedef long long ll; typedef array<int, 3> tri; typedef long double ld; template <class T> istream &operator>>(istream &I, vector<T> &v) { for (T &e : v) I >> e; return I; } template <class T> ostream &operator<<(ostream &O, const vector<T> &v) { for (const T &e : v) O << e << ' '; return O; } void _main() { int n, m; cin >> n >> m; vector<vector<int>> when((int)1e5 + 1); m++; int from = 1; while (n--) { int time, cost; cin >> time >> cost; when[m - time].emplace_back(cost); } ll ans = 0; priority_queue<int> pq; for (int time = m; time >= 1; time--) { while (when[time].size()) { pq.emplace(when[time].back()); when[time].pop_back(); } if (pq.size()) ans += pq.top(), pq.pop(); } cout << ans; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen("input.txt", "r", stdin); int _t = 1; // cin >> _t; while (_t--) _main(); return 0; }
#include <bits/stdc++.h> using namespace ::std; #define all(x) (x).begin(), (x).end() typedef long long ll; typedef array<int, 3> tri; typedef long double ld; template <class T> istream &operator>>(istream &I, vector<T> &v) { for (T &e : v) I >> e; return I; } template <class T> ostream &operator<<(ostream &O, const vector<T> &v) { for (const T &e : v) O << e << ' '; return O; } void _main() { int n, m; cin >> n >> m; vector<vector<int>> when((int)1e5 + 1); m++; int from = 1; while (n--) { int time, cost; cin >> time >> cost; if (m - time >= 1) when[m - time].emplace_back(cost); } ll ans = 0; priority_queue<int> pq; for (int time = m; time >= 1; time--) { while (when[time].size()) { pq.emplace(when[time].back()); when[time].pop_back(); } if (pq.size()) ans += pq.top(), pq.pop(); } cout << ans; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen("input.txt", "r", stdin); int _t = 1; // cin >> _t; while (_t--) _main(); return 0; }
replace
30
31
30
32
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, a) for (int i = 0; i < int(a); ++i) #define REP(i, a, b) for (int i = int(a); i < int(b); ++i) #define INF 10000000 using ll = long long; using itn = int; using namespace std; using Graph = vector<vector<int>>; int GCD(int a, int b) { return b ? GCD(b, a % b) : a; } int main() { int N, M; cin >> N >> M; vector<vector<int>> work(10); rep(i, N) { int a, b; cin >> a >> b; work.at(a).push_back(b); } ll ans = 0; priority_queue<int> q; for (int day = 0; day <= M; day++) { for (int i : work.at(day)) { q.push(i); } if (q.size() != 0) { ans += q.top(); q.pop(); } } cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, a) for (int i = 0; i < int(a); ++i) #define REP(i, a, b) for (int i = int(a); i < int(b); ++i) #define INF 10000000 using ll = long long; using itn = int; using namespace std; using Graph = vector<vector<int>>; int GCD(int a, int b) { return b ? GCD(b, a % b) : a; } int main() { int N, M; cin >> N >> M; vector<vector<int>> work(10e5 + 10); rep(i, N) { int a, b; cin >> a >> b; work.at(a).push_back(b); } ll ans = 0; priority_queue<int> q; for (int day = 0; day <= M; day++) { for (int i : work.at(day)) { q.push(i); } if (q.size() != 0) { ans += q.top(); q.pop(); } } cout << ans << endl; }
replace
12
13
12
13
0
p02948
C++
Runtime Error
/***"In the name of Allah(swt), the most gracious, most merciful. Allah(swt) * blesses with knowledge whom he wants."***/ /*Header file starts here*/ // #include<bits/stdc++.h> #include <algorithm> #include <bitset> #include <cctype> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> /*Header file ends here*/ /*Macro starts here*/ #define fasterInOut \ ios::sync_with_stdio(false); \ cin.tie(0); #define fin(in) freopen("in.txt", "r", stdin) #define fout(out) freopen("out.txt", "w", stdout) #define pb push_back #define ll long long #define lld I64d // for CF submissions #define rh cout << "Reached Here\n" #define inf LLONG_MAX #define neginf LLONG_MIN #define forit(it, s) \ for (__typeof((s).end()) it = (s).begin(); it != (s).end(); it++) #define string_reverse(s) \ reverse(s.begin(), s.end()) // Vector also can be reversed with this function #define memz(x) memset(x, 0, sizeof(x)); #define memneg(x) memset(x, -1, sizeof(x)); // Geometry & Maths #define gcd(a, b) __gcd(a, b) #define lcm(a, b) (a * b) / gcd(a, b) #define pi acos(-1.0) #define negmod(ans, x, m) \ ll y = (-1 * x) % m; \ if (y == 0) \ ans = 0; \ else \ ans = m - y; // for negative mod only i.e. when x<0. Undefined when m<0 #define dis(x1, y1, x2, y2) sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) #define t_area(a, b, c, s) \ sqrt(s *(s - a) * (s - b) * (s - c)) // s= (a+b+c)/2.0 #define t_angle(a, b, c) \ acos((a * a + b * b - c * c) / \ (2 * a * b)) // returns angle C in radian. a, b, c are anti-clockwise // formatted and side a and b form angle C #define pointPos(x1, y1, x2, y2, x3, y3) \ ((x2 - x1) * (y3 - y1)) - ((x3 - x1) * (y2 - y1)); /*returns NEGATIVE if the \ Point P3 is on the RIGHT side of the line P1P2, otherwise returns POSITIVE in \ case of LEFT and ZERO when the point is on the line*/ #define t_areaWithPoints(x1, y1, x2, y2, x3, y3) \ abs(0.5 * \ (x1 * (y2 - y3) + x2 * (y3 - y1) + \ x3 * \ (y1 - y2))); // returns the area of a triangle formed by P1, p2, p3 // Base Conversions #define toBin(bin, n) \ bin = bitset<8>(n).to_string() // returns a corresponding 8 bit Binary string // 'bin' of integer 'n' #define toOct(oct, n, ch) /*char ch[100]*/ \ sprintf(ch, "%o", n); \ oct = ch; // returns a string 'oct'(maximum 100 length): Octal represent of // number 'n' #define toHex(hex, n, ch) /*char ch[100]*/ \ sprintf(ch, "%x", n); \ hex = ch; // returns a string 'hex'(maximum 100 length): Hexadecimal represent // of number 'n' #define intToString(s, n, itos) /*stringstream itos;*/ \ itos << n; \ s = itos.str(); // converts a number 'n' to a string 's' #define stringToint(n, s) \ stringstream stoi(s); \ stoi >> n; // converts a string 's' to a number 'n'---ONLY ONCE USABLE--- // Others #define substring(s1, s2) \ strstr(s1.c_str(), \ s2.c_str()) // returns true if s1 contains s2 in O(n^2) complexity #define strCharRemove(s, c) \ s.erase(remove(s.begin(), s.end(), c), \ s.end()); // Removes all character 'c' from the string 's' #define strLastCharRemove(s) \ s.erase(s.end() - 1) // Removes last(position is given by s.end()-1) character // form string 's' #define vectorEraseSingle(v, pos) \ v.erase(v.begin() + pos) // Erases an element from "pos' position in zero // based index from the vector 'v' #define vectorEraseRange(v, spos, fpos) \ v.erase(v.begin() + spos, \ v.begin() + fpos) // Erases range inclusive spos' to // EXCLUSIVE(without) 'fpos' from vector 'v' #define lowerBound(v, elem) \ (lower_bound(v.begin(), v.end(), elem)) - \ v.begin(); /*returns the lower bound of 'elem' in integer(ZERO BASED \ INDEX), where lower bound means the LEFTMOST index where there is any integer \ which is GREATER OR EQUAL to 'elem'.*/ #define upperBound(v, elem) \ (upper_bound(v.begin(), v.end(), elem)) - v.begin(); /*returns the upper \ bound of 'elem' in integer(ZERO BASED INDEX), where upper bound means the \ LEFTMOST index where there is any integer which is GREATER than 'elem'.*/ #define setLowerBound(st, elem) \ st.lower_bound(elem); /*returns the lower bound ITERATOR of 'elem' in the \ stl set 'st', where lower bound means the LEFTMOST index where there is any \ integer which is GREATER OR EQUAL to 'elem'.*/ #define setUpperBound(st, elem) \ st.upper_bound(elem); /*returns the upper bound ITERATOR of 'elem' in the \ stl set 'st', where upper bound means the LEFTMOST index where there is any \ integer which is GREATER than 'elem'.*/ #define clearPQ(pq, type) \ pq = priority_queue<type>() /*It clears a priority queue by redeclaration*/ #define minPQ(PQ_name, type) \ priority_queue<type, vector<type>, greater<type>> \ PQ_name; /*min priority queue with built in type i.e int or long long \ etc. */ #define sortArr(arr, sz) \ sort(arr + 1, arr + (sz + 1)); /*Sorts an array from index 1 to index 'sz'*/ /*Macro ends here*/ using namespace std; vector<vector<ll>> v; int main() { // fasterInOut; ll n, m, i; cin >> n >> m; v = vector<vector<ll>>(m + 5); for (i = 1; i <= n; i++) { ll a, b; cin >> a >> b; v[a].pb(b); } ll ans = 0; priority_queue<ll> pq; for (i = 1; i <= m; i++) { ll j; for (j = 0; j < v[i].size(); j++) { pq.push(v[i][j]); } if (!pq.empty()) { ans += pq.top(); pq.pop(); } } cout << ans << "\n"; return 0; }
/***"In the name of Allah(swt), the most gracious, most merciful. Allah(swt) * blesses with knowledge whom he wants."***/ /*Header file starts here*/ // #include<bits/stdc++.h> #include <algorithm> #include <bitset> #include <cctype> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> /*Header file ends here*/ /*Macro starts here*/ #define fasterInOut \ ios::sync_with_stdio(false); \ cin.tie(0); #define fin(in) freopen("in.txt", "r", stdin) #define fout(out) freopen("out.txt", "w", stdout) #define pb push_back #define ll long long #define lld I64d // for CF submissions #define rh cout << "Reached Here\n" #define inf LLONG_MAX #define neginf LLONG_MIN #define forit(it, s) \ for (__typeof((s).end()) it = (s).begin(); it != (s).end(); it++) #define string_reverse(s) \ reverse(s.begin(), s.end()) // Vector also can be reversed with this function #define memz(x) memset(x, 0, sizeof(x)); #define memneg(x) memset(x, -1, sizeof(x)); // Geometry & Maths #define gcd(a, b) __gcd(a, b) #define lcm(a, b) (a * b) / gcd(a, b) #define pi acos(-1.0) #define negmod(ans, x, m) \ ll y = (-1 * x) % m; \ if (y == 0) \ ans = 0; \ else \ ans = m - y; // for negative mod only i.e. when x<0. Undefined when m<0 #define dis(x1, y1, x2, y2) sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) #define t_area(a, b, c, s) \ sqrt(s *(s - a) * (s - b) * (s - c)) // s= (a+b+c)/2.0 #define t_angle(a, b, c) \ acos((a * a + b * b - c * c) / \ (2 * a * b)) // returns angle C in radian. a, b, c are anti-clockwise // formatted and side a and b form angle C #define pointPos(x1, y1, x2, y2, x3, y3) \ ((x2 - x1) * (y3 - y1)) - ((x3 - x1) * (y2 - y1)); /*returns NEGATIVE if the \ Point P3 is on the RIGHT side of the line P1P2, otherwise returns POSITIVE in \ case of LEFT and ZERO when the point is on the line*/ #define t_areaWithPoints(x1, y1, x2, y2, x3, y3) \ abs(0.5 * \ (x1 * (y2 - y3) + x2 * (y3 - y1) + \ x3 * \ (y1 - y2))); // returns the area of a triangle formed by P1, p2, p3 // Base Conversions #define toBin(bin, n) \ bin = bitset<8>(n).to_string() // returns a corresponding 8 bit Binary string // 'bin' of integer 'n' #define toOct(oct, n, ch) /*char ch[100]*/ \ sprintf(ch, "%o", n); \ oct = ch; // returns a string 'oct'(maximum 100 length): Octal represent of // number 'n' #define toHex(hex, n, ch) /*char ch[100]*/ \ sprintf(ch, "%x", n); \ hex = ch; // returns a string 'hex'(maximum 100 length): Hexadecimal represent // of number 'n' #define intToString(s, n, itos) /*stringstream itos;*/ \ itos << n; \ s = itos.str(); // converts a number 'n' to a string 's' #define stringToint(n, s) \ stringstream stoi(s); \ stoi >> n; // converts a string 's' to a number 'n'---ONLY ONCE USABLE--- // Others #define substring(s1, s2) \ strstr(s1.c_str(), \ s2.c_str()) // returns true if s1 contains s2 in O(n^2) complexity #define strCharRemove(s, c) \ s.erase(remove(s.begin(), s.end(), c), \ s.end()); // Removes all character 'c' from the string 's' #define strLastCharRemove(s) \ s.erase(s.end() - 1) // Removes last(position is given by s.end()-1) character // form string 's' #define vectorEraseSingle(v, pos) \ v.erase(v.begin() + pos) // Erases an element from "pos' position in zero // based index from the vector 'v' #define vectorEraseRange(v, spos, fpos) \ v.erase(v.begin() + spos, \ v.begin() + fpos) // Erases range inclusive spos' to // EXCLUSIVE(without) 'fpos' from vector 'v' #define lowerBound(v, elem) \ (lower_bound(v.begin(), v.end(), elem)) - \ v.begin(); /*returns the lower bound of 'elem' in integer(ZERO BASED \ INDEX), where lower bound means the LEFTMOST index where there is any integer \ which is GREATER OR EQUAL to 'elem'.*/ #define upperBound(v, elem) \ (upper_bound(v.begin(), v.end(), elem)) - v.begin(); /*returns the upper \ bound of 'elem' in integer(ZERO BASED INDEX), where upper bound means the \ LEFTMOST index where there is any integer which is GREATER than 'elem'.*/ #define setLowerBound(st, elem) \ st.lower_bound(elem); /*returns the lower bound ITERATOR of 'elem' in the \ stl set 'st', where lower bound means the LEFTMOST index where there is any \ integer which is GREATER OR EQUAL to 'elem'.*/ #define setUpperBound(st, elem) \ st.upper_bound(elem); /*returns the upper bound ITERATOR of 'elem' in the \ stl set 'st', where upper bound means the LEFTMOST index where there is any \ integer which is GREATER than 'elem'.*/ #define clearPQ(pq, type) \ pq = priority_queue<type>() /*It clears a priority queue by redeclaration*/ #define minPQ(PQ_name, type) \ priority_queue<type, vector<type>, greater<type>> \ PQ_name; /*min priority queue with built in type i.e int or long long \ etc. */ #define sortArr(arr, sz) \ sort(arr + 1, arr + (sz + 1)); /*Sorts an array from index 1 to index 'sz'*/ /*Macro ends here*/ using namespace std; vector<vector<ll>> v; int main() { // fasterInOut; ll n, m, i; cin >> n >> m; v = vector<vector<ll>>(m + 5); for (i = 1; i <= n; i++) { ll a, b; cin >> a >> b; if (a > m) continue; v[a].pb(b); } ll ans = 0; priority_queue<ll> pq; for (i = 1; i <= m; i++) { ll j; for (j = 0; j < v[i].size(); j++) { pq.push(v[i][j]); } if (!pq.empty()) { ans += pq.top(); pq.pop(); } } cout << ans << "\n"; return 0; }
insert
147
147
147
149
0
p02948
C++
Runtime Error
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<long long, long long>; constexpr char ln = '\n'; constexpr long long MOD = 1000000007LL; constexpr long long INF = 1001001001LL; constexpr long long LINF = 1001001001001001001; #define all(x) (x).begin(), (x).end() #define rep(i, n) for (int i = 0; i < (n); i++) #define rept(i, j, n) for (int i = (j); i < (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; } int main() { int n, m; cin >> n >> m; vector<vector<int>> P(100100); rep(i, n) { int a, b; cin >> a >> b; P[m - a].push_back(b); // m-a日まで受注可能 } priority_queue<int> que; ll res = 0; for (int i = m; i >= 0; i--) { for (auto p : P[i]) { que.push(p); } if (!que.empty()) { res += que.top(); que.pop(); } } cout << res << ln; }
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<long long, long long>; constexpr char ln = '\n'; constexpr long long MOD = 1000000007LL; constexpr long long INF = 1001001001LL; constexpr long long LINF = 1001001001001001001; #define all(x) (x).begin(), (x).end() #define rep(i, n) for (int i = 0; i < (n); i++) #define rept(i, j, n) for (int i = (j); i < (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; } int main() { int n, m; cin >> n >> m; vector<vector<int>> P(100100); rep(i, n) { int a, b; cin >> a >> b; if (m - a >= 0) P[m - a].push_back(b); // m-a日まで受注可能 } priority_queue<int> que; ll res = 0; for (int i = m; i >= 0; i--) { for (auto p : P[i]) { que.push(p); } if (!que.empty()) { res += que.top(); que.pop(); } } cout << res << ln; }
replace
35
36
35
37
0
p02948
C++
Time Limit Exceeded
#include <bits/stdc++.h> #include <queue> using namespace std; using ll = long long; #define FOR(i, a, b) for (int i = a; i <= b; i++) #define FORD(i, a, b) for (int i = a; i >= b; i--) #define FORL(i, x) for (int i = head[x]; i; i = nxt[i]) #define ALL(a) (a).begin(), (a).end() #define SZ(a) int((a).size()) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define SORT(c) sort((c).begin(), (c).end()) #define PB push_back #define MP make_pair 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; } vector<pair<int, int>> p; vector<pair<int, int>> ans; priority_queue<pair<int, int>> que; int main() { int N, M; scanf("%d%d", &N, &M); FOR(i, 0, N - 1) { int neko, inu; cin >> neko; cin >> inu; inu = 0 - inu; p.PB(MP(neko, inu)); } sort(ALL(p)); int output = 0; int ref = 0; FOR(i, 0, M - 1) { int hold = -1; while (p[ref].first <= i + 1 && ref <= SZ(p) - 1) { que.push(MP((-p[ref].second), p[ref].first)); // cout << 0-p[0].second << " " << p[0].first << endl; p.erase(p.begin()); } if (!que.empty()) { // if(SZ(ans)>=2) sort(ALL(ans),greater<pair<int,int>>()); output += que.top().first; que.pop(); } // cout << output << endl; } cout << output << endl; }
#include <bits/stdc++.h> #include <queue> using namespace std; using ll = long long; #define FOR(i, a, b) for (int i = a; i <= b; i++) #define FORD(i, a, b) for (int i = a; i >= b; i--) #define FORL(i, x) for (int i = head[x]; i; i = nxt[i]) #define ALL(a) (a).begin(), (a).end() #define SZ(a) int((a).size()) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define SORT(c) sort((c).begin(), (c).end()) #define PB push_back #define MP make_pair 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; } vector<pair<int, int>> p; vector<pair<int, int>> ans; priority_queue<pair<int, int>> que; int main() { int N, M; scanf("%d%d", &N, &M); FOR(i, 0, N - 1) { int neko, inu; cin >> neko; cin >> inu; inu = 0 - inu; p.PB(MP(neko, inu)); } sort(ALL(p)); int output = 0; int ref = 0; FOR(i, 0, M - 1) { int hold = -1; while (p[ref].first <= i + 1 && ref <= SZ(p) - 1) { que.push(MP((-p[ref].second), p[ref].first)); // cout << 0-p[0].second << " " << p[0].first << endl; ++ref; } if (!que.empty()) { // if(SZ(ans)>=2) sort(ALL(ans),greater<pair<int,int>>()); output += que.top().first; que.pop(); } // cout << output << endl; } cout << output << endl; }
replace
55
56
55
56
TLE
p02948
C++
Runtime Error
#include "bits/stdc++.h" #include "math.h" using namespace std; typedef long long ll; typedef vector<ll> vll; typedef vector<vll> vvll; typedef vector<bool> vb; typedef vector<vb> vvb; typedef vector<int> vin; typedef pair<ll, ll> P; typedef vector<P> vp; #define rep(i, a, b) for (ll i = (a); i < (b); ++i) #define drep(i, a, b) for (ll i = (a); i >= (b); --i) #define SIZE(a) int((a).size()) #define out(a) cout << (a) << endl; const int INF = INT_MAX; const int MAX = 510000; const ll MOD = 1000000007; ll roundd(ll x, ll n) { if (x > n) { return x % n; } else if (x < 0) { return x % n + n; } else return x; } int main() { ll n, m; cin >> n >> m; priority_queue<ll> q; vvll ok(m + 1); rep(i, 0, n) { ll a, b; cin >> a >> b; ok[a].push_back(b); } ll ans = 0; rep(i, 1, m + 1) { for (auto u : ok[i]) q.push(u); if (!q.empty()) { ll t = q.top(); ans += t; q.pop(); } } cout << ans << endl; }
#include "bits/stdc++.h" #include "math.h" using namespace std; typedef long long ll; typedef vector<ll> vll; typedef vector<vll> vvll; typedef vector<bool> vb; typedef vector<vb> vvb; typedef vector<int> vin; typedef pair<ll, ll> P; typedef vector<P> vp; #define rep(i, a, b) for (ll i = (a); i < (b); ++i) #define drep(i, a, b) for (ll i = (a); i >= (b); --i) #define SIZE(a) int((a).size()) #define out(a) cout << (a) << endl; const int INF = INT_MAX; const int MAX = 510000; const ll MOD = 1000000007; ll roundd(ll x, ll n) { if (x > n) { return x % n; } else if (x < 0) { return x % n + n; } else return x; } int main() { ll n, m; cin >> n >> m; priority_queue<ll> q; vvll ok(100001); rep(i, 0, n) { ll a, b; cin >> a >> b; ok[a].push_back(b); } ll ans = 0; rep(i, 1, m + 1) { for (auto u : ok[i]) q.push(u); if (!q.empty()) { ll t = q.top(); ans += t; q.pop(); } } cout << ans << endl; }
replace
32
33
32
33
0
p02948
C++
Time Limit Exceeded
#include <algorithm> #include <cstdio> #include <cstring> #include <set> using namespace std; struct jb { int a, b; friend bool operator<(jb x, jb y) { return x.a > y.a; }; } g[100010]; int n, m, k, l, ans = 0, f[100010]; set<int> s; _Rb_tree_const_iterator<int> p; int mx(int x, int y) { return x > y ? x : y; } int mn(int x, int y) { return x < y ? x : y; } void read(int &x) { char c; x = 0; while (c > '9' || c < '0') c = getchar(); while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); } } int main() { // freopen("ted.in","r",stdin); read(n); read(m); for (int i = 0; i < n; i++) { read(g[i].b); read(g[i].a); } sort(g, g + n); for (int i = 0; i <= m; i++) s.insert(i); for (int i = 0; i < n; i++) { g[i].b = m - g[i].b; p = lower_bound(s.begin(), s.end(), g[i].b); if (p != s.begin() && (*p) > g[i].b) p--; if ((*p) <= g[i].b) { ans += g[i].a; s.erase(*p); } } printf("%d\n", ans); return 0; }
#include <algorithm> #include <cstdio> #include <cstring> #include <set> using namespace std; struct jb { int a, b; friend bool operator<(jb x, jb y) { return x.a > y.a; }; } g[100010]; int n, m, k, l, ans = 0, f[100010]; set<int> s; _Rb_tree_const_iterator<int> p; int mx(int x, int y) { return x > y ? x : y; } int mn(int x, int y) { return x < y ? x : y; } void read(int &x) { char c; x = 0; while (c > '9' || c < '0') c = getchar(); while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); } } int main() { // freopen("ted.in","r",stdin); read(n); read(m); for (int i = 0; i < n; i++) { read(g[i].b); read(g[i].a); } sort(g, g + n); for (int i = 0; i <= m; i++) s.insert(i); for (int i = 0; i < n; i++) { g[i].b = m - g[i].b; p = s.lower_bound(g[i].b); if (p != s.begin() && (*p) > g[i].b) p--; if ((*p) <= g[i].b) { ans += g[i].a; s.erase(*p); } } printf("%d\n", ans); return 0; }
replace
37
38
37
38
TLE
p02948
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) int main() { int N, M; cin >> N >> M; vector<pair<int, int>> A(N); rep(i, N) { cin >> A[i].first; cin >> A[i].second; } sort(A.begin(), A.end()); long long ans = 0; int j = 0; priority_queue<int> B; rep(i, M) { while (A[j].first <= i + 1 && j < N) { B.push(A[j].second); j++; } if (j != 0) { ans += B.top(); B.pop(); } } cout << ans; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) int main() { int N, M; cin >> N >> M; vector<pair<int, int>> A(N); rep(i, N) { cin >> A[i].first; cin >> A[i].second; } sort(A.begin(), A.end()); long long ans = 0; int j = 0; priority_queue<int> B; rep(i, M) { while (A[j].first <= i + 1 && j < N) { B.push(A[j].second); j++; } if (!B.empty()) { ans += B.top(); B.pop(); } } cout << ans; }
replace
23
24
23
24
-6
double free or corruption (out)
p02948
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; #define REP(i, a) for (int i = 0; i < (a); i++) #define ALL(a) (a).begin(), (a).end() typedef long long ll; typedef pair<int, int> P; const int INF = 1e9; const int MOD = 1e9 + 7; using Graph = vector<vector<int>>; /*第二引数で第一引数を割ったときの切り上げの計算*/ 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; } int main() { int N, M; cin >> N >> M; vector<vector<int>> s(10020); long long int sum = 0; priority_queue<int> q; for (int i = 0; i < N; i++) { int a, b; cin >> a >> b; if (a > M) { continue; } s[a].push_back(b); } for (int i = 1; i <= M; i++) { int max = 0; for (int j = 0; j < s[i].size(); j++) { if (s[i][j] > max) { q.push(max); max = s[i][j]; } else { q.push(s[i][j]); } } if (!q.empty()) { if (q.top() > max) { q.push(max); max = q.top(); q.pop(); } } sum = max + sum; } cout << sum; }
#include "bits/stdc++.h" using namespace std; #define REP(i, a) for (int i = 0; i < (a); i++) #define ALL(a) (a).begin(), (a).end() typedef long long ll; typedef pair<int, int> P; const int INF = 1e9; const int MOD = 1e9 + 7; using Graph = vector<vector<int>>; /*第二引数で第一引数を割ったときの切り上げの計算*/ 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; } int main() { int N, M; cin >> N >> M; vector<vector<int>> s(100020); long long int sum = 0; priority_queue<int> q; for (int i = 0; i < N; i++) { int a, b; cin >> a >> b; if (a > M) { continue; } s[a].push_back(b); } for (int i = 1; i <= M; i++) { int max = 0; for (int j = 0; j < s[i].size(); j++) { if (s[i][j] > max) { q.push(max); max = s[i][j]; } else { q.push(s[i][j]); } } if (!q.empty()) { if (q.top() > max) { q.push(max); max = q.top(); q.pop(); } } sum = max + sum; } cout << sum; }
replace
40
41
40
41
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<pair<int, int>> w(n); for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; w.at(i) = make_pair(a, b); } sort(w.begin(), w.end()); int index = 0; priority_queue<int> q; int ans = 0; for (int i = 1; i <= m; i++) { while (index < n && w.at(index).first <= i) q.push(w.at(index++).second); ans += q.top(); q.pop(); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<pair<int, int>> w(n); for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; w.at(i) = make_pair(a, b); } sort(w.begin(), w.end()); int index = 0; priority_queue<int> q; int ans = 0; for (int i = 1; i <= m; i++) { while (index < n && w.at(index).first <= i) q.push(w.at(index++).second); if (q.empty()) continue; ans += q.top(); q.pop(); } cout << ans << endl; }
insert
22
22
22
24
-11
p02948
C++
Runtime Error
/**Bismillahir Rahmanir Rahim.**/ #include <bits/stdc++.h> using namespace std; #define ln '\n' #define pf printf #define sf scanf #define inp(x) scanf("%lld", &x) #define D(x) cout << #x " = " << x << endl #define dbg(x) cerr << #x << " = " << x << endl; #define dbg2(x, y) cerr << #x << " = " << x << ", " << #y << " = " << y << endl; #define f0(i, b) for (int i = 0; i < (b); i++) #define f1(i, b) for (int i = 1; i <= (b); i++) #define f(a, b) for (int i = a; i <= (b); i++) #define _case cout << "Case " << ++cs << ": " #define MOD 1000000007 #define countv(v, a) count(v.begin(), v.end(), a) #define grtsrt(v) sort(v.begin(), v.end(), greater<int>()) #define mnv(v) *min_element(v.begin(), v.end()) #define mxv(v) *max_element(v.begin(), v.end()) #define uniq(v) v.resize(unique(all(v)) - v.begin()) #define PI acos(-1) #define ll long long int #define ull unsigned long long typedef pair<int, int> pii; typedef pair<double, double> pdd; typedef pair<ll, ll> pll; #define vi vector<int> #define vll vector<ll> #define vs vector<string> #define pb push_back #define eb emplace_back #define mpii map<int, int> #define mpsi map<string, int> #define mpll map<long long, long long> #define MP make_pair #define F first #define S second #define B begin() #define E end() #define sz size() #define GCD(a, b) __gcd(a, b) #define LCM(a, b) (a * (b / __gcd(a, b))) // #define harmonic(n) 0.57721566490153286l+log(n) #define rev(v) reverse(v.begin(), v.end()) #define srt(v) sort(v.begin(), v.end()) #define all(v) v.begin(), v.end() #define MEM(a, b) memset(a, b, sizeof(a)) #define fast ios_base::sync_with_stdio(false) /* #include <ext/pb_ds/assoc_container.hpp> // Common file #include <ext/pb_ds/tree_policy.hpp> // Including */ // using namespace __gnu_pbds; /* template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template<typename F, typename S> using ordered_map = tree<F, S, less<F>, rb_tree_tag, tree_order_statistics_node_update>; */ /// Inline functions inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; } inline bool isLeapYear(ll year) { return (year % 400 == 0) | (year % 4 == 0 && year % 100 != 0); } inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); } inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a * b) % MOD; } inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a + b) % MOD; } inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; } inline ll modPow(ll b, ll p) { ll r = 1; while (p) { if (p & 1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; } inline ll modInverse(ll a) { return modPow(a, MOD - 2); } inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); } inline bool isInside(pii p, ll n, ll m) { return (p.first >= 0 && p.first < n && p.second >= 0 && p.second < m); } inline bool isInside(pii p, ll n) { return (p.first >= 0 && p.first < n && p.second >= 0 && p.second < n); } inline bool isSquare(ll x) { ll s = sqrt(x); return (s * s == x); } inline bool isFib(ll x) { return isSquare(5 * x * x + 4) || isSquare(5 * x * x - 4); } inline bool isPowerOfTwo(ll x) { return ((1LL << (ll)log2(x)) == x); } struct func { // this is a sample overloading function for sorting stl bool operator()(pii const &a, pii const &b) { if (a.F == b.F) return (a.S < b.S); return (a.F < b.F); } }; const ll INF = 0x3f3f3f3f3f3f3f3f; const long double EPS = 1e-9; const int inf = 0x3f3f3f3f; const int mx = (int)1e5 + 9; /// count set bit C = (num * 0x200040008001ULL & 0x111111111111111ULL) % 0xf; /// /// 32 bit integer /*------------------------------Graph Moves----------------------------*/ // Rotation: S -> E -> N -> W // const int fx[] = {0, +1, 0, -1}; // const int fy[] = {-1, 0, +1, 0}; // const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1}; // Kings Move // const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1}; // Kings Move // const int fx[]={-2, -2, -1, -1, 1, 1, 2, 2}; // Knights Move // const int fy[]={-1, 1, -2, 2, -2, 2, -1, 1}; // Knights Move /*---------------------------------------------------------------------*/ /// Bit Operations /// inline bool checkBit(ll n, int i) { return n&(1LL<<i); } /// inline ll setBit(ll n, int i) { return n|(1LL<<i); } /// inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); } struct Point { ll s, p, x, y; string name; /// Point() {} /// Point(double x,double y) : x(x), y(y) {} bool operator<( const Point &ob) const /// decreasing sort as same as compare function { return s == ob.s ? p < ob.p : s > ob.s; } }; double distance(Point a, Point b) { return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); } /// ************************************** Code starts here /// ****************************************** */ string s, s1; ll n, m, a, b, i, j, d, t, cs = 0, counT = 0, k, l = 0, sum1 = 0, sum = 0, Max, Min, num; vector<ll> vc; map<ll, ll> mp; int main() { cin >> n >> k; priority_queue<ll> PQ[n + 1], res; f1(i, n) { cin >> a >> b; if (a <= k) PQ[a].push(b); } f1(i, k) { while (!PQ[i].empty()) { int x = PQ[i].top(); PQ[i].pop(); res.push(x); } if (!res.empty()) { sum += res.top(); res.pop(); } // D(i);D(sum); } cout << sum << ln; }
/**Bismillahir Rahmanir Rahim.**/ #include <bits/stdc++.h> using namespace std; #define ln '\n' #define pf printf #define sf scanf #define inp(x) scanf("%lld", &x) #define D(x) cout << #x " = " << x << endl #define dbg(x) cerr << #x << " = " << x << endl; #define dbg2(x, y) cerr << #x << " = " << x << ", " << #y << " = " << y << endl; #define f0(i, b) for (int i = 0; i < (b); i++) #define f1(i, b) for (int i = 1; i <= (b); i++) #define f(a, b) for (int i = a; i <= (b); i++) #define _case cout << "Case " << ++cs << ": " #define MOD 1000000007 #define countv(v, a) count(v.begin(), v.end(), a) #define grtsrt(v) sort(v.begin(), v.end(), greater<int>()) #define mnv(v) *min_element(v.begin(), v.end()) #define mxv(v) *max_element(v.begin(), v.end()) #define uniq(v) v.resize(unique(all(v)) - v.begin()) #define PI acos(-1) #define ll long long int #define ull unsigned long long typedef pair<int, int> pii; typedef pair<double, double> pdd; typedef pair<ll, ll> pll; #define vi vector<int> #define vll vector<ll> #define vs vector<string> #define pb push_back #define eb emplace_back #define mpii map<int, int> #define mpsi map<string, int> #define mpll map<long long, long long> #define MP make_pair #define F first #define S second #define B begin() #define E end() #define sz size() #define GCD(a, b) __gcd(a, b) #define LCM(a, b) (a * (b / __gcd(a, b))) // #define harmonic(n) 0.57721566490153286l+log(n) #define rev(v) reverse(v.begin(), v.end()) #define srt(v) sort(v.begin(), v.end()) #define all(v) v.begin(), v.end() #define MEM(a, b) memset(a, b, sizeof(a)) #define fast ios_base::sync_with_stdio(false) /* #include <ext/pb_ds/assoc_container.hpp> // Common file #include <ext/pb_ds/tree_policy.hpp> // Including */ // using namespace __gnu_pbds; /* template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template<typename F, typename S> using ordered_map = tree<F, S, less<F>, rb_tree_tag, tree_order_statistics_node_update>; */ /// Inline functions inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; } inline bool isLeapYear(ll year) { return (year % 400 == 0) | (year % 4 == 0 && year % 100 != 0); } inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); } inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a * b) % MOD; } inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a + b) % MOD; } inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; } inline ll modPow(ll b, ll p) { ll r = 1; while (p) { if (p & 1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; } inline ll modInverse(ll a) { return modPow(a, MOD - 2); } inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); } inline bool isInside(pii p, ll n, ll m) { return (p.first >= 0 && p.first < n && p.second >= 0 && p.second < m); } inline bool isInside(pii p, ll n) { return (p.first >= 0 && p.first < n && p.second >= 0 && p.second < n); } inline bool isSquare(ll x) { ll s = sqrt(x); return (s * s == x); } inline bool isFib(ll x) { return isSquare(5 * x * x + 4) || isSquare(5 * x * x - 4); } inline bool isPowerOfTwo(ll x) { return ((1LL << (ll)log2(x)) == x); } struct func { // this is a sample overloading function for sorting stl bool operator()(pii const &a, pii const &b) { if (a.F == b.F) return (a.S < b.S); return (a.F < b.F); } }; const ll INF = 0x3f3f3f3f3f3f3f3f; const long double EPS = 1e-9; const int inf = 0x3f3f3f3f; const int mx = (int)1e5 + 9; /// count set bit C = (num * 0x200040008001ULL & 0x111111111111111ULL) % 0xf; /// /// 32 bit integer /*------------------------------Graph Moves----------------------------*/ // Rotation: S -> E -> N -> W // const int fx[] = {0, +1, 0, -1}; // const int fy[] = {-1, 0, +1, 0}; // const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1}; // Kings Move // const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1}; // Kings Move // const int fx[]={-2, -2, -1, -1, 1, 1, 2, 2}; // Knights Move // const int fy[]={-1, 1, -2, 2, -2, 2, -1, 1}; // Knights Move /*---------------------------------------------------------------------*/ /// Bit Operations /// inline bool checkBit(ll n, int i) { return n&(1LL<<i); } /// inline ll setBit(ll n, int i) { return n|(1LL<<i); } /// inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); } struct Point { ll s, p, x, y; string name; /// Point() {} /// Point(double x,double y) : x(x), y(y) {} bool operator<( const Point &ob) const /// decreasing sort as same as compare function { return s == ob.s ? p < ob.p : s > ob.s; } }; double distance(Point a, Point b) { return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); } /// ************************************** Code starts here /// ****************************************** */ string s, s1; ll n, m, a, b, i, j, d, t, cs = 0, counT = 0, k, l = 0, sum1 = 0, sum = 0, Max, Min, num; vector<ll> vc; map<ll, ll> mp; int main() { cin >> n >> k; priority_queue<ll> PQ[k + 1], res; f1(i, n) { cin >> a >> b; if (a <= k) PQ[a].push(b); } f1(i, k) { while (!PQ[i].empty()) { int x = PQ[i].top(); PQ[i].pop(); res.push(x); } if (!res.empty()) { sum += res.top(); res.pop(); } // D(i);D(sum); } cout << sum << ln; }
replace
177
178
177
178
-11
p02948
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = 1e9; const ll mod = 1e9 + 7; typedef pair<int, int> P; typedef pair<pair<int, int>, pair<int, int>> PP; #define rep(i, N) for (int i = 0; i < N; i++) int main() { int n, m; cin >> n >> m; int a[n], b[n]; vector<P> p(n); priority_queue<int> pq; rep(i, n) { cin >> a[i] >> b[i]; // p[i]=make_pair(a[i],b[i]); p[i] = make_pair(a[i], b[i]); } sort(p.begin(), p.end()); int now = 1; ll ans = 0; int c = 0; for (int i = 1; i <= m; i++) { // cout<<i<<endl; while (i == p[0].first) { pq.push(p[0].second); p.erase(p.begin()); if (p.empty()) break; } if (pq.empty()) continue; ans += pq.top(); pq.pop(); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = 1e9; const ll mod = 1e9 + 7; typedef pair<int, int> P; typedef pair<pair<int, int>, pair<int, int>> PP; #define rep(i, N) for (int i = 0; i < N; i++) int main() { int n, m; cin >> n >> m; int a[n], b[n]; vector<P> p(n); priority_queue<int> pq; rep(i, n) { cin >> a[i] >> b[i]; // p[i]=make_pair(a[i],b[i]); p[i] = make_pair(a[i], b[i]); } sort(p.begin(), p.end()); int now = 1; ll ans = 0; int c = 0; for (int i = 1; i <= m; i++) { // cout<<i<<endl; while (i == p[c].first) { pq.push(p[c].second); c++; // p.erase(p.begin()); // if(p.empty())break; } if (pq.empty()) continue; ans += pq.top(); pq.pop(); } cout << ans << endl; }
replace
26
31
26
31
TLE
p02948
C++
Runtime Error
#include <iostream> #include <queue> using namespace std; priority_queue<int> q; vector<vector<int>> jobs; int main(void) { int n, m; cin >> n >> m; jobs = vector<vector<int>>(m + 1); for (int a = 0; a < n; a = a + 1) { int ai, bi; cin >> ai >> bi; jobs[ai].push_back(bi); } int ans = 0; for (int a = 1; a <= m; a = a + 1) { for (auto day : jobs[a]) q.push(day); if (!q.empty()) { ans += q.top(); q.pop(); } } cout << ans; return 0; }
#include <iostream> #include <queue> using namespace std; priority_queue<int> q; vector<vector<int>> jobs; int main(void) { int n, m; cin >> n >> m; jobs = vector<vector<int>>(100001); for (int a = 0; a < n; a = a + 1) { int ai, bi; cin >> ai >> bi; jobs[ai].push_back(bi); } int ans = 0; for (int a = 1; a <= m; a = a + 1) { for (auto day : jobs[a]) q.push(day); if (!q.empty()) { ans += q.top(); q.pop(); } } cout << ans; return 0; }
replace
12
13
12
13
0
p02948
C++
Runtime Error
/* Warn - Don't change next line else you will get WA verdict. Online Judge is configured to give WA if next line is not present. "An ideal problem has no test data." Author - Aryan Choudhary (@aryanc403) */ #pragma warning(disable : 4996) #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma GCC optimize("-ffloat-store") #include <bits/stdc++.h> #include <iostream> #include <stdio.h> using namespace std; #define fo(i, n) for (i = 0; i < (n); ++i) #define repA(i, j, n) for (i = (j); i <= (n); ++i) #define repD(i, j, n) for (i = (j); i >= (n); --i) #define pb push_back #define mp make_pair #define X first #define Y second #define endl "\n" typedef long long int lli; typedef long double mytype; typedef pair<lli, lli> ii; typedef vector<ii> vii; typedef vector<lli> vi; clock_t time_p = clock(); void aryanc403() { time_p = clock() - time_p; cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n"; } #ifdef ARYANC403 #define dbg(...) \ { \ cerr << "[ "; \ __aryanc403__(#__VA_ARGS__, __VA_ARGS__); \ } #undef endl template <typename Arg1, typename Arg2> ostream &operator<<(ostream &out, const pair<Arg1, Arg2> &x) { return out << "(" << x.X << "," << x.Y << ")"; } template <typename Arg1> ostream &operator<<(ostream &out, const vector<Arg1> &a) { out << "["; for (const auto &x : a) out << x << ","; return out << "]"; } template <typename Arg1> ostream &operator<<(ostream &out, const set<Arg1> &a) { out << "["; for (const auto &x : a) out << x << ","; return out << "]"; } template <typename Arg1, typename Arg2> ostream &operator<<(ostream &out, const map<Arg1, Arg2> &a) { out << "["; for (const auto &x : a) out << x << ","; return out << "]"; } template <typename Arg1> void __aryanc403__(const string name, Arg1 &&arg1) { cerr << name << " : " << arg1 << " ] " << endl; } template <typename Arg1, typename... Args> void __aryanc403__(const string names, Arg1 &&arg1, Args &&...args) { const string name = names.substr(0, names.find(',')); cerr << name << " : " << arg1 << " | "; __aryanc403__(names.substr(1 + (int)name.size()), args...); } #else #define dbg(args...) #endif const lli INF = 0xFFFFFFFFFFFFFFFL; lli seed; mt19937 rng(seed = chrono::steady_clock::now().time_since_epoch().count()); inline lli rnd(lli l = 0, lli r = INF) { return uniform_int_distribution<lli>(l, r)(rng); } class CMP { public: bool operator()(ii a, ii b) // For min priority_queue . { return !(a.X < b.X || a.X == b.X && a.Y <= b.Y); } }; void add(map<lli, lli> &m, lli x, lli cnt = 1) { auto jt = m.find(x); if (jt == m.end()) m.insert({x, cnt}); else jt->Y += cnt; } void del(map<lli, lli> &m, lli x, lli cnt = 1) { auto jt = m.find(x); if (jt->Y <= cnt) m.erase(jt); else jt->Y -= cnt; } bool cmp(const ii &a, const ii &b) { return a.X > b.X || (a.X == b.X && a.Y > b.Y); } const lli mod = 1000000007L; lli T, n, i, j, k, in, cnt, l, r, u, v, x, y; lli m; vii a; set<lli> s; // priority_queue < ii , vector < ii > , CMP > pq;// min priority_queue . int main(void) { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // freopen("txt.in", "r", stdin); // freopen("txt.out", "w", stdout); // cout<<std::fixed<<std::setprecision(35); // cin>>T;while(T--) { cin >> n >> m; a.clear(); a.reserve(n); fo(i, n) { cin >> k >> in; a.pb({in, m - k}); } repA(i, -1, m + 1) s.insert(i); sort(a.begin(), a.end(), cmp); dbg(a); lli ans = 0; for (auto x : a) { auto it = s.upper_bound(x.Y); --it; if (*it == -1) continue; ans += x.X; s.erase(it); } cout << ans << endl; } aryanc403(); return 0; }
/* Warn - Don't change next line else you will get WA verdict. Online Judge is configured to give WA if next line is not present. "An ideal problem has no test data." Author - Aryan Choudhary (@aryanc403) */ #pragma warning(disable : 4996) #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma GCC optimize("-ffloat-store") #include <bits/stdc++.h> #include <iostream> #include <stdio.h> using namespace std; #define fo(i, n) for (i = 0; i < (n); ++i) #define repA(i, j, n) for (i = (j); i <= (n); ++i) #define repD(i, j, n) for (i = (j); i >= (n); --i) #define pb push_back #define mp make_pair #define X first #define Y second #define endl "\n" typedef long long int lli; typedef long double mytype; typedef pair<lli, lli> ii; typedef vector<ii> vii; typedef vector<lli> vi; clock_t time_p = clock(); void aryanc403() { time_p = clock() - time_p; cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n"; } #ifdef ARYANC403 #define dbg(...) \ { \ cerr << "[ "; \ __aryanc403__(#__VA_ARGS__, __VA_ARGS__); \ } #undef endl template <typename Arg1, typename Arg2> ostream &operator<<(ostream &out, const pair<Arg1, Arg2> &x) { return out << "(" << x.X << "," << x.Y << ")"; } template <typename Arg1> ostream &operator<<(ostream &out, const vector<Arg1> &a) { out << "["; for (const auto &x : a) out << x << ","; return out << "]"; } template <typename Arg1> ostream &operator<<(ostream &out, const set<Arg1> &a) { out << "["; for (const auto &x : a) out << x << ","; return out << "]"; } template <typename Arg1, typename Arg2> ostream &operator<<(ostream &out, const map<Arg1, Arg2> &a) { out << "["; for (const auto &x : a) out << x << ","; return out << "]"; } template <typename Arg1> void __aryanc403__(const string name, Arg1 &&arg1) { cerr << name << " : " << arg1 << " ] " << endl; } template <typename Arg1, typename... Args> void __aryanc403__(const string names, Arg1 &&arg1, Args &&...args) { const string name = names.substr(0, names.find(',')); cerr << name << " : " << arg1 << " | "; __aryanc403__(names.substr(1 + (int)name.size()), args...); } #else #define dbg(args...) #endif const lli INF = 0xFFFFFFFFFFFFFFFL; lli seed; mt19937 rng(seed = chrono::steady_clock::now().time_since_epoch().count()); inline lli rnd(lli l = 0, lli r = INF) { return uniform_int_distribution<lli>(l, r)(rng); } class CMP { public: bool operator()(ii a, ii b) // For min priority_queue . { return !(a.X < b.X || a.X == b.X && a.Y <= b.Y); } }; void add(map<lli, lli> &m, lli x, lli cnt = 1) { auto jt = m.find(x); if (jt == m.end()) m.insert({x, cnt}); else jt->Y += cnt; } void del(map<lli, lli> &m, lli x, lli cnt = 1) { auto jt = m.find(x); if (jt->Y <= cnt) m.erase(jt); else jt->Y -= cnt; } bool cmp(const ii &a, const ii &b) { return a.X > b.X || (a.X == b.X && a.Y > b.Y); } const lli mod = 1000000007L; lli T, n, i, j, k, in, cnt, l, r, u, v, x, y; lli m; vii a; set<lli> s; // priority_queue < ii , vector < ii > , CMP > pq;// min priority_queue . int main(void) { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // freopen("txt.in", "r", stdin); // freopen("txt.out", "w", stdout); // cout<<std::fixed<<std::setprecision(35); // cin>>T;while(T--) { cin >> n >> m; a.clear(); a.reserve(n); fo(i, n) { cin >> k >> in; if (m - k < 0) continue; a.pb({in, m - k}); } repA(i, -1, m + 1) s.insert(i); sort(a.begin(), a.end(), cmp); dbg(a); lli ans = 0; for (auto x : a) { auto it = s.upper_bound(x.Y); --it; if (*it == -1) continue; ans += x.X; s.erase(it); } cout << ans << endl; } aryanc403(); return 0; }
insert
146
146
146
148
0
Time Taken : 0.000136
p02948
C++
Runtime Error
/*やったぜ。 投稿者:変態糞土方 (8月16日(水)07時14分22秒) 昨日の8月15日にいつもの浮浪者のおっさん(60歳)と先日メールくれた汚れ好きの土方のにいちゃん (45歳)とわし(53歳)の3人で県北にある川の土手の下で盛りあったぜ。 今日は明日が休みなんでコンビニで酒とつまみを買ってから滅多に人が来ない所なんで、 そこでしこたま酒を飲んでからやりはじめたんや。 3人でちんぽ舐めあいながら地下足袋だけになり持って来たいちぢく浣腸を3本ずつ入れあった。 しばらくしたら、けつの穴がひくひくして来るし、糞が出口を求めて腹の中でぐるぐるしている。 浮浪者のおっさんにけつの穴をなめさせながら、兄ちゃんのけつの穴を舐めてたら、 先に兄ちゃんがわしの口に糞をドバーっと出して来た。 それと同時におっさんもわしも糞を出したんや。もう顔中、糞まみれや、 3人で出した糞を手で掬いながらお互いの体にぬりあったり、 糞まみれのちんぽを舐めあって小便で浣腸したりした。ああ~~たまらねえぜ。 しばらくやりまくってから又浣腸をしあうともう気が狂う程気持ちええんじゃ。 浮浪者のおっさんのけつの穴にわしのちんぽを突うずるっ込んでやると けつの穴が糞と小便でずるずるして気持ちが良い。 にいちゃんもおっさんの口にちんぽ突っ込んで腰をつかって居る。 糞まみれのおっさんのちんぽを掻きながら、思い切り射精したんや。 それからは、もうめちゃくちゃにおっさんと兄ちゃんの糞ちんぽを舐めあい、 糞を塗りあい、二回も男汁を出した。もう一度やりたいぜ。 やはり大勢で糞まみれになると最高やで。こんな、変態親父と糞あそびしないか。 ああ~~早く糞まみれになろうぜ。 岡山の県北であえる奴なら最高や。わしは163*90*53,おっさんは165*75*60、や 糞まみれでやりたいやつ、至急、メールくれや。 土方姿のまま浣腸して、糞だらけでやろうや。*/ #include "bits/stdc++.h" #include <numeric> #define rep(i, n) for (ll i = 0; i < n; i++) typedef long long ll; typedef unsigned long long ull; using namespace std; #define llMAX numeric_limits<long long>::max() #define intMAX numeric_limits<int>::max() #define llMIN numeric_limits<long long>::min() #define intMIN numeric_limits<int>::min() #define d_5 100000 #define d9_7 1000000007 #define vll vector<vector<long long>> #define vl vector<long long> #define vi vector<int> #define vii vector<vector<int>> #define pb push_back #define pf push_front #define ld long double #define Sort(a) sort(a.begin(), a.end()) #define reSort(a) sort(a.rbegin(), a.rend()) ll digitpower(ll a, ll b) { // aのb乗を計算 if (b == 1) { return a; } else if (b == 0) { return 1; } if (b % 2 == 1) { ll tmp = digitpower(a, (b - 1) / 2); tmp %= d9_7; tmp *= tmp; tmp %= d9_7; tmp *= a; return (tmp) % d9_7; } else { ll tmp = digitpower(a, (b) / 2); tmp %= d9_7; tmp *= tmp; tmp %= d9_7; return (tmp) % d9_7; } } // 階乗 vl facs(1000000, -1); ll Factrial(ll num) { if (facs[num] != -1) { return facs[num]; } if (num == 1 || num <= 0) { return 1; } else if (num < 0) { printf("ERROR_minus\n"); return 0; } else { facs[num] = (num * Factrial(num - 1)) % d9_7; return facs[num]; } } long long modinv(long long a, long long m) { // modの逆元 long long b = m, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } ll linercomb(ll n, ll k, ll mod) { // n,kの線形時間で求める ll ans = Factrial(n); ans *= modinv(Factrial(k), mod); ans %= d9_7; ll k1 = Factrial(k); k1 %= mod; ans *= modinv(k1, mod); ans %= mod; return ans; } int LIS(vector<int> x) { int n = x.size(); vector<int> dp(n, intMAX); dp[0] = x[0]; int length = 1; rep(i, n - 1) { if (dp[length - 1] < x[i + 1]) { dp[length] = x[i + 1]; length++; continue; } *lower_bound(dp.begin(), dp.end(), x[i + 1]) = x[i + 1]; } int ans; rep(i, n) { if (dp[i + 1] == intMAX) { ans = i; break; } if (i == n - 1) { ans = dp[n - 1]; } } return ans; } struct datas { ll a; ll b; }; bool cmp(const datas &a, const datas &b) { return a.b < b.b; } int main(void) { ll n, m; cin >> n >> m; vector<datas> work(n); rep(i, n) { cin >> work[i].a >> work[i].b; } sort(work.rbegin(), work.rend(), cmp); vl sch(m + 1, -1); int rmax = m; int flag = 0; set<int> schs; rep(i, m + 1) { schs.insert(i); } rep(i, n) { if (schs.upper_bound(m - work[i].a) != schs.begin()) { auto itr = schs.lower_bound(m - work[i].a)--; sch[*itr] = work[i].b; schs.erase(itr); } } ll ans = 0; rep(i, m + 1) { if (sch[i] != -1) { ans += sch[i]; } } cout << ans << endl; return 0; }
/*やったぜ。 投稿者:変態糞土方 (8月16日(水)07時14分22秒) 昨日の8月15日にいつもの浮浪者のおっさん(60歳)と先日メールくれた汚れ好きの土方のにいちゃん (45歳)とわし(53歳)の3人で県北にある川の土手の下で盛りあったぜ。 今日は明日が休みなんでコンビニで酒とつまみを買ってから滅多に人が来ない所なんで、 そこでしこたま酒を飲んでからやりはじめたんや。 3人でちんぽ舐めあいながら地下足袋だけになり持って来たいちぢく浣腸を3本ずつ入れあった。 しばらくしたら、けつの穴がひくひくして来るし、糞が出口を求めて腹の中でぐるぐるしている。 浮浪者のおっさんにけつの穴をなめさせながら、兄ちゃんのけつの穴を舐めてたら、 先に兄ちゃんがわしの口に糞をドバーっと出して来た。 それと同時におっさんもわしも糞を出したんや。もう顔中、糞まみれや、 3人で出した糞を手で掬いながらお互いの体にぬりあったり、 糞まみれのちんぽを舐めあって小便で浣腸したりした。ああ~~たまらねえぜ。 しばらくやりまくってから又浣腸をしあうともう気が狂う程気持ちええんじゃ。 浮浪者のおっさんのけつの穴にわしのちんぽを突うずるっ込んでやると けつの穴が糞と小便でずるずるして気持ちが良い。 にいちゃんもおっさんの口にちんぽ突っ込んで腰をつかって居る。 糞まみれのおっさんのちんぽを掻きながら、思い切り射精したんや。 それからは、もうめちゃくちゃにおっさんと兄ちゃんの糞ちんぽを舐めあい、 糞を塗りあい、二回も男汁を出した。もう一度やりたいぜ。 やはり大勢で糞まみれになると最高やで。こんな、変態親父と糞あそびしないか。 ああ~~早く糞まみれになろうぜ。 岡山の県北であえる奴なら最高や。わしは163*90*53,おっさんは165*75*60、や 糞まみれでやりたいやつ、至急、メールくれや。 土方姿のまま浣腸して、糞だらけでやろうや。*/ #include "bits/stdc++.h" #include <numeric> #define rep(i, n) for (ll i = 0; i < n; i++) typedef long long ll; typedef unsigned long long ull; using namespace std; #define llMAX numeric_limits<long long>::max() #define intMAX numeric_limits<int>::max() #define llMIN numeric_limits<long long>::min() #define intMIN numeric_limits<int>::min() #define d_5 100000 #define d9_7 1000000007 #define vll vector<vector<long long>> #define vl vector<long long> #define vi vector<int> #define vii vector<vector<int>> #define pb push_back #define pf push_front #define ld long double #define Sort(a) sort(a.begin(), a.end()) #define reSort(a) sort(a.rbegin(), a.rend()) ll digitpower(ll a, ll b) { // aのb乗を計算 if (b == 1) { return a; } else if (b == 0) { return 1; } if (b % 2 == 1) { ll tmp = digitpower(a, (b - 1) / 2); tmp %= d9_7; tmp *= tmp; tmp %= d9_7; tmp *= a; return (tmp) % d9_7; } else { ll tmp = digitpower(a, (b) / 2); tmp %= d9_7; tmp *= tmp; tmp %= d9_7; return (tmp) % d9_7; } } // 階乗 vl facs(1000000, -1); ll Factrial(ll num) { if (facs[num] != -1) { return facs[num]; } if (num == 1 || num <= 0) { return 1; } else if (num < 0) { printf("ERROR_minus\n"); return 0; } else { facs[num] = (num * Factrial(num - 1)) % d9_7; return facs[num]; } } long long modinv(long long a, long long m) { // modの逆元 long long b = m, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } ll linercomb(ll n, ll k, ll mod) { // n,kの線形時間で求める ll ans = Factrial(n); ans *= modinv(Factrial(k), mod); ans %= d9_7; ll k1 = Factrial(k); k1 %= mod; ans *= modinv(k1, mod); ans %= mod; return ans; } int LIS(vector<int> x) { int n = x.size(); vector<int> dp(n, intMAX); dp[0] = x[0]; int length = 1; rep(i, n - 1) { if (dp[length - 1] < x[i + 1]) { dp[length] = x[i + 1]; length++; continue; } *lower_bound(dp.begin(), dp.end(), x[i + 1]) = x[i + 1]; } int ans; rep(i, n) { if (dp[i + 1] == intMAX) { ans = i; break; } if (i == n - 1) { ans = dp[n - 1]; } } return ans; } struct datas { ll a; ll b; }; bool cmp(const datas &a, const datas &b) { return a.b < b.b; } int main(void) { ll n, m; cin >> n >> m; vector<datas> work(n); rep(i, n) { cin >> work[i].a >> work[i].b; } sort(work.rbegin(), work.rend(), cmp); vl sch(m + 1, -1); int rmax = m; int flag = 0; set<int> schs; rep(i, m + 1) { schs.insert(i); } rep(i, n) { if (schs.upper_bound(m - work[i].a) != schs.begin()) { auto itr = --schs.upper_bound(m - work[i].a); sch[*itr] = work[i].b; schs.erase(itr); } } ll ans = 0; rep(i, m + 1) { if (sch[i] != -1) { ans += sch[i]; } } cout << ans << endl; return 0; }
replace
172
173
172
173
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; // マクロ // forループ関係 // 引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか // Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる #define REP(i, n) for (ll i = 0; i < ll(n); i++) #define REPD(i, n) for (ll i = n - 1; i >= 0; i--) #define FOR(i, a, b) for (ll i = a; i <= ll(b); i++) #define FORD(i, a, b) for (ll i = a; i >= ll(b); i--) // xにはvectorなどのコンテナ #define ALL(x) x.begin(), x.end() // sortなどの引数を省略したい #define SIZE(x) ll(x.size()) // sizeをsize_tからllに直しておく // 定数 #define INF 1000000000000 // 10^12:極めて大きい値,∞ #define MOD 1000000007 // 10^9+7:合同式の法 #define MAXR 100000 // 10^5:配列の最大のrange(素数列挙などで使用) // 略記 #define PB emplace_back // vectorヘの挿入 #define MP make_pair // pairのコンストラクタ #define F first // pairの一つ目の要素 #define S second // pairの二つ目の要素 #define Umap unordered_map #define Uset unordered_set int main() { ll n, m; cin >> n >> m; vector<ll> a(n), b(n); REP(i, n) cin >> a[i] >> b[i]; vector<vector<ll>> score(10001); priority_queue<ll> score_all; REP(i, n) score[a[i]].PB(b[i]); ll ans = 0; REP(i, m) { while (!score[i + 1].empty()) { score_all.push(score[i + 1].back()); score[i + 1].pop_back(); } if (score_all.empty()) continue; ans += score_all.top(); score_all.pop(); } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; // マクロ // forループ関係 // 引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか // Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる #define REP(i, n) for (ll i = 0; i < ll(n); i++) #define REPD(i, n) for (ll i = n - 1; i >= 0; i--) #define FOR(i, a, b) for (ll i = a; i <= ll(b); i++) #define FORD(i, a, b) for (ll i = a; i >= ll(b); i--) // xにはvectorなどのコンテナ #define ALL(x) x.begin(), x.end() // sortなどの引数を省略したい #define SIZE(x) ll(x.size()) // sizeをsize_tからllに直しておく // 定数 #define INF 1000000000000 // 10^12:極めて大きい値,∞ #define MOD 1000000007 // 10^9+7:合同式の法 #define MAXR 100000 // 10^5:配列の最大のrange(素数列挙などで使用) // 略記 #define PB emplace_back // vectorヘの挿入 #define MP make_pair // pairのコンストラクタ #define F first // pairの一つ目の要素 #define S second // pairの二つ目の要素 #define Umap unordered_map #define Uset unordered_set int main() { ll n, m; cin >> n >> m; vector<ll> a(n), b(n); REP(i, n) cin >> a[i] >> b[i]; vector<vector<ll>> score(MAXR + 1); priority_queue<ll> score_all; REP(i, n) score[a[i]].PB(b[i]); ll ans = 0; REP(i, m) { while (!score[i + 1].empty()) { score_all.push(score[i + 1].back()); score[i + 1].pop_back(); } if (score_all.empty()) continue; ans += score_all.top(); score_all.pop(); } cout << ans; return 0; }
replace
33
34
33
34
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> typedef int ll; using namespace __gnu_pbds; using namespace std; #define pb push_back #define mp make_pair #define ff first #define ss second #define len(v) ((int)v.size()) #define all(v) v.begin(), v.end() #define oset \ tree<int, null_type, less<int>, rb_tree_tag, \ tree_order_statistics_node_update> #define orz \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define inp \ freopen("input.txt", "r", stdin); \ freopen("out.txt", "w", stdout); ll mod1 = 1e9 + 7; void io() { ios_base::sync_with_stdio(false); cin.tie(NULL); // cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif } int main() { orz; inp; ll n, m; cin >> n >> m; vector<pair<ll, ll>> p; priority_queue<ll> pq; ll ans = 0; for (int i = 0; i < n; i++) { ll a, b; cin >> a >> b; p.emplace_back(a, b); } sort(p.begin(), p.end()); p.push_back(make_pair(-1, 0)); int i = 0; for (int t = 0; t <= m; ++t) { while (p[i].first == t) { pq.push(p[i].second); ++i; } if (pq.empty()) continue; ans += pq.top(); pq.pop(); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> typedef int ll; using namespace __gnu_pbds; using namespace std; #define pb push_back #define mp make_pair #define ff first #define ss second #define len(v) ((int)v.size()) #define all(v) v.begin(), v.end() #define oset \ tree<int, null_type, less<int>, rb_tree_tag, \ tree_order_statistics_node_update> #define orz \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define inp \ freopen("input.txt", "r", stdin); \ freopen("out.txt", "w", stdout); ll mod1 = 1e9 + 7; void io() { ios_base::sync_with_stdio(false); cin.tie(NULL); // cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif } int main() { orz; // inp; ll n, m; cin >> n >> m; vector<pair<ll, ll>> p; priority_queue<ll> pq; ll ans = 0; for (int i = 0; i < n; i++) { ll a, b; cin >> a >> b; p.emplace_back(a, b); } sort(p.begin(), p.end()); p.push_back(make_pair(-1, 0)); int i = 0; for (int t = 0; t <= m; ++t) { while (p[i].first == t) { pq.push(p[i].second); ++i; } if (pq.empty()) continue; ans += pq.top(); pq.pop(); } cout << ans << endl; return 0; }
replace
35
36
35
36
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p02948
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstdlib> #include <deque> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; #define INF 1000000007 #define LINF 8000000000000000007 #define MOD 1000000007 #define int long long #define rep(i, n) for (int i = 0; i < (n); i++) #define repb(i, n) for (int i = n - 1; i >= 0; i--) #define MODE 1 #ifdef MODE #define DEB(X) cout << #X << ": " << X << " "; #define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " "; #define END cout << endl; #else #define DEB(X) \ {} #define ARDEB(i, X) \ {} #define END \ {} #endif typedef pair<int, int> P; struct edge { int to, cost; }; typedef long long ll; using namespace std; int ans, ans2; int n, m; P p[111111]; signed main() { cin >> n >> m; rep(i, n) { int a, b; cin >> a >> b; p[i] = P(a, b); } sort(p, p + n); priority_queue<int> que; int j = 0; rep(i, m) { while (p[j].first <= i + 1) { que.push(p[j].second); j++; } if (que.size()) { ans += que.top(); que.pop(); } } cout << ans << endl; }
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstdlib> #include <deque> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; #define INF 1000000007 #define LINF 8000000000000000007 #define MOD 1000000007 #define int long long #define rep(i, n) for (int i = 0; i < (n); i++) #define repb(i, n) for (int i = n - 1; i >= 0; i--) #define MODE 1 #ifdef MODE #define DEB(X) cout << #X << ": " << X << " "; #define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " "; #define END cout << endl; #else #define DEB(X) \ {} #define ARDEB(i, X) \ {} #define END \ {} #endif typedef pair<int, int> P; struct edge { int to, cost; }; typedef long long ll; using namespace std; int ans, ans2; int n, m; P p[111111]; signed main() { cin >> n >> m; rep(i, n) { int a, b; cin >> a >> b; p[i] = P(a, b); } sort(p, p + n); priority_queue<int> que; int j = 0; rep(i, m) { while (p[j].first <= i + 1 && j < n) { que.push(p[j].second); j++; } if (que.size()) { ans += que.top(); que.pop(); } } cout << ans << endl; }
replace
61
62
61
62
-11
p02948
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define rep2(i, a, n) for (ll i = a; i < (ll)(n); i++) #define memi cout << endl #define kono(n) cout << fixed << setprecision(n) #define all(c) (c).begin(), (c).end() #define pb push_back #define hina cout << ' ' #define in(n) cin >> n #define in2(n, m) cin >> n >> m #define in3(n, m, l) cin >> n >> m >> l #define out(n) cout << n const ll mei = (ll)1e9 + 7; int main() { ll a, b, n, m; in2(n, m); a = b = 0; vector<pair<ll, ll>> c(n); rep(i, n) in2(c[i].first, c[i].second); sort(all(c)); priority_queue<ll> d; rep2(i, 1, m + 1) { if (b < n) { while (c[b].first == i) { d.push(c[b].second); b++; if (b == n) break; } } a += d.top(); d.pop(); } out(a); memi; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define rep2(i, a, n) for (ll i = a; i < (ll)(n); i++) #define memi cout << endl #define kono(n) cout << fixed << setprecision(n) #define all(c) (c).begin(), (c).end() #define pb push_back #define hina cout << ' ' #define in(n) cin >> n #define in2(n, m) cin >> n >> m #define in3(n, m, l) cin >> n >> m >> l #define out(n) cout << n const ll mei = (ll)1e9 + 7; int main() { ll a, b, n, m; in2(n, m); a = b = 0; vector<pair<ll, ll>> c(n); rep(i, n) in2(c[i].first, c[i].second); sort(all(c)); priority_queue<ll> d; rep2(i, 1, m + 1) { if (b < n) { while (c[b].first == i) { d.push(c[b].second); b++; if (b == n) break; } } if (!d.empty()) { a += d.top(); d.pop(); } } out(a); memi; }
replace
33
35
33
37
-11
p02948
C++
Runtime Error
#include <algorithm> #include <cctype> #include <cstdio> #include <cstring> #define ll long long #define il inline #define rgi register int using namespace std; const int oo = 0x3f3f3f3f; const int N = 100000 + 10; int n, m, ans; int a[N]; struct GIVE { int a, b; } p[N]; struct Seg_Tree { int lc, rc; ll add, val; Seg_Tree() { add = 0; } } t[N << 2]; il int read() { rgi x = 0, f = 0, ch; while (!isdigit(ch = getchar())) f |= ch == '-'; while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar(); return f ? -x : x; } void Update(int p) { t[p].val = max(t[p << 1].val, t[p << 1 | 1].val); } void Build(int p, int l, int r) { t[p].lc = l, t[p].rc = r; if (l == r) { t[p].val = a[l]; return; } int mid = l + r >> 1; Build(p << 1, l, mid); Build(p << 1 | 1, mid + 1, r); Update(p); } void Spread(int p) { if (t[p].add != 0) { t[p << 1].add += t[p].add; t[p << 1 | 1].add += t[p].add; t[p << 1].val += t[p].add * (t[p << 1].rc - t[p << 1].lc + 1); t[p << 1 | 1].val += t[p].add * (t[p << 1 | 1].rc - t[p << 1 | 1].lc + 1); t[p].add = 0; } } void Add(int p, int l, int r, int val) { if (l <= t[p].lc && t[p].rc <= r) { t[p].add += val; t[p].val += val * (t[p].rc - t[p].lc + 1); return; } Spread(p); int mid = t[p].lc + t[p].rc >> 1; if (l <= mid) Add(p << 1, l, r, val); if (mid < r) Add(p << 1 | 1, l, r, val); Update(p); } int Query(int p, int l, int r) { if (l <= t[p].lc && t[p].rc <= r) return t[p].val; Spread(p); int mid = t[p].lc + t[p].rc >> 1; int res = -oo; if (l <= mid) res = max(res, Query(p << 1, l, r)); if (mid < r) res = max(res, Query(p << 1 | 1, l, r)); return res; } bool cmp(struct GIVE A, struct GIVE B) { if (A.b == B.b) return A.a < B.a; return A.b > B.b; } int main() { n = read(), m = read(); for (rgi i = 1; i <= n; ++i) { p[i].a = read(); p[i].b = read(); } sort(p + 1, p + n + 1, cmp); for (rgi i = 1; i <= n; ++i) a[i] = i; Build(1, 1, n); for (rgi i = 1; i <= n; ++i) { int maxn = Query(1, 1, m - p[i].a + 1); if (maxn <= 0) continue; ans += p[i].b; Add(1, maxn, maxn, -oo); } printf("%d", ans); return 0; }
#include <algorithm> #include <cctype> #include <cstdio> #include <cstring> #define ll long long #define il inline #define rgi register int using namespace std; const int oo = 0x3f3f3f3f; const int N = 100000 + 10; int n, m, ans; int a[N]; struct GIVE { int a, b; } p[N]; struct Seg_Tree { int lc, rc; ll add, val; Seg_Tree() { add = 0; } } t[N << 2]; il int read() { rgi x = 0, f = 0, ch; while (!isdigit(ch = getchar())) f |= ch == '-'; while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar(); return f ? -x : x; } void Update(int p) { t[p].val = max(t[p << 1].val, t[p << 1 | 1].val); } void Build(int p, int l, int r) { t[p].lc = l, t[p].rc = r; if (l == r) { t[p].val = a[l]; return; } int mid = l + r >> 1; Build(p << 1, l, mid); Build(p << 1 | 1, mid + 1, r); Update(p); } void Spread(int p) { if (t[p].add != 0) { t[p << 1].add += t[p].add; t[p << 1 | 1].add += t[p].add; t[p << 1].val += t[p].add * (t[p << 1].rc - t[p << 1].lc + 1); t[p << 1 | 1].val += t[p].add * (t[p << 1 | 1].rc - t[p << 1 | 1].lc + 1); t[p].add = 0; } } void Add(int p, int l, int r, int val) { if (l <= t[p].lc && t[p].rc <= r) { t[p].add += val; t[p].val += val * (t[p].rc - t[p].lc + 1); return; } Spread(p); int mid = t[p].lc + t[p].rc >> 1; if (l <= mid) Add(p << 1, l, r, val); if (mid < r) Add(p << 1 | 1, l, r, val); Update(p); } int Query(int p, int l, int r) { if (l <= t[p].lc && t[p].rc <= r) return t[p].val; Spread(p); int mid = t[p].lc + t[p].rc >> 1; int res = -oo; if (l <= mid) res = max(res, Query(p << 1, l, r)); if (mid < r) res = max(res, Query(p << 1 | 1, l, r)); return res; } bool cmp(struct GIVE A, struct GIVE B) { if (A.b == B.b) return A.a < B.a; return A.b > B.b; } int main() { n = read(), m = read(); for (rgi i = 1; i <= n; ++i) { p[i].a = read(); p[i].b = read(); } sort(p + 1, p + n + 1, cmp); for (rgi i = 1; i <= n; ++i) a[i] = i; Build(1, 1, n); for (rgi i = 1; i <= n; ++i) { if (m - p[i].a + 1 < 1) continue; int maxn = Query(1, 1, m - p[i].a + 1); if (maxn <= 0) continue; ans += p[i].b; Add(1, maxn, maxn, -oo); } printf("%d", ans); return 0; }
insert
104
104
104
106
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 3e5 + 10; int a[N], b[N], v[N]; typedef pair<int, int> pa; vector<int> dead[N]; int main() { int n, m; cin >> n >> m; multiset<int> st; m++; for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; dead[m - a[i]].push_back(b[i]); } ll ans = 0; for (int i = m; i >= 1; i--) { for (int x : dead[i]) { st.insert(x); } if (!st.empty()) { auto it = prev(st.end()); ans += *it; st.erase(it); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 3e5 + 10; int a[N], b[N], v[N]; typedef pair<int, int> pa; vector<int> dead[N]; int main() { int n, m; cin >> n >> m; multiset<int> st; m++; for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; if (m - a[i] <= 0) continue; dead[m - a[i]].push_back(b[i]); } ll ans = 0; for (int i = m; i >= 1; i--) { for (int x : dead[i]) { st.insert(x); } if (!st.empty()) { auto it = prev(st.end()); ans += *it; st.erase(it); } } cout << ans << endl; return 0; }
insert
15
15
15
17
0
p02948
C++
Runtime Error
// D - Summer Vacation #include <bits/stdc++.h> using namespace std; int main(int argc, char *argv[]) { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vector<vector<int>> a(m); for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; a[x - 1].push_back(y); } priority_queue<long long> q; long long ans = 0; for (int i = 0; i < m; i++) { for (int j = 0; j < a[i].size(); j++) q.push(a[i][j]); if (!q.empty()) { ans += q.top(); q.pop(); } } cout << ans << endl; return 0; }
// D - Summer Vacation #include <bits/stdc++.h> using namespace std; int main(int argc, char *argv[]) { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vector<vector<int>> a(m); for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; if (x <= m) a[x - 1].push_back(y); } priority_queue<long long> q; long long ans = 0; for (int i = 0; i < m; i++) { for (int j = 0; j < a[i].size(); j++) q.push(a[i][j]); if (!q.empty()) { ans += q.top(); q.pop(); } } cout << ans << endl; return 0; }
replace
15
16
15
17
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long const int maxn = 5e5 + 5; inline int read() { char c = getchar(); int t = 0, f = 1; while (!isdigit(c)) { if (c == '-') f = -1; c = getchar(); } while (isdigit(c)) { t = (t << 3) + (t << 1) + (c ^ 48); c = getchar(); } return t * f; } int n, m; struct node { int a, b; } a[maxn]; bool cmp(node a, node b) { return a.a < b.a; } priority_queue<int, vector<int>, greater<int>> q; signed main() { n = read(), m = read(); for (int i = 1; i <= n; i++) { a[i].a = read(), a[i].b = read(); a[i].a = m - a[i].a + 1; } sort(a + 1, a + 1 + n, cmp); int sum = 0, sz = 0; for (int i = 1; i <= n; i++) { if (sz < a[i].a) { q.push(a[i].b); sum += a[i].b; sz++; } else { int alfa = q.top(); if (alfa < a[i].b) { q.pop(); sum -= alfa; sum += a[i].b; q.push(a[i].b); } } } printf("%lld\n", sum); return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long const int maxn = 5e5 + 5; inline int read() { char c = getchar(); int t = 0, f = 1; while (!isdigit(c)) { if (c == '-') f = -1; c = getchar(); } while (isdigit(c)) { t = (t << 3) + (t << 1) + (c ^ 48); c = getchar(); } return t * f; } int n, m; struct node { int a, b; } a[maxn]; bool cmp(node a, node b) { return a.a < b.a; } priority_queue<int, vector<int>, greater<int>> q; signed main() { n = read(), m = read(); for (int i = 1; i <= n; i++) { a[i].a = read(), a[i].b = read(); a[i].a = m - a[i].a + 1; } sort(a + 1, a + 1 + n, cmp); int sum = 0, sz = 0; for (int i = 1; i <= n; i++) { if (a[i].a <= 0) continue; if (sz < a[i].a) { q.push(a[i].b); sum += a[i].b; sz++; } else { int alfa = q.top(); if (alfa < a[i].b) { q.pop(); sum -= alfa; sum += a[i].b; q.push(a[i].b); } } } printf("%lld\n", sum); return 0; }
insert
33
33
33
35
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i, n) for (int i = 1; i < (int)(n); i++) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define vout(x) rep(i, x.size()) cout << x[i] << " " template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } using namespace std; using vint = vector<int>; using vvint = vector<vector<int>>; using ll = long long; using vll = vector<ll>; using vvll = vector<vector<ll>>; using P = pair<int, int>; const int inf = 1e9; const ll inf_l = 1LL << 62; const int MAX = 1e5; int main() { int n, m; cin >> n >> m; vvint data(m); rep(i, n) { int a, b; cin >> a >> b; a--; data[a].push_back(b); } priority_queue<int> q; int ans = 0; rep(i, m) { rep(j, data[i].size()) { q.push(data[i][j]); } if (!q.empty()) { ans += q.top(); q.pop(); } } cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i, n) for (int i = 1; i < (int)(n); i++) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define vout(x) rep(i, x.size()) cout << x[i] << " " template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } using namespace std; using vint = vector<int>; using vvint = vector<vector<int>>; using ll = long long; using vll = vector<ll>; using vvll = vector<vector<ll>>; using P = pair<int, int>; const int inf = 1e9; const ll inf_l = 1LL << 62; const int MAX = 1e5; int main() { int n, m; cin >> n >> m; vvint data(m); rep(i, n) { int a, b; cin >> a >> b; if (a > m) continue; a--; data[a].push_back(b); } priority_queue<int> q; int ans = 0; rep(i, m) { rep(j, data[i].size()) { q.push(data[i][j]); } if (!q.empty()) { ans += q.top(); q.pop(); } } cout << ans << endl; }
insert
38
38
38
40
0
p02948
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #include <fstream> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> typedef long long ll; const int maxn = 110000; const int mod = 1000000007; using namespace std; int n, m, ans; struct node { int time, v; } a[maxn]; bool cmp(node a, node b) { return a.time > b.time; } priority_queue<int, vector<int>, greater<int>> p; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) { scanf("%d %d", &a[i].time, &a[i].v); } sort(a + 1, a + 1 + n, cmp); for (int i = 1; i <= n; i++) { if (a[i].time <= m - p.size()) { p.push(a[i].v); } else { int t = p.top(); if (a[i].time <= m - p.size() + 1) { if (a[i].v > t) { p.pop(); p.push(a[i].v); } } } } while (p.size()) { ans += p.top(); p.pop(); } printf("%d", ans); }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #include <fstream> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> typedef long long ll; const int maxn = 110000; const int mod = 1000000007; using namespace std; int n, m, ans; struct node { int time, v; } a[maxn]; bool cmp(node a, node b) { return a.time > b.time; } priority_queue<int, vector<int>, greater<int>> p; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) { scanf("%d %d", &a[i].time, &a[i].v); } sort(a + 1, a + 1 + n, cmp); for (int i = 1; i <= n; i++) { if (a[i].time <= m - p.size()) { p.push(a[i].v); } else { int t = p.top(); if (a[i].time <= m - p.size() + 1 && p.size()) { if (a[i].v > t) { p.pop(); p.push(a[i].v); } } } } while (p.size()) { ans += p.top(); p.pop(); } printf("%d", ans); }
replace
34
35
34
35
0
p02948
C++
Runtime Error
#include <iostream> #include <queue> #include <vector> int main() { unsigned int N, M; std::cin >> N >> M; std::vector<std::vector<unsigned int>> day_jobs(100000); for (unsigned int i = 0; i < N; ++i) { unsigned int a, b; std::cin >> a >> b; day_jobs.at(a).push_back(b); } std::priority_queue<unsigned int> job_queue; unsigned long long sum = 0; for (unsigned int i = 1; i <= M; ++i) { for (auto x : day_jobs.at(i)) { job_queue.push(x); } if (!job_queue.empty()) { sum += job_queue.top(); job_queue.pop(); } } std::cout << sum << std::endl; return 0; }
#include <iostream> #include <queue> #include <vector> int main() { unsigned int N, M; std::cin >> N >> M; std::vector<std::vector<unsigned int>> day_jobs(100000 + 5); for (unsigned int i = 0; i < N; ++i) { unsigned int a, b; std::cin >> a >> b; day_jobs.at(a).push_back(b); } std::priority_queue<unsigned int> job_queue; unsigned long long sum = 0; for (unsigned int i = 1; i <= M; ++i) { for (auto x : day_jobs.at(i)) { job_queue.push(x); } if (!job_queue.empty()) { sum += job_queue.top(); job_queue.pop(); } } std::cout << sum << std::endl; return 0; }
replace
8
9
8
9
0
p02948
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; vector<long long> vp[230000]; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout); #endif long long n, m; cin >> n >> m; for (int i = 0; i < n; i++) { long long x, y; cin >> x >> y; vp[x].push_back(y); } long long ans = 0; priority_queue<long long> pq; for (int i = 1; i <= m; i++) { for (auto x : vp[i]) { pq.push(x); } if (!pq.empty()) { ans += pq.top(); pq.pop(); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; vector<long long> vp[230000]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n, m; cin >> n >> m; for (int i = 0; i < n; i++) { long long x, y; cin >> x >> y; vp[x].push_back(y); } long long ans = 0; priority_queue<long long> pq; for (int i = 1; i <= m; i++) { for (auto x : vp[i]) { pq.push(x); } if (!pq.empty()) { ans += pq.top(); pq.pop(); } } cout << ans << endl; return 0; }
replace
5
9
5
8
TLE
p02948
C++
Runtime Error
#pragma target("avx") #include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); long long n, m, ans = 0; cin >> n >> m; long long a[n], b[n]; vector<long long> v[10005]; for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; a[i]--; v[a[i]].push_back(b[i]); } priority_queue<long long> que; for (int i = 0; i < m; i++) { for (size_t j = 0; j < v[i].size(); j++) { que.push(v[i][j]); } if (!que.empty()) { ans += que.top(); que.pop(); } } cout << ans << endl; return 0; }
#pragma target("avx") #include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); long long n, m, ans = 0; cin >> n >> m; long long a[n], b[n]; vector<long long> v[100005]; for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; a[i]--; v[a[i]].push_back(b[i]); } priority_queue<long long> que; for (int i = 0; i < m; i++) { for (size_t j = 0; j < v[i].size(); j++) { que.push(v[i][j]); } if (!que.empty()) { ans += que.top(); que.pop(); } } cout << ans << endl; return 0; }
replace
13
14
13
14
0
p02948
C++
Runtime Error
#include <iostream> #include <queue> #include <vector> using namespace std; int main() { int n, m, i, a, b, ans = 0; priority_queue<int> q; cin >> n >> m; vector<vector<int>> v(m); for (i = 0; i < n; ++i) { cin >> a >> b; --a; v.at(a).push_back(b); } for (i = 0; i < m; ++i) { for (auto e : v.at(i)) q.push(e); if (!q.empty()) { ans += q.top(); q.pop(); } } cout << ans << endl; return 0; }
#include <iostream> #include <queue> #include <vector> using namespace std; int main() { int n, m, i, a, b, ans = 0; priority_queue<int> q; cin >> n >> m; vector<vector<int>> v(100000); for (i = 0; i < n; ++i) { cin >> a >> b; --a; v.at(a).push_back(b); } for (i = 0; i < m; ++i) { for (auto e : v.at(i)) q.push(e); if (!q.empty()) { ans += q.top(); q.pop(); } } cout << ans << endl; return 0; }
replace
9
10
9
10
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; struct node { int a, b; } p[100001]; bool cmp(node a, node b) { return a.a > b.a; } int f[100001]; int getfa(int x) { return x == f[x] ? f[x] : f[x] = getfa(f[x]); } int main() { int n, m; int ans = 0; cin >> n >> m; for (int i = 1; i <= n; i++) scanf("%d%d", &p[i].b, &p[i].a); sort(p + 1, p + n + 1, cmp); for (int i = 1; i <= m; i++) f[i] = i; for (int i = 1; i <= n; i++) { int t = getfa(m - p[i].b + 1); if (t != 0) { ans += p[i].a; f[t] = t - 1; } } printf("%d", ans); }
#include <bits/stdc++.h> using namespace std; struct node { int a, b; } p[100001]; bool cmp(node a, node b) { return a.a > b.a; } int f[100001]; int getfa(int x) { return x == f[x] ? f[x] : f[x] = getfa(f[x]); } int main() { int n, m; int ans = 0; cin >> n >> m; for (int i = 1; i <= n; i++) scanf("%d%d", &p[i].b, &p[i].a); sort(p + 1, p + n + 1, cmp); for (int i = 1; i <= m; i++) f[i] = i; for (int i = 1; i <= n; i++) { if (p[i].b > m) continue; int t = getfa(m - p[i].b + 1); if (t != 0) { ans += p[i].a; f[t] = t - 1; } } printf("%d", ans); }
insert
18
18
18
20
0
p02948
C++
Runtime Error
//============================================================================ // Falling Down is an accident, Staying Down is a Choice. // Author : Murad // Online Judge: Codeforces.cpp & Atcoder.cpp // Description : Problem name //============================================================================ #include <bits/stdc++.h> #include <unordered_map> #include <unordered_set> #include <utility> using namespace std; typedef long long LL; #define pi 3.1415926536 #define forn(i, a, b) for (int i = a; i < b; i++) #define ULL unsigned long long #define MP make_pair #define ff first #define ss second #define endl '\n' #define INF LL(1e9); #define _INF INT32_MIN #define pq priority_queue #define MM multimap #define PB push_back #define EMPP emplace_back #define vii vector<int> #define vll vector<LL> #define ipair pair<int, int> #define lpair pair<LL, LL> #define clr(v, d) memset(v, d, sizeof(v)) #define El3zba \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define modd 1000000007 #define sf1(v) scanf("%I64d", &v); #define sf2(v1, v2) scanf("%I64d %I64d", &v1, &v2) #define sf3(v1, v2, v3) scanf("%I64d %I64d %I64d", &v1, &v2, &v3) // std::transform(s1.begin(), s1.end(), s1.begin(),::tolower); char alphz[27] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}; float Euclidean(LL x1, LL x2, LL y1, LL y2) { return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2)); } LL GCD(LL a, LL b) { return !b ? a : GCD(b, a % b); } LL LCM(LL a, LL b) { return (a * b) / GCD(a, b); } void PrimeFactor(LL n) { while (n % 2 == 0) { // printf("%d ", 2); // aa.insert(2); n /= 2; } for (int i = 3; i <= sqrt(n); i += 2) { if (n % i == 0) { // printf("%d ", i); // aa.insert(i); n /= i; } } if (n > 2) { // printf("%d ", n); // aa.insert(n); }; } bool Is_Square(LL x) { LL l = 0, r = x; while (l <= r) { LL mid = l + (r - l) / 2; if (mid * mid == x) return true; if (mid * mid > x) r = mid - 1; else l = mid + 1; } return false; } LL Power(LL x, LL y) { LL temp; if (y == 0) return 1; temp = Power(x, y / 2); if (y % 2 == 0) return (temp * temp); else return (x * temp * temp); } bool Is_Prime(int x) { if (x == 2) return 1; else if (x % 2 == 0 || x < 2) return 0; for (int i = 3; i * i <= x; i += 2) if (x % i == 0) return 0; return 1; } bool Is_Palin(string s) { int i = 0, j = (int)s.size() - 1; while (i < j) { if (s[i] != s[j]) return 0; i++, j--; } return 1; } const int N = 10005; int mem[N][N]; vii a, b; int solv(int idx, int m, int n) { if (idx >= n) return 0; if (mem[idx][m] != -1) return mem[idx][m]; int go1 = 0, go2 = 0, go3 = 0; if (idx + a[idx] <= m) { go1 = solv(idx + 1, m, n); go2 = solv(idx + 1, m, n) + b[idx]; } if (idx + a[idx] > m) go3 = solv(idx + 1, m, n); mem[idx][m] = max({go1, go2, go3}); return mem[idx][m]; } int main() { El3zba; /*** بسم الله الرحمن الرحيم ***/ int n, m; cin >> n >> m; a.resize(n); b.resize(n); clr(mem, -1); for (int i = 0; i < n; i++) cin >> a[i] >> b[i]; int ans = solv(0, m, n); cout << ans << endl; return 0; }
//============================================================================ // Falling Down is an accident, Staying Down is a Choice. // Author : Murad // Online Judge: Codeforces.cpp & Atcoder.cpp // Description : Problem name //============================================================================ #include <bits/stdc++.h> #include <unordered_map> #include <unordered_set> #include <utility> using namespace std; typedef long long LL; #define pi 3.1415926536 #define forn(i, a, b) for (int i = a; i < b; i++) #define ULL unsigned long long #define MP make_pair #define ff first #define ss second #define endl '\n' #define INF LL(1e9); #define _INF INT32_MIN #define pq priority_queue #define MM multimap #define PB push_back #define EMPP emplace_back #define vii vector<int> #define vll vector<LL> #define ipair pair<int, int> #define lpair pair<LL, LL> #define clr(v, d) memset(v, d, sizeof(v)) #define El3zba \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define modd 1000000007 #define sf1(v) scanf("%I64d", &v); #define sf2(v1, v2) scanf("%I64d %I64d", &v1, &v2) #define sf3(v1, v2, v3) scanf("%I64d %I64d %I64d", &v1, &v2, &v3) // std::transform(s1.begin(), s1.end(), s1.begin(),::tolower); char alphz[27] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}; float Euclidean(LL x1, LL x2, LL y1, LL y2) { return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2)); } LL GCD(LL a, LL b) { return !b ? a : GCD(b, a % b); } LL LCM(LL a, LL b) { return (a * b) / GCD(a, b); } void PrimeFactor(LL n) { while (n % 2 == 0) { // printf("%d ", 2); // aa.insert(2); n /= 2; } for (int i = 3; i <= sqrt(n); i += 2) { if (n % i == 0) { // printf("%d ", i); // aa.insert(i); n /= i; } } if (n > 2) { // printf("%d ", n); // aa.insert(n); }; } bool Is_Square(LL x) { LL l = 0, r = x; while (l <= r) { LL mid = l + (r - l) / 2; if (mid * mid == x) return true; if (mid * mid > x) r = mid - 1; else l = mid + 1; } return false; } LL Power(LL x, LL y) { LL temp; if (y == 0) return 1; temp = Power(x, y / 2); if (y % 2 == 0) return (temp * temp); else return (x * temp * temp); } bool Is_Prime(int x) { if (x == 2) return 1; else if (x % 2 == 0 || x < 2) return 0; for (int i = 3; i * i <= x; i += 2) if (x % i == 0) return 0; return 1; } bool Is_Palin(string s) { int i = 0, j = (int)s.size() - 1; while (i < j) { if (s[i] != s[j]) return 0; i++, j--; } return 1; } const int N = 10005; int mem[N][N]; vii a, b; int solv(int idx, int m, int n) { if (idx >= n) return 0; if (mem[idx][m] != -1) return mem[idx][m]; int go1 = 0, go2 = 0, go3 = 0; if (idx + a[idx] <= m) { go1 = solv(idx + 1, m, n); go2 = solv(idx + 1, m, n) + b[idx]; } if (idx + a[idx] > m) go3 = solv(idx + 1, m, n); mem[idx][m] = max({go1, go2, go3}); return mem[idx][m]; } int main() { El3zba; /*** بسم الله الرحمن الرحيم ***/ int n, m; cin >> n >> m; pq<int> q; vector<ipair> a; for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; a.PB({x, y}); } sort(a.begin(), a.end()); int idx = 0, ans = 0; for (int i = 1; i <= m; i++) { while (idx < n && a[idx].ff <= i) { q.push(a[idx].ss); idx++; } if (!q.empty()) { ans += q.top(); q.pop(); } } cout << ans << endl; return 0; }
replace
130
136
130
149
-11
p02948
C++
Runtime Error
#include <bits/stdc++.h> #define pb push_back #define mp make_pair #define pii pair<int, int> #define fi first #define sc second #define ALL(x) x.begin(), x.end() #define RALL(X) x.begin(), x.end() #define FOR(i, n, k) for (i = 0; i < n; i += k) #define FO(i, n, k) for (i = 1; i <= n; i += k) #define CLEAR(a, b) memset(a, b, sizeof(a)) #define N 100005 #define mid ((l + r) / 2) #define dbg(x) (cerr << #x << " : " << x << endl) #define endl "\n" #define MOD 100000009 using namespace std; typedef long long int lli; int main() { ios_base::sync_with_stdio(false); int n, m; cin >> n >> m; vector<vector<int>> ar(n, vector<int>()); for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; ar[a].pb(b); } int res = 0; priority_queue<int> pq; for (int i = m - 1; i >= 0; i--) { for (int x : ar[m - i]) pq.push(x); if (!pq.empty()) { res += pq.top(); pq.pop(); } } cout << res; return 0; }
#include <bits/stdc++.h> #define pb push_back #define mp make_pair #define pii pair<int, int> #define fi first #define sc second #define ALL(x) x.begin(), x.end() #define RALL(X) x.begin(), x.end() #define FOR(i, n, k) for (i = 0; i < n; i += k) #define FO(i, n, k) for (i = 1; i <= n; i += k) #define CLEAR(a, b) memset(a, b, sizeof(a)) #define N 100005 #define mid ((l + r) / 2) #define dbg(x) (cerr << #x << " : " << x << endl) #define endl "\n" #define MOD 100000009 using namespace std; typedef long long int lli; int main() { ios_base::sync_with_stdio(false); int n, m; cin >> n >> m; vector<vector<int>> ar(100005, vector<int>()); for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; ar[a].pb(b); } int res = 0; priority_queue<int> pq; for (int i = m - 1; i >= 0; i--) { for (int x : ar[m - i]) pq.push(x); if (!pq.empty()) { res += pq.top(); pq.pop(); } } cout << res; return 0; }
replace
25
26
25
26
-6
malloc(): corrupted top size
p02948
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstring> #include <functional> #include <iostream> #include <list> #include <memory> #include <queue> #include <set> #include <utility> #include <vector> #define ll long long using namespace std; int main(int argc, char const *argv[]) { ll n, m; cin >> n >> m; vector<list<ll>> a(10005, list<ll>()); ll maxb = 0; for (ll i = 0; i < n; ++i) { ll p, q; cin >> p >> q; a[p].emplace_back(q); } priority_queue<ll> works; ll res = 0; for (ll i = m; i >= 0; --i) { for (auto &b : a[m - i]) { works.push(b); } if (!works.empty()) { // cerr << "i=" << i << ": " << *f << endl; res += works.top(); works.pop(); } // else { cerr << "i=" << i << ": " << 0 << endl;} } cout << res << endl; }
#include <algorithm> #include <cmath> #include <cstring> #include <functional> #include <iostream> #include <list> #include <memory> #include <queue> #include <set> #include <utility> #include <vector> #define ll long long using namespace std; int main(int argc, char const *argv[]) { ll n, m; cin >> n >> m; vector<list<ll>> a(100005, list<ll>()); ll maxb = 0; for (ll i = 0; i < n; ++i) { ll p, q; cin >> p >> q; a[p].emplace_back(q); } priority_queue<ll> works; ll res = 0; for (ll i = m; i >= 0; --i) { for (auto &b : a[m - i]) { works.push(b); } if (!works.empty()) { // cerr << "i=" << i << ": " << *f << endl; res += works.top(); works.pop(); } // else { cerr << "i=" << i << ": " << 0 << endl;} } cout << res << endl; }
replace
19
20
19
20
0
p02948
C++
Time Limit Exceeded
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; int main() { int N, M; cin >> N >> M; vector<pair<int, int>> v(N); priority_queue<int> pq; for (int i = 0; i < N; i++) { int A, B; cin >> A >> B; v[i] = make_pair(A, B); } int ans = 0; int j = 0; sort(v.begin(), v.end()); for (int i = 1; i <= M; i++) { if (j < N) { while (v[j].first <= i) { pq.push(v[j].second); j++; if (j >= N) break; } } if (!pq.empty()) { ans += pq.top(); pq.pop(); } } cout << ans << endl; }
// #define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; int main() { int N, M; cin >> N >> M; vector<pair<int, int>> v(N); priority_queue<int> pq; for (int i = 0; i < N; i++) { int A, B; cin >> A >> B; v[i] = make_pair(A, B); } int ans = 0; int j = 0; sort(v.begin(), v.end()); for (int i = 1; i <= M; i++) { if (j < N) { while (v[j].first <= i) { pq.push(v[j].second); j++; if (j >= N) break; } } if (!pq.empty()) { ans += pq.top(); pq.pop(); } } cout << ans << endl; }
replace
0
1
0
1
TLE
p02948
C++
Runtime Error
#pragma GCC optimize "03" #include <bits/stdc++.h> using namespace std; #define int long long int #define ld long double #define pi pair<int, int> #define pb push_back #define fi first #define se second #define IOS \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) #ifndef LOCAL #define endl '\n' #endif const int N = 1e5 + 5; const int mod = 1e9 + 7; const int inf = 1e9 + 9; multiset<int, greater<int>> s; vector<int> v[N]; signed main() { #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif IOS; int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) { int a, b; cin >> a >> b; v[m - a + 1].push_back(b); } int ans = 0; for (int i = m; i >= 1; i--) { for (auto j : v[i]) s.insert(j); if (!s.empty()) { ans += *s.begin(); s.erase(s.begin()); } } cout << ans; return 0; }
#pragma GCC optimize "03" #include <bits/stdc++.h> using namespace std; #define int long long int #define ld long double #define pi pair<int, int> #define pb push_back #define fi first #define se second #define IOS \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) #ifndef LOCAL #define endl '\n' #endif const int N = 1e5 + 5; const int mod = 1e9 + 7; const int inf = 1e9 + 9; multiset<int, greater<int>> s; vector<int> v[N]; signed main() { #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif IOS; int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) { int a, b; cin >> a >> b; if (m - a + 1 >= 1) v[m - a + 1].push_back(b); } int ans = 0; for (int i = m; i >= 1; i--) { for (auto j : v[i]) s.insert(j); if (!s.empty()) { ans += *s.begin(); s.erase(s.begin()); } } cout << ans; return 0; }
replace
36
37
36
38
0
p02948
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, int>; const int MAX_A = 1e5 + 1; int N, M; void solve() { cin >> N >> M; vector<P> jobs(N); for (int i = 0; i < N; ++i) { int a, b; cin >> a >> b; jobs[i] = P(a, b); } sort(jobs.begin(), jobs.end()); ll ans = 0; priority_queue<int> q; int start = 0; for (int d = 1; d <= M; ++d) { for (int i = start; i < N; ++i) { P j = jobs[i]; if (j.first <= d) { q.push(j.second); start++; } } if (!q.empty()) { ans += q.top(); q.pop(); } } cout << ans << endl; } int main() { solve(); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, int>; const int MAX_A = 1e5 + 1; int N, M; void solve() { cin >> N >> M; vector<P> jobs(N); for (int i = 0; i < N; ++i) { int a, b; cin >> a >> b; jobs[i] = P(a, b); } sort(jobs.begin(), jobs.end()); ll ans = 0; priority_queue<int> q; int start = 0; for (int d = 1; d <= M; ++d) { for (int i = start; i < N; ++i) { P j = jobs[i]; if (j.first <= d) { q.push(j.second); start++; } else { start = i; break; } } if (!q.empty()) { ans += q.top(); q.pop(); } } cout << ans << endl; } int main() { solve(); return 0; }
insert
25
25
25
28
TLE
p02948
C++
Runtime Error
/******************************* Author:galaxy yr LANG:C++ Created Time:2019/08/10 20:04:35 *******************************/ #include <algorithm> #include <cstdio> #include <iostream> using namespace std; const int maxn = 1e5 + 10; int n, m, _time, _end, f[maxn]; long long ans; struct Node { int a, b; bool operator<(const Node &p) { if (b == p.b) return a < p.a; return b > p.b; } } e[maxn]; int find(int x) { return (f[x] == x ? x : f[x] = find(f[x])); } int main() { // freopen("d.in","r",stdin); // freopen("d.out","w",stdout); cin >> n >> m; m++; for (int i = 1; i <= n; i++) cin >> e[i].a >> e[i].b; sort(e + 1, e + n + 1); for (int i = 1; i <= m; i++) f[i] = i; for (int i = 1; i <= n; i++) { int fa = find(m - e[i].a); if (fa != 0) { ans += e[i].b; f[fa] = find(fa - 1); } } cout << ans << endl; return 0; }
/******************************* Author:galaxy yr LANG:C++ Created Time:2019/08/10 20:04:35 *******************************/ #include <algorithm> #include <cstdio> #include <iostream> using namespace std; const int maxn = 1e5 + 10; int n, m, _time, _end, f[maxn]; long long ans; struct Node { int a, b; bool operator<(const Node &p) { if (b == p.b) return a < p.a; return b > p.b; } } e[maxn]; int find(int x) { return (f[x] == x ? x : f[x] = find(f[x])); } int main() { // freopen("d.in","r",stdin); // freopen("d.out","w",stdout); cin >> n >> m; m++; for (int i = 1; i <= n; i++) cin >> e[i].a >> e[i].b; sort(e + 1, e + n + 1); for (int i = 1; i <= m; i++) f[i] = i; for (int i = 1; i <= n; i++) { if (m - e[i].a < 0) continue; int fa = find(m - e[i].a); if (fa != 0) { ans += e[i].b; f[fa] = find(fa - 1); } } cout << ans << endl; return 0; }
insert
32
32
32
34
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<vector<int>> tasks(m + 1, vector<int>(0)); for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; tasks.at(a).push_back(b); } int answer = 0; priority_queue<int> q; for (int i = 1; i < m + 1; i++) { for (int j = 0; j < tasks.at(i).size(); j++) { q.push(tasks.at(i).at(j)); } if (q.size() != 0) { answer += q.top(); q.pop(); } } cout << answer << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<vector<int>> tasks(m + 1, vector<int>(0)); for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; if (a < m + 1) { tasks.at(a).push_back(b); } } int answer = 0; priority_queue<int> q; for (int i = 1; i < m + 1; i++) { for (int j = 0; j < tasks.at(i).size(); j++) { q.push(tasks.at(i).at(j)); } if (q.size() != 0) { answer += q.top(); q.pop(); } } cout << answer << endl; }
replace
11
12
11
15
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long llu; int main(int argc, char *argv[]) { ll n, m; cin >> n >> m; vector<vector<ll>> v(m + 1); for (ll i = 0; i < n; ++i) { ll a, b; cin >> a >> b; v[a].push_back(b); } priority_queue<ll> pq; ll ans = 0; for (ll i = 1; i <= m; ++i) { for (auto itr = v[i].begin(); itr != v[i].end(); ++itr) { pq.push(*itr); } if (pq.empty()) continue; ans += pq.top(); pq.pop(); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long llu; int main(int argc, char *argv[]) { ll n, m; cin >> n >> m; vector<vector<ll>> v(m + 1); for (ll i = 0; i < n; ++i) { ll a, b; cin >> a >> b; if (a > m) continue; v[a].push_back(b); } priority_queue<ll> pq; ll ans = 0; for (ll i = 1; i <= m; ++i) { for (auto itr = v[i].begin(); itr != v[i].end(); ++itr) { pq.push(*itr); } if (pq.empty()) continue; ans += pq.top(); pq.pop(); } cout << ans << endl; return 0; }
insert
14
14
14
16
0
p02948
C++
Runtime Error
/* Author:zeke pass System Test! GET AC!! */ #include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using ll = long long; using ld = long double; using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(), (x).end() #define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var)) #define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var)) #define Mp(a, b) make_pair((a), (b)) #define F first #define S second #define Icin(s) \ ll(s); \ cin >> (s); #define Scin(s) \ ll(s); \ cin >> (s); 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; } typedef pair<ll, ll> P; typedef vector<ll> V; typedef vector<V> VV; typedef vector<P> VP; ll mod = 1e9 + 7; ll MOD = 1e9 + 7; ll INF = 1e18; int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, m; cin >> n >> m; VV vec(m); rep(i, n) { ll a, b; cin >> a >> b; a--; if (a >= n) continue; vec[a].push_back(b); } priority_queue<ll> q; ll sum = 0; rep(i, m) { rep(j, vec[i].size()) { q.push(vec[i][j]); } if (!q.empty()) { sum += q.top(); q.pop(); } } cout << sum << endl; }
/* Author:zeke pass System Test! GET AC!! */ #include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using ll = long long; using ld = long double; using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(), (x).end() #define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var)) #define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var)) #define Mp(a, b) make_pair((a), (b)) #define F first #define S second #define Icin(s) \ ll(s); \ cin >> (s); #define Scin(s) \ ll(s); \ cin >> (s); 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; } typedef pair<ll, ll> P; typedef vector<ll> V; typedef vector<V> VV; typedef vector<P> VP; ll mod = 1e9 + 7; ll MOD = 1e9 + 7; ll INF = 1e18; int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, m; cin >> n >> m; VV vec(m); rep(i, n) { ll a, b; cin >> a >> b; a--; if (a >= m) continue; vec[a].push_back(b); } priority_queue<ll> q; ll sum = 0; rep(i, m) { rep(j, vec[i].size()) { q.push(vec[i][j]); } if (!q.empty()) { sum += q.top(); q.pop(); } } cout << sum << endl; }
replace
69
70
69
70
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define repr(i, n) for (int i = (n); i >= 0; --i) #define FOR(i, m, n) for (int i = (m); i < (n); ++i) #define FORR(i, m, n) for (int i = (m); i >= (n); --i) #define equals(a, b) (fabs((a) - (b)) < EPS) using namespace std; typedef long long ll; const ll mod = 1000000007; const ll mod2 = 998244353; const int INF = 1000000005; const long double EPS = 1e-10; vector<int> job[100005]; int main() { int n, m; cin >> n >> m; int a, b; rep(i, n) { cin >> a >> b; job[a - 1].push_back(b); } priority_queue<int> pq; int ans = 0; rep(i, m) { for (int x : job[i]) pq.push(x); ans += pq.top(); pq.pop(); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define repr(i, n) for (int i = (n); i >= 0; --i) #define FOR(i, m, n) for (int i = (m); i < (n); ++i) #define FORR(i, m, n) for (int i = (m); i >= (n); --i) #define equals(a, b) (fabs((a) - (b)) < EPS) using namespace std; typedef long long ll; const ll mod = 1000000007; const ll mod2 = 998244353; const int INF = 1000000005; const long double EPS = 1e-10; vector<int> job[100005]; int main() { int n, m; cin >> n >> m; int a, b; rep(i, n) { cin >> a >> b; job[a - 1].push_back(b); } priority_queue<int> pq; int ans = 0; rep(i, m) { for (int x : job[i]) pq.push(x); if (pq.empty()) continue; ans += pq.top(); pq.pop(); } cout << ans << endl; return 0; }
insert
30
30
30
32
-11
p02948
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; int main() { int N, M; cin >> N >> M; vector<vector<int>> jobs(M); // i日目に選択出来る仕事 rep(i, N) { int a, b; cin >> a >> b; jobs[M - a].push_back(b); } priority_queue<int> q; long ans = 0; for (int i = M - 1; i >= 0; i--) { for (int p : jobs[i]) { q.push(p); } if (!q.empty()) { ans += q.top(); q.pop(); } } cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; int main() { int N, M; cin >> N >> M; vector<vector<int>> jobs(M); // i日目に選択出来る仕事 rep(i, N) { int a, b; cin >> a >> b; if (a > M) continue; jobs[M - a].push_back(b); } priority_queue<int> q; long ans = 0; for (int i = M - 1; i >= 0; i--) { for (int p : jobs[i]) { q.push(p); } if (!q.empty()) { ans += q.top(); q.pop(); } } cout << ans << endl; }
insert
13
13
13
15
0
p02948
C++
Runtime Error
#include <algorithm> #include <cstdio> using namespace std; struct node { int x, y; } a[100005]; bool cmp(node a, node b) { return a.y > b.y || (a.y == b.y && a.x < b.x); } int n, m, i, ans, f[100005]; int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); } int main() { scanf("%d%d", &n, &m); m++; for (i = 1; i <= n; i++) scanf("%d%d", &a[i].x, &a[i].y); sort(a + 1, a + n + 1, cmp); for (i = 1; i <= m; i++) f[i] = i; for (i = 1; i <= n; i++) if (find(f[m - a[i].x])) ans += a[i].y, f[find(f[m - a[i].x])] = f[find(f[m - a[i].x] - 1)]; printf("%d\n", ans); return 0; }
#include <algorithm> #include <cstdio> using namespace std; struct node { int x, y; } a[100005]; bool cmp(node a, node b) { return a.y > b.y || (a.y == b.y && a.x < b.x); } int n, m, i, ans, f[100005]; int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); } int main() { scanf("%d%d", &n, &m); m++; for (i = 1; i <= n; i++) scanf("%d%d", &a[i].x, &a[i].y); sort(a + 1, a + n + 1, cmp); for (i = 1; i <= m; i++) f[i] = i; for (i = 1; i <= n; i++) if (m > a[i].x && find(f[m - a[i].x])) ans += a[i].y, f[find(f[m - a[i].x])] = f[find(f[m - a[i].x]) - 1]; printf("%d\n", ans); return 0; }
replace
18
20
18
20
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int n, m; vector<int> vs[100000]; int main() { cin >> n >> m; for (int i = 0; i < n; ++i) { int a, b; cin >> a >> b; if (m - a < 0) continue; vs[m - a].push_back(b); } priority_queue<int> q; long ans = 0; for (int j = m; j >= 0; --j) { for (int c : vs[j]) { q.push(c); } if (q.empty()) continue; ans += q.top(); q.pop(); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int n, m; vector<int> vs[100001]; int main() { cin >> n >> m; for (int i = 0; i < n; ++i) { int a, b; cin >> a >> b; if (m - a < 0) continue; vs[m - a].push_back(b); } priority_queue<int> q; long ans = 0; for (int j = m; j >= 0; --j) { for (int c : vs[j]) { q.push(c); } if (q.empty()) continue; ans += q.top(); q.pop(); } cout << ans << endl; }
replace
4
5
4
5
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define leading \ zero str.erase(0, min(str.find_first_not_of('0'), str.size() - 1)); using namespace __gnu_pbds; using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; string text = "abcdefghijklmnopqrstuvwxyz"; const int maxn = 1e6 + 7; // .--------------. // | Try First One| // '--------------' // | .--------------. // | | | // V V | // .--------------. | // | AC. |<---. | // '--------------' | | // (True)| |(False) | | // .--------' | | | // | V | | // | .--------------. | | // | | Try Again |----' | // | '--------------' | // | | // | .--------------. | // '->| Try Next One |-------' // '--------------' int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; vector<int> v[n + 2]; priority_queue<int> pq; ll ans = 0; for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; v[a].push_back(b); } for (int i = 1; i <= m; i++) { for (auto x : v[i]) pq.push(x); if (!pq.empty()) { ans += pq.top(); pq.pop(); } } cout << ans << endl; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define leading \ zero str.erase(0, min(str.find_first_not_of('0'), str.size() - 1)); using namespace __gnu_pbds; using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; string text = "abcdefghijklmnopqrstuvwxyz"; const int maxn = 1e6 + 7; // .--------------. // | Try First One| // '--------------' // | .--------------. // | | | // V V | // .--------------. | // | AC. |<---. | // '--------------' | | // (True)| |(False) | | // .--------' | | | // | V | | // | .--------------. | | // | | Try Again |----' | // | '--------------' | // | | // | .--------------. | // '->| Try Next One |-------' // '--------------' int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; vector<int> v[100005]; priority_queue<int> pq; ll ans = 0; for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; v[a].push_back(b); } for (int i = 1; i <= m; i++) { for (auto x : v[i]) pq.push(x); if (!pq.empty()) { ans += pq.top(); pq.pop(); } } cout << ans << endl; }
replace
38
39
38
39
0
p02948
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cassert> #include <climits> #include <cmath> #include <cstdint> #include <cstdio> #include <cstdlib> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; using ll = long long; using Pll = pair<ll, ll>; using Pii = pair<int, int>; constexpr ll MOD = 1000000007; constexpr long double EPS = 1e-10; constexpr int dyx[4][2] = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}}; int main() { std::ios::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; ll a, b; vector<ll> jobs[10001]; for (int i = 0; i < n; ++i) { cin >> a >> b; jobs[a].push_back(b); } priority_queue<ll> que; ll ans = 0; for (int i = m - 1; i >= 0; --i) { for (ll j : jobs[m - i]) { que.push(j); } if (!que.empty()) { ans += que.top(); que.pop(); } } cout << ans << endl; }
#include <algorithm> #include <bitset> #include <cassert> #include <climits> #include <cmath> #include <cstdint> #include <cstdio> #include <cstdlib> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; using ll = long long; using Pll = pair<ll, ll>; using Pii = pair<int, int>; constexpr ll MOD = 1000000007; constexpr long double EPS = 1e-10; constexpr int dyx[4][2] = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}}; int main() { std::ios::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; ll a, b; vector<ll> jobs[100001]; for (int i = 0; i < n; ++i) { cin >> a >> b; jobs[a].push_back(b); } priority_queue<ll> que; ll ans = 0; for (int i = m - 1; i >= 0; --i) { for (ll j : jobs[m - i]) { que.push(j); } if (!que.empty()) { ans += que.top(); que.pop(); } } cout << ans << endl; }
replace
34
35
34
35
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N, M; cin >> N >> M; int i, j, k; int a, b; int ans = 0; pair<int, int> p[M]; priority_queue<int> q; for (i = 0; i < N; i++) { cin >> a >> b; p[i] = make_pair(a, b); } sort(p, p + N); j = 0; for (i = 1; i <= M; i++) { if (j < N) { while (i >= p[j].first) { q.push(p[j].second); j++; if (j >= N) break; } } if (!q.empty()) { ans += q.top(); q.pop(); } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N, M; cin >> N >> M; int i, j, k; int a, b; int ans = 0; pair<int, int> p[N]; priority_queue<int> q; for (i = 0; i < N; i++) { cin >> a >> b; p[i] = make_pair(a, b); } sort(p, p + N); j = 0; for (i = 1; i <= M; i++) { if (j < N) { while (i >= p[j].first) { q.push(p[j].second); j++; if (j >= N) break; } } if (!q.empty()) { ans += q.top(); q.pop(); } } cout << ans << endl; }
replace
9
10
9
10
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> /* #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; */ using namespace std; #if DEBUG && !ONLINE_JUDGE #include "debug.h" #else #define debug(...) #endif typedef long long ll; typedef vector<int> vi; typedef pair<int, int> ii; typedef vector<vector<int>> vvi; typedef vector<vector<ii>> vvii; #define pb push_back #define mp make_pair #define all(x) x.begin(), x.end() #define sz(x) (int)x.size() #define fill(a, x) memset(a, x, sizeof(a)) #define ff first #define ss second #define trav(a, x) for (auto &a : x) #define FOR(i, a, b) for (int i = a; i <= b; ++i) #define NFOR(i, a, b) for (int i = a; i >= b; --i) const ll INF = 1e18; const int mod = 1e9 + 7; ll gcd(ll a, ll b) { if (a == 0) return b; return gcd(b % a, a); } ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); } ll Abs(ll a) { if (a > 0) return a; return -a; } ll Ceil(ll a, ll b) { if (a % b == 0) return a / b; else return a / b + 1; } double Abs(double a) { if (a > 0) return a; return -a; } //*X.find_by_order(2) element at index=2 // X.order_of_key(1) how many elements strictly less than 1 // #define ordered_set tree<int, null_type,less_equal<int>, // rb_tree_tag,tree_order_statistics_NOde_update> inline int pow_(ll x, ll y, ll p) { int r = 1; while (y) { if (y & 1) r = r * x % p; y >>= 1; x = x * x % p; } return r; } inline int inv_(int x) { return pow_(x, mod - 2, mod); } inline int add(int a, int b) { a += b; if (a >= mod) a -= mod; return a; } inline int mul(int a, int b) { return a * 1LL * b % mod; } inline int sub(int a, int b) { a -= b; if (a < 0) a += mod; return a; } int main() { #ifdef LOCAL_TEST freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); #else ios_base::sync_with_stdio(false); cin.tie(NULL); #endif ll n, m; cin >> n >> m; vector<ii> v; for (int i = 1; i <= n; i++) { int a, b; cin >> a >> b; v.pb(mp(a, b)); } sort(all(v)); priority_queue<int, vi> Q; ll ans = 0; ll p = 0; for (int i = m - 1; i >= 0; i--) { while (v[p].first + i <= m) { Q.push(v[p].second); p++; } if (!Q.empty()) { ll val = Q.top(); Q.pop(); ans += val; } } cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> /* #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; */ using namespace std; #if DEBUG && !ONLINE_JUDGE #include "debug.h" #else #define debug(...) #endif typedef long long ll; typedef vector<int> vi; typedef pair<int, int> ii; typedef vector<vector<int>> vvi; typedef vector<vector<ii>> vvii; #define pb push_back #define mp make_pair #define all(x) x.begin(), x.end() #define sz(x) (int)x.size() #define fill(a, x) memset(a, x, sizeof(a)) #define ff first #define ss second #define trav(a, x) for (auto &a : x) #define FOR(i, a, b) for (int i = a; i <= b; ++i) #define NFOR(i, a, b) for (int i = a; i >= b; --i) const ll INF = 1e18; const int mod = 1e9 + 7; ll gcd(ll a, ll b) { if (a == 0) return b; return gcd(b % a, a); } ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); } ll Abs(ll a) { if (a > 0) return a; return -a; } ll Ceil(ll a, ll b) { if (a % b == 0) return a / b; else return a / b + 1; } double Abs(double a) { if (a > 0) return a; return -a; } //*X.find_by_order(2) element at index=2 // X.order_of_key(1) how many elements strictly less than 1 // #define ordered_set tree<int, null_type,less_equal<int>, // rb_tree_tag,tree_order_statistics_NOde_update> inline int pow_(ll x, ll y, ll p) { int r = 1; while (y) { if (y & 1) r = r * x % p; y >>= 1; x = x * x % p; } return r; } inline int inv_(int x) { return pow_(x, mod - 2, mod); } inline int add(int a, int b) { a += b; if (a >= mod) a -= mod; return a; } inline int mul(int a, int b) { return a * 1LL * b % mod; } inline int sub(int a, int b) { a -= b; if (a < 0) a += mod; return a; } int main() { #ifdef LOCAL_TEST freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); #else ios_base::sync_with_stdio(false); cin.tie(NULL); #endif ll n, m; cin >> n >> m; vector<ii> v; for (int i = 1; i <= n; i++) { int a, b; cin >> a >> b; v.pb(mp(a, b)); } sort(all(v)); priority_queue<int, vi> Q; ll ans = 0; ll p = 0; for (int i = m - 1; i >= 0; i--) { while (p < v.size() && v[p].first + i <= m) { Q.push(v[p].second); p++; } if (!Q.empty()) { ll val = Q.top(); Q.pop(); ans += val; } } cout << ans << "\n"; return 0; }
replace
110
111
110
111
0
p02948
C++
Time Limit Exceeded
#define _GLIBCXX_DEBUG // 空コンテナ操作禁止 Clang環境では#define _LIBCPP_DEBUG // 0 #include <algorithm> #include <bitset> #include <cmath> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; using ll = long long; using Pi = pair<int, int>; using Pl = pair<ll, ll>; int main() { int N, M; cin >> N >> M; vector<pair<int, int>> p; // firstがA日後に入金、second 入金額 int tmpA, tmpB; pair<int, int> tmpP; priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> arbeit; for (int i = 0; i < N; i++) { cin >> tmpA >> tmpB; tmpP = make_pair(tmpA, tmpB); arbeit.push(tmpP); } /* for( int i=0; i<N; i++ ){ cout << arbeit.top().first << " " << arbeit.top().second << endl; arbeit.pop(); }*/ priority_queue<int> pq; int earn = 0; for (int day = 1; day <= M; day++) { // printf( "Day %d\n", day ); while (!arbeit.empty() && arbeit.top().first == day) { pq.push(arbeit.top().second); arbeit.pop(); } if (pq.empty()) continue; earn += pq.top(); pq.pop(); } cout << earn; return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; using ll = long long; using Pi = pair<int, int>; using Pl = pair<ll, ll>; int main() { int N, M; cin >> N >> M; vector<pair<int, int>> p; // firstがA日後に入金、second 入金額 int tmpA, tmpB; pair<int, int> tmpP; priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> arbeit; for (int i = 0; i < N; i++) { cin >> tmpA >> tmpB; tmpP = make_pair(tmpA, tmpB); arbeit.push(tmpP); } /* for( int i=0; i<N; i++ ){ cout << arbeit.top().first << " " << arbeit.top().second << endl; arbeit.pop(); }*/ priority_queue<int> pq; int earn = 0; for (int day = 1; day <= M; day++) { // printf( "Day %d\n", day ); while (!arbeit.empty() && arbeit.top().first == day) { pq.push(arbeit.top().second); arbeit.pop(); } if (pq.empty()) continue; earn += pq.top(); pq.pop(); } cout << earn; return 0; }
delete
0
2
0
0
TLE
p02948
C++
Runtime Error
// include //------------------------------------------ #include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; // conversion //------------------------------------------ inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } // math //------------------------------------------- template <class T> inline T sqr(T x) { return x * x; } // typedef //------------------------------------------ typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef long long LL; // container util //------------------------------------------ #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define EXISTch(s, c) \ ((((s).find_first_of(c)) != std::string::npos) ? 1 : 0) // cがあれば1 if(1) #define SORT(c) sort((c).begin(), (c).end()) #define REP(i, n) for (int i = 0; i < (int)n; ++i) #define FOR(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) // constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); const int INF = (int)1000000007; const LL MOD = (LL)1000000007; // 10^9+7 const LL INF2 = (LL)100000000000000000; // 10^18 int main() { LL n, m; cin >> n >> m; vector<vector<int>> d(m + 1, vector<int>()); for (int i = 0; i < n; i++) { LL a, b; cin >> a >> b; d[a].push_back(b); } priority_queue<LL> que; LL ans = 0; for (int i = 1; i < m + 1; i++) { for (int j = 0; j < d[i].size(); j++) { que.push(d[i][j]); } if (!que.empty()) { ans += que.top(); que.pop(); } } cout << ans << endl; return 0; }
// include //------------------------------------------ #include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; // conversion //------------------------------------------ inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } // math //------------------------------------------- template <class T> inline T sqr(T x) { return x * x; } // typedef //------------------------------------------ typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef long long LL; // container util //------------------------------------------ #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define EXISTch(s, c) \ ((((s).find_first_of(c)) != std::string::npos) ? 1 : 0) // cがあれば1 if(1) #define SORT(c) sort((c).begin(), (c).end()) #define REP(i, n) for (int i = 0; i < (int)n; ++i) #define FOR(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) // constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); const int INF = (int)1000000007; const LL MOD = (LL)1000000007; // 10^9+7 const LL INF2 = (LL)100000000000000000; // 10^18 int main() { LL n, m; cin >> n >> m; vector<vector<int>> d(100010, vector<int>()); for (int i = 0; i < n; i++) { LL a, b; cin >> a >> b; d[a].push_back(b); } priority_queue<LL> que; LL ans = 0; for (int i = 1; i < m + 1; i++) { for (int j = 0; j < d[i].size(); j++) { que.push(d[i][j]); } if (!que.empty()) { ans += que.top(); que.pop(); } } cout << ans << endl; return 0; }
replace
87
88
87
88
0
p02948
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> #define MOD 1000000007 using namespace std; typedef pair<int, int> P; typedef pair<long long, long long> LLP; int main() { int M, N; cin >> N >> M; vector<int> works[10001]; for (int i = 0; i < N; i++) { int A, B; cin >> A >> B; works[A].push_back(B); } priority_queue<int> que; long long score = 0; for (int i = 1; i <= M; i++) { for (int j = 0; j < works[i].size(); j++) { que.push(works[i][j]); } if (!que.empty()) { score += que.top(); que.pop(); } } cout << score << endl; return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> #define MOD 1000000007 using namespace std; typedef pair<int, int> P; typedef pair<long long, long long> LLP; int main() { int M, N; cin >> N >> M; vector<int> works[100001]; for (int i = 0; i < N; i++) { int A, B; cin >> A >> B; works[A].push_back(B); } priority_queue<int> que; long long score = 0; for (int i = 1; i <= M; i++) { for (int j = 0; j < works[i].size(); j++) { que.push(works[i][j]); } if (!que.empty()) { score += que.top(); que.pop(); } } cout << score << endl; return 0; }
replace
25
26
25
26
0
p02948
Python
Time Limit Exceeded
import heapq N, M = map(int, input().split()) dic = {} for i in range(N): A, B = map(int, input().split()) if A not in dic: dic[A] = [-B] else: dic[A].append(-B) # print(dic, sorted(dic.keys())) ans = 0 heap = [] for i in range(M): # print(i) if i + 1 in dic: heap.extend(dic[i + 1]) heapq.heapify(heap) # print(heap) if heap: ans = ans - heapq.heappop(heap) print(ans)
import heapq N, M = map(int, input().split()) dic = {} for i in range(N): A, B = map(int, input().split()) if A not in dic: dic[A] = [-B] else: dic[A].append(-B) # print(dic, sorted(dic.keys())) ans = 0 heap = [] for i in range(M): # print(i) if i + 1 in dic: for j in dic[i + 1]: heapq.heappush(heap, j) # print(heap) if heap: ans = ans - heapq.heappop(heap) print(ans)
replace
18
20
18
20
TLE
p02948
Python
Runtime Error
import heapq n, m = map(int, input().split()) lis = [] for i in range(n + 1): lis.append([]) for i in range(n): a, b = map(int, input().split()) if a <= m: lis[a].append(-b) cnd = [] heapq.heapify(cnd) res = 0 for j in range(1, m + 1): for e in lis[j]: heapq.heappush(cnd, e) if cnd: res += -heapq.heappop(cnd) print(res)
import heapq n, m = map(int, input().split()) lis = [] for i in range(m + 1): lis.append([]) for i in range(n): a, b = map(int, input().split()) if a <= m: lis[a].append(-b) cnd = [] heapq.heapify(cnd) res = 0 for j in range(1, m + 1): for e in lis[j]: heapq.heappush(cnd, e) if cnd: res += -heapq.heappop(cnd) print(res)
replace
4
5
4
5
IndexError: list index out of range
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02948/Python/s323852775.py", line 11, in <module> lis[a].append(-b) IndexError: list index out of range
p02948
Python
Runtime Error
from heapq import heappop, heapify, heappush def main(): n, m = map(int, input().split()) work = [[] for _ in range(10**4 + 1)] for _ in range(n): a, b = map(int, input().split()) work[a].append(b) ans = 0 q = [] heapify(q) for i in range(1, m + 1): for w in work[i]: heappush(q, -w) if len(q) == 0: continue ans += heappop(q) ans *= -1 print(ans) if __name__ == "__main__": main()
from heapq import heappop, heapify, heappush def main(): n, m = map(int, input().split()) work = [[] for _ in range(10**5 + 1)] for _ in range(n): a, b = map(int, input().split()) work[a].append(b) ans = 0 q = [] heapify(q) for i in range(1, m + 1): for w in work[i]: heappush(q, -w) if len(q) == 0: continue ans += heappop(q) ans *= -1 print(ans) if __name__ == "__main__": main()
replace
5
6
5
6
0
p02948
C++
Runtime Error
#include <algorithm> #include <iostream> using namespace std; const int N = 100005; int tree[2 * N + 5]; struct record { int a, b; }; record arr[N]; void update(int node, int start, int end, int idx, int val) { if (start == end) { tree[node] += val; } else { int mid = (start + end) / 2; if (start <= idx && idx <= mid) { update(node * 2, start, mid, idx, val); } else { update(node * 2 + 1, mid + 1, end, idx, val); } tree[node] = tree[node * 2] + tree[node * 2 + 1]; } } int query(int node, int start, int end, int l, int r) { if (l > end || r < start) return 0; if (l <= start && end <= r) return tree[node]; int mid = (start + end) / 2; int t1 = query(node * 2, start, mid, l, r); int t2 = query(node * 2 + 1, mid + 1, end, l, r); return t1 + t2; } int find_l(int start, int end) { int a = start, m = end; int result = -1; while (start <= end) { int mid = (start + end) / 2; int slot = query(1, 1, m, a, mid); if (slot < mid - a + 1) { result = mid; end = mid - 1; } else { start = mid + 1; } } return result; } bool compare(record x, record y) { if (x.b == y.b) { return x.a < y.a; } return x.b > y.b; } int main() { int n, m; cin >> n >> m; for (int i = 1; i <= n; ++i) { cin >> arr[i].a >> arr[i].b; } sort(arr + 1, arr + 1 + n, compare); /* cout << endl; for(int i = 1; i <=n; ++i){ cout << arr[i].b << " " << arr[i].a << endl; } */ int result = 0; for (int i = 1; i <= n; ++i) { int a = arr[i].a; int b = arr[i].b; if (a > m) continue; int slot = query(1, 1, m, a, m); if (slot < m - a + 1) { result += b; int l = find_l(a, m); update(1, 1, m, l, 1); } } cout << result << endl; return 0; }
#include <algorithm> #include <iostream> using namespace std; const int N = 100005; int tree[4 * N + 5]; struct record { int a, b; }; record arr[N]; void update(int node, int start, int end, int idx, int val) { if (start == end) { tree[node] += val; } else { int mid = (start + end) / 2; if (start <= idx && idx <= mid) { update(node * 2, start, mid, idx, val); } else { update(node * 2 + 1, mid + 1, end, idx, val); } tree[node] = tree[node * 2] + tree[node * 2 + 1]; } } int query(int node, int start, int end, int l, int r) { if (l > end || r < start) return 0; if (l <= start && end <= r) return tree[node]; int mid = (start + end) / 2; int t1 = query(node * 2, start, mid, l, r); int t2 = query(node * 2 + 1, mid + 1, end, l, r); return t1 + t2; } int find_l(int start, int end) { int a = start, m = end; int result = -1; while (start <= end) { int mid = (start + end) / 2; int slot = query(1, 1, m, a, mid); if (slot < mid - a + 1) { result = mid; end = mid - 1; } else { start = mid + 1; } } return result; } bool compare(record x, record y) { if (x.b == y.b) { return x.a < y.a; } return x.b > y.b; } int main() { int n, m; cin >> n >> m; for (int i = 1; i <= n; ++i) { cin >> arr[i].a >> arr[i].b; } sort(arr + 1, arr + 1 + n, compare); /* cout << endl; for(int i = 1; i <=n; ++i){ cout << arr[i].b << " " << arr[i].a << endl; } */ int result = 0; for (int i = 1; i <= n; ++i) { int a = arr[i].a; int b = arr[i].b; if (a > m) continue; int slot = query(1, 1, m, a, m); if (slot < m - a + 1) { result += b; int l = find_l(a, m); update(1, 1, m, l, 1); } } cout << result << endl; return 0; }
replace
6
7
6
7
0
p02948
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cassert> #include <cfloat> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits.h> #include <list> #include <map> #include <math.h> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } using namespace std; #define int long long #define ll long long #define rep(i, n) for (ll i = 0; i < (n); i++) #define P pair<ll, ll> #define sz(x) (ll) x.size() #define ALL(x) (x).begin(), (x).end() #define ALLR(x) (x).rbegin(), (x).rend() #define VE vector<ll> #define COUT(x) cout << (x) << endl #define MA map<ll, ll> #define SE set<ll> #define PQ priority_queue<ll> #define PQR priority_queue<ll, VE, greater<ll>> #define YES(n) cout << ((n) ? "YES" : "NO") << endl #define Yes(n) cout << ((n) ? "Yes" : "No") << endl #define EPS (1e-10) #define pb push_back long long MOD = 1000000007; // const long long MOD = 998244353; const long long INF = 1LL << 60; const double PI = acos(-1.0); struct mint { ll x; // typedef long long ll; mint(ll x = 0) : x((x % MOD + MOD) % MOD) {} mint operator-() const { return mint(-x); } mint &operator+=(const mint a) { if ((x += a.x) >= MOD) x -= MOD; return *this; } mint &operator-=(const mint a) { if ((x += MOD - a.x) >= MOD) x -= MOD; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= MOD; return *this; } mint operator+(const mint a) const { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime MOD mint inv() const { return pow(MOD - 2); } mint &operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res /= a; } }; istream &operator>>(istream &is, const mint &a) { return is >> a.x; } ostream &operator<<(ostream &os, const mint &a) { return os << a.x; } struct Sieve { int n; vector<int> f, primes; Sieve(int n = 1) : n(n), f(n + 1) { f[0] = f[1] = -1; for (ll i = 2; i <= n; ++i) { if (f[i]) continue; primes.push_back(i); f[i] = i; for (ll j = i * i; j <= n; j += i) { if (!f[j]) f[j] = i; } } } bool isPrime(int x) { return f[x] == x; } vector<int> factorList(int x) { vector<int> res; while (x != 1) { res.push_back(f[x]); x /= f[x]; } return res; } vector<P> factor(int x) { vector<int> fl = factorList(x); if (fl.size() == 0) return {}; vector<P> res(1, P(fl[0], 0)); for (int p : fl) { if (res.back().first == p) { res.back().second++; } else { res.emplace_back(p, 1); } } return res; } }; template <class t> t gcd(t a, t b) { return b != 0 ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; } bool prime(ll n) { for (ll i = 2; i <= sqrt(n); i++) { if (n % i == 0) return false; } return n != 1; } map<ll, ll> prime_factor(ll n) { map<ll, ll> ret; for (ll i = 2; i * i <= n; i++) { while (n % i == 0) { ret[i]++; n /= i; } } if (n != 1) ret[n] = 1; return ret; } ll modinv(ll a, ll m) { ll b = m, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } vector<pair<char, int>> RunLength(string s) { if (s.size() == 0) return {}; vector<pair<char, int>> res(1, pair<char, int>(s[0], 0)); for (char p : s) { if (res.back().first == p) { res.back().second++; } else { res.emplace_back(p, 1); } } return res; } // Digit Count int GetDigit(int num) { return log10(num) + 1; } // bit calculation[how many "1"] (= __builtin_popcount()) int bit_count(int n) { int cnt = 0; while (n > 0) { if (n % 2 == 1) cnt++; n /= 2; } return cnt; } vector<long long> enum_divisors(long long N) { vector<long long> res; for (long long i = 1; i * i <= N; ++i) { if (N % i == 0) { res.push_back(i); if (N / i != i) res.push_back(N / i); } } sort(res.begin(), res.end()); return res; } const ll dx[4] = {1, 0, -1, 0}; const ll dy[4] = {0, 1, 0, -1}; struct edge { ll to, cost; }; typedef long double ld; using Graph = vector<vector<int>>; class UnionFind { public: vector<ll> par; // 各元の親を表す配列 vector<ll> siz; // 素集合のサイズを表す配列(1 で初期化) // Constructor UnionFind(ll sz_) : par(sz_), siz(sz_, 1) { for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身 } void init(ll sz_) { par.resize(sz_); siz.resize(sz_, 1); for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身 } // Member Function // Find ll root(ll x) { // 根の検索 while (par[x] != x) { x = par[x] = par[par[x]]; // x の親の親を x の親とする } return x; } // Union(Unite, Merge) bool merge(ll x, ll y) { x = root(x); y = root(y); if (x == y) return false; // merge technique(データ構造をマージするテク.小を大にくっつける) if (siz[x] < siz[y]) swap(x, y); siz[x] += siz[y]; par[y] = x; return true; } bool issame(ll x, ll y) { // 連結判定 return root(x) == root(y); } ll size(ll x) { // 素集合のサイズ return siz[root(x)]; } }; struct combination { vector<mint> fact, ifact; combination(int n) : fact(n + 1), ifact(n + 1) { // assert(n < mod); fact[0] = 1; for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i; ifact[n] = fact[n].inv(); for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i; } mint operator()(int n, int k) { if (k < 0 || k > n) return 0; return fact[n] * ifact[k] * ifact[n - k]; } }; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // cout << fixed << setprecision(20); // combination com(200010); int n, m; cin >> n >> m; vector<VE> now(m + 1); rep(i, n) { int a, b; cin >> a >> b; now[a].push_back(b); } int ans = 0; priority_queue<int> que; for (int i = 1; i <= m; i++) { rep(j, now[i].size()) { que.push(now[i][j]); } if (que.size()) { ans += que.top(); que.pop(); } } cout << ans << endl; return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cfloat> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits.h> #include <list> #include <map> #include <math.h> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } using namespace std; #define int long long #define ll long long #define rep(i, n) for (ll i = 0; i < (n); i++) #define P pair<ll, ll> #define sz(x) (ll) x.size() #define ALL(x) (x).begin(), (x).end() #define ALLR(x) (x).rbegin(), (x).rend() #define VE vector<ll> #define COUT(x) cout << (x) << endl #define MA map<ll, ll> #define SE set<ll> #define PQ priority_queue<ll> #define PQR priority_queue<ll, VE, greater<ll>> #define YES(n) cout << ((n) ? "YES" : "NO") << endl #define Yes(n) cout << ((n) ? "Yes" : "No") << endl #define EPS (1e-10) #define pb push_back long long MOD = 1000000007; // const long long MOD = 998244353; const long long INF = 1LL << 60; const double PI = acos(-1.0); struct mint { ll x; // typedef long long ll; mint(ll x = 0) : x((x % MOD + MOD) % MOD) {} mint operator-() const { return mint(-x); } mint &operator+=(const mint a) { if ((x += a.x) >= MOD) x -= MOD; return *this; } mint &operator-=(const mint a) { if ((x += MOD - a.x) >= MOD) x -= MOD; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= MOD; return *this; } mint operator+(const mint a) const { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime MOD mint inv() const { return pow(MOD - 2); } mint &operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res /= a; } }; istream &operator>>(istream &is, const mint &a) { return is >> a.x; } ostream &operator<<(ostream &os, const mint &a) { return os << a.x; } struct Sieve { int n; vector<int> f, primes; Sieve(int n = 1) : n(n), f(n + 1) { f[0] = f[1] = -1; for (ll i = 2; i <= n; ++i) { if (f[i]) continue; primes.push_back(i); f[i] = i; for (ll j = i * i; j <= n; j += i) { if (!f[j]) f[j] = i; } } } bool isPrime(int x) { return f[x] == x; } vector<int> factorList(int x) { vector<int> res; while (x != 1) { res.push_back(f[x]); x /= f[x]; } return res; } vector<P> factor(int x) { vector<int> fl = factorList(x); if (fl.size() == 0) return {}; vector<P> res(1, P(fl[0], 0)); for (int p : fl) { if (res.back().first == p) { res.back().second++; } else { res.emplace_back(p, 1); } } return res; } }; template <class t> t gcd(t a, t b) { return b != 0 ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; } bool prime(ll n) { for (ll i = 2; i <= sqrt(n); i++) { if (n % i == 0) return false; } return n != 1; } map<ll, ll> prime_factor(ll n) { map<ll, ll> ret; for (ll i = 2; i * i <= n; i++) { while (n % i == 0) { ret[i]++; n /= i; } } if (n != 1) ret[n] = 1; return ret; } ll modinv(ll a, ll m) { ll b = m, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } vector<pair<char, int>> RunLength(string s) { if (s.size() == 0) return {}; vector<pair<char, int>> res(1, pair<char, int>(s[0], 0)); for (char p : s) { if (res.back().first == p) { res.back().second++; } else { res.emplace_back(p, 1); } } return res; } // Digit Count int GetDigit(int num) { return log10(num) + 1; } // bit calculation[how many "1"] (= __builtin_popcount()) int bit_count(int n) { int cnt = 0; while (n > 0) { if (n % 2 == 1) cnt++; n /= 2; } return cnt; } vector<long long> enum_divisors(long long N) { vector<long long> res; for (long long i = 1; i * i <= N; ++i) { if (N % i == 0) { res.push_back(i); if (N / i != i) res.push_back(N / i); } } sort(res.begin(), res.end()); return res; } const ll dx[4] = {1, 0, -1, 0}; const ll dy[4] = {0, 1, 0, -1}; struct edge { ll to, cost; }; typedef long double ld; using Graph = vector<vector<int>>; class UnionFind { public: vector<ll> par; // 各元の親を表す配列 vector<ll> siz; // 素集合のサイズを表す配列(1 で初期化) // Constructor UnionFind(ll sz_) : par(sz_), siz(sz_, 1) { for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身 } void init(ll sz_) { par.resize(sz_); siz.resize(sz_, 1); for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身 } // Member Function // Find ll root(ll x) { // 根の検索 while (par[x] != x) { x = par[x] = par[par[x]]; // x の親の親を x の親とする } return x; } // Union(Unite, Merge) bool merge(ll x, ll y) { x = root(x); y = root(y); if (x == y) return false; // merge technique(データ構造をマージするテク.小を大にくっつける) if (siz[x] < siz[y]) swap(x, y); siz[x] += siz[y]; par[y] = x; return true; } bool issame(ll x, ll y) { // 連結判定 return root(x) == root(y); } ll size(ll x) { // 素集合のサイズ return siz[root(x)]; } }; struct combination { vector<mint> fact, ifact; combination(int n) : fact(n + 1), ifact(n + 1) { // assert(n < mod); fact[0] = 1; for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i; ifact[n] = fact[n].inv(); for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i; } mint operator()(int n, int k) { if (k < 0 || k > n) return 0; return fact[n] * ifact[k] * ifact[n - k]; } }; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // cout << fixed << setprecision(20); // combination com(200010); int n, m; cin >> n >> m; vector<VE> now(m + 100010); rep(i, n) { int a, b; cin >> a >> b; now[a].push_back(b); } int ans = 0; priority_queue<int> que; for (int i = 1; i <= m; i++) { rep(j, now[i].size()) { que.push(now[i][j]); } if (que.size()) { ans += que.top(); que.pop(); } } cout << ans << endl; return 0; }
replace
317
318
317
318
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; const int mod = 1000000007; void solve() { int n, m; cin >> n >> m; vector<vector<int>> jobs(n + 1); rep(i, n) { int a, b; cin >> a >> b; if (a > m) continue; jobs[m - a].push_back(b); } priority_queue<int> q; ll ans = 0; for (int i = m - 1; i >= 0; i--) { for (auto x : jobs[i]) { q.push(x); } if (!q.empty()) { int temp = q.top(); ans += temp; q.pop(); } } cout << ans; } int main() { int y; y = 1; // cin>>y ; while (y--) { solve(); } }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; const int mod = 1000000007; void solve() { int n, m; cin >> n >> m; vector<vector<int>> jobs(m + 1); rep(i, n) { int a, b; cin >> a >> b; if (a > m) continue; jobs[m - a].push_back(b); } priority_queue<int> q; ll ans = 0; for (int i = m - 1; i >= 0; i--) { for (auto x : jobs[i]) { q.push(x); } if (!q.empty()) { int temp = q.top(); ans += temp; q.pop(); } } cout << ans; } int main() { int y; y = 1; // cin>>y ; while (y--) { solve(); } }
replace
10
11
10
11
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int n, m; cin >> n >> m; vector<int> a[10001]; for (int i = 0; i < n; i++) { int b, c; cin >> b >> c; a[b].push_back(c); } int ans = 0; priority_queue<int> q; for (int i = 1; i <= m; i++) { for (int x : a[i]) q.push(x); if (q.size()) { ans += q.top(); q.pop(); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int n, m; cin >> n >> m; vector<int> a[100001]; for (int i = 0; i < n; i++) { int b, c; cin >> b >> c; a[b].push_back(c); } int ans = 0; priority_queue<int> q; for (int i = 1; i <= m; i++) { for (int x : a[i]) q.push(x); if (q.size()) { ans += q.top(); q.pop(); } } cout << ans << endl; return 0; }
replace
7
8
7
8
0
p02948
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <stack> using namespace std; typedef long long ll; struct node { int a, b; bool operator<(const node &T) const { if (T.a == a) return b < T.b; return a < T.a; } }; node a[1111] = {0}; int main() { ios::sync_with_stdio(false); cin.tie(); int n, k, m, d; cin >> n >> d; for (int i = 0; i < n; i++) { cin >> a[i].a >> a[i].b; } sort(a, a + n); priority_queue<int> q; while (!q.empty()) { q.pop(); } long long sum = 0; int ind = 0; for (int i = 1; i <= d; i++) { while (ind < n && a[ind].a <= i) { q.push(a[ind].b); ind++; } if (!q.empty()) { // cout << q.top() << endl; sum += q.top(); q.pop(); } } cout << sum << endl; return 0; }
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <stack> using namespace std; typedef long long ll; struct node { int a, b; bool operator<(const node &T) const { if (T.a == a) return b < T.b; return a < T.a; } }; node a[111100] = {0}; int main() { ios::sync_with_stdio(false); cin.tie(); int n, k, m, d; cin >> n >> d; for (int i = 0; i < n; i++) { cin >> a[i].a >> a[i].b; } sort(a, a + n); priority_queue<int> q; while (!q.empty()) { q.pop(); } long long sum = 0; int ind = 0; for (int i = 1; i <= d; i++) { while (ind < n && a[ind].a <= i) { q.push(a[ind].b); ind++; } if (!q.empty()) { // cout << q.top() << endl; sum += q.top(); q.pop(); } } cout << sum << endl; return 0; }
replace
17
18
17
18
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> #define fi first #define se second #define rep(i, n) for (int i = 0; i < (n); ++i) #define rrep(i, n) for (int i = 1; i <= (n); ++i) #define drep(i, n) for (int i = (n)-1; i >= 0; --i) #define srep(i, s, t) for (int i = s; i < t; ++i) #define rng(a) a.begin(), a.end() #define rrng(a) a.rbegin(), a.rend() #define maxs(x, y) (x = max(x, y)) #define mins(x, y) (x = min(x, y)) #define limit(x, l, r) max(l, min(x, r)) #define lims(x, l, r) (x = max(l, min(x, r))) #define isin(x, l, r) ((l) <= (x) && (x) < (r)) #define pb push_back #define eb emplace_back #define sz(x) (int)(x).size() #define pcnt __builtin_popcountll #define uni(x) x.erase(unique(rng(x)), x.end()) #define show(x) cout << #x << " = " << x << endl; #define print(x) cout << x << endl; #define PQ(T) priority_queue<T, v(T), greater<T>> #define bn(x) ((1 << x) - 1) #define dup(x, y) (((x) + (y)-1) / (y)) #define newline puts("") #define v(T) vector<T> #define vv(T) v(v(T)) using namespace std; typedef long long int ll; typedef unsigned uint; typedef unsigned long long ull; typedef pair<int, int> P; typedef tuple<int, int, int> T; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<P> vp; typedef vector<T> vt; int main() { int n, m; cin >> n >> m; vi G[100005]; rep(i, n) { int a, b; cin >> a >> b; G[m - a].push_back(b); } priority_queue<int> q; ll ans = 0; drep(i, m) { for (auto x : G[i]) q.push(x); if (q.empty()) continue; ans += q.top(); q.pop(); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define fi first #define se second #define rep(i, n) for (int i = 0; i < (n); ++i) #define rrep(i, n) for (int i = 1; i <= (n); ++i) #define drep(i, n) for (int i = (n)-1; i >= 0; --i) #define srep(i, s, t) for (int i = s; i < t; ++i) #define rng(a) a.begin(), a.end() #define rrng(a) a.rbegin(), a.rend() #define maxs(x, y) (x = max(x, y)) #define mins(x, y) (x = min(x, y)) #define limit(x, l, r) max(l, min(x, r)) #define lims(x, l, r) (x = max(l, min(x, r))) #define isin(x, l, r) ((l) <= (x) && (x) < (r)) #define pb push_back #define eb emplace_back #define sz(x) (int)(x).size() #define pcnt __builtin_popcountll #define uni(x) x.erase(unique(rng(x)), x.end()) #define show(x) cout << #x << " = " << x << endl; #define print(x) cout << x << endl; #define PQ(T) priority_queue<T, v(T), greater<T>> #define bn(x) ((1 << x) - 1) #define dup(x, y) (((x) + (y)-1) / (y)) #define newline puts("") #define v(T) vector<T> #define vv(T) v(v(T)) using namespace std; typedef long long int ll; typedef unsigned uint; typedef unsigned long long ull; typedef pair<int, int> P; typedef tuple<int, int, int> T; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<P> vp; typedef vector<T> vt; int main() { int n, m; cin >> n >> m; vi G[100005]; rep(i, n) { int a, b; cin >> a >> b; if (m - a >= 0) G[m - a].push_back(b); } priority_queue<int> q; ll ans = 0; drep(i, m) { for (auto x : G[i]) q.push(x); if (q.empty()) continue; ans += q.top(); q.pop(); } cout << ans << endl; return 0; }
replace
46
47
46
48
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(v) v.begin(), v.end() #define _GLIBCXX_DEBUG int main() { int n, m; cin >> n >> m; vector<int> vec[m + 1]; rep(i, n) { int a, b; cin >> a >> b; vec[a].push_back(b); } long ans = 0; priority_queue<int> q; for (int i = 1; i < m + 1; i++) { if (vec[i].size() != 0) { for (int x : vec[i]) { q.push(x); } } if (q.size() == 0) { continue; } else { ans += q.top(); q.pop(); } } 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 all(v) v.begin(), v.end() #define _GLIBCXX_DEBUG int main() { int n, m; cin >> n >> m; vector<int> vec[100010]; rep(i, n) { int a, b; cin >> a >> b; vec[a].push_back(b); } long ans = 0; priority_queue<int> q; for (int i = 1; i < m + 1; i++) { if (vec[i].size() != 0) { for (int x : vec[i]) { q.push(x); } } if (q.size() == 0) { continue; } else { ans += q.top(); q.pop(); } } cout << ans << endl; return 0; }
replace
10
11
10
11
0
p02948
C++
Runtime Error
#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 COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl template <class T1, class T2> ostream &operator<<(ostream &s, pair<T1, T2> P) { return s << '<' << P.first << ", " << P.second << '>'; } template <class T> ostream &operator<<(ostream &s, vector<T> P) { for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; } template <class T> ostream &operator<<(ostream &s, vector<vector<T>> P) { for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; } template <class T> ostream &operator<<(ostream &s, set<T> P) { for (auto it : P) { s << "<" << it << "> "; } return s << endl; } template <class T1, class T2> ostream &operator<<(ostream &s, map<T1, T2> P) { for (auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; } int main() { int N, M; cin >> N >> M; vector<vector<long long>> all(M, vector<long long>()); for (int i = 0; i < N; ++i) { long long A, B; cin >> A >> B; if (A > M) continue; all[A - 1].push_back(B); } long long res = 0; priority_queue<long long> que; for (int d = 0; d < N; ++d) { for (auto v : all[d]) que.push(v); if (!que.empty()) { res += que.top(); que.pop(); } } cout << res << endl; }
#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 COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl template <class T1, class T2> ostream &operator<<(ostream &s, pair<T1, T2> P) { return s << '<' << P.first << ", " << P.second << '>'; } template <class T> ostream &operator<<(ostream &s, vector<T> P) { for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; } template <class T> ostream &operator<<(ostream &s, vector<vector<T>> P) { for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; } template <class T> ostream &operator<<(ostream &s, set<T> P) { for (auto it : P) { s << "<" << it << "> "; } return s << endl; } template <class T1, class T2> ostream &operator<<(ostream &s, map<T1, T2> P) { for (auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; } int main() { int N, M; cin >> N >> M; vector<vector<long long>> all(M, vector<long long>()); for (int i = 0; i < N; ++i) { long long A, B; cin >> A >> B; if (A > M) continue; all[A - 1].push_back(B); } long long res = 0; priority_queue<long long> que; for (int d = 0; d < M; ++d) { for (auto v : all[d]) que.push(v); if (!que.empty()) { res += que.top(); que.pop(); } } cout << res << endl; }
replace
62
63
62
63
0
p02948
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; #define fi first #define se second #define mp make_pair #define rep(i, n) for (int i = 0; i < n; ++i) #define rrep(i, n) for (int i = n; i >= 0; --i) const int inf = 1e9 + 7; const ll mod = 1e9 + 7; const ll big = 1e18; const double PI = 2 * asin(1); int main() { int N, M; cin >> N >> M; vector<vector<int>> arr(M); int A, B; for (int i = 0; i < N; ++i) { cin >> A >> B; A--; arr[A].push_back(B); } multiset<int> st; auto index = st.begin(); int ans = 0; for (int i = 0; i < M; ++i) { for (int j = 0; j < arr[i].size(); ++j) st.insert(arr[i][j]); if (st.size() == 0) continue; index = st.end(); index--; ans += *index; st.erase(st.find(*index)); } cout << ans << endl; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; #define fi first #define se second #define mp make_pair #define rep(i, n) for (int i = 0; i < n; ++i) #define rrep(i, n) for (int i = n; i >= 0; --i) const int inf = 1e9 + 7; const ll mod = 1e9 + 7; const ll big = 1e18; const double PI = 2 * asin(1); int main() { int N, M; cin >> N >> M; vector<vector<int>> arr(100005); int A, B; for (int i = 0; i < N; ++i) { cin >> A >> B; A--; arr[A].push_back(B); } multiset<int> st; auto index = st.begin(); int ans = 0; for (int i = 0; i < M; ++i) { for (int j = 0; j < arr[i].size(); ++j) st.insert(arr[i][j]); if (st.size() == 0) continue; index = st.end(); index--; ans += *index; st.erase(st.find(*index)); } cout << ans << endl; }
replace
26
27
26
27
0
p02948
C++
Runtime Error
#include <algorithm> #include <iostream> #include <queue> using namespace std; using llong = long long; pair<llong, llong> a[100005]; priority_queue<llong> p_que; int main() { llong n, m; cin >> n >> m; for (int i = 0; i < n; i++) { cin >> a[i].first >> a[i].second; } llong ans = 0; int idx = 0; sort(a, a + n); for (int i = m - 1; i >= 0; i--) { while (a[idx].first <= (m - i)) { p_que.push(a[idx].second); idx++; } if (p_que.empty()) continue; ans += p_que.top(); p_que.pop(); } cout << ans << endl; }
#include <algorithm> #include <iostream> #include <queue> using namespace std; using llong = long long; pair<llong, llong> a[100005]; priority_queue<llong> p_que; int main() { llong n, m; cin >> n >> m; for (int i = 0; i < n; i++) { cin >> a[i].first >> a[i].second; } llong ans = 0; int idx = 0; sort(a, a + n); for (int i = m - 1; i >= 0; i--) { while (idx < n && a[idx].first <= (m - i)) { p_que.push(a[idx].second); idx++; } if (p_que.empty()) continue; ans += p_que.top(); p_que.pop(); } cout << ans << endl; }
replace
21
22
21
22
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; const int nax = (int)1e5 + 7; int n, m; int sol; vector<int> bs[nax]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; for (int i = 1; i <= n; i++) { int a, b; cin >> a >> b; a = m - a + 1; bs[a].push_back(b); } priority_queue<int> q; for (int i = m; i >= 1; i--) { for (auto &b : bs[i]) q.push(b); if (!q.empty()) { sol += q.top(); q.pop(); } } cout << sol << "\n"; /// toate devin valide de atunci, iau una pe zi return 0; } /** **/
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; const int nax = (int)1e5 + 7; int n, m; int sol; vector<int> bs[nax]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; for (int i = 1; i <= n; i++) { int a, b; cin >> a >> b; a = m - a + 1; if (a >= 0) bs[a].push_back(b); } priority_queue<int> q; for (int i = m; i >= 1; i--) { for (auto &b : bs[i]) q.push(b); if (!q.empty()) { sol += q.top(); q.pop(); } } cout << sol << "\n"; /// toate devin valide de atunci, iau una pe zi return 0; } /** **/
replace
22
23
22
24
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int N, M; cin >> N >> M; vector<vector<int>> AB(M); for (int i = 0; i < N; i++) { int a, b; cin >> a >> b; a--; AB[a].emplace_back(b); } priority_queue<int> que; int res = 0; for (int i = 0; i < M; i++) { for (int x : AB[i]) { que.push(x); } if (que.empty()) continue; res += que.top(); que.pop(); } cout << res << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int N, M; cin >> N >> M; vector<vector<int>> AB(M); for (int i = 0; i < N; i++) { int a, b; cin >> a >> b; if (a > M) continue; a--; AB[a].emplace_back(b); } priority_queue<int> que; int res = 0; for (int i = 0; i < M; i++) { for (int x : AB[i]) { que.push(x); } if (que.empty()) continue; res += que.top(); que.pop(); } cout << res << '\n'; return 0; }
insert
13
13
13
15
0
p02948
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <string> #include <vector> using namespace std; typedef long long ll; typedef std::pair<int, int> ipair; bool lessPair(const ipair &l, const ipair &r) { return l.second < r.second; } bool morePair(const ipair &l, const ipair &r) { return l.second > r.second; } 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 ll MOD = 1e9 + 7; // const long long INF = 1LL<<60; void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; } void sub(long long &a, long long b) { a -= b; if (a < 0) a += MOD; } void mul(long long &a, long long b) { a *= b; a %= MOD; } ll llmin(ll a, ll b) { if (a < b) return a; else return b; } ll llmax(ll a, ll b) { if (a < b) return b; else return a; } ll llabs(ll a) { if (a >= 0) return a; else return -a; } ll llmodpow(ll a, ll n) { if (n == 0) return 1; ll tmp = llmodpow(a, n / 2); mul(tmp, tmp); if (n & 1) mul(tmp, a); return tmp; } int main() { int N, M; cin >> N >> M; vector<vector<int>> log; log.resize(M + 1); int a, b; for (int i = 0; i < N; i++) { cin >> a >> b; log[a].push_back(b); } priority_queue<int> q; ll ans = 0; for (int i = 1; i <= M; i++) { if (log[i].size() != 0) { for (auto &tmp : log[i]) { // cout << i << " " << tmp << endl; q.push(tmp); } } if (!q.empty()) { ans += q.top(); q.pop(); } } cout << ans << endl; return 0; }
#include <algorithm> #include <cmath> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <string> #include <vector> using namespace std; typedef long long ll; typedef std::pair<int, int> ipair; bool lessPair(const ipair &l, const ipair &r) { return l.second < r.second; } bool morePair(const ipair &l, const ipair &r) { return l.second > r.second; } 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 ll MOD = 1e9 + 7; // const long long INF = 1LL<<60; void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; } void sub(long long &a, long long b) { a -= b; if (a < 0) a += MOD; } void mul(long long &a, long long b) { a *= b; a %= MOD; } ll llmin(ll a, ll b) { if (a < b) return a; else return b; } ll llmax(ll a, ll b) { if (a < b) return b; else return a; } ll llabs(ll a) { if (a >= 0) return a; else return -a; } ll llmodpow(ll a, ll n) { if (n == 0) return 1; ll tmp = llmodpow(a, n / 2); mul(tmp, tmp); if (n & 1) mul(tmp, a); return tmp; } int main() { int N, M; cin >> N >> M; vector<vector<int>> log; // log.resize(M + 1); log.resize(100001); int a, b; for (int i = 0; i < N; i++) { cin >> a >> b; log[a].push_back(b); } priority_queue<int> q; ll ans = 0; for (int i = 1; i <= M; i++) { if (log[i].size() != 0) { for (auto &tmp : log[i]) { // cout << i << " " << tmp << endl; q.push(tmp); } } if (!q.empty()) { ans += q.top(); q.pop(); } } cout << ans << endl; return 0; }
replace
82
83
82
84
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using int64 = long long; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vector<vector<int>> d_to_v(m + 1); for (int i = 0; i < n; i++) { int d, v; cin >> d >> v; d_to_v[d].push_back(v); } priority_queue<int> pq; int ans = 0; for (int d = 1; d <= m; d++) { for (int v : d_to_v[d]) { pq.push(v); } if (!pq.empty()) { ans += pq.top(); pq.pop(); } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using int64 = long long; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vector<vector<int>> d_to_v(m + 1); for (int i = 0; i < n; i++) { int d, v; cin >> d >> v; if (d > m) continue; d_to_v[d].push_back(v); } priority_queue<int> pq; int ans = 0; for (int d = 1; d <= m; d++) { for (int v : d_to_v[d]) { pq.push(v); } if (!pq.empty()) { ans += pq.top(); pq.pop(); } } cout << ans << endl; }
insert
16
16
16
18
0
p02948
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <deque> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef pair<int, int> ii; typedef long long ll; typedef pair<ll, ll> p; typedef unsigned long long int ull; const ll MOD = 998244353; int dy[] = {1, 0, -1, 0}; int dx[] = {0, 1, 0, -1}; const int MAXN = 100000; const int MAXE = 100000; const int MAXV = 10000; const ll INF = 2e18; int main() { int n, m; cin >> n >> m; vector<ii> c(n); for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; c[i] = ii(a, b); } sort(c.begin(), c.end()); int i = 0; int ans = 0; priority_queue<int> que; for (int d = 1; d <= m; d++) { while (c[i].first <= d && i < n) { que.push(c[i].second); i++; } int mx = que.top(); que.pop(); ans += mx; } cout << ans << endl; return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <deque> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef pair<int, int> ii; typedef long long ll; typedef pair<ll, ll> p; typedef unsigned long long int ull; const ll MOD = 998244353; int dy[] = {1, 0, -1, 0}; int dx[] = {0, 1, 0, -1}; const int MAXN = 100000; const int MAXE = 100000; const int MAXV = 10000; const ll INF = 2e18; int main() { int n, m; cin >> n >> m; vector<ii> c(n); for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; c[i] = ii(a, b); } sort(c.begin(), c.end()); int i = 0; int ans = 0; priority_queue<int> que; for (int d = 1; d <= m; d++) { while (c[i].first <= d && i < n) { que.push(c[i].second); i++; } if (que.empty()) continue; int mx = que.top(); que.pop(); ans += mx; } cout << ans << endl; return 0; }
insert
43
43
43
45
-11
p02948
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (n); ++i) int main() { int n, m; cin >> n >> m; vector<vector<int>> jobs(m); rep(i, n) { int a, b; cin >> a >> b; if (a > m) continue; jobs[m - a].push_back(b); } priority_queue<int> q; ll ans = 0; for (int i = m - 1; i >= 0; ++i) { for (int b : jobs[i]) { q.push(b); } if (!q.empty()) { ans += q.top(); q.pop(); } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (n); ++i) int main() { int n, m; cin >> n >> m; vector<vector<int>> jobs(m); rep(i, n) { int a, b; cin >> a >> b; if (a > m) continue; jobs[m - a].push_back(b); } priority_queue<int> q; ll ans = 0; for (int i = m - 1; i >= 0; --i) { for (int b : jobs[i]) { q.push(b); } if (!q.empty()) { ans += q.top(); q.pop(); } } cout << ans << endl; }
replace
19
20
19
20
-11
p02948
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i = (a); i <= (b); ++i) #define rrep(i, a, b) for (int i = (a); i >= (b); --i) #define MP make_pair #define PB push_back typedef long long LL; const LL P = 998244353; const int N = 1e5 + 10; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); struct dat { int a, b; } a[N]; int n, m, fa[N]; int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); } int main() { scanf("%d%d", &n, &m); rep(i, 1, n) scanf("%d%d", &a[i].a, &a[i].b); sort(a + 1, a + n + 1, [](dat a, dat b) { return a.b > b.b; }); rep(i, 1, m) fa[i] = i; LL ans = 0; rep(i, 1, n) { int j = find(m - a[i].a + 1); if (j <= 0) continue; ans += 1ll * a[i].b; fa[j] = j - 1; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i = (a); i <= (b); ++i) #define rrep(i, a, b) for (int i = (a); i >= (b); --i) #define MP make_pair #define PB push_back typedef long long LL; const LL P = 998244353; const int N = 1e5 + 10; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); struct dat { int a, b; } a[N]; int n, m, fa[N]; int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); } int main() { scanf("%d%d", &n, &m); rep(i, 1, n) scanf("%d%d", &a[i].a, &a[i].b); sort(a + 1, a + n + 1, [](dat a, dat b) { return a.b > b.b; }); rep(i, 1, m) fa[i] = i; LL ans = 0; rep(i, 1, n) { if (m - a[i].a + 1 <= 0) continue; int j = find(m - a[i].a + 1); if (j <= 0) continue; ans += 1ll * a[i].b; fa[j] = j - 1; } cout << ans << endl; return 0; }
insert
25
25
25
27
0