Datasets:

problem_id
stringlengths
6
6
buggy_code
stringlengths
8
526k
fixed_code
stringlengths
12
526k
labels
listlengths
0
15
buggy_submission_id
int64
1
1.54M
fixed_submission_id
int64
2
1.54M
user_id
stringlengths
10
10
language
stringclasses
9 values
p02947
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define pb push_back #define mp make_pair #define forn(i, n) for (ll i = 0; i < n; i++) #define fore(i, a, b) for (ll i = a; i <= b; i++) #define ford(i, n) for (ll i = n - 1; i >= 0; i--) #define fi first #define se second #define endl "\n" #define all(a) a.begin(), a.end() #define sync \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define PI 3.14159265 /******************************************************************************************************/ void file() { #ifndef ONLINE_JUDGE // for getting input from input.txt freopen("input.txt", "r", stdin); // for writing output to output.txt freopen("output.txt", "w", stdout); #endif } /******************************************************************************************************/ const ll nax = 2e5 + 1, mod = 1e9 + 7; int main() { sync // file(); int n; cin >> n; map<string, int> mapp; while (n--) { string s; cin >> s; sort(all(s)); mapp[s]++; } ll ans = 0; for (auto it : mapp) { ans += (it.se * (it.se - 1)) / 2; } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define pb push_back #define mp make_pair #define forn(i, n) for (ll i = 0; i < n; i++) #define fore(i, a, b) for (ll i = a; i <= b; i++) #define ford(i, n) for (ll i = n - 1; i >= 0; i--) #define fi first #define se second #define endl "\n" #define all(a) a.begin(), a.end() #define sync \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define PI 3.14159265 /******************************************************************************************************/ void file() { #ifndef ONLINE_JUDGE // for getting input from input.txt freopen("input.txt", "r", stdin); // for writing output to output.txt freopen("output.txt", "w", stdout); #endif } /******************************************************************************************************/ const ll nax = 2e5 + 1, mod = 1e9 + 7; int main() { sync // file(); int n; cin >> n; map<string, ll> mapp; while (n--) { string s; cin >> s; sort(all(s)); mapp[s]++; } ll ans = 0; for (auto it : mapp) { ans += (it.se * (it.se - 1)) / 2; } cout << ans; return 0; }
[]
749,875
749,876
u576115185
cpp
p02947
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; using P = pair<int, int>; using PL = pair<ll, ll>; using vp = vector<P>; using vpl = vector<PL>; template <typename T> constexpr auto inf = numeric_limits<T>::max() / 2; constexpr int INF = inf<int>, MOD = 1000000007; constexpr ll LINF = inf<ll>; #define _ol3(_1, _2, _3, name, ...) name #define _rep(i, n) _repi(i, 0, n) #define _repi(i, a, b) for (int i = a, i##_l = (b); i < i##_l; ++i) #define REP(...) _ol3(__VA_ARGS__, _repi, _rep, )(__VA_ARGS__) #define REPR(i, n) for (int i = n - 1; i >= 0; --i) #define REPA(i, v) REP(i, v.size()) #define all(v) (v).begin(), (v).end() #define bit(n) (1ll << (n)) #define uniq(v) \ sort(all(v)); \ v.erase(unique(all(v)), v.end()) #define F first #define S second #define endl '\n' #define cho(n, a, b) cout << ((n) ? a : b) << endl void YES(int n) { cho(n, "YES", "NO"); } void Yes(int n) { cho(n, "Yes", "No"); } void Poss(int n) { cho(n, "Possible", "Impossible"); } void _print(ostream &s) {} template <class T, class... U> void _print(ostream &s, T &&t, U &&...u) { s << t << (sizeof...(u) ? ' ' : '\n'); _print(s, u...); } template <class... T> void print(T &&...t) { _print(cout, t...); } #ifndef LOCAL struct osd { template <class T> osd &operator<<(const T &t) { return *this; } }; osd cer_; #define dprint(...) #define cerr cer_ #else template <class... T> void dprint(T &&...t) { _print(cerr, t...); } #endif template <class T> void chmax(T &a, const T &b) { if (a < b) a = b; } template <class T> void chmin(T &a, const T &b) { if (a > b) a = b; } template <class T> ostream &operator<<(ostream &o, const vector<T> &v) { for (auto &&i : v) o << i << ' '; return o; } template <class T> istream &operator>>(istream &i, vector<T> &v) { for (T &j : v) i >> j; return i; } template <class T, class U> ostream &operator<<(ostream &o, const pair<T, U> &p) { return o << p.F << ' ' << p.S; } template <class T, class U> istream &operator>>(istream &i, pair<T, U> &p) { return i >> p.F >> p.S; } template <class T> ostream &operator<<(ostream &o, const set<T> &v) { for (auto &&i : v) o << i << ' '; return o; } template <class T> ostream &operator<<(ostream &o, const multiset<T> &v) { for (auto &&i : v) o << i << ' '; return o; } template <class T> vector<T> &operator<<(vector<T> &v, const T &t) { v.push_back(t); return v; } template <class T> set<T> &operator<<(set<T> &v, const T &t) { v.insert(t); return v; } template <class T> multiset<T> &operator<<(multiset<T> &v, const T &t) { v.insert(t); return v; } ll h(const string &s) { ll ret = 0; REPA(i, s) { ret = ret * 26 + s[i] - 'a'; } return ret; } int main() { cin.tie(0); ios::sync_with_stdio(0); int n; cin >> n; map<ll, int> m; string s; REP(i, n) { cin >> s; sort(all(s)); m[h(s)]++; } ll ans = 0; for (const auto &x : m) { ans += x.S * (x.S - 1) / 2; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; using P = pair<int, int>; using PL = pair<ll, ll>; using vp = vector<P>; using vpl = vector<PL>; template <typename T> constexpr auto inf = numeric_limits<T>::max() / 2; constexpr int INF = inf<int>, MOD = 1000000007; constexpr ll LINF = inf<ll>; #define _ol3(_1, _2, _3, name, ...) name #define _rep(i, n) _repi(i, 0, n) #define _repi(i, a, b) for (int i = a, i##_l = (b); i < i##_l; ++i) #define REP(...) _ol3(__VA_ARGS__, _repi, _rep, )(__VA_ARGS__) #define REPR(i, n) for (int i = n - 1; i >= 0; --i) #define REPA(i, v) REP(i, v.size()) #define all(v) (v).begin(), (v).end() #define bit(n) (1ll << (n)) #define uniq(v) \ sort(all(v)); \ v.erase(unique(all(v)), v.end()) #define F first #define S second #define endl '\n' #define cho(n, a, b) cout << ((n) ? a : b) << endl void YES(int n) { cho(n, "YES", "NO"); } void Yes(int n) { cho(n, "Yes", "No"); } void Poss(int n) { cho(n, "Possible", "Impossible"); } void _print(ostream &s) {} template <class T, class... U> void _print(ostream &s, T &&t, U &&...u) { s << t << (sizeof...(u) ? ' ' : '\n'); _print(s, u...); } template <class... T> void print(T &&...t) { _print(cout, t...); } #ifndef LOCAL struct osd { template <class T> osd &operator<<(const T &t) { return *this; } }; osd cer_; #define dprint(...) #define cerr cer_ #else template <class... T> void dprint(T &&...t) { _print(cerr, t...); } #endif template <class T> void chmax(T &a, const T &b) { if (a < b) a = b; } template <class T> void chmin(T &a, const T &b) { if (a > b) a = b; } template <class T> ostream &operator<<(ostream &o, const vector<T> &v) { for (auto &&i : v) o << i << ' '; return o; } template <class T> istream &operator>>(istream &i, vector<T> &v) { for (T &j : v) i >> j; return i; } template <class T, class U> ostream &operator<<(ostream &o, const pair<T, U> &p) { return o << p.F << ' ' << p.S; } template <class T, class U> istream &operator>>(istream &i, pair<T, U> &p) { return i >> p.F >> p.S; } template <class T> ostream &operator<<(ostream &o, const set<T> &v) { for (auto &&i : v) o << i << ' '; return o; } template <class T> ostream &operator<<(ostream &o, const multiset<T> &v) { for (auto &&i : v) o << i << ' '; return o; } template <class T> vector<T> &operator<<(vector<T> &v, const T &t) { v.push_back(t); return v; } template <class T> set<T> &operator<<(set<T> &v, const T &t) { v.insert(t); return v; } template <class T> multiset<T> &operator<<(multiset<T> &v, const T &t) { v.insert(t); return v; } ll h(const string &s) { ll ret = 0; REPA(i, s) { ret = ret * 26 + s[i] - 'a'; } return ret; } int main() { cin.tie(0); ios::sync_with_stdio(0); int n; cin >> n; map<ll, int> m; string s; REP(i, n) { cin >> s; sort(all(s)); m[h(s)]++; } ll ans = 0; for (const auto &x : m) { ans += 1ll * x.S * (x.S - 1) / 2; } cout << ans << endl; return 0; }
[ "assignment.change" ]
749,877
749,878
u502709453
cpp
p02947
#include <bits/stdc++.h> using namespace std; typedef long long ll; signed main() { // cout << setprecision(12) ; ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; map<string, int> mp; for (int i = 0; i < n; i++) { string s; cin >> s; sort(s.begin(), s.end()); mp[s]++; } ll ans = 0; for (auto i : mp) { ans += i.second * (i.second - 1) / 2; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; signed main() { // cout << setprecision(12) ; ios::sync_with_stdio(false); cin.tie(0); ll n; cin >> n; map<string, ll> mp; for (ll i = 0; i < n; i++) { string s; cin >> s; sort(s.begin(), s.end()); mp[s]++; } ll ans = 0; for (auto i : mp) { ans += i.second * (i.second - 1) / 2; } cout << ans << endl; }
[ "variable_declaration.type.change", "control_flow.loop.for.initializer.change" ]
749,879
749,880
u676029460
cpp
p02947
#define _CRT_SECURE_NO_WARNINGS #pragma comment(linker, "/stack:512000000") #include <algorithm> #include <bitset> #include <cassert> #include <ccomplex> #include <climits> #include <cmath> #include <cstdio> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define rep(i, n) for (int i = 0; i < (n); i++) #define all(x) x.begin(), x.end() #define mp make_pair #define X first #define Y second using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; mt19937_64 gen(time(NULL)); int const mod = 1e9 + 7; namespace { ll mul(ll a, ll b) { ll val = a * b - (ll)((ld)a * b / mod) * mod; if (val < 0) val += mod; if (val >= mod) val -= mod; return val; } ll poww(ll a, ll b) { ll val = 1; a %= mod; while (b > 0) { if (b % 2) val = mul(a, val); a = mul(a, a); b >>= 1; } return val % mod; } ll inv(ll a) { return poww(a, mod - 2); } } // namespace int const maxn = 2e5 + 5; map<string, int> mapa; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll n; cin >> n; for (ll i = 0; i < n; i++) { string s; cin >> s; sort(all(s)); mapa[s]++; } ll ans = 0; for (auto p : mapa) { ans += (p.Y) * (p.Y - 1); } ans /= 2; cout << ans; return 0; } /* */
#define _CRT_SECURE_NO_WARNINGS #pragma comment(linker, "/stack:512000000") #include <algorithm> #include <bitset> #include <cassert> #include <ccomplex> #include <climits> #include <cmath> #include <cstdio> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define rep(i, n) for (int i = 0; i < (n); i++) #define all(x) x.begin(), x.end() #define mp make_pair #define X first #define Y second using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; mt19937_64 gen(time(NULL)); int const mod = 1e9 + 7; namespace { ll mul(ll a, ll b) { ll val = a * b - (ll)((ld)a * b / mod) * mod; if (val < 0) val += mod; if (val >= mod) val -= mod; return val; } ll poww(ll a, ll b) { ll val = 1; a %= mod; while (b > 0) { if (b % 2) val = mul(a, val); a = mul(a, a); b >>= 1; } return val % mod; } ll inv(ll a) { return poww(a, mod - 2); } } // namespace int const maxn = 2e5 + 5; map<string, ll> mapa; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll n; cin >> n; for (ll i = 0; i < n; i++) { string s; cin >> s; sort(all(s)); mapa[s]++; } ll ans = 0; for (auto p : mapa) { ans += (p.Y) * (p.Y - 1); } ans /= 2; cout << ans; return 0; } /* */
[]
749,883
749,884
u258032299
cpp
p02947
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; typedef long long ll; string s[maxn]; map<string, int> mp; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> s[i]; sort(s[i].begin(), s[i].end()); mp[s[i]]++; } ll ans = 0; for (auto it = mp.begin(); it != mp.end(); it++) { ans += (ll)(it->second * (it->second - 1)) / 2; } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; typedef long long ll; string s[maxn]; map<string, int> mp; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> s[i]; sort(s[i].begin(), s[i].end()); mp[s[i]]++; } ll ans = 0; for (auto it = mp.begin(); it != mp.end(); it++) { ans += ((ll)it->second * (it->second - 1)) / 2; } cout << ans; return 0; }
[ "call.arguments.change" ]
749,885
749,886
u316852065
cpp
p02947
// In the name of God #include <bits/stdc++.h> using namespace std; const int N = (int)1e5 + 5; map<string, int> mp; int main() { ios_base::sync_with_stdio(0), cin.tie(0); int n; cin >> n; int ans = 0; for (int i = 0; i < n; i++) { string s; cin >> s; sort(s.begin(), s.end()); ans += mp[s]; mp[s]++; } cout << ans; return 0; }
// In the name of God #include <bits/stdc++.h> using namespace std; const int N = (int)1e5 + 5; map<string, long long> mp; int main() { ios_base::sync_with_stdio(0), cin.tie(0); int n; cin >> n; long long ans = 0; for (int i = 0; i < n; i++) { string s; cin >> s; sort(s.begin(), s.end()); ans += mp[s]; mp[s]++; } cout << ans; return 0; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
749,887
749,888
u832023241
cpp
p02947
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define IOS \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define MOD 1000000007 #define MOD2 998244353 #define pb emplace_back #define mp make_pair #define all(v) v.begin(), v.end() #define sz(x) (ll) x.size() #define F first #define S second #define FOR(i, a, b) for (ll i = a; i <= b; ++i) #define ROF(i, a, b) for (ll i = a; i >= b; --i) #define trace(x) cerr << #x << ": " << x << '\n'; typedef long long ll; using namespace std; using namespace __gnu_pbds; #define T ll #define ordered_set \ tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update> ll mexp(ll a, ll b, ll m) { ll ans = 1; a %= m; while (b) { if (b & 1) ans = ans * a % m; b >>= 1; a = a * a % m; } return ans; } map<string, int> f; int main() { IOS int n; cin >> n; string s; FOR(i, 1, n) { cin >> s; sort(all(s)); f[s]++; } ll ans = 0; for (auto i : f) { ans += i.S * (i.S - 1) / 2; } cout << ans; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define IOS \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define MOD 1000000007 #define MOD2 998244353 #define pb emplace_back #define mp make_pair #define all(v) v.begin(), v.end() #define sz(x) (ll) x.size() #define F first #define S second #define FOR(i, a, b) for (ll i = a; i <= b; ++i) #define ROF(i, a, b) for (ll i = a; i >= b; --i) #define trace(x) cerr << #x << ": " << x << '\n'; typedef long long ll; using namespace std; using namespace __gnu_pbds; #define T ll #define ordered_set \ tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update> ll mexp(ll a, ll b, ll m) { ll ans = 1; a %= m; while (b) { if (b & 1) ans = ans * a % m; b >>= 1; a = a * a % m; } return ans; } map<string, ll> f; int main() { IOS int n; cin >> n; string s; FOR(i, 1, n) { cin >> s; sort(all(s)); f[s]++; } ll ans = 0; for (auto i : f) { ans += i.S * (i.S - 1) / 2; } cout << ans; return 0; }
[]
749,891
749,892
u380459040
cpp
p02947
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1e5 + 10; int t; string s; map<string, int> mp; map<string, int>::iterator it; ll vis[N]; void init() { for (int i = 1; i <= 100000; i++) vis[i] = i * (i - 1) / 2; } int main() { init(); cin >> t; while (t--) { cin >> s; sort(s.begin(), s.end()); mp[s]++; } ll ans = 0; for (it = mp.begin(); it != mp.end(); it++) ans += vis[it->second]; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1e5 + 10; int t; string s; map<string, int> mp; map<string, int>::iterator it; ll vis[N]; void init() { for (ll i = 1; i <= 100000; i++) vis[i] = i * (i - 1) / 2; } int main() { init(); cin >> t; while (t--) { cin >> s; sort(s.begin(), s.end()); mp[s]++; } ll ans = 0; for (it = mp.begin(); it != mp.end(); it++) ans += vis[it->second]; cout << ans << endl; }
[ "control_flow.loop.for.initializer.change", "variable_declaration.type.change" ]
749,893
749,894
u461754222
cpp
p02947
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; int N; string s; map<string, int> M; ll ans; int main() { int i, j; cin >> N; for (i = 1; i <= N; i++) { cin >> s; sort(s.begin(), s.end()); ans += M[s]++; } printf("%d", ans); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; int N; string s; map<string, int> M; ll ans; int main() { int i, j; cin >> N; for (i = 1; i <= N; i++) { cin >> s; sort(s.begin(), s.end()); ans += M[s]++; } printf("%lld", ans); }
[ "literal.string.change", "call.arguments.change", "io.output.change" ]
749,895
749,896
u539847337
cpp
p02947
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; map<string, int> cnt; for (int i = 0; i < n; i++) { string s; cin >> s; sort(s.begin(), s.end()); cnt[s]++; } int ans = 0; for (auto &it : cnt) { ans += it.second * (it.second - 1) / 2; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; map<string, int> cnt; for (int i = 0; i < n; i++) { string s; cin >> s; sort(s.begin(), s.end()); cnt[s]++; } long long ans = 0; for (auto &it : cnt) { ans += 1LL * it.second * (it.second - 1) / 2; } cout << ans << endl; return 0; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change", "assignment.change" ]
749,897
749,898
u986669926
cpp
p02947
#include <bits/stdc++.h> using namespace std; map<string, int> mmp; set<string> st; string s; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> s; sort(s.begin(), s.end()); mmp[s]++; st.insert(s); } long long ans = 0; for (auto v : st) { ans += (mmp[v] * (mmp[v] - 1) / 2); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; map<string, long long> mmp; set<string> st; string s; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> s; sort(s.begin(), s.end()); mmp[s]++; st.insert(s); } long long ans = 0; for (auto v : st) { ans += (mmp[v] * (mmp[v] - 1) / 2); } cout << ans << endl; return 0; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
749,899
749,900
u206489571
cpp
p02947
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; long long int INF = 3e18; double Pi = 3.1415926535897932384626; vector<ll> G1[500005]; vector<ll> G2[500005]; // vector<P> tree[500010]; priority_queue<ll> pql; priority_queue<P> pqp; // big priority queue priority_queue<ll, vector<ll>, greater<ll>> pqls; priority_queue<P, vector<P>, greater<P>> pqps; // small priority queue // top pop int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1}; int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1}; char dir[] = "DRUL"; // ll bit[500005]; //↓,→,↑,← #define p(x) cout << x << endl; #define el cout << endl; #define pe(x) cout << (x) << " "; #define ps(x) cout << fixed << setprecision(25) << x << endl; #define pu(x) cout << (x); #define pb push_back #define lb lower_bound #define ub upper_bound ll mod = 1000000007; ll rui(ll number1, ll number2) { if (number2 == 0) { return 1; } else { ll number3 = rui(number1, number2 / 2); number3 *= number3; number3 %= mod; if (number2 % 2 == 1) { number3 *= number1; number3 %= mod; } return number3; } } ll gcd(ll number1, ll number2) { if (number1 > number2) { swap(number1, number2); } if (number1 == 0 || number1 == number2) { return number2; } else { return gcd(number2 % number1, number1); } } void YES(bool condition) { if (condition) { p("YES"); } else { p("NO"); } return; } void Yes(bool condition) { if (condition) { p("Yes"); } else { p("No"); } return; } // ll fact[800005],rfact[800005]; /* void c3_init(){ fact[0] = rfact[0] = 1; for(ll i=1; i<=800000; i++){ fact[i] = (fact[i-1]*i) % mod; } rfact[800000] = rui(fact[800000],mod - 2); for(ll i=800000; i>=1; i--){ rfact[i-1] = rfact[i] * i; rfact[i-1] %= mod; } return;} ll c3(ll n,ll r){ return (((fact[n] * rfact[r]) % mod) * rfact[n-r]) % mod;} */ ll n, m, num, sum, ans, a, b, c, e, g, h, w, i, j, k, q; vector<ll> table[5000]; ll x[500005], y[500005]; char s[50005][15]; ll push_num; int main() { cin >> n; for (i = 0; i < n; i++) { cin >> s[i]; num = 0; for (j = 0; j < 10; j++) { x[j] = (s[i][j] - 'a'); } sort(x, x + 10); num = 0; for (j = 0; j < 10; j++) { num *= 26; num += x[j]; } y[i] = num; } sort(y, y + n); ll stock = 0; for (i = 0; i < n; i++) { // p(y[i]); } for (i = 0; i < n - 1; i++) { if (y[i] == y[i + 1]) { stock++; } else { ans += (stock * stock + stock) / 2; stock = 0; } } ans += (stock * stock + stock) / 2; p(ans); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; long long int INF = 3e18; double Pi = 3.1415926535897932384626; vector<ll> G1[500005]; vector<ll> G2[500005]; // vector<P> tree[500010]; priority_queue<ll> pql; priority_queue<P> pqp; // big priority queue priority_queue<ll, vector<ll>, greater<ll>> pqls; priority_queue<P, vector<P>, greater<P>> pqps; // small priority queue // top pop int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1}; int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1}; char dir[] = "DRUL"; // ll bit[500005]; //↓,→,↑,← #define p(x) cout << x << endl; #define el cout << endl; #define pe(x) cout << (x) << " "; #define ps(x) cout << fixed << setprecision(25) << x << endl; #define pu(x) cout << (x); #define pb push_back #define lb lower_bound #define ub upper_bound ll mod = 1000000007; ll rui(ll number1, ll number2) { if (number2 == 0) { return 1; } else { ll number3 = rui(number1, number2 / 2); number3 *= number3; number3 %= mod; if (number2 % 2 == 1) { number3 *= number1; number3 %= mod; } return number3; } } ll gcd(ll number1, ll number2) { if (number1 > number2) { swap(number1, number2); } if (number1 == 0 || number1 == number2) { return number2; } else { return gcd(number2 % number1, number1); } } void YES(bool condition) { if (condition) { p("YES"); } else { p("NO"); } return; } void Yes(bool condition) { if (condition) { p("Yes"); } else { p("No"); } return; } // ll fact[800005],rfact[800005]; /* void c3_init(){ fact[0] = rfact[0] = 1; for(ll i=1; i<=800000; i++){ fact[i] = (fact[i-1]*i) % mod; } rfact[800000] = rui(fact[800000],mod - 2); for(ll i=800000; i>=1; i--){ rfact[i-1] = rfact[i] * i; rfact[i-1] %= mod; } return;} ll c3(ll n,ll r){ return (((fact[n] * rfact[r]) % mod) * rfact[n-r]) % mod;} */ ll n, m, num, sum, ans, a, b, c, e, g, h, w, i, j, k, q; vector<ll> table[5000]; ll x[500005], y[500005]; char s[500005][15]; ll push_num; int main() { cin >> n; for (i = 0; i < n; i++) { cin >> s[i]; num = 0; for (j = 0; j < 10; j++) { x[j] = (s[i][j] - 'a'); } sort(x, x + 10); num = 0; for (j = 0; j < 10; j++) { num *= 26; num += x[j]; } y[i] = num; } sort(y, y + n); ll stock = 0; for (i = 0; i < n; i++) { // p(y[i]); } for (i = 0; i < n - 1; i++) { if (y[i] == y[i + 1]) { stock++; } else { ans += (stock * stock + stock) / 2; stock = 0; } } ans += (stock * stock + stock) / 2; p(ans); return 0; }
[ "literal.number.change", "variable_declaration.array_dimensions.change" ]
749,901
749,902
u399527088
cpp
p02947
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int n; cin >> n; map<string, int> m; for (int i = 0; i < n; i++) { string s; cin >> s; sort(begin(s), end(s)); m[s]++; } ll r = 0; for (auto e : m) r += e.second * (e.second - 1) / 2; cout << r << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int n; cin >> n; map<string, ll> m; for (int i = 0; i < n; i++) { string s; cin >> s; sort(begin(s), end(s)); m[s]++; } ll r = 0; for (auto e : m) r += e.second * (e.second - 1) / 2; cout << r << endl; }
[]
749,903
749,904
u848737670
cpp
p02947
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) #define eee(a) (cerr << (#a) << ": " << (a) << endl); using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>; using mint = map<int, int>; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; const char sp = ' '; const char cmm = ','; const int MOD = 1e9 + 7; const int INF = 1e9; const ll LINF = 1e18; ll mod(ll a, ll b) { return (a % b + b) % b; } ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a * b / gcd(a, b); } void Yes() { cout << "Yes" << endl; } void No() { cout << "No" << endl; } void Judge(bool b) { b ? Yes() : No(); } void YES() { cout << "YES" << endl; } void NO() { cout << "NO" << endl; } void JUDGE(bool b) { b ? YES() : NO(); } ll powmod(ll b, ll e) { ll r = 1; while (e > 0) { if (e & 1) r = (r % MOD) * (b % MOD) % MOD; b = (b % MOD) * (b % MOD) % MOD; e >>= 1; } return r; } double distance(ll x1, ll y1, ll x2, ll y2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); } template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } template <typename T> void ppp(T n) { cout << n << endl; } template <typename T1, typename T2> ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s << "(" << p.first << ", " << p.second << ")"; } template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) { int len = v.size(); s << '['; for (int i = 0; i < len; ++i) { s << v[i]; if (i < len - 1) s << ", "; } s << ']'; return s; } struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(15); }; } fastio; int main() { int n; cin >> n; ll ans = 0; map<string, int> mp; rep(i, n) { string s; cin >> s; sort(s.begin(), s.end()); mp[s]++; } for (auto x : mp) { int y = x.second; ans += y * (y - 1) / 2; } ppp(ans); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) #define eee(a) (cerr << (#a) << ": " << (a) << endl); using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>; using mint = map<int, int>; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; const char sp = ' '; const char cmm = ','; const int MOD = 1e9 + 7; const int INF = 1e9; const ll LINF = 1e18; ll mod(ll a, ll b) { return (a % b + b) % b; } ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a * b / gcd(a, b); } void Yes() { cout << "Yes" << endl; } void No() { cout << "No" << endl; } void Judge(bool b) { b ? Yes() : No(); } void YES() { cout << "YES" << endl; } void NO() { cout << "NO" << endl; } void JUDGE(bool b) { b ? YES() : NO(); } ll powmod(ll b, ll e) { ll r = 1; while (e > 0) { if (e & 1) r = (r % MOD) * (b % MOD) % MOD; b = (b % MOD) * (b % MOD) % MOD; e >>= 1; } return r; } double distance(ll x1, ll y1, ll x2, ll y2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); } template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } template <typename T> void ppp(T n) { cout << n << endl; } template <typename T1, typename T2> ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s << "(" << p.first << ", " << p.second << ")"; } template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) { int len = v.size(); s << '['; for (int i = 0; i < len; ++i) { s << v[i]; if (i < len - 1) s << ", "; } s << ']'; return s; } struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(15); }; } fastio; int main() { int n; cin >> n; ll ans = 0; map<string, ll> mp; rep(i, n) { string s; cin >> s; sort(s.begin(), s.end()); mp[s]++; } for (auto x : mp) { ll y = x.second; ans += y * (y - 1) / 2; } ppp(ans); return 0; }
[ "variable_declaration.type.change" ]
749,905
749,906
u306142032
cpp
p02947
#include <bits/stdc++.h> #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 fore(i, a) for (auto &i : a) #define all(x) (x).begin(), (x).end() //#pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } //------------------------------------------------------------------------------ template <int MOD> struct ModInt { static const int Mod = MOD; unsigned x; ModInt() : x(0) {} ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; } ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; } int get() const { return (int)x; } ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; } ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; } ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; } ModInt &operator/=(ModInt that) { return *this *= that.inverse(); } ModInt operator+(ModInt that) const { return ModInt(*this) += that; } ModInt operator-(ModInt that) const { return ModInt(*this) -= that; } ModInt operator*(ModInt that) const { return ModInt(*this) *= that; } ModInt operator/(ModInt that) const { return ModInt(*this) /= that; } ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); } return ModInt(u); } bool operator==(ModInt that) const { return x == that.x; } bool operator!=(ModInt that) const { return x != that.x; } ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; } }; template <int MOD> ostream &operator<<(ostream &st, const ModInt<MOD> a) { st << a.get(); return st; }; template <int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) { ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; } template <typename T, int FAC_MAX> struct Comb { vector<T> fac, ifac; Comb() { fac.resize(FAC_MAX, 1); ifac.resize(FAC_MAX, 1); rep(i, 1, FAC_MAX) fac[i] = fac[i - 1] * i; ifac[FAC_MAX - 1] = T(1) / fac[FAC_MAX - 1]; rrep(i, FAC_MAX - 2, 1) ifac[i] = ifac[i + 1] * T(i + 1); } T aPb(int a, int b) { if (b < 0 || a < b) return T(0); return fac[a] * ifac[a - b]; } T aCb(int a, int b) { if (b < 0 || a < b) return T(0); return fac[a] * ifac[a - b] * ifac[b]; } T nHk(int n, int k) { if (n == 0 && k == 0) return T(1); if (n <= 0 || k < 0) return 0; return aCb(n + k - 1, k); } }; // nHk = (n+k-1)Ck : n is separator typedef ModInt<1000000007> mint; //------------------------------------------------------------------------------ void _main() { int N; cin >> N; map<string, int> m; rep(i, 0, N) { string s; cin >> s; sort(all(s)); ++m[s]; } ll ans = 0; for (const auto &p : m) { ans += p.second * (p.second - 1) / 2; } cout << ans << endl; }
#include <bits/stdc++.h> #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 fore(i, a) for (auto &i : a) #define all(x) (x).begin(), (x).end() //#pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } //------------------------------------------------------------------------------ template <int MOD> struct ModInt { static const int Mod = MOD; unsigned x; ModInt() : x(0) {} ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; } ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; } int get() const { return (int)x; } ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; } ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; } ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; } ModInt &operator/=(ModInt that) { return *this *= that.inverse(); } ModInt operator+(ModInt that) const { return ModInt(*this) += that; } ModInt operator-(ModInt that) const { return ModInt(*this) -= that; } ModInt operator*(ModInt that) const { return ModInt(*this) *= that; } ModInt operator/(ModInt that) const { return ModInt(*this) /= that; } ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); } return ModInt(u); } bool operator==(ModInt that) const { return x == that.x; } bool operator!=(ModInt that) const { return x != that.x; } ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; } }; template <int MOD> ostream &operator<<(ostream &st, const ModInt<MOD> a) { st << a.get(); return st; }; template <int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) { ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; } template <typename T, int FAC_MAX> struct Comb { vector<T> fac, ifac; Comb() { fac.resize(FAC_MAX, 1); ifac.resize(FAC_MAX, 1); rep(i, 1, FAC_MAX) fac[i] = fac[i - 1] * i; ifac[FAC_MAX - 1] = T(1) / fac[FAC_MAX - 1]; rrep(i, FAC_MAX - 2, 1) ifac[i] = ifac[i + 1] * T(i + 1); } T aPb(int a, int b) { if (b < 0 || a < b) return T(0); return fac[a] * ifac[a - b]; } T aCb(int a, int b) { if (b < 0 || a < b) return T(0); return fac[a] * ifac[a - b] * ifac[b]; } T nHk(int n, int k) { if (n == 0 && k == 0) return T(1); if (n <= 0 || k < 0) return 0; return aCb(n + k - 1, k); } }; // nHk = (n+k-1)Ck : n is separator typedef ModInt<1000000007> mint; //------------------------------------------------------------------------------ void _main() { int N; cin >> N; map<string, ll> m; rep(i, 0, N) { string s; cin >> s; sort(all(s)); ++m[s]; } ll ans = 0; for (const auto &p : m) { ans += p.second * (p.second - 1) / 2; } cout << ans << endl; }
[]
749,907
749,908
u532065884
cpp
p02947
#include <bits/stdc++.h> const int INF = 1e9; const int MOD = 1e9 + 7; using LL = long long; const LL LINF = 1e18; const double EPS = 1e-10; using namespace std; class Edge { public: int from, to, value; Edge(LL a, LL b, LL c) { from = a; to = b; value = c; } Edge(LL a, LL b) { from = a; to = b; } }; int main() { int N; cin >> N; map<map<char, int>, int> vec; for (int i = 0; i < N; i++) { string s; cin >> s; map<char, int> mp; for (auto a : s) mp[a]++; vec[mp]++; } LL ans = 0; for (auto a : vec) { ans += (a.second * (a.second - 1)) / 2; } cout << ans << endl; }
#include <bits/stdc++.h> const int INF = 1e9; const int MOD = 1e9 + 7; using LL = long long; const LL LINF = 1e18; const double EPS = 1e-10; using namespace std; class Edge { public: int from, to, value; Edge(LL a, LL b, LL c) { from = a; to = b; value = c; } Edge(LL a, LL b) { from = a; to = b; } }; int main() { int N; cin >> N; map<map<char, int>, LL> vec; for (int i = 0; i < N; i++) { string s; cin >> s; map<char, int> mp; for (auto a : s) mp[a]++; vec[mp]++; } LL ans = 0; for (auto a : vec) { ans += (a.second * (a.second - 1)) / 2; } cout << ans << endl; }
[]
749,911
749,912
u580402951
cpp
p02947
#include <bits/stdc++.h> #define Ms(a, b) memset(a, b, sizeof a) #define db(x) cout << #x << "=" << x << endl; #define db2(x, y) cout << #x << "=" << x << " " << #y << "=" << y << endl; #define db3(x, y, z) \ cout << #x << "=" << x << " " << #y << "=" << y << " " << #z << "=" << z \ << endl; using namespace std; int n, ans; string a; map<string, int> m; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { cin >> a; sort(a.begin(), a.end()); ans += m[a]; m[a]++; } printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> #define Ms(a, b) memset(a, b, sizeof a) #define db(x) cout << #x << "=" << x << endl; #define db2(x, y) cout << #x << "=" << x << " " << #y << "=" << y << endl; #define db3(x, y, z) \ cout << #x << "=" << x << " " << #y << "=" << y << " " << #z << "=" << z \ << endl; using namespace std; int n; long long ans; string a; map<string, int> m; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { cin >> a; sort(a.begin(), a.end()); ans += m[a]; m[a]++; } printf("%lld\n", ans); return 0; }
[ "literal.string.change", "call.arguments.change", "io.output.change" ]
749,915
749,916
u928673524
cpp
p02947
#include <bits/stdc++.h> #define LL long long #define REP(i, n) for (int i = 0; i < (n); ++i) #define PER(i, n) for (int i = n - 1; i >= 0; --i) #define REPA(i, n) for (int i = 1; i < (n); ++i) #define foreach(i, n) for (auto &i : (n)) #define PII pair<int, int> #define PLI pair<long long, int> #define PLL pair<long long, long long> #define MOD ((int)1e9 + 7) #define INF ((int)1e9 + 5) #define INFLL ((LL)4e18) #define ALL(x) (x).begin(), (x).end() #define BIT(x) (1LL << (x)) using namespace std; int main() { int N; cin >> N; vector<string> line(N); REP(i, N) { cin >> line[i]; sort(ALL(line[i])); } sort(ALL(line)); string bn = line[0]; int count = 1; LL ans = 0; REPA(i, N) { if (bn == line[i]) { ++count; } else { ans += count * (count - 1) / 2; count = 1; bn = line[i]; } } ans += count * (count - 1) / 2; cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define LL long long #define REP(i, n) for (int i = 0; i < (n); ++i) #define PER(i, n) for (int i = n - 1; i >= 0; --i) #define REPA(i, n) for (int i = 1; i < (n); ++i) #define foreach(i, n) for (auto &i : (n)) #define PII pair<int, int> #define PLI pair<long long, int> #define PLL pair<long long, long long> #define MOD ((int)1e9 + 7) #define INF ((int)1e9 + 5) #define INFLL ((LL)4e18) #define ALL(x) (x).begin(), (x).end() #define BIT(x) (1LL << (x)) using namespace std; int main() { int N; cin >> N; vector<string> line(N); REP(i, N) { cin >> line[i]; sort(ALL(line[i])); } sort(ALL(line)); string bn = line[0]; LL count = 1; LL ans = 0; REPA(i, N) { if (bn == line[i]) { ++count; } else { ans += count * (count - 1) / 2; count = 1; bn = line[i]; } } ans += count * (count - 1) / 2; cout << ans << endl; return 0; }
[ "variable_declaration.type.change" ]
749,917
749,918
u493610446
cpp
p02947
#include <bits/stdc++.h> #define ll long long int #define pb push_back #define mp make_pair #define mod 1000000007 #define pi 3.141592653589793 using namespace std; int main() { // cout << setprecision(10); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; map<string, int> d; while (n--) { string s; cin >> s; sort(s.begin(), s.end()); d[s]++; } ll ans = 0; for (auto e : d) { ans += e.second * (e.second - 1) / 2; } cout << ans; }
#include <bits/stdc++.h> #define ll long long int #define pb push_back #define mp make_pair #define mod 1000000007 #define pi 3.141592653589793 using namespace std; int main() { // cout << setprecision(10); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n; cin >> n; map<string, ll> d; while (n--) { string s; cin >> s; sort(s.begin(), s.end()); d[s]++; } ll ans = 0; for (auto e : d) { ans += e.second * (e.second - 1) / 2; } cout << ans; }
[ "variable_declaration.type.change" ]
749,919
749,920
u188208110
cpp
p02947
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define ff first #define ss second #define pb push_back #define mp make_pair #define MOD 1000000007 #define N 1000000 int main() { ll n; cin >> n; string s; map<string, ll> m; int ans = 0; for (int i = 0; i < n; i++) { cin >> s; sort(s.begin(), s.end()); ans += m[s]; m[s]++; } cout << ans; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define ff first #define ss second #define pb push_back #define mp make_pair #define MOD 1000000007 #define N 1000000 int main() { ll n; cin >> n; string s; map<string, ll> m; ll ans = 0; for (ll i = 0; i < n; i++) { cin >> s; sort(s.begin(), s.end()); ans += m[s]; m[s]++; } cout << ans; }
[ "variable_declaration.type.change", "control_flow.loop.for.initializer.change" ]
749,923
749,924
u131797876
cpp
p02947
#include <bits/stdc++.h> using namespace std; using llong = long long; using ldbl = long double; using lpair = pair<llong, llong>; #define ALL(x) x.begin(), x.end() const llong inf = 1100100100100100ll; const llong mod = 1e9 + 7; int main() { llong N; vector<string> s; cin >> N; s.resize(N); for (int i = 0; i < N; ++i) { cin >> s[i]; sort(ALL(s[i])); } map<string, int> m; for (auto x : s) m[x]++; llong ans = 0; for (auto it = m.begin(); it != m.end(); ++it) { ans += it->second * (it->second - 1) / 2; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using llong = long long; using ldbl = long double; using lpair = pair<llong, llong>; #define ALL(x) x.begin(), x.end() const llong inf = 1100100100100100ll; const llong mod = 1e9 + 7; int main() { llong N; vector<string> s; cin >> N; s.resize(N); for (int i = 0; i < N; ++i) { cin >> s[i]; sort(ALL(s[i])); } map<string, llong> m; for (auto x : s) m[x]++; llong ans = 0; for (auto it = m.begin(); it != m.end(); ++it) { ans += it->second * (it->second - 1) / 2ll; } cout << ans << endl; return 0; }
[]
749,925
749,926
u341957179
cpp
p02947
#include <bits/stdc++.h> using namespace std; map<string, int> mp; string s; int ans = 0; int main() { int n; cin >> n; while (n--) { cin >> s; sort(s.begin(), s.end()); ans += mp[s]; mp[s]++; } cout << ans; }
#include <bits/stdc++.h> using namespace std; map<string, int> mp; string s; long long ans = 0; int main() { int n; cin >> n; while (n--) { cin >> s; sort(s.begin(), s.end()); ans += mp[s]; mp[s]++; } cout << ans; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
749,927
749,928
u902105722
cpp
p02947
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <string> #include <vector> #define DEBUG 0 #define fi first #define se second #define pb push_back #define INF 1000000000 #define fore(i, a, b) for (int i = (a), _b = (b); i < (_b); ++i) #define fort(i, a, b) for (int i = (a), _b = (b); i <= (_b); ++i) #define ford(i, a, b) for (int i = (a), _b = (b); i >= (_b); --i) using namespace std; typedef long long LL; typedef pair<int, int> ii; typedef vector<ii> vii; typedef vector<vii> vvii; typedef vector<int> vi; typedef vector<vi> vvi; int main() { if (DEBUG) { freopen("CP.inp", "r", stdin); // freopen("CP.out", "w", stdout); } ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; map<string, int> m; while (n--) { string s; cin >> s; sort(s.begin(), s.end()); ++m[s]; } LL res = 0; for (auto &x : m) { res += x.se * (x.se - 1) / 2; } cout << res << '\n'; return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <string> #include <vector> #define DEBUG 0 #define fi first #define se second #define pb push_back #define INF 1000000000 #define fore(i, a, b) for (int i = (a), _b = (b); i < (_b); ++i) #define fort(i, a, b) for (int i = (a), _b = (b); i <= (_b); ++i) #define ford(i, a, b) for (int i = (a), _b = (b); i >= (_b); --i) using namespace std; typedef long long LL; typedef pair<int, int> ii; typedef vector<ii> vii; typedef vector<vii> vvii; typedef vector<int> vi; typedef vector<vi> vvi; int main() { if (DEBUG) { freopen("CP.inp", "r", stdin); // freopen("CP.out", "w", stdout); } ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; map<string, LL> m; while (n--) { string s; cin >> s; sort(s.begin(), s.end()); ++m[s]; } LL res = 0; for (auto &x : m) { res += x.se * (x.se - 1) / 2; } cout << res << '\n'; return 0; }
[]
749,929
749,930
u334141868
cpp
p02947
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, e) for (int i = a; i < e; ++i) using LL = long long; int main() { int N; cin >> N; vector<string> a(N); for (int i = 0; i < N; ++i) { cin >> a[i]; } auto b = a; FOR(i, 0, N) { sort(b[i].begin(), b[i].end()); } map<string, int> m; FOR(i, 0, N) { m[b[i]]++; } LL ans = 0; for (auto it : m) { LL ret = it.second * (it.second - 1) / 2; ans += ret; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, e) for (int i = a; i < e; ++i) using LL = long long; int main() { int N; cin >> N; vector<string> a(N); for (int i = 0; i < N; ++i) { cin >> a[i]; } auto b = a; FOR(i, 0, N) { sort(b[i].begin(), b[i].end()); } map<string, LL> m; FOR(i, 0, N) { m[b[i]]++; } LL ans = 0; for (auto it : m) { LL ret = it.second * (it.second - 1) / 2; ans += ret; } cout << ans << endl; }
[]
749,931
749,932
u110336585
cpp
p02947
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; typedef vector<ll> vl; typedef vector<vl> vvl; template <typename T> using pq = priority_queue<T>; template <typename T> using minpq = priority_queue<T, vector<T>, greater<T>>; template <typename T, typename K> using ump = unordered_map<T, K>; const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; const ll mod = 1000000007; const ll inf = ll(1e9); const ll e5 = ll(1e5); const ll ll_inf = ll(1e9) * ll(1e9); #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define repr(i, n) for (ll i = n - 1; i >= 0; i--) #define repone(i, n) for (ll i = 1; i <= (ll)(n); i++) #define each(i, mp) for (auto &i : mp) #define eb emplace_back #define F first #define S second #define all(obj) (obj).begin(), (obj).end() template <class T> void dump_debug(T list) { #ifdef MY_DEBUG each(e, list) cout << e << " "; printf("\n"); #endif } /* ------------- ANSWER ------------- */ /* ---------------------------------- */ int main() { #ifdef MY_DEBUG while (true) { #endif ll n; cin >> n; vector<string> s(n); unordered_map<string, ll> c; rep(i, n) { cin >> s[i]; sort(all(s[i])); c[s[i]]++; } ll ans = 0; each(e, c) { ans += e.second * (e.second - 1) / 2; ans %= mod; } cout << ans << endl; #ifdef MY_DEBUG } #endif return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; typedef vector<ll> vl; typedef vector<vl> vvl; template <typename T> using pq = priority_queue<T>; template <typename T> using minpq = priority_queue<T, vector<T>, greater<T>>; template <typename T, typename K> using ump = unordered_map<T, K>; const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; const ll mod = 1000000007; const ll inf = ll(1e9); const ll e5 = ll(1e5); const ll ll_inf = ll(1e9) * ll(1e9); #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define repr(i, n) for (ll i = n - 1; i >= 0; i--) #define repone(i, n) for (ll i = 1; i <= (ll)(n); i++) #define each(i, mp) for (auto &i : mp) #define eb emplace_back #define F first #define S second #define all(obj) (obj).begin(), (obj).end() template <class T> void dump_debug(T list) { #ifdef MY_DEBUG each(e, list) cout << e << " "; printf("\n"); #endif } /* ------------- ANSWER ------------- */ /* ---------------------------------- */ int main() { #ifdef MY_DEBUG while (true) { #endif ll n; cin >> n; vector<string> s(n); unordered_map<string, ll> c; rep(i, n) { cin >> s[i]; sort(all(s[i])); c[s[i]]++; } ll ans = 0; each(e, c) { ans += e.second * (e.second - 1) / 2; } cout << ans << endl; #ifdef MY_DEBUG } #endif return 0; }
[]
749,933
749,934
u136378781
cpp
p02948
#pragma GCC optimize("O3") #include <bits/stdc++.h> #define ll long long #define cst first #define dur second #define IO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); using namespace std; const int N = 1e5 + 5, M = 2 * N + 5; int n, m; vector<int> idx[N]; int main() { scanf("%d%d", &n, &m); for (int i = 0; i < n; ++i) { int a, b; scanf("%d%d", &a, &b); if (a <= b) idx[a].emplace_back(b); } ll ans = 0; priority_queue<int> pq; for (int day = 1; day <= m; ++day) { for (auto j : idx[day]) pq.emplace(j); if (pq.size()) ans += (1LL * pq.top()), pq.pop(); } printf("%lld\n", ans); }
#pragma GCC optimize("O3") #include <bits/stdc++.h> #define ll long long #define cst first #define dur second #define IO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); using namespace std; const int N = 1e5 + 5, M = 2 * N + 5; int n, m; vector<int> idx[N]; int main() { scanf("%d%d", &n, &m); for (int i = 0; i < n; ++i) { int a, b; scanf("%d%d", &a, &b); if (a <= m) idx[a].emplace_back(b); } ll ans = 0; priority_queue<int> pq; for (int day = 1; day <= m; ++day) { for (auto j : idx[day]) pq.emplace(j); if (pq.size()) ans += (1LL * pq.top()), pq.pop(); } printf("%lld\n", ans); }
[ "identifier.change", "control_flow.branch.if.condition.change" ]
749,939
749,940
u863370423
cpp
p02948
#include <bits/stdc++.h> #define rep(i, n) for (ll i = 0; i < n; ++i) #define all_map(pos, mp) for (ll pos = mp.begin(); pos != mp.end(); pos - ++) #define ALL(a) (a).begin(), (a).end() using namespace std; using ll = long long; using pll = pair<ll, ll>; const ll MOD = 1e9 + 7; const ll LINF = 1LL << 62; const int INF = 1e9 + 7; int main() { ll n, m; cin >> n >> m; // reward[i] : i+1日後にもらえる報酬のベクトル vector<vector<ll>> reward(m); rep(i, n) { ll a, b; cin >> a >> b; reward[a - 1].push_back(b); } // 未来から逆算,Mまでにもらえる最大報酬のバイトをする priority_queue<ll> que; ll ans = 0; rep(i, m) { for (ll r_i : reward[i]) que.push(r_i); if (!que.empty()) { ans += que.top(); que.pop(); } } cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (ll i = 0; i < n; ++i) #define all_map(pos, mp) for (ll pos = mp.begin(); pos != mp.end(); pos - ++) #define ALL(a) (a).begin(), (a).end() using namespace std; using ll = long long; using pll = pair<ll, ll>; const ll MOD = 1e9 + 7; const ll LINF = 1LL << 62; const int INF = 1e9 + 7; int main() { ll n, m; cin >> n >> m; // reward[i] : i+1日後にもらえる報酬のベクトル vector<vector<ll>> reward(100010); rep(i, n) { ll a, b; cin >> a >> b; reward[a - 1].push_back(b); } // 未来から逆算,Mまでにもらえる最大報酬のバイトをする priority_queue<ll> que; ll ans = 0; rep(i, m) { for (ll r_i : reward[i]) que.push(r_i); if (!que.empty()) { ans += que.top(); que.pop(); } } cout << ans << endl; }
[]
749,959
749,960
u969116807
cpp
p02948
#include <bits/stdc++.h> using namespace std; int N, M, a, b, ans; int main() { cin >> N >> M; vector<vector<int>> v(1 << 17); for (int i = 0; i < M; i++) { cin >> a >> b; v[a].push_back(b); } priority_queue<int> q; for (int i = 1; i <= M; i++) { for (auto e : v[i]) q.push(e); if (q.size()) ans += q.top(), q.pop(); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int N, M, a, b, ans; int main() { cin >> N >> M; vector<vector<int>> v(1 << 17); for (int i = 0; i < N; i++) { cin >> a >> b; v[a].push_back(b); } priority_queue<int> q; for (int i = 1; i <= M; i++) { for (auto e : v[i]) q.push(e); if (q.size()) ans += q.top(), q.pop(); } cout << ans << endl; }
[ "identifier.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
749,986
749,987
u743561048
cpp
p02948
#include <bits/stdc++.h> using namespace std; int N, M, a, b, ans; int main() { cin >> N >> M; vector<vector<int>> v(1 << 17); for (int i = 0; i < M; i++) { cin >> a >> b; v[a].push_back(b); } priority_queue<int> q; for (int i = 1; i <= M; i++) { for (auto e : v[i]) q.push(e); if (q.size()) ans += q.top(), q.pop(); } cout << ans; }
#include <bits/stdc++.h> using namespace std; int N, M, a, b, ans; int main() { cin >> N >> M; vector<vector<int>> v(1 << 17); for (int i = 0; i < N; i++) { cin >> a >> b; v[a].push_back(b); } priority_queue<int> q; for (int i = 1; i <= M; i++) { for (auto e : v[i]) q.push(e); if (q.size()) ans += q.top(), q.pop(); } cout << ans << endl; }
[ "identifier.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change", "io.output.newline.add" ]
749,988
749,987
u743561048
cpp
p02948
#include <bits/stdc++.h> using namespace std; int N, M, a, b, ans; int main() { cin >> N >> M; vector<vector<int>> v(1 << 17); for (int i = 0; i < M; i++) { cin >> a >> b; v[a].push_back(b); } priority_queue<int> q; for (int i = 1; i <= M; i++) { for (auto e : v[i]) q.push(e); if (q.size()) ans += q.top(), q.pop(); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; long N, M, a, b, ans; int main() { cin >> N >> M; vector<vector<long>> v(1 << 17); for (int i = 0; i < N; i++) { cin >> a >> b; v[a].push_back(b); } priority_queue<long> q; for (int i = 1; i <= M; i++) { for (auto e : v[i]) q.push(e); if (q.size()) ans += q.top(), q.pop(); } cout << ans << endl; }
[ "variable_declaration.type.primitive.change", "identifier.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
749,986
749,989
u743561048
cpp
p02948
#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; }
[ "literal.number.change", "call.arguments.change", "expression.operation.binary.change" ]
750,008
750,009
u809967037
cpp
p02948
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define per(i, n) for (int i = n - 1; i >= 0; i--) typedef long long ll; typedef pair<int, int> P; typedef pair<long long, long long> Pll; typedef vector<int> vi; typedef vector<ll> vll; const long long mod = 1000000007LL; int main() { int n, m; cin >> n >> m; priority_queue<int> pq; vector<vi> v(m + 2); rep(i, n) { int a, b; cin >> a >> b; v[a].push_back(b); } int ans = 0; for (int i = 1; i <= m; i++) { rep(j, v[i].size()) pq.push(v[i][j]); if (!pq.empty()) { int k = pq.top(); ans += k; pq.pop(); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define per(i, n) for (int i = n - 1; i >= 0; i--) typedef long long ll; typedef pair<int, int> P; typedef pair<long long, long long> Pll; typedef vector<int> vi; typedef vector<ll> vll; const long long mod = 1000000007LL; int main() { int n, m; cin >> n >> m; priority_queue<int> pq; vector<vi> v(110000); rep(i, n) { int a, b; cin >> a >> b; v[a].push_back(b); } int ans = 0; for (int i = 1; i <= m; i++) { rep(j, v[i].size()) pq.push(v[i][j]); if (!pq.empty()) { int k = pq.top(); ans += k; pq.pop(); } } cout << ans << endl; return 0; }
[ "identifier.replace.remove", "literal.replace.add", "call.arguments.change", "expression.operation.binary.change", "expression.operation.binary.remove" ]
750,012
750,013
u615662061
cpp
p02948
#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, N) { 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; }
[ "literal.number.change", "call.arguments.change" ]
750,020
750,019
u024383312
cpp
p02948
#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; }
[ "identifier.replace.remove", "literal.replace.add", "call.arguments.change", "expression.operation.binary.change", "expression.operation.binary.remove" ]
750,037
750,038
u107406081
cpp
p02948
#include <bits/stdc++.h> #define pb push_back #define fst first #define snd second #define ALL(s) s.begin(), s.end() #define fill(a, c) memset(&a, c, sizeof(a)) #define fore(i, x, y) for (ll i = x; i < y; i++) #define SZ(x) ((int)(x).size()) #define PI 3.1415926535897932384626433832795 #define FIN \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) typedef long long ll; using namespace std; int main() { FIN; int n, m; cin >> n >> m; vector<pair<int, ll>> v; fore(i, 0, n) { int a; ll b; cin >> a >> b; if (a > m) continue; v.pb({a, b}); } sort(ALL(v)); ll ans = 0; int j = 0; priority_queue<ll> pq; fore(i, 1, m + 1) { while (j < SZ(v) && v[j].fst == i) { pq.push(v[j].fst); j++; } if (!pq.empty()) { ans += pq.top(); pq.pop(); } } cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> #define pb push_back #define fst first #define snd second #define ALL(s) s.begin(), s.end() #define fill(a, c) memset(&a, c, sizeof(a)) #define fore(i, x, y) for (ll i = x; i < y; i++) #define SZ(x) ((int)(x).size()) #define PI 3.1415926535897932384626433832795 #define FIN \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) typedef long long ll; using namespace std; int main() { FIN; int n, m; cin >> n >> m; vector<pair<int, ll>> v; fore(i, 0, n) { int a; ll b; cin >> a >> b; if (a > m) continue; v.pb({a, b}); } sort(ALL(v)); ll ans = 0; int j = 0; priority_queue<ll> pq; fore(i, 1, m + 1) { while (j < SZ(v) && v[j].fst == i) { pq.push(v[j].snd); j++; } if (!pq.empty()) { ans += pq.top(); pq.pop(); } } cout << ans << "\n"; return 0; }
[ "call.arguments.change" ]
750,047
750,048
u510872737
cpp
p02948
#include <bits/stdc++.h> using namespace std; #define int long long #define double long double #define endl "\n" #define pb push_back #define PI 3.1415926535897932384626433832795l #define F first #define S second #define mp make_pair #define f(i, n) for (int i = 0; i < n; ++i) #define loop(i, a, b) for (int i = a; i < b; ++i) #define fastio \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define gcd(a, b) __gcd((a), (b)) #define fill(a, value) memset(a, value, sizeof(a)); #define minn(v) *min_element(v.begin(), v.end()); #define maxx(v) *max_element(v.begin(), v.end()); #define print(x) cout << (x) << endl; #define sum(v) +x accumulate(v.begin(), v.end(), x); typedef pair<int, int> pii; typedef vector<int> vi; signed main() { fastio; cout << fixed << setprecision(12); int n, m; cin >> n >> m; vector<vector<int>> a(n + 1); f(i, n) { int x, y; cin >> x >> y; a[x].pb(y); } multiset<int> s; int ans = 0; for (int i = 1; i <= m; i++) { for (auto p : a[i]) { s.insert(p); } if (s.size()) { ans += *s.rbegin(); s.erase(--s.end()); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define double long double #define endl "\n" #define pb push_back #define PI 3.1415926535897932384626433832795l #define F first #define S second #define mp make_pair #define f(i, n) for (int i = 0; i < n; ++i) #define loop(i, a, b) for (int i = a; i < b; ++i) #define fastio \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define gcd(a, b) __gcd((a), (b)) #define fill(a, value) memset(a, value, sizeof(a)); #define minn(v) *min_element(v.begin(), v.end()); #define maxx(v) *max_element(v.begin(), v.end()); #define print(x) cout << (x) << endl; #define sum(v) +x accumulate(v.begin(), v.end(), x); typedef pair<int, int> pii; typedef vector<int> vi; signed main() { fastio; cout << fixed << setprecision(12); int n, m; cin >> n >> m; vector<vector<int>> a(100005); f(i, n) { int x, y; cin >> x >> y; a[x].pb(y); } multiset<int> s; int ans = 0; for (int i = 1; i <= m; i++) { for (auto p : a[i]) { s.insert(p); } if (s.size()) { ans += *s.rbegin(); s.erase(--s.end()); } } cout << ans << endl; return 0; }
[ "identifier.replace.remove", "literal.replace.add", "call.arguments.change", "expression.operation.binary.change", "expression.operation.binary.remove" ]
750,063
750,064
u858929490
cpp
p02948
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (ll i = 0; i < n; i++) #define repl(i, l, r) for (ll i = (l); i < (r); i++) #define per(i, n) for (ll i = n - 1; i >= 0; i--) #define perl(i, r, l) for (ll i = r - 1; i >= l; i--) #define fi first #define se second #define pb push_back #define ins insert #define all(x) (x).begin(), (x).end() using ll = long long; using vl = vector<ll>; using vvl = vector<vector<ll>>; const ll MOD = 1000000007; const ll MOD9 = 998244353; const int inf = 1e9 + 10; const ll INF = 4e18; const ll dy[8] = {1, 0, -1, 0, 1, 1, -1, -1}; const ll dx[8] = {0, -1, 0, 1, 1, -1, 1, -1}; using Graph = vector<vector<int>>; double nCk(int n, int k) { double res = 1.0; for (int i = 0; i < n; i++) { res *= 0.5; } for (int i = 0; i < k; i++) { res *= (double)(n - i); res /= (double)(k - i); } return res; } struct edge { ll to, cost; }; typedef pair<ll, ll> P; struct graph { ll V; vector<vector<edge>> G; vector<ll> d; graph(ll n) { init(n); } void init(ll n) { V = n; G.resize(V); d.resize(V); rep(i, V) { d[i] = INF; } } void add_edge(ll s, ll t, ll cost) { edge e; e.to = t, e.cost = cost; G[s].push_back(e); } void dijkstra(ll s) { rep(i, V) { d[i] = INF; } d[s] = 0; priority_queue<P, vector<P>, greater<P>> que; que.push(P(0, s)); while (!que.empty()) { P p = que.top(); que.pop(); ll v = p.second; if (d[v] < p.first) continue; for (auto e : G[v]) { if (d[e.to] > d[v] + e.cost) { d[e.to] = d[v] + e.cost; que.push(P(d[e.to], e.to)); } } } } }; class UnionFind { public: int par[100005]; int depth[100005]; int nGroup[100005]; UnionFind(int n) { init(n); } void init(int n) { for (int i = 0; i < n; i++) { par[i] = i; depth[i] = 0; nGroup[i] = 1; } } int root(int x) { if (par[x] == x) { return x; } else { return par[x] = root(par[x]); } } bool same(int x, int y) { return root(x) == root(y); } void unite(int x, int y) { x = root(x); y = root(y); if (x == y) return; if (depth[x] < depth[y]) { par[x] = y; nGroup[y] += nGroup[x]; nGroup[x] = 0; } else { par[y] = x; nGroup[x] += nGroup[y]; nGroup[y] = 0; if (depth[x] == depth[y]) depth[x]++; } } }; const ll MAX = 510000; ll fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 ll COM(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } int main() { ll n, k; cin >> n >> k; vl mp[100005] = {}; rep(i, n) { ll r, l; cin >> r >> l; mp[r].pb(l); } ll ans = 0; priority_queue<ll> a; repl(i, 1, k) { for (auto p : mp[i]) { a.push(p); } if (!a.empty()) { ans += a.top(); a.pop(); } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (ll i = 0; i < n; i++) #define repl(i, l, r) for (ll i = (l); i < (r); i++) #define per(i, n) for (ll i = n - 1; i >= 0; i--) #define perl(i, r, l) for (ll i = r - 1; i >= l; i--) #define fi first #define se second #define pb push_back #define ins insert #define all(x) (x).begin(), (x).end() using ll = long long; using vl = vector<ll>; using vvl = vector<vector<ll>>; const ll MOD = 1000000007; const ll MOD9 = 998244353; const int inf = 1e9 + 10; const ll INF = 4e18; const ll dy[8] = {1, 0, -1, 0, 1, 1, -1, -1}; const ll dx[8] = {0, -1, 0, 1, 1, -1, 1, -1}; using Graph = vector<vector<int>>; double nCk(int n, int k) { double res = 1.0; for (int i = 0; i < n; i++) { res *= 0.5; } for (int i = 0; i < k; i++) { res *= (double)(n - i); res /= (double)(k - i); } return res; } struct edge { ll to, cost; }; typedef pair<ll, ll> P; struct graph { ll V; vector<vector<edge>> G; vector<ll> d; graph(ll n) { init(n); } void init(ll n) { V = n; G.resize(V); d.resize(V); rep(i, V) { d[i] = INF; } } void add_edge(ll s, ll t, ll cost) { edge e; e.to = t, e.cost = cost; G[s].push_back(e); } void dijkstra(ll s) { rep(i, V) { d[i] = INF; } d[s] = 0; priority_queue<P, vector<P>, greater<P>> que; que.push(P(0, s)); while (!que.empty()) { P p = que.top(); que.pop(); ll v = p.second; if (d[v] < p.first) continue; for (auto e : G[v]) { if (d[e.to] > d[v] + e.cost) { d[e.to] = d[v] + e.cost; que.push(P(d[e.to], e.to)); } } } } }; class UnionFind { public: int par[100005]; int depth[100005]; int nGroup[100005]; UnionFind(int n) { init(n); } void init(int n) { for (int i = 0; i < n; i++) { par[i] = i; depth[i] = 0; nGroup[i] = 1; } } int root(int x) { if (par[x] == x) { return x; } else { return par[x] = root(par[x]); } } bool same(int x, int y) { return root(x) == root(y); } void unite(int x, int y) { x = root(x); y = root(y); if (x == y) return; if (depth[x] < depth[y]) { par[x] = y; nGroup[y] += nGroup[x]; nGroup[x] = 0; } else { par[y] = x; nGroup[x] += nGroup[y]; nGroup[y] = 0; if (depth[x] == depth[y]) depth[x]++; } } }; const ll MAX = 510000; ll fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 ll COM(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } int main() { ll n, k; cin >> n >> k; vl mp[100005] = {}; rep(i, n) { ll r, l; cin >> r >> l; mp[r].pb(l); } ll ans = 0; priority_queue<ll> a; repl(i, 1, k + 1) { for (auto p : mp[i]) { a.push(p); } if (!a.empty()) { ans += a.top(); a.pop(); } } cout << ans << endl; }
[ "expression.operation.binary.add" ]
750,073
750,074
u722640678
cpp
p02948
#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; }
[ "identifier.replace.remove", "literal.replace.add", "call.arguments.change", "expression.operation.binary.change", "expression.operation.binary.remove" ]
750,077
750,078
u476488060
cpp
p02948
#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; }
[]
750,081
750,082
u714732628
cpp
p02948
/////////////////////////////////////////////////////////////////////////////// #include <bits/stdc++.h> #include <sys/time.h> #include <time.h> #include <unistd.h> using namespace std; /////////////////////////////////////////////////////////////////////////////// #define DEBUG 0 #define pb push_back #define V vector #define M unordered_map #define S static #define rep(i, n) for (ll i = 0LL; i < n; ++i) #define srep(i, s, n) for (ll i = s; i < n; ++i) #define rrep(i, n) for (ll i = n - 1LL; i >= 0LL; --i) #define ALL(a) (a).begin(), (a).end() #define CIN(x) \ do { \ assert(!cin.eof()); \ cin >> x; \ assert(!cin.fail()); \ } while (0); #if DEBUG #define debug_print(...) _debug_print(__VA_ARGS__) #define debug_printf(...) printf(__VA_ARGS__) #define debug_print_time _debug_print_time #else // DEBUG #define debug_print(...) #define debug_printf(...) #define debug_print_time #endif // DEBUG typedef long long ll; typedef unsigned long long ull; typedef tuple<ll, ll> t2; typedef tuple<ll, ll, ll> t3; typedef tuple<ll, ll, ll, ll> t4; typedef tuple<ll, ll, ll, ll, ll> t5; template <typename T> using priority_queue_incr = priority_queue<T, V<T>, greater<T>>; /////////////////////////////////////////////////////////////////////////////// template <typename TT, typename T> T get_m(M<TT, T> &m, TT k, T default_value) { if (m.find(k) == m.end()) return m[k] = default_value; return m[k]; } template <typename TT, typename T> void incr_m(M<TT, T> &m, TT k) { if (m.find(k) == m.end()) m[k] = 0; m[k]++; } struct UnionFind { ull *parent, *count, *rank; UnionFind(ull n) { parent = new ull[n + 1]; count = new ull[n + 1]; rank = new ull[n + 1]; for (ull i = 0ULL; i < n + 1; ++i) { parent[i] = i; count[i] = 1; rank[i] = 0; } } ~UnionFind() { delete rank; delete count; delete parent; } ull root(ull i) { if (parent[i] == i) return i; parent[i] = root(parent[i]); return parent[i]; } void unite(ull i, ull j) { ull rooti = root(i); ull rootj = root(j); if (rooti == rootj) return; if (rank[rootj] < rank[rooti]) { parent[i] = parent[j] = parent[rootj] = rooti; count[rooti] += count[rootj]; } else { parent[i] = parent[j] = parent[rooti] = rootj; count[rootj] += count[rooti]; if (rank[rootj] == rank[rooti]) rank[rootj]++; } } bool same(ull i, ull j) { return root(i) == root(j); } }; struct UnionFindM { M<ull, ull> parent, count, rank; ull root(ull i) { ull parent_i = get_m(parent, i, i); if (parent_i == i) return i; return parent[i] = root(parent_i); } void unite(ull i, ull j) { ull rooti = root(i); ull rootj = root(j); if (rooti == rootj) return; if (get_m(rank, rootj, 0ULL) < get_m(rank, rooti, 0ULL)) { parent[i] = parent[j] = parent[rootj] = rooti; count[rooti] = get_m(count, rooti, 1ULL) + get_m(count, rootj, 1ULL); } else { parent[i] = parent[j] = parent[rooti] = rootj; count[rootj] = get_m(count, rootj, 1ULL) + get_m(count, rooti, 1ULL); if (get_m(rank, rootj, 0ULL) == get_m(rank, rooti, 0ULL)) rank[rootj]++; } } bool same(ull i, ull j) { return root(i) == root(j); } }; struct BIT { ll *tree; ll size; BIT(ll n, ll init) { tree = new ll[n + 1]; size = n; this->init(init); } void init(ll init) { memset(tree, 0, sizeof(ll) * (size + 1)); rep(i0, size) { ll idx = i0 + 1LL; while (idx <= size) { tree[idx] += init; idx += (idx & (-idx)); } } } // idx is 1 origin void add(ll idx, ll x) { assert(idx > 0LL); while (idx <= size) { tree[idx] += x; idx += (idx & (-idx)); } } // idx is 1 origin ll sum(ll idx) { assert(idx > 0LL); ll ret = 0LL; while (idx > 0LL) { ret += tree[idx]; idx -= (idx & (-idx)); } return ret; } }; struct MaxFlow { V<ll> links[1005]; ll capacities[1005][1005]; ll nodes; MaxFlow(ll nodes) { // i == 0 --> S // i == nodes+1 --> T rep(i, nodes + 2LL) links[i].clear(); memset(capacities, 0, sizeof(capacities)); this->nodes = nodes; } void add_path(ll a, ll b, ll capacity) { links[a].pb(b); links[b].pb(a); capacities[a][b] = capacity; capacities[b][a] = 0LL; } ll solve(void) { deque<V<ll>> q; ll ret = 0LL; for (;; q.clear()) { V<ll> start; start.pb(0); q.push_front(start); bool checked[nodes + 2]; memset(checked, 0, sizeof(checked)); V<ll> found; for (; !(q.empty());) { V<ll> path = q.front(); q.pop_front(); ll last = path[path.size() - 1]; if (checked[last]) continue; if (last == nodes + 1) { found = path; break; } checked[last] = true; for (auto next : (links[last])) { if (capacities[last][next] == 0) continue; V<ll> newpath(path); newpath.pb(next); q.push_front(newpath); } } if (found.size() == 0) { break; } else { ll flowcount = capacities[found[0]][found[1]]; rep(i, found.size() - 1) { ll src = found[i]; ll dst = found[i + 1]; flowcount = min(flowcount, capacities[src][dst]); } rep(i, found.size() - 1) { ll src = found[i]; ll dst = found[i + 1]; capacities[src][dst] -= flowcount; capacities[dst][src] += flowcount; } ret += flowcount; } } return ret; } }; template <typename T> struct SegmentTree { T *nodes; t2 *ranges; // [start, end) ll nodecount; ll itemcount; T unit; T (*op)(T, T); SegmentTree(ll itemcount, T unit, T op(T, T)) { ll orig_itemcount = itemcount; this->itemcount = 1LL; while (this->itemcount < orig_itemcount) this->itemcount *= 2LL; nodecount = this->itemcount * 2 - 1; nodes = new T[nodecount]; ranges = new t2[nodecount]; this->unit = unit; this->op = op; ll start = 0LL; ll end = this->itemcount; ll len = this->itemcount; rep(i, nodecount) { nodes[i] = unit; ranges[i] = t2(start, end); if (end >= this->itemcount) { len /= 2LL; start = 0LL; end = len; } else { start = end; end = start + len; } } } void update(ll k, T v) { ll idx = k + itemcount - 1LL; nodes[idx] = v; idx = (idx - 1LL) / 2LL; for (; idx >= 0; idx = (idx - 1LL) / 2LL) { nodes[idx] = op(nodes[idx * 2LL + 1LL], nodes[idx * 2LL + 2LL]); if (!idx) break; } } // query to [start, end) T query(ll start, ll end) const { return _query(start, end, 0LL); } T _query(ll start, ll end, ll idx) const { ll rstart = get<0>(ranges[idx]); ll rend = get<1>(ranges[idx]); if (start <= rstart && rend <= end) { return nodes[idx]; } if (rend <= start || end <= rstart) { return unit; } T left = _query(start, end, idx * 2LL + 1LL); T right = _query(start, end, idx * 2LL + 2LL); return op(left, right); } }; void llin(ll &a) { CIN(a); } void llinl1(auto &v, ll count) { for (ll i = 0LL; i < count; ++i) { ll a; CIN(a); v.push_back(a); } } void llinl2(auto &v, ll count) { for (ll i = 0LL; i < count; ++i) { ll a, b; CIN(a >> b); v.push_back(t2(a, b)); } } void llinl3(auto &v, ll count) { for (ll i = 0LL; i < count; ++i) { ll a, b, c; CIN(a >> b >> c); v.push_back(t3(a, b, c)); } } void llinl4(auto &v, ll count) { for (ll i = 0LL; i < count; ++i) { ll a, b, c, d; CIN(a >> b >> c >> d); v.push_back(t4(a, b, c, d)); } } void llina(auto &v, ll count) { llinl1(v, count); } template <typename T> T min(const V<T> v) { T ret = v[0]; for (auto i : v) ret = min(ret, i); return ret; } template <typename T> T max(const V<T> v) { T ret = v[0]; for (auto i : v) ret = max(ret, i); return ret; } ll absll(ll x) { if (x < 0) return -x; return x; } ll mod_mlt(ll x, ll y, ll mod) { ll ret = 0LL; x %= mod; while (y) { if (y & 1LL) { ret += x; ret %= mod; } y >>= 1; x <<= 1; x %= mod; } return ret; } // O(log(exp)) ll mod_pow(ll base, ll exp, ll mod) { ll ret = 1LL; for (; exp;) { if (exp & 1LL) { ret *= base; ret %= mod; } base = (base * base) % mod; exp >>= 1; } return ret; } // O(log(mod)) ll mod_inv(ll x, ll mod) { // available only when mod is prime return mod_pow(x, mod - 2LL, mod); } ll gcm(ll x, ll y) { while (y != 0) { ll z = x % y; x = y; y = z; } return x; } template <typename T> void sort(V<T> &v) { sort(v.begin(), v.end()); } template <typename T> void sort_reverse(V<T> &v) { sort(v.begin(), v.end(), greater<T>()); } void get_divisors(V<ll> &retlist, ll x) { for (ll i = 1LL; i < sqrt(x) + 3LL; ++i) { if (x % i == 0LL) { retlist.push_back(i); retlist.push_back(x / i); } } } // returns factors and 1 void get_factors(V<ll> &retlist, ll x) { retlist.pb(1LL); for (ll i = 2LL; i < (ll)(sqrt(x)) + 3LL; ++i) { while (x % i == 0LL) { retlist.pb(i); x /= i; } } retlist.pb(x); } bool is_prime(ll x) { V<ll> factors, factors2; get_factors(factors, x); for (auto factor : factors) { if (factor > 1) factors2.pb(factor); } return factors2.size() == 1 && x == factors2[0]; } template <typename T> void intersection(const set<T> &a, const set<T> &b, set<T> &result) { set_intersection(ALL(a), ALL(b), inserter(result, result.end())); } ull combination(ll x, ll y) { if (y > x / 2LL) y = x - y; ull ret = 1LL; for (ll i = 0LL; i < y; ++i) { ret *= x--; ret /= (i + 1LL); } return ret; } ull mod_combination(ll x, ll y, ll mod) { if (y > x / 2LL) y = x - y; ll ret = 1; for (ll i = 0LL; i < y; ++i) { ret = (ret * x--) % mod; ret = (ret * mod_inv(i + 1LL, mod)) % mod; } return ret; } void make_perms(ll perms[], ll perm_invs[], ll size, ll mod) { perms[0] = 1LL; srep(i, 1, size) { perms[i] = perms[i - 1] * i; perms[i] %= mod; } rep(i, size) { perm_invs[i] = mod_inv(perms[i], mod); } } void make_linklist(const V<t2> &srclist, V<ll> dstlist[]) { for (auto src : srclist) { ll a = get<0>(src); ll b = get<1>(src); dstlist[a].pb(b); dstlist[b].pb(a); } } void make_parental_relation(const V<ll> linklist[], ll root, ll n, ll parent[], V<ll> children[], ll level[]) { queue<ll> q; bool checked[n + 1]; memset(checked, 0, sizeof(checked)); q.push(root); checked[root] = true; parent[root] = root; level[root] = 0LL; for (; !(q.empty());) { ll now = q.front(); q.pop(); for (auto next : linklist[now]) { if (checked[next]) continue; q.push(next); checked[next] = true; parent[next] = now; children[now].pb(next); level[next] = level[now] + 1LL; } } } void make_subtree_sizes(const ll child_count[], const ll parents[], ll subtree_sizes[], ll n) { ll remain_count[n + 1LL]; memcpy(remain_count, child_count, sizeof(remain_count)); queue<ll> q; srep(node, 1LL, n + 1LL) { subtree_sizes[node] = 1LL; if (remain_count[node] > 0) continue; q.push(node); } while (!q.empty()) { ll node = q.front(); q.pop(); ll parent = parents[node]; if (node == parent) continue; remain_count[parent]--; subtree_sizes[parent] += subtree_sizes[node]; if (remain_count[parent] == 0LL) q.push(parent); } } void get_centroids(const V<ll> children[], const ll subtree_sizes[], ll root, ll n, V<ll> &centroids) { queue<ll> q; q.push(root); while (!q.empty()) { ll now = q.front(); q.pop(); bool is_centroid = true; for (auto child : children[now]) { q.push(child); if (subtree_sizes[child] > n / 2LL) is_centroid = false; } if (n - subtree_sizes[now] > n / 2LL) is_centroid = false; if (is_centroid) centroids.pb(now); } assert(centroids.size() == 1LL || centroids.size() == 2LL); } #define POW_ANCESTOR_MAXSIZE 20 // preprocess for get_common_ancestor() void make_pow_ancestor(const ll parent[], ll n, ll (*pow_ancestor)[POW_ANCESTOR_MAXSIZE]) { rep(i, n) pow_ancestor[i + 1][0] = parent[i + 1]; for (int pow2 = 1; pow(2, pow2) <= n; ++pow2) { rep(i0, n) { int i = i0 + 1; ll prev = pow_ancestor[i][pow2 - 1]; pow_ancestor[i][pow2] = pow_ancestor[prev][pow2 - 1]; } } } ll get_common_ancestor(ll n, ll x, ll y, const ll (*pow_ancestor)[POW_ANCESTOR_MAXSIZE], const ll level[]) { if (level[x] < level[y]) { ll diff = level[y] - level[x]; for (; diff;) { ll bit = diff & -diff; y = pow_ancestor[y][(int)log2(bit)]; diff -= bit; } } else { ll diff = level[x] - level[y]; for (; diff;) { ll bit = diff & -diff; x = pow_ancestor[x][(int)log2(bit)]; diff -= bit; } } if (x == y) return x; rrep(i, (int)log2(n) + 1) { if (pow_ancestor[x][i] != pow_ancestor[y][i]) { x = pow_ancestor[x][i]; y = pow_ancestor[y][i]; } } return pow_ancestor[x][0]; } void kmp_init(const string &pattern, ll kmp_next[]) { kmp_next[0] = -1LL; ll plen = pattern.size(); ll prefix_end = -1; rep(suffix_end, pattern.size()) { while (prefix_end >= 0 && pattern[suffix_end] != pattern[prefix_end]) { prefix_end = kmp_next[prefix_end]; } kmp_next[suffix_end + 1] = ++prefix_end; } kmp_next[0] = 0LL; } // founds ... list of text's idx of match position. start position idx. void kmp_search(const string &text, const string &pattern, const ll kmp_next[], V<ll> &founds) { ll text_size = text.size(); ll pattern_size = pattern.size(); ll text_start = 0LL; ll pattern_idx = 0LL; assert(pattern_size <= text_size); for (;;) { if (text_start + pattern_idx >= text_size) break; if (pattern_idx >= pattern_size) break; if (text[text_start + pattern_idx] == pattern[pattern_idx]) { pattern_idx++; if (pattern_idx == pattern_size) { founds.pb(text_start); pattern_idx = kmp_next[pattern_idx]; text_start += (pattern_size - pattern_idx); } } else { text_start += (pattern_idx - kmp_next[pattern_idx]); pattern_idx = kmp_next[pattern_idx]; if (pattern_idx == 0LL && text[text_start] != pattern[0]) { text_start++; } } } } void z_algorithm(ll matchcounts[], const string &str) { ll n = str.size(); ll base_idx = 0LL; memset(matchcounts, 0, sizeof(ll) * n); srep(idx, 1LL, n) { ll checked_len = base_idx + matchcounts[base_idx]; if (idx + matchcounts[idx - base_idx] < checked_len) { matchcounts[idx] = matchcounts[idx - base_idx]; continue; } ll start = max(0LL, base_idx + matchcounts[base_idx] - idx); matchcounts[idx] = start; srep(cmp, start, n - idx) { if (str[cmp] == str[idx + cmp]) matchcounts[idx]++; else break; } base_idx = idx; } matchcounts[0] = n; } void _debug_print(auto x) { cout << x << endl; } void _debug_print(const t2 &x) { ll x1 = get<0>(x); ll x2 = get<1>(x); cout << "-- " << x1 << " -- " << x2 << endl; } void _debug_print(const t3 &x) { ll x1 = get<0>(x); ll x2 = get<1>(x); ll x3 = get<2>(x); cout << "-- " << x1 << " -- " << x2 << " -- " << x3 << endl; } void _debug_print(const t4 &x) { ll x1 = get<0>(x); ll x2 = get<1>(x); ll x3 = get<2>(x); ll x4 = get<3>(x); cout << "-- " << x1 << " -- " << x2 << " -- " << x3 << " -- " << x4 << endl; } template <typename T> void _debug_print(T xarray[], ll n) { rep(i, n) _debug_print(xarray[i]); } template <typename T> void _debug_print(const V<T> &xlist) { for (auto x : xlist) { cout << "-- "; _debug_print(x); } } template <typename T> void _debug_print(const set<T> &xset) { for (auto x : xset) { cout << "-- "; _debug_print(x); } } template <typename TT, typename T> void _debug_print(const M<TT, T> &xlist) { for (auto x : xlist) { TT k = x.first; T v = x.second; cout << "====" << endl; cout << "K="; _debug_print(k); cout << "V="; _debug_print(v); } } void _debug_print_time(const char *prefix) { struct timeval tv; gettimeofday(&tv, NULL); struct tm *tm = localtime(&tv.tv_sec); printf("-- %s %02d:%02d:%02d.%06ld\n", prefix, tm->tm_hour, tm->tm_min, tm->tm_sec, tv.tv_usec); } /////////////////////////////////////////////////////////////////////////////// void _main(); int main() { cout << setprecision(12); _main(); return 0; } void _main() { ll n; llin(n); ll duration; llin(duration); S V<t2> ablist; llinl2(ablist, n); S V<t2> bmalist; for (auto ab : ablist) bmalist.pb(t2(get<1>(ab), -get<0>(ab))); sort_reverse(bmalist); ll ans = 0LL; S BIT tree(n + 1, 0LL); for (auto bma : bmalist) { ll a = -get<1>(bma); ll b = get<0>(bma); if (duration < a) continue; ll sub = duration - a + 1 - tree.sum(duration - a + 1); if (sub <= 0LL) continue; debug_printf("a=%lld b=%lld sub=%lld len=%lld\n", a, b, sub, duration - a + 1); ll left = 1LL; ll right = duration - a + 1; ll now = (left + right) / 2LL; ll pos = 1e18; for (; left <= right; now = (left + right) / 2LL) { if (now - tree.sum(now) >= sub) { pos = min(pos, now); right = now - 1LL; } else { left = now + 1LL; } } debug_printf(" pos=%lld\n", pos); tree.add(pos, 1LL); ans += b; } cout << ans << endl; } ///////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////// #include <bits/stdc++.h> #include <sys/time.h> #include <time.h> #include <unistd.h> using namespace std; /////////////////////////////////////////////////////////////////////////////// #define DEBUG 0 #define pb push_back #define V vector #define M unordered_map #define S static #define rep(i, n) for (ll i = 0LL; i < n; ++i) #define srep(i, s, n) for (ll i = s; i < n; ++i) #define rrep(i, n) for (ll i = n - 1LL; i >= 0LL; --i) #define ALL(a) (a).begin(), (a).end() #define CIN(x) \ do { \ assert(!cin.eof()); \ cin >> x; \ assert(!cin.fail()); \ } while (0); #if DEBUG #define debug_print(...) _debug_print(__VA_ARGS__) #define debug_printf(...) printf(__VA_ARGS__) #define debug_print_time _debug_print_time #else // DEBUG #define debug_print(...) #define debug_printf(...) #define debug_print_time #endif // DEBUG typedef long long ll; typedef unsigned long long ull; typedef tuple<ll, ll> t2; typedef tuple<ll, ll, ll> t3; typedef tuple<ll, ll, ll, ll> t4; typedef tuple<ll, ll, ll, ll, ll> t5; template <typename T> using priority_queue_incr = priority_queue<T, V<T>, greater<T>>; /////////////////////////////////////////////////////////////////////////////// template <typename TT, typename T> T get_m(M<TT, T> &m, TT k, T default_value) { if (m.find(k) == m.end()) return m[k] = default_value; return m[k]; } template <typename TT, typename T> void incr_m(M<TT, T> &m, TT k) { if (m.find(k) == m.end()) m[k] = 0; m[k]++; } struct UnionFind { ull *parent, *count, *rank; UnionFind(ull n) { parent = new ull[n + 1]; count = new ull[n + 1]; rank = new ull[n + 1]; for (ull i = 0ULL; i < n + 1; ++i) { parent[i] = i; count[i] = 1; rank[i] = 0; } } ~UnionFind() { delete rank; delete count; delete parent; } ull root(ull i) { if (parent[i] == i) return i; parent[i] = root(parent[i]); return parent[i]; } void unite(ull i, ull j) { ull rooti = root(i); ull rootj = root(j); if (rooti == rootj) return; if (rank[rootj] < rank[rooti]) { parent[i] = parent[j] = parent[rootj] = rooti; count[rooti] += count[rootj]; } else { parent[i] = parent[j] = parent[rooti] = rootj; count[rootj] += count[rooti]; if (rank[rootj] == rank[rooti]) rank[rootj]++; } } bool same(ull i, ull j) { return root(i) == root(j); } }; struct UnionFindM { M<ull, ull> parent, count, rank; ull root(ull i) { ull parent_i = get_m(parent, i, i); if (parent_i == i) return i; return parent[i] = root(parent_i); } void unite(ull i, ull j) { ull rooti = root(i); ull rootj = root(j); if (rooti == rootj) return; if (get_m(rank, rootj, 0ULL) < get_m(rank, rooti, 0ULL)) { parent[i] = parent[j] = parent[rootj] = rooti; count[rooti] = get_m(count, rooti, 1ULL) + get_m(count, rootj, 1ULL); } else { parent[i] = parent[j] = parent[rooti] = rootj; count[rootj] = get_m(count, rootj, 1ULL) + get_m(count, rooti, 1ULL); if (get_m(rank, rootj, 0ULL) == get_m(rank, rooti, 0ULL)) rank[rootj]++; } } bool same(ull i, ull j) { return root(i) == root(j); } }; struct BIT { ll *tree; ll size; BIT(ll n, ll init) { tree = new ll[n + 1]; size = n; this->init(init); } void init(ll init) { memset(tree, 0, sizeof(ll) * (size + 1)); rep(i0, size) { ll idx = i0 + 1LL; while (idx <= size) { tree[idx] += init; idx += (idx & (-idx)); } } } // idx is 1 origin void add(ll idx, ll x) { assert(idx > 0LL); while (idx <= size) { tree[idx] += x; idx += (idx & (-idx)); } } // idx is 1 origin ll sum(ll idx) { assert(idx > 0LL); ll ret = 0LL; while (idx > 0LL) { ret += tree[idx]; idx -= (idx & (-idx)); } return ret; } }; struct MaxFlow { V<ll> links[1005]; ll capacities[1005][1005]; ll nodes; MaxFlow(ll nodes) { // i == 0 --> S // i == nodes+1 --> T rep(i, nodes + 2LL) links[i].clear(); memset(capacities, 0, sizeof(capacities)); this->nodes = nodes; } void add_path(ll a, ll b, ll capacity) { links[a].pb(b); links[b].pb(a); capacities[a][b] = capacity; capacities[b][a] = 0LL; } ll solve(void) { deque<V<ll>> q; ll ret = 0LL; for (;; q.clear()) { V<ll> start; start.pb(0); q.push_front(start); bool checked[nodes + 2]; memset(checked, 0, sizeof(checked)); V<ll> found; for (; !(q.empty());) { V<ll> path = q.front(); q.pop_front(); ll last = path[path.size() - 1]; if (checked[last]) continue; if (last == nodes + 1) { found = path; break; } checked[last] = true; for (auto next : (links[last])) { if (capacities[last][next] == 0) continue; V<ll> newpath(path); newpath.pb(next); q.push_front(newpath); } } if (found.size() == 0) { break; } else { ll flowcount = capacities[found[0]][found[1]]; rep(i, found.size() - 1) { ll src = found[i]; ll dst = found[i + 1]; flowcount = min(flowcount, capacities[src][dst]); } rep(i, found.size() - 1) { ll src = found[i]; ll dst = found[i + 1]; capacities[src][dst] -= flowcount; capacities[dst][src] += flowcount; } ret += flowcount; } } return ret; } }; template <typename T> struct SegmentTree { T *nodes; t2 *ranges; // [start, end) ll nodecount; ll itemcount; T unit; T (*op)(T, T); SegmentTree(ll itemcount, T unit, T op(T, T)) { ll orig_itemcount = itemcount; this->itemcount = 1LL; while (this->itemcount < orig_itemcount) this->itemcount *= 2LL; nodecount = this->itemcount * 2 - 1; nodes = new T[nodecount]; ranges = new t2[nodecount]; this->unit = unit; this->op = op; ll start = 0LL; ll end = this->itemcount; ll len = this->itemcount; rep(i, nodecount) { nodes[i] = unit; ranges[i] = t2(start, end); if (end >= this->itemcount) { len /= 2LL; start = 0LL; end = len; } else { start = end; end = start + len; } } } void update(ll k, T v) { ll idx = k + itemcount - 1LL; nodes[idx] = v; idx = (idx - 1LL) / 2LL; for (; idx >= 0; idx = (idx - 1LL) / 2LL) { nodes[idx] = op(nodes[idx * 2LL + 1LL], nodes[idx * 2LL + 2LL]); if (!idx) break; } } // query to [start, end) T query(ll start, ll end) const { return _query(start, end, 0LL); } T _query(ll start, ll end, ll idx) const { ll rstart = get<0>(ranges[idx]); ll rend = get<1>(ranges[idx]); if (start <= rstart && rend <= end) { return nodes[idx]; } if (rend <= start || end <= rstart) { return unit; } T left = _query(start, end, idx * 2LL + 1LL); T right = _query(start, end, idx * 2LL + 2LL); return op(left, right); } }; void llin(ll &a) { CIN(a); } void llinl1(auto &v, ll count) { for (ll i = 0LL; i < count; ++i) { ll a; CIN(a); v.push_back(a); } } void llinl2(auto &v, ll count) { for (ll i = 0LL; i < count; ++i) { ll a, b; CIN(a >> b); v.push_back(t2(a, b)); } } void llinl3(auto &v, ll count) { for (ll i = 0LL; i < count; ++i) { ll a, b, c; CIN(a >> b >> c); v.push_back(t3(a, b, c)); } } void llinl4(auto &v, ll count) { for (ll i = 0LL; i < count; ++i) { ll a, b, c, d; CIN(a >> b >> c >> d); v.push_back(t4(a, b, c, d)); } } void llina(auto &v, ll count) { llinl1(v, count); } template <typename T> T min(const V<T> v) { T ret = v[0]; for (auto i : v) ret = min(ret, i); return ret; } template <typename T> T max(const V<T> v) { T ret = v[0]; for (auto i : v) ret = max(ret, i); return ret; } ll absll(ll x) { if (x < 0) return -x; return x; } ll mod_mlt(ll x, ll y, ll mod) { ll ret = 0LL; x %= mod; while (y) { if (y & 1LL) { ret += x; ret %= mod; } y >>= 1; x <<= 1; x %= mod; } return ret; } // O(log(exp)) ll mod_pow(ll base, ll exp, ll mod) { ll ret = 1LL; for (; exp;) { if (exp & 1LL) { ret *= base; ret %= mod; } base = (base * base) % mod; exp >>= 1; } return ret; } // O(log(mod)) ll mod_inv(ll x, ll mod) { // available only when mod is prime return mod_pow(x, mod - 2LL, mod); } ll gcm(ll x, ll y) { while (y != 0) { ll z = x % y; x = y; y = z; } return x; } template <typename T> void sort(V<T> &v) { sort(v.begin(), v.end()); } template <typename T> void sort_reverse(V<T> &v) { sort(v.begin(), v.end(), greater<T>()); } void get_divisors(V<ll> &retlist, ll x) { for (ll i = 1LL; i < sqrt(x) + 3LL; ++i) { if (x % i == 0LL) { retlist.push_back(i); retlist.push_back(x / i); } } } // returns factors and 1 void get_factors(V<ll> &retlist, ll x) { retlist.pb(1LL); for (ll i = 2LL; i < (ll)(sqrt(x)) + 3LL; ++i) { while (x % i == 0LL) { retlist.pb(i); x /= i; } } retlist.pb(x); } bool is_prime(ll x) { V<ll> factors, factors2; get_factors(factors, x); for (auto factor : factors) { if (factor > 1) factors2.pb(factor); } return factors2.size() == 1 && x == factors2[0]; } template <typename T> void intersection(const set<T> &a, const set<T> &b, set<T> &result) { set_intersection(ALL(a), ALL(b), inserter(result, result.end())); } ull combination(ll x, ll y) { if (y > x / 2LL) y = x - y; ull ret = 1LL; for (ll i = 0LL; i < y; ++i) { ret *= x--; ret /= (i + 1LL); } return ret; } ull mod_combination(ll x, ll y, ll mod) { if (y > x / 2LL) y = x - y; ll ret = 1; for (ll i = 0LL; i < y; ++i) { ret = (ret * x--) % mod; ret = (ret * mod_inv(i + 1LL, mod)) % mod; } return ret; } void make_perms(ll perms[], ll perm_invs[], ll size, ll mod) { perms[0] = 1LL; srep(i, 1, size) { perms[i] = perms[i - 1] * i; perms[i] %= mod; } rep(i, size) { perm_invs[i] = mod_inv(perms[i], mod); } } void make_linklist(const V<t2> &srclist, V<ll> dstlist[]) { for (auto src : srclist) { ll a = get<0>(src); ll b = get<1>(src); dstlist[a].pb(b); dstlist[b].pb(a); } } void make_parental_relation(const V<ll> linklist[], ll root, ll n, ll parent[], V<ll> children[], ll level[]) { queue<ll> q; bool checked[n + 1]; memset(checked, 0, sizeof(checked)); q.push(root); checked[root] = true; parent[root] = root; level[root] = 0LL; for (; !(q.empty());) { ll now = q.front(); q.pop(); for (auto next : linklist[now]) { if (checked[next]) continue; q.push(next); checked[next] = true; parent[next] = now; children[now].pb(next); level[next] = level[now] + 1LL; } } } void make_subtree_sizes(const ll child_count[], const ll parents[], ll subtree_sizes[], ll n) { ll remain_count[n + 1LL]; memcpy(remain_count, child_count, sizeof(remain_count)); queue<ll> q; srep(node, 1LL, n + 1LL) { subtree_sizes[node] = 1LL; if (remain_count[node] > 0) continue; q.push(node); } while (!q.empty()) { ll node = q.front(); q.pop(); ll parent = parents[node]; if (node == parent) continue; remain_count[parent]--; subtree_sizes[parent] += subtree_sizes[node]; if (remain_count[parent] == 0LL) q.push(parent); } } void get_centroids(const V<ll> children[], const ll subtree_sizes[], ll root, ll n, V<ll> &centroids) { queue<ll> q; q.push(root); while (!q.empty()) { ll now = q.front(); q.pop(); bool is_centroid = true; for (auto child : children[now]) { q.push(child); if (subtree_sizes[child] > n / 2LL) is_centroid = false; } if (n - subtree_sizes[now] > n / 2LL) is_centroid = false; if (is_centroid) centroids.pb(now); } assert(centroids.size() == 1LL || centroids.size() == 2LL); } #define POW_ANCESTOR_MAXSIZE 20 // preprocess for get_common_ancestor() void make_pow_ancestor(const ll parent[], ll n, ll (*pow_ancestor)[POW_ANCESTOR_MAXSIZE]) { rep(i, n) pow_ancestor[i + 1][0] = parent[i + 1]; for (int pow2 = 1; pow(2, pow2) <= n; ++pow2) { rep(i0, n) { int i = i0 + 1; ll prev = pow_ancestor[i][pow2 - 1]; pow_ancestor[i][pow2] = pow_ancestor[prev][pow2 - 1]; } } } ll get_common_ancestor(ll n, ll x, ll y, const ll (*pow_ancestor)[POW_ANCESTOR_MAXSIZE], const ll level[]) { if (level[x] < level[y]) { ll diff = level[y] - level[x]; for (; diff;) { ll bit = diff & -diff; y = pow_ancestor[y][(int)log2(bit)]; diff -= bit; } } else { ll diff = level[x] - level[y]; for (; diff;) { ll bit = diff & -diff; x = pow_ancestor[x][(int)log2(bit)]; diff -= bit; } } if (x == y) return x; rrep(i, (int)log2(n) + 1) { if (pow_ancestor[x][i] != pow_ancestor[y][i]) { x = pow_ancestor[x][i]; y = pow_ancestor[y][i]; } } return pow_ancestor[x][0]; } void kmp_init(const string &pattern, ll kmp_next[]) { kmp_next[0] = -1LL; ll plen = pattern.size(); ll prefix_end = -1; rep(suffix_end, pattern.size()) { while (prefix_end >= 0 && pattern[suffix_end] != pattern[prefix_end]) { prefix_end = kmp_next[prefix_end]; } kmp_next[suffix_end + 1] = ++prefix_end; } kmp_next[0] = 0LL; } // founds ... list of text's idx of match position. start position idx. void kmp_search(const string &text, const string &pattern, const ll kmp_next[], V<ll> &founds) { ll text_size = text.size(); ll pattern_size = pattern.size(); ll text_start = 0LL; ll pattern_idx = 0LL; assert(pattern_size <= text_size); for (;;) { if (text_start + pattern_idx >= text_size) break; if (pattern_idx >= pattern_size) break; if (text[text_start + pattern_idx] == pattern[pattern_idx]) { pattern_idx++; if (pattern_idx == pattern_size) { founds.pb(text_start); pattern_idx = kmp_next[pattern_idx]; text_start += (pattern_size - pattern_idx); } } else { text_start += (pattern_idx - kmp_next[pattern_idx]); pattern_idx = kmp_next[pattern_idx]; if (pattern_idx == 0LL && text[text_start] != pattern[0]) { text_start++; } } } } void z_algorithm(ll matchcounts[], const string &str) { ll n = str.size(); ll base_idx = 0LL; memset(matchcounts, 0, sizeof(ll) * n); srep(idx, 1LL, n) { ll checked_len = base_idx + matchcounts[base_idx]; if (idx + matchcounts[idx - base_idx] < checked_len) { matchcounts[idx] = matchcounts[idx - base_idx]; continue; } ll start = max(0LL, base_idx + matchcounts[base_idx] - idx); matchcounts[idx] = start; srep(cmp, start, n - idx) { if (str[cmp] == str[idx + cmp]) matchcounts[idx]++; else break; } base_idx = idx; } matchcounts[0] = n; } void _debug_print(auto x) { cout << x << endl; } void _debug_print(const t2 &x) { ll x1 = get<0>(x); ll x2 = get<1>(x); cout << "-- " << x1 << " -- " << x2 << endl; } void _debug_print(const t3 &x) { ll x1 = get<0>(x); ll x2 = get<1>(x); ll x3 = get<2>(x); cout << "-- " << x1 << " -- " << x2 << " -- " << x3 << endl; } void _debug_print(const t4 &x) { ll x1 = get<0>(x); ll x2 = get<1>(x); ll x3 = get<2>(x); ll x4 = get<3>(x); cout << "-- " << x1 << " -- " << x2 << " -- " << x3 << " -- " << x4 << endl; } template <typename T> void _debug_print(T xarray[], ll n) { rep(i, n) _debug_print(xarray[i]); } template <typename T> void _debug_print(const V<T> &xlist) { for (auto x : xlist) { cout << "-- "; _debug_print(x); } } template <typename T> void _debug_print(const set<T> &xset) { for (auto x : xset) { cout << "-- "; _debug_print(x); } } template <typename TT, typename T> void _debug_print(const M<TT, T> &xlist) { for (auto x : xlist) { TT k = x.first; T v = x.second; cout << "====" << endl; cout << "K="; _debug_print(k); cout << "V="; _debug_print(v); } } void _debug_print_time(const char *prefix) { struct timeval tv; gettimeofday(&tv, NULL); struct tm *tm = localtime(&tv.tv_sec); printf("-- %s %02d:%02d:%02d.%06ld\n", prefix, tm->tm_hour, tm->tm_min, tm->tm_sec, tv.tv_usec); } /////////////////////////////////////////////////////////////////////////////// void _main(); int main() { cout << setprecision(12); _main(); return 0; } void _main() { ll n; llin(n); ll duration; llin(duration); S V<t2> ablist; llinl2(ablist, n); S V<t2> bmalist; for (auto ab : ablist) bmalist.pb(t2(get<1>(ab), -get<0>(ab))); sort_reverse(bmalist); ll ans = 0LL; S BIT tree(100005, 0LL); for (auto bma : bmalist) { ll a = -get<1>(bma); ll b = get<0>(bma); if (duration < a) continue; ll sub = duration - a + 1 - tree.sum(duration - a + 1); if (sub <= 0LL) continue; debug_printf("a=%lld b=%lld sub=%lld len=%lld\n", a, b, sub, duration - a + 1); ll left = 1LL; ll right = duration - a + 1; ll now = (left + right) / 2LL; ll pos = 1e18; for (; left <= right; now = (left + right) / 2LL) { if (now - tree.sum(now) >= sub) { pos = min(pos, now); right = now - 1LL; } else { left = now + 1LL; } } debug_printf(" pos=%lld\n", pos); tree.add(pos, 1LL); ans += b; } cout << ans << endl; } ///////////////////////////////////////////////////////////////////////////////
[ "identifier.replace.remove", "literal.replace.add", "call.arguments.change", "expression.operation.binary.change", "expression.operation.binary.remove" ]
750,089
750,090
u167931717
cpp
p02948
/////////////////////////////////////////////////////////////////////////////// #include <bits/stdc++.h> #include <sys/time.h> #include <time.h> #include <unistd.h> using namespace std; /////////////////////////////////////////////////////////////////////////////// #define DEBUG 0 #define pb push_back #define V vector #define M unordered_map #define S static #define rep(i, n) for (ll i = 0LL; i < n; ++i) #define srep(i, s, n) for (ll i = s; i < n; ++i) #define rrep(i, n) for (ll i = n - 1LL; i >= 0LL; --i) #define ALL(a) (a).begin(), (a).end() #define CIN(x) \ do { \ assert(!cin.eof()); \ cin >> x; \ assert(!cin.fail()); \ } while (0); #if DEBUG #define debug_print(...) _debug_print(__VA_ARGS__) #define debug_printf(...) printf(__VA_ARGS__) #define debug_print_time _debug_print_time #else // DEBUG #define debug_print(...) #define debug_printf(...) #define debug_print_time #endif // DEBUG typedef long long ll; typedef unsigned long long ull; typedef tuple<ll, ll> t2; typedef tuple<ll, ll, ll> t3; typedef tuple<ll, ll, ll, ll> t4; typedef tuple<ll, ll, ll, ll, ll> t5; template <typename T> using priority_queue_incr = priority_queue<T, V<T>, greater<T>>; /////////////////////////////////////////////////////////////////////////////// template <typename TT, typename T> T get_m(M<TT, T> &m, TT k, T default_value) { if (m.find(k) == m.end()) return m[k] = default_value; return m[k]; } template <typename TT, typename T> void incr_m(M<TT, T> &m, TT k) { if (m.find(k) == m.end()) m[k] = 0; m[k]++; } struct UnionFind { ull *parent, *count, *rank; UnionFind(ull n) { parent = new ull[n + 1]; count = new ull[n + 1]; rank = new ull[n + 1]; for (ull i = 0ULL; i < n + 1; ++i) { parent[i] = i; count[i] = 1; rank[i] = 0; } } ~UnionFind() { delete rank; delete count; delete parent; } ull root(ull i) { if (parent[i] == i) return i; parent[i] = root(parent[i]); return parent[i]; } void unite(ull i, ull j) { ull rooti = root(i); ull rootj = root(j); if (rooti == rootj) return; if (rank[rootj] < rank[rooti]) { parent[i] = parent[j] = parent[rootj] = rooti; count[rooti] += count[rootj]; } else { parent[i] = parent[j] = parent[rooti] = rootj; count[rootj] += count[rooti]; if (rank[rootj] == rank[rooti]) rank[rootj]++; } } bool same(ull i, ull j) { return root(i) == root(j); } }; struct UnionFindM { M<ull, ull> parent, count, rank; ull root(ull i) { ull parent_i = get_m(parent, i, i); if (parent_i == i) return i; return parent[i] = root(parent_i); } void unite(ull i, ull j) { ull rooti = root(i); ull rootj = root(j); if (rooti == rootj) return; if (get_m(rank, rootj, 0ULL) < get_m(rank, rooti, 0ULL)) { parent[i] = parent[j] = parent[rootj] = rooti; count[rooti] = get_m(count, rooti, 1ULL) + get_m(count, rootj, 1ULL); } else { parent[i] = parent[j] = parent[rooti] = rootj; count[rootj] = get_m(count, rootj, 1ULL) + get_m(count, rooti, 1ULL); if (get_m(rank, rootj, 0ULL) == get_m(rank, rooti, 0ULL)) rank[rootj]++; } } bool same(ull i, ull j) { return root(i) == root(j); } }; struct BIT { ll *tree; ll size; BIT(ll n, ll init) { tree = new ll[n + 1]; size = n; this->init(init); } void init(ll init) { memset(tree, 0, sizeof(ll) * (size + 1)); rep(i0, size) { ll idx = i0 + 1LL; while (idx <= size) { tree[idx] += init; idx += (idx & (-idx)); } } } // idx is 1 origin void add(ll idx, ll x) { assert(idx > 0LL); while (idx <= size) { tree[idx] += x; idx += (idx & (-idx)); } } // idx is 1 origin ll sum(ll idx) { assert(idx > 0LL); ll ret = 0LL; while (idx > 0LL) { ret += tree[idx]; idx -= (idx & (-idx)); } return ret; } }; struct MaxFlow { V<ll> links[1005]; ll capacities[1005][1005]; ll nodes; MaxFlow(ll nodes) { // i == 0 --> S // i == nodes+1 --> T rep(i, nodes + 2LL) links[i].clear(); memset(capacities, 0, sizeof(capacities)); this->nodes = nodes; } void add_path(ll a, ll b, ll capacity) { links[a].pb(b); links[b].pb(a); capacities[a][b] = capacity; capacities[b][a] = 0LL; } ll solve(void) { deque<V<ll>> q; ll ret = 0LL; for (;; q.clear()) { V<ll> start; start.pb(0); q.push_front(start); bool checked[nodes + 2]; memset(checked, 0, sizeof(checked)); V<ll> found; for (; !(q.empty());) { V<ll> path = q.front(); q.pop_front(); ll last = path[path.size() - 1]; if (checked[last]) continue; if (last == nodes + 1) { found = path; break; } checked[last] = true; for (auto next : (links[last])) { if (capacities[last][next] == 0) continue; V<ll> newpath(path); newpath.pb(next); q.push_front(newpath); } } if (found.size() == 0) { break; } else { ll flowcount = capacities[found[0]][found[1]]; rep(i, found.size() - 1) { ll src = found[i]; ll dst = found[i + 1]; flowcount = min(flowcount, capacities[src][dst]); } rep(i, found.size() - 1) { ll src = found[i]; ll dst = found[i + 1]; capacities[src][dst] -= flowcount; capacities[dst][src] += flowcount; } ret += flowcount; } } return ret; } }; template <typename T> struct SegmentTree { T *nodes; t2 *ranges; // [start, end) ll nodecount; ll itemcount; T unit; T (*op)(T, T); SegmentTree(ll itemcount, T unit, T op(T, T)) { ll orig_itemcount = itemcount; this->itemcount = 1LL; while (this->itemcount < orig_itemcount) this->itemcount *= 2LL; nodecount = this->itemcount * 2 - 1; nodes = new T[nodecount]; ranges = new t2[nodecount]; this->unit = unit; this->op = op; ll start = 0LL; ll end = this->itemcount; ll len = this->itemcount; rep(i, nodecount) { nodes[i] = unit; ranges[i] = t2(start, end); if (end >= this->itemcount) { len /= 2LL; start = 0LL; end = len; } else { start = end; end = start + len; } } } void update(ll k, T v) { ll idx = k + itemcount - 1LL; nodes[idx] = v; idx = (idx - 1LL) / 2LL; for (; idx >= 0; idx = (idx - 1LL) / 2LL) { nodes[idx] = op(nodes[idx * 2LL + 1LL], nodes[idx * 2LL + 2LL]); if (!idx) break; } } // query to [start, end) T query(ll start, ll end) const { return _query(start, end, 0LL); } T _query(ll start, ll end, ll idx) const { ll rstart = get<0>(ranges[idx]); ll rend = get<1>(ranges[idx]); if (start <= rstart && rend <= end) { return nodes[idx]; } if (rend <= start || end <= rstart) { return unit; } T left = _query(start, end, idx * 2LL + 1LL); T right = _query(start, end, idx * 2LL + 2LL); return op(left, right); } }; void llin(ll &a) { CIN(a); } void llinl1(auto &v, ll count) { for (ll i = 0LL; i < count; ++i) { ll a; CIN(a); v.push_back(a); } } void llinl2(auto &v, ll count) { for (ll i = 0LL; i < count; ++i) { ll a, b; CIN(a >> b); v.push_back(t2(a, b)); } } void llinl3(auto &v, ll count) { for (ll i = 0LL; i < count; ++i) { ll a, b, c; CIN(a >> b >> c); v.push_back(t3(a, b, c)); } } void llinl4(auto &v, ll count) { for (ll i = 0LL; i < count; ++i) { ll a, b, c, d; CIN(a >> b >> c >> d); v.push_back(t4(a, b, c, d)); } } void llina(auto &v, ll count) { llinl1(v, count); } template <typename T> T min(const V<T> v) { T ret = v[0]; for (auto i : v) ret = min(ret, i); return ret; } template <typename T> T max(const V<T> v) { T ret = v[0]; for (auto i : v) ret = max(ret, i); return ret; } ll absll(ll x) { if (x < 0) return -x; return x; } ll mod_mlt(ll x, ll y, ll mod) { ll ret = 0LL; x %= mod; while (y) { if (y & 1LL) { ret += x; ret %= mod; } y >>= 1; x <<= 1; x %= mod; } return ret; } // O(log(exp)) ll mod_pow(ll base, ll exp, ll mod) { ll ret = 1LL; for (; exp;) { if (exp & 1LL) { ret *= base; ret %= mod; } base = (base * base) % mod; exp >>= 1; } return ret; } // O(log(mod)) ll mod_inv(ll x, ll mod) { // available only when mod is prime return mod_pow(x, mod - 2LL, mod); } ll gcm(ll x, ll y) { while (y != 0) { ll z = x % y; x = y; y = z; } return x; } template <typename T> void sort(V<T> &v) { sort(v.begin(), v.end()); } template <typename T> void sort_reverse(V<T> &v) { sort(v.begin(), v.end(), greater<T>()); } void get_divisors(V<ll> &retlist, ll x) { for (ll i = 1LL; i < sqrt(x) + 3LL; ++i) { if (x % i == 0LL) { retlist.push_back(i); retlist.push_back(x / i); } } } // returns factors and 1 void get_factors(V<ll> &retlist, ll x) { retlist.pb(1LL); for (ll i = 2LL; i < (ll)(sqrt(x)) + 3LL; ++i) { while (x % i == 0LL) { retlist.pb(i); x /= i; } } retlist.pb(x); } bool is_prime(ll x) { V<ll> factors, factors2; get_factors(factors, x); for (auto factor : factors) { if (factor > 1) factors2.pb(factor); } return factors2.size() == 1 && x == factors2[0]; } template <typename T> void intersection(const set<T> &a, const set<T> &b, set<T> &result) { set_intersection(ALL(a), ALL(b), inserter(result, result.end())); } ull combination(ll x, ll y) { if (y > x / 2LL) y = x - y; ull ret = 1LL; for (ll i = 0LL; i < y; ++i) { ret *= x--; ret /= (i + 1LL); } return ret; } ull mod_combination(ll x, ll y, ll mod) { if (y > x / 2LL) y = x - y; ll ret = 1; for (ll i = 0LL; i < y; ++i) { ret = (ret * x--) % mod; ret = (ret * mod_inv(i + 1LL, mod)) % mod; } return ret; } void make_perms(ll perms[], ll perm_invs[], ll size, ll mod) { perms[0] = 1LL; srep(i, 1, size) { perms[i] = perms[i - 1] * i; perms[i] %= mod; } rep(i, size) { perm_invs[i] = mod_inv(perms[i], mod); } } void make_linklist(const V<t2> &srclist, V<ll> dstlist[]) { for (auto src : srclist) { ll a = get<0>(src); ll b = get<1>(src); dstlist[a].pb(b); dstlist[b].pb(a); } } void make_parental_relation(const V<ll> linklist[], ll root, ll n, ll parent[], V<ll> children[], ll level[]) { queue<ll> q; bool checked[n + 1]; memset(checked, 0, sizeof(checked)); q.push(root); checked[root] = true; parent[root] = root; level[root] = 0LL; for (; !(q.empty());) { ll now = q.front(); q.pop(); for (auto next : linklist[now]) { if (checked[next]) continue; q.push(next); checked[next] = true; parent[next] = now; children[now].pb(next); level[next] = level[now] + 1LL; } } } void make_subtree_sizes(const ll child_count[], const ll parents[], ll subtree_sizes[], ll n) { ll remain_count[n + 1LL]; memcpy(remain_count, child_count, sizeof(remain_count)); queue<ll> q; srep(node, 1LL, n + 1LL) { subtree_sizes[node] = 1LL; if (remain_count[node] > 0) continue; q.push(node); } while (!q.empty()) { ll node = q.front(); q.pop(); ll parent = parents[node]; if (node == parent) continue; remain_count[parent]--; subtree_sizes[parent] += subtree_sizes[node]; if (remain_count[parent] == 0LL) q.push(parent); } } void get_centroids(const V<ll> children[], const ll subtree_sizes[], ll root, ll n, V<ll> &centroids) { queue<ll> q; q.push(root); while (!q.empty()) { ll now = q.front(); q.pop(); bool is_centroid = true; for (auto child : children[now]) { q.push(child); if (subtree_sizes[child] > n / 2LL) is_centroid = false; } if (n - subtree_sizes[now] > n / 2LL) is_centroid = false; if (is_centroid) centroids.pb(now); } assert(centroids.size() == 1LL || centroids.size() == 2LL); } #define POW_ANCESTOR_MAXSIZE 20 // preprocess for get_common_ancestor() void make_pow_ancestor(const ll parent[], ll n, ll (*pow_ancestor)[POW_ANCESTOR_MAXSIZE]) { rep(i, n) pow_ancestor[i + 1][0] = parent[i + 1]; for (int pow2 = 1; pow(2, pow2) <= n; ++pow2) { rep(i0, n) { int i = i0 + 1; ll prev = pow_ancestor[i][pow2 - 1]; pow_ancestor[i][pow2] = pow_ancestor[prev][pow2 - 1]; } } } ll get_common_ancestor(ll n, ll x, ll y, const ll (*pow_ancestor)[POW_ANCESTOR_MAXSIZE], const ll level[]) { if (level[x] < level[y]) { ll diff = level[y] - level[x]; for (; diff;) { ll bit = diff & -diff; y = pow_ancestor[y][(int)log2(bit)]; diff -= bit; } } else { ll diff = level[x] - level[y]; for (; diff;) { ll bit = diff & -diff; x = pow_ancestor[x][(int)log2(bit)]; diff -= bit; } } if (x == y) return x; rrep(i, (int)log2(n) + 1) { if (pow_ancestor[x][i] != pow_ancestor[y][i]) { x = pow_ancestor[x][i]; y = pow_ancestor[y][i]; } } return pow_ancestor[x][0]; } void kmp_init(const string &pattern, ll kmp_next[]) { kmp_next[0] = -1LL; ll plen = pattern.size(); ll prefix_end = -1; rep(suffix_end, pattern.size()) { while (prefix_end >= 0 && pattern[suffix_end] != pattern[prefix_end]) { prefix_end = kmp_next[prefix_end]; } kmp_next[suffix_end + 1] = ++prefix_end; } kmp_next[0] = 0LL; } // founds ... list of text's idx of match position. start position idx. void kmp_search(const string &text, const string &pattern, const ll kmp_next[], V<ll> &founds) { ll text_size = text.size(); ll pattern_size = pattern.size(); ll text_start = 0LL; ll pattern_idx = 0LL; assert(pattern_size <= text_size); for (;;) { if (text_start + pattern_idx >= text_size) break; if (pattern_idx >= pattern_size) break; if (text[text_start + pattern_idx] == pattern[pattern_idx]) { pattern_idx++; if (pattern_idx == pattern_size) { founds.pb(text_start); pattern_idx = kmp_next[pattern_idx]; text_start += (pattern_size - pattern_idx); } } else { text_start += (pattern_idx - kmp_next[pattern_idx]); pattern_idx = kmp_next[pattern_idx]; if (pattern_idx == 0LL && text[text_start] != pattern[0]) { text_start++; } } } } void z_algorithm(ll matchcounts[], const string &str) { ll n = str.size(); ll base_idx = 0LL; memset(matchcounts, 0, sizeof(ll) * n); srep(idx, 1LL, n) { ll checked_len = base_idx + matchcounts[base_idx]; if (idx + matchcounts[idx - base_idx] < checked_len) { matchcounts[idx] = matchcounts[idx - base_idx]; continue; } ll start = max(0LL, base_idx + matchcounts[base_idx] - idx); matchcounts[idx] = start; srep(cmp, start, n - idx) { if (str[cmp] == str[idx + cmp]) matchcounts[idx]++; else break; } base_idx = idx; } matchcounts[0] = n; } void _debug_print(auto x) { cout << x << endl; } void _debug_print(const t2 &x) { ll x1 = get<0>(x); ll x2 = get<1>(x); cout << "-- " << x1 << " -- " << x2 << endl; } void _debug_print(const t3 &x) { ll x1 = get<0>(x); ll x2 = get<1>(x); ll x3 = get<2>(x); cout << "-- " << x1 << " -- " << x2 << " -- " << x3 << endl; } void _debug_print(const t4 &x) { ll x1 = get<0>(x); ll x2 = get<1>(x); ll x3 = get<2>(x); ll x4 = get<3>(x); cout << "-- " << x1 << " -- " << x2 << " -- " << x3 << " -- " << x4 << endl; } template <typename T> void _debug_print(T xarray[], ll n) { rep(i, n) _debug_print(xarray[i]); } template <typename T> void _debug_print(const V<T> &xlist) { for (auto x : xlist) { cout << "-- "; _debug_print(x); } } template <typename T> void _debug_print(const set<T> &xset) { for (auto x : xset) { cout << "-- "; _debug_print(x); } } template <typename TT, typename T> void _debug_print(const M<TT, T> &xlist) { for (auto x : xlist) { TT k = x.first; T v = x.second; cout << "====" << endl; cout << "K="; _debug_print(k); cout << "V="; _debug_print(v); } } void _debug_print_time(const char *prefix) { struct timeval tv; gettimeofday(&tv, NULL); struct tm *tm = localtime(&tv.tv_sec); printf("-- %s %02d:%02d:%02d.%06ld\n", prefix, tm->tm_hour, tm->tm_min, tm->tm_sec, tv.tv_usec); } /////////////////////////////////////////////////////////////////////////////// void _main(); int main() { cout << setprecision(12); _main(); return 0; } void _main() { ll n; llin(n); ll duration; llin(duration); S V<t2> ablist; llinl2(ablist, n); S V<t2> bmalist; for (auto ab : ablist) bmalist.pb(t2(get<1>(ab), -get<0>(ab))); sort_reverse(bmalist); ll ans = 0LL; BIT tree(n + 1, 0LL); for (auto bma : bmalist) { ll a = -get<1>(bma); ll b = get<0>(bma); if (duration < a) continue; ll sub = duration - a + 1 - tree.sum(duration - a + 1); if (sub <= 0LL) continue; debug_printf("a=%lld b=%lld sub=%lld len=%lld\n", a, b, sub, duration - a + 1); ll left = 1LL; ll right = duration - a + 1; ll now = (left + right) / 2LL; ll pos = 1e18; for (; left <= right; now = (left + right) / 2LL) { if (now - tree.sum(now) >= sub) { pos = min(pos, now); right = now - 1LL; } else { left = now + 1LL; } } debug_printf(" pos=%lld\n", pos); tree.add(pos, 1LL); ans += b; } cout << ans << endl; } ///////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////// #include <bits/stdc++.h> #include <sys/time.h> #include <time.h> #include <unistd.h> using namespace std; /////////////////////////////////////////////////////////////////////////////// #define DEBUG 0 #define pb push_back #define V vector #define M unordered_map #define S static #define rep(i, n) for (ll i = 0LL; i < n; ++i) #define srep(i, s, n) for (ll i = s; i < n; ++i) #define rrep(i, n) for (ll i = n - 1LL; i >= 0LL; --i) #define ALL(a) (a).begin(), (a).end() #define CIN(x) \ do { \ assert(!cin.eof()); \ cin >> x; \ assert(!cin.fail()); \ } while (0); #if DEBUG #define debug_print(...) _debug_print(__VA_ARGS__) #define debug_printf(...) printf(__VA_ARGS__) #define debug_print_time _debug_print_time #else // DEBUG #define debug_print(...) #define debug_printf(...) #define debug_print_time #endif // DEBUG typedef long long ll; typedef unsigned long long ull; typedef tuple<ll, ll> t2; typedef tuple<ll, ll, ll> t3; typedef tuple<ll, ll, ll, ll> t4; typedef tuple<ll, ll, ll, ll, ll> t5; template <typename T> using priority_queue_incr = priority_queue<T, V<T>, greater<T>>; /////////////////////////////////////////////////////////////////////////////// template <typename TT, typename T> T get_m(M<TT, T> &m, TT k, T default_value) { if (m.find(k) == m.end()) return m[k] = default_value; return m[k]; } template <typename TT, typename T> void incr_m(M<TT, T> &m, TT k) { if (m.find(k) == m.end()) m[k] = 0; m[k]++; } struct UnionFind { ull *parent, *count, *rank; UnionFind(ull n) { parent = new ull[n + 1]; count = new ull[n + 1]; rank = new ull[n + 1]; for (ull i = 0ULL; i < n + 1; ++i) { parent[i] = i; count[i] = 1; rank[i] = 0; } } ~UnionFind() { delete rank; delete count; delete parent; } ull root(ull i) { if (parent[i] == i) return i; parent[i] = root(parent[i]); return parent[i]; } void unite(ull i, ull j) { ull rooti = root(i); ull rootj = root(j); if (rooti == rootj) return; if (rank[rootj] < rank[rooti]) { parent[i] = parent[j] = parent[rootj] = rooti; count[rooti] += count[rootj]; } else { parent[i] = parent[j] = parent[rooti] = rootj; count[rootj] += count[rooti]; if (rank[rootj] == rank[rooti]) rank[rootj]++; } } bool same(ull i, ull j) { return root(i) == root(j); } }; struct UnionFindM { M<ull, ull> parent, count, rank; ull root(ull i) { ull parent_i = get_m(parent, i, i); if (parent_i == i) return i; return parent[i] = root(parent_i); } void unite(ull i, ull j) { ull rooti = root(i); ull rootj = root(j); if (rooti == rootj) return; if (get_m(rank, rootj, 0ULL) < get_m(rank, rooti, 0ULL)) { parent[i] = parent[j] = parent[rootj] = rooti; count[rooti] = get_m(count, rooti, 1ULL) + get_m(count, rootj, 1ULL); } else { parent[i] = parent[j] = parent[rooti] = rootj; count[rootj] = get_m(count, rootj, 1ULL) + get_m(count, rooti, 1ULL); if (get_m(rank, rootj, 0ULL) == get_m(rank, rooti, 0ULL)) rank[rootj]++; } } bool same(ull i, ull j) { return root(i) == root(j); } }; struct BIT { ll *tree; ll size; BIT(ll n, ll init) { tree = new ll[n + 1]; size = n; this->init(init); } void init(ll init) { memset(tree, 0, sizeof(ll) * (size + 1)); rep(i0, size) { ll idx = i0 + 1LL; while (idx <= size) { tree[idx] += init; idx += (idx & (-idx)); } } } // idx is 1 origin void add(ll idx, ll x) { assert(idx > 0LL); while (idx <= size) { tree[idx] += x; idx += (idx & (-idx)); } } // idx is 1 origin ll sum(ll idx) { assert(idx > 0LL); ll ret = 0LL; while (idx > 0LL) { ret += tree[idx]; idx -= (idx & (-idx)); } return ret; } }; struct MaxFlow { V<ll> links[1005]; ll capacities[1005][1005]; ll nodes; MaxFlow(ll nodes) { // i == 0 --> S // i == nodes+1 --> T rep(i, nodes + 2LL) links[i].clear(); memset(capacities, 0, sizeof(capacities)); this->nodes = nodes; } void add_path(ll a, ll b, ll capacity) { links[a].pb(b); links[b].pb(a); capacities[a][b] = capacity; capacities[b][a] = 0LL; } ll solve(void) { deque<V<ll>> q; ll ret = 0LL; for (;; q.clear()) { V<ll> start; start.pb(0); q.push_front(start); bool checked[nodes + 2]; memset(checked, 0, sizeof(checked)); V<ll> found; for (; !(q.empty());) { V<ll> path = q.front(); q.pop_front(); ll last = path[path.size() - 1]; if (checked[last]) continue; if (last == nodes + 1) { found = path; break; } checked[last] = true; for (auto next : (links[last])) { if (capacities[last][next] == 0) continue; V<ll> newpath(path); newpath.pb(next); q.push_front(newpath); } } if (found.size() == 0) { break; } else { ll flowcount = capacities[found[0]][found[1]]; rep(i, found.size() - 1) { ll src = found[i]; ll dst = found[i + 1]; flowcount = min(flowcount, capacities[src][dst]); } rep(i, found.size() - 1) { ll src = found[i]; ll dst = found[i + 1]; capacities[src][dst] -= flowcount; capacities[dst][src] += flowcount; } ret += flowcount; } } return ret; } }; template <typename T> struct SegmentTree { T *nodes; t2 *ranges; // [start, end) ll nodecount; ll itemcount; T unit; T (*op)(T, T); SegmentTree(ll itemcount, T unit, T op(T, T)) { ll orig_itemcount = itemcount; this->itemcount = 1LL; while (this->itemcount < orig_itemcount) this->itemcount *= 2LL; nodecount = this->itemcount * 2 - 1; nodes = new T[nodecount]; ranges = new t2[nodecount]; this->unit = unit; this->op = op; ll start = 0LL; ll end = this->itemcount; ll len = this->itemcount; rep(i, nodecount) { nodes[i] = unit; ranges[i] = t2(start, end); if (end >= this->itemcount) { len /= 2LL; start = 0LL; end = len; } else { start = end; end = start + len; } } } void update(ll k, T v) { ll idx = k + itemcount - 1LL; nodes[idx] = v; idx = (idx - 1LL) / 2LL; for (; idx >= 0; idx = (idx - 1LL) / 2LL) { nodes[idx] = op(nodes[idx * 2LL + 1LL], nodes[idx * 2LL + 2LL]); if (!idx) break; } } // query to [start, end) T query(ll start, ll end) const { return _query(start, end, 0LL); } T _query(ll start, ll end, ll idx) const { ll rstart = get<0>(ranges[idx]); ll rend = get<1>(ranges[idx]); if (start <= rstart && rend <= end) { return nodes[idx]; } if (rend <= start || end <= rstart) { return unit; } T left = _query(start, end, idx * 2LL + 1LL); T right = _query(start, end, idx * 2LL + 2LL); return op(left, right); } }; void llin(ll &a) { CIN(a); } void llinl1(auto &v, ll count) { for (ll i = 0LL; i < count; ++i) { ll a; CIN(a); v.push_back(a); } } void llinl2(auto &v, ll count) { for (ll i = 0LL; i < count; ++i) { ll a, b; CIN(a >> b); v.push_back(t2(a, b)); } } void llinl3(auto &v, ll count) { for (ll i = 0LL; i < count; ++i) { ll a, b, c; CIN(a >> b >> c); v.push_back(t3(a, b, c)); } } void llinl4(auto &v, ll count) { for (ll i = 0LL; i < count; ++i) { ll a, b, c, d; CIN(a >> b >> c >> d); v.push_back(t4(a, b, c, d)); } } void llina(auto &v, ll count) { llinl1(v, count); } template <typename T> T min(const V<T> v) { T ret = v[0]; for (auto i : v) ret = min(ret, i); return ret; } template <typename T> T max(const V<T> v) { T ret = v[0]; for (auto i : v) ret = max(ret, i); return ret; } ll absll(ll x) { if (x < 0) return -x; return x; } ll mod_mlt(ll x, ll y, ll mod) { ll ret = 0LL; x %= mod; while (y) { if (y & 1LL) { ret += x; ret %= mod; } y >>= 1; x <<= 1; x %= mod; } return ret; } // O(log(exp)) ll mod_pow(ll base, ll exp, ll mod) { ll ret = 1LL; for (; exp;) { if (exp & 1LL) { ret *= base; ret %= mod; } base = (base * base) % mod; exp >>= 1; } return ret; } // O(log(mod)) ll mod_inv(ll x, ll mod) { // available only when mod is prime return mod_pow(x, mod - 2LL, mod); } ll gcm(ll x, ll y) { while (y != 0) { ll z = x % y; x = y; y = z; } return x; } template <typename T> void sort(V<T> &v) { sort(v.begin(), v.end()); } template <typename T> void sort_reverse(V<T> &v) { sort(v.begin(), v.end(), greater<T>()); } void get_divisors(V<ll> &retlist, ll x) { for (ll i = 1LL; i < sqrt(x) + 3LL; ++i) { if (x % i == 0LL) { retlist.push_back(i); retlist.push_back(x / i); } } } // returns factors and 1 void get_factors(V<ll> &retlist, ll x) { retlist.pb(1LL); for (ll i = 2LL; i < (ll)(sqrt(x)) + 3LL; ++i) { while (x % i == 0LL) { retlist.pb(i); x /= i; } } retlist.pb(x); } bool is_prime(ll x) { V<ll> factors, factors2; get_factors(factors, x); for (auto factor : factors) { if (factor > 1) factors2.pb(factor); } return factors2.size() == 1 && x == factors2[0]; } template <typename T> void intersection(const set<T> &a, const set<T> &b, set<T> &result) { set_intersection(ALL(a), ALL(b), inserter(result, result.end())); } ull combination(ll x, ll y) { if (y > x / 2LL) y = x - y; ull ret = 1LL; for (ll i = 0LL; i < y; ++i) { ret *= x--; ret /= (i + 1LL); } return ret; } ull mod_combination(ll x, ll y, ll mod) { if (y > x / 2LL) y = x - y; ll ret = 1; for (ll i = 0LL; i < y; ++i) { ret = (ret * x--) % mod; ret = (ret * mod_inv(i + 1LL, mod)) % mod; } return ret; } void make_perms(ll perms[], ll perm_invs[], ll size, ll mod) { perms[0] = 1LL; srep(i, 1, size) { perms[i] = perms[i - 1] * i; perms[i] %= mod; } rep(i, size) { perm_invs[i] = mod_inv(perms[i], mod); } } void make_linklist(const V<t2> &srclist, V<ll> dstlist[]) { for (auto src : srclist) { ll a = get<0>(src); ll b = get<1>(src); dstlist[a].pb(b); dstlist[b].pb(a); } } void make_parental_relation(const V<ll> linklist[], ll root, ll n, ll parent[], V<ll> children[], ll level[]) { queue<ll> q; bool checked[n + 1]; memset(checked, 0, sizeof(checked)); q.push(root); checked[root] = true; parent[root] = root; level[root] = 0LL; for (; !(q.empty());) { ll now = q.front(); q.pop(); for (auto next : linklist[now]) { if (checked[next]) continue; q.push(next); checked[next] = true; parent[next] = now; children[now].pb(next); level[next] = level[now] + 1LL; } } } void make_subtree_sizes(const ll child_count[], const ll parents[], ll subtree_sizes[], ll n) { ll remain_count[n + 1LL]; memcpy(remain_count, child_count, sizeof(remain_count)); queue<ll> q; srep(node, 1LL, n + 1LL) { subtree_sizes[node] = 1LL; if (remain_count[node] > 0) continue; q.push(node); } while (!q.empty()) { ll node = q.front(); q.pop(); ll parent = parents[node]; if (node == parent) continue; remain_count[parent]--; subtree_sizes[parent] += subtree_sizes[node]; if (remain_count[parent] == 0LL) q.push(parent); } } void get_centroids(const V<ll> children[], const ll subtree_sizes[], ll root, ll n, V<ll> &centroids) { queue<ll> q; q.push(root); while (!q.empty()) { ll now = q.front(); q.pop(); bool is_centroid = true; for (auto child : children[now]) { q.push(child); if (subtree_sizes[child] > n / 2LL) is_centroid = false; } if (n - subtree_sizes[now] > n / 2LL) is_centroid = false; if (is_centroid) centroids.pb(now); } assert(centroids.size() == 1LL || centroids.size() == 2LL); } #define POW_ANCESTOR_MAXSIZE 20 // preprocess for get_common_ancestor() void make_pow_ancestor(const ll parent[], ll n, ll (*pow_ancestor)[POW_ANCESTOR_MAXSIZE]) { rep(i, n) pow_ancestor[i + 1][0] = parent[i + 1]; for (int pow2 = 1; pow(2, pow2) <= n; ++pow2) { rep(i0, n) { int i = i0 + 1; ll prev = pow_ancestor[i][pow2 - 1]; pow_ancestor[i][pow2] = pow_ancestor[prev][pow2 - 1]; } } } ll get_common_ancestor(ll n, ll x, ll y, const ll (*pow_ancestor)[POW_ANCESTOR_MAXSIZE], const ll level[]) { if (level[x] < level[y]) { ll diff = level[y] - level[x]; for (; diff;) { ll bit = diff & -diff; y = pow_ancestor[y][(int)log2(bit)]; diff -= bit; } } else { ll diff = level[x] - level[y]; for (; diff;) { ll bit = diff & -diff; x = pow_ancestor[x][(int)log2(bit)]; diff -= bit; } } if (x == y) return x; rrep(i, (int)log2(n) + 1) { if (pow_ancestor[x][i] != pow_ancestor[y][i]) { x = pow_ancestor[x][i]; y = pow_ancestor[y][i]; } } return pow_ancestor[x][0]; } void kmp_init(const string &pattern, ll kmp_next[]) { kmp_next[0] = -1LL; ll plen = pattern.size(); ll prefix_end = -1; rep(suffix_end, pattern.size()) { while (prefix_end >= 0 && pattern[suffix_end] != pattern[prefix_end]) { prefix_end = kmp_next[prefix_end]; } kmp_next[suffix_end + 1] = ++prefix_end; } kmp_next[0] = 0LL; } // founds ... list of text's idx of match position. start position idx. void kmp_search(const string &text, const string &pattern, const ll kmp_next[], V<ll> &founds) { ll text_size = text.size(); ll pattern_size = pattern.size(); ll text_start = 0LL; ll pattern_idx = 0LL; assert(pattern_size <= text_size); for (;;) { if (text_start + pattern_idx >= text_size) break; if (pattern_idx >= pattern_size) break; if (text[text_start + pattern_idx] == pattern[pattern_idx]) { pattern_idx++; if (pattern_idx == pattern_size) { founds.pb(text_start); pattern_idx = kmp_next[pattern_idx]; text_start += (pattern_size - pattern_idx); } } else { text_start += (pattern_idx - kmp_next[pattern_idx]); pattern_idx = kmp_next[pattern_idx]; if (pattern_idx == 0LL && text[text_start] != pattern[0]) { text_start++; } } } } void z_algorithm(ll matchcounts[], const string &str) { ll n = str.size(); ll base_idx = 0LL; memset(matchcounts, 0, sizeof(ll) * n); srep(idx, 1LL, n) { ll checked_len = base_idx + matchcounts[base_idx]; if (idx + matchcounts[idx - base_idx] < checked_len) { matchcounts[idx] = matchcounts[idx - base_idx]; continue; } ll start = max(0LL, base_idx + matchcounts[base_idx] - idx); matchcounts[idx] = start; srep(cmp, start, n - idx) { if (str[cmp] == str[idx + cmp]) matchcounts[idx]++; else break; } base_idx = idx; } matchcounts[0] = n; } void _debug_print(auto x) { cout << x << endl; } void _debug_print(const t2 &x) { ll x1 = get<0>(x); ll x2 = get<1>(x); cout << "-- " << x1 << " -- " << x2 << endl; } void _debug_print(const t3 &x) { ll x1 = get<0>(x); ll x2 = get<1>(x); ll x3 = get<2>(x); cout << "-- " << x1 << " -- " << x2 << " -- " << x3 << endl; } void _debug_print(const t4 &x) { ll x1 = get<0>(x); ll x2 = get<1>(x); ll x3 = get<2>(x); ll x4 = get<3>(x); cout << "-- " << x1 << " -- " << x2 << " -- " << x3 << " -- " << x4 << endl; } template <typename T> void _debug_print(T xarray[], ll n) { rep(i, n) _debug_print(xarray[i]); } template <typename T> void _debug_print(const V<T> &xlist) { for (auto x : xlist) { cout << "-- "; _debug_print(x); } } template <typename T> void _debug_print(const set<T> &xset) { for (auto x : xset) { cout << "-- "; _debug_print(x); } } template <typename TT, typename T> void _debug_print(const M<TT, T> &xlist) { for (auto x : xlist) { TT k = x.first; T v = x.second; cout << "====" << endl; cout << "K="; _debug_print(k); cout << "V="; _debug_print(v); } } void _debug_print_time(const char *prefix) { struct timeval tv; gettimeofday(&tv, NULL); struct tm *tm = localtime(&tv.tv_sec); printf("-- %s %02d:%02d:%02d.%06ld\n", prefix, tm->tm_hour, tm->tm_min, tm->tm_sec, tv.tv_usec); } /////////////////////////////////////////////////////////////////////////////// void _main(); int main() { cout << setprecision(12); _main(); return 0; } void _main() { ll n; llin(n); ll duration; llin(duration); S V<t2> ablist; llinl2(ablist, n); S V<t2> bmalist; for (auto ab : ablist) bmalist.pb(t2(get<1>(ab), -get<0>(ab))); sort_reverse(bmalist); ll ans = 0LL; S BIT tree(100005, 0LL); for (auto bma : bmalist) { ll a = -get<1>(bma); ll b = get<0>(bma); if (duration < a) continue; ll sub = duration - a + 1 - tree.sum(duration - a + 1); if (sub <= 0LL) continue; debug_printf("a=%lld b=%lld sub=%lld len=%lld\n", a, b, sub, duration - a + 1); ll left = 1LL; ll right = duration - a + 1; ll now = (left + right) / 2LL; ll pos = 1e18; for (; left <= right; now = (left + right) / 2LL) { if (now - tree.sum(now) >= sub) { pos = min(pos, now); right = now - 1LL; } else { left = now + 1LL; } } debug_printf(" pos=%lld\n", pos); tree.add(pos, 1LL); ans += b; } cout << ans << endl; } ///////////////////////////////////////////////////////////////////////////////
[ "identifier.replace.remove", "literal.replace.add", "call.arguments.change", "expression.operation.binary.change", "expression.operation.binary.remove" ]
750,091
750,090
u167931717
cpp
p02948
#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; }
[ "identifier.replace.remove", "literal.replace.add", "expression.operation.binary.change", "expression.operation.binary.remove" ]
750,092
750,093
u989611568
cpp
p02948
#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; }
[]
750,098
750,099
u860546679
cpp
p02948
#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; }
[ "identifier.replace.remove", "literal.replace.add", "expression.operation.binary.change", "expression.operation.binary.remove" ]
750,138
750,139
u518042385
cpp
p02948
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define mod 1000000007 typedef long long ll; using namespace std; int main(void) { int n, m; cin >> n >> m; vector<int> p[m + 1]; rep(i, n) { int a, b; cin >> a >> b; p[a].push_back(b); } // rep(i,n) cout << p[i].second << " " << p[i].first << endl; priority_queue<int> que; ll ans = 0; for (int i = 1; i <= m; i++) { for (int j = 0; j < p[i].size(); j++) { que.push(p[i][j]); } if (!que.empty()) { ans += que.top(); que.pop(); } } cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define mod 1000000007 typedef long long ll; using namespace std; int main(void) { int n, m; cin >> n >> m; vector<int> p[100005]; rep(i, n) { int a, b; cin >> a >> b; p[a].push_back(b); } // rep(i,n) cout << p[i].second << " " << p[i].first << endl; priority_queue<int> que; ll ans = 0; for (int i = 1; i <= m; i++) { for (int j = 0; j < p[i].size(); j++) { que.push(p[i][j]); } if (!que.empty()) { ans += que.top(); que.pop(); } } cout << ans << endl; }
[ "identifier.replace.remove", "literal.replace.add", "expression.operation.binary.change", "expression.operation.binary.remove" ]
750,191
750,192
u243407720
cpp
p02948
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) typedef long long ll; typedef pair<ll, ll> P; const int MOD = 1000000007; const int MAX = 5100000; ll gcd(ll a, ll b) { return (b == 0) ? a : gcd(b, a % b); } long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 ll COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } // 以下から const int MAX_N = 100000; struct Edge { int to; int id; }; vector<vector<Edge>> g; vector<int> ans; const int MN = 15; vector<int> searched(MN, 0); vector<int> color(MN, -1); int main() { int n, m; cin >> n >> m; vector<vector<int>> days(m); rep(i, n) { int a, b; cin >> a >> b; a--; days[a].push_back(b); } priority_queue<int> pq; int sum = 0; for (int i = 0; i < m; i++) { for (int j = 0; j < days[i].size(); j++) { pq.push(days[i][j]); } if (!pq.empty()) { int val = pq.top(); pq.pop(); sum += val; } } cout << sum << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) typedef long long ll; typedef pair<ll, ll> P; const int MOD = 1000000007; const int MAX = 5100000; ll gcd(ll a, ll b) { return (b == 0) ? a : gcd(b, a % b); } long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 ll COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } // 以下から const int MAX_N = 100000; struct Edge { int to; int id; }; vector<vector<Edge>> g; vector<int> ans; const int MN = 15; vector<int> searched(MN, 0); vector<int> color(MN, -1); int main() { int n, m; cin >> n >> m; vector<vector<int>> days(100000); rep(i, n) { int a, b; cin >> a >> b; a--; days[a].push_back(b); } priority_queue<int> pq; int sum = 0; for (int i = 0; i < m; i++) { for (int j = 0; j < days[i].size(); j++) { pq.push(days[i][j]); } if (!pq.empty()) { int val = pq.top(); pq.pop(); sum += val; } } cout << sum << endl; }
[]
750,217
750,218
u598710706
cpp
p02948
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) typedef long long ll; typedef pair<ll, ll> P; const int MOD = 1000000007; const int MAX = 5100000; ll gcd(ll a, ll b) { return (b == 0) ? a : gcd(b, a % b); } long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 ll COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } // 以下から const int MAX_N = 100000; struct Edge { int to; int id; }; vector<vector<Edge>> g; vector<int> ans; void dfs(int v, int c = -1, int p = -1) { int k = 1; rep(i, g[v].size()) { int u = g[v][i].to, ei = g[v][i].id; if (u == p) continue; if (k == c) ++k; ans[ei] = k; ++k; dfs(u, ans[ei], v); } } int main() { int n, m; cin >> n >> m; vector<vector<int>> v(m + 5); rep(i, n) { int a, b; cin >> a >> b; v[a].push_back(b); } int ans = 0; priority_queue<int> pq; for (int i = 1; i <= m; i++) { rep(j, v[i].size()) { pq.push(v[i][j]); } if (!pq.empty()) { ans += pq.top(); pq.pop(); } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) typedef long long ll; typedef pair<ll, ll> P; const int MOD = 1000000007; const int MAX = 5100000; ll gcd(ll a, ll b) { return (b == 0) ? a : gcd(b, a % b); } long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 ll COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } // 以下から const int MAX_N = 100000; struct Edge { int to; int id; }; vector<vector<Edge>> g; vector<int> ans; void dfs(int v, int c = -1, int p = -1) { int k = 1; rep(i, g[v].size()) { int u = g[v][i].to, ei = g[v][i].id; if (u == p) continue; if (k == c) ++k; ans[ei] = k; ++k; dfs(u, ans[ei], v); } } int main() { int n, m; cin >> n >> m; vector<vector<int>> v(100005); rep(i, n) { int a, b; cin >> a >> b; v[a].push_back(b); } int ans = 0; priority_queue<int> pq; for (int i = 1; i <= m; i++) { rep(j, v[i].size()) { pq.push(v[i][j]); } if (!pq.empty()) { ans += pq.top(); pq.pop(); } } cout << ans << endl; }
[ "identifier.replace.remove", "literal.replace.add", "call.arguments.change", "expression.operation.binary.change", "expression.operation.binary.remove" ]
750,219
750,220
u598710706
cpp
p02948
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef set<int> si; typedef pair<int, int> pii; #define rep(i, a, b) for (int i = (a); i < (b); ++i) #define per(i, a, b) for (int i = (b)-1; i >= (a); --i) #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() #define mp make_pair #define pb push_back #define F first #define S second const int INF = 1000000007; const int MOD = (int)1e9 + 7; const long double PI = (acos(-1)); const long double EPS = 0.0000000001; int dy[4] = {-2, -1}; int dx[4] = {-1, -2}; const int MAX_N = 100000; const int MAX_B = 10000; int n, m; set<pii> s; priority_queue<int> Q; int main(void) { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // freopen("in.txt", "r", stdin); cin >> n >> m; rep(i, 0, n) { int a, b; cin >> a >> b; s.insert(mp(a, b)); } int total = 0; auto start = s.begin(); per(i, 0, m) { int limit = m - i; auto end = s.upper_bound(mp(limit, MAX_B)); for (auto it = start; it != end; ++it) { int b = it->S; Q.push(b); } if (!Q.empty()) { total += Q.top(); Q.pop(); } start = end; } cout << total << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef set<int> si; typedef pair<int, int> pii; #define rep(i, a, b) for (int i = (a); i < (b); ++i) #define per(i, a, b) for (int i = (b)-1; i >= (a); --i) #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() #define mp make_pair #define pb push_back #define F first #define S second const int INF = 1000000007; const int MOD = (int)1e9 + 7; const long double PI = (acos(-1)); const long double EPS = 0.0000000001; int dy[4] = {-2, -1}; int dx[4] = {-1, -2}; const int MAX_N = 100000; const int MAX_B = 10000; int n, m; multiset<pii> s; priority_queue<int> Q; int main(void) { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // freopen("in.txt", "r", stdin); cin >> n >> m; rep(i, 0, n) { int a, b; cin >> a >> b; s.insert(mp(a, b)); } int total = 0; auto start = s.begin(); per(i, 0, m) { int limit = m - i; auto end = s.upper_bound(mp(limit, MAX_B)); for (auto it = start; it != end; ++it) { int b = it->S; Q.push(b); } if (!Q.empty()) { total += Q.top(); Q.pop(); } start = end; } cout << total << endl; return 0; }
[ "variable_declaration.type.change" ]
750,252
750,253
u035566695
cpp
p02948
#define _LIBCPP_DEBUG 0 #include <bits/stdc++.h> using namespace std; typedef long long int ll; ll MOD = 1e9 + 7; int main(void) { int N, M; cin >> N >> M; vector<vector<int>> vec(N); for (int i = 0; i < N; ++i) { int A, B; cin >> A >> B; vec[A - 1].push_back(B); } int ans = 0; priority_queue<int> pq; for (int i = 0; i < M; ++i) { for (int j : vec[i]) pq.push(j); if (!pq.empty()) ans += pq.top(); pq.pop(); } cout << ans << endl; return 0; }
#define _LIBCPP_DEBUG 0 #include <bits/stdc++.h> using namespace std; typedef long long int ll; ll MOD = 1e9 + 7; int main(void) { int N, M; cin >> N >> M; vector<vector<int>> vec(1e5); for (int i = 0; i < N; ++i) { int A, B; cin >> A >> B; vec[A - 1].push_back(B); } int ans = 0; priority_queue<int> pq; for (int i = 0; i < M; ++i) { for (int j : vec[i]) pq.push(j); if (!pq.empty()) { ans += pq.top(); pq.pop(); } } cout << ans << endl; return 0; }
[]
750,292
750,293
u635358463
cpp
p02948
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vector<pair<int, int>> a; for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; if (x <= m) { a.push_back(make_pair(x, y)); } } ll ans = 0; sort(a.begin(), a.end()); priority_queue<int> pq; ll x = 0; for (int i = 1; i <= m; i++) { while (x < n and a[x].first <= i) { pq.push(a[x].second); x++; } if (pq.size()) { ans += pq.top(); pq.pop(); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vector<pair<int, int>> a; for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; if (x <= m) { a.push_back(make_pair(x, y)); } } ll ans = 0; sort(a.begin(), a.end()); priority_queue<int> pq; ll x = 0; for (int i = 1; i <= m; i++) { while (x < a.size() and a[x].first <= i) { pq.push(a[x].second); x++; } if (pq.size()) { ans += pq.top(); pq.pop(); } } cout << ans << endl; return 0; }
[ "control_flow.loop.condition.change", "control_flow.loop.for.condition.change", "call.add" ]
750,302
750,303
u657667703
cpp
p02948
#include <bits/stdc++.h> using namespace std; typedef long long int ll; const ll inf = 1e18; const ll mod = 1e9 + 7; const ll maxn = 1e5; bool srts(const pair<ll, ll> &a, const pair<ll, ll> &b) { // if(a.second==b.second)return a.first>b.first; if (a.first == b.first) return a.second > b.second; return (a.first > b.first); } ll add(ll a, ll b) { return ((a % mod) + (b % mod)) % mod; } ll mul(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; } ll powm(ll x, ll n, ll M) { ll result = 1; while (n > 0) { if (n % 2 == 1) result = (result * x) % M; x = (x * x) % M; n = n / 2; } return result; } int main() { // #ifndef ONLINE_JUDGE // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); // #endif ios_base::sync_with_stdio(false); cin.tie(NULL); ll n, m; cin >> n >> m; vector<pair<ll, ll>> v; for (int i = 0; i < n; i++) { ll x, y; cin >> x >> y; v.push_back({x, y}); } sort(v.begin(), v.end()); ll ans = 0; // for(int i=0;i<n;i++)cout<<v[i].first<<" "<<v[i].second<<"\n"; priority_queue<ll> pq; ll x = 0; for (int i = 1; i <= m; i++) { while (v[x].first <= i) { pq.push(v[x].second); x++; } if (pq.size()) { ans += pq.top(); pq.pop(); } } cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; const ll inf = 1e18; const ll mod = 1e9 + 7; const ll maxn = 1e5; bool srts(const pair<ll, ll> &a, const pair<ll, ll> &b) { // if(a.second==b.second)return a.first>b.first; if (a.first == b.first) return a.second > b.second; return (a.first > b.first); } ll add(ll a, ll b) { return ((a % mod) + (b % mod)) % mod; } ll mul(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; } ll powm(ll x, ll n, ll M) { ll result = 1; while (n > 0) { if (n % 2 == 1) result = (result * x) % M; x = (x * x) % M; n = n / 2; } return result; } int main() { // #ifndef ONLINE_JUDGE // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); // #endif ios_base::sync_with_stdio(false); cin.tie(NULL); ll n, m; cin >> n >> m; vector<pair<ll, ll>> v; for (int i = 0; i < n; i++) { ll x, y; cin >> x >> y; v.push_back({x, y}); } sort(v.begin(), v.end()); ll ans = 0; // for(int i=0;i<n;i++)cout<<v[i].first<<" "<<v[i].second<<"\n"; priority_queue<ll> pq; ll x = 0; for (int i = 1; i <= m; i++) { while (x < n and v[x].first <= i) { pq.push(v[x].second); x++; } if (pq.size()) { ans += pq.top(); pq.pop(); } } cout << ans << "\n"; return 0; }
[ "control_flow.loop.condition.change", "control_flow.loop.for.condition.change" ]
750,304
750,305
u086395150
cpp
p02948
#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'; }
[ "identifier.replace.remove", "literal.replace.add", "call.arguments.change", "expression.operation.binary.change" ]
750,328
750,329
u408053343
cpp
p02948
#include <bits/stdc++.h> #define REP(i, N) for (int 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) { int 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'; }
[ "preprocessor.define.value.change", "identifier.replace.remove", "literal.replace.add", "call.arguments.change", "expression.operation.binary.change", "variable_declaration.type.change" ]
750,330
750,329
u408053343
cpp
p02948
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (long i = 0; i < n; i++) /* バイトがn件あり、m日後までに受け取れる報酬の総和を最大化する。 例:m=4、(4,3),(4,1),(2,2) ペア(a,b)について、 ペアをaの値でソートし、頭から順に実行していく。 ただし、残りi日のタイミングでiより大きいaを持つペアは消す。 forループ。i=0からスタートし、i=m-1の間で、ペアの配列を順番に走査。 配列のaがm-i<aであれば、配列の頭を削除し、続ける。 */ /* void solve(){ int n,m; cin >> n >> m; vector<pair<int,int>> v; rep(i,n){ int a,b; cin >> a >> b; v.emplace_back(make_pair(a,b)); } sort(v.rbegin(), v.rend()); cout << v[0].first << " " << v[0].second << " " << v[1].first << " " << v[1].second << " " << endl; int sum = 0; int pointer = 0; for(int i=0; i<m; i++){ //int a = v[pointer].first; //int b = v[pointer].second; while(m-i<v[pointer].first){ pointer++; } sum += v[pointer].second; pointer++; } cout << sum << endl; } */ /* これは正しくない。 */ /* 正しいやり方。 制約の厳しい方から順に見ていく。すなわち、 i=1~mについて、a<=iを満たすペアの中で最もbが大きいものを取り出し、bを加算。 */ void solve() { int n, m; cin >> n >> m; vector<pair<int, int>> v1; rep(i, n) { int a, b; cin >> a >> b; v1.emplace_back(make_pair(a, -b)); } //第一要素は昇順、第二要素は降順 sort(v1.begin(), v1.end()); vector<pair<int, int>> v; rep(i, n) { int a, b; a = v1[i].first; b = v1[i].second; v.emplace_back(make_pair(a, -b)); } int sum = 0; int pointer = 0; priority_queue<int> q; for (int i = 1; i <= m; i++) { // cout << "start!!!" << endl; // cout << i << " " << pointer << " " << v.at(pointer).first << " " << // v.at(pointer).second << endl; while (pointer < v.size() - 1 && v.at(pointer).first <= i) { q.push(v.at(pointer).second); pointer++; } if (!q.empty()) { sum += q.top(); q.pop(); } } cout << sum << endl; } int main() { solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (long i = 0; i < n; i++) /* バイトがn件あり、m日後までに受け取れる報酬の総和を最大化する。 例:m=4、(4,3),(4,1),(2,2) ペア(a,b)について、 ペアをaの値でソートし、頭から順に実行していく。 ただし、残りi日のタイミングでiより大きいaを持つペアは消す。 forループ。i=0からスタートし、i=m-1の間で、ペアの配列を順番に走査。 配列のaがm-i<aであれば、配列の頭を削除し、続ける。 */ /* void solve(){ int n,m; cin >> n >> m; vector<pair<int,int>> v; rep(i,n){ int a,b; cin >> a >> b; v.emplace_back(make_pair(a,b)); } sort(v.rbegin(), v.rend()); cout << v[0].first << " " << v[0].second << " " << v[1].first << " " << v[1].second << " " << endl; int sum = 0; int pointer = 0; for(int i=0; i<m; i++){ //int a = v[pointer].first; //int b = v[pointer].second; while(m-i<v[pointer].first){ pointer++; } sum += v[pointer].second; pointer++; } cout << sum << endl; } */ /* これは正しくない。 */ /* 正しいやり方。 制約の厳しい方から順に見ていく。すなわち、 i=1~mについて、a<=iを満たすペアの中で最もbが大きいものを取り出し、bを加算。 */ void solve() { int n, m; cin >> n >> m; vector<pair<int, int>> v1; rep(i, n) { int a, b; cin >> a >> b; v1.emplace_back(make_pair(a, -b)); } //第一要素は昇順、第二要素は降順 sort(v1.begin(), v1.end()); vector<pair<int, int>> v; rep(i, n) { int a, b; a = v1[i].first; b = v1[i].second; v.emplace_back(make_pair(a, -b)); } int sum = 0; int pointer = 0; priority_queue<int> q; for (int i = 1; i <= m; i++) { // cout << "start!!!" << endl; // cout << i << " " << pointer << " " << v.at(pointer).first << " " << // v.at(pointer).second << endl; while (pointer < v.size() && v.at(pointer).first <= i) { // cout << "v.size:" << v.size() << " pointer:" << pointer << endl; q.push(v.at(pointer).second); pointer++; } if (!q.empty()) { // cout << "q.top():"<< q.top() << endl; sum += q.top(); q.pop(); } } cout << sum << endl; } int main() { solve(); return 0; }
[ "control_flow.loop.for.condition.change", "expression.operation.binary.remove" ]
750,372
750,373
u272496669
cpp
p02948
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; void *wmem; template <class T> inline void walloc1d(T **arr, int x, void **mem = &wmem) { static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; (*mem) = (void *)(((char *)(*mem)) + skip[((unsigned long long)(*mem)) & 15]); (*arr) = (T *)(*mem); (*mem) = ((*arr) + x); } inline void rd(int &x) { int k, m = 0; x = 0; for (;;) { k = getchar_unlocked(); if (k == '-') { m = 1; break; } if ('0' <= k && k <= '9') { x = k - '0'; break; } } for (;;) { k = getchar_unlocked(); if (k < '0' || k > '9') { break; } x = x * 10 + k - '0'; } if (m) { x = -x; } } inline void wt_L(char a) { putchar_unlocked(a); } inline void wt_L(int x) { char f[10]; int m = 0, s = 0; if (x < 0) { m = 1; x = -x; } while (x) { f[s++] = x % 10; x /= 10; } if (!s) { f[s++] = 0; } if (m) { putchar_unlocked('-'); } while (s--) { putchar_unlocked(f[s] + '0'); } } template <class T> struct Heap_max { T *val; int size; void malloc(const int N) { val = (T *)std::malloc(N * sizeof(T)); size = 0; } void walloc(const int N, void **mem = &wmem) { walloc1d(&val, N, mem); size = 0; } void free() { std::free(val); } void init() { size = 0; } void up() { int m, n = size - 1; while (n) { m = (n - 1) / 2; if (val[m] >= val[n]) { break; } swap(val[m], val[n]); n = m; } } void down() { int m, n = 0; for (;;) { m = 2 * n + 1; if (m >= size) { break; } if (m + 1 < size && val[m] < val[m + 1]) { m++; } if (val[m] <= val[n]) { break; } swap(val[m], val[n]); n = m; } } T top() { return val[0]; } T pop() { T res = val[0]; size--; if (size > 0) { val[0] = val[size]; down(); } return res; } void push(const T x) { val[size++] = x; up(); } }; template <class S> void wAdjEdge_L(const int N, const int M, const int *A, const S *B, int **res_sz, S ***res_B, void **mem = &wmem) { int i, j, k; walloc1d(res_sz, N, mem); for (i = 0; i < (N); i++) { (*res_sz)[i] = 0; } for (i = 0; i < (M); i++) { (*res_sz)[A[i]]++; } walloc1d(res_B, N, mem); for (i = 0; i < (N); i++) { walloc1d(&((*res_B)[i]), (*res_sz)[i], mem); } for (i = 0; i < (N); i++) { (*res_sz)[i] = 0; } for (i = 0; i < (M); i++) { (*res_B)[A[i]][(*res_sz)[A[i]]++] = B[i]; } } char memarr[96000000]; int N; int M; int A[100000]; int B[100000]; int *sz; int **val; int main() { Heap_max<int> h; int i, j, res = 0; wmem = memarr; rd(N); rd(M); { int Lj4PdHRW; for (Lj4PdHRW = 0; Lj4PdHRW < (N); Lj4PdHRW++) { rd(A[Lj4PdHRW]); A[Lj4PdHRW] += (-1); rd(B[Lj4PdHRW]); } } wAdjEdge_L(M, N, A, B, &sz, &val); h.walloc(N); for (i = 0; i < (M); i++) { for (j = 0; j < (sz[i]); j++) { h.push(val[i][j]); } if (h.size) { res += h.pop(); } } wt_L(res); wt_L('\n'); return 0; } // cLay varsion 20190822-2 // --- original code --- // int N, M, A[1d5], B[1d5]; // int *sz, **val; // { // int i, j, res = 0; // Heap_max<int> h; // // rd(N,M,(A--,B)(N)); // wAdjEdge(M, N, A, B, &sz, &val); // // h.walloc(N); // // rep(i,M){ // rep(j,sz[i]) h.push(val[i][j]); // if(h.size) res += h.pop(); // } // // wt(res); // }
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; void *wmem; template <class T> inline void walloc1d(T **arr, int x, void **mem = &wmem) { static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; (*mem) = (void *)(((char *)(*mem)) + skip[((unsigned long long)(*mem)) & 15]); (*arr) = (T *)(*mem); (*mem) = ((*arr) + x); } inline void rd(int &x) { int k, m = 0; x = 0; for (;;) { k = getchar_unlocked(); if (k == '-') { m = 1; break; } if ('0' <= k && k <= '9') { x = k - '0'; break; } } for (;;) { k = getchar_unlocked(); if (k < '0' || k > '9') { break; } x = x * 10 + k - '0'; } if (m) { x = -x; } } inline void wt_L(char a) { putchar_unlocked(a); } inline void wt_L(int x) { char f[10]; int m = 0, s = 0; if (x < 0) { m = 1; x = -x; } while (x) { f[s++] = x % 10; x /= 10; } if (!s) { f[s++] = 0; } if (m) { putchar_unlocked('-'); } while (s--) { putchar_unlocked(f[s] + '0'); } } template <class T> struct Heap_max { T *val; int size; void malloc(const int N) { val = (T *)std::malloc(N * sizeof(T)); size = 0; } void walloc(const int N, void **mem = &wmem) { walloc1d(&val, N, mem); size = 0; } void free() { std::free(val); } void init() { size = 0; } void up() { int m, n = size - 1; while (n) { m = (n - 1) / 2; if (val[m] >= val[n]) { break; } swap(val[m], val[n]); n = m; } } void down() { int m, n = 0; for (;;) { m = 2 * n + 1; if (m >= size) { break; } if (m + 1 < size && val[m] < val[m + 1]) { m++; } if (val[m] <= val[n]) { break; } swap(val[m], val[n]); n = m; } } T top() { return val[0]; } T pop() { T res = val[0]; size--; if (size > 0) { val[0] = val[size]; down(); } return res; } void push(const T x) { val[size++] = x; up(); } }; template <class S> void wAdjEdge_L(const int N, const int M, const int *A, const S *B, int **res_sz, S ***res_B, void **mem = &wmem) { int i, j, k; walloc1d(res_sz, N, mem); for (i = 0; i < (N); i++) { (*res_sz)[i] = 0; } for (i = 0; i < (M); i++) { (*res_sz)[A[i]]++; } walloc1d(res_B, N, mem); for (i = 0; i < (N); i++) { walloc1d(&((*res_B)[i]), (*res_sz)[i], mem); } for (i = 0; i < (N); i++) { (*res_sz)[i] = 0; } for (i = 0; i < (M); i++) { (*res_B)[A[i]][(*res_sz)[A[i]]++] = B[i]; } } char memarr[96000000]; int N; int M; int A[100000]; int B[100000]; int *sz; int **val; int main() { Heap_max<int> h; int i, j, res = 0; wmem = memarr; rd(N); rd(M); { int Lj4PdHRW; for (Lj4PdHRW = 0; Lj4PdHRW < (N); Lj4PdHRW++) { rd(A[Lj4PdHRW]); A[Lj4PdHRW] += (-1); rd(B[Lj4PdHRW]); } } wAdjEdge_L(100000, N, A, B, &sz, &val); h.walloc(N); for (i = 0; i < (M); i++) { for (j = 0; j < (sz[i]); j++) { h.push(val[i][j]); } if (h.size) { res += h.pop(); } } wt_L(res); wt_L('\n'); return 0; } // cLay varsion 20190822-2 // --- original code --- // int N, M, A[1d5], B[1d5]; // int *sz, **val; // { // int i, j, res = 0; // Heap_max<int> h; // // rd(N,M,(A--,B)(N)); // wAdjEdge(1d5, N, A, B, &sz, &val); // // h.walloc(N); // // rep(i,M){ // rep(j,sz[i]) h.push(val[i][j]); // if(h.size) res += h.pop(); // } // // wt(res); // }
[ "identifier.replace.remove", "literal.replace.add", "call.arguments.change" ]
750,393
750,394
u066369439
cpp
p02948
// review #include <algorithm> #include <iostream> #include <queue> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> P; const int MAXN = 1e5 + 10; int n, m; int a[MAXN], b[MAXN]; void solve() { vector<P> v; for (int i = 0; i < n; i++) { if (m >= a[i]) { v.push_back(P(m - a[i], b[i])); } } sort(v.begin(), v.end()); ll sum = 0; int currentTime = m; int cur = v.size() - 1; priority_queue<int> que; while (currentTime >= 0) { while (cur > 0 && v[cur].first == currentTime) { que.push(v[cur--].second); } currentTime--; if (!que.empty()) { sum += que.top(); que.pop(); } } cout << sum << endl; } int main() { cin >> n >> m; for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; } solve(); }
// review #include <algorithm> #include <iostream> #include <queue> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> P; const int MAXN = 1e5 + 10; int n, m; int a[MAXN], b[MAXN]; void solve() { vector<P> v; for (int i = 0; i < n; i++) { if (m >= a[i]) { v.push_back(P(m - a[i], b[i])); } } sort(v.begin(), v.end()); ll sum = 0; int currentTime = m; int cur = v.size() - 1; priority_queue<int> que; while (currentTime >= 0) { while (cur >= 0 && v[cur].first == currentTime) { que.push(v[cur--].second); } currentTime--; if (!que.empty()) { sum += que.top(); que.pop(); } } cout << sum << endl; } int main() { cin >> n >> m; for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; } solve(); }
[ "expression.operator.compare.change", "control_flow.loop.condition.change" ]
750,397
750,398
u550178285
cpp
p02948
#include <bits/stdc++.h> using namespace std; #define all(x) (x).begin(), (x).end() #define mp make_pair #define pb push_back #define ff first #define ss second #define ll long long typedef pair<ll, ll> pll; typedef vector<ll> vi; #define out(x) return cout << x, 0; #define precision(x, d) cout << fixed << setprecision(d) << x #define coutif(a, b, c) cout << (a ? b : c) int main() { ll n, m, j, k = 0, x = 0, y = 0, i, ans = 0; cin >> n >> m; priority_queue<ll> q; vi v[100005]; for (i = 0; i < n; i++) { cin >> x >> y; v[x].pb(y); } for (i = 1; i <= m; i++) { for (j = 0; j < v[i].size(); i++) { q.push(v[i][j]); } if (!q.empty()) { ans += q.top(); q.pop(); } } cout << ans; }
#include <bits/stdc++.h> using namespace std; #define all(x) (x).begin(), (x).end() #define mp make_pair #define pb push_back #define ff first #define ss second #define ll long long typedef pair<ll, ll> pll; typedef vector<ll> vi; #define out(x) return cout << x, 0; #define precision(x, d) cout << fixed << setprecision(d) << x #define coutif(a, b, c) cout << (a ? b : c) int main() { ll n, m, j, k = 0, x = 0, y = 0, i, ans = 0; cin >> n >> m; priority_queue<ll> q; vi v[100005]; for (i = 0; i < n; i++) { cin >> x >> y; v[x].pb(y); } for (i = 1; i <= m; i++) { for (j = 0; j < v[i].size(); j++) { q.push(v[i][j]); } if (!q.empty()) { ans += q.top(); q.pop(); } } cout << ans; }
[ "identifier.change" ]
750,410
750,411
u415518175
cpp
p02948
#include <bits/stdc++.h> using namespace std; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cerr << x; } void __print(double x) { cerr << x; } void __print(long double x) { cerr << x; } void __print(char x) { cerr << '\'' << x << '\''; } void __print(const char *x) { cerr << '\"' << x << '\"'; } void __print(const string &x) { cerr << '\"' << x << '\"'; } void __print(bool x) { cerr << (x ? "true" : "false"); } template <typename T, typename V> void __print(const pair<T, V> &x) { cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}'; } template <typename T> void __print(const T &x) { int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}"; } void _print() { cerr << "]\n"; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); } #ifndef ONLINE_JUDGE #define debug(x...) \ cerr << "[" << #x << "] = ["; \ _print(x) #else #define debug(x...) #endif #define REP(i, n) for (int i = 0; i < (n); i++) #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 A first #define B second #define MOD 1000000007 typedef pair<int, int> ii; typedef vector<ii> vii; typedef long long ll; int mulmd(ll a, ll b) { ll ret = (a * b) % MOD; return (int)ret; } inline int power(ll x, ll y, int p) { ll res = 1; x = x % p; while (y > 0) { if (y & 1) res = mulmd(res, x); y = y >> 1; x = mulmd(x, x); } return (int)res; } int submd(ll a, ll b) { ll ret = a - b; if (ret < 0) { ret += MOD; } return (int)ret; } int addmd(ll a, ll b) { ll ret = (a + b) % MOD; return (int)ret; } int phi(int n) { int result = n; for (int i = 2; i * i <= n; i++) { if (n % i == 0) { while (n % i == 0) { n = n / i; } result -= result / i; } } if (n > 1) result -= result / n; return result; } const int N = 1e5 + 5; int arr[N]; /** Check out for boundary cases, (n = 1 or n = 0) check for integer overflow **/ map<int, int> mp; vii tr; vector<int> ans; bool cmp(ii a, ii b) { if (a.A < b.A) return true; if (a.A == b.A && a.B > b.B) return true; return false; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; ans.resize(m + 1); priority_queue<int> pq; FOR(i, 0, n - 1) { int a, b; cin >> a >> b; if (mp.find(a) == mp.end()) { mp[a] = b; } else { mp[a] = max(mp[a], b); } tr.push_back({a, b}); } sort(tr.begin(), tr.end(), cmp); // debug(tr); int r = 1; FOR(i, 0, tr.size() - 1) { ii cur = tr[i]; while (mp.find(r) == mp.end() && pq.size() > 0) { auto tp = pq.top(); ans[r] = tp; pq.pop(); r++; } if (r != cur.A) r = cur.A; // debug(pq.size()); if (mp[cur.A] == cur.B) { if (pq.size() > 0 && cur.B < pq.top()) { pq.push(cur.B); ans[r] = pq.top(); r++; pq.pop(); } else { ans[r] = cur.B; r++; } } else { // debug(cur.B); pq.push(cur.B); } } int ar = 0; // debug(ans); FOR(i, 1, m) { // debug(ans[i]); ar += ans[i]; } cout << ar; }
#include <bits/stdc++.h> using namespace std; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cerr << x; } void __print(double x) { cerr << x; } void __print(long double x) { cerr << x; } void __print(char x) { cerr << '\'' << x << '\''; } void __print(const char *x) { cerr << '\"' << x << '\"'; } void __print(const string &x) { cerr << '\"' << x << '\"'; } void __print(bool x) { cerr << (x ? "true" : "false"); } template <typename T, typename V> void __print(const pair<T, V> &x) { cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}'; } template <typename T> void __print(const T &x) { int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}"; } void _print() { cerr << "]\n"; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); } #ifndef ONLINE_JUDGE #define debug(x...) \ cerr << "[" << #x << "] = ["; \ _print(x) #else #define debug(x...) #endif #define REP(i, n) for (int i = 0; i < (n); i++) #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 A first #define B second #define MOD 1000000007 typedef pair<int, int> ii; typedef vector<ii> vii; typedef long long ll; int mulmd(ll a, ll b) { ll ret = (a * b) % MOD; return (int)ret; } inline int power(ll x, ll y, int p) { ll res = 1; x = x % p; while (y > 0) { if (y & 1) res = mulmd(res, x); y = y >> 1; x = mulmd(x, x); } return (int)res; } int submd(ll a, ll b) { ll ret = a - b; if (ret < 0) { ret += MOD; } return (int)ret; } int addmd(ll a, ll b) { ll ret = (a + b) % MOD; return (int)ret; } int phi(int n) { int result = n; for (int i = 2; i * i <= n; i++) { if (n % i == 0) { while (n % i == 0) { n = n / i; } result -= result / i; } } if (n > 1) result -= result / n; return result; } const int N = 1e5 + 5; vector<int> arr[N]; /** Check out for boundary cases, (n = 1 or n = 0) check for integer overflow **/ int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; arr[a].push_back(b); } priority_queue<int> q; int ans = 0; FOR(i, 1, m) { // debug(arr[i]); for (int j = 0; j < arr[i].size(); j++) q.push(arr[i][j]); if (q.size() > 0) { ans += q.top(); q.pop(); } } cout << ans; }
[]
750,420
750,421
u773638671
cpp
p02948
#include <bits/stdc++.h> using namespace std; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cerr << x; } void __print(double x) { cerr << x; } void __print(long double x) { cerr << x; } void __print(char x) { cerr << '\'' << x << '\''; } void __print(const char *x) { cerr << '\"' << x << '\"'; } void __print(const string &x) { cerr << '\"' << x << '\"'; } void __print(bool x) { cerr << (x ? "true" : "false"); } template <typename T, typename V> void __print(const pair<T, V> &x) { cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}'; } template <typename T> void __print(const T &x) { int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}"; } void _print() { cerr << "]\n"; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); } #ifndef ONLINE_JUDGE #define debug(x...) \ cerr << "[" << #x << "] = ["; \ _print(x) #else #define debug(x...) #endif #define REP(i, n) for (int i = 0; i < (n); i++) #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 A first #define B second #define MOD 1000000007 typedef pair<int, int> ii; typedef vector<ii> vii; typedef long long ll; int mulmd(ll a, ll b) { ll ret = (a * b) % MOD; return (int)ret; } inline int power(ll x, ll y, int p) { ll res = 1; x = x % p; while (y > 0) { if (y & 1) res = mulmd(res, x); y = y >> 1; x = mulmd(x, x); } return (int)res; } int submd(ll a, ll b) { ll ret = a - b; if (ret < 0) { ret += MOD; } return (int)ret; } int addmd(ll a, ll b) { ll ret = (a + b) % MOD; return (int)ret; } int phi(int n) { int result = n; for (int i = 2; i * i <= n; i++) { if (n % i == 0) { while (n % i == 0) { n = n / i; } result -= result / i; } } if (n > 1) result -= result / n; return result; } const int N = 1e5 + 5; int arr[N]; /** Check out for boundary cases, (n = 1 or n = 0) check for integer overflow **/ int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; priority_queue<ii> pq; FOR(i, 0, n - 1) { int a, b; cin >> a >> b; pq.push({b, a}); } int r = 0; int ans = 0; while (!pq.empty()) { auto x = pq.top(); if (r + x.B <= m) { ans += x.A; r++; } pq.pop(); } cout << ans; }
#include <bits/stdc++.h> using namespace std; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cerr << x; } void __print(double x) { cerr << x; } void __print(long double x) { cerr << x; } void __print(char x) { cerr << '\'' << x << '\''; } void __print(const char *x) { cerr << '\"' << x << '\"'; } void __print(const string &x) { cerr << '\"' << x << '\"'; } void __print(bool x) { cerr << (x ? "true" : "false"); } template <typename T, typename V> void __print(const pair<T, V> &x) { cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}'; } template <typename T> void __print(const T &x) { int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}"; } void _print() { cerr << "]\n"; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); } #ifndef ONLINE_JUDGE #define debug(x...) \ cerr << "[" << #x << "] = ["; \ _print(x) #else #define debug(x...) #endif #define REP(i, n) for (int i = 0; i < (n); i++) #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 A first #define B second #define MOD 1000000007 typedef pair<int, int> ii; typedef vector<ii> vii; typedef long long ll; int mulmd(ll a, ll b) { ll ret = (a * b) % MOD; return (int)ret; } inline int power(ll x, ll y, int p) { ll res = 1; x = x % p; while (y > 0) { if (y & 1) res = mulmd(res, x); y = y >> 1; x = mulmd(x, x); } return (int)res; } int submd(ll a, ll b) { ll ret = a - b; if (ret < 0) { ret += MOD; } return (int)ret; } int addmd(ll a, ll b) { ll ret = (a + b) % MOD; return (int)ret; } int phi(int n) { int result = n; for (int i = 2; i * i <= n; i++) { if (n % i == 0) { while (n % i == 0) { n = n / i; } result -= result / i; } } if (n > 1) result -= result / n; return result; } const int N = 1e5 + 5; vector<int> arr[N]; /** Check out for boundary cases, (n = 1 or n = 0) check for integer overflow **/ int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; arr[a].push_back(b); } priority_queue<int> q; int ans = 0; FOR(i, 1, m) { // debug(arr[i]); for (int j = 0; j < arr[i].size(); j++) q.push(arr[i][j]); if (q.size() > 0) { ans += q.top(); q.pop(); } } cout << ans; }
[]
750,422
750,421
u773638671
cpp
p02948
#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; }
[]
750,423
750,424
u724515098
cpp
p02948
#include <bits/stdc++.h> #include <stdlib.h> using namespace std; typedef long long ll; const ll mod = 1000000007; const ll BIG = 1e15; int main() { int N, M; cin >> N >> M; vector<pair<int, int>> d; for (int i = 0; i < N; i++) { int A, B; cin >> A >> B; d.push_back(make_pair(A, B)); } sort(d.begin(), d.end()); ll ans = 0; multiset<int> S; int j = 0; // for(int i=0;i<N;i++) cout<<d.at(i).first<<' '<<d.at(i).second<<endl; for (int i = 0; i <= M; i++) { if (j < N) { while (d.at(j).first <= i) { S.insert(d.at(j).second); j++; if (j >= N) break; } } if (S.size() != 0) { auto itr = S.end(); // itr--; // cout<<*itr<<endl; ans += *itr; S.erase(*itr); // cout<<ans<<endl; } } cout << ans << endl; }
#include <bits/stdc++.h> #include <stdlib.h> using namespace std; typedef long long ll; const ll mod = 1000000007; const ll BIG = 1e15; int main() { int N, M; cin >> N >> M; vector<pair<int, int>> d; for (int i = 0; i < N; i++) { int A, B; cin >> A >> B; d.push_back(make_pair(A, B)); } sort(d.begin(), d.end()); ll ans = 0; multiset<int> S; int j = 0; // for(int i=0;i<N;i++) cout<<d.at(i).first<<' '<<d.at(i).second<<endl; for (int i = 0; i <= M; i++) { if (j < N) { while (d.at(j).first <= i) { S.insert(d.at(j).second); j++; if (j >= N) break; } } if (S.size() != 0) { auto itr = S.end(); itr--; // cout<<i<<':'<<S.size()<<endl; // cout<<*itr<<endl; ans += *itr; S.erase(itr); // cout<<ans<<endl; } } cout << ans << endl; }
[ "expression.unary.arithmetic.add", "call.arguments.change" ]
750,520
750,521
u951952491
cpp
p02948
/* Dsingh_24 */ #include <bits/stdc++.h> #define ll long long #define pb push_back #define endl '\n' #define pii pair<ll int, ll int> #define vi vector<ll int> #define all(a) (a).begin(), (a).end() #define F first #define S second #define sz(x) (ll int)x.size() #define hell 1000000007 #define rep(i, a, b) for (ll int i = a; i < b; i++) #define lbnd lower_bound #define ubnd upper_bound #define bs binary_search #define mp make_pair #define ios \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); using namespace std; #define N 100005 ll par[100005]; ll find_set(ll v) { if (v == par[v]) return v; return par[v] = find_set(par[v]); } void make_set(ll v) { par[v] = v; } void union_sets(ll a, ll b) { a = find_set(a); b = find_set(b); if (a != b) { if (a > b) swap(a, b); par[b] = a; } } int main() { ios ll n, m, i, j, x, y, ans = 0, cnt = 0; cin >> n >> m; vector<pii> s; s.pb({hell, hell}); for (i = 1; i <= n; i++) { cin >> x >> y; s.push_back({y, x}); } sort(all(s)); reverse(all(s)); for (i = 0; i <= n; i++) { make_set(i); } for (i = 1; i <= n; i++) { ll nxt = m - s[i].S + 1; if (nxt < 0) continue; ll ff = find_set(nxt); if (ff > 0) { ans += s[i].F; union_sets(ff, ff - 1); union_sets(nxt, ff - 1); cnt++; if (cnt >= m) { break; } } } cout << ans; return 0; }
/* Dsingh_24 */ #include <bits/stdc++.h> #define ll long long #define pb push_back #define endl '\n' #define pii pair<ll int, ll int> #define vi vector<ll int> #define all(a) (a).begin(), (a).end() #define F first #define S second #define sz(x) (ll int)x.size() #define hell 1000000007 #define rep(i, a, b) for (ll int i = a; i < b; i++) #define lbnd lower_bound #define ubnd upper_bound #define bs binary_search #define mp make_pair #define ios \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); using namespace std; #define N 100005 ll par[100005]; ll find_set(ll v) { if (v == par[v]) return v; return par[v] = find_set(par[v]); } void make_set(ll v) { par[v] = v; } void union_sets(ll a, ll b) { a = find_set(a); b = find_set(b); if (a != b) { if (a > b) swap(a, b); par[b] = a; } } int main() { ios ll n, m, i, j, x, y, ans = 0, cnt = 0; cin >> n >> m; vector<pii> s; s.pb({hell, hell}); for (i = 1; i <= n; i++) { cin >> x >> y; s.push_back({y, x}); } sort(all(s)); reverse(all(s)); for (i = 0; i <= m; i++) { make_set(i); } for (i = 1; i <= n; i++) { ll nxt = m - s[i].S + 1; if (nxt <= 0) continue; ll ff = find_set(nxt); if (ff > 0) { ans += s[i].F; union_sets(ff, ff - 1); union_sets(nxt, ff - 1); cnt++; if (cnt >= m) { break; } } } cout << ans; return 0; }
[ "identifier.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change", "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
750,531
750,532
u535413433
cpp
p02948
#include <bits/stdc++.h> using namespace std; int main() { int N, M, ans = 0; cin >> N >> M; vector<pair<int, int>> AB; for (int i = 0; i < N; i++) { int A, B; cin >> A >> B; AB.push_back(make_pair(A, B)); } sort(AB.begin(), AB.end()); reverse(AB.begin(), AB.end()); priority_queue<int, vector<int>, greater<int>> que; for (int i = 0; i < N; i++) { int A = AB[i].first, B = AB[i].second; if (M - A + 1 > que.size()) { ans += B; que.push(B); } else { if (M - A + 1 < 0 || que.empty()) continue; if (B > que.top()) { ans -= que.top(); que.pop(); ans += B; que.push(B); } } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N, M, ans = 0; cin >> N >> M; vector<pair<int, int>> AB; for (int i = 0; i < N; i++) { int A, B; cin >> A >> B; AB.push_back(make_pair(A, B)); } sort(AB.begin(), AB.end()); reverse(AB.begin(), AB.end()); priority_queue<int, vector<int>, greater<int>> que; for (int i = 0; i < N; i++) { int A = AB[i].first, B = AB[i].second; if (M - A + 1 > ((int)que.size())) { ans += B; que.push(B); } else { if (M - A + 1 < 0 || que.empty()) continue; if (B > que.top()) { ans -= que.top(); que.pop(); ans += B; que.push(B); } } } cout << ans << endl; return 0; }
[ "control_flow.branch.if.condition.change", "control_flow.loop.for.condition.change" ]
750,535
750,536
u573082373
cpp
p02948
#include <bits/stdc++.h> using namespace std; int main() { long long n, m; cin >> n >> m; set<pair<long long, long long>> s; //{date,get} set<pair<long long, long long>> u; //{get,date} for (long long i = 0; i < n; i++) { long long a, b; cin >> a >> b; s.insert({a, b}); } for (auto p = s.rbegin(); p != s.rend(); p++) { // cout<<p->first<<" "<<p->second<<endl; if ((u.size() + p->first) <= m) { u.insert({p->second, p->first}); } else if (u.size() && (u.begin()->first) < (p->second) && (u.size() - 1 + p->first) <= m) { u.erase(u.begin()); u.insert({p->second, p->first}); } } long long a = 0; for (auto p : u) a += p.first; cout << a << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, m; cin >> n >> m; multiset<pair<long long, long long>> s; //{date,get} multiset<pair<long long, long long>> u; //{get,date} for (long long i = 0; i < n; i++) { long long a, b; cin >> a >> b; s.insert({a, b}); } for (auto p = s.rbegin(); p != s.rend(); p++) { // cout<<p->first<<" "<<p->second<<endl; if ((u.size() + p->first) <= m) { u.insert({p->second, p->first}); } else if (u.size() && (u.begin()->first) < (p->second) && (u.size() - 1 + p->first) <= m) { u.erase(u.begin()); u.insert({p->second, p->first}); } } long long a = 0; for (auto p : u) a += p.first; cout << a << endl; }
[ "variable_declaration.type.change" ]
750,543
750,544
u729337236
cpp
p02948
#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; }
[ "identifier.replace.remove", "literal.replace.add", "call.arguments.change", "expression.operation.binary.change", "expression.operation.binary.remove" ]
750,545
750,546
u775224245
cpp
p02948
#include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPr(i, n) for (int i = (n)-1; i >= 0; --i) #define FORq(i, m, n) for (int i = (m); i <= (n); ++i) #define FORqr(i, m, n) for (int i = (n); i >= (m); --i) #define PB push_back #define MP make_pair #define DEBUG printf("%s\n", "debug") #define fst first #define snd second #define SIN(x, S) (S.count(x) != 0) #define M0(x) memset(x, 0, sizeof(x)) #define FILL(x, y) memset(x, y, sizeof(x)) #define MM(x) memset(x, -1, sizeof(x)) #define ALL(x) (x).begin(), (x).end() #define SCD(n) scanf("%d", &n) #define SCD2(m, n) scanf("%d%d", &m, &n) #define SCD3(m, n, k) scanf("%d%d%d", &m, &n, &k) #define SCLLD(n) scanf("%lld", &n) #define SCLLD2(m, n) scanf("%lld%lld", &m, &n) #define SCLLD3(m, n, k) scanf("%lld%lld%lld", &m, &n, &k) using namespace std; typedef pair<int, int> PII; typedef pair<long long, long long> PLL; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<long long> VL; typedef long long ll; typedef long long integer; /////////////////////////////////////////////// const ll MOD = 1e9 + 7; ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } /////////////////////////////////////////////// /*(._.)*/ int main() { ll ans = 0; int N, M; cin >> N >> M; vector<vector<ll>> AB(M + 2); REP(i, N) { int A, B; cin >> A >> B; AB[A].PB(B); } priority_queue<ll> Q; FORq(i, 1, M) { REP(j, AB[i].size()) { Q.push((AB[i])[j]); } if (Q.empty() == true) continue; ll nvalue = Q.top(); Q.pop(); ans += nvalue; } cout << ans << "\n"; }
#include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPr(i, n) for (int i = (n)-1; i >= 0; --i) #define FORq(i, m, n) for (int i = (m); i <= (n); ++i) #define FORqr(i, m, n) for (int i = (n); i >= (m); --i) #define PB push_back #define MP make_pair #define DEBUG printf("%s\n", "debug") #define fst first #define snd second #define SIN(x, S) (S.count(x) != 0) #define M0(x) memset(x, 0, sizeof(x)) #define FILL(x, y) memset(x, y, sizeof(x)) #define MM(x) memset(x, -1, sizeof(x)) #define ALL(x) (x).begin(), (x).end() #define SCD(n) scanf("%d", &n) #define SCD2(m, n) scanf("%d%d", &m, &n) #define SCD3(m, n, k) scanf("%d%d%d", &m, &n, &k) #define SCLLD(n) scanf("%lld", &n) #define SCLLD2(m, n) scanf("%lld%lld", &m, &n) #define SCLLD3(m, n, k) scanf("%lld%lld%lld", &m, &n, &k) using namespace std; typedef pair<int, int> PII; typedef pair<long long, long long> PLL; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<long long> VL; typedef long long ll; typedef long long integer; /////////////////////////////////////////////// const ll MOD = 1e9 + 7; ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } /////////////////////////////////////////////// /*(._.)*/ int main() { ll ans = 0; int N, M; cin >> N >> M; vector<vector<ll>> AB(100002); REP(i, N) { ll A, B; cin >> A >> B; AB[A].PB(B); } priority_queue<ll> Q; FORq(i, 1, M) { REP(j, AB[i].size()) { Q.push((AB[i])[j]); } if (Q.empty() == true) continue; ll nvalue = Q.top(); Q.pop(); ans += nvalue; } cout << ans << "\n"; }
[ "identifier.replace.remove", "literal.replace.add", "call.arguments.change", "expression.operation.binary.change", "expression.operation.binary.remove", "variable_declaration.type.change" ]
750,565
750,566
u236433947
cpp
p02948
// This is getting accepted! #include <bits/stdc++.h> #define ll long long #define oo 1000000009 #define FOR(i, a, b) for (int i = (a); i <= (b); ++i) #define INARR(a, n) \ for (int i = 1; i <= (n); ++i) \ cin >> a[i]; #define ITE(x) for (auto it = (x).begin(); it != (x).end(); ++it) #define isset(x, i) (((x) >> (i)) & 1) #define setbit(x, i) ((x) ^ (1ll << (i))) #define clearbit(x, i) ((x) & (~(1ll << (i)))) #define twoexp(i) (1ll << (i)) #define MAX(a, b) ((a) > (b) ? (a) : (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define FI first #define SE second #define son1 (id * 2) #define son2 (id * 2 + 1) using namespace std; const int MOD = 1000000007; const double EPS = 1e-8; const double PI = 2 * acos(0); const int MAXN = 1e6 + 6; int n, m; int a[MAXN], b[MAXN]; set<int> rem; set<pair<int, int>> bag; void input() { int u, v, w, x, y, qtype; cin >> n >> m; FOR(i, 1, n) cin >> a[i] >> b[i]; } void preprocess() { FOR(i, 1, m) rem.insert(i); FOR(i, 1, n) bag.insert({-b[i], a[i]}); ll res = 0; while (bag.size()) { int val = -bag.begin()->first; int days = bag.begin()->second; bag.erase(bag.begin()); auto it = rem.lower_bound(days); if (it != rem.end()) { res += val; rem.erase(it); } } cout << res << endl; } void process(int itest) { int u, v, w, x, y, qtype; } void oneTest() { input(); preprocess(); process(0); } void multiTest() { int t; cin >> t; for (int it = 1; it <= t; ++it) { input(); preprocess(); process(it); } } int main() { #ifndef ONLINE_JUDGE // freopen("../out.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); oneTest(); // multiTest(); return 0; }
// This is getting accepted! #include <bits/stdc++.h> #define ll long long #define oo 1000000009 #define FOR(i, a, b) for (int i = (a); i <= (b); ++i) #define INARR(a, n) \ for (int i = 1; i <= (n); ++i) \ cin >> a[i]; #define ITE(x) for (auto it = (x).begin(); it != (x).end(); ++it) #define isset(x, i) (((x) >> (i)) & 1) #define setbit(x, i) ((x) ^ (1ll << (i))) #define clearbit(x, i) ((x) & (~(1ll << (i)))) #define twoexp(i) (1ll << (i)) #define MAX(a, b) ((a) > (b) ? (a) : (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define FI first #define SE second #define son1 (id * 2) #define son2 (id * 2 + 1) using namespace std; const int MOD = 1000000007; const double EPS = 1e-8; const double PI = 2 * acos(0); const int MAXN = 1e6 + 6; int n, m; int a[MAXN], b[MAXN]; set<int> rem; multiset<pair<int, int>> bag; void input() { int u, v, w, x, y, qtype; cin >> n >> m; FOR(i, 1, n) cin >> a[i] >> b[i]; } void preprocess() { FOR(i, 1, m) rem.insert(i); FOR(i, 1, n) bag.insert({-b[i], a[i]}); ll res = 0; while (bag.size()) { int val = -bag.begin()->first; int days = bag.begin()->second; bag.erase(bag.begin()); auto it = rem.lower_bound(days); if (it != rem.end()) { res += val; rem.erase(it); } } cout << res << endl; } void process(int itest) { int u, v, w, x, y, qtype; } void oneTest() { input(); preprocess(); process(0); } void multiTest() { int t; cin >> t; for (int it = 1; it <= t; ++it) { input(); preprocess(); process(it); } } int main() { #ifndef ONLINE_JUDGE // freopen("../out.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); oneTest(); // multiTest(); return 0; }
[ "variable_declaration.type.change" ]
750,569
750,570
u050328876
cpp
p02948
#include <bits/stdc++.h> #include <iomanip> #include <numeric> using namespace std; using ll = long long; constexpr int mo = 1e9 + 7; constexpr int mod = mo; constexpr ll inf = 1ll << 50; constexpr int infi = 1 << 30; int main() { int n, m; cin >> n >> m; vector<vector<int>> c(m + 1); for (int i = 0; i < n; ++i) { int a, b; cin >> a >> b; c[a].push_back(b); } priority_queue<ll> q; ll ret = 0ll; for (int i = 1; i <= m; ++i) { for (auto &cur : c[i]) { q.push(cur); } if (q.size()) { ret += q.top(); q.pop(); } } cout << ret << endl; return 0; }
#include <bits/stdc++.h> #include <iomanip> #include <numeric> using namespace std; using ll = long long; constexpr int mo = 1e9 + 7; constexpr int mod = mo; constexpr ll inf = 1ll << 50; constexpr int infi = 1 << 30; int main() { int n, m; cin >> n >> m; vector<vector<int>> c(100050); for (int i = 0; i < n; ++i) { int a, b; cin >> a >> b; c[a].push_back(b); } priority_queue<ll> q; ll ret = 0ll; for (int i = 1; i <= m; ++i) { for (auto cur : c[i]) { q.push(cur); } if (q.size()) { ret += q.top(); q.pop(); } } cout << ret << endl; return 0; }
[ "identifier.replace.remove", "literal.replace.add", "call.arguments.change", "expression.operation.binary.change", "expression.operation.binary.remove" ]
750,580
750,581
u699193595
cpp
p02948
// // main.cpp // temp // // Created by tolemy on 2019/08/04. // Copyright © 2019 tolemy. All rights reserved. // #include <algorithm> #include <iostream> #include <queue> #include <vector> using namespace std; int main(int argc, const char *argv[]) { const int MAX_WORKS_COUNT = 100000 + 1; //方針 // 0〜M-1日間で考える(M日目は報酬を受け取ることはできるが、仕事をしても翌日以降がないため意味がない) // M-1日目から初めて、残り日数のうちに報酬がもらえる仕事のうち、報酬が最大の仕事を順番にこなしていく //インプットの処理 // n:仕事の数 // m:日数 int n, m; cin >> n >> m; //報酬受け取り期間と報酬の2次元配列を作る。 // vectorの配列とする。 typedef vector<int> values; values works[MAX_WORKS_COUNT]; for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; works[a].push_back(b); } //報酬受け取り期間の昇順にソート for (int i = 0; i < MAX_WORKS_COUNT; i++) { sort(works[i].begin(), works[i].end()); } //合計報酬の最大値を計算 //一度行った仕事は除外するため、priority_queueで管理 long value = 0; priority_queue<int> pq; //日付をM日目からループ for (int i = m; i >= 1; i--) { //最終日からi日目に報酬受け取り期間iの仕事ができるようになる。 int daysLeft = m - i; for (int value : works[daysLeft]) { pq.push(value); } if (pq.empty()) continue; //仕事の取り出し value += pq.top(); pq.pop(); } cout << value; return 0; }
// // main.cpp // temp // // Created by tolemy on 2019/08/04. // Copyright © 2019 tolemy. All rights reserved. // #include <algorithm> #include <iostream> #include <queue> #include <vector> using namespace std; int main(int argc, const char *argv[]) { const int MAX_WORKS_COUNT = 100000 + 1; //方針 // 0〜M-1日間で考える(M日目は報酬を受け取ることはできるが、仕事をしても翌日以降がないため意味がない) // M-1日目から初めて、残り日数のうちに報酬がもらえる仕事のうち、報酬が最大の仕事を順番にこなしていく //インプットの処理 // n:仕事の数 // m:日数 int n, m; cin >> n >> m; //報酬受け取り期間と報酬の2次元配列を作る。 // vectorの配列とする。 typedef vector<int> values; values works[MAX_WORKS_COUNT]; for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; works[a].push_back(b); } //報酬受け取り期間の昇順にソート for (int i = 0; i < MAX_WORKS_COUNT; i++) { sort(works[i].begin(), works[i].end()); } //合計報酬の最大値を計算 //一度行った仕事は除外するため、priority_queueで管理 long value = 0; priority_queue<int> pq; //日付をM日目からループ for (int i = m; i >= 0; i--) { //最終日からi日目に報酬受け取り期間iの仕事ができるようになる。 int daysLeft = m - i; for (int value : works[daysLeft]) { pq.push(value); } if (pq.empty()) continue; //仕事の取り出し value += pq.top(); pq.pop(); } cout << value; return 0; }
[ "literal.number.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
750,584
750,583
u889915625
cpp
p02948
// // main.cpp // temp // // Created by tolemy on 2019/08/04. // Copyright © 2019 tolemy. All rights reserved. // #include <algorithm> #include <iostream> #include <queue> #include <vector> using namespace std; int main(int argc, const char *argv[]) { const int MAX_WORKS_COUNT = 100000 + 1; //方針 // 0〜M-1日間で考える(M日目は報酬を受け取ることはできるが、仕事をしても翌日以降がないため意味がない) // M-1日目から初めて、残り日数のうちに報酬がもらえる仕事のうち、報酬が最大の仕事を順番にこなしていく //インプットの処理 // n:仕事の数 // m:日数 int n, m; cin >> n >> m; //報酬受け取り期間と報酬の2次元配列を作る。 // vectorの配列とする。 typedef vector<int> values; values works[MAX_WORKS_COUNT]; for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; works[a].push_back(b); } //報酬受け取り期間の昇順にソート for (int i = 0; i < n; i++) { sort(works[i].begin(), works[i].end()); } //合計報酬の最大値を計算 //一度行った仕事は除外するため、priority_queueで管理 long value = 0; priority_queue<int> pq; //日付をM日目からループ for (int i = m; i >= 1; i--) { //最終日からi日目に報酬受け取り期間iの仕事ができるようになる。 int daysLeft = m - i; for (int value : works[daysLeft]) { pq.push(value); } if (pq.empty()) continue; //仕事の取り出し value += pq.top(); pq.pop(); } cout << value; return 0; }
// // main.cpp // temp // // Created by tolemy on 2019/08/04. // Copyright © 2019 tolemy. All rights reserved. // #include <algorithm> #include <iostream> #include <queue> #include <vector> using namespace std; int main(int argc, const char *argv[]) { const int MAX_WORKS_COUNT = 100000 + 1; //方針 // 0〜M-1日間で考える(M日目は報酬を受け取ることはできるが、仕事をしても翌日以降がないため意味がない) // M-1日目から初めて、残り日数のうちに報酬がもらえる仕事のうち、報酬が最大の仕事を順番にこなしていく //インプットの処理 // n:仕事の数 // m:日数 int n, m; cin >> n >> m; //報酬受け取り期間と報酬の2次元配列を作る。 // vectorの配列とする。 typedef vector<int> values; values works[MAX_WORKS_COUNT]; for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; works[a].push_back(b); } //報酬受け取り期間の昇順にソート for (int i = 0; i < MAX_WORKS_COUNT; i++) { sort(works[i].begin(), works[i].end()); } //合計報酬の最大値を計算 //一度行った仕事は除外するため、priority_queueで管理 long value = 0; priority_queue<int> pq; //日付をM日目からループ for (int i = m; i >= 0; i--) { //最終日からi日目に報酬受け取り期間iの仕事ができるようになる。 int daysLeft = m - i; for (int value : works[daysLeft]) { pq.push(value); } if (pq.empty()) continue; //仕事の取り出し value += pq.top(); pq.pop(); } cout << value; return 0; }
[ "identifier.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change", "literal.number.change", "expression.off_by_one" ]
750,585
750,583
u889915625
cpp
p02948
#include <bits/stdc++.h> using namespace std; signed main() { cin.tie(0); ios::sync_with_stdio(false); long N, M; cin >> N >> M; vector<vector<long>> v(M + 2); priority_queue<long> q; long A; int B; for (long i = 0; i < N; i++) { cin >> A >> B; v[A].push_back(B); } long long t = 0; pair<int, long> tp; for (long D = 1; D < M + 1; D++) { for (auto &vv : v[D]) q.push(vv); if (q.size() > 0) { t += q.top(); q.pop(); } } cout << t << endl; return 0; }
#include <bits/stdc++.h> using namespace std; signed main() { cin.tie(0); ios::sync_with_stdio(false); long N, M; cin >> N >> M; vector<vector<long>> v(100010); priority_queue<long> q; long A; int B; for (long i = 0; i < N; i++) { cin >> A >> B; v[A].push_back(B); } long long t = 0; pair<int, long> tp; for (long D = 1; D < M + 1; D++) { for (auto &vv : v[D]) q.push(vv); if (q.size() > 0) { t += q.top(); q.pop(); } } cout << t << endl; return 0; }
[ "identifier.replace.remove", "literal.replace.add", "call.arguments.change", "expression.operation.binary.change", "expression.operation.binary.remove" ]
750,593
750,594
u128513271
cpp
p02948
#include <bits/stdc++.h> using namespace std; using ll = long long; using ii = pair<int, int>; using pll = pair<ll, ll>; using i3 = pair<int, ii>; using vi = vector<int>; using vl = vector<ll>; using vii = vector<ii>; using vi3 = vector<i3>; const int N = 2e5 + 5; const ll INF = 1e12; const double eps = 1e-9, PI = acos(-1); int n, m; vii v; bool cmp(ii a, ii b) { if (a.second == b.second) return a.first < b.first; return a.second > b.second; } set<int> days; void solve() { scanf("%d %d", &n, &m); for (int i = 1; i <= n; i++) { int a, b; scanf("%d %d", &a, &b); v.push_back({a, b}); } sort(v.begin(), v.end(), cmp); for (int i = 0; i <= m; i++) { days.insert(i); } int ans = 0; for (ii V : v) { int a = V.first; int b = V.second; if (a > m) continue; auto it = days.lower_bound(m - a); if (it == days.end()) continue; ans += b; days.erase(it); } printf("%d\n", ans); } main() { int t = 1; // scanf("%d" , &t); while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ii = pair<int, int>; using pll = pair<ll, ll>; using i3 = pair<int, ii>; using vi = vector<int>; using vl = vector<ll>; using vii = vector<ii>; using vi3 = vector<i3>; const int N = 2e5 + 5; const ll INF = 1e12; const double eps = 1e-9, PI = acos(-1); int n, m; vii v; bool cmp(ii a, ii b) { if (a.second == b.second) return a.first < b.first; return a.second > b.second; } set<int> days; void solve() { scanf("%d %d", &n, &m); for (int i = 1; i <= n; i++) { int a, b; scanf("%d %d", &a, &b); v.push_back({a, b}); } sort(v.begin(), v.end(), cmp); for (int i = 0; i <= m; i++) { days.insert(i); } int ans = 0; for (ii V : v) { int a = V.first; int b = V.second; if (a > m) continue; auto it = days.lower_bound(a); if (it == days.end()) continue; ans += b; days.erase(it); } printf("%d\n", ans); } main() { int t = 1; // scanf("%d" , &t); while (t--) { solve(); } return 0; }
[ "expression.operation.binary.remove" ]
750,601
750,602
u284539389
cpp
p02948
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <string> #include <vector> #pragma GCC optimize("Ofast", "inline", "-ffast-math") #pragma GCC target("avx,sse2,sse3,sse4,mmx") using namespace std; typedef long long ll; const ll inf = 0x3f3f3f3f3f3f3f; const int maxn = 100100; vector<int> p[maxn]; priority_queue<int> q; int main(void) { int n, m; int a, b; scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%d%d", &a, &b); p[a].push_back(b); } int ans = 0; for (int i = 1; i < maxn; i++) sort(p[i].begin(), p[i].end()); for (int i = 1; i <= m; i++) { for (int j = 0; j < p[i].size(); j++) { q.push(p[i][j]); } while (!q.empty()) { ans += q.top(); q.pop(); } } printf("%d\n", ans); return 0; }
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <string> #include <vector> #pragma GCC optimize("Ofast", "inline", "-ffast-math") #pragma GCC target("avx,sse2,sse3,sse4,mmx") using namespace std; typedef long long ll; const ll inf = 0x3f3f3f3f3f3f3f; const int maxn = 100100; vector<int> p[maxn]; priority_queue<int> q; int main(void) { int n, m; int a, b; scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%d%d", &a, &b); p[a].push_back(b); } int ans = 0; for (int i = 1; i < maxn; i++) sort(p[i].begin(), p[i].end()); for (int i = 1; i <= m; i++) { for (int j = 0; j < p[i].size(); j++) { q.push(p[i][j]); } if (!q.empty()) { ans += q.top(); q.pop(); } } printf("%d\n", ans); return 0; }
[ "control_flow.branch.while.replace.add", "control_flow.loop.if.replace.remove" ]
750,610
750,611
u682748256
cpp
p02948
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <string> #include <vector> #pragma GCC optimize("Ofast", "inline", "-ffast-math") #pragma GCC target("avx,sse2,sse3,sse4,mmx") using namespace std; typedef long long ll; const ll inf = 0x3f3f3f3f3f3f3f; const int maxn = 100100; vector<int> p[maxn]; priority_queue<int> q; int main(void) { int n, m; int a, b; scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%d%d", &a, &b); p[a].push_back(b); } int ans = 0; for (int i = 1; i < maxn; i++) sort(p[i].begin(), p[i].end()); for (int i = 1; i <= m; i++) { for (int j = 0; j < p[i].size(); j++) { q.push(p[i][j]); } while (!q.empty()) { ans += q.top(); q.pop(); } } printf("%d\n", ans); return 0; }
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <string> #include <vector> #pragma GCC optimize("Ofast", "inline", "-ffast-math") #pragma GCC target("avx,sse2,sse3,sse4,mmx") using namespace std; typedef long long ll; const ll inf = 0x3f3f3f3f3f3f3f; const int maxn = 100010; vector<int> p[maxn]; priority_queue<int> q; int main(void) { int n, m; int a, b; scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%d%d", &a, &b); p[a].push_back(b); } int ans = 0; for (int i = 1; i < maxn; i++) sort(p[i].begin(), p[i].end()); for (int i = 1; i <= m; i++) { for (int j = 0; j < p[i].size(); j++) { q.push(p[i][j]); } if (!q.empty()) { ans += q.top(); q.pop(); } } printf("%d\n", ans); return 0; }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.branch.while.replace.add", "control_flow.loop.if.replace.remove" ]
750,610
750,612
u682748256
cpp
p02948
// 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; }
[ "identifier.replace.remove", "literal.replace.add", "call.arguments.change", "expression.operation.binary.change", "expression.operation.binary.remove" ]
750,624
750,625
u874996917
cpp
p02948
// 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() { int n, m; cin >> n >> m; vector<vector<int>> d(m + 1, vector<int>()); for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; d[a].push_back(b); } priority_queue<int> 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; }
[ "variable_declaration.type.change", "identifier.replace.remove", "literal.replace.add", "call.arguments.change", "expression.operation.binary.change", "expression.operation.binary.remove" ]
750,626
750,625
u874996917
cpp
p02948
// 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() { int n, m; cin >> n >> m; vector<vector<int>> d(n, vector<int>()); for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; d[a].push_back(b); } priority_queue<int> 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; }
[ "variable_declaration.type.change" ]
750,627
750,625
u874996917
cpp
p02948
/* This Submission is to determine how many 120/240 min const. delivery point there are. */ #define _CRT_SECURE_NO_WARNINGS #include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <complex> #include <cstdlib> #include <cstring> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <math.h> #include <queue> #include <random> #include <set> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string> #include <time.h> #include <typeinfo> #include <unordered_map> #include <utility> #include <vector> using namespace std; typedef string::const_iterator State; #define Ma_PI 3.141592653589793 #define eps 0.00000001 #define LONG_INF 1e18 #define GOLD 1.61803398874989484820458 #define MAX_MOD 1000000007 #define MOD 1000000007 #define seg_size 262144 #define REP(a, b) for (long long a = 0; a < b; ++a) unsigned long xor128() { static unsigned long x = time(NULL), y = 362436069, z = 521288629, w = 88675123; unsigned long t = (x ^ (x << 11)); x = y; y = z; z = w; return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8))); } long long go_back[200000] = {}; int union_find(int now) { if (now == -1) return -1; if (go_back[now] == now) return now; return go_back[now] = union_find(go_back[now]); } int main() { iostream::sync_with_stdio(false); int n, m; cin >> n >> m; vector<pair<long long, long long>> next; REP(i, n) { long long a, b; cin >> a >> b; next.push_back(make_pair(b, a)); } sort(next.begin(), next.end()); for (int i = 0; i < m; ++i) { go_back[i] = i; } long long ans = 0; for (int i = next.size() - 1; i >= 0; --i) { long long geko = union_find(m - next[i].second); if (geko != -1) { ans += next[i].first; go_back[geko] = geko - 1; } } cout << ans << endl; return 0; }
/* This Submission is to determine how many 120/240 min const. delivery point there are. */ #define _CRT_SECURE_NO_WARNINGS #include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <complex> #include <cstdlib> #include <cstring> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <math.h> #include <queue> #include <random> #include <set> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string> #include <time.h> #include <typeinfo> #include <unordered_map> #include <utility> #include <vector> using namespace std; typedef string::const_iterator State; #define Ma_PI 3.141592653589793 #define eps 0.00000001 #define LONG_INF 1e18 #define GOLD 1.61803398874989484820458 #define MAX_MOD 1000000007 #define MOD 1000000007 #define seg_size 262144 #define REP(a, b) for (long long a = 0; a < b; ++a) unsigned long xor128() { static unsigned long x = time(NULL), y = 362436069, z = 521288629, w = 88675123; unsigned long t = (x ^ (x << 11)); x = y; y = z; z = w; return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8))); } long long go_back[300000] = {}; int union_find(int now) { if (now <= -1) return -1; if (go_back[now] == now) return now; return go_back[now] = union_find(go_back[now]); } int main() { iostream::sync_with_stdio(false); int n, m; cin >> n >> m; vector<pair<long long, long long>> next; REP(i, n) { long long a, b; cin >> a >> b; next.push_back(make_pair(b, a)); } sort(next.begin(), next.end()); for (int i = 0; i < m; ++i) { go_back[i] = i; } long long ans = 0; for (int i = next.size() - 1; i >= 0; --i) { long long geko = union_find(m - next[i].second); if (geko != -1) { ans += next[i].first; go_back[geko] = geko - 1; } } cout << ans << endl; return 0; }
[ "literal.number.change", "variable_declaration.array_dimensions.change", "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
750,645
750,646
u545022164
cpp
p02949
#include <bits/stdc++.h> using namespace std; //入力 template <typename T> istream &operator>>(istream &is, vector<T> &a) { for (int i = 0; i < a.size(); i++) is >> a[i]; return is; } template <typename T, typename U> istream &operator>>(istream &is, pair<T, U> &p) { is >> p.first >> p.second; return is; } //出力 template <typename T> ostream &operator<<(ostream &os, const vector<T> &a) { for (int i = 0; i < a.size(); i++) { os << a[i] << ((i + 1 != a.size()) ? " " : ""); } return os; } template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; } //入出力高速化 struct hishimochi { hishimochi() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(10); } }; hishimochi Hishimochi; //辺 struct edge { long long to, cost; edge(long long t, long long c) : to(t), cost(c) {} }; struct edge2 { long long from, to, cost; edge2(long long f, long long t, long long c) : from(f), to(t), cost(c) {} }; //型名 using ll = long long; using ull = unsigned long long; using ld = long double; using pll = pair<long long, long long>; using vl = vector<long long>; using vvl = vector<vector<long long>>; using vvvl = vector<vector<vector<long long>>>; using vc = vector<char>; using vvc = vector<vector<char>>; using vs = vector<string>; using vb = vector<bool>; using vvb = vector<vector<bool>>; using vp = vector<pair<long long, long long>>; using Lqueue = priority_queue<long long>; using Squeue = priority_queue<long long, vector<long long>, greater<long long>>; //定数 const int MOD1 = 1000000007; const int MOD2 = 998244353; const long double PI = 3.1415926535897932; const long long MAXLL = 9223372036854775807; const int MAXI = 2147483647; const long long INF = 2305843009213693951; const int inf = 1073741789; const long double eps = 0.000000001; const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}; const int dy[] = {1, 0, -1, 0, 1, 1, -1, -1}; //マクロ #define overload3(_1, _2, _3, name, ...) name #define rep1(n) for (int _ = 0; _ < (n); _++) #define rep2(i, n) for (int i = 0; i < (n); i++) #define rep3(i, s, n) for (long long i = (s); i < (n); i++) #define rep(...) overload3(__VA_ARGS__, rep3, rep2, rep1)(__VA_ARGS__) #define bitrep1(n) for (int _ = 0; _ < (1LL << (n)); _++) #define bitrep2(i, n) for (int i = 0; i < (1LL << (n)); i++) #define bitrep3(i, s, n) for (int i = (s); i < (1LL << (n)); i++) #define bitrep(...) \ overload3(__VA_ARGS__, bitrep3, bitrep2, bitrep1)(__VA_ARGS__) #define rrep0(n) for (int i = (n)-1; i >= 0; i--) #define rrep1(i, n) for (int i = (n)-1; i >= 0; i--) #define rrep2(i, s, n) for (long long i = (n - 1); i >= (s); i--) #define rrep(...) overload3(__VA_ARGS__, rrep2, rrep1, rrep0)(__VA_ARGS__) #define rbf(a, x) for (auto &a : x) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define bitcheck(bit, i) (bit) & (1LL << (i)) #define Maxe(x) *max_element((x).begin(), (x).end()) #define Mine(x) *min_element((x).begin(), (x).end()) #define Sume(x) accumulate((x).begin(), (x).end(), 0LL) #define Size(x) ((long long)(x).size()) #define Sort(x) sort((x).begin(), (x).end()) #define rSort(x) sort((x).rbegin(), (x).rend()) #define Rev(x) reverse((x).begin(), (x).end()) #define Lin(s) getline(cin, (s)) //省略 #define fi first #define se second #define mp make_pair #define mt make_tuple #define eb emplace_back //関数 void Yes(bool a) { cout << (a ? "Yes" : "No") << endl; } void YES(bool a) { cout << (a ? "YES" : "NO") << endl; } long long modpow(long long x, long long n, int m) { long long r = 1; while (n > 0) { if (n & 1) (r *= x) %= m; (x *= x) %= m; n >>= 1; } return r; } long long Gcd(long long a, long long b) { return b ? Gcd(b, a % b) : a; } long long Lcm(long long a, long long b) { return a / Gcd(a, b) * b; } inline long long cutup(long long a, long long b) { return (a + b - 1) / b; } inline long long popcnt(long long a) { return __builtin_popcountll(a); } template <class T, class U> auto max(T a, U b) { return a > b ? a : b; } template <class T, class U> auto min(T a, U b) { return a < b ? a : b; } template <class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true; } return false; } template <class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true; } return false; } template <class T> void print(T a) { cout << a << endl; } template <class t> t mypow(t a, long long b) { if (b == 0) return 1; if (a == 0) return 0; t x = 1; while (b > 0) { if (b & 1LL) x *= a; a *= a; b >>= 1LL; } return x; } struct BellmanFord { int V; vector<long long> d; vector<edge2> Es; BellmanFord(int v) : V(v), d(v) {} void add(int f, int t, long long c) { edge2 E(f, t, c); Es.emplace_back(E); } //-INFの場合、負閉路を用いて無限にコストを下げられる // trueを返す場合に負閉路が存在する bool build(int s) { bool c = false; for (int i = 0; i < V; i++) d[i] = INF; d[s] = 0; for (int i = 0; i < V - 1; i++) { for (auto &e : Es) { if (d[e.from] == INF) continue; if (d[e.from] + e.cost < d[e.to]) d[e.to] = d[e.from] + e.cost; } } for (int i = 0; i < V; i++) { for (auto &e : Es) { if (d[e.from] == INF) continue; if (d[e.from] + e.cost < d[e.to]) { c = true; d[e.to] = -INF; } } } return c; } }; signed main() { ll n, m, p; cin >> n >> m >> p; BellmanFord BF(n); rep(m) { ll a, b, c; cin >> a >> b >> c; a--; b--; BF.add(a, b, -c + p); } BF.build(0); if (BF.d[n - 1] == -INF) { cout << -1 << endl; } else { cout << -BF.d[n - 1] << endl; } }
#include <bits/stdc++.h> using namespace std; //入力 template <typename T> istream &operator>>(istream &is, vector<T> &a) { for (int i = 0; i < a.size(); i++) is >> a[i]; return is; } template <typename T, typename U> istream &operator>>(istream &is, pair<T, U> &p) { is >> p.first >> p.second; return is; } //出力 template <typename T> ostream &operator<<(ostream &os, const vector<T> &a) { for (int i = 0; i < a.size(); i++) { os << a[i] << ((i + 1 != a.size()) ? " " : ""); } return os; } template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; } //入出力高速化 struct hishimochi { hishimochi() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(10); } }; hishimochi Hishimochi; //辺 struct edge { long long to, cost; edge(long long t, long long c) : to(t), cost(c) {} }; struct edge2 { long long from, to, cost; edge2(long long f, long long t, long long c) : from(f), to(t), cost(c) {} }; //型名 using ll = long long; using ull = unsigned long long; using ld = long double; using pll = pair<long long, long long>; using vl = vector<long long>; using vvl = vector<vector<long long>>; using vvvl = vector<vector<vector<long long>>>; using vc = vector<char>; using vvc = vector<vector<char>>; using vs = vector<string>; using vb = vector<bool>; using vvb = vector<vector<bool>>; using vp = vector<pair<long long, long long>>; using Lqueue = priority_queue<long long>; using Squeue = priority_queue<long long, vector<long long>, greater<long long>>; //定数 const int MOD1 = 1000000007; const int MOD2 = 998244353; const long double PI = 3.1415926535897932; const long long MAXLL = 9223372036854775807; const int MAXI = 2147483647; const long long INF = 2305843009213693951; const int inf = 1073741789; const long double eps = 0.000000001; const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}; const int dy[] = {1, 0, -1, 0, 1, 1, -1, -1}; //マクロ #define overload3(_1, _2, _3, name, ...) name #define rep1(n) for (int _ = 0; _ < (n); _++) #define rep2(i, n) for (int i = 0; i < (n); i++) #define rep3(i, s, n) for (long long i = (s); i < (n); i++) #define rep(...) overload3(__VA_ARGS__, rep3, rep2, rep1)(__VA_ARGS__) #define bitrep1(n) for (int _ = 0; _ < (1LL << (n)); _++) #define bitrep2(i, n) for (int i = 0; i < (1LL << (n)); i++) #define bitrep3(i, s, n) for (int i = (s); i < (1LL << (n)); i++) #define bitrep(...) \ overload3(__VA_ARGS__, bitrep3, bitrep2, bitrep1)(__VA_ARGS__) #define rrep0(n) for (int i = (n)-1; i >= 0; i--) #define rrep1(i, n) for (int i = (n)-1; i >= 0; i--) #define rrep2(i, s, n) for (long long i = (n - 1); i >= (s); i--) #define rrep(...) overload3(__VA_ARGS__, rrep2, rrep1, rrep0)(__VA_ARGS__) #define rbf(a, x) for (auto &a : x) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define bitcheck(bit, i) (bit) & (1LL << (i)) #define Maxe(x) *max_element((x).begin(), (x).end()) #define Mine(x) *min_element((x).begin(), (x).end()) #define Sume(x) accumulate((x).begin(), (x).end(), 0LL) #define Size(x) ((long long)(x).size()) #define Sort(x) sort((x).begin(), (x).end()) #define rSort(x) sort((x).rbegin(), (x).rend()) #define Rev(x) reverse((x).begin(), (x).end()) #define Lin(s) getline(cin, (s)) //省略 #define fi first #define se second #define mp make_pair #define mt make_tuple #define eb emplace_back //関数 void Yes(bool a) { cout << (a ? "Yes" : "No") << endl; } void YES(bool a) { cout << (a ? "YES" : "NO") << endl; } long long modpow(long long x, long long n, int m) { long long r = 1; while (n > 0) { if (n & 1) (r *= x) %= m; (x *= x) %= m; n >>= 1; } return r; } long long Gcd(long long a, long long b) { return b ? Gcd(b, a % b) : a; } long long Lcm(long long a, long long b) { return a / Gcd(a, b) * b; } inline long long cutup(long long a, long long b) { return (a + b - 1) / b; } inline long long popcnt(long long a) { return __builtin_popcountll(a); } template <class T, class U> auto max(T a, U b) { return a > b ? a : b; } template <class T, class U> auto min(T a, U b) { return a < b ? a : b; } template <class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true; } return false; } template <class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true; } return false; } template <class T> void print(T a) { cout << a << endl; } template <class t> t mypow(t a, long long b) { if (b == 0) return 1; if (a == 0) return 0; t x = 1; while (b > 0) { if (b & 1LL) x *= a; a *= a; b >>= 1LL; } return x; } struct BellmanFord { int V; vector<long long> d; vector<edge2> Es; BellmanFord(int v) : V(v), d(v) {} void add(int f, int t, long long c) { edge2 E(f, t, c); Es.emplace_back(E); } //-INFの場合、負閉路を用いて無限にコストを下げられる // trueを返す場合に負閉路が存在する bool build(int s) { bool c = false; for (int i = 0; i < V; i++) d[i] = INF; d[s] = 0; for (int i = 0; i < V - 1; i++) { for (auto &e : Es) { if (d[e.from] == INF) continue; if (d[e.from] + e.cost < d[e.to]) d[e.to] = d[e.from] + e.cost; } } for (int i = 0; i < V; i++) { for (auto &e : Es) { if (d[e.from] == INF) continue; if (d[e.from] + e.cost < d[e.to]) { c = true; d[e.to] = -INF; } } } return c; } }; signed main() { ll n, m, p; cin >> n >> m >> p; BellmanFord BF(n); rep(m) { ll a, b, c; cin >> a >> b >> c; a--; b--; BF.add(a, b, -c + p); } BF.build(0); if (BF.d[n - 1] == -INF) { cout << -1 << endl; } else { cout << max(-BF.d[n - 1], 0) << endl; } }
[ "call.add", "call.arguments.add" ]
750,647
750,648
u190580703
cpp
p02949
#include <bits/stdc++.h> using namespace std; using ll = long long; using VI = vector<int>; #define FOR(i, a, n) for (int(i) = (a); (i) < (n); (i)++) #define eFOR(i, a, n) for (int(i) = (a); (i) <= (n); (i)++) #define SORT(i) sort((i).begin(), (i).end()) #define rSORT(i, a) sort((i).begin(), (i).end(), (a)) constexpr auto INF = 1000000000; constexpr auto LLINF = 1LL << 60; constexpr auto mod = 1000000007; constexpr auto MOD = 998244353; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n, m; ll p; cin >> n >> m >> p; int a, b; ll c; vector<tuple<int, int, ll>> edge; FOR(i, 0, m) { cin >> a >> b >> c; edge.push_back(make_tuple(--a, --b, c - p)); } vector<bool> neg(n, false); vector<ll> ans(n, -LLINF); ans[0] = 0; eFOR(i, 1, n * 2) { for (auto next : edge) { tie(a, b, c) = next; if (ans[a] < LLINF / 2) continue; if (chmax(ans[b], ans[a] + c)) { if (i > n) neg[b] = true; } if (neg[a]) neg[b] = true; } } cout << (neg[n - 1] ? -1 : max(ans[n - 1], 0LL)) << "\n"; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using VI = vector<int>; #define FOR(i, a, n) for (int(i) = (a); (i) < (n); (i)++) #define eFOR(i, a, n) for (int(i) = (a); (i) <= (n); (i)++) #define SORT(i) sort((i).begin(), (i).end()) #define rSORT(i, a) sort((i).begin(), (i).end(), (a)) constexpr auto INF = 1000000000; constexpr auto LLINF = 1LL << 60; constexpr auto mod = 1000000007; constexpr auto MOD = 998244353; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n, m; ll p; cin >> n >> m >> p; int a, b; ll c; vector<tuple<int, int, ll>> edge; FOR(i, 0, m) { cin >> a >> b >> c; edge.push_back(make_tuple(--a, --b, c - p)); } vector<bool> neg(n, false); vector<ll> ans(n, -LLINF); ans[0] = 0; eFOR(i, 1, n * 2) { for (auto next : edge) { tie(a, b, c) = next; if (ans[a] < -LLINF / 2) continue; if (chmax(ans[b], ans[a] + c)) { if (i > n) neg[b] = true; } if (neg[a]) neg[b] = true; } } cout << (neg[n - 1] ? -1 : max(ans[n - 1], 0LL)) << "\n"; }
[ "expression.operation.unary.add", "control_flow.branch.if.condition.change" ]
750,651
750,652
u863044225
cpp
p02949
#include <bits/stdc++.h> using namespace std; using ll = long long; using VI = vector<int>; #define FOR(i, a, n) for (int(i) = (a); (i) < (n); (i)++) #define eFOR(i, a, n) for (int(i) = (a); (i) <= (n); (i)++) #define SORT(i) sort((i).begin(), (i).end()) #define rSORT(i, a) sort((i).begin(), (i).end(), (a)) constexpr auto INF = 1000000000; constexpr auto LLINF = 1LL << 60; constexpr auto mod = 1000000007; constexpr auto MOD = 998244353; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n, m; ll p; cin >> n >> m >> p; int a, b; ll c; vector<tuple<int, int, ll>> edge; FOR(i, 0, m) { cin >> a >> b >> c; edge.push_back(make_tuple(--a, --b, c - p)); } vector<bool> neg(n, false); vector<ll> ans(n, -LLINF); ans[0] = 0; eFOR(i, 1, n * 2) { for (auto next : edge) { tie(a, b, c) = next; if (ans[a] == LLINF) continue; if (chmax(ans[b], ans[a] + c)) { if (i > n) neg[b] = true; } if (neg[a]) neg[b] = true; } } cout << (neg[n - 1] ? -1 : max(ans[n - 1], 0LL)) << "\n"; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using VI = vector<int>; #define FOR(i, a, n) for (int(i) = (a); (i) < (n); (i)++) #define eFOR(i, a, n) for (int(i) = (a); (i) <= (n); (i)++) #define SORT(i) sort((i).begin(), (i).end()) #define rSORT(i, a) sort((i).begin(), (i).end(), (a)) constexpr auto INF = 1000000000; constexpr auto LLINF = 1LL << 60; constexpr auto mod = 1000000007; constexpr auto MOD = 998244353; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n, m; ll p; cin >> n >> m >> p; int a, b; ll c; vector<tuple<int, int, ll>> edge; FOR(i, 0, m) { cin >> a >> b >> c; edge.push_back(make_tuple(--a, --b, c - p)); } vector<bool> neg(n, false); vector<ll> ans(n, -LLINF); ans[0] = 0; eFOR(i, 1, n * 2) { for (auto next : edge) { tie(a, b, c) = next; if (ans[a] < -LLINF / 2) continue; if (chmax(ans[b], ans[a] + c)) { if (i > n) neg[b] = true; } if (neg[a]) neg[b] = true; } } cout << (neg[n - 1] ? -1 : max(ans[n - 1], 0LL)) << "\n"; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change", "expression.operation.unary.add" ]
750,653
750,652
u863044225
cpp
p02949
#include <algorithm> #include <bitset> #include <cmath> #include <deque> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef vector<int> VI; #define FOR(i, a, n) for (int(i) = (a); (i) < (n); (i)++) #define eFOR(i, a, n) for (int(i) = (a); (i) <= (n); (i)++) #define SORT(i) sort((i).begin(), (i).end()) #define rSORT(i, a) sort((i).begin(), (i).end(), (a)) constexpr auto INF = 1000000000; constexpr auto LLINF = 1LL << 62; constexpr auto mod = 1000000007; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } int main() { cin.tie(0); ios::sync_with_stdio(false); int n, m, p; cin >> n >> m >> p; int a, b; ll c; vector<vector<pair<int, ll>>> edge(n); FOR(i, 0, m) { cin >> a >> b >> c; edge[--a].push_back(make_pair(--b, c - p)); } vector<ll> ans(n, -LLINF); ans[0] = 0; bool neg = false; FOR(i, 0, n * 2) { FOR(j, 0, n) { for (auto next : edge[j]) { a = j; tie(b, c) = next; if (chmax(ans[b], ans[a] + c)) { if (i == n * 2 - 1 && b == n - 1) neg = true; } } } } cout << (neg ? -1 : max(ans[n - 1], 0LL)) << "\n"; }
#include <algorithm> #include <bitset> #include <cmath> #include <deque> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef vector<int> VI; #define FOR(i, a, n) for (int(i) = (a); (i) < (n); (i)++) #define eFOR(i, a, n) for (int(i) = (a); (i) <= (n); (i)++) #define SORT(i) sort((i).begin(), (i).end()) #define rSORT(i, a) sort((i).begin(), (i).end(), (a)) constexpr auto INF = 1000000000; constexpr auto LLINF = 1LL << 62; constexpr auto mod = 1000000007; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } int main() { cin.tie(0); ios::sync_with_stdio(false); int n, m, p; cin >> n >> m >> p; int a, b; ll c; vector<vector<pair<int, ll>>> edge(n); FOR(i, 0, m) { cin >> a >> b >> c; edge[--a].push_back(make_pair(--b, c - p)); } vector<ll> ans(n, -LLINF); ans[0] = 0; bool neg = false; FOR(i, 0, n * 2) { FOR(j, 0, n) { for (auto next : edge[j]) { a = j; tie(b, c) = next; if (chmax(ans[b], ans[a] + c)) { if (i >= n && b == n - 1) neg = true; } } } } cout << (neg ? -1 : max(ans[n - 1], 0LL)) << "\n"; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change", "expression.operation.binary.remove" ]
750,654
750,655
u863044225
cpp
p02949
#include <algorithm> #include <bitset> #include <cmath> #include <deque> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef vector<int> VI; #define FOR(i, a, n) for (int(i) = (a); (i) < (n); (i)++) #define eFOR(i, a, n) for (int(i) = (a); (i) <= (n); (i)++) #define SORT(i) sort((i).begin(), (i).end()) #define rSORT(i, a) sort((i).begin(), (i).end(), (a)) constexpr auto INF = 1000000000; constexpr auto LLINF = 1LL << 60; constexpr auto mod = 1000000007; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } int main() { cin.tie(0); ios::sync_with_stdio(false); int n, m; ll p; cin >> n >> m >> p; int a, b; ll c; vector<tuple<int, int, ll>> edge; FOR(i, 0, m) { cin >> a >> b >> c; edge.push_back(make_tuple(--a, --b, c - p)); } vector<ll> ans(n, -LLINF); ans[0] = 0; bool neg = false; eFOR(i, 1, n * 2) { for (auto next : edge) { tie(a, b, c) = next; if (chmax(ans[b], ans[a] + c)) { if (i == n * 2 && b == n - 1) neg = true; } } } cout << (neg ? -1 : max(ans[n - 1], 0LL)) << "\n"; }
#include <algorithm> #include <bitset> #include <cmath> #include <deque> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef vector<int> VI; #define FOR(i, a, n) for (int(i) = (a); (i) < (n); (i)++) #define eFOR(i, a, n) for (int(i) = (a); (i) <= (n); (i)++) #define SORT(i) sort((i).begin(), (i).end()) #define rSORT(i, a) sort((i).begin(), (i).end(), (a)) constexpr auto INF = 1000000000; constexpr auto LLINF = 1LL << 60; constexpr auto mod = 1000000007; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } int main() { cin.tie(0); ios::sync_with_stdio(false); int n, m; ll p; cin >> n >> m >> p; int a, b; ll c; vector<tuple<int, int, ll>> edge; FOR(i, 0, m) { cin >> a >> b >> c; edge.push_back(make_tuple(--a, --b, c - p)); } vector<ll> ans(n, -LLINF); ans[0] = 0; bool neg = false; eFOR(i, 1, n * 2) { for (auto next : edge) { tie(a, b, c) = next; if (chmax(ans[b], ans[a] + c)) { if (i >= n && b == n - 1) neg = true; } } } cout << (neg ? -1 : max(ans[n - 1], 0LL)) << "\n"; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change", "expression.operation.binary.remove" ]
750,656
750,657
u863044225
cpp
p02949
#include <algorithm> #include <bitset> #include <cmath> #include <deque> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef vector<int> VI; #define FOR(i, a, n) for (int(i) = (a); (i) < (n); (i)++) #define eFOR(i, a, n) for (int(i) = (a); (i) <= (n); (i)++) #define SORT(i) sort((i).begin(), (i).end()) #define rSORT(i, a) sort((i).begin(), (i).end(), (a)) constexpr auto INF = 1000000000; constexpr auto LLINF = 1LL << 60; constexpr auto mod = 1000000007; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } int main() { cin.tie(0); ios::sync_with_stdio(false); int n, m; ll p; cin >> n >> m >> p; int a, b; ll c; vector<tuple<int, int, ll>> edge; FOR(i, 0, m) { cin >> a >> b >> c; edge.push_back(make_tuple(--a, --b, c - p)); } vector<ll> ans(n, -LLINF); ans[0] = 0; bool neg = false; eFOR(i, 1, n * 2) { for (auto next : edge) { tie(a, b, c) = next; if (chmax(ans[b], ans[a] + c)) { if (i == n * 2 && b == n - 1) neg = true; } } } cout << (neg ? -1 : max(ans[n - 1], 0LL)) << "\n"; }
#include <algorithm> #include <bitset> #include <cmath> #include <deque> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef vector<int> VI; #define FOR(i, a, n) for (int(i) = (a); (i) < (n); (i)++) #define eFOR(i, a, n) for (int(i) = (a); (i) <= (n); (i)++) #define SORT(i) sort((i).begin(), (i).end()) #define rSORT(i, a) sort((i).begin(), (i).end(), (a)) constexpr auto INF = 1000000000; constexpr auto LLINF = 1LL << 60; constexpr auto mod = 1000000007; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } int main() { cin.tie(0); ios::sync_with_stdio(false); int n, m; ll p; cin >> n >> m >> p; int a, b; ll c; vector<tuple<int, int, ll>> edge; FOR(i, 0, m) { cin >> a >> b >> c; edge.push_back(make_tuple(--a, --b, c - p)); } vector<ll> ans(n, -LLINF); ans[0] = 0; bool neg = false; eFOR(i, 1, n * 2) { for (auto next : edge) { tie(a, b, c) = next; if (chmax(ans[b], ans[a] + c)) { if (i > n && b == n - 1) neg = true; } } } cout << (neg ? -1 : max(ans[n - 1], 0LL)) << "\n"; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change", "expression.operation.binary.remove" ]
750,656
750,659
u863044225
cpp
p02949
#include <algorithm> #include <bitset> #include <cassert> #include <ciso646> #include <cmath> #include <complex> #include <cstdio> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef unsigned int ui; const ll mod = 1000000007; const ll INF = (ll)1000000007 * 1000000007; typedef pair<int, int> P; #define stop \ char nyaa; \ cin >> nyaa; #define rep(i, n) for (int i = 0; i < n; i++) #define per(i, n) for (int i = n - 1; i >= 0; i--) #define Rep(i, sta, n) for (int i = sta; i < n; i++) #define Per(i, sta, n) for (int i = n - 1; i >= sta; i--) #define rep1(i, n) for (int i = 1; i <= n; i++) #define per1(i, n) for (int i = n; i >= 1; i--) #define Rep1(i, sta, n) for (int i = sta; i <= n; i++) typedef long double ld; const ld eps = 1e-8; const ld pi = acos(-1.0); typedef pair<ll, ll> LP; int dx[4] = {1, -1, 0, 0}; int dy[4] = {0, 0, 1, -1}; template <typename T> struct BellmanFord { struct edge { int u, v; T w; edge() {} edge(int u, int v, T w) : u(u), v(v), w(w) {} }; const T inf = (numeric_limits<T>::max()) / 2; // infを設定する int n; vector<vector<int>> G; vector<int> used, reach; BellmanFord(int n) : n(n), G(n), used(n, 0), reach(n, 1) {} vector<edge> es; void add_edge(int u, int v, T c) { es.emplace_back(u, v, c); G[u].emplace_back(v); } vector<T> build(int from, int &neg_loop) { vector<T> ds(n, inf); ds[from] = 0; for (int j = 0; j < n; j++) { bool update = 0; for (auto e : es) { if (!reach[e.u] || !reach[e.v] || ds[e.u] == INF) continue; if (ds[e.v] > ds[e.u] + e.w) { ds[e.v] = ds[e.u] + e.w; update = 1; } } if (!update) break; if (j == n - 1) { neg_loop = 1; return ds; } } neg_loop = 0; return ds; } void dfs(int v) { if (used[v]) return; used[v] = 1; for (int u : G[v]) dfs(u); } T shortest_path(int from, int to, int &neg_loop) { for (int i = 0; i < n; i++) { fill(used.begin(), used.end(), 0); dfs(i); reach[i] = used[to]; } return build(from, neg_loop)[to]; } }; int n, m; ll p; void solve() { cin >> n >> m >> p; BellmanFord<ll> bel(n); rep(i, m) { int u, v; ll c; cin >> u >> v >> c; u--; v--; bel.add_edge(u, v, p - c); } int neg = 0; ll ans = bel.shortest_path(0, n - 1, neg); if (neg) cout << -1 << endl; else cout << max(0ll, -ans) << endl; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(50); solve(); }
#include <algorithm> #include <bitset> #include <cassert> #include <ciso646> #include <cmath> #include <complex> #include <cstdio> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef unsigned int ui; const ll mod = 1000000007; const ll INF = (ll)1000000007 * 1000000007; typedef pair<int, int> P; #define stop \ char nyaa; \ cin >> nyaa; #define rep(i, n) for (int i = 0; i < n; i++) #define per(i, n) for (int i = n - 1; i >= 0; i--) #define Rep(i, sta, n) for (int i = sta; i < n; i++) #define Per(i, sta, n) for (int i = n - 1; i >= sta; i--) #define rep1(i, n) for (int i = 1; i <= n; i++) #define per1(i, n) for (int i = n; i >= 1; i--) #define Rep1(i, sta, n) for (int i = sta; i <= n; i++) typedef long double ld; const ld eps = 1e-8; const ld pi = acos(-1.0); typedef pair<ll, ll> LP; int dx[4] = {1, -1, 0, 0}; int dy[4] = {0, 0, 1, -1}; template <typename T> struct BellmanFord { struct edge { int u, v; T w; edge() {} edge(int u, int v, T w) : u(u), v(v), w(w) {} }; const T inf = (numeric_limits<T>::max()) / 2; // infを設定する int n; vector<vector<int>> G; vector<int> used, reach; BellmanFord(int n) : n(n), G(n), used(n, 0), reach(n, 1) {} vector<edge> es; void add_edge(int u, int v, T c) { es.emplace_back(u, v, c); G[u].emplace_back(v); } vector<T> build(int from, int &neg_loop) { vector<T> ds(n, inf); ds[from] = 0; for (int j = 0; j < n; j++) { bool update = 0; for (auto e : es) { if (!reach[e.u] || !reach[e.v] || ds[e.u] == inf) continue; if (ds[e.v] > ds[e.u] + e.w) { ds[e.v] = ds[e.u] + e.w; update = 1; } } if (!update) break; if (j == n - 1) { neg_loop = 1; return ds; } } neg_loop = 0; return ds; } void dfs(int v) { if (used[v]) return; used[v] = 1; for (int u : G[v]) dfs(u); } T shortest_path(int from, int to, int &neg_loop) { for (int i = 0; i < n; i++) { fill(used.begin(), used.end(), 0); dfs(i); reach[i] = used[to]; } return build(from, neg_loop)[to]; } }; int n, m; ll p; void solve() { cin >> n >> m >> p; BellmanFord<ll> bel(n); rep(i, m) { int u, v; ll c; cin >> u >> v >> c; u--; v--; bel.add_edge(u, v, p - c); } int neg = 0; ll ans = bel.shortest_path(0, n - 1, neg); if (neg) cout << -1 << endl; else cout << max(0ll, -ans) << endl; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(50); solve(); }
[ "identifier.change", "control_flow.branch.if.condition.change" ]
750,661
750,662
u236127431
cpp
p02949
#include <algorithm> #include <bitset> #include <cassert> #include <ciso646> #include <cmath> #include <complex> #include <cstdio> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef unsigned int ui; const ll mod = 1000000007; const ll INF = (ll)1000000007 * 1000000007; typedef pair<int, int> P; #define stop \ char nyaa; \ cin >> nyaa; #define rep(i, n) for (int i = 0; i < n; i++) #define per(i, n) for (int i = n - 1; i >= 0; i--) #define Rep(i, sta, n) for (int i = sta; i < n; i++) #define Per(i, sta, n) for (int i = n - 1; i >= sta; i--) #define rep1(i, n) for (int i = 1; i <= n; i++) #define per1(i, n) for (int i = n; i >= 1; i--) #define Rep1(i, sta, n) for (int i = sta; i <= n; i++) typedef long double ld; const ld eps = 1e-8; const ld pi = acos(-1.0); typedef pair<ll, ll> LP; int dx[4] = {1, -1, 0, 0}; int dy[4] = {0, 0, 1, -1}; template <typename T> struct BellmanFord { struct edge { int u, v; T w; edge() {} edge(int u, int v, T w) : u(u), v(v), w(w) {} }; int n; vector<vector<int>> G; vector<int> used, reach; BellmanFord(int n) : n(n), G(n), used(n, 0), reach(n, 1) {} vector<edge> es; void add_edge(int u, int v, T c) { es.emplace_back(u, v, c); G[u].emplace_back(v); } vector<T> build(int from, int &neg_loop) { vector<T> ds(n, INF); ds[from] = 0; for (int j = 0; j < n; j++) { bool update = 0; for (auto e : es) { if (!reach[e.u] || !reach[e.v] || ds[e.u] == INF) continue; if (ds[e.v] > ds[e.u] + e.w) { ds[e.v] = ds[e.u] + e.w; update = 1; } } if (!update) break; if (j == n - 1) { neg_loop = 1; return ds; } } neg_loop = 0; return ds; } void dfs(int v) { if (used[v]) return; used[v] = 1; for (int u : G[v]) dfs(u); } T shortest_path(int from, int to, int &neg_loop) { for (int i = 0; i < n; i++) { fill(used.begin(), used.end(), 0); dfs(i); reach[i] = used[to]; } return build(from, neg_loop)[to]; } }; int n, m; ll p; void solve() { cin >> n >> m >> p; BellmanFord<ll> bel(n); rep(i, m) { int u, v; ll c; cin >> u >> v >> c; u--; v--; bel.add_edge(u, v, c - p); } int neg = 0; ll ans = bel.shortest_path(0, n - 1, neg); if (neg) cout << -1 << endl; else cout << max(0ll, ans) << endl; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(50); solve(); }
#include <algorithm> #include <bitset> #include <cassert> #include <ciso646> #include <cmath> #include <complex> #include <cstdio> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef unsigned int ui; const ll mod = 1000000007; const ll INF = (ll)1000000007 * 1000000007; typedef pair<int, int> P; #define stop \ char nyaa; \ cin >> nyaa; #define rep(i, n) for (int i = 0; i < n; i++) #define per(i, n) for (int i = n - 1; i >= 0; i--) #define Rep(i, sta, n) for (int i = sta; i < n; i++) #define Per(i, sta, n) for (int i = n - 1; i >= sta; i--) #define rep1(i, n) for (int i = 1; i <= n; i++) #define per1(i, n) for (int i = n; i >= 1; i--) #define Rep1(i, sta, n) for (int i = sta; i <= n; i++) typedef long double ld; const ld eps = 1e-8; const ld pi = acos(-1.0); typedef pair<ll, ll> LP; int dx[4] = {1, -1, 0, 0}; int dy[4] = {0, 0, 1, -1}; template <typename T> struct BellmanFord { struct edge { int u, v; T w; edge() {} edge(int u, int v, T w) : u(u), v(v), w(w) {} }; int n; vector<vector<int>> G; vector<int> used, reach; BellmanFord(int n) : n(n), G(n), used(n, 0), reach(n, 1) {} vector<edge> es; void add_edge(int u, int v, T c) { es.emplace_back(u, v, c); G[u].emplace_back(v); } vector<T> build(int from, int &neg_loop) { vector<T> ds(n, INF); ds[from] = 0; for (int j = 0; j < n; j++) { bool update = 0; for (auto e : es) { if (!reach[e.u] || !reach[e.v] || ds[e.u] == INF) continue; if (ds[e.v] > ds[e.u] + e.w) { ds[e.v] = ds[e.u] + e.w; update = 1; } } if (!update) break; if (j == n - 1) { neg_loop = 1; return ds; } } neg_loop = 0; return ds; } void dfs(int v) { if (used[v]) return; used[v] = 1; for (int u : G[v]) dfs(u); } T shortest_path(int from, int to, int &neg_loop) { for (int i = 0; i < n; i++) { fill(used.begin(), used.end(), 0); dfs(i); reach[i] = used[to]; } return build(from, neg_loop)[to]; } }; int n, m; ll p; void solve() { cin >> n >> m >> p; BellmanFord<ll> bel(n); rep(i, m) { int u, v; ll c; cin >> u >> v >> c; u--; v--; bel.add_edge(u, v, p - c); } int neg = 0; ll ans = bel.shortest_path(0, n - 1, neg); if (neg) cout << -1 << endl; else cout << max(0ll, -ans) << endl; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(50); solve(); }
[ "expression.operation.binary.remove", "expression.operation.unary.add", "call.arguments.change" ]
750,663
750,664
u236127431
cpp
p02949
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using P = pair<int, int>; const int INF = 1001001001; vector<int> to[2505]; vector<int> rto[2505]; bool rf1[2505]; bool rtn[2505]; bool ok[2505]; void dfs(int v) { if (rf1[v]) return; rf1[v] = true; for (int u : to[v]) dfs(u); } void rdfs(int v) { if (rtn[v]) return; rtn[v] = true; for (int u : to[v]) rdfs(u); } int main() { int n, m, p; cin >> n >> m >> p; vector<tuple<int, int, int>> es; rep(i, m) { int a, b, c; cin >> a >> b >> c; a--; b--; c -= p; c = -c; es.emplace_back(a, b, c); to[a].push_back(b); rto[b].push_back(a); } dfs(0); rdfs(n - 1); rep(i, n) ok[i] = rf1[i] & rtn[i]; vector<int> d(n, INF); d[0] = 0; bool upd = true; int step = 0; while (upd) { upd = false; rep(i, m) { int a, b, c; tie(a, b, c) = es[i]; if (!ok[a]) continue; if (!ok[b]) continue; int newD = d[a] + c; if (newD < d[b]) { upd = true; d[b] = newD; } } step++; if (step > n) { cout << -1 << endl; return 0; } } int ans = -d[n - 1]; ans = max(ans, 0); cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using P = pair<int, int>; const int INF = 1001001001; vector<int> to[2505]; vector<int> rto[2505]; bool rf1[2505]; bool rtn[2505]; bool ok[2505]; void dfs(int v) { if (rf1[v]) return; rf1[v] = true; for (int u : to[v]) dfs(u); } void rdfs(int v) { if (rtn[v]) return; rtn[v] = true; for (int u : rto[v]) rdfs(u); } int main() { int n, m, p; cin >> n >> m >> p; vector<tuple<int, int, int>> es; rep(i, m) { int a, b, c; cin >> a >> b >> c; a--; b--; c -= p; c = -c; es.emplace_back(a, b, c); to[a].push_back(b); rto[b].push_back(a); } dfs(0); rdfs(n - 1); rep(i, n) ok[i] = rf1[i] & rtn[i]; vector<int> d(n, INF); d[0] = 0; bool upd = true; int step = 0; while (upd) { upd = false; rep(i, m) { int a, b, c; tie(a, b, c) = es[i]; if (!ok[a]) continue; if (!ok[b]) continue; int newD = d[a] + c; if (newD < d[b]) { upd = true; d[b] = newD; } } step++; if (step > n) { cout << -1 << endl; return 0; } } int ans = -d[n - 1]; ans = max(ans, 0); cout << ans << endl; }
[ "identifier.change" ]
750,667
750,668
u422506696
cpp
p02949
#include <bits/stdc++.h> using namespace std; using ll = long long; using vin = vector<int>; using vll = vector<long long>; using vvin = vector<vector<int>>; using vvll = vector<vector<long long>>; using vstr = vector<string>; using vvstr = vector<vector<string>>; using vch = vector<char>; using vvch = vector<vector<char>>; using vbo = vector<bool>; using vvbo = vector<vector<bool>>; using vpii = vector<pair<int, int>>; using pqsin = priority_queue<int, vector<int>, greater<int>>; #define mp make_pair #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) #define all(v) v.begin(), v.end() #define decp(n) cout << fixed << setprecision((int)n) const ll inf = 1e9 + 7; const ll INF = 1e18; struct edge { int from, to; ll cost; }; vector<edge> e; vll d(2550); int v; bool MAX = true; void bellman(int s) { fill(all(d), -INF); d[s] = (ll)0; bool update, maxupdate; rep(i, 2 * v + 5) { update = false; maxupdate = false; for (auto hen : e) { if (d[hen.from] != -INF && d[hen.to] < d[hen.from] + hen.cost) { d[hen.to] = (i < v - 1) ? d[hen.from] + hen.cost : 2 * INF; update = true; // if(hen.to==v)maxupdate=true; } } if (!update) break; /*if(i>=v&&maxupdate){ MAX=false; break; }*/ } } int main() { int n, m; ll p; cin >> n >> m >> p; v = n; vin a(m), b(m); vll c(m); rep(i, m) { cin >> a[i] >> b[i] >> c[i]; c[i] -= p; e.push_back((edge){a[i], b[i], c[i]}); } bellman(1); if (d[n] != -2 * INF) cout << max(d[n], (ll)0) << endl; else cout << -1 << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using vin = vector<int>; using vll = vector<long long>; using vvin = vector<vector<int>>; using vvll = vector<vector<long long>>; using vstr = vector<string>; using vvstr = vector<vector<string>>; using vch = vector<char>; using vvch = vector<vector<char>>; using vbo = vector<bool>; using vvbo = vector<vector<bool>>; using vpii = vector<pair<int, int>>; using pqsin = priority_queue<int, vector<int>, greater<int>>; #define mp make_pair #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) #define all(v) v.begin(), v.end() #define decp(n) cout << fixed << setprecision((int)n) const ll inf = 1e9 + 7; const ll INF = 1e18; struct edge { int from, to; ll cost; }; vector<edge> e; vll d(2550); int v; bool MAX = true; void bellman(int s) { fill(all(d), -INF); d[s] = (ll)0; bool update, maxupdate; rep(i, 2 * v + 5) { update = false; maxupdate = false; for (auto hen : e) { if (d[hen.from] != -INF && d[hen.to] < d[hen.from] + hen.cost) { d[hen.to] = (i < v - 1) ? d[hen.from] + hen.cost : 2 * INF; update = true; // if(hen.to==v)maxupdate=true; } } if (!update) break; /*if(i>=v&&maxupdate){ MAX=false; break; }*/ } } int main() { int n, m; ll p; cin >> n >> m >> p; v = n; vin a(m), b(m); vll c(m); rep(i, m) { cin >> a[i] >> b[i] >> c[i]; c[i] -= p; e.push_back((edge){a[i], b[i], c[i]}); } bellman(1); if (d[n] != 2 * INF) cout << max(d[n], (ll)0) << endl; else cout << -1 << endl; }
[ "expression.operation.unary.arithmetic.remove" ]
750,669
750,670
u919867411
cpp
p02949
#include <bits/stdc++.h> using namespace std; using ll = long long; using vin = vector<int>; using vll = vector<long long>; using vvin = vector<vector<int>>; using vvll = vector<vector<long long>>; using vstr = vector<string>; using vvstr = vector<vector<string>>; using vch = vector<char>; using vvch = vector<vector<char>>; using vbo = vector<bool>; using vvbo = vector<vector<bool>>; using vpii = vector<pair<int, int>>; using pqsin = priority_queue<int, vector<int>, greater<int>>; #define mp make_pair #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) #define all(v) v.begin(), v.end() #define decp(n) cout << fixed << setprecision((int)n) const ll inf = 1e9 + 7; const ll INF = 1e18; struct edge { int from, to; ll cost; }; vector<edge> e; vll d(2550); int v; bool MAX = true; void bellman(int s) { fill(all(d), -INF); d[s] = (ll)0; bool update, maxupdate; rep(i, 2 * v + 5) { update = false; maxupdate = false; for (auto hen : e) { if (d[hen.from] != -INF && d[hen.to] < d[hen.from] + hen.cost) { d[hen.to] = (i < v - 1) ? d[hen.from] + hen.cost : -2 * INF; update = true; // if(hen.to==v)maxupdate=true; } } if (!update) break; /*if(i>=v&&maxupdate){ MAX=false; break; }*/ } } int main() { int n, m; ll p; cin >> n >> m >> p; v = n; vin a(m), b(m); vll c(m); rep(i, m) { cin >> a[i] >> b[i] >> c[i]; c[i] -= p; e.push_back((edge){a[i], b[i], c[i]}); } bellman(1); if (d[n] != -2 * INF) cout << max(d[n], (ll)0) << endl; else cout << -1 << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using vin = vector<int>; using vll = vector<long long>; using vvin = vector<vector<int>>; using vvll = vector<vector<long long>>; using vstr = vector<string>; using vvstr = vector<vector<string>>; using vch = vector<char>; using vvch = vector<vector<char>>; using vbo = vector<bool>; using vvbo = vector<vector<bool>>; using vpii = vector<pair<int, int>>; using pqsin = priority_queue<int, vector<int>, greater<int>>; #define mp make_pair #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) #define all(v) v.begin(), v.end() #define decp(n) cout << fixed << setprecision((int)n) const ll inf = 1e9 + 7; const ll INF = 1e18; struct edge { int from, to; ll cost; }; vector<edge> e; vll d(2550); int v; bool MAX = true; void bellman(int s) { fill(all(d), -INF); d[s] = (ll)0; bool update, maxupdate; rep(i, 2 * v + 5) { update = false; maxupdate = false; for (auto hen : e) { if (d[hen.from] != -INF && d[hen.to] < d[hen.from] + hen.cost) { d[hen.to] = (i < v - 1) ? d[hen.from] + hen.cost : 2 * INF; update = true; // if(hen.to==v)maxupdate=true; } } if (!update) break; /*if(i>=v&&maxupdate){ MAX=false; break; }*/ } } int main() { int n, m; ll p; cin >> n >> m >> p; v = n; vin a(m), b(m); vll c(m); rep(i, m) { cin >> a[i] >> b[i] >> c[i]; c[i] -= p; e.push_back((edge){a[i], b[i], c[i]}); } bellman(1); if (d[n] != 2 * INF) cout << max(d[n], (ll)0) << endl; else cout << -1 << endl; }
[ "expression.operation.unary.arithmetic.remove" ]
750,671
750,670
u919867411
cpp
p02949
#include <algorithm> #include <cassert> #include <cstdio> #include <cstdlib> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define repi(i, a, b) for (ll i = (a); i < (b); ++i) #define rep(i, a) repi(i, 0, a) #define repdi(i, a, b) for (ll i = (a)-1; i >= (b); --i) #define repd(i, a) repdi(i, a, 0) #define itr(it, a) for (auto it = (a).begin(); it != (a).end(); ++it) #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() using ll = long long; constexpr ll INF = 1ll << 60; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class S, class T> std::ostream &operator<<(std::ostream &out, const std::pair<S, T> &a) { std::cout << '(' << a.first << ", " << a.second << ')'; return out; } template <class T> std::ostream &operator<<(std::ostream &out, const std::vector<T> &a) { std::cout << '['; rep(i, a.size()) { std::cout << a[i]; if (i != a.size() - 1) std::cout << ", "; } std::cout << ']'; return out; } struct edge { ll from, to, cost; edge(ll from, ll to, ll cost) : from(from), to(to), cost(cost) {} }; ll N, M, P; std::vector<edge> es; std::vector<ll> d; std::vector<ll> G[3000], rG[3000]; bool conn1[3000], connN[3000]; void dfs(ll v) { conn1[v] = true; for (auto u : G[v]) if (!conn1[u]) dfs(u); } void rdfs(ll v) { connN[v] = true; for (auto u : rG[v]) if (!connN[u]) rdfs(u); } int main() { std::cin >> N >> M >> P; rep(i, M) { ll A, B, C; std::cin >> A >> B >> C; --A; --B; es.emplace_back(A, B, P - C); G[A].emplace_back(B); rG[B].emplace_back(A); } dfs(0); rdfs(N - 1); d.assign(N + 10, INF); d[0] = 0; bool upd = true; ll cnt = 0; while (upd) { upd = false; auto ok = [&](ll v) { return conn1[v] && connN[v]; }; for (auto e : es) { if (!ok(e.from)) continue; if (!ok(e.to)) continue; if (d[e.from] != INF && chmin(d[e.to], d[e.from] + e.cost)) upd = true; } ++cnt; if (cnt == N) { std::cout << -1 << std::endl; return 0; } } std::cout << std::max(0ll, -d[N - 1]) << std::endl; return 0; }
#include <algorithm> #include <cassert> #include <cstdio> #include <cstdlib> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define repi(i, a, b) for (ll i = (a); i < (b); ++i) #define rep(i, a) repi(i, 0, a) #define repdi(i, a, b) for (ll i = (a)-1; i >= (b); --i) #define repd(i, a) repdi(i, a, 0) #define itr(it, a) for (auto it = (a).begin(); it != (a).end(); ++it) #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() using ll = long long; constexpr ll INF = 1ll << 60; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class S, class T> std::ostream &operator<<(std::ostream &out, const std::pair<S, T> &a) { std::cout << '(' << a.first << ", " << a.second << ')'; return out; } template <class T> std::ostream &operator<<(std::ostream &out, const std::vector<T> &a) { std::cout << '['; rep(i, a.size()) { std::cout << a[i]; if (i != a.size() - 1) std::cout << ", "; } std::cout << ']'; return out; } struct edge { ll from, to, cost; edge(ll from, ll to, ll cost) : from(from), to(to), cost(cost) {} }; ll N, M, P; std::vector<edge> es; std::vector<ll> d; std::vector<ll> G[3000], rG[3000]; bool conn1[3000], connN[3000]; void dfs(ll v) { conn1[v] = true; for (auto u : G[v]) if (!conn1[u]) dfs(u); } void rdfs(ll v) { connN[v] = true; for (auto u : rG[v]) if (!connN[u]) rdfs(u); } int main() { std::cin >> N >> M >> P; rep(i, M) { ll A, B, C; std::cin >> A >> B >> C; --A; --B; es.emplace_back(A, B, P - C); G[A].emplace_back(B); rG[B].emplace_back(A); } dfs(0); rdfs(N - 1); d.assign(N + 10, INF); d[0] = 0; bool upd = true; ll cnt = 0; while (upd) { upd = false; auto ok = [&](ll v) { return conn1[v] && connN[v]; }; for (auto e : es) { if (!ok(e.from)) continue; if (!ok(e.to)) continue; if (d[e.from] != INF && chmin(d[e.to], d[e.from] + e.cost)) upd = true; } ++cnt; if (cnt > N) { std::cout << -1 << std::endl; return 0; } } std::cout << std::max(0ll, -d[N - 1]) << std::endl; return 0; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
750,674
750,675
u265250376
cpp
p02949
#include <bits/stdc++.h> #define rep(i, x) for (ll i = 0; i < x; i++) #define all(a) (a).begin(), (a).end() using ll = long long; using ld = long double; using namespace std; const ll INF = 1000000000000000000; const ll mod = 1000000007; const ld pi = 3.141592653589793238; bool used1[1 << 18], used2[1 << 18]; //頂点fromから頂点toへのコストcostの辺 struct edge { ll from, to, cost; }; edge es[345678]; //辺 ll d[345678]; //最短距離 // Vは頂点数、Eは辺数 // s番目の頂点から各頂点への最短距離を求める void Bellman_Ford(ll V, ll E, ll s) { for (int i = 0; i <= V; i++) d[i] = INF; d[s] = 0; for (int z = 0; z <= V; z++) { bool flag = false; for (int i = 0; i < E; i++) { edge e = es[i]; if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) { d[e.to] = d[e.from] + e.cost; if (used1[e.to] == true && used2[e.to] == true) { flag = true; } } if (flag == false) { break; } if (z == V) { d[V] = INF; } } } } ll test[12345678], a[1234567], b[1234567], c[1234567]; signed main() { ll n, m, ppp; cin >> n >> m >> ppp; rep(h, m) { cin >> a[h] >> b[h] >> c[h]; c[h] -= ppp; es[h] = {a[h], b[h], 0 - c[h]}; } used1[1] = true; rep(h, n) { rep(i, m) { if (used1[a[i]] == true) { used1[b[i]] = true; } } } used2[n] = true; rep(h, n) { rep(i, m) { if (used2[b[i]] == true) { used2[a[i]] = true; } } } Bellman_Ford(n, m, 1); if (d[n] == INF) { cout << "-1\n"; } else { cout << max((ll)0, 0 - d[n]) << endl; } return 0; }
#include <bits/stdc++.h> #define rep(i, x) for (ll i = 0; i < x; i++) #define all(a) (a).begin(), (a).end() using ll = long long; using ld = long double; using namespace std; const ll INF = 1000000000000000000; const ll mod = 1000000007; const ld pi = 3.141592653589793238; bool used1[1 << 18], used2[1 << 18]; //頂点fromから頂点toへのコストcostの辺 struct edge { ll from, to, cost; }; edge es[345678]; //辺 ll d[345678]; //最短距離 // Vは頂点数、Eは辺数 // s番目の頂点から各頂点への最短距離を求める void Bellman_Ford(ll V, ll E, ll s) { for (int i = 0; i <= V; i++) d[i] = INF; d[s] = 0; for (int z = 0; z <= V; z++) { bool flag = false; for (int i = 0; i < E; i++) { edge e = es[i]; if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) { d[e.to] = d[e.from] + e.cost; if (used1[e.to] == true && used2[e.to] == true) { flag = true; } } } if (flag == false) { break; } if (z == V) { d[V] = INF; break; } } } ll test[12345678], a[1234567], b[1234567], c[1234567]; signed main() { ll n, m, ppp; cin >> n >> m >> ppp; rep(h, m) { cin >> a[h] >> b[h] >> c[h]; c[h] -= ppp; es[h] = {a[h], b[h], 0 - c[h]}; } used1[1] = true; rep(h, n) { rep(i, m) { if (used1[a[i]] == true) { used1[b[i]] = true; } } } used2[n] = true; rep(h, n) { rep(i, m) { if (used2[b[i]] == true) { used2[a[i]] = true; } } } Bellman_Ford(n, m, 1); if (d[n] == INF) { cout << "-1\n"; } else { cout << max((ll)0, 0 - d[n]) << endl; } return 0; }
[]
750,676
750,677
u986568278
cpp
p02949
#include <iostream> #include <queue> #include <utility> #include <vector> using namespace std; int INF = 1000000000; int main() { int N, M, P; cin >> N >> M >> P; vector<vector<pair<int, int>>> E(N); vector<vector<int>> E2(N); for (int i = 0; i < M; i++) { int A, B, C; cin >> A >> B >> C; A--; B--; E[A].push_back(make_pair(C - P, B)); E2[B].push_back(A); } vector<bool> ok(N, false); ok[0] = true; queue<int> Q; Q.push(0); while (!Q.empty()) { int v = Q.front(); Q.pop(); for (auto P : E[v]) { int w = P.second; if (!ok[w]) { ok[w] = true; Q.push(w); } } } vector<bool> ok2(N, false); ok2[N - 1] = true; queue<int> Q2; Q2.push(N - 1); while (!Q2.empty()) { int v = Q2.front(); Q2.pop(); for (int w : E2[v]) { if (!ok2[w]) { ok2[w] = true; Q2.push(w); } } } vector<int> d(N, -INF); d[0] = 0; bool inf = false; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { for (auto P : E[j]) { int c = P.first; int w = P.second; if (d[w] < d[j] + c) { d[w] = d[j] + c; if (i == N - 1 && ok[w] && ok2[w]) { inf = true; } } } } } if (inf) { cout << -1 << endl; } else { cout << d[N - 1] << endl; } }
#include <iostream> #include <queue> #include <utility> #include <vector> using namespace std; int INF = 1000000000; int main() { int N, M, P; cin >> N >> M >> P; vector<vector<pair<int, int>>> E(N); vector<vector<int>> E2(N); for (int i = 0; i < M; i++) { int A, B, C; cin >> A >> B >> C; A--; B--; E[A].push_back(make_pair(C - P, B)); E2[B].push_back(A); } vector<bool> ok(N, false); ok[0] = true; queue<int> Q; Q.push(0); while (!Q.empty()) { int v = Q.front(); Q.pop(); for (auto P : E[v]) { int w = P.second; if (!ok[w]) { ok[w] = true; Q.push(w); } } } vector<bool> ok2(N, false); ok2[N - 1] = true; queue<int> Q2; Q2.push(N - 1); while (!Q2.empty()) { int v = Q2.front(); Q2.pop(); for (int w : E2[v]) { if (!ok2[w]) { ok2[w] = true; Q2.push(w); } } } vector<int> d(N, -INF); d[0] = 0; bool inf = false; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { for (auto P : E[j]) { int c = P.first; int w = P.second; if (d[w] < d[j] + c) { d[w] = d[j] + c; if (i == N - 1 && ok[w] && ok2[w]) { inf = true; } } } } } if (inf) { cout << -1 << endl; } else { cout << max(d[N - 1], 0) << endl; } }
[ "call.add", "call.arguments.add" ]
750,680
750,681
u424374375
cpp
p02949
#include "bits/stdc++.h" #define MOD 1000000007 #define rep(i, n) for (ll i = 0; i < (n); i++) #define rrep(i, n) for (ll i = (n)-1; i >= 0; i--) #define ALL(v) v.begin(), v.end() #define rALL(v) v.rbegin(), v.rend() #define FOR(i, j, k) for (ll i = j; i < k; i++) #define debug_print(var) cerr << #var << "=" << var << endl; #define DUMP(i, v) \ for (ll i = 0; i < v.size(); i++) \ cerr << v[i] << " " using namespace std; typedef long long int ll; typedef vector<ll> llvec; typedef vector<double> dvec; typedef pair<ll, ll> P; typedef long double ld; struct edge { ll x, c; }; struct edge2 { ll f, t, c; }; ll mod(ll a, ll mod) { ll res = a % mod; if (res < 0) res = res + mod; return res; } ll modpow(ll a, ll n, ll mod) { ll res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } ll modinv(ll a, ll mod) { return modpow(a, mod - 2, mod); } ll gcd(ll a, ll b) { ll r = a % b; if (r == 0) return b; else return gcd(b, a % b); } bool is_prime(ll n) { ll i = 2; if (n == 1) return false; if (n == 2) return true; bool res = true; while (i * i < n) { if (n % i == 0) { res = false; } i = i + 1; } // if(i==1)res = false; if (n % i == 0) res = false; return res; } struct UnionFind { ll N; llvec p; llvec cnt; UnionFind(ll n) { N = n; p = llvec(N); cnt = llvec(N, 0); rep(i, N) { p[i] = i; cnt[i] = 1; } } void con(ll a, ll b) { P at = root(a); P bt = root(b); if (at.second != bt.second) { if (at.first > bt.first) { swap(at, bt); swap(a, b); } p[at.second] = bt.second; cnt[bt.second] += cnt[at.second]; p[a] = bt.second; } } P root(ll a) { ll atmp = a; ll c = 0; while (atmp != p[atmp]) { atmp = p[atmp]; c++; } p[a] = atmp; return {c, atmp}; } bool is_con(ll a, ll b) { P at = root(a); P bt = root(b); return at.second == bt.second; } }; struct dijkstra { ll N; llvec d; vector<vector<edge>> e; dijkstra(ll n) { N = n; // d = llvec(N, 1e18); e = vector<vector<edge>>(N); } void add_edge(ll from, ll to, ll cost) { e[from].push_back({to, cost}); } void run(ll start) { priority_queue<P, vector<P>, greater<P>> que; que.push({0, start}); d = llvec(N, 1e18); d[start] = 0; while (!que.empty()) { P q = que.top(); que.pop(); ll dc = q.first; ll x = q.second; if (dc > d[x]) { continue; } else { for (auto ip : e[x]) { if (d[ip.x] <= d[x] + ip.c) { continue; } else { d[ip.x] = d[x] + ip.c; que.push({d[ip.x], ip.x}); } } } } } }; /************************************** ** A main function starts from here ** ***************************************/ int main() { ll N, M, P; cin >> N >> M >> P; vector<edge2> e(M); rep(i, M) { ll a, b, c; cin >> a >> b >> c; a--; b--; e[i] = {a, b, P - c}; } llvec d(N, 1e18); d[0] = 0; ll cnt = 0; while (true) { if (cnt > N - 1) break; bool update = false; rep(j, M) { auto e2 = e[j]; if (d[e2.f] == 1e18) continue; if (d[e2.t] > d[e2.f] + e2.c) { d[e2.t] = d[e2.f] + e2.c; update = true; } } if (!update) break; cnt++; } ll ans = d[N - 1]; vector<bool> loop(N, false); rep(k, N) { rep(j, M) { auto e2 = e[j]; if (d[e2.f] == 1e18) continue; if (d[e2.t] > d[e2.f] + e2.c) { d[e2.t] = -1e18; loop[e2.t] = true; } if (loop[e2.f]) loop[e2.t] = true; } } if (d[N - 1]) { cout << -1; } else { cout << max(-ans, 0LL); } return 0; }
#include "bits/stdc++.h" #define MOD 1000000007 #define rep(i, n) for (ll i = 0; i < (n); i++) #define rrep(i, n) for (ll i = (n)-1; i >= 0; i--) #define ALL(v) v.begin(), v.end() #define rALL(v) v.rbegin(), v.rend() #define FOR(i, j, k) for (ll i = j; i < k; i++) #define debug_print(var) cerr << #var << "=" << var << endl; #define DUMP(i, v) \ for (ll i = 0; i < v.size(); i++) \ cerr << v[i] << " " using namespace std; typedef long long int ll; typedef vector<ll> llvec; typedef vector<double> dvec; typedef pair<ll, ll> P; typedef long double ld; struct edge { ll x, c; }; struct edge2 { ll f, t, c; }; ll mod(ll a, ll mod) { ll res = a % mod; if (res < 0) res = res + mod; return res; } ll modpow(ll a, ll n, ll mod) { ll res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } ll modinv(ll a, ll mod) { return modpow(a, mod - 2, mod); } ll gcd(ll a, ll b) { ll r = a % b; if (r == 0) return b; else return gcd(b, a % b); } bool is_prime(ll n) { ll i = 2; if (n == 1) return false; if (n == 2) return true; bool res = true; while (i * i < n) { if (n % i == 0) { res = false; } i = i + 1; } // if(i==1)res = false; if (n % i == 0) res = false; return res; } struct UnionFind { ll N; llvec p; llvec cnt; UnionFind(ll n) { N = n; p = llvec(N); cnt = llvec(N, 0); rep(i, N) { p[i] = i; cnt[i] = 1; } } void con(ll a, ll b) { P at = root(a); P bt = root(b); if (at.second != bt.second) { if (at.first > bt.first) { swap(at, bt); swap(a, b); } p[at.second] = bt.second; cnt[bt.second] += cnt[at.second]; p[a] = bt.second; } } P root(ll a) { ll atmp = a; ll c = 0; while (atmp != p[atmp]) { atmp = p[atmp]; c++; } p[a] = atmp; return {c, atmp}; } bool is_con(ll a, ll b) { P at = root(a); P bt = root(b); return at.second == bt.second; } }; struct dijkstra { ll N; llvec d; vector<vector<edge>> e; dijkstra(ll n) { N = n; // d = llvec(N, 1e18); e = vector<vector<edge>>(N); } void add_edge(ll from, ll to, ll cost) { e[from].push_back({to, cost}); } void run(ll start) { priority_queue<P, vector<P>, greater<P>> que; que.push({0, start}); d = llvec(N, 1e18); d[start] = 0; while (!que.empty()) { P q = que.top(); que.pop(); ll dc = q.first; ll x = q.second; if (dc > d[x]) { continue; } else { for (auto ip : e[x]) { if (d[ip.x] <= d[x] + ip.c) { continue; } else { d[ip.x] = d[x] + ip.c; que.push({d[ip.x], ip.x}); } } } } } }; /************************************** ** A main function starts from here ** ***************************************/ int main() { ll N, M, P; cin >> N >> M >> P; vector<edge2> e(M); rep(i, M) { ll a, b, c; cin >> a >> b >> c; a--; b--; e[i] = {a, b, P - c}; } llvec d(N, 1e18); d[0] = 0; ll cnt = 0; while (true) { if (cnt > N - 1) break; bool update = false; rep(j, M) { auto e2 = e[j]; if (d[e2.f] == 1e18) continue; if (d[e2.t] > d[e2.f] + e2.c) { d[e2.t] = d[e2.f] + e2.c; update = true; } } if (!update) break; cnt++; } ll ans = d[N - 1]; vector<bool> loop(N, false); rep(k, N) { rep(j, M) { auto e2 = e[j]; if (d[e2.f] == 1e18) continue; if (d[e2.t] > d[e2.f] + e2.c) { d[e2.t] = -1e18; loop[e2.t] = true; } if (loop[e2.f]) loop[e2.t] = true; } } if (loop[N - 1]) { cout << -1; } else { cout << max(-ans, 0LL); } return 0; }
[ "identifier.change", "control_flow.branch.if.condition.change" ]
750,706
750,707
u225053756
cpp
p02949
/* * atcoder/abc137/e.cpp */ // C++ 14 #include <algorithm> #include <cassert> #include <cmath> #include <cstring> // memset #include <iostream> #include <tuple> #include <vector> using namespace std; #define ll long long #define loop(__x, __start, __end) for (int __x = __start; __x < __end; __x++) template <class T> ostream &operator<<(ostream &out, vector<T> const &v) { for (auto &&a : v) out << a << " "; out << endl; return out; } template <class T> void dump(T &a) { cout << a << endl; } void solve(); int main() { solve(); return 0; } /* * 1. 0から到達不可能な頂点を削除 * 2. N-1へ到達不可能な頂点を削除 * 3. 削除後のグラフに対してベルマンフォード * 4. */ const int MAX = 2500; const int INF = 1010101010; int n, m, p; int G[MAX][MAX]; bool from1[MAX] = {0}; bool toN[MAX] = {0}; void dfs1(int v) { if (from1[v]) return; from1[v] = true; int a, b, c; for (int i = 0; i < n; i++) { if (G[v][i] == INF) continue; dfs1(i); } } void dfsN(int v) { if (toN[v]) return; toN[v] = true; int a, b, c; for (int i = 0; i < n; i++) { if (G[i][v] == INF) continue; dfsN(i); } } template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } void solve() { int a, b, c; cin >> n >> m >> p; loop(i, 0, MAX) loop(j, 0, MAX) G[i][j] = INF; loop(i, 0, m) { cin >> a >> b >> c; G[--a][--b] = -(c - p); } dfs1(0); dfsN(n - 1); vector<tuple<int, int, int>> E; loop(i, 0, n) loop(j, 0, n) { if (from1[i] and toN[j] and from1[j] and toN[i]) { if (G[i][j] == INF) continue; E.emplace_back(i, j, G[i][j]); } } // bellman-ford vector<int> D(n, INF); D[0] = 0; loop(count, 0, n) { for (auto &&e : E) { tie(a, b, c) = e; if (D[a] == INF) continue; if (chmin(D[b], D[a] + c) and count == n - 1) { cout << -1 << endl; return; } } } cout << max(0, D[n - 1] * -1) << endl; }
/* * atcoder/abc137/e.cpp */ // C++ 14 #include <algorithm> #include <cassert> #include <cmath> #include <cstring> // memset #include <iostream> #include <tuple> #include <vector> using namespace std; #define ll long long #define loop(__x, __start, __end) for (int __x = __start; __x < __end; __x++) template <class T> ostream &operator<<(ostream &out, vector<T> const &v) { for (auto &&a : v) out << a << " "; out << endl; return out; } template <class T> void dump(T &a) { cout << a << endl; } void solve(); int main() { solve(); return 0; } /* * 1. 0から到達不可能な頂点を削除 * 2. N-1へ到達不可能な頂点を削除 * 3. 削除後のグラフに対してベルマンフォード * 4. */ const int MAX = 2500; const int INF = 1010101010; int n, m, p; int G[MAX][MAX]; bool from1[MAX] = {0}; bool toN[MAX] = {0}; void dfs1(int v) { if (from1[v]) return; from1[v] = true; int a, b, c; for (int i = 0; i < n; i++) { if (G[v][i] == INF) continue; dfs1(i); } } void dfsN(int v) { if (toN[v]) return; toN[v] = true; int a, b, c; for (int i = 0; i < n; i++) { if (G[i][v] == INF) continue; dfsN(i); } } template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } void solve() { int a, b, c; cin >> n >> m >> p; loop(i, 0, MAX) loop(j, 0, MAX) G[i][j] = INF; loop(i, 0, m) { cin >> a >> b >> c; chmin(G[--a][--b], -(c - p)); } dfs1(0); dfsN(n - 1); vector<tuple<int, int, int>> E; loop(i, 0, n) loop(j, 0, n) { if (from1[i] and toN[j] and from1[j] and toN[i]) { if (G[i][j] == INF) continue; E.emplace_back(i, j, G[i][j]); } } // for (auto&&e: E) { // tie(a, b, c) = e; // cout << a << " " << b << " " << c << endl; // } // bellman-ford vector<int> D(n, INF); D[0] = 0; loop(count, 0, n) { for (auto &&e : E) { tie(a, b, c) = e; if (D[a] == INF) continue; if (chmin(D[b], D[a] + c) and count == n - 1) { cout << -1 << endl; return; } } } cout << max(0, D[n - 1] * -1) << endl; }
[ "call.add", "call.arguments.change" ]
750,708
750,709
u823862638
cpp
p02949
#include <bits/stdc++.h> #define _overload(_1, _2, _3, name, ...) name #define _rep(i, n) _range(i, 0, n) #define _range(i, a, b) for (int i = (int)(a); i < (int)(b); ++i) #define rep(...) _overload(__VA_ARGS__, _range, _rep, )(__VA_ARGS__) #define _rrep(i, n) _rrange(i, n, 0) #define _rrange(i, a, b) for (int i = (int)(a)-1; i >= (int)(b); --i) #define rrep(...) _overload(__VA_ARGS__, _rrange, _rrep, )(__VA_ARGS__) #define _all(arg) begin(arg), end(arg) #define uniq(arg) sort(_all(arg)), (arg).erase(unique(_all(arg)), end(arg)) #define bit(n) (1LL << (n)) // #define DEBUG #ifdef DEBUG #define dump(...) fprintf(stderr, __VA_ARGS__) #else #define dump(...) #endif template <class T> bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0; } template <class T> bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0; } using namespace std; using ll = long long; using vi = vector<int>; using vll = vector<ll>; const double EPS = 1e-10; const double PI = acos(-1.0); const int inf = INT_MAX; const ll INF = LLONG_MAX; const ll MOD = 1000000007LL; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; ll extgcd(ll a, ll b, ll &x, ll &y) { x = 1, y = 0; ll g = a; if (b != 0) g = extgcd(b, a % b, y, x), y -= a / b * x; return g; } ll ADD(const ll &a, const ll &b, const ll mod = MOD) { return (a + b) % mod; } ll SUB(const ll &a, const ll &b, const ll mod = MOD) { return (a - b + mod) % mod; } ll MUL(const ll &a, const ll &b, const ll mod = MOD) { return (1LL * a * b) % mod; } ll DIV(const ll &a, const ll &b, const ll mod = MOD) { ll x, y; extgcd(b, mod, x, y); return MUL(a, (x + mod) % mod, mod); } int n, start; // to, cost using Edge = tuple<int, int>; vector<vector<Edge>> G; vi active; vll dist; bool bellman_ford() { dist = vll(n, INF); dist[start] = 0; rep(loop, n) { rep(v, n) { if (dist[v] == INF) continue; for (auto &e : G[v]) { int nv, cost; tie(nv, cost) = e; if (not active[nv]) continue; if (dist[nv] > dist[v] + cost) { dist[nv] = min(dist[nv], dist[v] + cost); if (loop == n - 1) return true; } } } } return false; } void dfs(vi &used, vector<vi> &T, int v) { if (used[v]) return; used[v] = true; for (auto &nv : T[v]) { dfs(used, T, nv); } } vi calc(vector<vi> &T, int sv) { vi used(n); dfs(used, T, sv); return used; } int main(void) { cin.tie(0); ios::sync_with_stdio(false); int m, P; cin >> n >> m >> P; start = 0; G = vector<vector<Edge>>(n); vector<vi> T1(n); vector<vi> T2(n); rep(_, m) { int a, b, c; cin >> a >> b >> c; a--, b--; G[a].push_back(Edge(b, -(c - P))); T1[a].push_back(b); T2[b].push_back(a); } vi used1 = calc(T1, 0); vi used2 = calc(T1, n - 1); active = vi(n); rep(i, n) { active[i] = (used1[i] & used2[i]); } int res = (bellman_ford() ? -1LL : max(0LL, -dist[n - 1])); cout << res << endl; return 0; }
#include <bits/stdc++.h> #define _overload(_1, _2, _3, name, ...) name #define _rep(i, n) _range(i, 0, n) #define _range(i, a, b) for (int i = (int)(a); i < (int)(b); ++i) #define rep(...) _overload(__VA_ARGS__, _range, _rep, )(__VA_ARGS__) #define _rrep(i, n) _rrange(i, n, 0) #define _rrange(i, a, b) for (int i = (int)(a)-1; i >= (int)(b); --i) #define rrep(...) _overload(__VA_ARGS__, _rrange, _rrep, )(__VA_ARGS__) #define _all(arg) begin(arg), end(arg) #define uniq(arg) sort(_all(arg)), (arg).erase(unique(_all(arg)), end(arg)) #define bit(n) (1LL << (n)) // #define DEBUG #ifdef DEBUG #define dump(...) fprintf(stderr, __VA_ARGS__) #else #define dump(...) #endif template <class T> bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0; } template <class T> bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0; } using namespace std; using ll = long long; using vi = vector<int>; using vll = vector<ll>; const double EPS = 1e-10; const double PI = acos(-1.0); const int inf = INT_MAX; const ll INF = LLONG_MAX; const ll MOD = 1000000007LL; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; ll extgcd(ll a, ll b, ll &x, ll &y) { x = 1, y = 0; ll g = a; if (b != 0) g = extgcd(b, a % b, y, x), y -= a / b * x; return g; } ll ADD(const ll &a, const ll &b, const ll mod = MOD) { return (a + b) % mod; } ll SUB(const ll &a, const ll &b, const ll mod = MOD) { return (a - b + mod) % mod; } ll MUL(const ll &a, const ll &b, const ll mod = MOD) { return (1LL * a * b) % mod; } ll DIV(const ll &a, const ll &b, const ll mod = MOD) { ll x, y; extgcd(b, mod, x, y); return MUL(a, (x + mod) % mod, mod); } int n, start; // to, cost using Edge = tuple<int, int>; vector<vector<Edge>> G; vi active; vll dist; bool bellman_ford() { dist = vll(n, INF); dist[start] = 0; rep(loop, n) { rep(v, n) { if (dist[v] == INF) continue; for (auto &e : G[v]) { int nv, cost; tie(nv, cost) = e; if (not active[nv]) continue; if (dist[nv] > dist[v] + cost) { dist[nv] = min(dist[nv], dist[v] + cost); if (loop == n - 1) return true; } } } } return false; } void dfs(vi &used, vector<vi> &T, int v) { if (used[v]) return; used[v] = true; for (auto &nv : T[v]) { dfs(used, T, nv); } } vi calc(vector<vi> &T, int sv) { vi used(n); dfs(used, T, sv); return used; } int main(void) { cin.tie(0); ios::sync_with_stdio(false); int m, P; cin >> n >> m >> P; start = 0; G = vector<vector<Edge>>(n); vector<vi> T1(n); vector<vi> T2(n); rep(_, m) { int a, b, c; cin >> a >> b >> c; a--, b--; G[a].push_back(Edge(b, -(c - P))); T1[a].push_back(b); T2[b].push_back(a); } vi used1 = calc(T1, 0); vi used2 = calc(T2, n - 1); active = vi(n); rep(i, n) { active[i] = (used1[i] & used2[i]); } int res = (bellman_ford() ? -1LL : max(0LL, -dist[n - 1])); cout << res << endl; return 0; }
[ "identifier.change", "call.arguments.change" ]
750,714
750,715
u704625420
cpp
p02949
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define F first #define S second #define pii pair<int, int> #define pli pair<ll, int> #define pil pair<int, ll> #define pll pair<ll, ll> #define eb emplace_back #define all(v) v.begin(), v.end() #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep3(i, l, n) for (int i = l; i < (n); ++i) #define sz(v) (int)v.size() #define endl '\n' const int inf = 1000000007; const ll INF = 1e18; int mod = 998244353; // int mod = 1000000007; #define abs(x) (x >= 0 ? x : -(x)) #define lb(v, x) (int)(lower_bound(all(v), x) - v.begin()) #define ub(v, x) (int)(upper_bound(all(v), x) - v.begin()) template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; } template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } template <typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; } ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; } template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << p.F << " " << p.S; return os; } template <class T> ostream &operator<<(ostream &os, const vector<T> &vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; } template <typename T> inline istream &operator>>(istream &is, vector<T> &v) { rep(j, sz(v)) is >> v[j]; return is; } template <class T, class T2> inline void add(T &a, T2 b) { a += b; if (a >= mod) a -= mod; } template <class T> void operator+=(vector<T> &v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); } void solve(); int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout << fixed << setprecision(11); int T; T = 1; while (T--) solve(); } void solve() { int n, m; cin >> n >> m; int p; cin >> p; vector<vector<pil>> G(n), G2(n); rep(i, m) { int a, b, c; cin >> a >> b >> c; a--; b--; G[a].eb(b, p - c); G2[b].eb(a, 1); } vector<int> c(n); auto dfs = [&](auto &&dfs, int v, int be) -> void { c[v] = 1; // debuged, for の外 for (pil p : G2[v]) { if (c[p.F]) continue; // debuged, p.F==be to c[p.F] dfs(dfs, p.F, v); } }; dfs(dfs, n - 1, -1); // cerr << c << endl; vector<ll> d(n, INF); auto bell = [&](int s) { // O(NM) d[s] = 0; int cnt = 0; while (1) { int update = 0; rep(v, n) { // O(M) if (d[v] == INF || c[v] == 0) continue; for (pil p : G[v]) if (c[p.F] == 1 && chmin(d[p.F], d[v] + p.S)) update = 1; } if (update == 0) break; if (cnt++ == 2 * n) return 1; // 負閉路検出 } return 0; }; if (bell(0)) cout << -1 << endl; cout << max(0LL, -d[n - 1]) << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define F first #define S second #define pii pair<int, int> #define pli pair<ll, int> #define pil pair<int, ll> #define pll pair<ll, ll> #define eb emplace_back #define all(v) v.begin(), v.end() #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep3(i, l, n) for (int i = l; i < (n); ++i) #define sz(v) (int)v.size() #define endl '\n' const int inf = 1000000007; const ll INF = 1e18; int mod = 998244353; // int mod = 1000000007; #define abs(x) (x >= 0 ? x : -(x)) #define lb(v, x) (int)(lower_bound(all(v), x) - v.begin()) #define ub(v, x) (int)(upper_bound(all(v), x) - v.begin()) template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; } template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } template <typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; } ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; } template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << p.F << " " << p.S; return os; } template <class T> ostream &operator<<(ostream &os, const vector<T> &vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; } template <typename T> inline istream &operator>>(istream &is, vector<T> &v) { rep(j, sz(v)) is >> v[j]; return is; } template <class T, class T2> inline void add(T &a, T2 b) { a += b; if (a >= mod) a -= mod; } template <class T> void operator+=(vector<T> &v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); } void solve(); int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout << fixed << setprecision(11); int T; T = 1; while (T--) solve(); } void solve() { int n, m; cin >> n >> m; int p; cin >> p; vector<vector<pil>> G(n), G2(n); rep(i, m) { int a, b, c; cin >> a >> b >> c; a--; b--; G[a].eb(b, p - c); G2[b].eb(a, 1); } vector<int> c(n); auto dfs = [&](auto &&dfs, int v, int be) -> void { c[v] = 1; // debuged, for の外 for (pil p : G2[v]) { if (c[p.F]) continue; // debuged, p.F==be to c[p.F] dfs(dfs, p.F, v); } }; dfs(dfs, n - 1, -1); // cerr << c << endl; vector<ll> d(n, INF); auto bell = [&](int s) { // O(NM) d[s] = 0; int cnt = 0; while (1) { int update = 0; rep(v, n) { // O(M) if (d[v] == INF || c[v] == 0) continue; for (pil p : G[v]) if (c[p.F] == 1 && chmin(d[p.F], d[v] + p.S)) update = 1; } if (update == 0) break; if (cnt++ == 2 * n) return 1; // 負閉路検出 } return 0; }; if (bell(0)) cout << -1 << endl; else cout << max(0LL, -d[n - 1]) << endl; // debuged, forget else }
[ "control_flow.branch.else_if.replace.remove", "control_flow.branch.if.replace.add" ]
750,716
750,717
u277556971
cpp
p02949
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define F first #define S second #define pii pair<int, int> #define eb emplace_back #define all(v) v.begin(), v.end() #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep3(i, l, n) for (int i = l; i < (n); ++i) #define sz(v) (int)v.size() const int inf = 1e9 + 7; const ll INF = 1e18; const int mod = 1000000007; #define abs(x) (x >= 0 ? x : -(x)) #define lb(v, x) (int)(lower_bound(all(v), x) - v.begin()) #define ub(v, x) (int)(upper_bound(all(v), x) - v.begin()) template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; } template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; } template <typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); } template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } template <typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; } ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; } template <class T> ostream &operator<<(ostream &os, const vector<T> &vec) { for (auto &vi : vec) os << vi << " "; return os; } template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << p.F << " " << p.S; return os; } template <typename T> inline istream &operator>>(istream &is, vector<T> &v) { rep(j, sz(v)) is >> v[j]; return is; } template <class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; } void solve(); int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout << fixed << setprecision(10); int T; // cin >> T; T = 1; while (T--) { solve(); } } int n; const int N = 2501; vector<ll> d(N, INF); using pil = pair<int, ll>; vector<vector<pil>> G(N); int flg; void bell(int s) { d[s] = 0; int cnt = 0; while (1) { int update = 0; rep(v, n) { if (d[v] == INF) continue; for (pil p : G[v]) { int nv = p.F; ll cost = p.S; if (chmin(d[nv], d[v] + cost)) { update = 1; } } } if (update == 0) break; cnt++; if (cnt == 2 * n) { flg = 1; return; } } } vector<int> reached(N); void dfs(int v) { for (pil p : G[v]) { int nv = p.F; if (reached[nv]) continue; reached[nv] = 1; dfs(nv); } } void solve() { int m, p; cin >> n >> m >> p; d.resize(n); vector<tuple<int, int, int>> v(m); rep(i, m) { int a, b, c; cin >> a >> b >> c; a--; b--; G[b].eb(a, 1); v[i] = make_tuple(a, b, c); } // まずは, ゴールにいけないとこ潰す reached.resize(n); dfs(n - 1); // cout << reached << endl; reached[n - 1] = 1; // debuged rep(i, n) G[i].clear(); // debuged, G.clear(); error rep(i, m) { int a, b, c; tie(a, b, c) = v[i]; if (reached[a] == 0 || reached[b] == 0) continue; G[a].eb(b, p - c); } // rep(i, n) { for (pil p : G[i]) { int j = p.F; cout << j << " "; } cout << // endl; } d[0] = 0; bell(0); // cout << d << endl; if (flg) { cout << -1 << endl; return; } // cout << -*min_element(all(d)) << endl; cout << -d[n - 1] << endl; // debuged }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define F first #define S second #define pii pair<int, int> #define eb emplace_back #define all(v) v.begin(), v.end() #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep3(i, l, n) for (int i = l; i < (n); ++i) #define sz(v) (int)v.size() const int inf = 1e9 + 7; const ll INF = 1e18; const int mod = 1000000007; #define abs(x) (x >= 0 ? x : -(x)) #define lb(v, x) (int)(lower_bound(all(v), x) - v.begin()) #define ub(v, x) (int)(upper_bound(all(v), x) - v.begin()) template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; } template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; } template <typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); } template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } template <typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; } ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; } template <class T> ostream &operator<<(ostream &os, const vector<T> &vec) { for (auto &vi : vec) os << vi << " "; return os; } template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << p.F << " " << p.S; return os; } template <typename T> inline istream &operator>>(istream &is, vector<T> &v) { rep(j, sz(v)) is >> v[j]; return is; } template <class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; } void solve(); int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout << fixed << setprecision(10); int T; // cin >> T; T = 1; while (T--) { solve(); } } int n; const int N = 2501; vector<ll> d(N, INF); using pil = pair<int, ll>; vector<vector<pil>> G(N); int flg; void bell(int s) { d[s] = 0; int cnt = 0; while (1) { int update = 0; rep(v, n) { if (d[v] == INF) continue; for (pil p : G[v]) { int nv = p.F; ll cost = p.S; if (chmin(d[nv], d[v] + cost)) { update = 1; } } } if (update == 0) break; cnt++; if (cnt == 2 * n) { flg = 1; return; } } } vector<int> reached(N); void dfs(int v) { for (pil p : G[v]) { int nv = p.F; if (reached[nv]) continue; reached[nv] = 1; dfs(nv); } } void solve() { int m, p; cin >> n >> m >> p; d.resize(n); vector<tuple<int, int, int>> v(m); rep(i, m) { int a, b, c; cin >> a >> b >> c; a--; b--; G[b].eb(a, 1); v[i] = make_tuple(a, b, c); } // まずは, ゴールにいけないとこ潰す reached.resize(n); dfs(n - 1); // cout << reached << endl; reached[n - 1] = 1; // debuged rep(i, n) G[i].clear(); // debuged, G.clear(); error rep(i, m) { int a, b, c; tie(a, b, c) = v[i]; if (reached[a] == 0 || reached[b] == 0) continue; G[a].eb(b, p - c); } // rep(i, n) { for (pil p : G[i]) { int j = p.F; cout << j << " "; } cout << // endl; } d[0] = 0; bell(0); // cout << d << endl; if (flg) { cout << -1 << endl; return; } // cout << -*min_element(all(d)) << endl; cout << max(0LL, -d[n - 1]) << endl; // debuged }
[ "call.add", "call.arguments.change" ]
750,718
750,719
u277556971
cpp
p02949
#include <bits/stdc++.h> using namespace std; #define FOR(i, l, r) for (long long i = (l); i < (r); ++i) #define REP(i, n) FOR(i, 0, n) #define REPS(i, n) FOR(i, 1, n + 1) #define RFOR(i, l, r) for (long long i = (l); i >= (r); --i) #define RREP(i, n) RFOR(i, n - 1, 0) #define RREPS(i, n) RFOR(i, n, 1) #define int long long #define mp make_pair #define pb push_back #define eb emplace_back #define SZ(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } const int INF = 1e18; const int MOD = 1e9 + 7; const int MAX_M = 5000; const int MAX_V = 2500; struct edge { int from, to, cost; }; edge es[MAX_M]; int d[MAX_V]; bool eused[MAX_M]; int v, e, p; int co = 0; void dfs(int x) { REP(i, e) { if (eused[i]) continue; if (es[i].to == x) { eused[i] = true; dfs(es[i].to); } } } void shortest_path() { REP(i, v) d[i] = INF; d[0] = 0; while (true) { bool update = false; co++; if (co > 2 * v) break; REP(i, e) { if (!eused[i]) continue; edge z = es[i]; if (d[z.from] != INF && d[z.to] > d[z.from] + z.cost) { d[z.to] = d[z.from] + z.cost; update = true; } } if (!update) break; } } void solve() { cin >> v >> e >> p; REP(i, e) eused[i] = false; REP(i, e) { int a, b, c; cin >> a >> b >> c; a--; b--; c = p - c; es[i] = {a, b, c}; } dfs(v - 1); shortest_path(); if (co > 2 * v) { cout << -1 << endl; return; } cout << (d[v - 1] != INF ? max(0ll, d[v - 1] * (-1)) : -1) << endl; } signed main() { solve(); }
#include <bits/stdc++.h> using namespace std; #define FOR(i, l, r) for (long long i = (l); i < (r); ++i) #define REP(i, n) FOR(i, 0, n) #define REPS(i, n) FOR(i, 1, n + 1) #define RFOR(i, l, r) for (long long i = (l); i >= (r); --i) #define RREP(i, n) RFOR(i, n - 1, 0) #define RREPS(i, n) RFOR(i, n, 1) #define int long long #define mp make_pair #define pb push_back #define eb emplace_back #define SZ(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } const int INF = 1e18; const int MOD = 1e9 + 7; const int MAX_M = 5000; const int MAX_V = 2500; struct edge { int from, to, cost; }; edge es[MAX_M]; int d[MAX_V]; bool eused[MAX_M]; int v, e, p; int co = 0; void dfs(int x) { REP(i, e) { if (eused[i]) continue; if (es[i].to == x) { eused[i] = true; dfs(es[i].from); } } } void shortest_path() { REP(i, v) d[i] = INF; d[0] = 0; while (true) { bool update = false; co++; if (co > 2 * v) break; REP(i, e) { if (!eused[i]) continue; edge z = es[i]; if (d[z.from] != INF && d[z.to] > d[z.from] + z.cost) { d[z.to] = d[z.from] + z.cost; update = true; } } if (!update) break; } } void solve() { cin >> v >> e >> p; REP(i, e) eused[i] = false; REP(i, e) { int a, b, c; cin >> a >> b >> c; a--; b--; c = p - c; es[i] = {a, b, c}; } dfs(v - 1); shortest_path(); if (co > 2 * v) { cout << -1 << endl; return; } cout << (d[v - 1] != INF ? max(0ll, d[v - 1] * (-1)) : -1) << endl; } signed main() { solve(); }
[ "call.arguments.change" ]
750,729
750,730
u342075214
cpp
p02949
#include "bits/stdc++.h" using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; using vl = vector<ll>; using vvi = vector<vi>; using vvl = vector<vl>; const ll INF = 1LL << 60; const ll MOD = 1000000007; template <class T> bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0; } template <class T> bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0; } template <class C> void print(const C &c, std::ostream &os = std::cout) { std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " ")); os << std::endl; } template <typename T> // T : type of cost struct BellmanFord { T inf = numeric_limits<T>::max(); // initial value, reused when clear() is called int n; // number of nodes vector<T> dist; // distance from start node bool negativeLoop; struct edge { int from, to; T cost; edge(int from, int to, T cost) : from(from), to(to), cost(cost) {} }; vector<edge> edges; BellmanFord(int n) : n(n), negativeLoop(false), dist(n, inf){}; // 0-indexed! void addEdge(int from, int to, T cost) { edges.emplace_back(from, to, cost); } // calculate dist[i] as a shortest distance from start (to end) // end is used to check if there is "relevant" negative circuit // even if there is negative curcuit, it might not affect the path of interest void build(int start, int end = -1) { dist[start] = 0; for (int i = 0; i < n; ++i) { for (auto &e : edges) { if (dist[e.from] != inf && dist[e.to] > dist[e.from] + e.cost) { dist[e.to] = dist[e.from] + e.cost; if (i == n - 1 && (end == -1 || end == e.to)) { negativeLoop = true; break; } } } } } }; int main() { ll n, m, p; cin >> n >> m >> p; BellmanFord<ll> graph(n); vl a(m), b(m), c(m); for (int i = 0; i < m; ++i) { cin >> a[i] >> b[i] >> c[i]; a[i]--; b[i]--; graph.addEdge(a[i], b[i], p - c[i]); } graph.build(0, n - 1); if (graph.negativeLoop) { cout << -1 << "\n"; return 0; } BellmanFord<ll> graph2(n); for (int i = 0; i < m; ++i) { graph2.addEdge(a[i], b[i], p - c[i]); } graph2.build(n - 1, n - 1); if (graph2.negativeLoop) { cout << -1 << "\n"; } else { cout << max(0LL, -graph.dist[n - 1] - graph2.dist[n - 1]) << "\n"; } return 0; }
#include "bits/stdc++.h" using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; using vl = vector<ll>; using vvi = vector<vi>; using vvl = vector<vl>; const ll INF = 1LL << 60; const ll MOD = 1000000007; template <class T> bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0; } template <class T> bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0; } template <class C> void print(const C &c, std::ostream &os = std::cout) { std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " ")); os << std::endl; } template <typename T> // T : type of cost struct BellmanFord { T inf = numeric_limits<T>::max(); // initial value, reused when clear() is called int n; // number of nodes vector<T> dist; // distance from start node bool negativeLoop; struct edge { int from, to; T cost; edge(int from, int to, T cost) : from(from), to(to), cost(cost) {} }; vector<edge> edges; BellmanFord(int n) : n(n), negativeLoop(false), dist(n, inf){}; // 0-indexed! void addEdge(int from, int to, T cost) { edges.emplace_back(from, to, cost); } // calculate dist[i] as a shortest distance from start (to end) // end is used to check if there is "relevant" negative circuit // even if there is negative curcuit, it might not affect the path of interest void build(int start, int end = -1) { dist[start] = 0; for (int i = 0; i <= 2 * n; ++i) { for (auto &e : edges) { if (dist[e.from] != inf && dist[e.to] > dist[e.from] + e.cost) { dist[e.to] = dist[e.from] + e.cost; if (i >= n && (end == -1 || end == e.to)) { negativeLoop = true; break; } } } } } }; int main() { ll n, m, p; cin >> n >> m >> p; BellmanFord<ll> graph(n); vl a(m), b(m), c(m); for (int i = 0; i < m; ++i) { cin >> a[i] >> b[i] >> c[i]; a[i]--; b[i]--; graph.addEdge(a[i], b[i], p - c[i]); } graph.build(0, n - 1); if (graph.negativeLoop) { cout << -1 << "\n"; return 0; } BellmanFord<ll> graph2(n); for (int i = 0; i < m; ++i) { graph2.addEdge(a[i], b[i], p - c[i]); } graph2.build(n - 1, n - 1); if (graph2.negativeLoop) { cout << -1 << "\n"; } else { cout << max(0LL, -graph.dist[n - 1] - graph2.dist[n - 1]) << "\n"; } return 0; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change", "control_flow.branch.if.condition.change", "expression.operation.binary.remove" ]
750,731
750,732
u756088996
cpp
p02949
#include "bits/stdc++.h" using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; using vl = vector<ll>; using vvi = vector<vi>; using vvl = vector<vl>; const ll INF = 1LL << 60; const ll MOD = 1000000007; template <class T> bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0; } template <class T> bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0; } template <class C> void print(const C &c, std::ostream &os = std::cout) { std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " ")); os << std::endl; } template <typename T> // T : type of cost struct BellmanFord { T inf = numeric_limits<T>::max(); // initial value, reused when clear() is called int n; // number of nodes vector<T> dist; // distance from start node bool negativeLoop; struct edge { int from, to; T cost; edge(int from, int to, T cost) : from(from), to(to), cost(cost) {} }; vector<edge> edges; BellmanFord(int n) : n(n), negativeLoop(false), dist(n, inf){}; // 0-indexed! void addEdge(int from, int to, T cost) { edges.emplace_back(from, to, cost); } // calculate dist[i] as a shortest distance from start (to end) // end is used to check if there is "relevant" negative circuit // even if there is negative curcuit, it might not affect the path of interest void build(int start, int end = -1) { dist[start] = 0; for (int i = 0; i < n; ++i) { for (auto &e : edges) { if (dist[e.from] != inf && dist[e.to] > dist[e.from] + e.cost) { dist[e.to] = dist[e.from] + e.cost; if (i == n - 1 && (end == -1 || end == e.to)) { negativeLoop = true; break; } } } } } }; int main() { ll n, m, p; cin >> n >> m >> p; BellmanFord<ll> graph(n); vl a(m), b(m), c(m); for (int i = 0; i < m; ++i) { cin >> a[i] >> b[i] >> c[i]; a[i]--; b[i]--; graph.addEdge(a[i], b[i], p - c[i]); } graph.build(0, n - 1); if (graph.negativeLoop) { cout << -1 << "\n"; return 0; } BellmanFord<ll> graph2(n); for (int i = 0; i < m; ++i) { graph2.addEdge(a[i], b[i], p - c[i]); } graph2.build(n - 1, n - 1); if (graph2.negativeLoop) { cout << -1 << "\n"; } else { cout << max(0LL, -graph.dist[n - 1] - graph2.dist[n - 1]) << "\n"; } return 0; }
#include "bits/stdc++.h" using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; using vl = vector<ll>; using vvi = vector<vi>; using vvl = vector<vl>; const ll INF = 1LL << 60; const ll MOD = 1000000007; template <class T> bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0; } template <class T> bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0; } template <class C> void print(const C &c, std::ostream &os = std::cout) { std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " ")); os << std::endl; } template <typename T> // T : type of cost struct BellmanFord { T inf = numeric_limits<T>::max(); // initial value, reused when clear() is called int n; // number of nodes vector<T> dist; // distance from start node bool negativeLoop; struct edge { int from, to; T cost; edge(int from, int to, T cost) : from(from), to(to), cost(cost) {} }; vector<edge> edges; BellmanFord(int n) : n(n), negativeLoop(false), dist(n, inf){}; // 0-indexed! void addEdge(int from, int to, T cost) { edges.emplace_back(from, to, cost); } // calculate dist[i] as a shortest distance from start (to end) // end is used to check if there is "relevant" negative circuit // even if there is negative curcuit, it might not affect the path of interest void build(int start, int end = -1) { dist[start] = 0; for (int i = 0; i < 3 * n; ++i) { for (auto &e : edges) { if (dist[e.from] != inf && dist[e.to] > dist[e.from] + e.cost) { dist[e.to] = dist[e.from] + e.cost; if (i >= 2 * n - 1 && (end == -1 || end == e.to)) { negativeLoop = true; break; } } } } } }; int main() { ll n, m, p; cin >> n >> m >> p; BellmanFord<ll> graph(n); vl a(m), b(m), c(m); for (int i = 0; i < m; ++i) { cin >> a[i] >> b[i] >> c[i]; a[i]--; b[i]--; graph.addEdge(a[i], b[i], p - c[i]); } graph.build(0, n - 1); if (graph.negativeLoop) { cout << -1 << "\n"; return 0; } BellmanFord<ll> graph2(n); for (int i = 0; i < m; ++i) { graph2.addEdge(a[i], b[i], p - c[i]); } graph2.build(n - 1, n - 1); if (graph2.negativeLoop) { cout << -1 << "\n"; } else { cout << max(0LL, -graph.dist[n - 1] - graph2.dist[n - 1]) << "\n"; } return 0; }
[ "control_flow.loop.for.condition.change", "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
750,731
750,733
u756088996
cpp