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
p03007
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) #define repn(i, n) for (int(i) = 1; (i) <= (n); (i)++) #define repr(i, n) for (int(i) = (n - 1); (i) >= 0; (i)--) #define all(x) (x).begin(), (x).end() #define lint long long #define ulint unsigned long long #define fi first #define se second #define setpre(x) cout << fixed << setprecision(x) #define ii(x) \ int x; \ cin >> (x) #define ii2(x, y) \ int x, y; \ cin >> (x) >> (y) #define ii3(x, y, z) \ int x, y, z; \ cin >> (x) >> (y) >> (z) #define out(x) cout << (x) << endl #define outs(x) cout << (x) << " " #define yn(x) cout << ((x) ? ("Yes") : ("No")) << endl #define YN(x) cout << ((x) ? ("YES") : ("NO")) << endl #define bit_c(x) __builtin_popcountll(x) inline void logger() { cout << endl; } template <typename A, typename... B> void logger(const A &a, const B &...b) { cout << a << " , "; logger(b...); } typedef pair<lint, lint> P; const lint MOD = 1000000007; const lint MOD9 = 998244353; const lint INF = MOD * MOD; const int MAX = 10005; /* ...o(^-^)o... */ int main() { ii(n); vector<lint> a(n); rep(i, n) cin >> a[i]; sort(all(a)); vector<lint> b, c; lint m = 0; if (a[0] > 0) { b.push_back(a[0]); m -= a[0]; rep(i, n - 1) { c.push_back(a[i + 1]); m += a[i + 1]; } } else if (a[n - 1] < 0) { rep(i, n - 1) { b.push_back(a[i]); m -= a[i]; } c.push_back(a[n - 1]); m += a[n - 1]; } else { rep(i, n) { if (a[i] <= 0) { b.push_back(a[i]); m -= a[i]; } else { c.push_back(a[i]); m += a[i]; } } } out(m); int p = b.size(), q = c.size(); lint tmp = b[0]; rep(i, q - 1) { outs(tmp); outs(c[i]); out(""); tmp -= c[i]; } outs(c[q - 1]); outs(tmp); out(""); tmp = c[q - 1] - tmp; rep(i, p - 1) { outs(tmp); outs(b[i + 1]); out(""); tmp -= b[i + 1]; } }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) #define repn(i, n) for (int(i) = 1; (i) <= (n); (i)++) #define repr(i, n) for (int(i) = (n - 1); (i) >= 0; (i)--) #define all(x) (x).begin(), (x).end() #define lint long long #define ulint unsigned long long #define fi first #define se second #define setpre(x) cout << fixed << setprecision(x) #define ii(x) \ int x; \ cin >> (x) #define ii2(x, y) \ int x, y; \ cin >> (x) >> (y) #define ii3(x, y, z) \ int x, y, z; \ cin >> (x) >> (y) >> (z) #define out(x) cout << (x) << endl #define outs(x) cout << (x) << " " #define yn(x) cout << ((x) ? ("Yes") : ("No")) << endl #define YN(x) cout << ((x) ? ("YES") : ("NO")) << endl #define bit_c(x) __builtin_popcountll(x) inline void logger() { cout << endl; } template <typename A, typename... B> void logger(const A &a, const B &...b) { cout << a << " , "; logger(b...); } typedef pair<lint, lint> P; const lint MOD = 1000000007; const lint MOD9 = 998244353; const lint INF = MOD * MOD; const int MAX = 10005; /* ...o(^-^)o... */ int main() { ii(n); vector<lint> a(n); rep(i, n) cin >> a[i]; sort(all(a)); vector<lint> b, c; lint m = 0; if (a[0] >= 0) { b.push_back(a[0]); m -= a[0]; rep(i, n - 1) { c.push_back(a[i + 1]); m += a[i + 1]; } } else if (a[n - 1] <= 0) { rep(i, n - 1) { b.push_back(a[i]); m -= a[i]; } c.push_back(a[n - 1]); m += a[n - 1]; } else { rep(i, n) { if (a[i] <= 0) { b.push_back(a[i]); m -= a[i]; } else { c.push_back(a[i]); m += a[i]; } } } out(m); int p = b.size(), q = c.size(); lint tmp = b[0]; rep(i, q - 1) { outs(tmp); outs(c[i]); out(""); tmp -= c[i]; } outs(c[q - 1]); outs(tmp); out(""); tmp = c[q - 1] - tmp; rep(i, p - 1) { outs(tmp); outs(b[i + 1]); out(""); tmp -= b[i + 1]; } }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
821,504
821,505
u632094970
cpp
p03007
#include <bits/stdc++.h> #define f(i, n) for (int i = 0; i < (n); i++) #define inf (int)(3e18) #define int long long #define mod (int)(1000000007) #define intt long long #define P pair<int, int> using namespace std; // Library //モッドパウ int modpow(int x, int y, int m = mod) { int res = 1; while (y) { if (y % 2) { res *= x; res %= m; } x = x * x % mod; y /= 2; } return res; } int mypow(int x, int y) { int res = 1; while (y) { if (y % 2) { res *= x; } x = x * x; y /= 2; } return res; } // is the number (x) a prime number? bool prime(int x) { for (int i = 2; i * i <= x; i++) { if (!(x % i)) { return false; } } return true; } double kyori(pair<int, int> f, pair<int, int> s) { double ans = 0; double t = fabs(f.first - s.first); double y = fabs(f.second - s.second); ans = sqrt(t * t + y * y); return ans; } // saidai-kouyakusuu inline int gcd(int x, int y) { if (!y) { return x; } return gcd(y, x % y); } // Union-Find Tree class Union_Find { vector<int> par; vector<int> rankmy; public: Union_Find(int size) { par = vector<int>(size); rankmy = vector<int>(size); for (int i = 0; i < size; i++) { par[i] = i; } } int find(int x) { if (par[x] == x) { return x; } return par[x] = find(par[x]); } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) { return; } if (rankmy[x] < rankmy[y]) { par[x] = y; } else { par[y] = x; if (rankmy[x] == rankmy[y]) { rankmy[x]++; } } } bool same(int x, int y) { return find(x) == find(y); } }; // Union-Find-End // SegTree template <class T> class SegTree { int n; // 葉の数 vector<T> data; // データを格納するvector T def; // 初期値かつ単位元 function<T(T, T)> operation; // 区間クエリで使う処理 function<T(T, T)> update; // 点更新で使う処理 // 区間[a,b)の総和。ノードk=[l,r)に着目している。 T _query(int a, int b, int k, int l, int r) { if (r <= a || b <= l) return def; // 交差しない if (a <= l && r <= b) return data[k]; // a,l,r,bの順で完全に含まれる else { T c1 = _query(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子 T c2 = _query(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子 return operation(c1, c2); } } public: // _n:必要サイズ, _def:初期値かつ単位元, _operation:クエリ関数, // _update:更新関数 SegTree(size_t _n, T _def, function<T(T, T)> _operation, function<T(T, T)> _update) : def(_def), operation(_operation), update(_update) { n = 1; while (n < _n) { n *= 2; } data = vector<T>(2 * n - 1, def); } // 場所i(0-indexed)の値をxで更新 void change(int i, T x) { i += n - 1; data[i] = update(data[i], x); while (i > 0) { i = (i - 1) / 2; data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]); } } // [a, b)の区間クエリを実行 T query(int a, int b) { return _query(a, b, 0, 0, n); } // 添字でアクセス T operator[](int i) { return data[i + n - 1]; } }; #define R_MIN ([](long long a, long long b) { return min(a, b); }) #define R_MAX ([](long long a, long long b) { return max(a, b); }) #define R_SUM ([](long long a, long long b) { return a + b; }) #define NORMAL_UPDATE ([](long long a, long long b) { return b; }) #define ADD_UPDATE ([](long long a, long long b) { return a + b; }) #define MINUS_UPDATE ([](long long a, long long b) { return a - b; } // Seg-Tree-End // dfs // vector<int> v[100004]; // bool went[100004]; // void dfs(int x) { // went[x] = true; // for (int i = 0; i < (int)v[x].size(); i++) { // if (!went[v[x][i]]) { // dfs(v[x][i]); // } // } //} // number of keta int keta(int x) { int ans = 0; while (x) { x /= 10; ans++; } return ans; } // sum of keta int ketasum(int x) { int ans = 0; while (x) { ans += x % 10; x /= 10; } return ans; } inline int lcm(int x, int y) { int ans = x / gcd(x, y) * y; return ans; } int twobeki(int x) { int ans = 0; while (1) { if (!(x & 1)) { ans++; x /= 2; } else { break; } } return ans; } int kai(int x, int y) { int res = 1; for (int i = x - y + 1; i <= x; i++) { res *= i; res %= mod; } return res; } int comb(int x, int y) { if (y > x) return 0; // cout<<kai(x, y)<<' '<<modpow(kai(y, y), mod - 2)<<endl; return kai(x, y) * modpow(kai(y, y), mod - 2) % mod; } int fukugen(vector<int> l) { int ans = 0; for (int i = 0; i < (int)l.size(); i++) { ans *= 10; ans += l[i]; } return ans; } int nanjyo(int n) { int ans = 0; while (n > 1) { ans++; n /= 2; } return ans; } bool intersect(pair<pair<int, int>, pair<int, int>> p1, pair<pair<int, int>, pair<int, int>> p2) { int men11 = (p2.first.first - p1.first.first) * (p2.second.second - p1.first.second) - (p2.second.first - p1.first.first) * (p2.first.second - p1.first.second); int men12 = (p2.first.first - p1.second.first) * (p2.second.second - p1.second.second) - (p2.second.first - p1.second.first) * (p2.first.second - p1.second.second); int men21 = (p1.first.first - p2.first.first) * (p1.second.second - p2.first.second) - (p1.second.first - p2.first.first) * (p1.first.second - p2.first.second); int men22 = (p1.first.first - p2.second.first) * (p1.second.second - p2.second.second) - (p1.second.first - p2.second.first) * (p1.first.second - p2.second.second); return ((signbit(men11)) ^ (signbit(men12))) && ((signbit(men21)) ^ (signbit(men22))); } template <class T, class U> inline bool chmax(T &lhs, const U &rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; } template <class T, class U> inline bool chmin(T &lhs, const U &rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; } void Yes() { cout << "Yes" << endl; } void No() { cout << "No" << endl; } void YES() { cout << "YES" << endl; } void NO() { cout << "NO" << endl; } int yakusuu(int x) { int ans = 0; for (int i = 1; i * i <= x; i++) { if (!(x % i)) { if (i * i == x) { ans++; } else ans += 2; } } return ans; } #define rep(i, n) for (int i = 0; i < n; i++) #define REP(i, n) for (int i = 1; i <= n; i++) // Library-End int n, a[100004], ans; vector<int> mi, po; vector<pair<int, int>> v; signed main() { cin >> n; rep(i, n) { scanf("%lld", &a[i]); if (a[i] > 0) { po.push_back(a[i]); } if (a[i] < 0) { mi.push_back(a[i]); } } sort(po.begin(), po.end(), greater<int>()); sort(mi.begin(), mi.end()); if (!mi.size()) { mi.push_back(po[(int)po.size() - 1]); po.pop_back(); } if (!po.size()) { po.push_back(mi[(int)mi.size()] - 1); mi.pop_back(); } rep(i, (int)po.size() - 1) { v.push_back({mi[0], po[i + 1]}); mi[0] -= po[i + 1]; } rep(i, (int)mi.size() - 1) { v.push_back({po[0], mi[i + 1]}); po[0] -= mi[i + 1]; } v.push_back({po[0], mi[0]}); cout << po[0] - mi[0] << endl; rep(i, v.size()) { printf("%lld %lld\n", v[i].first, v[i].second); } }
#include <bits/stdc++.h> #define f(i, n) for (int i = 0; i < (n); i++) #define inf (int)(3e18) #define int long long #define mod (int)(1000000007) #define intt long long #define P pair<int, int> using namespace std; // Library //モッドパウ int modpow(int x, int y, int m = mod) { int res = 1; while (y) { if (y % 2) { res *= x; res %= m; } x = x * x % mod; y /= 2; } return res; } int mypow(int x, int y) { int res = 1; while (y) { if (y % 2) { res *= x; } x = x * x; y /= 2; } return res; } // is the number (x) a prime number? bool prime(int x) { for (int i = 2; i * i <= x; i++) { if (!(x % i)) { return false; } } return true; } double kyori(pair<int, int> f, pair<int, int> s) { double ans = 0; double t = fabs(f.first - s.first); double y = fabs(f.second - s.second); ans = sqrt(t * t + y * y); return ans; } // saidai-kouyakusuu inline int gcd(int x, int y) { if (!y) { return x; } return gcd(y, x % y); } // Union-Find Tree class Union_Find { vector<int> par; vector<int> rankmy; public: Union_Find(int size) { par = vector<int>(size); rankmy = vector<int>(size); for (int i = 0; i < size; i++) { par[i] = i; } } int find(int x) { if (par[x] == x) { return x; } return par[x] = find(par[x]); } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) { return; } if (rankmy[x] < rankmy[y]) { par[x] = y; } else { par[y] = x; if (rankmy[x] == rankmy[y]) { rankmy[x]++; } } } bool same(int x, int y) { return find(x) == find(y); } }; // Union-Find-End // SegTree template <class T> class SegTree { int n; // 葉の数 vector<T> data; // データを格納するvector T def; // 初期値かつ単位元 function<T(T, T)> operation; // 区間クエリで使う処理 function<T(T, T)> update; // 点更新で使う処理 // 区間[a,b)の総和。ノードk=[l,r)に着目している。 T _query(int a, int b, int k, int l, int r) { if (r <= a || b <= l) return def; // 交差しない if (a <= l && r <= b) return data[k]; // a,l,r,bの順で完全に含まれる else { T c1 = _query(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子 T c2 = _query(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子 return operation(c1, c2); } } public: // _n:必要サイズ, _def:初期値かつ単位元, _operation:クエリ関数, // _update:更新関数 SegTree(size_t _n, T _def, function<T(T, T)> _operation, function<T(T, T)> _update) : def(_def), operation(_operation), update(_update) { n = 1; while (n < _n) { n *= 2; } data = vector<T>(2 * n - 1, def); } // 場所i(0-indexed)の値をxで更新 void change(int i, T x) { i += n - 1; data[i] = update(data[i], x); while (i > 0) { i = (i - 1) / 2; data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]); } } // [a, b)の区間クエリを実行 T query(int a, int b) { return _query(a, b, 0, 0, n); } // 添字でアクセス T operator[](int i) { return data[i + n - 1]; } }; #define R_MIN ([](long long a, long long b) { return min(a, b); }) #define R_MAX ([](long long a, long long b) { return max(a, b); }) #define R_SUM ([](long long a, long long b) { return a + b; }) #define NORMAL_UPDATE ([](long long a, long long b) { return b; }) #define ADD_UPDATE ([](long long a, long long b) { return a + b; }) #define MINUS_UPDATE ([](long long a, long long b) { return a - b; } // Seg-Tree-End // dfs // vector<int> v[100004]; // bool went[100004]; // void dfs(int x) { // went[x] = true; // for (int i = 0; i < (int)v[x].size(); i++) { // if (!went[v[x][i]]) { // dfs(v[x][i]); // } // } //} // number of keta int keta(int x) { int ans = 0; while (x) { x /= 10; ans++; } return ans; } // sum of keta int ketasum(int x) { int ans = 0; while (x) { ans += x % 10; x /= 10; } return ans; } inline int lcm(int x, int y) { int ans = x / gcd(x, y) * y; return ans; } int twobeki(int x) { int ans = 0; while (1) { if (!(x & 1)) { ans++; x /= 2; } else { break; } } return ans; } int kai(int x, int y) { int res = 1; for (int i = x - y + 1; i <= x; i++) { res *= i; res %= mod; } return res; } int comb(int x, int y) { if (y > x) return 0; // cout<<kai(x, y)<<' '<<modpow(kai(y, y), mod - 2)<<endl; return kai(x, y) * modpow(kai(y, y), mod - 2) % mod; } int fukugen(vector<int> l) { int ans = 0; for (int i = 0; i < (int)l.size(); i++) { ans *= 10; ans += l[i]; } return ans; } int nanjyo(int n) { int ans = 0; while (n > 1) { ans++; n /= 2; } return ans; } bool intersect(pair<pair<int, int>, pair<int, int>> p1, pair<pair<int, int>, pair<int, int>> p2) { int men11 = (p2.first.first - p1.first.first) * (p2.second.second - p1.first.second) - (p2.second.first - p1.first.first) * (p2.first.second - p1.first.second); int men12 = (p2.first.first - p1.second.first) * (p2.second.second - p1.second.second) - (p2.second.first - p1.second.first) * (p2.first.second - p1.second.second); int men21 = (p1.first.first - p2.first.first) * (p1.second.second - p2.first.second) - (p1.second.first - p2.first.first) * (p1.first.second - p2.first.second); int men22 = (p1.first.first - p2.second.first) * (p1.second.second - p2.second.second) - (p1.second.first - p2.second.first) * (p1.first.second - p2.second.second); return ((signbit(men11)) ^ (signbit(men12))) && ((signbit(men21)) ^ (signbit(men22))); } template <class T, class U> inline bool chmax(T &lhs, const U &rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; } template <class T, class U> inline bool chmin(T &lhs, const U &rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; } void Yes() { cout << "Yes" << endl; } void No() { cout << "No" << endl; } void YES() { cout << "YES" << endl; } void NO() { cout << "NO" << endl; } int yakusuu(int x) { int ans = 0; for (int i = 1; i * i <= x; i++) { if (!(x % i)) { if (i * i == x) { ans++; } else ans += 2; } } return ans; } #define rep(i, n) for (int i = 0; i < n; i++) #define REP(i, n) for (int i = 1; i <= n; i++) // Library-End int n, a[100004], ans; vector<int> mi, po; vector<pair<int, int>> v; signed main() { cin >> n; rep(i, n) { scanf("%lld", &a[i]); if (a[i] >= 0) { po.push_back(a[i]); } if (a[i] < 0) { mi.push_back(a[i]); } } sort(po.begin(), po.end(), greater<int>()); sort(mi.begin(), mi.end()); if (!mi.size()) { mi.push_back(po[(int)po.size() - 1]); po.pop_back(); } if (!po.size()) { po.push_back(mi[(int)mi.size()] - 1); mi.pop_back(); } rep(i, (int)po.size() - 1) { v.push_back({mi[0], po[i + 1]}); mi[0] -= po[i + 1]; } rep(i, (int)mi.size() - 1) { v.push_back({po[0], mi[i + 1]}); po[0] -= mi[i + 1]; } v.push_back({po[0], mi[0]}); cout << po[0] - mi[0] << endl; rep(i, v.size()) { printf("%lld %lld\n", v[i].first, v[i].second); } }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
821,506
821,507
u943070796
cpp
p03007
#include "bits/stdc++.h" using namespace std; typedef long long int ll; typedef pair<ll, ll> pi; typedef pair<pair<ll, ll>, ll> pii; vector<ll> vec; vector<vector<ll>> vec2; ll MOD = 1000000007; ll INF = 1145141919454519; //大胆な気持ちで考える //プラスはプラスのまま答えに足したいし //マイナスはプラスにして答えに足したい //でもx-yという操作をする必要があるので //すべてをプラスにしたりマイナスにすることは絶対にできない //必ず+と-の要素が必要 //つまり最大値と最小値を+と-に固定すれば,あとの数字はどのような //符号の付け方でも良い int main() { // ifstream in("23.txt"); // cin.rdbuf(in.rdbuf()); ll N; cin >> N; vector<ll> minus; vector<ll> plus; for (ll i = 0; i < N; i++) { ll t; cin >> t; vec.push_back(t); } sort(vec.begin(), vec.end()); ll sum = 0; //-から+に数字が分布しているならすべての符号を+にできる // A_N(最大でプラス) - (A_1(最小でマイナス) - プラスの奴ら ) - マイナスの奴ら //ですべての符号をプラスに揃えることができる!!!! for (ll i = 0; i < N; i++) { sum += abs(vec[i]); } //-または+しか存在しない数列だとはみ出た分考慮する if (vec[0] >= 0) sum -= vec[0] * 2; if (vec[vec.size() - 1] < 0) sum += vec[vec.size() - 1] * 2; cout << sum << endl; //操作を復元する //最小の値から操作していく ll tmp = vec[0]; //まずはプラスのやつらを引いていく //ここ(A_1(最小でマイナス) - プラスの奴ら ) の操作 for (ll i = 1; i < N - 1; i++) { if (vec[i] >= 0) { cout << tmp << " " << vec[i] << endl; //更新 tmp -= vec[i]; } } //次にマイナスの奴らを引いていく // A_N(最大でプラス) - (tmp) - マイナスの奴ら cout << vec[vec.size() - 1] << " " << tmp << endl; tmp -= vec[vec.size() - 1] - tmp; for (ll i = 1; i < N - 1; i++) { if (vec[i] < 0) { cout << tmp << " " << vec[i] << endl; tmp -= vec[i]; } } }
#include "bits/stdc++.h" using namespace std; typedef long long int ll; typedef pair<ll, ll> pi; typedef pair<pair<ll, ll>, ll> pii; vector<ll> vec; vector<vector<ll>> vec2; ll MOD = 1000000007; ll INF = 1145141919454519; //大胆な気持ちで考える //プラスはプラスのまま答えに足したいし //マイナスはプラスにして答えに足したい //でもx-yという操作をする必要があるので //すべてをプラスにしたりマイナスにすることは絶対にできない //必ず+と-の要素が必要 //つまり最大値と最小値を+と-に固定すれば,あとの数字はどのような //符号の付け方でも良い int main() { // ifstream in("23.txt"); // cin.rdbuf(in.rdbuf()); ll N; cin >> N; vector<ll> minus; vector<ll> plus; for (ll i = 0; i < N; i++) { ll t; cin >> t; vec.push_back(t); } sort(vec.begin(), vec.end()); ll sum = 0; //-から+に数字が分布しているならすべての符号を+にできる // A_N(最大でプラス) - (A_1(最小でマイナス) - プラスの奴ら ) - マイナスの奴ら //ですべての符号をプラスに揃えることができる!!!! for (ll i = 0; i < N; i++) { sum += abs(vec[i]); } //-または+しか存在しない数列だとはみ出た分考慮する if (vec[0] > 0) sum -= vec[0] * 2; if (vec[vec.size() - 1] < 0) sum += vec[vec.size() - 1] * 2; cout << sum << endl; //操作を復元する //最小の値から操作していく ll tmp = vec[0]; //まずはプラスのやつらを引いていく //ここ(A_1(最小でマイナス) - プラスの奴ら ) の操作 for (ll i = 1; i < N - 1; i++) { if (vec[i] >= 0) { cout << tmp << " " << vec[i] << endl; //更新 tmp -= vec[i]; } } //次にマイナスの奴らを引いていく // A_N(最大でプラス) - (tmp) - マイナスの奴ら cout << vec[vec.size() - 1] << " " << tmp << endl; tmp = vec[vec.size() - 1] - tmp; for (ll i = 1; i < N - 1; i++) { if (vec[i] < 0) { cout << tmp << " " << vec[i] << endl; tmp -= vec[i]; } } }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change", "assignment.value.change" ]
821,518
821,519
u048791623
cpp
p03007
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pll = pair<ll, ll>; const ll MOD = 1000000007; ll abs1(ll a) { if (a >= 0) return a; else return -a; } ll pow1(ll a, ll b, ll p = LLONG_MAX) { ll ret = 1; while (b != 0) { if ((b & 1) == 1) { ret *= a; } a *= a; if (a >= p) a %= p; b = b >> 1; } return ret; } int digit(ll a, ll b) { int i = 0; while (a != 0) { a /= b; i++; } return i; } int ord(ll a, ll p) { int i = 0; while (a % p == 0) { a /= p; i++; } return i; } ll gcd1(ll a, ll b) { if (a == 0 && b == 0) return 0; ll n; while (a % b != 0) { n = a % b; a = b; b = n; } return b; } ll solveLinear(ll n, ll m, ll c) { if (n == 0 && m == 0) return 0; ll a[100], b[100]; a[0] = n; b[0] = m; int i = 1; while (b[i - 1] != 0) { a[i] = b[i - 1]; b[i] = a[i - 1] % b[i - 1]; i++; } n = i; if (c % a[n - 1] != 0) { return 0; } ll x = c / a[n - 1], y = 0; for (i = 1; i < n; i++) { ll cnt = x; x = y; y = cnt - (a[n - i - 1] / b[n - i - 1]) * y; } return x; } ll modRev(ll a, ll p = MOD) { a %= p; ll n = solveLinear(a, p, 1); n %= p; if (n < 0) return n + p; return n; } ll fact(ll n, ll p = MOD) { if (n < 0) return 0; int i; ll ret = 1; for (i = 0; i < n; i++) { ret = ret * (i + 1); if (ret >= p) ret %= p; } return ret; } ll perm(ll n, ll k, ll p = MOD) { if (n < 0 || k < 0 || n < k) return 0; int i; ll ret = 1; for (i = 0; i < k; i++) { ret = ret * (n - i); if (ret >= p) ret %= p; } return ret; } ll binom(ll n, ll k, ll p = MOD) { if (n < 0 || k < 0 || n < k) return 0; int i; ll ret = 1, fact = 1; for (i = 0; i < k; i++) { ret = ret * (n - i); fact *= i + 1; if (ret >= p) ret %= p; if (fact >= p) fact %= p; } return (ret * modRev(fact)) % p; } int main() { int i, j, k; ll cnt = 0; ll n; cin >> n; ll a[n]; for (i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); ll sum = 0; for (i = 0; i < n; i++) sum += a[i]; if (a[0] >= 0) { cout << sum - 2 * a[0] << endl; for (i = 1; i < n - 1; i++) { cout << a[0] << " " << a[i] << endl; a[0] -= a[i]; } cout << a[n - 1] << " " << a[0] << endl; return 0; } if (a[n - 1] <= 0) { cout << 2 * a[n - 1] - sum << endl; for (i = 0; i < n - 1; i++) { cout << a[n - 1] << " " << a[i] << endl; a[n - 1] += a[i]; } return 0; } sum = 0; for (i = 0; i < n; i++) sum += abs1(a[i]); cout << sum << endl; for (i = 0; i < n - 1; i++) { if (a[i] < 0 && 0 <= a[i + 1]) { cnt = i; } if (0 <= a[i]) { cout << a[0] << " " << a[i] << endl; a[0] -= a[i]; } } for (i = 0; i <= cnt; i++) { cout << a[n - 1] << " " << a[i] << endl; a[n - 1] -= a[i]; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pll = pair<ll, ll>; const ll MOD = 1000000007; ll abs1(ll a) { if (a >= 0) return a; else return -a; } ll pow1(ll a, ll b, ll p = LLONG_MAX) { ll ret = 1; while (b != 0) { if ((b & 1) == 1) { ret *= a; } a *= a; if (a >= p) a %= p; b = b >> 1; } return ret; } int digit(ll a, ll b) { int i = 0; while (a != 0) { a /= b; i++; } return i; } int ord(ll a, ll p) { int i = 0; while (a % p == 0) { a /= p; i++; } return i; } ll gcd1(ll a, ll b) { if (a == 0 && b == 0) return 0; ll n; while (a % b != 0) { n = a % b; a = b; b = n; } return b; } ll solveLinear(ll n, ll m, ll c) { if (n == 0 && m == 0) return 0; ll a[100], b[100]; a[0] = n; b[0] = m; int i = 1; while (b[i - 1] != 0) { a[i] = b[i - 1]; b[i] = a[i - 1] % b[i - 1]; i++; } n = i; if (c % a[n - 1] != 0) { return 0; } ll x = c / a[n - 1], y = 0; for (i = 1; i < n; i++) { ll cnt = x; x = y; y = cnt - (a[n - i - 1] / b[n - i - 1]) * y; } return x; } ll modRev(ll a, ll p = MOD) { a %= p; ll n = solveLinear(a, p, 1); n %= p; if (n < 0) return n + p; return n; } ll fact(ll n, ll p = MOD) { if (n < 0) return 0; int i; ll ret = 1; for (i = 0; i < n; i++) { ret = ret * (i + 1); if (ret >= p) ret %= p; } return ret; } ll perm(ll n, ll k, ll p = MOD) { if (n < 0 || k < 0 || n < k) return 0; int i; ll ret = 1; for (i = 0; i < k; i++) { ret = ret * (n - i); if (ret >= p) ret %= p; } return ret; } ll binom(ll n, ll k, ll p = MOD) { if (n < 0 || k < 0 || n < k) return 0; int i; ll ret = 1, fact = 1; for (i = 0; i < k; i++) { ret = ret * (n - i); fact *= i + 1; if (ret >= p) ret %= p; if (fact >= p) fact %= p; } return (ret * modRev(fact)) % p; } int main() { int i, j, k; ll cnt = 0; ll n; cin >> n; ll a[n]; for (i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); ll sum = 0; for (i = 0; i < n; i++) sum += a[i]; if (a[0] >= 0) { cout << sum - 2 * a[0] << endl; for (i = 1; i < n - 1; i++) { cout << a[0] << " " << a[i] << endl; a[0] -= a[i]; } cout << a[n - 1] << " " << a[0] << endl; return 0; } if (a[n - 1] <= 0) { cout << 2 * a[n - 1] - sum << endl; for (i = 0; i < n - 1; i++) { cout << a[n - 1] << " " << a[i] << endl; a[n - 1] -= a[i]; } return 0; } sum = 0; for (i = 0; i < n; i++) sum += abs1(a[i]); cout << sum << endl; for (i = 0; i < n - 1; i++) { if (a[i] < 0 && 0 <= a[i + 1]) { cnt = i; } if (0 <= a[i]) { cout << a[0] << " " << a[i] << endl; a[0] -= a[i]; } } for (i = 0; i <= cnt; i++) { cout << a[n - 1] << " " << a[i] << endl; a[n - 1] -= a[i]; } return 0; }
[ "expression.operator.change" ]
821,538
821,539
u952130512
cpp
p03007
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPR(i, n) for (int i = (n); i >= 0; --i) #define FOR(i, m, n) for (int i = (m); i < (n); ++i) using ll = long long; #define INF 1e9 int main() { int N; cin >> N; vector<int> A(N); REP(i, N) { cin >> A[i]; } int maxa = -INF, mina = INF, sum = 0; REP(i, N) { maxa = max(maxa, A[i]); mina = min(mina, A[i]); sum += abs(A[i]); } vector<int> plus, minus; REP(i, N) { if (A[i] > 0) { plus.push_back(A[i]); } else if (A[i] < 0) { minus.push_back(A[i]); } else { plus.push_back(A[i]); } } if (maxa < 0 || (plus.size() == 1)) { if (maxa < 0) sum += maxa * 2; cout << sum << endl; sort(A.begin(), A.end()); REP(i, N - 1) { cout << maxa << " " << A[i] << endl; maxa = maxa - A[i]; } } else if (mina > 0 || minus.size() == 1) { if (mina > 0) sum -= mina * 2; cout << sum << endl; sort(A.begin(), A.end()); if (N == 2) { cout << A[0] << " " << A[1] << endl; } else { FOR(i, 1, N - 1) { cout << mina << " " << A[i] << endl; mina = mina - A[i]; } cout << A[N - 1] << " " << mina << endl; } } else { cout << sum << endl; int p = minus[0]; FOR(i, 1, plus.size()) { cout << p << " " << plus[i] << endl; p -= plus[i]; } int m = plus[0]; FOR(i, 1, minus.size()) { cout << m << " " << minus[i] << endl; m -= minus[i]; } cout << m << " " << p << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPR(i, n) for (int i = (n); i >= 0; --i) #define FOR(i, m, n) for (int i = (m); i < (n); ++i) using ll = long long; #define INF 1e9 int main() { int N; cin >> N; vector<int> A(N); REP(i, N) { cin >> A[i]; } int maxa = -INF, mina = INF, sum = 0; REP(i, N) { maxa = max(maxa, A[i]); mina = min(mina, A[i]); sum += abs(A[i]); } vector<int> plus, minus; REP(i, N) { if (A[i] > 0) { plus.push_back(A[i]); } else if (A[i] < 0) { minus.push_back(A[i]); } else { plus.push_back(A[i]); } } if (maxa < 0 || (plus.size() == 1)) { if (maxa < 0) sum += maxa * 2; cout << sum << endl; sort(A.begin(), A.end()); REP(i, N - 1) { cout << maxa << " " << A[i] << endl; maxa = maxa - A[i]; } } else if (mina >= 0 || (minus.size() == 1)) { if (mina > 0) sum -= mina * 2; cout << sum << endl; sort(A.begin(), A.end()); if (N == 2) { cout << A[1] << " " << A[0] << endl; } else { FOR(i, 1, N - 1) { cout << mina << " " << A[i] << endl; mina = mina - A[i]; } cout << A[N - 1] << " " << mina << endl; } } else { cout << sum << endl; int p = minus[0]; FOR(i, 1, plus.size()) { cout << p << " " << plus[i] << endl; p -= plus[i]; } int m = plus[0]; FOR(i, 1, minus.size()) { cout << m << " " << minus[i] << endl; m -= minus[i]; } cout << m << " " << p << endl; } return 0; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change", "literal.number.change", "variable_access.subscript.index.change", "io.output.change" ]
821,554
821,555
u174434198
cpp
p03007
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ll n, i, j; cin >> n; vector<ll> v(n); for (i = 0; i < n; i++) { cin >> v[i]; } sort(v.begin(), v.end()); ll sum = 0; for (i = 0; i < n; i++) { sum += abs(v[i]); } vector<pair<ll, ll>> vp; if (v[0] <= 0 && v.back() >= 0) { for (i = 0; i < n; i++) { if (v[i] >= 0) break; } for (j = i; j < n - 1; j++) { vp.push_back({v[0], v[j]}); v[0] -= v[j]; } for (j = 0; j < i; j++) { vp.push_back({v.back(), v[j]}); v[n - 1] -= v[j]; } } else if (v[0] >= 0) { sum -= 2 * v[0]; for (j = 1; j < n - 1; j++) { vp.push_back({v[0], v[j]}); v[0] -= v[j]; } vp.push_back({v.back(), v[0]}); } else { for (j = 0; j < n - 1; j++) { vp.push_back({v.back(), v[j]}); v[n - 1] -= v[j]; } sum = v.back(); } cout << sum << endl; for (auto x : vp) { cout << x.first << " " << x.second << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ll n, i, j; cin >> n; vector<ll> v(n); for (i = 0; i < n; i++) { cin >> v[i]; } sort(v.begin(), v.end()); ll sum = 0; for (i = 0; i < n; i++) { sum += abs(v[i]); } vector<pair<ll, ll>> vp; if (v[0] < 0 && v.back() >= 0) { for (i = 0; i < n; i++) { if (v[i] >= 0) break; } for (j = i; j < n - 1; j++) { vp.push_back({v[0], v[j]}); v[0] -= v[j]; } for (j = 0; j < i; j++) { vp.push_back({v.back(), v[j]}); v[n - 1] -= v[j]; } } else if (v[0] >= 0) { sum -= 2 * v[0]; for (j = 1; j < n - 1; j++) { vp.push_back({v[0], v[j]}); v[0] -= v[j]; } vp.push_back({v.back(), v[0]}); } else { for (j = 0; j < n - 1; j++) { vp.push_back({v.back(), v[j]}); v[n - 1] -= v[j]; } sum = v.back(); } cout << sum << endl; for (auto x : vp) { cout << x.first << " " << x.second << endl; } return 0; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
821,562
821,563
u595893956
cpp
p03007
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> using namespace std; template <typename Tp> inline void getint(Tp &num) { register int ch, neg = 0; while (!isdigit(ch = getchar())) if (ch == '-') neg = 1; num = ch & 15; while (isdigit(ch = getchar())) num = num * 10 + (ch & 15); if (neg) num = -num; } int N, A[100005]; int main() { getint(N); for (register int i = 1; i <= N; i++) getint(A[i]); for (register int i = 2; i <= N; i++) if (A[i] < A[1]) swap(A[i], A[1]); for (register int i = 1; i < N; i++) if (A[i] > A[N]) swap(A[i], A[N + 1]); int ans = A[N] - A[1]; for (register int i = 2; i < N; i++) ans += abs(A[i]); printf("%d\n", ans); for (register int i = 2; i < N; i++) if (A[i] > 0) printf("%d %d\n", A[1], A[i]), A[1] -= A[i]; else printf("%d %d\n", A[N], A[i]), A[N] -= A[i]; return printf("%d %d\n", A[N], A[1]), 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> using namespace std; template <typename Tp> inline void getint(Tp &num) { register int ch, neg = 0; while (!isdigit(ch = getchar())) if (ch == '-') neg = 1; num = ch & 15; while (isdigit(ch = getchar())) num = num * 10 + (ch & 15); if (neg) num = -num; } int N, A[100005]; int main() { getint(N); for (register int i = 1; i <= N; i++) getint(A[i]); for (register int i = 2; i <= N; i++) if (A[i] < A[1]) swap(A[i], A[1]); for (register int i = 1; i < N; i++) if (A[i] > A[N]) swap(A[i], A[N]); int ans = A[N] - A[1]; for (register int i = 2; i < N; i++) ans += abs(A[i]); printf("%d\n", ans); for (register int i = 2; i < N; i++) if (A[i] > 0) printf("%d %d\n", A[1], A[i]), A[1] -= A[i]; else printf("%d %d\n", A[N], A[i]), A[N] -= A[i]; return printf("%d %d\n", A[N], A[1]), 0; }
[ "expression.operation.binary.remove" ]
821,578
821,579
u244167505
cpp
p03007
#include <bits/stdc++.h> using namespace std; 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'); } } int N; int A[100000]; int res; int ress; int resx[100000]; int resy[100000]; inline int doit(int x, int y) { resx[ress] = x; resy[ress++] = y; return x - y; } int main() { int i, j, k, mi, mx; rd(N); { int Lj4PdHRW; for (Lj4PdHRW = 0; Lj4PdHRW < N; Lj4PdHRW++) { rd(A[Lj4PdHRW]); } } { int KL2GvlyY, Q5VJL1cS = 0, RZTsC2BF, cTE1_r3A, e98WHCEY; for (KL2GvlyY = 0; KL2GvlyY < (N - 1) + 1; KL2GvlyY++) { cTE1_r3A = A[KL2GvlyY]; if (Q5VJL1cS == 0 || e98WHCEY > cTE1_r3A) { e98WHCEY = cTE1_r3A; Q5VJL1cS = 1; RZTsC2BF = KL2GvlyY; } } mi = RZTsC2BF; } { int FmcKpFmN, KrdatlYV, WYIGIcGE, t_ynMSdg, xr20shxY = 0; for (FmcKpFmN = 0; FmcKpFmN < (N - 1) + 1; FmcKpFmN++) { t_ynMSdg = A[FmcKpFmN]; if (xr20shxY == 0 || WYIGIcGE < t_ynMSdg) { WYIGIcGE = t_ynMSdg; xr20shxY = 1; KrdatlYV = FmcKpFmN; } } mx = KrdatlYV; } if (mi == mx) { mx++; } for (i = 1; i < N - 1; i++) { if (i == mi || i == mx) { continue; } if (A[i] >= 0) { A[mi] = doit(A[mi], A[i]); } else { A[mx] = doit(A[mx], A[i]); } } res = doit(A[mx], A[mi]); wt_L(res); wt_L('\n'); for (i = 0; i < ress; i++) { wt_L(resx[i]); wt_L(' '); wt_L(resy[i]); wt_L('\n'); } return 0; } // cLay varsion 20190609-2 [beta] // --- original code --- // int N, A[1d5]; // // int res, ress, resx[1d5], resy[1d5]; // // inline int doit(int x, int y){ // resx[ress] = x; // resy[ress++] = y; // return x - y; // } // // { // int i, j, k, mi, mx; // rd(N,A(N)); // // mi = argmin[k=0---N-1](A[k]); // mx = argmax[k=0---N-1](A[k]); // if(mi==mx) mx++; // // rep(i,1,N-1){ // if(i==mi || i==mx) continue; // if(A[i] >= 0) A[mi] = doit(A[mi], A[i]); // else A[mx] = doit(A[mx], A[i]); // } // res = doit(A[mx], A[mi]); // // wt(res); // rep(i,ress) wt(resx[i], resy[i]); // }
#include <bits/stdc++.h> using namespace std; 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'); } } int N; int A[100000]; int res; int ress; int resx[100000]; int resy[100000]; inline int doit(int x, int y) { resx[ress] = x; resy[ress++] = y; return x - y; } int main() { int i, j, k, mi, mx; rd(N); { int Lj4PdHRW; for (Lj4PdHRW = 0; Lj4PdHRW < N; Lj4PdHRW++) { rd(A[Lj4PdHRW]); } } { int KL2GvlyY, Q5VJL1cS = 0, RZTsC2BF, cTE1_r3A, e98WHCEY; for (KL2GvlyY = 0; KL2GvlyY < (N - 1) + 1; KL2GvlyY++) { cTE1_r3A = A[KL2GvlyY]; if (Q5VJL1cS == 0 || e98WHCEY > cTE1_r3A) { e98WHCEY = cTE1_r3A; Q5VJL1cS = 1; RZTsC2BF = KL2GvlyY; } } mi = RZTsC2BF; } { int FmcKpFmN, KrdatlYV, WYIGIcGE, t_ynMSdg, xr20shxY = 0; for (FmcKpFmN = 0; FmcKpFmN < (N - 1) + 1; FmcKpFmN++) { t_ynMSdg = A[FmcKpFmN]; if (xr20shxY == 0 || WYIGIcGE < t_ynMSdg) { WYIGIcGE = t_ynMSdg; xr20shxY = 1; KrdatlYV = FmcKpFmN; } } mx = KrdatlYV; } if (mi == mx) { mx++; } for (i = 0; i < N; i++) { if (i == mi || i == mx) { continue; } if (A[i] >= 0) { A[mi] = doit(A[mi], A[i]); } else { A[mx] = doit(A[mx], A[i]); } } res = doit(A[mx], A[mi]); wt_L(res); wt_L('\n'); for (i = 0; i < ress; i++) { wt_L(resx[i]); wt_L(' '); wt_L(resy[i]); wt_L('\n'); } return 0; } // cLay varsion 20190609-2 [beta] // --- original code --- // int N, A[1d5]; // // int res, ress, resx[1d5], resy[1d5]; // // inline int doit(int x, int y){ // resx[ress] = x; // resy[ress++] = y; // return x - y; // } // // { // int i, j, k, mi, mx; // rd(N,A(N)); // // mi = argmin[k=0---N-1](A[k]); // mx = argmax[k=0---N-1](A[k]); // if(mi==mx) mx++; // // rep(i,N){ // if(i==mi || i==mx) continue; // if(A[i] >= 0) A[mi] = doit(A[mi], A[i]); // else A[mx] = doit(A[mx], A[i]); // } // res = doit(A[mx], A[mi]); // // wt(res); // rep(i,ress) wt(resx[i], resy[i]); // }
[ "literal.number.change", "assignment.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one", "control_flow.loop.for.condition.change", "expression.operation.binary.remove" ]
821,590
821,591
u066369439
cpp
p03007
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> PII; int main() { int N; cin >> N; vector<int> data; int pl = 0; int mn = 0; vector<int> pls, mns; for (int i = 0; i < N; i++) { int a; cin >> a; if (a > 0) pls.push_back(a); if (a < 0) mns.push_back(a); } sort(mns.begin(), mns.end()); sort(pls.begin(), pls.end()); reverse(pls.begin(), pls.end()); if (pls.size() == 0) { int k = mns.back(); mns.pop_back(); pls.push_back(k); } if (mns.size() == 0) { int k = pls.back(); pls.pop_back(); mns.push_back(k); } vector<PII> output; while (pls.size() >= 2) { int k = mns.back(); mns.pop_back(); int j = pls.back(); pls.pop_back(); output.push_back(PII(k, j)); k -= j; mns.push_back(k); } while (mns.size() >= 1) { int k = pls.back(); pls.pop_back(); int j = mns.back(); mns.pop_back(); output.push_back(PII(k, j)); k -= j; pls.push_back(k); } cout << pls[0] << endl; for (auto elem : output) { int a = elem.first; int b = elem.second; cout << a << " " << b << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> PII; int main() { int N; cin >> N; vector<int> data; int pl = 0; int mn = 0; vector<int> pls, mns; for (int i = 0; i < N; i++) { int a; cin >> a; if (a > 0) pls.push_back(a); else mns.push_back(a); } sort(mns.begin(), mns.end()); sort(pls.begin(), pls.end()); reverse(pls.begin(), pls.end()); if (pls.size() == 0) { int k = mns.back(); mns.pop_back(); pls.push_back(k); } if (mns.size() == 0) { int k = pls.back(); pls.pop_back(); mns.push_back(k); } vector<PII> output; while (pls.size() >= 2) { int k = mns.back(); mns.pop_back(); int j = pls.back(); pls.pop_back(); output.push_back(PII(k, j)); k -= j; mns.push_back(k); } while (mns.size() >= 1) { int k = pls.back(); pls.pop_back(); int j = mns.back(); mns.pop_back(); output.push_back(PII(k, j)); k -= j; pls.push_back(k); } cout << pls[0] << endl; for (auto elem : output) { int a = elem.first; int b = elem.second; cout << a << " " << b << endl; } return 0; }
[ "control_flow.loop.for.condition.change" ]
821,594
821,595
u806201407
cpp
p03007
#include <bits/stdc++.h> using namespace std; using Int = int_fast64_t; Int n; vector<Int> a; using P = pair<Int, Int>; vector<P> v; int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> n; a.resize(n); for (auto &i : a) cin >> i; Int mi = 1e9, ma = -1e9, imi = -1, ima = -1; for (size_t i = 0; i < a.size(); ++i) { if (a[i] > ma) { ma = a[i]; ima = i; } } for (size_t i = 0; i < a.size(); ++i) { if (a[i] < ma && a[i] < mi) { mi = a[i]; imi = i; } } for (size_t i = 0; i < a.size(); ++i) { if (a[i] >= 0 && i != imi && i != ima) { v.push_back(P(a[imi], a[i])); a[imi] -= a[i]; } } for (size_t i = 0; i < a.size(); ++i) { if ((a[i] < 0 || i == imi) && i != ima) { v.push_back(P(a[ima], a[i])); a[ima] -= a[i]; } } cout << a[ima] << "\n"; for (auto i : v) cout << i.first << " " << i.second << "\n"; }
#include <bits/stdc++.h> using namespace std; using Int = int_fast64_t; Int n; vector<Int> a; using P = pair<Int, Int>; vector<P> v; int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> n; a.resize(n); for (auto &i : a) cin >> i; Int mi = 1e9, ma = -1e9, imi = -1, ima = -1; for (size_t i = 0; i < a.size(); ++i) { if (a[i] > ma) { ma = a[i]; ima = i; } } for (size_t i = 0; i < a.size(); ++i) { if (i != ima && a[i] < mi) { mi = a[i]; imi = i; } } for (size_t i = 0; i < a.size(); ++i) { if (a[i] >= 0 && i != imi && i != ima) { v.push_back(P(a[imi], a[i])); a[imi] -= a[i]; } } for (size_t i = 0; i < a.size(); ++i) { if ((a[i] < 0 || i == imi) && i != ima) { v.push_back(P(a[ima], a[i])); a[ima] -= a[i]; } } cout << a[ima] << "\n"; for (auto i : v) cout << i.first << " " << i.second << "\n"; }
[ "control_flow.loop.for.condition.change", "control_flow.branch.if.condition.change" ]
821,596
821,597
u207036582
cpp
p03007
#include <bits/stdc++.h> using namespace std; #define int long long #define FOR(i, a, b) for (ll i = (a); i < (b); ++i) #define FORR(i, a, b) for (ll i = (a); i > (b); --i) #define REP(i, n) for (ll i = 0; i < (n); ++i) #define REPR(i, n) for (ll i = n; i >= 0; i--) #define FOREACH(x, a) for (auto &(x) : (a)) #define VECCIN(x) \ for (auto &youso_ : (x)) \ cin >> youso_ #define bitcnt __builtin_popcount #define SZ(x) ((ll)(x).size()) #define fi first #define se second #define All(a) (a).begin(), (a).end() template <typename T = long long> inline T IN() { T x; cin >> x; return (x); } inline void CIN() {} template <class Head, class... Tail> inline void CIN(Head &&head, Tail &&...tail) { cin >> head; CIN(move(tail)...); } #define CINT(...) \ int __VA_ARGS__; \ CIN(__VA_ARGS__) #define LCIN(...) \ ll __VA_ARGS__; \ CIN(__VA_ARGS__) #define SCIN(...) \ string __VA_ARGS__; \ CIN(__VA_ARGS__) #define Yes(a) cout << (a ? "Yes" : "No") << "\n" #define YES(a) cout << (a ? "YES" : "NO") << "\n" #define Printv(v) \ { \ FOREACH(x, v) { cout << x << " "; } \ cout << "\n"; \ } template <typename T = string> inline void eputs(T s) { cout << s << "\n"; exit(0); } template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } typedef long long ll; typedef unsigned long long ul; typedef vector<ll> VL; typedef pair<ll, ll> PL; typedef priority_queue<ll> PQ; typedef priority_queue<ll, VL, greater<ll>> PQG; const int INF = 1e9; const int MOD = 1e9 + 7; // const int MOD = 998244353; const ll LINF = 1e18 + 1; const ll dx[] = {1, -1, 0, 0}; const ll dy[] = {0, 0, 1, -1}; ll N; VL A; vector<PL> ope; signed main() { cin >> N; REP(i, N) A.emplace_back(IN()); ll sum = 0; sort(All(A)); ll bo = lower_bound(All(A), 0) - A.begin(); if (bo == N - 1) bo = N - 2; if (bo == 0) bo = 1; FOR(i, bo, N - 1) { ope.emplace_back(A[0], A[i]); A[0] -= A[i]; } REP(i, bo) { ope.emplace_back(A[N - 1], A[i]); A[N - 1] -= A[i]; } cout << A[N - 1] << "\n"; REP(i, ope.size()) { cout << ope[i].first << " " << ope[i].second << "\n"; } }
#include <bits/stdc++.h> using namespace std; #define int long long #define FOR(i, a, b) for (ll i = (a); i < (b); ++i) #define FORR(i, a, b) for (ll i = (a); i > (b); --i) #define REP(i, n) for (ll i = 0; i < (n); ++i) #define REPR(i, n) for (ll i = n; i >= 0; i--) #define FOREACH(x, a) for (auto &(x) : (a)) #define VECCIN(x) \ for (auto &youso_ : (x)) \ cin >> youso_ #define bitcnt __builtin_popcount #define SZ(x) ((ll)(x).size()) #define fi first #define se second #define All(a) (a).begin(), (a).end() template <typename T = long long> inline T IN() { T x; cin >> x; return (x); } inline void CIN() {} template <class Head, class... Tail> inline void CIN(Head &&head, Tail &&...tail) { cin >> head; CIN(move(tail)...); } #define CINT(...) \ int __VA_ARGS__; \ CIN(__VA_ARGS__) #define LCIN(...) \ ll __VA_ARGS__; \ CIN(__VA_ARGS__) #define SCIN(...) \ string __VA_ARGS__; \ CIN(__VA_ARGS__) #define Yes(a) cout << (a ? "Yes" : "No") << "\n" #define YES(a) cout << (a ? "YES" : "NO") << "\n" #define Printv(v) \ { \ FOREACH(x, v) { cout << x << " "; } \ cout << "\n"; \ } template <typename T = string> inline void eputs(T s) { cout << s << "\n"; exit(0); } template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } typedef long long ll; typedef unsigned long long ul; typedef vector<ll> VL; typedef pair<ll, ll> PL; typedef priority_queue<ll> PQ; typedef priority_queue<ll, VL, greater<ll>> PQG; const int INF = 1e9; const int MOD = 1e9 + 7; // const int MOD = 998244353; const ll LINF = 1e18 + 1; const ll dx[] = {1, -1, 0, 0}; const ll dy[] = {0, 0, 1, -1}; ll N; VL A; vector<PL> ope; signed main() { cin >> N; REP(i, N) A.emplace_back(IN()); ll sum = 0; sort(All(A)); ll bo = lower_bound(All(A), 0) - A.begin(); if (bo == N) bo = N - 1; if (bo == 0) bo = 1; FOR(i, bo, N - 1) { ope.emplace_back(A[0], A[i]); A[0] -= A[i]; } REP(i, bo) { ope.emplace_back(A[N - 1], A[i]); A[N - 1] -= A[i]; } cout << A[N - 1] << "\n"; REP(i, ope.size()) { cout << ope[i].first << " " << ope[i].second << "\n"; } }
[ "expression.operation.binary.remove", "literal.number.change", "assignment.value.change", "expression.operation.binary.change" ]
821,602
821,601
u139031151
cpp
p03007
#include <bits/stdc++.h> #define ll long long #define pb push_back #define mod 1000000007 #define all(v) v.begin(), v.end() #define MP make_pair #define F first #define S second #define sz(v) (ll) v.size() #define inf 1000000000000000000 #define vll vector<ll> using namespace std; const int N = 100005; void solve() { ll n, a[N], i, ans, pre1, pre2; cin >> n; for (i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); ans = -a[0] + a[n - 1]; for (i = 1; i < n - 1; i++) ans += abs(a[i]); cout << ans << "\n"; pre1 = a[n - 1]; for (i = 1; i < n; i++) { if (a[i] < 0) { cout << pre1 << " " << a[i] << "\n"; pre1 -= a[i]; } else break; } pre2 = a[0]; for (i = n - 2; i >= 0; i--) if (a[i] >= 0) { cout << pre2 << " " << a[i] << "\n"; pre2 -= a[i]; } cout << pre1 << " " << pre2 << "\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll t = 1; // cin>>t; while (t--) solve(); return 0; }
#include <bits/stdc++.h> #define ll long long #define pb push_back #define mod 1000000007 #define all(v) v.begin(), v.end() #define MP make_pair #define F first #define S second #define sz(v) (ll) v.size() #define inf 1000000000000000000 #define vll vector<ll> using namespace std; const int N = 100005; void solve() { ll n, a[N], i, ans, pre1, pre2; cin >> n; for (i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); ans = -a[0] + a[n - 1]; for (i = 1; i < n - 1; i++) ans += abs(a[i]); cout << ans << "\n"; pre1 = a[n - 1]; for (i = 1; i < n - 1; i++) { if (a[i] < 0) { cout << pre1 << " " << a[i] << "\n"; pre1 -= a[i]; } else break; } pre2 = a[0]; for (i = n - 2; i > 0; i--) if (a[i] >= 0) { cout << pre2 << " " << a[i] << "\n"; pre2 -= a[i]; } cout << pre1 << " " << pre2 << "\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll t = 1; // cin>>t; while (t--) solve(); return 0; }
[ "control_flow.loop.for.condition.change", "misc.off_by_one", "expression.operator.compare.change", "expression.operation.binary.change" ]
821,603
821,604
u850006519
cpp
p03007
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> ii; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector<int> a; a.resize(n); for (int i = 0; i < n; i++) cin >> a[i]; multiset<int> s; for (int i : a) s.insert(i); vector<ii> moves; while (s.size() > 1) { auto first = s.begin(); auto last = --s.end(); auto secondLast = --(--s.end()); if (s.size() == 2) { moves.emplace_back(*last, *first); int res = (*last) - (*first); s.erase(first); s.erase(last); s.insert(res); } else if (*secondLast > 0) { int res = (*first) - (*secondLast); moves.emplace_back(*secondLast, *first); s.erase(first); s.erase(secondLast); s.insert(res); } else { moves.emplace_back(*last, *first); int res = (*last) - (*first); s.erase(first); s.erase(last); s.insert(res); } } cout << (*s.begin()) << '\n'; for (ii m : moves) cout << m.first << " " << m.second << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> ii; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector<int> a; a.resize(n); for (int i = 0; i < n; i++) cin >> a[i]; multiset<int> s; for (int i : a) s.insert(i); vector<ii> moves; while (s.size() > 1) { auto first = s.begin(); auto last = --s.end(); auto secondLast = --(--s.end()); if (s.size() == 2) { moves.emplace_back(*last, *first); int res = (*last) - (*first); s.erase(first); s.erase(last); s.insert(res); } else if (*secondLast > 0) { int res = (*first) - (*secondLast); moves.emplace_back(*first, *secondLast); s.erase(first); s.erase(secondLast); s.insert(res); } else { moves.emplace_back(*last, *first); int res = (*last) - (*first); s.erase(first); s.erase(last); s.insert(res); } } cout << (*s.begin()) << '\n'; for (ii m : moves) cout << m.first << " " << m.second << '\n'; return 0; }
[ "identifier.change", "call.arguments.change" ]
821,611
821,612
u925767073
cpp
p03007
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int n, a[N]; int main() { cin >> n; int Max = 1, Min = 1; for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); if (a[i] > a[Max]) Max = i; if (a[i] < a[Min]) Min = i; } if (Max == Min) Max = 2; long long sum = 0; for (int i = 1; i <= n; i++) if (i != Max && i != Min) sum += abs(a[i]); cout << (long long)a[Max] - a[Min] + sum << endl; for (int i = 1; i <= n; i++) if (i != Max && i != Min && a[i] >= 0) printf("%d %d\n", a[Min], a[i]), a[Min] -= a[i]; for (int i = 1; i <= n; i++) if (i != Max && i != Min && a[i] < 0) printf("%d %d\n", a[Max], a[i]), a[Max] += a[i]; printf("%d %d\n", a[Max], a[Min]); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int n, a[N]; int main() { cin >> n; int Max = 1, Min = 1; for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); if (a[i] > a[Max]) Max = i; if (a[i] < a[Min]) Min = i; } if (Max == Min) Max = 2; long long sum = 0; for (int i = 1; i <= n; i++) if (i != Max && i != Min) sum += abs(a[i]); cout << (long long)a[Max] - a[Min] + sum << endl; for (int i = 1; i <= n; i++) if (i != Max && i != Min && a[i] >= 0) printf("%d %d\n", a[Min], a[i]), a[Min] -= a[i]; for (int i = 1; i <= n; i++) if (i != Max && i != Min && a[i] < 0) printf("%d %d\n", a[Max], a[i]), a[Max] -= a[i]; printf("%d %d\n", a[Max], a[Min]); return 0; }
[ "expression.operator.change" ]
821,615
821,616
u027681381
cpp
p03007
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; ++i) #define REPR(i, n) for (int i = n; i >= 0; --i) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define FORR(i, a, b) for (int i = b - 1; i >= a; --i) #define p(s) cout << (s) << endl #define p2(s, t) cout << (s) << " " << (t) << endl #define ALL(v) (v).begin(), (v).end() #define m0(x) memset(x, 0, sizeof(x)) typedef long long ll; using namespace std; static const ll MOD = 1e9 + 7; static const ll INF = 1e18; static const int White = 0; static const int Gray = 1; static const int Black = 2; void pvector(vector<int> A) { cout << "[vector]"; for (int i = 0; i < A.size(); i++) { cout << A[i] << " "; } cout << endl; } int main() { ll N; cin >> N; vector<ll> A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } sort(ALL(A)); auto pos = lower_bound(ALL(A), 0); int idx; idx = distance(A.begin(), pos); ll sum = 0; if (idx == N) { int tmp = A[N - 1]; for (int i = 0; i < N - 1; i++) { sum -= A[i]; } sum += A[N - 1]; cout << sum << endl; for (int i = N - 2; i >= 0; i--) { cout << tmp << " "; tmp -= A[i]; cout << A[i] << endl; } } else if (idx == 0) { int tmp = A[0]; for (int i = 1; i < N; i++) { sum += A[i]; } sum -= A[0]; cout << sum << endl; for (int i = 1; i <= N - 2; i++) { cout << tmp << " "; tmp -= A[i]; cout << A[i] << endl; } cout << A[N - 1] << " " << tmp << endl; } else { int tmp = A[idx - 1]; for (int i = 0; i < N; i++) { sum += A[i]; } cout << sum << endl; for (int i = idx; i <= N - 2; i++) { cout << tmp << " "; tmp -= A[i]; cout << A[i] << endl; } cout << A[N - 1] << " " << tmp << endl; tmp = A[N - 1] - tmp; for (int i = 0; i <= idx - 2; i++) { cout << tmp << " "; tmp -= A[i]; cout << A[i] << endl; } } }
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; ++i) #define REPR(i, n) for (int i = n; i >= 0; --i) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define FORR(i, a, b) for (int i = b - 1; i >= a; --i) #define p(s) cout << (s) << endl #define p2(s, t) cout << (s) << " " << (t) << endl #define ALL(v) (v).begin(), (v).end() #define m0(x) memset(x, 0, sizeof(x)) typedef long long ll; using namespace std; static const ll MOD = 1e9 + 7; static const ll INF = 1e18; static const int White = 0; static const int Gray = 1; static const int Black = 2; void pvector(vector<int> A) { cout << "[vector]"; for (int i = 0; i < A.size(); i++) { cout << A[i] << " "; } cout << endl; } int main() { ll N; cin >> N; vector<ll> A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } sort(ALL(A)); auto pos = lower_bound(ALL(A), 0); // 0以上の最初の位置のiterator int idx; idx = distance(A.begin(), pos); // iteratorを配列の位置に変換 ll sum = 0; if (idx == N) { int tmp = A[N - 1]; for (int i = 0; i < N - 1; i++) { sum -= A[i]; } sum += A[N - 1]; cout << sum << endl; for (int i = N - 2; i >= 0; i--) { cout << tmp << " "; tmp -= A[i]; cout << A[i] << endl; } } else if (idx == 0) { int tmp = A[0]; for (int i = 1; i < N; i++) { sum += A[i]; } sum -= A[0]; cout << sum << endl; for (int i = 1; i <= N - 2; i++) { cout << tmp << " "; tmp -= A[i]; cout << A[i] << endl; } cout << A[N - 1] << " " << tmp << endl; } else { int tmp = A[idx - 1]; for (int i = 0; i < N; i++) { sum += llabs(A[i]); } cout << sum << endl; for (int i = idx; i <= N - 2; i++) { cout << tmp << " "; tmp -= A[i]; cout << A[i] << endl; } cout << A[N - 1] << " " << tmp << endl; tmp = A[N - 1] - tmp; for (int i = 0; i <= idx - 2; i++) { cout << tmp << " "; tmp -= A[i]; cout << A[i] << endl; } } }
[ "call.add", "call.arguments.change" ]
821,627
821,628
u839397805
cpp
p03007
#include <algorithm> #include <climits> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> using namespace std; #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) #define repf(i, m, n) for (int(i) = m; (i) < n; (i)++) #define all(v) (v).begin(), (v).end() #define ll long long #define vec(name, num) vector<ll> name((num), 0); #define op(i) cout << (i) << endl; #define ip(i) cin >> (i); #define opN cout << "No" << endl; #define opY cout << "Yes" << endl; #define opP cout << "Possible" << endl; #define opI cout << "Impossible" << endl; #define mat(name, fnum, snum) \ ; \ vector<vector<ll>> name((fnum), vector<ll>((snum), 0)); #define matC(name, fnum, snum) \ ; \ vector<vector<char>> name((fnum), vector<char>((snum), 0)); #define debugP \ int debug_point; \ cin >> debug_point; #define FI first #define SE second const ll MOD = 1e9 + 7; template <typename T> void putv(vector<T> &V) { // cout << "The elements in the vector are: " << endl; for (auto x : V) cout << x << " "; cout << endl; } ll pow_mod(ll fi, ll se, ll mod) { if (se == 0) { return 1; } if (se % 2) { return pow_mod(fi, se - 1, mod) * fi % mod; } ll t = pow_mod(fi, se / 2, mod); return t * t % mod; } template <class T> vector<T> getv(ll n) { vector<T> Vector_temp; rep(i, n) { T input; cin >> input; Vector_temp.emplace_back(input); } return Vector_temp; } ll gcd(ll c, ll b) { while (1) { if (c % b != 0) { ll tmp = b; b = c % b; c = tmp; } else { return b; } } } vector<pair<int, int>> Dir = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}}; /* <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3*/ int main() { ll n; cin >> n; vec(a, n); rep(i, n) { cin >> a[i]; } sort(all(a)); ll con = 0; rep(i, n) { if (con == 0) { if (a[i] >= 0) con = 1; else con = 2; } else if (con == 1) { if (a[i] < 0) con = 3; } else if (con == 2) { if (a[i] >= 0) con = 3; } } ll ans = 0; ll plus_head, minus_head; vector<ll> pl, mi; plus_head = a[n - 1]; ans += plus_head; minus_head = a[0]; ans -= minus_head; repf(i, 1, n - 1) { if (a[i] >= 0) { pl.push_back(a[i]); ans += a[i]; } else { mi.push_back(a[i]); ans -= a[i]; } } op(ans); rep(i, pl.size()) { cout << minus_head << " " << pl[i] << endl; minus_head = (minus_head - pl[i]); } rep(i, mi.size()) { cout << minus_head << " " << mi[i] << endl; minus_head = (minus_head - mi[i]); } cout << plus_head << " " << minus_head << endl; return 0; }
#include <algorithm> #include <climits> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> using namespace std; #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) #define repf(i, m, n) for (int(i) = m; (i) < n; (i)++) #define all(v) (v).begin(), (v).end() #define ll long long #define vec(name, num) vector<ll> name((num), 0); #define op(i) cout << (i) << endl; #define ip(i) cin >> (i); #define opN cout << "No" << endl; #define opY cout << "Yes" << endl; #define opP cout << "Possible" << endl; #define opI cout << "Impossible" << endl; #define mat(name, fnum, snum) \ ; \ vector<vector<ll>> name((fnum), vector<ll>((snum), 0)); #define matC(name, fnum, snum) \ ; \ vector<vector<char>> name((fnum), vector<char>((snum), 0)); #define debugP \ int debug_point; \ cin >> debug_point; #define FI first #define SE second const ll MOD = 1e9 + 7; template <typename T> void putv(vector<T> &V) { // cout << "The elements in the vector are: " << endl; for (auto x : V) cout << x << " "; cout << endl; } ll pow_mod(ll fi, ll se, ll mod) { if (se == 0) { return 1; } if (se % 2) { return pow_mod(fi, se - 1, mod) * fi % mod; } ll t = pow_mod(fi, se / 2, mod); return t * t % mod; } template <class T> vector<T> getv(ll n) { vector<T> Vector_temp; rep(i, n) { T input; cin >> input; Vector_temp.emplace_back(input); } return Vector_temp; } ll gcd(ll c, ll b) { while (1) { if (c % b != 0) { ll tmp = b; b = c % b; c = tmp; } else { return b; } } } vector<pair<int, int>> Dir = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}}; /* <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3*/ int main() { ll n; cin >> n; vec(a, n); rep(i, n) { cin >> a[i]; } sort(all(a)); ll con = 0; rep(i, n) { if (con == 0) { if (a[i] >= 0) con = 1; else con = 2; } else if (con == 1) { if (a[i] < 0) con = 3; } else if (con == 2) { if (a[i] >= 0) con = 3; } } ll ans = 0; ll plus_head, minus_head; vector<ll> pl, mi; plus_head = a[n - 1]; ans += plus_head; minus_head = a[0]; ans -= minus_head; repf(i, 1, n - 1) { if (a[i] >= 0) { pl.push_back(a[i]); ans += a[i]; } else { mi.push_back(a[i]); ans -= a[i]; } } op(ans); rep(i, pl.size()) { cout << minus_head << " " << pl[i] << endl; minus_head = (minus_head - pl[i]); } rep(i, mi.size()) { cout << plus_head << " " << mi[i] << endl; plus_head = (plus_head - mi[i]); } cout << plus_head << " " << minus_head << endl; return 0; }
[ "identifier.change", "io.output.change", "assignment.variable.change", "assignment.value.change", "expression.operation.binary.change" ]
821,629
821,630
u190234543
cpp
p03007
#include <bits/stdc++.h> using namespace std; int n; int a[100005]; vector<pair<int, int>> pairs; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } sort(a + 1, a + n + 1); for (int i = n; i >= 2; i--) { if (a[i] < 0) break; pairs.push_back(make_pair(a[1], a[i])); a[1] -= a[i]; } for (int i = 2; i <= n; i++) { if (a[i] >= 0) break; pairs.push_back(make_pair(a[n], a[i])); a[n] -= a[i]; } int ans = a[n] - a[1]; pairs.push_back(make_pair(a[n], a[1])); cout << ans << endl; for (int i = 0; i < pairs.size(); i++) { cout << pairs[i].first << " " << pairs[i].second << endl; } }
#include <bits/stdc++.h> using namespace std; int n; int a[100005]; vector<pair<int, int>> pairs; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } sort(a + 1, a + n + 1); for (int i = n - 1; i >= 2; i--) { if (a[i] < 0) break; pairs.push_back(make_pair(a[1], a[i])); a[1] -= a[i]; } for (int i = 2; i <= n - 1; i++) { if (a[i] >= 0) break; pairs.push_back(make_pair(a[n], a[i])); a[n] -= a[i]; } int ans = a[n] - a[1]; pairs.push_back(make_pair(a[n], a[1])); cout << ans << endl; for (int i = 0; i < pairs.size(); i++) { cout << pairs[i].first << " " << pairs[i].second << endl; } }
[ "control_flow.loop.for.initializer.change", "control_flow.loop.for.condition.change", "misc.off_by_one" ]
821,631
821,632
u185917548
cpp
p03007
//#include<stdio.h> #include <bits/stdc++.h> using namespace std; #define ll long long #define f_(i, a, b) for (int i = a; i >= b; i--) #define f(i, a, b) for (int i = a; i <= b; i++) const ll mod = 1000000007; int n, a[100005]; vector<pair<int, int>> ans; int main() { // freopen("","r",stdin); // freopen("","w",stdout); scanf("%d", &n); f(i, 1, n) scanf("%d", &a[i]); sort(a + 1, a + 1 + n); f_(i, n - 1, 2) { if (a[i] < 0) break; ans.push_back(make_pair(a[1], a[i])); a[1] -= a[i]; } f(i, 2, n - 1) { if (a[i] > 0) break; ans.push_back(make_pair(a[n], a[i])); a[n] -= a[i]; } ans.push_back(make_pair(a[n], a[1])); a[n] -= a[1]; printf("%d\n", a[n]); for (int i = 0; i < ans.size(); i++) printf("%d %d\n", ans[i].first, ans[i].second); return 0; }
//#include<stdio.h> #include <bits/stdc++.h> using namespace std; #define ll long long #define f_(i, a, b) for (int i = a; i >= b; i--) #define f(i, a, b) for (int i = a; i <= b; i++) const ll mod = 1000000007; int n, a[100005]; vector<pair<int, int>> ans; int main() { // freopen("","r",stdin); // freopen("","w",stdout); scanf("%d", &n); f(i, 1, n) scanf("%d", &a[i]); sort(a + 1, a + 1 + n); f_(i, n - 1, 2) { if (a[i] < 0) break; ans.push_back(make_pair(a[1], a[i])); a[1] -= a[i]; } f(i, 2, n - 1) { if (a[i] >= 0) break; ans.push_back(make_pair(a[n], a[i])); a[n] -= a[i]; } ans.push_back(make_pair(a[n], a[1])); a[n] -= a[1]; printf("%d\n", a[n]); for (int i = 0; i < ans.size(); i++) printf("%d %d\n", ans[i].first, ans[i].second); return 0; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
821,633
821,634
u108124198
cpp
p03007
//#include <bits/stdc++.h> #include <algorithm> #include <bitset> #include <cctype> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define FOR(i, j, k) for (int i = (int)(j); i < (int)(k); ++i) #define ROF(i, j, k) for (int i = (int)(j); i >= (int)(k); --i) #define FORLL(i, n, m) for (long long i = n; i < (long long)(m); i++) #define SORT(v, n) sort(v, v + n) #define REVERSE(v) reverse((v).begin(), (v).end()) using namespace std; using ll = long long; const ll MOD = 1000000007LL; typedef pair<int, int> P; ll ADD(ll x, ll y) { return (x + y) % MOD; } ll SUB(ll x, ll y) { return (x - y + MOD) % MOD; } ll MUL(ll x, ll y) { return x * y % MOD; } ll POW(ll x, ll e) { ll v = 1; for (; e; x = MUL(x, x), e >>= 1) if (e & 1) v = MUL(v, x); return v; } ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD - 2)); } template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; } int main(void) { ios_base::sync_with_stdio(false); cin.tie(0); ll n; cin >> n; vector<ll> a(n); deque<ll> dq; bool hasMinus = false, hasPlus = false; REP(i, n) cin >> a[i]; sort(a.begin(), a.end()); REP(i, n) { if (a[i] < 0) hasMinus = true; if (a[i] > 0) hasPlus = true; dq.push_back(a[i]); } vector<string> ans_s; ll val = 0LL; if (hasPlus && hasMinus) { ll fv = dq.front(); dq.pop_front(); ll bv = dq.back(); dq.pop_back(); // cerr << "current fv:" << fv << " bv:" << bv << endl; while (!dq.empty()) { ll fvv = dq.front(); dq.pop_front(); ll tmp; if (fvv < 0) { tmp = bv; bv += abs(fvv); } else { tmp = fv; fv -= abs(fvv); } ans_s.push_back(to_string(tmp) + " " + to_string(fvv)); } ans_s.push_back(to_string(bv) + " " + to_string(fv)); val = bv - fv; } else if (hasMinus) { ll fv = dq.front(); dq.pop_front(); ll bv = dq.back(); dq.pop_back(); while (!dq.empty()) { ll fvv = dq.front(); dq.pop_front(); ll tmp = bv; bv += fvv; ans_s.push_back(to_string(tmp) + " " + to_string(fvv)); } ans_s.push_back(to_string(bv) + " " + to_string(fv)); val = bv - fv; } else { ll fv = dq.front(); dq.pop_front(); ll bv = dq.back(); dq.pop_back(); while (!dq.empty()) { ll fvv = dq.front(); dq.pop_front(); ll tmp = fv; fv -= fvv; ans_s.push_back(to_string(tmp) + " " + to_string(fvv)); } ans_s.push_back(to_string(bv) + " " + to_string(fv)); val = bv - fv; } cout << val << endl; for (auto &e : ans_s) cout << e << endl; return 0; }
//#include <bits/stdc++.h> #include <algorithm> #include <bitset> #include <cctype> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define FOR(i, j, k) for (int i = (int)(j); i < (int)(k); ++i) #define ROF(i, j, k) for (int i = (int)(j); i >= (int)(k); --i) #define FORLL(i, n, m) for (long long i = n; i < (long long)(m); i++) #define SORT(v, n) sort(v, v + n) #define REVERSE(v) reverse((v).begin(), (v).end()) using namespace std; using ll = long long; const ll MOD = 1000000007LL; typedef pair<int, int> P; ll ADD(ll x, ll y) { return (x + y) % MOD; } ll SUB(ll x, ll y) { return (x - y + MOD) % MOD; } ll MUL(ll x, ll y) { return x * y % MOD; } ll POW(ll x, ll e) { ll v = 1; for (; e; x = MUL(x, x), e >>= 1) if (e & 1) v = MUL(v, x); return v; } ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD - 2)); } template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; } int main(void) { ios_base::sync_with_stdio(false); cin.tie(0); ll n; cin >> n; vector<ll> a(n); deque<ll> dq; bool hasMinus = false, hasPlus = false; REP(i, n) cin >> a[i]; sort(a.begin(), a.end()); REP(i, n) { if (a[i] < 0) hasMinus = true; if (a[i] > 0) hasPlus = true; dq.push_back(a[i]); } vector<string> ans_s; ll val = 0LL; if (hasPlus && hasMinus) { ll fv = dq.front(); dq.pop_front(); ll bv = dq.back(); dq.pop_back(); // cerr << "current fv:" << fv << " bv:" << bv << endl; while (!dq.empty()) { ll fvv = dq.front(); dq.pop_front(); ll tmp; if (fvv < 0) { tmp = bv; bv += abs(fvv); } else { tmp = fv; fv -= abs(fvv); } ans_s.push_back(to_string(tmp) + " " + to_string(fvv)); } ans_s.push_back(to_string(bv) + " " + to_string(fv)); val = bv - fv; } else if (hasMinus) { ll fv = dq.front(); dq.pop_front(); ll bv = dq.back(); dq.pop_back(); while (!dq.empty()) { ll fvv = dq.front(); dq.pop_front(); ll tmp = bv; bv -= fvv; ans_s.push_back(to_string(tmp) + " " + to_string(fvv)); } ans_s.push_back(to_string(bv) + " " + to_string(fv)); val = bv - fv; } else { ll fv = dq.front(); dq.pop_front(); ll bv = dq.back(); dq.pop_back(); while (!dq.empty()) { ll fvv = dq.front(); dq.pop_front(); ll tmp = fv; fv -= fvv; ans_s.push_back(to_string(tmp) + " " + to_string(fvv)); } ans_s.push_back(to_string(bv) + " " + to_string(fv)); val = bv - fv; } cout << val << endl; for (auto &e : ans_s) cout << e << endl; return 0; }
[ "expression.operator.change" ]
821,635
821,636
u783861517
cpp
p03007
#include <bits/stdc++.h> using namespace std; // Here's a small hint that helped motivate my solution. typedef long long int ll; int main() { // Suppose we have three terms x, y, and z. After subtracting z from y, we get // y-z, and after subtracting // that from x, we get x-y+z. As you can see, the z is being added now, since // it was subtracted twice. In general, subtracting a number an even number of // times is equivalent to adding that number. Can we take advantage of this // somehow? ll no; cin >> no; ll a; vector<ll> p, n; for (int i = 0; i < no; i++) { cin >> a; if (a > 0) p.push_back(a); if (a < 0) n.push_back(a); } ll b; int flag = 0; if (p.size() == 0) { sort(n.rbegin(), n.rend()); flag = 1; a = n[0]; b = n[1]; ll val = n[0] - n[1]; p.push_back(val); n.erase(n.begin(), n.begin() + 2); } if (n.size() == 0) { if (p.size() == 2) { sort(p.begin(), p.end()); cout << p[1] - p[0] << "\n" << p[1] << " " << p[0] << endl; return 0; } if (p.size() > 2) { sort(p.begin(), p.end()); a = p[0]; b = p[1]; ll val = p[0] - p[1]; n.push_back(val); p.erase(p.begin(), p.begin() + 2); flag = 1; } } // for(int i=0;i<p.size();i++) cout<<p[i]; // cout<<endl; // for(int i=0;i<n.size();i++) cout<<n[i]; // cout<<endl; ll sum = 0; ll s = 0; for (int i = 0; i < p.size(); i++) sum += p[i]; for (int i = 0; i < n.size(); i++) s += n[i]; s *= -1; sum += s; cout << sum << endl; if (flag) cout << a << " " << b << endl; if (p.size() != 0 && n.size() != 0) { ll val = n[0]; for (int i = 0; i < p.size() - 1; i++) { cout << val << " " << p[i] << endl; val = val - p[i]; } cout << p[p.size() - 1] << " " << val << endl; val = p[p.size() - 1] - val; for (int i = 1; i < n.size(); i++) { cout << val << " " << n[i] << endl; val = val - n[i]; } return 0; } }
#include <bits/stdc++.h> using namespace std; // Here's a small hint that helped motivate my solution. typedef long long int ll; int main() { // Suppose we have three terms x, y, and z. After subtracting z from y, we get // y-z, and after subtracting // that from x, we get x-y+z. As you can see, the z is being added now, since // it was subtracted twice. In general, subtracting a number an even number of // times is equivalent to adding that number. Can we take advantage of this // somehow? ll no; cin >> no; ll a; vector<ll> p, n; for (int i = 0; i < no; i++) { cin >> a; if (a >= 0) p.push_back(a); if (a < 0) n.push_back(a); } ll b; int flag = 0; if (p.size() == 0) { sort(n.rbegin(), n.rend()); flag = 1; a = n[0]; b = n[1]; ll val = n[0] - n[1]; p.push_back(val); n.erase(n.begin(), n.begin() + 2); } if (n.size() == 0) { if (p.size() == 2) { sort(p.begin(), p.end()); cout << p[1] - p[0] << "\n" << p[1] << " " << p[0] << endl; return 0; } if (p.size() > 2) { sort(p.begin(), p.end()); a = p[0]; b = p[1]; ll val = p[0] - p[1]; n.push_back(val); p.erase(p.begin(), p.begin() + 2); flag = 1; } } // for(int i=0;i<p.size();i++) cout<<p[i]; // cout<<endl; // for(int i=0;i<n.size();i++) cout<<n[i]; // cout<<endl; ll sum = 0; ll s = 0; for (int i = 0; i < p.size(); i++) sum += p[i]; for (int i = 0; i < n.size(); i++) s += n[i]; s *= -1; sum += s; cout << sum << endl; if (flag) cout << a << " " << b << endl; if (p.size() != 0 && n.size() != 0) { ll val = n[0]; for (int i = 0; i < p.size() - 1; i++) { cout << val << " " << p[i] << endl; val = val - p[i]; } cout << p[p.size() - 1] << " " << val << endl; val = p[p.size() - 1] - val; for (int i = 1; i < n.size(); i++) { cout << val << " " << n[i] << endl; val = val - n[i]; } return 0; } }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
821,651
821,652
u377622126
cpp
p03007
#include <bits/stdc++.h> #define fi first #define se second #define pii pair<int, int> #define mp make_pair #define pb push_back #define space putchar(' ') #define enter putchar('\n') #define eps 1e-10 #define ba 47 #define MAXN 100005 //#define ivorysi using namespace std; typedef long long int64; typedef unsigned int u32; typedef double db; template <class T> void read(T &res) { res = 0; T f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); } res *= f; } template <class T> void out(T x) { if (x < 0) { x = -x; putchar('-'); } if (x >= 10) { out(x / 10); } putchar('0' + x % 10); } int N, a[100005], cnt[2]; vector<pii> ans; int64 res = 0; void Solve() { read(N); for (int i = 1; i <= N; ++i) { read(a[i]); if (a[i] < 0) cnt[0]++; else cnt[1]++; } if (cnt[0] && cnt[1]) { int s, t; for (int i = 1; i <= N; ++i) res += abs(a[i]); for (int i = 1; i <= N; ++i) { if (a[i] > 0) s = i; if (a[i] < 0) t = i; } for (int i = 1; i <= N; ++i) { if (a[i] >= 0 && i != s) { ans.pb(mp(a[t], a[i])); a[t] -= a[i]; } } for (int i = 1; i <= N; ++i) { if (a[i] < 0) { ans.pb(mp(a[s], a[i])); a[s] -= a[i]; } } } else if (cnt[0]) { int p = 1; for (int i = 2; i <= N; ++i) { if (a[i] > a[p]) p = i; } res += a[p]; for (int i = 1; i <= N; ++i) { if (i != p) res += abs(a[i]); } for (int i = 1; i <= N; ++i) { if (i != p) { ans.pb(mp(a[p], a[i])); a[p] -= a[i]; } } } else { int p = 1, q; for (int i = 2; i <= N; ++i) { if (a[i] < a[p]) p = i; } res -= a[p]; for (int i = 1; i <= N; ++i) { if (i != p) res += a[i]; } if (p == 1) q = 2; else q = 1; for (int i = 1; i <= N; ++i) { if (i != p && i != q) { ans.pb(mp(a[p], a[i])); a[p] -= a[i]; } } ans.pb(mp(a[q], a[p])); } out(res); enter; for (auto t : ans) { out(t.fi); space; out(t.se); enter; } } int main() { #ifdef ivorysi freopen("f1.in", "r", stdin); #endif Solve(); }
#include <bits/stdc++.h> #define fi first #define se second #define pii pair<int, int> #define mp make_pair #define pb push_back #define space putchar(' ') #define enter putchar('\n') #define eps 1e-10 #define ba 47 #define MAXN 100005 //#define ivorysi using namespace std; typedef long long int64; typedef unsigned int u32; typedef double db; template <class T> void read(T &res) { res = 0; T f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); } res *= f; } template <class T> void out(T x) { if (x < 0) { x = -x; putchar('-'); } if (x >= 10) { out(x / 10); } putchar('0' + x % 10); } int N, a[100005], cnt[2]; vector<pii> ans; int64 res = 0; void Solve() { read(N); for (int i = 1; i <= N; ++i) { read(a[i]); if (a[i] < 0) cnt[0]++; else cnt[1]++; } if (cnt[0] && cnt[1]) { int s, t; for (int i = 1; i <= N; ++i) res += abs(a[i]); for (int i = 1; i <= N; ++i) { if (a[i] >= 0) s = i; if (a[i] < 0) t = i; } for (int i = 1; i <= N; ++i) { if (a[i] >= 0 && i != s) { ans.pb(mp(a[t], a[i])); a[t] -= a[i]; } } for (int i = 1; i <= N; ++i) { if (a[i] < 0) { ans.pb(mp(a[s], a[i])); a[s] -= a[i]; } } } else if (cnt[0]) { int p = 1; for (int i = 2; i <= N; ++i) { if (a[i] > a[p]) p = i; } res += a[p]; for (int i = 1; i <= N; ++i) { if (i != p) res += abs(a[i]); } for (int i = 1; i <= N; ++i) { if (i != p) { ans.pb(mp(a[p], a[i])); a[p] -= a[i]; } } } else { int p = 1, q; for (int i = 2; i <= N; ++i) { if (a[i] < a[p]) p = i; } res -= a[p]; for (int i = 1; i <= N; ++i) { if (i != p) res += a[i]; } if (p == 1) q = 2; else q = 1; for (int i = 1; i <= N; ++i) { if (i != p && i != q) { ans.pb(mp(a[p], a[i])); a[p] -= a[i]; } } ans.pb(mp(a[q], a[p])); } out(res); enter; for (auto t : ans) { out(t.fi); space; out(t.se); enter; } } int main() { #ifdef ivorysi freopen("f1.in", "r", stdin); #endif Solve(); }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
821,665
821,666
u845980916
cpp
p03007
#include <algorithm> #include <bitset> #include <climits> #include <complex> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define __int64 long long #define long __int64 #define REP(i, a, b) for (int i = a; i < b; i++) #define rep(i, n) REP(i, 0, n) const int Vec = 4; const int Vecy[Vec] = {0, -1, 0, 1}; const int Vecx[Vec] = {1, 0, -1, 0}; const int Modd = 1000000007; int n; multiset<int> a; int ans[100000][2]; int result; int in; int main() { cin >> n; rep(i, n) { cin >> in; a.insert(in); } for (int i = 0; i < n - 2; i++) { /* cout << "\t"; for(int j=0; j<a.size(); j++){ cout << a[j] << " "; } cout << endl; */ auto target = a.begin(); target++; auto bottom = a.end(); bottom--; if (*target <= 0) { ans[i][0] = *bottom; ans[i][1] = *target; a.erase(*target); a.erase(*bottom); a.insert(ans[i][0] - ans[i][1]); } else { ans[i][0] = *a.begin(); ans[i][1] = *target; a.erase(*target); a.erase(*a.begin()); a.insert(ans[i][0] - ans[i][1]); } } // cout << "\t"; // for(int j=0; j<a.size(); j++){ // cout << a[j] << " "; // } // cout << endl; auto itr = a.begin(); ans[n - 2][1] = *itr; itr++; ans[n - 2][0] = *itr; // cout << "a:" << ans[n-2][0] << "\tb:" << ans[n result = ans[n - 2][0] - ans[n - 2][1]; cout << result << endl; for (int i = 0; i < n - 1; i++) { cout << ans[i][0] << " " << ans[i][1] << endl; } return 0; }
#include <algorithm> #include <bitset> #include <climits> #include <complex> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define __int64 long long #define long __int64 #define REP(i, a, b) for (int i = a; i < b; i++) #define rep(i, n) REP(i, 0, n) const int Vec = 4; const int Vecy[Vec] = {0, -1, 0, 1}; const int Vecx[Vec] = {1, 0, -1, 0}; const int Modd = 1000000007; int n; multiset<int> a; int ans[100000][2]; int result; int in; int main() { cin >> n; rep(i, n) { cin >> in; a.insert(in); } for (int i = 0; i < n - 2; i++) { /* cout << "\t"; for(int j=0; j<a.size(); j++){ cout << a[j] << " "; } cout << endl; */ auto target = a.begin(); target++; auto bottom = a.end(); bottom--; if (*target <= 0) { ans[i][0] = *bottom; ans[i][1] = *target; a.erase(target); a.erase(bottom); a.insert(ans[i][0] - ans[i][1]); } else { ans[i][0] = *a.begin(); ans[i][1] = *target; a.erase(target); a.erase(a.begin()); a.insert(ans[i][0] - ans[i][1]); } } // cout << "\t"; // for(int j=0; j<a.size(); j++){ // cout << a[j] << " "; // } // cout << endl; auto itr = a.begin(); ans[n - 2][1] = *itr; itr++; ans[n - 2][0] = *itr; // cout << "a:" << ans[n-2][0] << "\tb:" << ans[n result = ans[n - 2][0] - ans[n - 2][1]; cout << result << endl; for (int i = 0; i < n - 1; i++) { cout << ans[i][0] << " " << ans[i][1] << endl; } return 0; }
[ "call.arguments.change" ]
821,667
821,668
u805346907
cpp
p03007
#include <algorithm> #include <bitset> #include <climits> #include <complex> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define __int64 long long #define long __int64 #define REP(i, a, b) for (int i = a; i < b; i++) #define rep(i, n) REP(i, 0, n) const int Vec = 4; const int Vecy[Vec] = {0, -1, 0, 1}; const int Vecx[Vec] = {1, 0, -1, 0}; const int Modd = 1000000007; int n; multiset<int> a; int ans[100000][2]; int result; int in; int main() { cin >> n; rep(i, n) { cin >> in; a.insert(in); } for (int i = 0; i < n - 2; i++) { /* cout << "\t"; for(int j=0; j<a.size(); j++){ cout << a[j] << " "; } cout << endl; */ auto target = a.begin(); target++; auto bottom = a.end(); bottom--; if (*target <= 0) { ans[i][0] = *bottom; ans[i][1] = *target; a.erase(*target); a.erase(*bottom); a.insert(ans[i][0] - ans[i][1]); } else { ans[i][0] = *a.begin(); ans[i][1] = *target; a.erase(*target); a.erase(*a.begin()); a.insert(ans[i][0] - ans[i][1]); } } // cout << "\t"; // for(int j=0; j<a.size(); j++){ // cout << a[j] << " "; // } // cout << endl; auto itr = a.begin(); ans[n - 2][1] = *itr; itr++; ans[n - 2][0] = *itr; // cout << "a:" << ans[n-2][0] << "\tb:" << ans[n result = ans[n - 2][0] - ans[n - 2][1]; cout << result << endl; for (int i = 0; i < n - 1; i++) { cout << ans[i][0] << " " << ans[i][1] << endl; } return 0; }
#include <algorithm> #include <bitset> #include <climits> #include <complex> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define __int64 long long #define long __int64 #define REP(i, a, b) for (int i = a; i < b; i++) #define rep(i, n) REP(i, 0, n) const int Vec = 4; const int Vecy[Vec] = {0, -1, 0, 1}; const int Vecx[Vec] = {1, 0, -1, 0}; const int Modd = 1000000007; int n; multiset<int> a; int ans[100000][2]; int result; int in; int main() { cin >> n; rep(i, n) { cin >> in; a.insert(in); } for (int i = 0; i < n - 2; i++) { /* cout << "\t"; for(int j=0; j<a.size(); j++){ cout << a[j] << " "; } cout << endl; */ auto target = a.begin(); target++; auto bottom = a.end(); bottom--; if (*target <= 0) { ans[i][0] = *bottom; ans[i][1] = *target; a.erase(target); a.erase(bottom); a.insert(ans[i][0] - ans[i][1]); } else { ans[i][0] = *a.begin(); ans[i][1] = *target; a.erase(target); a.erase(a.begin()); a.insert(ans[i][0] - ans[i][1]); } } // cout << "\t"; // for(int j=0; j<a.size(); j++){ // cout << a[j] << " "; // } // cout << endl; auto itr = a.begin(); ans[n - 2][1] = *itr; itr++; ans[n - 2][0] = *itr; // cout << "a:" << ans[n-2][0] << "\tb:" << ans[n result = ans[n - 2][0] - ans[n - 2][1]; cout << result << endl; for (int i = 0; i < n - 1; i++) { cout << ans[i][0] << " " << ans[i][1] << endl; } return 0; }
[ "call.arguments.change" ]
821,667
821,669
u805346907
cpp
p03007
#include <algorithm> #include <bitset> #include <complex> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define REP(i, m, n) for (int i = (int)m; i < (int)n; ++i) #define rep(i, n) REP(i, 0, n) typedef long long ll; typedef pair<int, int> pint; typedef pair<ll, int> pli; const int inf = 1e9 + 7; const ll longinf = 1LL << 60; const ll mod = 1000003; int main() { ll n; cin >> n; ll a[n]; rep(i, n) cin >> a[i]; sort(a, a + n); ll p = 0; // the first positive index of a while (a[p] <= 0) p++; if (n == 2) { cout << a[1] - a[0] << endl; cout << a[1] << ' ' << a[0] << endl; return 0; } if (p == 0) { int ans = 0; rep(i, n) { if (i == 0) ans -= a[i]; else ans += a[i]; } cout << ans << endl; for (int i = 1; i < n - 1; i++) { cout << a[0] << ' ' << a[i] << endl; a[0] -= a[i]; } cout << a[n - 1] << ' ' << a[0] << endl; return 0; } if (p == n - 1) { ll ans = 0; rep(i, n) { if (i == n - 1) ans += a[i]; else ans -= a[i]; } cout << ans << endl; for (int i = 0; i < n - 1; i++) { cout << a[n - 1] << ' ' << a[i] << endl; a[n - 1] -= a[i]; } return 0; } ll ans = 0; rep(i, n) { if (a[i] < 0) ans -= a[i]; else ans += a[i]; } cout << ans << endl; for (int i = p; i < n - 1; i++) { cout << a[0] << ' ' << a[i] << endl; a[0] -= a[i]; } for (int i = 1; i < p; i++) { cout << a[n - 1] << ' ' << a[i] << endl; a[n - 1] -= a[i]; } cout << a[n - 1] << ' ' << a[0] << endl; return 0; }
#include <algorithm> #include <bitset> #include <complex> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define REP(i, m, n) for (int i = (int)m; i < (int)n; ++i) #define rep(i, n) REP(i, 0, n) typedef long long ll; typedef pair<int, int> pint; typedef pair<ll, int> pli; const int inf = 1e9 + 7; const ll longinf = 1LL << 60; const ll mod = 1000003; int main() { ll n; cin >> n; ll a[n]; rep(i, n) cin >> a[i]; sort(a, a + n); ll p = 0; // the first positive index of a while (a[p] <= 0) p++; if (n == 2) { cout << a[1] - a[0] << endl; cout << a[1] << ' ' << a[0] << endl; return 0; } if (p == 0) { int ans = 0; rep(i, n) { if (i == 0) ans -= a[i]; else ans += a[i]; } cout << ans << endl; for (int i = 1; i < n - 1; i++) { cout << a[0] << ' ' << a[i] << endl; a[0] -= a[i]; } cout << a[n - 1] << ' ' << a[0] << endl; return 0; } if (p == n) { ll ans = 0; rep(i, n) { if (i == n - 1) ans += a[i]; else ans -= a[i]; } cout << ans << endl; for (int i = 0; i < n - 1; i++) { cout << a[n - 1] << ' ' << a[i] << endl; a[n - 1] -= a[i]; } return 0; } ll ans = 0; rep(i, n) { if (a[i] < 0) ans -= a[i]; else ans += a[i]; } cout << ans << endl; for (int i = p; i < n - 1; i++) { cout << a[0] << ' ' << a[i] << endl; a[0] -= a[i]; } for (int i = 1; i < p; i++) { cout << a[n - 1] << ' ' << a[i] << endl; a[n - 1] -= a[i]; } cout << a[n - 1] << ' ' << a[0] << endl; return 0; }
[ "expression.operation.binary.remove" ]
821,672
821,673
u906208439
cpp
p03007
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define rep(i, n) for (ll i = 0; i < n; i++) #define FOR(i, a, b) for (ll i = a; i < b; i++) #define len(v) ll(v.size()) template <class T> void cout_vec(const vector<T> &vec) { for (auto itr : vec) cout << itr << ' '; cout << '\n'; } typedef pair<ll, ll> P; const ll mod = 1e9 + 7; int main() { cin.tie(0); ios::sync_with_stdio(false); ll n; cin >> n; vector<ll> a(n); rep(i, n) cin >> a[i]; sort(begin(a), end(a)); ll now; vector<P> ans; if (a[0] < 0 && a.back() > 0) { ll sum = 0; rep(i, n) sum += abs(a[i]); cout << sum << endl; priority_queue<ll> pu, mi; rep(i, n - 1) { if (a[i] <= 0) mi.push(a[i]); else pu.push(a[i]); } while (!pu.empty()) { ll x = pu.top(); pu.pop(); ll y = mi.top(); mi.pop(); mi.push(y - x); cout << y << ' ' << x << endl; } now = a.back(); while (!mi.empty()) { cout << now << ' ' << mi.top() << endl; now -= mi.top(); mi.pop(); } } else if (a[0] > 0) { now = a[0]; rep(i, n - 2) { ans.push_back(P(now, a[i + 1])); now -= a[i + 1]; } ans.push_back(P(a[n - 1], now)); now = a[n - 1] - now; cout << now << endl; for (auto itr : ans) { cout << itr.first << ' ' << itr.second << endl; } } else { reverse(begin(a), end(a)); now = a[0]; rep(i, n - 1) { ans.push_back(P(now, a[i + 1])); now -= a[i + 1]; } cout << now << endl; for (auto itr : ans) { cout << itr.first << ' ' << itr.second << endl; } } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define rep(i, n) for (ll i = 0; i < n; i++) #define FOR(i, a, b) for (ll i = a; i < b; i++) #define len(v) ll(v.size()) template <class T> void cout_vec(const vector<T> &vec) { for (auto itr : vec) cout << itr << ' '; cout << '\n'; } typedef pair<ll, ll> P; const ll mod = 1e9 + 7; int main() { cin.tie(0); ios::sync_with_stdio(false); ll n; cin >> n; vector<ll> a(n); rep(i, n) cin >> a[i]; sort(begin(a), end(a)); ll now; vector<P> ans; if (a[0] <= 0 && a.back() >= 0) { ll sum = 0; rep(i, n) sum += abs(a[i]); cout << sum << endl; priority_queue<ll> pu, mi; rep(i, n - 1) { if (a[i] <= 0) mi.push(a[i]); else pu.push(a[i]); } while (!pu.empty()) { ll x = pu.top(); pu.pop(); ll y = mi.top(); mi.pop(); mi.push(y - x); cout << y << ' ' << x << endl; } now = a.back(); while (!mi.empty()) { cout << now << ' ' << mi.top() << endl; now -= mi.top(); mi.pop(); } } else if (a[0] > 0) { now = a[0]; rep(i, n - 2) { ans.push_back(P(now, a[i + 1])); now -= a[i + 1]; } ans.push_back(P(a[n - 1], now)); now = a[n - 1] - now; cout << now << endl; for (auto itr : ans) { cout << itr.first << ' ' << itr.second << endl; } } else { reverse(begin(a), end(a)); now = a[0]; rep(i, n - 1) { ans.push_back(P(now, a[i + 1])); now -= a[i + 1]; } cout << now << endl; for (auto itr : ans) { cout << itr.first << ' ' << itr.second << endl; } } }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
821,674
821,675
u340010271
cpp
p03007
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <utility> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) #define rep1(i, n) for (int i = 1; i <= n; i++) #define prin(arg) cout << arg << "\n" #define prin2(arg1, arg2) cout << arg1 << " " << arg2 << "\n" #define fill(arg, n) memset(arg, n, sizeof(arg)) #define mp make_pair #define pb push_back using namespace std; typedef long long ll; typedef pair<int, int> pi; typedef vector<int> vi; typedef vector<ll> vll; typedef set<int> si; typedef string str; const int INF = 1e+9; const ll INFLL = 1e+17; const ll MOD = 1e+9 + 7; int N; ll A[100010]; vll p, m, v; int main() { cin >> N; rep(i, N) { cin >> A[i]; } sort(A, A + N); ll mx = A[N - 1]; ll mn = A[0]; rep1(i, N - 2) { if (A[i] >= 0) p.pb(A[i]); else m.pb(A[i]); } int ps = p.size(), ms = m.size(); ll sum = 0; rep(i, ps) sum += p[i]; rep(i, ms) sum += m[i]; sum += mx; sum -= mn; prin(sum); ll y = mn; rep(i, ps) { prin2(y, p[i]); y -= p[i]; } ll x = mx; rep(i, ms) { prin2(x, m[i]); x -= m[i]; } prin2(x, y); return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <utility> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) #define rep1(i, n) for (int i = 1; i <= n; i++) #define prin(arg) cout << arg << "\n" #define prin2(arg1, arg2) cout << arg1 << " " << arg2 << "\n" #define fill(arg, n) memset(arg, n, sizeof(arg)) #define mp make_pair #define pb push_back using namespace std; typedef long long ll; typedef pair<int, int> pi; typedef vector<int> vi; typedef vector<ll> vll; typedef set<int> si; typedef string str; const int INF = 1e+9; const ll INFLL = 1e+17; const ll MOD = 1e+9 + 7; int N; ll A[100010]; vll p, m, v; int main() { cin >> N; rep(i, N) { cin >> A[i]; } sort(A, A + N); ll mx = A[N - 1]; ll mn = A[0]; rep1(i, N - 2) { if (A[i] >= 0) p.pb(A[i]); else m.pb(A[i]); } int ps = p.size(), ms = m.size(); ll sum = 0; rep(i, ps) sum += p[i]; rep(i, ms) sum -= m[i]; sum += mx; sum -= mn; prin(sum); ll y = mn; rep(i, ps) { prin2(y, p[i]); y -= p[i]; } ll x = mx; rep(i, ms) { prin2(x, m[i]); x -= m[i]; } prin2(x, y); return 0; }
[ "expression.operator.change" ]
821,678
821,679
u110996038
cpp
p03007
#include <algorithm> #include <iostream> #include <vector> using namespace std; #define int long long signed main() { int n; cin >> n; vector<int> a(n); for (int i = 0, i_len = (int)n; i < i_len; ++i) cin >> a[i]; sort(a.begin(), a.end()); bool isplus[100010]; isplus[0] = false; isplus[n - 1] = true; for (int i = 1; i < n - 1; ++i) { isplus[i] = (a[i] > 0); } int ans = 0; for (int i = 0; i < n; ++i) { if (isplus[i]) { ans += a[i]; } else { ans -= a[i]; } } cout << ans << endl; int now = a[0]; for (int i = 1; i < n - 1; ++i) { if (isplus[i]) { cout << now << " " << a[i] << endl; now -= a[i]; } } int now2 = a[n - 1]; for (int i = 1; i < n - 1; ++i) { if (!isplus[i]) { cout << now2 << " " << a[i] << endl; now -= a[i]; } } cout << now2 << " " << now << endl; return 0; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; #define int long long signed main() { int n; cin >> n; vector<int> a(n); for (int i = 0, i_len = (int)n; i < i_len; ++i) cin >> a[i]; sort(a.begin(), a.end()); bool isplus[100010]; isplus[0] = false; isplus[n - 1] = true; for (int i = 1; i < n - 1; ++i) { isplus[i] = (a[i] > 0); } int ans = 0; for (int i = 0; i < n; ++i) { if (isplus[i]) { ans += a[i]; } else { ans -= a[i]; } } cout << ans << endl; int now = a[0]; for (int i = 1; i < n - 1; ++i) { if (isplus[i]) { cout << now << " " << a[i] << endl; now -= a[i]; } } int now2 = a[n - 1]; for (int i = 1; i < n - 1; ++i) { if (!isplus[i]) { cout << now2 << " " << a[i] << endl; now2 -= a[i]; } } cout << now2 << " " << now << endl; return 0; }
[ "assignment.variable.change", "identifier.change" ]
821,684
821,685
u509680664
cpp
p03007
#include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define MOD (1000000007) using namespace std; typedef long long int Int; int N; int A[100005], neg[100005]; int main(void) { cin >> N; for (int i = 1; i <= N; i++) { cin >> A[i]; } sort(A + 1, A + N + 1); for (int i = 2; i <= N - 1; i++) { if (A[i] < 0) neg[i] = -1; else neg[i] = 1; } neg[1] = -1; neg[N] = 1; int ans = 0; for (int i = 1; i <= N; i++) { ans += neg[i] * A[i]; } cout << ans << endl; for (int i = 2; i <= N - 1; i++) { if (neg[i] == 1) { cout << A[0] << " " << A[i] << endl; A[0] -= A[i]; } } for (int i = 1; i < N; i++) { if (neg[i] == -1) { cout << A[N] << " " << A[i] << endl; A[N] -= A[i]; } } return 0; }
#include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define MOD (1000000007) using namespace std; typedef long long int Int; int N; int A[100005], neg[100005]; int main(void) { cin >> N; for (int i = 1; i <= N; i++) { cin >> A[i]; } sort(A + 1, A + N + 1); for (int i = 2; i <= N - 1; i++) { if (A[i] < 0) neg[i] = -1; else neg[i] = 1; } neg[1] = -1; neg[N] = 1; int ans = 0; for (int i = 1; i <= N; i++) { ans += neg[i] * A[i]; } cout << ans << endl; for (int i = 2; i <= N - 1; i++) { if (neg[i] == 1) { cout << A[1] << " " << A[i] << endl; A[1] -= A[i]; } } for (int i = 1; i < N; i++) { if (neg[i] == -1) { cout << A[N] << " " << A[i] << endl; A[N] -= A[i]; } } return 0; }
[ "literal.number.change", "variable_access.subscript.index.change", "io.output.change", "assignment.variable.change" ]
821,692
821,693
u498141549
cpp
p03007
#include <algorithm> #include <iostream> #include <map> #include <set> #include <vector> using namespace std; int N; vector<int> V; int main(void) { // Your code here! cin >> N; int a; for (int i = 0; i < N; i++) { cin >> a; V.push_back(a); } sort(V.begin(), V.end()); int sum = 0; for (int i = 0; i < V.size(); i++) sum += abs(V[i]); if (V.front() > 0) sum -= 2 * V.front(); if (V.back() < 0) sum += 2 * V.back(); cout << sum << endl; int f = V.front(); for (int i = 0; i < N - 1; i++) { if (V[i] >= 0) { cout << f << " " << V[i] << endl; f -= V[i]; } } cout << V.back() << " " << f << endl; f = V.back() - f; for (int i = 1; i < N - 1; i++) { if (V[i] < 0) { cout << f << " " << V[i] << endl; f -= V[i]; } } }
#include <algorithm> #include <iostream> #include <map> #include <set> #include <vector> using namespace std; int N; vector<int> V; int main(void) { // Your code here! cin >> N; int a; for (int i = 0; i < N; i++) { cin >> a; V.push_back(a); } sort(V.begin(), V.end()); int sum = 0; for (int i = 0; i < V.size(); i++) sum += abs(V[i]); if (V.front() > 0) sum -= 2 * V.front(); if (V.back() < 0) sum += 2 * V.back(); cout << sum << endl; int f = V.front(); for (int i = 1; i < N - 1; i++) { if (V[i] >= 0) { cout << f << " " << V[i] << endl; f -= V[i]; } } cout << V.back() << " " << f << endl; f = V.back() - f; for (int i = 1; i < N - 1; i++) { if (V[i] < 0) { cout << f << " " << V[i] << endl; f -= V[i]; } } }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one" ]
821,700
821,701
u279137361
cpp
p03007
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cmath> #include <cstdint> #include <cstdio> #include <cstring> #include <deque> #include <fstream> #include <functional> #include <iostream> #include <limits> #include <map> #include <numeric> #include <queue> #include <set> #include <vector> using namespace std; using ll = long long; #define fst first #define snd second /* clang-format off */ template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; }; template <class T> struct _vec<T, 0> { using type = T; }; template <class T, size_t D> using vec = typename _vec<T, D>::type; template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); } template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); } template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; } template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; } /* clang-format on */ int main() { #ifdef DEBUG ifstream ifs("in.txt"); cin.rdbuf(ifs.rdbuf()); #endif int N; while (cin >> N) { vector<ll> A(N); for (ll &x : A) cin >> x; sort(A.begin(), A.end()); vector<ll> L, R; ll M = A.back() - A.front(); for (int i = 1; i < N - 1; i++) { if (A[i] < 0) { L.push_back(A[i]); } else { R.push_back(A[i]); } M += abs(A[i]); } cout << M << endl; ll lsum = A.back(), rsum = A.front(); for (ll x : L) { cout << lsum << " " << x << endl; lsum += x; } for (ll x : R) { cout << x << " " << rsum << endl; rsum = x - rsum; } cout << lsum << " " << rsum << endl; } return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cmath> #include <cstdint> #include <cstdio> #include <cstring> #include <deque> #include <fstream> #include <functional> #include <iostream> #include <limits> #include <map> #include <numeric> #include <queue> #include <set> #include <vector> using namespace std; using ll = long long; #define fst first #define snd second /* clang-format off */ template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; }; template <class T> struct _vec<T, 0> { using type = T; }; template <class T, size_t D> using vec = typename _vec<T, D>::type; template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); } template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); } template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; } template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; } /* clang-format on */ int main() { #ifdef DEBUG ifstream ifs("in.txt"); cin.rdbuf(ifs.rdbuf()); #endif int N; while (cin >> N) { vector<ll> A(N); for (ll &x : A) cin >> x; sort(A.begin(), A.end()); vector<ll> L, R; ll M = A.back() - A.front(); for (int i = 1; i < N - 1; i++) { if (A[i] < 0) { L.push_back(A[i]); } else { R.push_back(A[i]); } M += abs(A[i]); } cout << M << endl; ll lsum = A.back(), rsum = A.front(); for (ll x : L) { cout << lsum << " " << x << endl; lsum -= x; } for (ll x : R) { cout << rsum << " " << x << endl; rsum -= x; } cout << lsum << " " << rsum << endl; } return 0; }
[ "expression.operator.change", "identifier.change", "io.output.change", "assignment.value.change", "expression.operation.binary.remove" ]
821,718
821,719
u107292917
cpp
p03007
#include <bits/stdc++.h> #define EM 100000000 using namespace std; using LL = long long; using P = pair<LL, LL>; LL LINF = 1e18; int INF = 1e9; using vint = vector<int>; using vLL = vector<LL>; using vvint = vector<vector<int>>; using vvLL = vector<vector<LL>>; int main() { int N; cin >> N; vint a(N); for (int i = 0; i < N; i++) cin >> a[i]; sort(a.begin(), a.end()); vector<P> ans; int id = N - 1; for (int i = 0; i < N; i++) { if (a[i] > 0) { id = i; break; } } for (int i = id + !id; i < N - 1; i++) { ans.push_back(P(a[max(0, id - 1)], a[i + !id])); a[max(0, id - 1)] -= a[i + !id]; } for (int i = 0; i < id + !id; i++) { ans.push_back(P(a[N - 1], a[i])); a[N - 1] -= a[i]; } cout << a[N - 1] << endl; for (auto an : ans) cout << an.first << " " << an.second << endl; }
#include <bits/stdc++.h> #define EM 100000000 using namespace std; using LL = long long; using P = pair<LL, LL>; LL LINF = 1e18; int INF = 1e9; using vint = vector<int>; using vLL = vector<LL>; using vvint = vector<vector<int>>; using vvLL = vector<vector<LL>>; int main() { int N; cin >> N; vint a(N); for (int i = 0; i < N; i++) cin >> a[i]; sort(a.begin(), a.end()); vector<P> ans; int id = N - 1; for (int i = 0; i < N; i++) { if (a[i] > 0) { id = i; break; } } for (int i = id + !id; i < N - 1; i++) { ans.push_back(P(a[max(0, id - 1)], a[i])); a[max(0, id - 1)] -= a[i]; } for (int i = 0; i < id + !id; i++) { ans.push_back(P(a[N - 1], a[i])); a[N - 1] -= a[i]; } cout << a[N - 1] << endl; for (auto an : ans) cout << an.first << " " << an.second << endl; }
[ "expression.operation.binary.remove" ]
821,725
821,726
u510175787
cpp
p03007
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <string> #include <utility> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(a) (a).begin(), (a).end() typedef long long lint; typedef pair<int, int> P; #define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0])) int main() { int N; cin >> N; vector<int> A; int a; REP(i, N) { cin >> a; A.push_back(a); } sort(ALL(A)); vector<int> minus; vector<int> plus; // minus.push_back(A[0]); // plus.push_back(A[N-1]); FOR(i, 1, N - 1) { if (A[i] > 0) plus.push_back(A[i]); else minus.push_back(A[i]); } lint ans = 0; ans += A[N - 1] - A[0]; for (auto i : minus) ans -= i; for (auto i : plus) ans += i; cout << ans << endl; int tmp = A[0]; for (auto i : plus) { cout << tmp << " " << i << endl; tmp -= i; } lint tmp2 = A[N - 1]; for (auto i : minus) { cout << tmp2 << " " << i << endl; tmp2 -= i; } cout << A[N - 1] << " " << tmp << endl; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <string> #include <utility> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(a) (a).begin(), (a).end() typedef long long lint; typedef pair<int, int> P; #define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0])) int main() { int N; cin >> N; vector<int> A; int a; REP(i, N) { cin >> a; A.push_back(a); } sort(ALL(A)); vector<int> minus; vector<int> plus; // minus.push_back(A[0]); // plus.push_back(A[N-1]); FOR(i, 1, N - 1) { if (A[i] > 0) plus.push_back(A[i]); else minus.push_back(A[i]); } lint ans = 0; ans += A[N - 1] - A[0]; for (auto i : minus) ans -= i; for (auto i : plus) ans += i; cout << ans << endl; int tmp = A[0]; for (auto i : plus) { cout << tmp << " " << i << endl; tmp -= i; } lint tmp2 = A[N - 1]; for (auto i : minus) { cout << tmp2 << " " << i << endl; tmp2 -= i; } cout << tmp2 << " " << tmp << endl; }
[ "io.output.change" ]
821,733
821,734
u380391081
cpp
p03007
#include <algorithm> #include <cmath> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <string> #include <vector> typedef long double ld; typedef long long ll; const ll INF = (ll)1e18 + 1; const ll MOD = 1e9 + 7; // Split namespace util { std::vector<std::string> split(std::string s, char delimiter) { std::vector<std::string> vs; std::string sub; for (auto c : s) { if (c == delimiter) vs.push_back(sub), sub.clear(); else sub += c; } vs.push_back(sub); return vs; } } // namespace util // Minimum, Maximum template <class T> T minimum(T head, T tail) { return std::min(head, tail); } template <class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); } template <class T> T maximum(T head, T tail) { return std::max(head, tail); } template <class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); } // Output template <class T, class S> std::ostream &operator<<(std::ostream &os, std::pair<T, S> p) { return os << "(" << p.first << " " << p.second << ")"; } template <class T> std::ostream &operator<<(std::ostream &os, std::vector<T> v) { for (ll i = 0; i < (ll)v.size(); i++) { os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; } // os << v[0]; for (ll i = 1; i < (ll)v.size(); i++){ os << " " << v[i]; } return os; } template <class T, class S> std::ostream &operator<<(std::ostream &os, std::map<T, S> m) { ll i = 0; for (auto p : m) { os << " [" << i << "]" << p.first << "->" << p.second; i++; } return os; } void print() { std::cout << std::endl; } template <typename H> void print(H head) { std::cout << head << std::endl; } template <typename H, typename... T> void print(H head, T... tail) { std::cout << head << " ", print(tail...); } int main() { ll N; std::cin >> N; std::vector<ll> va(N, 0LL); for (ll i = 0; i < N; i++) { std::cin >> va[i]; } std::sort(va.begin(), va.end()); std::vector<std::pair<ll, ll>> vans; ll ans = 0LL; if (va[0] >= 0) { for (ll i = 1; i < N - 1; i++) { vans.push_back({va[0], va[i]}); va[0] -= va[i]; } vans.push_back({va[N - 1], va[0]}); ans = va[N - 1] - va[0]; } else if (va[N - 1] <= 0) { for (ll i = N - 1; i >= 0; i--) { vans.push_back({va[N - 1], va[i]}); va[N - 1] -= va[i]; } ans = va[N - 1]; } else { for (ll i = 1; i < N - 1; i++) { if (va[i] >= 0) { vans.push_back({va[0], va[i]}); va[0] -= va[i]; } } for (ll i = 0; i < N - 1; i++) { if (va[i] < 0) { vans.push_back({va[N - 1], va[i]}); va[N - 1] -= va[i]; } } ans = va[N - 1]; } print(ans); for (auto &p : vans) { print(p.first, p.second); } return 0; }
#include <algorithm> #include <cmath> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <string> #include <vector> typedef long double ld; typedef long long ll; const ll INF = (ll)1e18 + 1; const ll MOD = 1e9 + 7; // Split namespace util { std::vector<std::string> split(std::string s, char delimiter) { std::vector<std::string> vs; std::string sub; for (auto c : s) { if (c == delimiter) vs.push_back(sub), sub.clear(); else sub += c; } vs.push_back(sub); return vs; } } // namespace util // Minimum, Maximum template <class T> T minimum(T head, T tail) { return std::min(head, tail); } template <class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); } template <class T> T maximum(T head, T tail) { return std::max(head, tail); } template <class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); } // Output template <class T, class S> std::ostream &operator<<(std::ostream &os, std::pair<T, S> p) { return os << "(" << p.first << " " << p.second << ")"; } template <class T> std::ostream &operator<<(std::ostream &os, std::vector<T> v) { for (ll i = 0; i < (ll)v.size(); i++) { os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; } // os << v[0]; for (ll i = 1; i < (ll)v.size(); i++){ os << " " << v[i]; } return os; } template <class T, class S> std::ostream &operator<<(std::ostream &os, std::map<T, S> m) { ll i = 0; for (auto p : m) { os << " [" << i << "]" << p.first << "->" << p.second; i++; } return os; } void print() { std::cout << std::endl; } template <typename H> void print(H head) { std::cout << head << std::endl; } template <typename H, typename... T> void print(H head, T... tail) { std::cout << head << " ", print(tail...); } int main() { ll N; std::cin >> N; std::vector<ll> va(N, 0LL); for (ll i = 0; i < N; i++) { std::cin >> va[i]; } std::sort(va.begin(), va.end()); std::vector<std::pair<ll, ll>> vans; ll ans = 0LL; if (va[0] >= 0) { for (ll i = 1; i < N - 1; i++) { vans.push_back({va[0], va[i]}); va[0] -= va[i]; } vans.push_back({va[N - 1], va[0]}); ans = va[N - 1] - va[0]; } else if (va[N - 1] <= 0) { for (ll i = N - 2; i >= 0; i--) { vans.push_back({va[N - 1], va[i]}); va[N - 1] -= va[i]; } ans = va[N - 1]; } else { for (ll i = 1; i < N - 1; i++) { if (va[i] >= 0) { vans.push_back({va[0], va[i]}); va[0] -= va[i]; } } for (ll i = 0; i < N - 1; i++) { if (va[i] < 0) { vans.push_back({va[N - 1], va[i]}); va[N - 1] -= va[i]; } } ans = va[N - 1]; } print(ans); for (auto &p : vans) { print(p.first, p.second); } return 0; }
[ "literal.number.change", "control_flow.loop.for.initializer.change", "expression.off_by_one", "expression.operation.binary.change" ]
821,735
821,736
u343930666
cpp
p03007
#include "bits/stdc++.h" using namespace std; void solve(void) { int n; cin >> n; vector<int> xs(n), as, bs; int pc = 0, nc = 0; for (int &x : xs) { cin >> x; if (x >= 0) pc++; else nc++; } sort(xs.begin(), xs.end()); if (pc == 0) { nc--; pc++; } else if (nc == 0) { pc--; nc++; } long res = xs[0], res2 = xs[n - 1]; for (int i = nc; i < n - 1; i++) { as.push_back(res); bs.push_back(xs[i]); res -= xs[i]; } for (int i = 1; i < nc; i++) { as.push_back(res2); bs.push_back(xs[i]); res -= xs[i]; } as.push_back(res2); bs.push_back(res); res2 -= res; cout << res2 << '\n'; for (int i = 0; i < n - 1; i++) { cout << as[i] << ' ' << bs[i] << '\n'; } } int main() { solve(); // cout << "yui(*-v・)yui" << endl; return 0; }
#include "bits/stdc++.h" using namespace std; void solve(void) { int n; cin >> n; vector<int> xs(n), as, bs; int pc = 0, nc = 0; for (int &x : xs) { cin >> x; if (x >= 0) pc++; else nc++; } sort(xs.begin(), xs.end()); if (pc == 0) { nc--; pc++; } else if (nc == 0) { pc--; nc++; } int res = xs[0], res2 = xs[n - 1]; for (int i = nc; i < n - 1; i++) { as.push_back(res); bs.push_back(xs[i]); res -= xs[i]; } for (int i = 1; i < nc; i++) { as.push_back(res2); bs.push_back(xs[i]); res2 -= xs[i]; } as.push_back(res2); bs.push_back(res); res2 -= res; cout << res2 << '\n'; for (int i = 0; i < n - 1; i++) { cout << as[i] << ' ' << bs[i] << '\n'; } } int main() { solve(); // cout << "yui(*-v・)yui" << endl; return 0; }
[ "variable_declaration.type.primitive.change", "assignment.variable.change", "identifier.change" ]
821,737
821,738
u344412812
cpp
p03007
#include "bits/stdc++.h" using namespace std; void solve(void) { int n; cin >> n; vector<int> xs(n), as, bs; int pc = 0, nc = 0; for (int &x : xs) { cin >> x; if (x >= 0) pc++; else nc++; } sort(xs.begin(), xs.end()); if (pc == 0) { nc--; pc++; } else if (nc == 0) { pc--; nc++; } long res = xs[0], res2 = xs[n - 1]; for (int i = nc; i < n - 1; i++) { as.push_back(res); bs.push_back(xs[i]); res -= xs[i]; } for (int i = 1; i < nc; i++) { as.push_back(res2); bs.push_back(xs[i]); res -= xs[i]; } as.push_back(res2); bs.push_back(res); res2 -= res; cout << res2 << '\n'; for (int i = 0; i < n - 1; i++) { cout << as[i] << ' ' << bs[i] << '\n'; } } int main() { solve(); // cout << "yui(*-v・)yui" << endl; return 0; }
#include "bits/stdc++.h" using namespace std; void solve(void) { int n; cin >> n; vector<int> xs(n), as, bs; int pc = 0, nc = 0; for (int &x : xs) { cin >> x; if (x >= 0) pc++; else nc++; } sort(xs.begin(), xs.end()); if (pc == 0) { nc--; pc++; } else if (nc == 0) { pc--; nc++; } long res = xs[0], res2 = xs[n - 1]; for (int i = nc; i < n - 1; i++) { as.push_back(res); bs.push_back(xs[i]); res -= xs[i]; } for (int i = 1; i < nc; i++) { as.push_back(res2); bs.push_back(xs[i]); res2 -= xs[i]; } as.push_back(res2); bs.push_back(res); res2 -= res; cout << res2 << '\n'; for (int i = 0; i < n - 1; i++) { cout << as[i] << ' ' << bs[i] << '\n'; } } int main() { solve(); // cout << "yui(*-v・)yui" << endl; return 0; }
[ "assignment.variable.change", "identifier.change" ]
821,737
821,739
u344412812
cpp
p03007
#include <bits/stdc++.h> using namespace std; #define REP(i, N) for (int i = 0; i < N; ++i) #define MAX_I INT_MAX // 1e9 #define MIN_I INT_MIN //-1e9 #define MAX_UI UINT_MAX // 1e9 #define MAX_LL LLONG_MAX // 1e18 #define MIN_LL LLONG_MIN //-1e18 #define MAX_ULL ULLONG_MAX // 1e19 typedef long long ll; typedef pair<int, int> PII; typedef pair<char, char> PCC; typedef pair<ll, ll> PLL; typedef pair<char, int> PCI; typedef pair<int, char> PIC; typedef pair<ll, int> PLI; typedef pair<int, ll> PIL; typedef pair<ll, char> PLC; typedef pair<char, ll> PCL; int main(void) { ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(15); int N; cin >> N; vector<ll> v(N); REP(i, N) cin >> v[i]; sort(v.begin(), v.end(), greater<ll>()); queue<PLL> ans; ll maximum = v[0], minimum = v[N - 1]; REP(i, N - 2) { if (v[i + 1] >= 0) { ans.push(PLL(minimum, v[i + 1])); minimum -= v[i + 1]; } else { ans.push(PLL(maximum, v[i + 1])); maximum += v[i + 1]; } } ans.push(PLL(maximum, minimum)); cout << maximum - minimum << endl; while (!ans.empty()) { cout << ans.front().first << " " << ans.front().second << endl; ans.pop(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, N) for (int i = 0; i < N; ++i) #define MAX_I INT_MAX // 1e9 #define MIN_I INT_MIN //-1e9 #define MAX_UI UINT_MAX // 1e9 #define MAX_LL LLONG_MAX // 1e18 #define MIN_LL LLONG_MIN //-1e18 #define MAX_ULL ULLONG_MAX // 1e19 typedef long long ll; typedef pair<int, int> PII; typedef pair<char, char> PCC; typedef pair<ll, ll> PLL; typedef pair<char, int> PCI; typedef pair<int, char> PIC; typedef pair<ll, int> PLI; typedef pair<int, ll> PIL; typedef pair<ll, char> PLC; typedef pair<char, ll> PCL; int main(void) { ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(15); int N; cin >> N; vector<ll> v(N); REP(i, N) cin >> v[i]; sort(v.begin(), v.end(), greater<ll>()); queue<PLL> ans; ll maximum = v[0], minimum = v[N - 1]; REP(i, N - 2) { if (v[i + 1] >= 0) { ans.push(PLL(minimum, v[i + 1])); minimum -= v[i + 1]; } else { ans.push(PLL(maximum, v[i + 1])); maximum -= v[i + 1]; } } ans.push(PLL(maximum, minimum)); cout << maximum - minimum << endl; while (!ans.empty()) { cout << ans.front().first << " " << ans.front().second << endl; ans.pop(); } return 0; }
[ "expression.operator.change" ]
821,742
821,743
u069450081
cpp
p03007
#define DEBUG 0 /** * File : C.cpp * Author : Kazune Takahashi * Created : 6/15/2019, 9:15:16 PM * Powered by Visual Studio Code */ #include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <chrono> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> using namespace std; #define maxs(x, y) (x = max(x, y)) #define mins(x, y) (x = min(x, y)) typedef long long ll; void Yes() { cout << "Yes" << endl; exit(0); } void No() { cout << "No" << endl; exit(0); } const int MAX_SIZE = 1000010; class mint { public: static ll MOD; ll x; mint() : x(0) {} mint(ll x) : x(x % MOD) {} mint operator-() const { return mint(0) - *this; } mint &operator+=(const mint &a) { if ((x += a.x) >= MOD) { x -= MOD; } return *this; } mint &operator-=(const mint &a) { return *this += -a; } mint &operator*=(const mint &a) { (x *= a.x) %= MOD; return *this; } mint &operator/=(const mint &a) { return (*this *= power(MOD - 2)); } mint operator+(const mint &a) const { return mint(*this) += a; } mint operator-(const mint &a) const { return mint(*this) -= a; } mint operator*(const mint &a) const { return mint(*this) *= a; } mint operator/(const mint &a) const { return mint(*this) /= a; } bool operator<(const mint &a) const { return x < a.x; } bool operator==(const mint &a) const { return x == a.x; } const mint power(ll N) { if (N == 0) { return 1; } else if (N % 2 == 1) { return *this * power(N - 1); } else { mint half = power(N / 2); return half * half; } } }; ll mint::MOD = 1e9 + 7; istream &operator>>(istream &stream, mint &a) { return stream >> a.x; } ostream &operator<<(ostream &stream, const mint &a) { return stream << a.x; } mint inv[MAX_SIZE]; mint fact[MAX_SIZE]; mint factinv[MAX_SIZE]; void init() { inv[1] = 1; for (int i = 2; i < MAX_SIZE; i++) { inv[i] = (-inv[mint::MOD % i]) * (mint::MOD / i); } fact[0] = factinv[0] = 1; for (int i = 1; i < MAX_SIZE; i++) { fact[i] = mint(i) * fact[i - 1]; factinv[i] = inv[i] * factinv[i - 1]; } } mint choose(int n, int k) { if (n >= 0 && k >= 0 && n - k >= 0) { return fact[n] * factinv[k] * factinv[n - k]; } return 0; } ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } // const double epsilon = 1e-10; // const ll infty = 1000000000000000LL; // const int dx[4] = {1, 0, -1, 0}; // const int dy[4] = {0, 1, 0, -1}; int N; ll A[100010]; void solve() { int ind = 0; for (auto i = 0; i < N; i++) { if (A[i] > 0) { ind = i; break; } } ll ans = 0; for (auto i = 0; i < N; i++) { ans += abs(A[i]); } cout << ans << endl; ll now = A[0]; for (auto i = ind; i < N - 1; i++) { cout << now << " " << A[i] << endl; now -= A[i]; } ll now2 = A[N - 1]; for (auto i = 1; i < ind; i++) { cout << now2 << " " << A[i] << endl; now2 -= A[i]; } cout << now2 << " " << now << endl; assert(now2 - now == ans); } void solve_plus() { ll ans = -A[0]; for (auto i = 1; i < N; i++) { ans += abs(A[i]); } cout << ans << endl; ll now = A[0]; for (auto i = 1; i < N - 1; i++) { cout << now << " " << A[i] << endl; now -= A[i]; } cout << A[N - 1] << " " << now << endl; assert(A[N - 1] - now == ans); } void solve_minus() { ll ans = A[N - 1]; for (auto i = 0; i < N - 1; i++) { ans += abs(A[i]); } cout << ans << endl; ll now = A[N - 1]; for (auto i = 0; i < N - 1; i++) { cout << now << " " << A[i] << endl; now -= A[i]; } assert(now == ans); } int main() { // init(); cin >> N; for (auto i = 0; i < N; i++) { cin >> A[i]; } sort(A, A + N); if (A[0] > 0) { solve_plus(); } else if (A[N - 1] < 0) { solve_minus(); } else { solve(); } }
#define DEBUG 0 /** * File : C.cpp * Author : Kazune Takahashi * Created : 6/15/2019, 9:15:16 PM * Powered by Visual Studio Code */ #include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <chrono> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> using namespace std; #define maxs(x, y) (x = max(x, y)) #define mins(x, y) (x = min(x, y)) typedef long long ll; void Yes() { cout << "Yes" << endl; exit(0); } void No() { cout << "No" << endl; exit(0); } const int MAX_SIZE = 1000010; class mint { public: static ll MOD; ll x; mint() : x(0) {} mint(ll x) : x(x % MOD) {} mint operator-() const { return mint(0) - *this; } mint &operator+=(const mint &a) { if ((x += a.x) >= MOD) { x -= MOD; } return *this; } mint &operator-=(const mint &a) { return *this += -a; } mint &operator*=(const mint &a) { (x *= a.x) %= MOD; return *this; } mint &operator/=(const mint &a) { return (*this *= power(MOD - 2)); } mint operator+(const mint &a) const { return mint(*this) += a; } mint operator-(const mint &a) const { return mint(*this) -= a; } mint operator*(const mint &a) const { return mint(*this) *= a; } mint operator/(const mint &a) const { return mint(*this) /= a; } bool operator<(const mint &a) const { return x < a.x; } bool operator==(const mint &a) const { return x == a.x; } const mint power(ll N) { if (N == 0) { return 1; } else if (N % 2 == 1) { return *this * power(N - 1); } else { mint half = power(N / 2); return half * half; } } }; ll mint::MOD = 1e9 + 7; istream &operator>>(istream &stream, mint &a) { return stream >> a.x; } ostream &operator<<(ostream &stream, const mint &a) { return stream << a.x; } mint inv[MAX_SIZE]; mint fact[MAX_SIZE]; mint factinv[MAX_SIZE]; void init() { inv[1] = 1; for (int i = 2; i < MAX_SIZE; i++) { inv[i] = (-inv[mint::MOD % i]) * (mint::MOD / i); } fact[0] = factinv[0] = 1; for (int i = 1; i < MAX_SIZE; i++) { fact[i] = mint(i) * fact[i - 1]; factinv[i] = inv[i] * factinv[i - 1]; } } mint choose(int n, int k) { if (n >= 0 && k >= 0 && n - k >= 0) { return fact[n] * factinv[k] * factinv[n - k]; } return 0; } ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } // const double epsilon = 1e-10; // const ll infty = 1000000000000000LL; // const int dx[4] = {1, 0, -1, 0}; // const int dy[4] = {0, 1, 0, -1}; int N; ll A[100010]; void solve() { int ind = 0; for (auto i = 0; i < N; i++) { if (A[i] > 0) { ind = i; break; } } ll ans = 0; for (auto i = 0; i < N; i++) { ans += abs(A[i]); } cout << ans << endl; ll now = A[0]; for (auto i = ind; i < N - 1; i++) { cout << now << " " << A[i] << endl; now -= A[i]; } ll now2 = A[N - 1]; for (auto i = 1; i < ind; i++) { cout << now2 << " " << A[i] << endl; now2 -= A[i]; } cout << now2 << " " << now << endl; assert(now2 - now == ans); } void solve_plus() { ll ans = -A[0]; for (auto i = 1; i < N; i++) { ans += abs(A[i]); } cout << ans << endl; ll now = A[0]; for (auto i = 1; i < N - 1; i++) { cout << now << " " << A[i] << endl; now -= A[i]; } cout << A[N - 1] << " " << now << endl; assert(A[N - 1] - now == ans); } void solve_minus() { ll ans = A[N - 1]; for (auto i = 0; i < N - 1; i++) { ans += abs(A[i]); } cout << ans << endl; ll now = A[N - 1]; for (auto i = 0; i < N - 1; i++) { cout << now << " " << A[i] << endl; now -= A[i]; } assert(now == ans); } int main() { // init(); cin >> N; for (auto i = 0; i < N; i++) { cin >> A[i]; } sort(A, A + N); if (A[0] >= 0) { solve_plus(); } else if (A[N - 1] <= 0) { solve_minus(); } else { solve(); } }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
821,744
821,745
u521272340
cpp
p03007
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { int n, ans = 0; cin >> n; vector<int> a(n), x(n - 1), y(n - 1); for (int i = 0; i < n; i++) cin >> a[i]; sort(a.begin(), a.end()); reverse(a.begin(), a.end()); int idx = 0; for (; a[idx] > 0 && idx < n; idx++) ; if (!idx) idx++; if (idx == n) idx--; x[0] = a[n - 1]; y[0] = a[1]; if (n > 1) { int i = 1; for (; i < idx - 1 || i < 1; i++) { x[i] = x[i - 1] - y[i - 1]; y[i] = a[i + 1]; } x[idx - 1] = a[0]; y[idx - 1] = x[idx - 2] - y[idx - 2]; for (i = idx; i < n - 1; i++) { x[i] = x[i - 1] - y[i - 1]; y[i] = a[i]; } } else { x[0] = a[0]; y[0] = a[1]; for (int i = 1; i < n - 1; i++) { x[i] = x[i - 1] - y[i - 1]; y[i] = a[i + 1]; } } cout << x[n - 2] - y[n - 2] << endl; for (int j = 0; j < n - 1; j++) { cout << x[j] << " " << y[j] << endl; } }
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { int n, ans = 0; cin >> n; vector<int> a(n), x(n - 1), y(n - 1); for (int i = 0; i < n; i++) cin >> a[i]; sort(a.begin(), a.end()); reverse(a.begin(), a.end()); int idx = 0; for (; a[idx] > 0 && idx < n; idx++) ; if (!idx) idx++; if (idx == n) idx--; x[0] = a[n - 1]; y[0] = a[1]; if (idx > 1) { int i = 1; for (; i < idx - 1 || i < 1; i++) { x[i] = x[i - 1] - y[i - 1]; y[i] = a[i + 1]; } x[idx - 1] = a[0]; y[idx - 1] = x[idx - 2] - y[idx - 2]; for (i = idx; i < n - 1; i++) { x[i] = x[i - 1] - y[i - 1]; y[i] = a[i]; } } else { x[0] = a[0]; y[0] = a[1]; for (int i = 1; i < n - 1; i++) { x[i] = x[i - 1] - y[i - 1]; y[i] = a[i + 1]; } } cout << x[n - 2] - y[n - 2] << endl; for (int j = 0; j < n - 1; j++) { cout << x[j] << " " << y[j] << endl; } }
[ "identifier.change", "control_flow.branch.if.condition.change" ]
821,748
821,749
u803893892
cpp
p03007
#include <bits/stdc++.h> using namespace std; #define For(i, n) for (long i = 0; i < (n); i++) long gcd(long a, long b) { return b ? gcd(b, a % b) : a; } long n, k, ans = 0; int main() { cin >> n; vector<long> a(n); long plus = 0; long notplus = 0; For(i, n) { cin >> a.at(i); if (a.at(i) > 0) { plus++; } else { notplus++; } } sort(a.begin(), a.end()); if (notplus == 0) { For(i, n) { if (i == 0) { ans -= a.at(i); } else { ans += a.at(i); } } } else if (plus == 0) { For(i, n) { if (i == n - 1) { ans -= abs(a.at(i)); } else { ans += abs(a.at(i)); } } } else { For(i, n) { ans += abs(a.at(i)); } } cout << ans << endl; if (notplus == 0) { for (long i = 1; i < n - 1; i++) { cout << a.at(0) << " " << a.at(i) << endl; a.at(0) -= a.at(i); } cout << a.at(n - 1) << " " << a.at(0) << endl; a.at(0) = a.at(n - 1) - a.at(0); // cout<<a.at(0); } else if (plus == 0) { For(i, n - 1) { cout << a.at(i) << " " << a.at(n - 1) << endl; a.at(n - 1) -= a.at(i); } // cout<<a.at(n-1); } else { for (long i = 1; i < notplus; i++) { cout << a.at(notplus) << " " << a.at(i) << endl; a.at(notplus) -= a.at(i); } for (long i = notplus; i < n - 1; i++) { cout << a.at(0) << " " << a.at(i) << endl; a.at(0) -= a.at(i); } cout << a.at(n - 1) << " " << a.at(0) << endl; a.at(n - 1) -= a.at(0); // cout<<a.at(n-1); } }
#include <bits/stdc++.h> using namespace std; #define For(i, n) for (long i = 0; i < (n); i++) long gcd(long a, long b) { return b ? gcd(b, a % b) : a; } long n, k, ans = 0; int main() { cin >> n; vector<long> a(n); long plus = 0; long notplus = 0; For(i, n) { cin >> a.at(i); if (a.at(i) > 0) { plus++; } else { notplus++; } } sort(a.begin(), a.end()); if (notplus == 0) { For(i, n) { if (i == 0) { ans -= a.at(i); } else { ans += a.at(i); } } } else if (plus == 0) { For(i, n) { if (i == n - 1) { ans -= abs(a.at(i)); } else { ans += abs(a.at(i)); } } } else { For(i, n) { ans += abs(a.at(i)); } } cout << ans << endl; if (notplus == 0) { for (long i = 1; i < n - 1; i++) { cout << a.at(0) << " " << a.at(i) << endl; a.at(0) -= a.at(i); } cout << a.at(n - 1) << " " << a.at(0) << endl; a.at(0) = a.at(n - 1) - a.at(0); // cout<<a.at(0); } else if (plus == 0) { For(i, n - 1) { cout << a.at(n - 1) << " " << a.at(i) << endl; a.at(n - 1) -= a.at(i); } // cout<<a.at(n-1); } else { for (long i = 1; i < notplus; i++) { cout << a.at(notplus) << " " << a.at(i) << endl; a.at(notplus) -= a.at(i); } for (long i = notplus; i < n - 1; i++) { cout << a.at(0) << " " << a.at(i) << endl; a.at(0) -= a.at(i); } cout << a.at(n - 1) << " " << a.at(0) << endl; a.at(n - 1) -= a.at(0); // cout<<a.at(n-1); } }
[ "expression.operation.binary.remove", "io.output.change" ]
821,767
821,768
u813174766
cpp
p03007
#pragma GCC optimize "-O3" #pragma GCC optimize("Ofast") #pragma GCC optimization("unroll-loops") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; #define LSOne(S) (S & (-S)) #define ll long long #define two pair<int, int> #define twol pair<ll, ll> #define four pair<two, two> #define pb push_back #define mk make_pair #define y1 y1922 #define INF 1000000000000000000 #define P 1000000007 #define lmax 1000000000 #define nn 1000003 #define ff first.first #define fs first.second #define sf second.first #define ss second.second #define f first #define s second #define vi vector<int> #define vll vector<ll> #define vtwo vector<two> #define ALL(container) (container).begin(), (container).end() #define sz(container) (int)(container.size()) #define max(a, b) ((a) > (b) ? (a) : (b)) #define min(a, b) ((a) < (b) ? (a) : (b)) #define mid(a, b) (a + b >> 1) #define minN 0 #define maxN 10000000 #define na(x) ((x) < P ? (x) : (x)-P) #define ab(a) (-(a) < (a) ? (a) : -(a)) #define FAST std::ios::sync_with_stdio(false) #define xRand \ mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) #define rnd rng #define IT iterator typedef tree<int, // aq pair<int,int> shegidzlia null_type, less /*_equal*/<int>, // aqac rb_tree_tag, tree_order_statistics_node_update> ordered_set; // '_equal' mashin ginda roca multiset gchirdeba template <class key, class value, class cmp = std::less<key>> using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>; ordered_map<int, int> my_map; inline int rin() { int x = 0, w = 1; char ch = getchar(); while ((ch < '0' || ch > '9') && ch != '-') ch = getchar(); if (ch == '-') w = 0, ch = getchar(); while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar(); return w ? x : -x; } inline int bin() { int x = 0; char ch = getchar(); while (ch < '0' || ch > '9') ch = getchar(); while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar(); return x; } ll n, a; multiset<int> s; multiset<int>::IT it, it1; vector<two> v; int main() { FAST; xRand; cin >> n; for (int i = 1; i <= n; i++) { cin >> a; s.insert(a); } while (sz(s) > 2) { it = s.end(); it--; it1 = it; it--; if ((*it) < 0) { v.pb({(*it1), (*it)}); a = (*it); s.erase(it); it1 = s.end(); it1--; n = (*it1); s.erase(it1); s.insert(a - n); continue; } it1 = s.begin(); v.pb({(*it1), (*it)}); n = (*it); s.erase(it); it1 = s.begin(); a = (*it1); s.erase(it1); s.insert(a - n); } if (sz(s) == 2) { it = s.begin(); it1 = s.end(); it1--; cout << (*it1) - (*it) << endl; v.pb({(*it1), (*it)}); } if (sz(s) == 1) { it = s.begin(); cout << (*it) << endl; } for (int i = 0; i < sz(v); i++) { cout << v[i].f << " " << v[i].s << endl; } } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#pragma GCC optimize "-O3" #pragma GCC optimize("Ofast") #pragma GCC optimization("unroll-loops") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; #define LSOne(S) (S & (-S)) #define ll long long #define two pair<int, int> #define twol pair<ll, ll> #define four pair<two, two> #define pb push_back #define mk make_pair #define y1 y1922 #define INF 1000000000000000000 #define P 1000000007 #define lmax 1000000000 #define nn 1000003 #define ff first.first #define fs first.second #define sf second.first #define ss second.second #define f first #define s second #define vi vector<int> #define vll vector<ll> #define vtwo vector<two> #define ALL(container) (container).begin(), (container).end() #define sz(container) (int)(container.size()) #define max(a, b) ((a) > (b) ? (a) : (b)) #define min(a, b) ((a) < (b) ? (a) : (b)) #define mid(a, b) (a + b >> 1) #define minN 0 #define maxN 10000000 #define na(x) ((x) < P ? (x) : (x)-P) #define ab(a) (-(a) < (a) ? (a) : -(a)) #define FAST std::ios::sync_with_stdio(false) #define xRand \ mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) #define rnd rng #define IT iterator typedef tree<int, // aq pair<int,int> shegidzlia null_type, less /*_equal*/<int>, // aqac rb_tree_tag, tree_order_statistics_node_update> ordered_set; // '_equal' mashin ginda roca multiset gchirdeba template <class key, class value, class cmp = std::less<key>> using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>; ordered_map<int, int> my_map; inline int rin() { int x = 0, w = 1; char ch = getchar(); while ((ch < '0' || ch > '9') && ch != '-') ch = getchar(); if (ch == '-') w = 0, ch = getchar(); while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar(); return w ? x : -x; } inline int bin() { int x = 0; char ch = getchar(); while (ch < '0' || ch > '9') ch = getchar(); while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar(); return x; } ll n, a; multiset<int> s; multiset<int>::IT it, it1; vector<two> v; int main() { FAST; xRand; cin >> n; for (int i = 1; i <= n; i++) { cin >> a; s.insert(a); } while (sz(s) > 2) { it = s.end(); it--; it1 = it; it--; if ((*it) < 0) { v.pb({(*it1), (*it)}); a = (*it); s.erase(it); it1 = s.end(); it1--; n = (*it1); s.erase(it1); s.insert(n - a); continue; } it1 = s.begin(); v.pb({(*it1), (*it)}); n = (*it); s.erase(it); it1 = s.begin(); a = (*it1); s.erase(it1); s.insert(a - n); } if (sz(s) == 2) { it = s.begin(); it1 = s.end(); it1--; cout << (*it1) - (*it) << endl; v.pb({(*it1), (*it)}); } if (sz(s) == 1) { it = s.begin(); cout << (*it) << endl; } for (int i = 0; i < sz(v); i++) { cout << v[i].f << " " << v[i].s << endl; } } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
[ "expression.operation.binary.remove" ]
821,769
821,770
u927221551
cpp
p03007
#include <algorithm> #include <assert.h> #include <cstring> #include <iterator> #include <list> #include <map> #include <math.h> #include <queue> #include <set> #include <stdio.h> #include <stdlib.h> #include <string> #include <vector> #pragma warning(disable : 4996) typedef long long ll; #define MIN(a, b) ((a) > (b) ? (b) : (a)) #define MAX(a, b) ((a) < (b) ? (b) : (a)) #define LINF 9223300000000000000 #define INF 2140000000 const long long MOD = 1000000007; using namespace std; int main(int argc, char *argv[]) { int n; scanf("%d", &n); vector<int> a, b; // +,- int cnt0 = 0; int i; for (i = 0; i < n; i++) { int tmp = 0; scanf("%d", &tmp); if (tmp > 0) a.push_back(tmp); else if (tmp < 0) b.push_back(tmp); else cnt0++; } sort(a.rbegin(), a.rend()); sort(b.begin(), b.end()); if (a.empty() && b.empty()) { a.push_back(0); for (i = 0; i < n - 1; i++) b.push_back(0); } else if (a.empty()) { if (cnt0) { for (i = 0; i < cnt0; i++) a.push_back(0); } else { int tmp = b.back(); b.pop_back(); a.push_back(tmp); } } else { if (cnt0) { for (i = 0; i < cnt0; i++) b.push_back(0); } else if (b.empty()) { int tmp = a.back(); a.pop_back(); b.push_back(tmp); } } #if 0 //#ifdef _DEBUG for(i=0; i<a.size(); i++) { printf("%d ", a[i]); } printf("\n"); for(i=0; i<b.size(); i++) { printf("%d ", b[i]); } printf("\n"); #endif ll sum = 0; for (i = 0; i < (int)a.size(); i++) { sum += a[i]; } for (i = 0; i < (int)b.size(); i++) { sum -= b[i]; } printf("%lld\n", sum); ll tmp = a[0]; for (i = 1; i < (int)b.size(); i++) { printf("%lld %d", tmp, b[i]); tmp = tmp - b[i]; } ll tmp2 = b[0]; for (i = 1; i < (int)a.size(); i++) { printf("%lld %d\n", tmp2, a[i]); tmp2 = tmp2 - a[i]; } printf("%lld %lld\n", tmp, tmp2); return 0; }
#include <algorithm> #include <assert.h> #include <cstring> #include <iterator> #include <list> #include <map> #include <math.h> #include <queue> #include <set> #include <stdio.h> #include <stdlib.h> #include <string> #include <vector> #pragma warning(disable : 4996) typedef long long ll; #define MIN(a, b) ((a) > (b) ? (b) : (a)) #define MAX(a, b) ((a) < (b) ? (b) : (a)) #define LINF 9223300000000000000 #define INF 2140000000 const long long MOD = 1000000007; using namespace std; int main(int argc, char *argv[]) { int n; scanf("%d", &n); vector<int> a, b; // +,- int cnt0 = 0; int i; for (i = 0; i < n; i++) { int tmp = 0; scanf("%d", &tmp); if (tmp > 0) a.push_back(tmp); else if (tmp < 0) b.push_back(tmp); else cnt0++; } sort(a.rbegin(), a.rend()); sort(b.begin(), b.end()); if (a.empty() && b.empty()) { a.push_back(0); for (i = 0; i < n - 1; i++) b.push_back(0); } else if (a.empty()) { if (cnt0) { for (i = 0; i < cnt0; i++) a.push_back(0); } else { int tmp = b.back(); b.pop_back(); a.push_back(tmp); } } else { if (cnt0) { for (i = 0; i < cnt0; i++) b.push_back(0); } else if (b.empty()) { int tmp = a.back(); a.pop_back(); b.push_back(tmp); } } #if 0 //#ifdef _DEBUG for(i=0; i<a.size(); i++) { printf("%d ", a[i]); } printf("\n"); for(i=0; i<b.size(); i++) { printf("%d ", b[i]); } printf("\n"); #endif ll sum = 0; for (i = 0; i < (int)a.size(); i++) { sum += a[i]; } for (i = 0; i < (int)b.size(); i++) { sum -= b[i]; } printf("%lld\n", sum); ll tmp = a[0]; for (i = 1; i < (int)b.size(); i++) { printf("%lld %d\n", tmp, b[i]); tmp = tmp - b[i]; } ll tmp2 = b[0]; for (i = 1; i < (int)a.size(); i++) { printf("%lld %d\n", tmp2, a[i]); tmp2 = tmp2 - a[i]; } printf("%lld %lld\n", tmp, tmp2); return 0; }
[ "literal.string.change", "call.arguments.change", "io.output.change", "io.output.newline.add" ]
821,771
821,772
u209713918
cpp
p03007
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); vector<int> pos, neg; int zero = 0; for (int i = 0; i < n; i++) { int temp; scanf("%d", &temp); if (temp > 0) pos.push_back(temp); else if (temp < 0) neg.push_back(temp); else zero++; } int a = pos.size(), b = neg.size(); int res = 0; vector<pair<int, int>> v; if (a == 0 && b == 0) { for (int i = 0; i < n - 1; i++) v.push_back(make_pair(0, 0)); } else if (b == 0) { for (int i = 0; i < zero; i++) { pos.push_back(0); sort(pos.begin(), pos.end()); } int now = pos[0]; for (int i = 1; i < (int)pos.size() - 1; i++) { v.push_back(make_pair(now, pos[i])); now -= pos[i]; } v.push_back(make_pair(pos.back(), now)); res = pos.back() - now; } else if (a == 0) { for (int i = 0; i < zero; i++) { neg.push_back(0); sort(neg.begin(), neg.end(), greater<int>()); } int now = neg[0]; for (int i = 1; i < (int)neg.size(); i++) { v.push_back(make_pair(now, neg[i])); now -= neg[i]; } res = now; } else { int tp = pos.back(), tn = neg.back(); pos.pop_back(); neg.pop_back(); pos.push_back(tn); neg.push_back(tp); for (int i = 0; i < zero; i++) pos.push_back(0); sort(pos.begin(), pos.end()); sort(neg.begin(), neg.end(), greater<int>()); int one = pos[0]; for (int i = 1; i < (int)pos.size(); i++) { v.push_back(make_pair(one, pos[i])); one -= pos[i]; } int two = neg[0]; for (int i = 1; i < (int)neg.size(); i++) { v.push_back(make_pair(two, neg[i])); two -= neg[i]; } v.push_back(make_pair(two, one)); res = two - one; } printf("%d\n", res); for (int i = 0; i < n - 1; i++) printf("%d %d\n", v[i].first, v[i].second); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); vector<int> pos, neg; int zero = 0; for (int i = 0; i < n; i++) { int temp; scanf("%d", &temp); if (temp > 0) pos.push_back(temp); else if (temp < 0) neg.push_back(temp); else zero++; } int a = pos.size(), b = neg.size(); int res = 0; vector<pair<int, int>> v; if (a == 0 && b == 0) { for (int i = 0; i < n - 1; i++) v.push_back(make_pair(0, 0)); } else if (b == 0) { for (int i = 0; i < zero; i++) pos.push_back(0); sort(pos.begin(), pos.end()); int now = pos[0]; for (int i = 1; i < (int)pos.size() - 1; i++) { v.push_back(make_pair(now, pos[i])); now -= pos[i]; } v.push_back(make_pair(pos.back(), now)); res = pos.back() - now; } else if (a == 0) { for (int i = 0; i < zero; i++) neg.push_back(0); sort(neg.begin(), neg.end(), greater<int>()); int now = neg[0]; for (int i = 1; i < (int)neg.size(); i++) { v.push_back(make_pair(now, neg[i])); now -= neg[i]; } res = now; } else { int tp = pos.back(), tn = neg.back(); pos.pop_back(); neg.pop_back(); pos.push_back(tn); neg.push_back(tp); for (int i = 0; i < zero; i++) pos.push_back(0); sort(pos.begin(), pos.end()); sort(neg.begin(), neg.end(), greater<int>()); int one = pos[0]; for (int i = 1; i < (int)pos.size(); i++) { v.push_back(make_pair(one, pos[i])); one -= pos[i]; } int two = neg[0]; for (int i = 1; i < (int)neg.size(); i++) { v.push_back(make_pair(two, neg[i])); two -= neg[i]; } v.push_back(make_pair(two, one)); res = two - one; } printf("%d\n", res); for (int i = 0; i < n - 1; i++) printf("%d %d\n", v[i].first, v[i].second); return 0; }
[]
821,773
821,774
u535008646
cpp
p03007
/*author: hyperion_1724 date: */ #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define inf 1e10 #define READ(X) cin >> X; #define READV(X) \ long long X; \ cin >> X; #define READAR(A, N) \ long long A[N]; \ for (int i = 0; i < N; i++) { \ cin >> A[i]; \ } #define rz(A, N) A.resize(N); #define sz(X) (long long)(X.size()) #define fi first #define se second #define trav(x, A) for (auto &x : A) #define veci vector<int> #define vecl vector<long long> #define FORI(a, b, c) for (int a = b; a < c; a++) #define FORD(a, b, c) for (int a = b; a > c; a--) #define adj(N) vector<vector<int>> ADJ(N + 1) typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; typedef tree<long long, null_type, greater<long long>, rb_tree_tag, tree_order_statistics_node_update> ordered_set1; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<long, long> pll; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); multiset<ll> P; multiset<ll, greater<ll>> N; ll z = 0; READV(N1); FORI(i, 0, N1) { READV(x); if (x > 0) { P.insert(x); } else if (x < 0) { P.insert(x); } else { z++; } } if (sz(P) == 0 && z > 0) { P.insert(0); z--; } if (sz(N) == 0 && z > 0) { N.insert(0); z--; } if (z > 0) { while (z--) { P.insert(0); } } vector<pll> ans; if (sz(N) == 0) { auto it = P.begin(); ll x = *it; it++; ll y = *it; N.insert(x - y); ans.push_back({x, y}); P.erase(P.begin()); P.erase(P.begin()); } if (sz(P) == 0) { auto it = N.begin(); ll x = *it; it++; ll y = *it; P.insert(x - y); ans.push_back({x, y}); N.erase(N.begin()); N.erase(N.begin()); } while (sz(N) > 1) { auto it = N.begin(); auto it1 = P.begin(); ll x = *it1; ll y = *it; ans.push_back({x, y}); P.erase(it1); N.erase(it); P.insert(x - y); } while (sz(P) > 1) { auto it = N.begin(); auto it1 = P.begin(); ll y = *it1; ll x = *it; ans.push_back({x, y}); P.erase(it1); N.erase(it); N.insert(x - y); } ll x = *(P.begin()); ll y = *(N.begin()); ans.push_back({x, y}); cout << x - y << endl; FORI(i, 0, sz(ans)) { cout << ans[i].fi << " " << ans[i].se << endl; } return 0; }
/*author: hyperion_1724 date: */ #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define inf 1e10 #define READ(X) cin >> X; #define READV(X) \ long long X; \ cin >> X; #define READAR(A, N) \ long long A[N]; \ for (int i = 0; i < N; i++) { \ cin >> A[i]; \ } #define rz(A, N) A.resize(N); #define sz(X) (long long)(X.size()) #define fi first #define se second #define trav(x, A) for (auto &x : A) #define veci vector<int> #define vecl vector<long long> #define FORI(a, b, c) for (int a = b; a < c; a++) #define FORD(a, b, c) for (int a = b; a > c; a--) #define adj(N) vector<vector<int>> ADJ(N + 1) typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; typedef tree<long long, null_type, greater<long long>, rb_tree_tag, tree_order_statistics_node_update> ordered_set1; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<long, long> pll; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); multiset<ll> P; multiset<ll, greater<ll>> N; ll z = 0; READV(N1); FORI(i, 0, N1) { READV(x); if (x > 0) { P.insert(x); } else if (x < 0) { N.insert(x); } else { z++; } } if (sz(P) == 0 && z > 0) { P.insert(0); z--; } if (sz(N) == 0 && z > 0) { N.insert(0); z--; } if (z > 0) { while (z--) { P.insert(0); } } vector<pll> ans; if (sz(N) == 0) { auto it = P.begin(); ll x = *it; it++; ll y = *it; N.insert(x - y); ans.push_back({x, y}); P.erase(P.begin()); P.erase(P.begin()); } if (sz(P) == 0) { auto it = N.begin(); ll x = *it; it++; ll y = *it; P.insert(x - y); ans.push_back({x, y}); N.erase(N.begin()); N.erase(N.begin()); } while (sz(N) > 1) { auto it = N.begin(); auto it1 = P.begin(); ll x = *it1; ll y = *it; ans.push_back({x, y}); P.erase(it1); N.erase(it); P.insert(x - y); } while (sz(P) > 1) { auto it = N.begin(); auto it1 = P.begin(); ll y = *it1; ll x = *it; ans.push_back({x, y}); P.erase(it1); N.erase(it); N.insert(x - y); } ll x = *(P.begin()); ll y = *(N.begin()); ans.push_back({x, y}); cout << x - y << endl; FORI(i, 0, sz(ans)) { cout << ans[i].fi << " " << ans[i].se << endl; } return 0; }
[ "identifier.change" ]
821,781
821,782
u086878393
cpp
p03007
#include <bits/stdc++.h> using namespace std; const int MAXN = 100005; int N, A[MAXN]; int main() { scanf("%d", &N); int z = -1; for (int i = 0; i < N; i++) { scanf("%d", &A[i]); if (A[i] == 0) z = i; } sort(A, A + N); reverse(A, A + N); if (A[0] < 0) { int M = 0; for (int i = 0; i < N; i++) { if (i == 0) M += A[i]; else M -= A[i]; } printf("%d\n", M); for (int i = 1; i < N; i++) { printf("%d %d\n", A[0], A[i]); A[0] -= A[i]; } return 0; } if (A[N - 1] > 0) { int M = 0; for (int i = 0; i < N; i++) { if (i == N - 1) M -= A[i]; else M += A[i]; } printf("%d\n", M); for (int i = 1; i < N - 1; i++) { printf("%d %d\n", A[N - 1], A[i]); A[N - 1] -= A[i]; } printf("%d %d\n", A[0], A[N - 1]); return 0; } int M = 0; for (int i = 0; i < N; i++) M += abs(A[i]); printf("%d\n", M); for (int i = 1; i < N; i++) { if (A[i] <= 0) break; printf("%d %d\n", A[N - 1], A[i]); A[N - 1] -= A[i]; } for (int i = N - 1; i >= 0; i--) { if (A[i] > 0) break; printf("%d %d\n", A[0], A[i]); A[0] -= A[i]; } return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 100005; int N, A[MAXN]; int main() { scanf("%d", &N); int z = -1; for (int i = 0; i < N; i++) { scanf("%d", &A[i]); if (A[i] == 0) z = i; } sort(A, A + N); reverse(A, A + N); if (A[0] < 0) { int M = 0; for (int i = 0; i < N; i++) { if (i == 0) M += A[i]; else M -= A[i]; } printf("%d\n", M); for (int i = 1; i < N; i++) { printf("%d %d\n", A[0], A[i]); A[0] -= A[i]; } return 0; } if (A[N - 1] > 0) { int M = 0; for (int i = 0; i < N; i++) { if (i == N - 1) M -= A[i]; else M += A[i]; } printf("%d\n", M); for (int i = 1; i < N - 1; i++) { printf("%d %d\n", A[N - 1], A[i]); A[N - 1] -= A[i]; } printf("%d %d\n", A[0], A[N - 1]); return 0; } int M = 0; for (int i = 0; i < N; i++) M += abs(A[i]); printf("%d\n", M); for (int i = 1; i < N; i++) { if (A[i] <= 0) break; printf("%d %d\n", A[N - 1], A[i]); A[N - 1] -= A[i]; } for (int i = N - 1; i >= 1; i--) { if (A[i] > 0) break; printf("%d %d\n", A[0], A[i]); A[0] -= A[i]; } return 0; }
[ "literal.number.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
821,787
821,788
u063863677
cpp
p03007
/* ****TCIITB**** */ #include <bits/stdc++.h> #define io \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #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 time \ cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; using namespace std; #define N 100005 int main() { io ll n; cin >> n; std::vector<ll> a(n); ll cp = 0, cn = 0; rep(i, 0, n) { cin >> a[i]; if (a[i] > 0) cp++; else cn++; } std::vector<pii> res; if (cp == n) { sort(all(a)); ll curr = a[0]; rep(i, 1, n) { if (i != (n - 1)) { res.pb({curr, a[i]}); curr = (curr - a[i]); } else { res.pb({a[i], curr}); curr = (a[i] - curr); } } cout << curr << endl; for (auto i : res) { cout << i.F << " " << i.S << endl; } exit(0); } if (cn == n) { sort(all(a)); reverse(all(a)); ll curr = a[0]; rep(i, 1, n) { res.pb({curr, a[i]}); curr = (curr - a[i]); } cout << curr << endl; for (auto i : res) { cout << i.F << " " << i.S << endl; } exit(0); } sort(all(a)); ll stp = 0; rep(i, 0, n) { if (a[i] >= 0) { stp = i; break; } } ll curr = a[0]; rep(i, stp, n) { if (i != (n - 1)) { res.pb({curr, a[i]}); curr = (curr - a[i]); } else { res.pb({a[i], curr}); curr = (-curr + a[i]); } } rep(i, 1, stp) { res.pb({curr, a[i]}); curr = (curr - a[i]); } cout << curr << endl; for (auto i : res) { cout << i.F << " " << i.S << endl; } exit(0); }
/* ****TCIITB**** */ #include <bits/stdc++.h> #define io \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #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 time \ cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; using namespace std; #define N 100005 int main() { io ll n; cin >> n; std::vector<ll> a(n); ll cp = 0, cn = 0; rep(i, 0, n) { cin >> a[i]; if (a[i] >= 0) cp++; else cn++; } std::vector<pii> res; if (cp == n) { sort(all(a)); ll curr = a[0]; rep(i, 1, n) { if (i != (n - 1)) { res.pb({curr, a[i]}); curr = (curr - a[i]); } else { res.pb({a[i], curr}); curr = (a[i] - curr); } } cout << curr << endl; for (auto i : res) { cout << i.F << " " << i.S << endl; } exit(0); } if (cn == n) { sort(all(a)); reverse(all(a)); ll curr = a[0]; rep(i, 1, n) { res.pb({curr, a[i]}); curr = (curr - a[i]); } cout << curr << endl; for (auto i : res) { cout << i.F << " " << i.S << endl; } exit(0); } sort(all(a)); ll stp = 0; rep(i, 0, n) { if (a[i] >= 0) { stp = i; break; } } ll curr = a[0]; rep(i, stp, n) { if (i != (n - 1)) { res.pb({curr, a[i]}); curr = (curr - a[i]); } else { res.pb({a[i], curr}); curr = (-curr + a[i]); } } rep(i, 1, stp) { res.pb({curr, a[i]}); curr = (curr - a[i]); } cout << curr << endl; for (auto i : res) { cout << i.F << " " << i.S << endl; } exit(0); }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
821,808
821,809
u930865369
cpp
p03007
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define pb pushback #define fr(i, n) for (int i = 0; i < n; i++) #define ifr(i, n) for (int i = n - 1; i >= 0; i--) int main() { int n; cin >> n; int a[n]; int m = 0; int x, y; fr(i, n) { cin >> a[i]; m += abs(a[i]); } sort(a, a + n); if (a[0] < 0 && 0 < a[n - 1]) { cout << m << endl; int plus; fr(i, n) { if (a[i] > 0) { plus = i; break; } } x = a[plus - 1]; y = a[plus]; fr(i, n - 1 - plus) { cout << x << " " << y << endl; x = x - y; y = a[plus + i + 1]; } x += y; y = x - y; x -= y; fr(i, plus) { cout << x << " " << y << endl; x = x - y; y = a[i]; } } else if (a[0] >= 0) { cout << m - 2 * a[0] << endl; x = a[0]; y = a[1]; fr(i, n - 2) { cout << x << " " << y << endl; x = x - y; y = a[i + 2]; } cout << y << " " << x << endl; } else { cout << m + 2 * a[0] << endl; x = a[n - 1]; y = a[0]; fr(i, n - 1) { cout << x << " " << y << endl; x = x - y; y = a[i + 1]; } } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define pb pushback #define fr(i, n) for (int i = 0; i < n; i++) #define ifr(i, n) for (int i = n - 1; i >= 0; i--) int main() { int n; cin >> n; int a[n]; int m = 0; int x, y; fr(i, n) { cin >> a[i]; m += abs(a[i]); } sort(a, a + n); if (a[0] < 0 && 0 < a[n - 1]) { cout << m << endl; int plus; fr(i, n) { if (a[i] > 0) { plus = i; break; } } x = a[plus - 1]; y = a[plus]; fr(i, n - 1 - plus) { cout << x << " " << y << endl; x = x - y; y = a[plus + i + 1]; } x += y; y = x - y; x -= y; fr(i, plus) { cout << x << " " << y << endl; x = x - y; y = a[i]; } } else if (a[0] >= 0) { cout << m - 2 * a[0] << endl; x = a[0]; y = a[1]; fr(i, n - 2) { cout << x << " " << y << endl; x = x - y; y = a[i + 2]; } cout << y << " " << x << endl; } else { cout << m + 2 * a[n - 1] << endl; x = a[n - 1]; y = a[0]; fr(i, n - 1) { cout << x << " " << y << endl; x = x - y; y = a[i + 1]; } } }
[ "identifier.replace.add", "literal.replace.remove", "variable_access.subscript.index.change", "io.output.change" ]
821,810
821,811
u806159048
cpp
p03007
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define pb pushback #define fr(i, n) for (int i = 0; i < n; i++) #define ifr(i, n) for (int i = n - 1; i >= 0; i--) int main() { int n; cin >> n; int a[n]; int m = 0; int x, y; fr(i, n) { cin >> a[i]; m += abs(a[i]); } sort(a, a + n); if (a[0] < 0 && 0 < a[n - 1]) { cout << m << endl; int plus; fr(i, n) { if (a[i] > 0) { plus = i; break; } } x = a[plus - 1]; y = a[plus]; fr(i, n - 1 - plus) { cout << x << " " << y << endl; x = x - y; y = a[plus + i + 1]; } x += y; y = x - y; x -= y; fr(i, plus) { cout << x << " " << y << endl; x = x - y; y = a[i]; } } else if (a[0] >= 0) { cout << m - 2 * a[0] << endl; x = a[0]; y = a[1]; fr(i, n - 2) { cout << x << " " << y << endl; x = x - y; y = a[i + 2]; } cout << y << " " << x << endl; } else { cout << m - 2 * a[0] << endl; x = a[n - 1]; y = a[0]; fr(i, n - 1) { cout << x << " " << y << endl; x = x - y; y = a[i + 1]; } } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define pb pushback #define fr(i, n) for (int i = 0; i < n; i++) #define ifr(i, n) for (int i = n - 1; i >= 0; i--) int main() { int n; cin >> n; int a[n]; int m = 0; int x, y; fr(i, n) { cin >> a[i]; m += abs(a[i]); } sort(a, a + n); if (a[0] < 0 && 0 < a[n - 1]) { cout << m << endl; int plus; fr(i, n) { if (a[i] > 0) { plus = i; break; } } x = a[plus - 1]; y = a[plus]; fr(i, n - 1 - plus) { cout << x << " " << y << endl; x = x - y; y = a[plus + i + 1]; } x += y; y = x - y; x -= y; fr(i, plus) { cout << x << " " << y << endl; x = x - y; y = a[i]; } } else if (a[0] >= 0) { cout << m - 2 * a[0] << endl; x = a[0]; y = a[1]; fr(i, n - 2) { cout << x << " " << y << endl; x = x - y; y = a[i + 2]; } cout << y << " " << x << endl; } else { cout << m + 2 * a[n - 1] << endl; x = a[n - 1]; y = a[0]; fr(i, n - 1) { cout << x << " " << y << endl; x = x - y; y = a[i + 1]; } } }
[ "misc.opposites", "expression.operator.arithmetic.change", "io.output.change", "identifier.replace.add", "literal.replace.remove", "variable_access.subscript.index.change" ]
821,812
821,811
u806159048
cpp
p03007
#include <algorithm> #include <iostream> #include <map> #include <vector> using namespace std; using ll = long long; int main() { int n; cin >> n; vector<int> a(n), t, h; for (int i = 0; i < n; i++) cin >> a[i]; sort(a.begin(), a.end()); int temp = n - 2; t.push_back(a[n - 1]); int ans = a[n - 1]; for (int i = n - 2; i >= 0; i--) { if (temp > 0 && a[i] >= 0) { ans += a[i]; t.push_back(a[i]); temp--; } else { ans += (a[i] * -1); h.push_back(a[i]); } } cout << ans << endl; ll num; if (t.size() > 1) { num = h[0] - t[1]; cout << h[0] << " " << t[0] << endl; for (int i = 2; i < t.size(); i++) { cout << num << " " << t[i] << endl; num = num - t[i]; } cout << t[0] << " " << num << endl; num = t[0] - num; for (int i = 1; i < h.size(); i++) { cout << num << " " << h[i] << endl; num = num - h[i]; } } else { num = t[0] - h[0]; cout << t[0] << " " << h[0] << endl; for (int i = 1; i < h.size(); i++) { cout << num << " " << h[i] << endl; num = num - h[i]; } } }
#include <algorithm> #include <iostream> #include <map> #include <vector> using namespace std; using ll = long long; int main() { int n; cin >> n; vector<int> a(n), t, h; for (int i = 0; i < n; i++) cin >> a[i]; sort(a.begin(), a.end()); int temp = n - 2; t.push_back(a[n - 1]); int ans = a[n - 1]; for (int i = n - 2; i >= 0; i--) { if (temp > 0 && a[i] >= 0) { ans += a[i]; t.push_back(a[i]); temp--; } else { ans += (a[i] * -1); h.push_back(a[i]); } } cout << ans << endl; ll num; if (t.size() > 1) { num = h[0] - t[1]; cout << h[0] << " " << t[1] << endl; for (int i = 2; i < t.size(); i++) { cout << num << " " << t[i] << endl; num = num - t[i]; } cout << t[0] << " " << num << endl; num = t[0] - num; for (int i = 1; i < h.size(); i++) { cout << num << " " << h[i] << endl; num = num - h[i]; } } else { num = t[0] - h[0]; cout << t[0] << " " << h[0] << endl; for (int i = 1; i < h.size(); i++) { cout << num << " " << h[i] << endl; num = num - h[i]; } } }
[ "literal.number.change", "variable_access.subscript.index.change", "io.output.change" ]
821,813
821,814
u855186748
cpp
p03007
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return x * f; } inline void write(int x) { if (x < 0) putchar('-'), x = -x; if (x > 9) write(x / 10); putchar(x % 10 + '0'); } inline void pr1(int x) { write(x), putchar(' '); } inline void pr2(int x) { write(x), puts(""); } long long x[100010], y[100010], a[100010]; int main() { // freopen("a.in","r",stdin); // freopen("a.out","w",stdout); int n = read(); int now = 0; long long d; for (int i = 1; i <= n; i++) a[i] = read(); sort(a + 1, a + n + 1); int p = 0; d = a[1]; for (int i = 2; i < n; i++) { if (a[i] < 0) p = i; if (a[i] >= 0) { now++; x[now] = d, y[now] = a[i]; d -= a[i]; } } now++; x[now] = a[n], y[now] = d; a[n] -= d; for (int i = 2; i <= p; i++) { x[now] = a[n], y[now] = a[i]; a[n] -= a[i]; } printf("%lld\n", a[n]); for (int i = 1; i <= now; i++) printf("%lld %lld\n", x[i], y[i]); return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return x * f; } inline void write(int x) { if (x < 0) putchar('-'), x = -x; if (x > 9) write(x / 10); putchar(x % 10 + '0'); } inline void pr1(int x) { write(x), putchar(' '); } inline void pr2(int x) { write(x), puts(""); } long long x[100010], y[100010], a[100010]; int main() { // freopen("a.in","r",stdin); // freopen("a.out","w",stdout); int n = read(); int now = 0; long long d; for (int i = 1; i <= n; i++) a[i] = read(); sort(a + 1, a + n + 1); int p = 0; d = a[1]; for (int i = 2; i < n; i++) { if (a[i] < 0) p = i; if (a[i] >= 0) { now++; x[now] = d, y[now] = a[i]; d -= a[i]; } } now++; x[now] = a[n], y[now] = d; a[n] -= d; for (int i = 2; i <= p; i++) { now++; x[now] = a[n], y[now] = a[i]; a[n] -= a[i]; } printf("%lld\n", a[n]); for (int i = 1; i <= now; i++) printf("%lld %lld\n", x[i], y[i]); return 0; }
[ "expression.unary.arithmetic.add" ]
821,822
821,823
u475221259
cpp
p03007
#include <bits/stdc++.h> using namespace std; ; #define ll long long #define rep(i, n) for (int i = 0; i < n; i++) #define repr(i, n) for (int i = n; i >= 0; i--) #define FOR(i, m, n) for (int i = m; i < n; i++) #define FORR(i, m, n) for (int i = m; i >= n; i--) #define INF 1 << 30 #define LINF 1LL << 62 #define all(x) (x).begin(), (x).end() #define mp make_pair #define pb push_back const int MOD = 1000000007; typedef pair<int, int> P; typedef pair<ll, ll> LP; typedef pair<int, P> PP; typedef pair<ll, LP> LPP; int main() { ios::sync_with_stdio(false); cin.tie(0); ll n; cin >> n; vector<ll> a(n); bool pos = true; bool neg = true; ll sum = 0; ll dsum = 0; ll mi = LINF; ll ma = -LINF; vector<ll> ps, ns; rep(i, n) { cin >> a[i]; sum += a[i]; dsum += abs(a[i]); mi = min(mi, a[i]); ma = max(ma, a[i]); if (a[i] < 0) pos = false; if (a[i] > 0) neg = false; if (a[i] >= 0) ps.pb(a[i]); else ns.pb(a[i]); } sort(all(ps)); sort(all(ns)); reverse(all(ns)); if (n == 2) { cout << ma - mi << endl; cout << ma << " " << mi << endl; return 0; } if (pos) { cout << sum - 2 * mi << endl; ll tmp = mi; FOR(i, 1, n - 1) { cout << tmp << " " << ps[i] << endl; tmp -= ps[i]; } cout << ps[n - 1] << " " << tmp << endl; return 0; } if (neg) { cout << -(sum - 2 * ma) << endl; ll tmp = ma; FOR(i, 1, n) { cout << tmp << " " << ns[i] << endl; tmp -= ns[i]; } return 0; } cout << dsum << endl; rep(i, ps.size() - 1) { cout << ns[0] << " " << ps[i] << endl; ; ns[0] -= ps[i]; } rep(i, ns.size()) { cout << ps[ps.size() - 1] << " " << ns[i] << endl; ps[ps.size() - 1] -= ns[i]; } }
#include <bits/stdc++.h> using namespace std; ; #define ll long long #define rep(i, n) for (int i = 0; i < n; i++) #define repr(i, n) for (int i = n; i >= 0; i--) #define FOR(i, m, n) for (int i = m; i < n; i++) #define FORR(i, m, n) for (int i = m; i >= n; i--) #define INF 1 << 30 #define LINF 1LL << 62 #define all(x) (x).begin(), (x).end() #define mp make_pair #define pb push_back const int MOD = 1000000007; typedef pair<int, int> P; typedef pair<ll, ll> LP; typedef pair<int, P> PP; typedef pair<ll, LP> LPP; int main() { ios::sync_with_stdio(false); cin.tie(0); ll n; cin >> n; vector<ll> a(n); bool pos = true; bool neg = true; ll sum = 0; ll dsum = 0; ll mi = LINF; ll ma = -LINF; vector<ll> ps, ns; rep(i, n) { cin >> a[i]; sum += a[i]; dsum += abs(a[i]); mi = min(mi, a[i]); ma = max(ma, a[i]); if (a[i] < 0) pos = false; if (a[i] >= 0) neg = false; if (a[i] >= 0) ps.pb(a[i]); else ns.pb(a[i]); } sort(all(ps)); sort(all(ns)); reverse(all(ns)); if (n == 2) { cout << ma - mi << endl; cout << ma << " " << mi << endl; return 0; } if (pos) { cout << sum - 2 * mi << endl; ll tmp = mi; FOR(i, 1, n - 1) { cout << tmp << " " << ps[i] << endl; tmp -= ps[i]; } cout << ps[n - 1] << " " << tmp << endl; return 0; } if (neg) { cout << -(sum - 2 * ma) << endl; ll tmp = ma; FOR(i, 1, n) { cout << tmp << " " << ns[i] << endl; tmp -= ns[i]; } return 0; } cout << dsum << endl; rep(i, ps.size() - 1) { cout << ns[0] << " " << ps[i] << endl; ; ns[0] -= ps[i]; } rep(i, ns.size()) { cout << ps[ps.size() - 1] << " " << ns[i] << endl; ps[ps.size() - 1] -= ns[i]; } }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
821,824
821,825
u013628553
cpp
p03007
#include <algorithm> #include <iostream> using namespace std; int main() { int N; int A[100000]; int ans = 0; cin >> N; for (int i = 0; i < N; i++) { cin >> A[i]; } sort(A, A + N); if (N == 2) { cout << A[1] - A[0] << endl; cout << A[1] << ' ' << A[0] << endl; return 0; } if (A[1] > 0) { ans = -A[0]; for (int i = 1; i < N; i++) ans += A[i]; int sum = A[0] - A[1]; cout << ans << endl; cout << A[0] << ' ' << A[1] << endl; for (int i = 2; i < N - 1; i++) { cout << sum << ' ' << A[i] << endl; sum -= A[i]; } cout << A[N - 1] << ' ' << sum << endl; } else if (A[N - 2] < 0) { ans = A[N - 1]; for (int i = N - 2; i >= 0; i--) ans -= A[i]; cout << ans << endl; int sum = A[N - 1]; for (int i = N - 2; i >= 0; i--) { cout << sum << ' ' << A[i] << endl; sum -= A[i]; } } else { int idx; for (int i = 0; i < N; i++) { if (A[i] >= 0) { idx = i; break; } } int sum = A[0]; for (int i = idx; i < N - 1; i++) { // cout << sum << ' ' << A[i] << endl; sum -= A[i]; } // cout << A[N-1] << ' ' << sum << endl; sum = A[N - 1] - sum; for (int i = 1; i < idx; i++) { // cout << sum << ' ' << A[i] << endl; sum -= A[i]; } cout << sum << endl; sum = A[0]; for (int i = idx; i < N - 1; i++) { cout << sum << ' ' << A[i] << endl; sum -= A[i]; } cout << A[N - 1] << ' ' << sum << endl; sum = A[N - 1] - sum; for (int i = 1; i < idx; i++) { cout << sum << ' ' << A[i] << endl; sum -= A[i]; } } }
#include <algorithm> #include <iostream> using namespace std; int main() { int N; int A[100000]; int ans = 0; cin >> N; for (int i = 0; i < N; i++) { cin >> A[i]; } sort(A, A + N); if (N == 2) { cout << A[1] - A[0] << endl; cout << A[1] << ' ' << A[0] << endl; return 0; } if (A[1] > 0) { ans = -A[0]; for (int i = 1; i < N; i++) ans += A[i]; int sum = A[0] - A[1]; cout << ans << endl; cout << A[0] << ' ' << A[1] << endl; for (int i = 2; i < N - 1; i++) { cout << sum << ' ' << A[i] << endl; sum -= A[i]; } cout << A[N - 1] << ' ' << sum << endl; } else if (A[N - 2] < 0) { ans = A[N - 1]; for (int i = N - 2; i >= 0; i--) ans -= A[i]; cout << ans << endl; int sum = A[N - 1]; for (int i = N - 2; i >= 0; i--) { cout << sum << ' ' << A[i] << endl; sum -= A[i]; } } else { int idx; for (int i = 2; i < N; i++) { if (A[i] >= 0) { idx = i; break; } } int sum = A[0]; for (int i = idx; i < N - 1; i++) { // cout << sum << ' ' << A[i] << endl; sum -= A[i]; } // cout << A[N-1] << ' ' << sum << endl; sum = A[N - 1] - sum; for (int i = 1; i < idx; i++) { // cout << sum << ' ' << A[i] << endl; sum -= A[i]; } cout << sum << endl; sum = A[0]; for (int i = idx; i < N - 1; i++) { cout << sum << ' ' << A[i] << endl; sum -= A[i]; } cout << A[N - 1] << ' ' << sum << endl; sum = A[N - 1] - sum; for (int i = 1; i < idx; i++) { cout << sum << ' ' << A[i] << endl; sum -= A[i]; } } }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change" ]
821,832
821,833
u693133807
cpp
p03007
#include <algorithm> #include <iostream> using namespace std; int main() { int N; int A[100000]; int ans = 0; cin >> N; for (int i = 0; i < N; i++) { cin >> A[i]; } sort(A, A + N); if (N == 2) { cout << A[1] - A[0] << endl; cout << A[1] << ' ' << A[0] << endl; return 0; } if (A[1] > 0) { ans = -A[0]; for (int i = 1; i < N; i++) ans += A[i]; int sum = A[0] - A[1]; cout << ans << endl; cout << A[0] << ' ' << A[1] << endl; for (int i = 2; i < N - 1; i++) { cout << sum << ' ' << A[i] << endl; sum -= A[i]; } cout << A[N - 1] << ' ' << sum << endl; } else if (A[N - 2] < 0) { ans = A[N - 1]; for (int i = N - 2; i >= 0; i--) ans -= A[i]; cout << ans << endl; int sum = A[N - 1]; for (int i = N - 2; i >= 0; i--) { cout << sum << ' ' << A[i] << endl; sum -= A[i]; } } else { int idx; for (int i = 0; i < N; i++) { if (A[i] > 0) { idx = i; break; } } int sum = A[0]; for (int i = idx; i < N - 1; i++) { // cout << sum << ' ' << A[i] << endl; sum -= A[i]; } // cout << A[N-1] << ' ' << sum << endl; sum = A[N - 1] - sum; for (int i = 1; i < idx; i++) { // cout << sum << ' ' << A[i] << endl; sum -= A[i]; } cout << sum << endl; sum = A[0]; for (int i = idx; i < N - 1; i++) { cout << sum << ' ' << A[i] << endl; sum -= A[i]; } cout << A[N - 1] << ' ' << sum << endl; sum = A[N - 1] - sum; for (int i = 1; i < idx; i++) { cout << sum << ' ' << A[i] << endl; sum -= A[i]; } } }
#include <algorithm> #include <iostream> using namespace std; int main() { int N; int A[100000]; int ans = 0; cin >> N; for (int i = 0; i < N; i++) { cin >> A[i]; } sort(A, A + N); if (N == 2) { cout << A[1] - A[0] << endl; cout << A[1] << ' ' << A[0] << endl; return 0; } if (A[1] > 0) { ans = -A[0]; for (int i = 1; i < N; i++) ans += A[i]; int sum = A[0] - A[1]; cout << ans << endl; cout << A[0] << ' ' << A[1] << endl; for (int i = 2; i < N - 1; i++) { cout << sum << ' ' << A[i] << endl; sum -= A[i]; } cout << A[N - 1] << ' ' << sum << endl; } else if (A[N - 2] < 0) { ans = A[N - 1]; for (int i = N - 2; i >= 0; i--) ans -= A[i]; cout << ans << endl; int sum = A[N - 1]; for (int i = N - 2; i >= 0; i--) { cout << sum << ' ' << A[i] << endl; sum -= A[i]; } } else { int idx; for (int i = 2; i < N; i++) { if (A[i] >= 0) { idx = i; break; } } int sum = A[0]; for (int i = idx; i < N - 1; i++) { // cout << sum << ' ' << A[i] << endl; sum -= A[i]; } // cout << A[N-1] << ' ' << sum << endl; sum = A[N - 1] - sum; for (int i = 1; i < idx; i++) { // cout << sum << ' ' << A[i] << endl; sum -= A[i]; } cout << sum << endl; sum = A[0]; for (int i = idx; i < N - 1; i++) { cout << sum << ' ' << A[i] << endl; sum -= A[i]; } cout << A[N - 1] << ' ' << sum << endl; sum = A[N - 1] - sum; for (int i = 1; i < idx; i++) { cout << sum << ' ' << A[i] << endl; sum -= A[i]; } } }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
821,834
821,833
u693133807
cpp
p03007
#include <algorithm> #include <cstring> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <math.h> #include <queue> #include <string> #include <tuple> #include <vector> using namespace std; #define MOD (long long int)(1e9 + 7) #define ll long long int #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define reps(i, n) for (int i = 1; i <= (int)(n); i++) #define REP(i, n) for (int i = n - 1; i >= 0; i--) #define REPS(i, n) for (int i = n; i > 0; i--) #define INF (int)(1123456789) #define LINF (long long int)(112345678901234567) #define chmax(a, b) a = (((a) < (b)) ? (b) : (a)) #define chmin(a, b) a = (((a) > (b)) ? (b) : (a)) #define all(v) v.begin(), v.end() int main(void) { int n; vector<ll> A; ll a, countP, countM; countP = 0; countM = 0; cin >> n; rep(i, n) { cin >> a; A.push_back(a); if (a >= 0) { countP++; } if (a <= 0) { countM++; } } sort(all(A)); reverse(all(A)); ll ans = 0; if (countP == 0) { rep(i, n) { ans += abs(A[i]); } ans -= abs(A[0]) * 2; cout << ans << endl; ll memo = A[0]; rep(i, n) { if (i == 0) continue; cout << memo << " " << A[i] << endl; memo -= A[i]; } return 0; } else if (countM == 0) { sort(all(A)); rep(i, n) { ans += A[i]; } ans -= A[0] * 2; cout << ans << endl; ll memo = A[0]; rep(i, n) { if (i == 0) continue; if (i == n - 1) { cout << A[i] << " " << memo << endl; return 0; } cout << memo << " " << A[i] << endl; memo -= A[i]; } } else { //降順 rep(i, n) { ans += abs(A[i]); } cout << ans << endl; int idx = 1; while (A[idx] >= 0 && idx < n) { cout << A[n - 1] << " " << A[idx] << endl; A[n - 1] -= A[idx]; idx++; } while (idx <= n - 2) { cout << A[0] << " " << A[idx] << endl; A[0] -= A[idx]; idx++; } cout << A[0] << " " << A[n - 1] << endl; return 0; } return 0; }
#include <algorithm> #include <cstring> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <math.h> #include <queue> #include <string> #include <tuple> #include <vector> using namespace std; #define MOD (long long int)(1e9 + 7) #define ll long long int #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define reps(i, n) for (int i = 1; i <= (int)(n); i++) #define REP(i, n) for (int i = n - 1; i >= 0; i--) #define REPS(i, n) for (int i = n; i > 0; i--) #define INF (int)(1123456789) #define LINF (long long int)(112345678901234567) #define chmax(a, b) a = (((a) < (b)) ? (b) : (a)) #define chmin(a, b) a = (((a) > (b)) ? (b) : (a)) #define all(v) v.begin(), v.end() int main(void) { int n; vector<ll> A; ll a, countP, countM; countP = 0; countM = 0; cin >> n; rep(i, n) { cin >> a; A.push_back(a); if (a >= 0) { countP++; } if (a <= 0) { countM++; } } sort(all(A)); reverse(all(A)); ll ans = 0; if (countP == 0) { rep(i, n) { ans += abs(A[i]); } ans -= abs(A[0]) * 2; cout << ans << endl; ll memo = A[0]; rep(i, n) { if (i == 0) continue; cout << memo << " " << A[i] << endl; memo -= A[i]; } return 0; } else if (countM == 0) { sort(all(A)); rep(i, n) { ans += A[i]; } ans -= A[0] * 2; cout << ans << endl; ll memo = A[0]; rep(i, n) { if (i == 0) continue; if (i == n - 1) { cout << A[i] << " " << memo << endl; return 0; } cout << memo << " " << A[i] << endl; memo -= A[i]; } } else { //降順 rep(i, n) { ans += abs(A[i]); } cout << ans << endl; int idx = 1; while (A[idx] >= 0 && idx <= n - 2) { cout << A[n - 1] << " " << A[idx] << endl; A[n - 1] -= A[idx]; idx++; } while (idx <= n - 2) { cout << A[0] << " " << A[idx] << endl; A[0] -= A[idx]; idx++; } cout << A[0] << " " << A[n - 1] << endl; return 0; } return 0; }
[ "expression.operator.compare.change", "control_flow.loop.condition.change" ]
821,846
821,847
u838742270
cpp
p03007
#include <bits/stdc++.h> //#include <ext/pb_ds/tree_policy.hpp> //#include <ext/pb_ds/assoc_container.hpp> using namespace std; // using namespace __gnu_pbds; // template<typename key, typename val> // using ordered_tree = // tree<key, val, greater<>, rb_tree_tag, tree_order_statistics_node_update>; typedef long long int64; typedef complex<double> comp; const double pi = 3.14159265358979323846; const int inf = (int)1e+9 + 2; const int64 inf64 = (int64)1e+18 + 2; const double dinf = 1e+20; const int mod = 1'000'000'007; // 998244353; const int base = 2187; const double eps = 1e-8; const int N = 200'000; const int LOGN = 18; int n, m, k; void solve(int test) { cin >> n; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } sort(a.begin(), a.end()); vector<pair<int, int>> ans; if (a.front() >= 0 && a.back() >= 0) { int val = a[0]; for (int i = 1; i < n - 1; ++i) { ans.emplace_back(val, a[i]); val -= a[i]; } ans.emplace_back(a.back(), val); } else if (a.front() <= 0 && a.back() <= 0) { reverse(a.begin(), a.end()); int val = a[0]; for (int i = 0; i < n; ++i) { ans.emplace_back(val, a[i]); val -= a[i]; } } else { int mid; for (mid = 0; a[mid] < 0; ++mid) ; int val = a[0]; for (int i = mid; i < n - 1; ++i) { ans.emplace_back(val, a[i]); val -= a[i]; } ans.emplace_back(a[n - 1], val); val = a[n - 1] - val; for (int i = 1; i < mid; ++i) { ans.emplace_back(val, a[i]); val -= a[i]; } } cout << ans.back().first - ans.back().second << '\n'; for (auto &pr : ans) { cout << pr.first << ' ' << pr.second << '\n'; } } void precalc() {} int main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); precalc(); int test = 1; // cin >> test; // auto start = chrono::high_resolution_clock::now(); for (int i = 1; i <= test; ++i) solve(i); // cerr << // chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() // - start).count() << '\n'; return 0; }
#include <bits/stdc++.h> //#include <ext/pb_ds/tree_policy.hpp> //#include <ext/pb_ds/assoc_container.hpp> using namespace std; // using namespace __gnu_pbds; // template<typename key, typename val> // using ordered_tree = // tree<key, val, greater<>, rb_tree_tag, tree_order_statistics_node_update>; typedef long long int64; typedef complex<double> comp; const double pi = 3.14159265358979323846; const int inf = (int)1e+9 + 2; const int64 inf64 = (int64)1e+18 + 2; const double dinf = 1e+20; const int mod = 1'000'000'007; // 998244353; const int base = 2187; const double eps = 1e-8; const int N = 200'000; const int LOGN = 18; int n, m, k; void solve(int test) { cin >> n; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } sort(a.begin(), a.end()); vector<pair<int, int>> ans; if (a.front() >= 0 && a.back() >= 0) { int val = a[0]; for (int i = 1; i < n - 1; ++i) { ans.emplace_back(val, a[i]); val -= a[i]; } ans.emplace_back(a.back(), val); } else if (a.front() <= 0 && a.back() <= 0) { reverse(a.begin(), a.end()); int val = a[0]; for (int i = 1; i < n; ++i) { ans.emplace_back(val, a[i]); val -= a[i]; } } else { int mid; for (mid = 0; a[mid] < 0; ++mid) ; int val = a[0]; for (int i = mid; i < n - 1; ++i) { ans.emplace_back(val, a[i]); val -= a[i]; } ans.emplace_back(a[n - 1], val); val = a[n - 1] - val; for (int i = 1; i < mid; ++i) { ans.emplace_back(val, a[i]); val -= a[i]; } } cout << ans.back().first - ans.back().second << '\n'; for (auto &pr : ans) { cout << pr.first << ' ' << pr.second << '\n'; } } void precalc() {} int main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); precalc(); int test = 1; // cin >> test; // auto start = chrono::high_resolution_clock::now(); for (int i = 1; i <= test; ++i) solve(i); // cerr << // chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() // - start).count() << '\n'; return 0; }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one" ]
821,848
821,849
u432090061
cpp
p03007
// Copyright: lzt #include <algorithm> #include <cmath> #include <cstdlib> #include <cstring> #include <ctime> #include <iostream> #include <map> #include <queue> #include <set> #include <stdio.h> #include <string> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef long double ld; typedef unsigned long long ull; typedef pair<long long, long long> pll; #define fi first #define se second #define pb push_back #define mp make_pair #define rep(i, j, k) for (register int i = (int)(j); i <= (int)(k); i++) #define rrep(i, j, k) for (register int i = (int)(j); i >= (int)(k); i--) #define Debug(...) fprintf(stderr, __VA_ARGS__) ll read() { ll x = 0, f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); } return x * f; } const int maxn = 100100; int n; int a[maxn]; vector<pii> vec; inline void sub(int &x, int y) { vec.pb(mp(x, y)); x -= y; } void out() { rep(i, 0, vec.size() - 1) printf("%d %d\n", vec[i].fi, vec[i].se); } void work() { n = read(); rep(i, 1, n) a[i] = read(); sort(a + 1, a + n + 1); if (a[1] <= 0 && a[n] >= 0) { int x = a[1]; int j = n; rrep(i, n - 1, 1) { if (a[i] < 0) break; sub(x, a[i]); j = i; } a[1] = x; x = a[n]; rep(i, 1, j - 1) sub(x, a[i]); printf("%d\n", x); out(); return; } if (a[1] > 0) { int x = a[1]; rep(i, 2, n - 1) sub(x, a[i]); sub(a[n], x); printf("%d\n", a[n]); out(); return; } if (a[n] < 0) { while (1) ; int x = a[n]; rep(i, 1, n - 1) sub(x, a[i]); printf("%d\n", x); out(); return; } } int main() { #ifdef LZT freopen("in", "r", stdin); #endif work(); #ifdef LZT Debug("My Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC); #endif }
// Copyright: lzt #include <algorithm> #include <cmath> #include <cstdlib> #include <cstring> #include <ctime> #include <iostream> #include <map> #include <queue> #include <set> #include <stdio.h> #include <string> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef long double ld; typedef unsigned long long ull; typedef pair<long long, long long> pll; #define fi first #define se second #define pb push_back #define mp make_pair #define rep(i, j, k) for (register int i = (int)(j); i <= (int)(k); i++) #define rrep(i, j, k) for (register int i = (int)(j); i >= (int)(k); i--) #define Debug(...) fprintf(stderr, __VA_ARGS__) ll read() { ll x = 0, f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); } return x * f; } const int maxn = 100100; int n; int a[maxn]; vector<pii> vec; inline void sub(int &x, int y) { vec.pb(mp(x, y)); x -= y; } void out() { rep(i, 0, vec.size() - 1) printf("%d %d\n", vec[i].fi, vec[i].se); } void work() { n = read(); rep(i, 1, n) a[i] = read(); sort(a + 1, a + n + 1); if (a[1] <= 0 && a[n] >= 0) { int x = a[1]; int j = n; rrep(i, n - 1, 2) { if (a[i] < 0) break; sub(x, a[i]); j = i; } a[1] = x; x = a[n]; rep(i, 1, j - 1) sub(x, a[i]); printf("%d\n", x); out(); return; } if (a[1] > 0) { int x = a[1]; rep(i, 2, n - 1) sub(x, a[i]); sub(a[n], x); printf("%d\n", a[n]); out(); return; } if (a[n] < 0) { int x = a[n]; rep(i, 1, n - 1) sub(x, a[i]); printf("%d\n", x); out(); return; } } int main() { #ifdef LZT freopen("in", "r", stdin); #endif work(); #ifdef LZT Debug("My Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC); #endif }
[ "literal.number.change", "call.arguments.change" ]
821,854
821,853
u357800105
cpp
p03007
// Copyright: lzt #include <algorithm> #include <cmath> #include <cstdlib> #include <cstring> #include <ctime> #include <iostream> #include <map> #include <queue> #include <set> #include <stdio.h> #include <string> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef long double ld; typedef unsigned long long ull; typedef pair<long long, long long> pll; #define fi first #define se second #define pb push_back #define mp make_pair #define rep(i, j, k) for (register int i = (int)(j); i <= (int)(k); i++) #define rrep(i, j, k) for (register int i = (int)(j); i >= (int)(k); i--) #define Debug(...) fprintf(stderr, __VA_ARGS__) ll read() { ll x = 0, f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); } return x * f; } const int maxn = 100100; int n; int a[maxn]; vector<pii> vec; inline void sub(int &x, int y) { vec.pb(mp(x, y)); x -= y; } void out() { rep(i, 0, vec.size() - 1) printf("%d %d\n", vec[i].fi, vec[i].se); } void work() { n = read(); rep(i, 1, n) a[i] = read(); sort(a + 1, a + n + 1); if (a[1] <= 0 && a[n] >= 0) { int x = a[1]; int j = n; rrep(i, n - 1, 1) { if (a[i] < 0) break; sub(x, a[i]); j = i; } a[1] = x; x = a[n]; rep(i, 1, j - 1) sub(x, a[i]); printf("%d\n", x); out(); return; } if (a[1] > 0) { int x = a[1]; rep(i, 2, n - 1) sub(x, a[i]); sub(a[n], x); printf("%d\n", a[n]); out(); return; } if (a[n] < 0) { int x = a[n]; rep(i, 1, n - 1) sub(x, a[i]); printf("%d\n", x); out(); return; } } int main() { #ifdef LZT freopen("in", "r", stdin); #endif work(); #ifdef LZT Debug("My Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC); #endif }
// Copyright: lzt #include <algorithm> #include <cmath> #include <cstdlib> #include <cstring> #include <ctime> #include <iostream> #include <map> #include <queue> #include <set> #include <stdio.h> #include <string> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef long double ld; typedef unsigned long long ull; typedef pair<long long, long long> pll; #define fi first #define se second #define pb push_back #define mp make_pair #define rep(i, j, k) for (register int i = (int)(j); i <= (int)(k); i++) #define rrep(i, j, k) for (register int i = (int)(j); i >= (int)(k); i--) #define Debug(...) fprintf(stderr, __VA_ARGS__) ll read() { ll x = 0, f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); } return x * f; } const int maxn = 100100; int n; int a[maxn]; vector<pii> vec; inline void sub(int &x, int y) { vec.pb(mp(x, y)); x -= y; } void out() { rep(i, 0, vec.size() - 1) printf("%d %d\n", vec[i].fi, vec[i].se); } void work() { n = read(); rep(i, 1, n) a[i] = read(); sort(a + 1, a + n + 1); if (a[1] <= 0 && a[n] >= 0) { int x = a[1]; int j = n; rrep(i, n - 1, 2) { if (a[i] < 0) break; sub(x, a[i]); j = i; } a[1] = x; x = a[n]; rep(i, 1, j - 1) sub(x, a[i]); printf("%d\n", x); out(); return; } if (a[1] > 0) { int x = a[1]; rep(i, 2, n - 1) sub(x, a[i]); sub(a[n], x); printf("%d\n", a[n]); out(); return; } if (a[n] < 0) { int x = a[n]; rep(i, 1, n - 1) sub(x, a[i]); printf("%d\n", x); out(); return; } } int main() { #ifdef LZT freopen("in", "r", stdin); #endif work(); #ifdef LZT Debug("My Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC); #endif }
[ "literal.number.change", "call.arguments.change" ]
821,856
821,853
u357800105
cpp
p03007
// Copyright: lzt #include <algorithm> #include <cmath> #include <cstdlib> #include <cstring> #include <ctime> #include <iostream> #include <map> #include <queue> #include <set> #include <stdio.h> #include <string> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef long double ld; typedef unsigned long long ull; typedef pair<long long, long long> pll; #define fi first #define se second #define pb push_back #define mp make_pair #define rep(i, j, k) for (register int i = (int)(j); i <= (int)(k); i++) #define rrep(i, j, k) for (register int i = (int)(j); i >= (int)(k); i--) #define Debug(...) fprintf(stderr, __VA_ARGS__) ll read() { ll x = 0, f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); } return x * f; } const int maxn = 100100; int n; int a[maxn]; vector<pii> vec; inline void sub(int &x, int y) { vec.pb(mp(x, y)); x -= y; } void out() { rep(i, 0, vec.size() - 1) printf("%d %d\n", vec[i].fi, vec[i].se); } void work() { n = read(); rep(i, 1, n) a[i] = read(); sort(a + 1, a + n + 1); if (a[1] <= 0 && a[n] >= 0) { int x = a[1]; int j; rrep(i, n - 1, 1) { if (a[i] < 0) break; sub(x, a[i]); j = i; } a[1] = x; x = a[n]; rep(i, 1, j - 1) sub(x, a[i]); printf("%d\n", x); out(); return; } if (a[1] > 0) { int x = a[1]; rep(i, 2, n - 1) sub(x, a[i]); sub(a[n], x); printf("%d\n", a[n]); out(); return; } if (a[n] < 0) { int x = a[n]; rep(i, 1, n - 1) sub(x, a[i]); printf("%d\n", x); out(); return; } } int main() { #ifdef LZT freopen("in", "r", stdin); #endif work(); #ifdef LZT Debug("My Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC); #endif }
// Copyright: lzt #include <algorithm> #include <cmath> #include <cstdlib> #include <cstring> #include <ctime> #include <iostream> #include <map> #include <queue> #include <set> #include <stdio.h> #include <string> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef long double ld; typedef unsigned long long ull; typedef pair<long long, long long> pll; #define fi first #define se second #define pb push_back #define mp make_pair #define rep(i, j, k) for (register int i = (int)(j); i <= (int)(k); i++) #define rrep(i, j, k) for (register int i = (int)(j); i >= (int)(k); i--) #define Debug(...) fprintf(stderr, __VA_ARGS__) ll read() { ll x = 0, f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); } return x * f; } const int maxn = 100100; int n; int a[maxn]; vector<pii> vec; inline void sub(int &x, int y) { vec.pb(mp(x, y)); x -= y; } void out() { rep(i, 0, vec.size() - 1) printf("%d %d\n", vec[i].fi, vec[i].se); } void work() { n = read(); rep(i, 1, n) a[i] = read(); sort(a + 1, a + n + 1); if (a[1] <= 0 && a[n] >= 0) { int x = a[1]; int j = n; rrep(i, n - 1, 2) { if (a[i] < 0) break; sub(x, a[i]); j = i; } a[1] = x; x = a[n]; rep(i, 1, j - 1) sub(x, a[i]); printf("%d\n", x); out(); return; } if (a[1] > 0) { int x = a[1]; rep(i, 2, n - 1) sub(x, a[i]); sub(a[n], x); printf("%d\n", a[n]); out(); return; } if (a[n] < 0) { int x = a[n]; rep(i, 1, n - 1) sub(x, a[i]); printf("%d\n", x); out(); return; } } int main() { #ifdef LZT freopen("in", "r", stdin); #endif work(); #ifdef LZT Debug("My Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC); #endif }
[ "variable_declaration.value.change", "literal.number.change", "call.arguments.change" ]
821,857
821,853
u357800105
cpp
p03007
#include <bits/stdc++.h> using namespace std; int n, m, ans, A, B, BA, a[120000]; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%d", a + i); } sort(a + 1, a + n + 1); ans = -a[1] + a[n]; for (int i = 2; i < n; ++i) ans += abs(a[i]); printf("%d\n", ans); int x = a[1], y = a[n]; for (int i = 2; i < n; ++i) if (a[i] < 0) { printf("%d %d\n", y, a[i]); y -= a[i]; } else { printf("%d %d\n", x, a[i]); x -= a[i]; } printf("%d %d\n", a[n], x); return 0; }
#include <bits/stdc++.h> using namespace std; int n, m, ans, A, B, BA, a[120000]; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%d", a + i); } sort(a + 1, a + n + 1); ans = -a[1] + a[n]; for (int i = 2; i < n; ++i) ans += abs(a[i]); printf("%d\n", ans); int x = a[1], y = a[n]; for (int i = 2; i < n; ++i) if (a[i] < 0) { printf("%d %d\n", y, a[i]); y -= a[i]; } else { printf("%d %d\n", x, a[i]); x -= a[i]; } printf("%d %d\n", y, x); return 0; }
[ "call.arguments.change", "io.output.change" ]
821,866
821,867
u225045588
cpp
p03007
#include <algorithm> #include <cstdint> #include <cstdio> #include <iostream> #include <string> #include <unordered_map> #include <vector> int main() { int n; while (std::cin >> n) { std::vector<int> a; for (int i = 0; i < n; ++i) { int x; std::cin >> x; a.push_back(x); } std::sort(a.begin(), a.end()); int ma = a.back(), mi = a.front(); int res = 0; for (int i = 1; i < n - 1; ++i) { if (a[i] > 0) { mi -= a[i]; } else { ma += a[i]; } } res = ma - mi; std::cout << res << std::endl; ma = a.back(), mi = a.front(); for (int i = 1; i < n - 1; ++i) { if (a[i] > 0) { std::cout << mi << " " << a[i] << std::endl; mi -= a[i]; } else { std::cout << ma << " " << a[i] << std::endl; ma += a[i]; } } std::cout << ma << " " << mi << std::endl; } return 0; }
#include <algorithm> #include <cstdint> #include <cstdio> #include <iostream> #include <string> #include <unordered_map> #include <vector> int main() { int n; while (std::cin >> n) { std::vector<int> a; for (int i = 0; i < n; ++i) { int x; std::cin >> x; a.push_back(x); } std::sort(a.begin(), a.end()); int ma = a.back(), mi = a.front(); int res = 0; for (int i = 1; i < n - 1; ++i) { if (a[i] > 0) { mi -= a[i]; } else { ma -= a[i]; } } res = ma - mi; std::cout << res << std::endl; ma = a.back(), mi = a.front(); for (int i = 1; i < n - 1; ++i) { if (a[i] > 0) { std::cout << mi << " " << a[i] << std::endl; mi -= a[i]; } else { std::cout << ma << " " << a[i] << std::endl; ma -= a[i]; } } std::cout << ma << " " << mi << std::endl; } return 0; }
[ "expression.operator.change" ]
821,870
821,871
u839270100
cpp
p03007
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> #define REP(i, n) for (ll i = 0; i < (ll)n; i++) #define INF 1000000000000000 using namespace std; typedef long long ll; typedef double db; typedef string str; int main() { int n; cin >> n; ll a[n]; REP(i, n) cin >> a[i]; sort(a, a + n); int k = 1; while (a[k] < 0) k++; k = min(n - 2, k); vector<ll> x1, y1; REP(i, n - k - 1) { x1.push_back(a[0]); y1.push_back(a[k + i]); a[0] = x1[i] - y1[i]; } vector<ll> x2, y2; REP(i, k - 1) { x2.push_back(a[n - 1]); y2.push_back(a[1 + i]); a[n - 1] = x2[i] - y2[i]; } ll x3 = a[n - 1], y3 = a[0]; cout << x3 - y3 << endl; REP(i, n - k - 1) printf("%lld %lld\n", x1[i], y1[i]); REP(i, k - 1) printf("%lld %lld\n", x2[i], y2[i]); printf("%lld %lld\n", x3, y3); return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> #define REP(i, n) for (ll i = 0; i < (ll)n; i++) #define INF 1000000000000000 using namespace std; typedef long long ll; typedef double db; typedef string str; int main() { int n; cin >> n; ll a[n]; REP(i, n) cin >> a[i]; sort(a, a + n); int k = 1; while (a[k] < 0) k++; k = min(n - 1, k); vector<ll> x1, y1; REP(i, n - k - 1) { x1.push_back(a[0]); y1.push_back(a[k + i]); a[0] = x1[i] - y1[i]; } vector<ll> x2, y2; REP(i, k - 1) { x2.push_back(a[n - 1]); y2.push_back(a[1 + i]); a[n - 1] = x2[i] - y2[i]; } ll x3 = a[n - 1], y3 = a[0]; cout << x3 - y3 << endl; REP(i, n - k - 1) printf("%lld %lld\n", x1[i], y1[i]); REP(i, k - 1) printf("%lld %lld\n", x2[i], y2[i]); printf("%lld %lld\n", x3, y3); return 0; }
[ "literal.number.change", "assignment.value.change", "call.arguments.change", "expression.operation.binary.change" ]
821,878
821,879
u780950519
cpp
p03007
//#define NDEBUG #include <cstddef> #include <cstdint> #include <vector> namespace n91 { using i8 = std::int_fast8_t; using i32 = std::int_fast32_t; using i64 = std::int_fast64_t; using u8 = std::uint_fast8_t; using u32 = std::uint_fast32_t; using u64 = std::uint_fast64_t; using isize = std::ptrdiff_t; using usize = std::size_t; constexpr usize operator"" _z(unsigned long long x) noexcept { return static_cast<usize>(x); } class rep { const usize f, l; public: class itr { friend rep; usize i; constexpr itr(const usize x) noexcept : i(x) {} public: void operator++() noexcept { ++i; } constexpr usize operator*() const noexcept { return i; } constexpr bool operator!=(const itr x) const noexcept { return i != x.i; } }; constexpr rep(const usize first, const usize last) noexcept : f(first), l(last) {} constexpr itr begin() const noexcept { return itr(f); } constexpr itr end() const noexcept { return itr(l); } }; class revrep { const usize f, l; public: class itr { friend revrep; usize i; constexpr itr(usize x) noexcept : i(x) {} public: void operator++() noexcept { --i; } constexpr usize operator*() const noexcept { return i; } constexpr bool operator!=(const itr x) const noexcept { return i != x.i; } }; constexpr revrep(usize first, usize last) noexcept : f(--first), l(--last) {} constexpr itr begin() const noexcept { return itr(l); } constexpr itr end() const noexcept { return itr(f); } }; template <class T> using vec_alias = std::vector<T>; template <class T> auto md_vec(const usize n, const T &value) { return std::vector<T>(n, value); } template <class... Args> auto md_vec(const usize n, Args... args) { return std::vector<decltype(md_vec(args...))>(n, md_vec(args...)); } template <class T> constexpr T difference(const T &a, const T &b) { return a < b ? b - a : a - b; } } // namespace n91 #include <algorithm> #include <iostream> #include <limits> #include <set> #include <utility> namespace n91 { void main_() { usize n; std::cin >> n; std::vector<bool> pos(n); std::vector<i32> a(n); for (auto &e : a) { std::cin >> e; } std::sort(a.begin(), a.end()); i32 sum = static_cast<i32>(0); for (const auto e : a) { sum += std::abs(e); } if (a.front() > static_cast<i32>(0)) { pos.front() = false; for (const auto i : rep(1_z, n)) { pos[i] = true; } sum -= a.front() + a.front(); } else if (a.back() < static_cast<i32>(0)) { for (const auto i : rep(0_z, n - 1_z)) { pos[i] = false; } pos.back() = true; sum += a.back() + a.back(); } else { pos.front() = false; for (const auto i : rep(1_z, n - 1_z)) { pos[i] = a[i] >= static_cast<i32>(0); } pos.back() = true; } std::cout << sum << std::endl; usize pi, ni; for (const auto i : rep(0_z, n)) { if (pos[i]) { pi = i; } else { ni = i; } } for (const auto i : rep(0_z, n)) { if (pos[i] && i != pi) { std::cout << a[ni] << " " << a[i] << "\n"; a[ni] -= a[i]; } } for (const auto i : rep(0_z, n)) { if (!pos[i]) { std::cout << a[pi] << " " << a[i] << "\n"; a[pi] - a[i]; } } } } // namespace n91 int main() { n91::main_(); return 0; }
//#define NDEBUG #include <cstddef> #include <cstdint> #include <vector> namespace n91 { using i8 = std::int_fast8_t; using i32 = std::int_fast32_t; using i64 = std::int_fast64_t; using u8 = std::uint_fast8_t; using u32 = std::uint_fast32_t; using u64 = std::uint_fast64_t; using isize = std::ptrdiff_t; using usize = std::size_t; constexpr usize operator"" _z(unsigned long long x) noexcept { return static_cast<usize>(x); } class rep { const usize f, l; public: class itr { friend rep; usize i; constexpr itr(const usize x) noexcept : i(x) {} public: void operator++() noexcept { ++i; } constexpr usize operator*() const noexcept { return i; } constexpr bool operator!=(const itr x) const noexcept { return i != x.i; } }; constexpr rep(const usize first, const usize last) noexcept : f(first), l(last) {} constexpr itr begin() const noexcept { return itr(f); } constexpr itr end() const noexcept { return itr(l); } }; class revrep { const usize f, l; public: class itr { friend revrep; usize i; constexpr itr(usize x) noexcept : i(x) {} public: void operator++() noexcept { --i; } constexpr usize operator*() const noexcept { return i; } constexpr bool operator!=(const itr x) const noexcept { return i != x.i; } }; constexpr revrep(usize first, usize last) noexcept : f(--first), l(--last) {} constexpr itr begin() const noexcept { return itr(l); } constexpr itr end() const noexcept { return itr(f); } }; template <class T> using vec_alias = std::vector<T>; template <class T> auto md_vec(const usize n, const T &value) { return std::vector<T>(n, value); } template <class... Args> auto md_vec(const usize n, Args... args) { return std::vector<decltype(md_vec(args...))>(n, md_vec(args...)); } template <class T> constexpr T difference(const T &a, const T &b) { return a < b ? b - a : a - b; } } // namespace n91 #include <algorithm> #include <iostream> #include <limits> #include <set> #include <utility> namespace n91 { void main_() { usize n; std::cin >> n; std::vector<bool> pos(n); std::vector<i32> a(n); for (auto &e : a) { std::cin >> e; } std::sort(a.begin(), a.end()); i32 sum = static_cast<i32>(0); for (const auto e : a) { sum += std::abs(e); } if (a.front() > static_cast<i32>(0)) { pos.front() = false; for (const auto i : rep(1_z, n)) { pos[i] = true; } sum -= a.front() + a.front(); } else if (a.back() < static_cast<i32>(0)) { for (const auto i : rep(0_z, n - 1_z)) { pos[i] = false; } pos.back() = true; sum += a.back() + a.back(); } else { pos.front() = false; for (const auto i : rep(1_z, n - 1_z)) { pos[i] = a[i] >= static_cast<i32>(0); } pos.back() = true; } std::cout << sum << std::endl; usize pi, ni; for (const auto i : rep(0_z, n)) { if (pos[i]) { pi = i; } else { ni = i; } } for (const auto i : rep(0_z, n)) { if (pos[i] && i != pi) { std::cout << a[ni] << " " << a[i] << "\n"; a[ni] -= a[i]; } } for (const auto i : rep(0_z, n)) { if (!pos[i]) { std::cout << a[pi] << " " << a[i] << "\n"; a[pi] -= a[i]; } } } } // namespace n91 int main() { n91::main_(); return 0; }
[ "assignment.compound.arithmetic.replace.add", "expression.operator.arithmetic.replace.remove", "expression.operation.binary.change" ]
821,880
821,881
u708618797
cpp
p03007
#include <bits/stdc++.h> #define INF 1e9 #define llINF 1e18 #define MOD 1000000007 #define pb push_back #define mp make_pair #define F first #define S second #define ll long long #define ull unsigned long long #define vi vector<ll> #define vvi vector<vi> #define DBG_N(hoge) cerr << " " << (hoge) << endl; #define DBG cerr << "!" << endl; #define BITLE(n) (1LL << ((ll)n)) #define BITCNT(n) (__builtin_popcountll(n)) #define SUBS(s, f, t) ((s).substr((f)-1, (t) - (f) + 1)) #define ALL(a) (a).begin(), (a).end() using namespace std; bool used[222222]; int main() { cin.tie(0); ios::sync_with_stdio(false); ll n; cin >> n; vi A(n); bool fl = false; for (auto &a : A) { cin >> a; if (a == 0) fl = true; } sort(ALL(A)); if (A[n - 1] < 0) { vector<pair<ll, ll>> ans; ans.pb(mp(A[n - 1], A[n - 2])); A[n - 1] -= A[n - 2]; for (int i = 0; i < n - 2; i++) { ans.pb(mp(A[n - 1], A[i])); A[n - 1] -= A[i]; } cout << A[n - 1] << endl; for (auto a : ans) cout << a.F << " " << a.S << endl; } else if (A[0] > 0) { vector<pair<ll, ll>> ans; for (int i = 1; i < n - 1; i++) { ans.pb(mp(A[0], A[i])); A[0] -= A[i]; } ans.pb(mp(A[n - 1], A[0])); A[n - 1] -= A[0]; cout << A[n - 1] << endl; for (auto a : ans) cout << a.F << " " << a.S << endl; } else { vector<pair<ll, ll>> ans; for (int i = 0; i < n - 1; i++) { if (A[i] >= 0) { ans.pb(mp(A[0], A[i])); used[i] = true; A[0] -= A[i]; } } for (int i = 0; i < n - 1; i++) { if (used[i] == false) { ans.pb(mp(A[n - 1], A[i])); A[n - 1] -= A[i]; } } cout << A[n - 1] << endl; for (auto a : ans) cout << a.F << " " << a.S << endl; } return 0; }
#include <bits/stdc++.h> #define INF 1e9 #define llINF 1e18 #define MOD 1000000007 #define pb push_back #define mp make_pair #define F first #define S second #define ll long long #define ull unsigned long long #define vi vector<ll> #define vvi vector<vi> #define DBG_N(hoge) cerr << " " << (hoge) << endl; #define DBG cerr << "!" << endl; #define BITLE(n) (1LL << ((ll)n)) #define BITCNT(n) (__builtin_popcountll(n)) #define SUBS(s, f, t) ((s).substr((f)-1, (t) - (f) + 1)) #define ALL(a) (a).begin(), (a).end() using namespace std; bool used[222222]; int main() { cin.tie(0); ios::sync_with_stdio(false); ll n; cin >> n; vi A(n); bool fl = false; for (auto &a : A) { cin >> a; if (a == 0) fl = true; } sort(ALL(A)); if (A[n - 1] <= 0) { vector<pair<ll, ll>> ans; ans.pb(mp(A[n - 1], A[n - 2])); A[n - 1] -= A[n - 2]; for (int i = 0; i < n - 2; i++) { ans.pb(mp(A[n - 1], A[i])); A[n - 1] -= A[i]; } cout << A[n - 1] << endl; for (auto a : ans) cout << a.F << " " << a.S << endl; } else if (A[0] >= 0) { vector<pair<ll, ll>> ans; for (int i = 1; i < n - 1; i++) { ans.pb(mp(A[0], A[i])); A[0] -= A[i]; } ans.pb(mp(A[n - 1], A[0])); A[n - 1] -= A[0]; cout << A[n - 1] << endl; for (auto a : ans) cout << a.F << " " << a.S << endl; } else { vector<pair<ll, ll>> ans; for (int i = 0; i < n - 1; i++) { if (A[i] >= 0) { ans.pb(mp(A[0], A[i])); used[i] = true; A[0] -= A[i]; } } for (int i = 0; i < n - 1; i++) { if (used[i] == false) { ans.pb(mp(A[n - 1], A[i])); A[n - 1] -= A[i]; } } cout << A[n - 1] << endl; for (auto a : ans) cout << a.F << " " << a.S << endl; } return 0; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
821,886
821,887
u905715926
cpp
p03007
#include <algorithm> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stdio.h> #include <string.h> #include <string> #include <vector> using namespace std; typedef long long ll; #define lowbit(x) (x) & (-x) #define sqr(x) (x) * (x) #define rep(i, a, b) for (register int i = a; i <= b; i++) #define per(i, a, b) for (register int i = a; i >= b; i--) #define fir first #define sec second #define mp(a, b) make_pair(a, b) #define pb(a) push_back(a) #define maxd 998244353 #define eps 1e-8 int n, a[100100]; int read() { int x = 0, f = 1; char ch = getchar(); while ((ch < '0') || (ch > '9')) { if (ch == '-') f = -1; ch = getchar(); } while ((ch >= '0') && (ch <= '9')) { x = x * 10 + (ch - '0'); ch = getchar(); } return x * f; } int main() { n = read(); rep(i, 1, n) a[i] = read(); sort(a + 1, a + 1 + n); int ans = 0; if (a[1] > 0) { rep(i, 2, n) ans += a[i]; ans -= a[1]; printf("%d\n", ans); if (n == 2) printf("%d %d", a[2], a[1]); else { int tmp = a[1]; rep(i, 2, n - 1) { printf("%d %d\n", tmp, a[i]); tmp -= a[i]; } printf("%d %d", a[n], tmp); } } else if (a[n] < 0) { int ans = 0; rep(i, 1, n - 1) ans -= a[i]; ans += a[n]; printf("%d\n", ans); int tmp = a[n]; rep(i, 1, n - 1) { printf("%d %d\n", tmp, a[i]); tmp -= a[i]; } } else { int ans = 0; rep(i, 1, n) ans += abs(a[i]); printf("%d\n", ans); int tmp = a[1]; rep(i, 1, n - 1) { if (a[i] >= 0) { printf("%d %d\n", tmp, a[i]); tmp -= a[i]; } } printf("%d %d\n", a[n], tmp); tmp = a[n] - tmp; rep(i, 2, n) { if (a[i] < 0) { printf("%d %d\n", tmp, a[i]); tmp -= a[i]; } } } return 0; }
#include <algorithm> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stdio.h> #include <string.h> #include <string> #include <vector> using namespace std; typedef long long ll; #define lowbit(x) (x) & (-x) #define sqr(x) (x) * (x) #define rep(i, a, b) for (register int i = a; i <= b; i++) #define per(i, a, b) for (register int i = a; i >= b; i--) #define fir first #define sec second #define mp(a, b) make_pair(a, b) #define pb(a) push_back(a) #define maxd 998244353 #define eps 1e-8 int n, a[100100]; int read() { int x = 0, f = 1; char ch = getchar(); while ((ch < '0') || (ch > '9')) { if (ch == '-') f = -1; ch = getchar(); } while ((ch >= '0') && (ch <= '9')) { x = x * 10 + (ch - '0'); ch = getchar(); } return x * f; } int main() { n = read(); rep(i, 1, n) a[i] = read(); sort(a + 1, a + 1 + n); int ans = 0; if (a[1] > 0) { rep(i, 2, n) ans += a[i]; ans -= a[1]; printf("%d\n", ans); if (n == 2) printf("%d %d", a[2], a[1]); else { int tmp = a[1]; rep(i, 2, n - 1) { printf("%d %d\n", tmp, a[i]); tmp -= a[i]; } printf("%d %d", a[n], tmp); } } else if (a[n] < 0) { int ans = 0; rep(i, 1, n - 1) ans -= a[i]; ans += a[n]; printf("%d\n", ans); int tmp = a[n]; rep(i, 1, n - 1) { printf("%d %d\n", tmp, a[i]); tmp -= a[i]; } } else { int ans = 0; rep(i, 1, n) ans += abs(a[i]); printf("%d\n", ans); int tmp = a[1]; rep(i, 2, n - 1) { if (a[i] >= 0) { printf("%d %d\n", tmp, a[i]); tmp -= a[i]; } } printf("%d %d\n", a[n], tmp); tmp = a[n] - tmp; rep(i, 2, n - 1) { if (a[i] < 0) { printf("%d %d\n", tmp, a[i]); tmp -= a[i]; } } } return 0; }
[ "literal.number.change", "call.arguments.change" ]
821,888
821,889
u340402002
cpp
p03007
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; signed main() { ios::sync_with_stdio(false); cin.tie(0); // c int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a.begin(), a.end()); int ans = 0; vector<int> neg, pos; for (int i = 1; i + 1 < n; i++) { if (a[i] < 0) neg.push_back(a[i]), ans -= a[i]; else pos.push_back(a[i]), ans += a[i]; } neg.push_back(a[0]); cout << ans - a[0] + a.back() << endl; while (pos.size()) { cout << neg[0] << " " << pos.back() << '\n'; neg[0] -= pos.back(); pos.pop_back(); } while (neg.size()) { cout << a.back() << " " << neg.back() << '\n'; a.back() += neg.back(); neg.pop_back(); } return 0; }
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; signed main() { ios::sync_with_stdio(false); cin.tie(0); // c int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a.begin(), a.end()); int ans = 0; vector<int> neg, pos; for (int i = 1; i + 1 < n; i++) { if (a[i] < 0) neg.push_back(a[i]), ans -= a[i]; else pos.push_back(a[i]), ans += a[i]; } neg.push_back(a[0]); cout << ans - a[0] + a.back() << endl; while (pos.size()) { cout << neg[0] << " " << pos.back() << '\n'; neg[0] -= pos.back(); pos.pop_back(); } while (neg.size()) { cout << a.back() << " " << neg.back() << '\n'; a.back() -= neg.back(); neg.pop_back(); } return 0; }
[ "expression.operator.change" ]
821,894
821,895
u817760251
cpp
p03007
#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 m) { ll r = 1; while (e > 0) { if (e & 1) r = (r % m) * (b % m) % m; b = (b % m) * (b % m) % m; 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; vector<int> a(n); bool neg = false, pos = false; rep(i, n) { cin >> a[i]; if (a[i] < 0) neg = true; else if (a[i] > 0) pos = true; } sort(a.begin(), a.end()); if (pos and !neg) { ll m = -a.front(); for (int i = n - 1; i >= 1; --i) { m += a[i]; } ppp(m); int b = a[0]; rep(i, n - 2) { cout << b << sp << a[i + 1] << endl; b -= a[i + 1]; } cout << a[n - 1] << sp << b << endl; } else if (!pos and neg) { ll m = a.back(); for (int i = 0; i < n - 1; ++i) { m -= a[i]; } ppp(m); int b = a[n - 1]; for (int i = 0; i < n - 1; ++i) { cout << b << sp << a[i] << endl; b -= a[i]; } } else if (pos and neg) { ll m = 0ll; for (int i = 0; i < n; ++i) { m += abs(a[i]); } ppp(m); int p = lower_bound(a.begin(), a.end(), 0) - a.begin(); ll b = a[0]; for (int i = p; i < n - 1; ++i) { cout << b << sp << a[i] << endl; b -= a[i]; } a[0] = b; b = a[n - 1]; for (int i = 0; i < n - p - 1; ++i) { cout << b << sp << a[i] << endl; b -= a[i]; } } else { ppp(0); rep(i, n - 1) { cout << "0 0" << endl; } } 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 m) { ll r = 1; while (e > 0) { if (e & 1) r = (r % m) * (b % m) % m; b = (b % m) * (b % m) % m; 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; vector<int> a(n); bool neg = false, pos = false; rep(i, n) { cin >> a[i]; if (a[i] < 0) neg = true; else if (a[i] > 0) pos = true; } sort(a.begin(), a.end()); if (pos and !neg) { ll m = -a.front(); for (int i = n - 1; i >= 1; --i) { m += a[i]; } ppp(m); int b = a[0]; rep(i, n - 2) { cout << b << sp << a[i + 1] << endl; b -= a[i + 1]; } cout << a[n - 1] << sp << b << endl; } else if (!pos and neg) { ll m = a.back(); for (int i = 0; i < n - 1; ++i) { m -= a[i]; } ppp(m); int b = a[n - 1]; for (int i = 0; i < n - 1; ++i) { cout << b << sp << a[i] << endl; b -= a[i]; } } else if (pos and neg) { ll m = 0ll; for (int i = 0; i < n; ++i) { m += abs(a[i]); } ppp(m); int p = lower_bound(a.begin(), a.end(), 0) - a.begin(); // cerr << a << endl; ll b = a[0]; for (int i = p; i < n - 1; ++i) { cout << b << sp << a[i] << endl; b -= a[i]; } a[0] = b; b = a[n - 1]; for (int i = 0; i < p; ++i) { cout << b << sp << a[i] << endl; b -= a[i]; } } else { ppp(0); rep(i, n - 1) { cout << "0 0" << endl; } } return 0; }
[ "expression.operation.binary.remove" ]
821,900
821,901
u306142032
cpp
p03007
#include <bits/stdc++.h> using namespace std; #define ld long double #define ll long long #define ALL(a) (a).begin(), (a).end() #define ALLR(a) (a).rbegin(), (a).rend() #define spa << " " << #define MP make_pair const ll MOD = 1e9 + 7; // const ll MOD = 998244353; ll INF = 1e18; void chmin(ll &a, ll b) { if (a > b) a = b; } void chmax(ll &a, ll b) { if (a < b) a = b; } void pmod(ll &a, ll b) { a = (a + b) % MOD; } void qmod(ll &a, ll b) { a = (a * b) % MOD; } void ans1(bool x) { if (x) cout << "Yes" << endl; else cout << "No" << endl; } void ans2(bool x) { if (x) cout << "YES" << endl; else cout << "NO" << endl; } void ans3(bool x) { if (x) cout << "Yay!" << endl; else cout << ":(" << endl; } void ans(bool x, ll y, ll z) { if (x) cout << y << endl; else cout << z << endl; } void ans(bool x, string y, string z) { if (x) cout << y << endl; else cout << z << endl; } ll gcd(ll x, ll y) { ll r; while ((r = x % y) != 0) { x = y; y = r; } return y; } int main() { ll i, j, o; ll res = 0, res1 = INF, res2 = -INF, buf = 0, buf1 = 0, buf2 = 0, buf3 = 0, buf4 = 0, sum = 0; ll l = 0, r = 0; bool judge = true; ll n; cin >> n; vector<ll> a(n); vector<pair<ll, ll>> b; for (i = 0; i < n; i++) { cin >> a[i]; } sort(ALLR(a)); vector<ll> c, d, e; for (i = 0; i < n; i++) { if (a[i] > 0) { c.push_back(a[i]); l++; } else if (a[i] < 0) { d.push_back(a[i]); r++; } else { buf3++; c.push_back(0); }; } sort(ALLR(c)); sort(ALL(d)); // cout<<l spa r<<endl; if (r == 0) { if (l != 2) { b.push_back({c.back(), c[c.size() - 2]}); buf = c.back() - c[c.size() - 2]; c.pop_back(); c.pop_back(); } else { b.push_back({c[c.size() - 2], c.back()}); buf = c[c.size() - 2] - c.back(); c.pop_back(); c.pop_back(); } } else if (l >= 2) { b.push_back({d.back(), c.back()}); buf = d.back() - c.back(); c.pop_back(); d.pop_back(); } else if (l != 0) { b.push_back({c.back(), d.back()}); buf = c.back() - d.back(); c.pop_back(); d.pop_back(); } else if (l == 0) { b.push_back({d.back(), d[d.size() - 2]}); buf = d.back() - d[d.size() - 2]; d.pop_back(); d.pop_back(); } sort(ALL(c)); sort(ALLR(d)); // cout<<c.size()<<endl; if (!c.empty()) { for (i = 0; i < c.size() - 1; i++) { res += c[i]; b.push_back({buf, c[i]}); buf = buf - c[i]; // cout<<buf<<endl; } b.push_back({c.back(), buf}); buf = c.back() - buf; // cout<<"tsts"<<endl; } for (i = 0; i < d.size(); i++) { res -= d[i]; b.push_back({buf, d[i]}); buf -= d[i]; } cout << buf << endl; for (i = 0; i < n - 1; i++) { cout << b[i].first spa b[i].second << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define ld long double #define ll long long #define ALL(a) (a).begin(), (a).end() #define ALLR(a) (a).rbegin(), (a).rend() #define spa << " " << #define MP make_pair const ll MOD = 1e9 + 7; // const ll MOD = 998244353; ll INF = 1e18; void chmin(ll &a, ll b) { if (a > b) a = b; } void chmax(ll &a, ll b) { if (a < b) a = b; } void pmod(ll &a, ll b) { a = (a + b) % MOD; } void qmod(ll &a, ll b) { a = (a * b) % MOD; } void ans1(bool x) { if (x) cout << "Yes" << endl; else cout << "No" << endl; } void ans2(bool x) { if (x) cout << "YES" << endl; else cout << "NO" << endl; } void ans3(bool x) { if (x) cout << "Yay!" << endl; else cout << ":(" << endl; } void ans(bool x, ll y, ll z) { if (x) cout << y << endl; else cout << z << endl; } void ans(bool x, string y, string z) { if (x) cout << y << endl; else cout << z << endl; } ll gcd(ll x, ll y) { ll r; while ((r = x % y) != 0) { x = y; y = r; } return y; } int main() { ll i, j, o; ll res = 0, res1 = INF, res2 = -INF, buf = 0, buf1 = 0, buf2 = 0, buf3 = 0, buf4 = 0, sum = 0; ll l = 0, r = 0; bool judge = true; ll n; cin >> n; vector<ll> a(n); vector<pair<ll, ll>> b; for (i = 0; i < n; i++) { cin >> a[i]; } sort(ALLR(a)); vector<ll> c, d, e; for (i = 0; i < n; i++) { if (a[i] > 0) { c.push_back(a[i]); l++; } else if (a[i] < 0) { d.push_back(a[i]); r++; } else { buf3++; c.push_back(0); l++; }; } sort(ALLR(c)); sort(ALL(d)); // cout<<l spa r<<endl; if (r == 0) { if (l != 2) { b.push_back({c.back(), c[c.size() - 2]}); buf = c.back() - c[c.size() - 2]; c.pop_back(); c.pop_back(); } else { b.push_back({c[c.size() - 2], c.back()}); buf = c[c.size() - 2] - c.back(); c.pop_back(); c.pop_back(); } } else if (l >= 2) { b.push_back({d.back(), c.back()}); buf = d.back() - c.back(); c.pop_back(); d.pop_back(); } else if (l != 0) { b.push_back({c.back(), d.back()}); buf = c.back() - d.back(); c.pop_back(); d.pop_back(); } else if (l == 0) { b.push_back({d.back(), d[d.size() - 2]}); buf = d.back() - d[d.size() - 2]; d.pop_back(); d.pop_back(); } sort(ALL(c)); sort(ALLR(d)); // cout<<c.size()<<endl; if (!c.empty()) { for (i = 0; i < c.size() - 1; i++) { res += c[i]; b.push_back({buf, c[i]}); buf = buf - c[i]; // cout<<buf<<endl; } b.push_back({c.back(), buf}); buf = c.back() - buf; // cout<<"tsts"<<endl; } for (i = 0; i < d.size(); i++) { res -= d[i]; b.push_back({buf, d[i]}); buf -= d[i]; } cout << buf << endl; for (i = 0; i < n - 1; i++) { cout << b[i].first spa b[i].second << endl; } return 0; }
[ "expression.unary.arithmetic.add" ]
821,902
821,903
u898167769
cpp
p03007
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; int a[N]; inline bool cmp(const int &x, const int &y) { return x > y; } int main() { int n; scanf("%d", &n); int s = 0; for (int i = 1; i <= n; i++) scanf("%d", &a[i]), s += a[i]; sort(a + 1, a + n + 1, cmp); if (a[n] > 0) { s -= a[n] * 2; printf("%d\n", s); int t = a[n]; for (int i = 2; i < n; i++) { printf("%d %d\n", t, a[i]); t = t - a[i]; } printf("%d %d\n", a[1], t); } else if (a[2] < 0) { s = a[1] * 2 - s; printf("%d\n", s); int t = a[1]; for (int i = 2; i <= n; i++) { printf("%d %d\n", t, a[i]); t -= a[i]; } } else { int k = 1; while (a[k] >= 0) k++; s = 0; for (int i = 1; i <= n; i++) s += abs(a[i]); printf("%d\n", s); int t = a[k]; for (int i = 2; i < k; i++) { printf("%d %d\n", t, a[i]); t -= a[i]; } printf("%d %d\n", a[1], t); t = a[1] - t; for (int i = k + 1; i <= n; i++) { printf("%d %d\n", t, a[i]); t -= a[i]; } } return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; int a[N]; inline bool cmp(const int &x, const int &y) { return x > y; } int main() { int n; scanf("%d", &n); int s = 0; for (int i = 1; i <= n; i++) scanf("%d", &a[i]), s += a[i]; sort(a + 1, a + n + 1, cmp); if (a[n] > 0) { s -= a[n] * 2; printf("%d\n", s); int t = a[n]; for (int i = 2; i < n; i++) { printf("%d %d\n", t, a[i]); t = t - a[i]; } printf("%d %d\n", a[1], t); } else if (a[2] < 0) { s = a[1] * 2 - s; printf("%d\n", s); int t = a[1]; for (int i = 2; i <= n; i++) { printf("%d %d\n", t, a[i]); t -= a[i]; } } else { int k = 1; while (k < n && a[k] >= 0) k++; s = 0; for (int i = 1; i <= n; i++) s += abs(a[i]); printf("%d\n", s); int t = a[k]; for (int i = 2; i < k; i++) { printf("%d %d\n", t, a[i]); t -= a[i]; } printf("%d %d\n", a[1], t); t = a[1] - t; for (int i = k + 1; i <= n; i++) { printf("%d %d\n", t, a[i]); t -= a[i]; } } return 0; }
[ "control_flow.loop.condition.change" ]
821,912
821,913
u113808031
cpp
p03007
//#define anjn // Anjan Agarwala - anjn98 #define opti #ifdef opti #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast,unroll-loops,fast-math") #pragma GCC target( \ "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") #endif #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; typedef long long int ll; typedef unsigned long long int ull; typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // ll power(ll x,ll y,ll p){ll r=1; x=x%p; while(y){ if(y&1) r= r*x%p; y=y>>1; // x=x*x%p; } return r; } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int csrand(int l = 0, int r = 1e9) { uniform_int_distribution<int> uid(l, r); return uid(rng); } #define PR(x) cout << #x << ": " << x << "\n"; #define PR1(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << "\n"; #define PR2(x, y, z) \ cout << #x << ": " << x << " | " << #y << ": " << y << " | " << #z \ << ": " << z << "\n"; #define ED cout << '\n'; #define IO \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define FILEIO \ freopen("input.txt", "r", stdin); \ freopen("output.txt", "w", stdout); #define all(v) v.begin(), v.end() #define endl '\n' #define fr1(j, n) for (int j = 0; j < n; j++) #define fr(n) for (int i = 0; i < n; i++) #define trav(x, s) for (auto x : s) #define PB push_back #define pii pair<int, int> #define pll pair<long long int, long long int> #define F first #define S second #define binf 2000000000000000001 #define mod 1000000007 const int N = 3e5 + 99; int32_t main() { IO int n, pp = 0, nn = 0; cin >> n; vector<int> a(n); fr(n) cin >> a[i]; sort(all(a)); fr(n) if (a[i] < 0) nn = 1; else pp = 1; if (n == 1) { cout << a[0] << endl; return 0; } if (pp && nn) { ll ps = 0, p1 = -1, ns = 0, n1 = -1, ans = 0; for (int i = 0; i < n; i++) { if (a[i] >= 0) ps = a[i], p1 = i; else ns = a[i], n1 = i; ans += abs(a[i]); } cout << ans << endl; for (int i = 0; i < n; i++) { if (a[i] >= 0 || i == n1) continue; cout << ps << " " << a[i] << endl; ps -= a[i]; } for (int i = 0; i < n; i++) { if (a[i] < 0 || i == p1) continue; cout << ns << " " << a[i] << endl; ns -= a[i]; } cout << ps << " " << ns << endl; } else if (pp) { ll sum = 0; fr(n) sum += a[i]; cout << (sum - a[0] - a[0]) << endl; sum = a[0]; for (int i = 1; i < n - 1; i++) { cout << sum << " " << a[i] << endl; sum -= a[i]; } cout << a[n - 1] << " " << sum << endl; } else { ll sum = 0; fr(n) sum += abs(a[i]); cout << sum + a[n - 1] + a[n - 1] << endl; sum = a[n - 1]; for (int i = n - 2; i >= 0; i--) { cout << sum << " " << a[i] << endl; sum -= a[i]; } } return 0; }
//#define anjn // Anjan Agarwala - anjn98 //#define opti #ifdef opti #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast,unroll-loops,fast-math") #pragma GCC target( \ "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") #endif #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; typedef long long int ll; typedef unsigned long long int ull; typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // ll power(ll x,ll y,ll p){ll r=1; x=x%p; while(y){ if(y&1) r= r*x%p; y=y>>1; // x=x*x%p; } return r; } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int csrand(int l = 0, int r = 1e9) { uniform_int_distribution<int> uid(l, r); return uid(rng); } #define PR(x) cout << #x << ": " << x << "\n"; #define PR1(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << "\n"; #define PR2(x, y, z) \ cout << #x << ": " << x << " | " << #y << ": " << y << " | " << #z \ << ": " << z << "\n"; #define ED cout << '\n'; #define IO \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define FILEIO \ freopen("input.txt", "r", stdin); \ freopen("output.txt", "w", stdout); #define all(v) v.begin(), v.end() #define endl '\n' #define fr1(j, n) for (int j = 0; j < n; j++) #define fr(n) for (int i = 0; i < n; i++) #define trav(x, s) for (auto x : s) #define PB push_back #define pii pair<int, int> #define pll pair<long long int, long long int> #define F first #define S second #define binf 2000000000000000001 #define mod 1000000007 const int N = 3e5 + 99; int32_t main() { IO int n, pp = 0, nn = 0; cin >> n; vector<ll> a(n); fr(n) cin >> a[i]; sort(all(a)); fr(n) if (a[i] < 0) nn = 1; else pp = 1; if (n == 1) { cout << a[0] << endl; return 0; } if (pp && nn) { ll ps = 0, p1 = -1, ns = 0, n1 = -1, ans = 0; for (int i = 0; i < n; i++) { if (a[i] >= 0) ps = a[i], p1 = i; else ns = a[i], n1 = i; ans += abs(a[i]); } cout << ans << endl; for (int i = 0; i < n; i++) { if (a[i] >= 0 || i == n1) continue; cout << ps << " " << a[i] << endl; ps -= a[i]; } for (int i = 0; i < n; i++) { if (a[i] < 0 || i == p1) continue; cout << ns << " " << a[i] << endl; ns -= a[i]; } cout << ps << " " << ns << endl; } else if (pp) { ll sum = 0; fr(n) sum += a[i]; cout << (sum - a[0] - a[0]) << endl; sum = a[0]; for (int i = 1; i < n - 1; i++) { cout << sum << " " << a[i] << endl; sum -= a[i]; } cout << a[n - 1] << " " << sum << endl; } else { ll sum = 0; fr(n) sum += abs(a[i]); cout << sum + a[n - 1] + a[n - 1] << endl; sum = a[n - 1]; for (int i = n - 2; i >= 0; i--) { cout << sum << " " << a[i] << endl; sum -= a[i]; } } return 0; }
[]
821,914
821,915
u089572841
cpp
p03007
#include <bits/stdc++.h> #define repd(i, a, b) for (ll i = (a); i < (b); i++) #define rep(i, n) repd(i, 0, n) typedef long long ll; using namespace std; template <typename T> void output(T, int); int gcd(int a, int b); void prime_map(map<ll, ll> &, ll); int main() { // source ll n; cin >> n; ll a[n]; rep(i, n) { cin >> a[i]; } sort(a, a + n); ll *lower_zero = lower_bound(a, a + n, 0); vector<pair<ll, ll>> ans; ll total; if (lower_zero == a) { repd(i, 1, n - 1) { ans.push_back(make_pair(a[0], a[i])); a[0] -= a[i]; } ans.push_back(make_pair(a[0], a[n - 1])); total = a[n - 1] - a[0]; } else if (lower_zero == a + n) { rep(i, n - 1) { ans.push_back(make_pair(a[n - 1], a[i])); a[n - 1] -= a[i]; } total = a[n - 1]; } else { ll num_zero = lower_zero - a; repd(i, 1, num_zero) { ans.push_back(make_pair(a[n - 1], a[i])); a[n - 1] -= a[i]; } repd(i, num_zero, n - 1) { ans.push_back(make_pair(a[0], a[i])); a[0] -= a[i]; } ans.push_back(make_pair(a[n - 1], a[0])); total = a[n - 1] - a[0]; } cout << total << endl; rep(i, n - 1) { cout << ans[i].first << " " << ans[i].second << endl; } return 0; } template <typename T> void output(T a, int precision) { if (precision > 0) { cout << setprecision(precision) << a << "\n"; } else { cout << a << "\n"; } } template <typename T> T min(T a, T b) { if (a < b) { return a; } else { return b; } } int gcd(int a, int b) { if (b == 0) { return a; } return gcd(b, a % b); } void prime_map(map<ll, ll> &m, ll num) { ll cache = num; repd(i, 2, sqrt(num) + 2) { if (num % i == 0) { if (m[i] == 0) { m[i] = 1; } else { m[i]++; } num /= i; break; } } if (cache == num) { if (m[num] == 0) { m[num] = 1; } else { m[num]++; } return; } else { prime_map(m, num); } }
#include <bits/stdc++.h> #define repd(i, a, b) for (ll i = (a); i < (b); i++) #define rep(i, n) repd(i, 0, n) typedef long long ll; using namespace std; template <typename T> void output(T, int); int gcd(int a, int b); void prime_map(map<ll, ll> &, ll); int main() { // source ll n; cin >> n; ll a[n]; rep(i, n) { cin >> a[i]; } sort(a, a + n); ll *lower_zero = lower_bound(a, a + n, 0); vector<pair<ll, ll>> ans; ll total; if (lower_zero == a) { repd(i, 1, n - 1) { ans.push_back(make_pair(a[0], a[i])); a[0] -= a[i]; } ans.push_back(make_pair(a[n - 1], a[0])); total = a[n - 1] - a[0]; } else if (lower_zero == a + n) { rep(i, n - 1) { ans.push_back(make_pair(a[n - 1], a[i])); a[n - 1] -= a[i]; } total = a[n - 1]; } else { ll num_zero = lower_zero - a; repd(i, 1, num_zero) { ans.push_back(make_pair(a[n - 1], a[i])); a[n - 1] -= a[i]; } repd(i, num_zero, n - 1) { ans.push_back(make_pair(a[0], a[i])); a[0] -= a[i]; } ans.push_back(make_pair(a[n - 1], a[0])); total = a[n - 1] - a[0]; } cout << total << endl; rep(i, n - 1) { cout << ans[i].first << " " << ans[i].second << endl; } return 0; } template <typename T> void output(T a, int precision) { if (precision > 0) { cout << setprecision(precision) << a << "\n"; } else { cout << a << "\n"; } } template <typename T> T min(T a, T b) { if (a < b) { return a; } else { return b; } } int gcd(int a, int b) { if (b == 0) { return a; } return gcd(b, a % b); } void prime_map(map<ll, ll> &m, ll num) { ll cache = num; repd(i, 2, sqrt(num) + 2) { if (num % i == 0) { if (m[i] == 0) { m[i] = 1; } else { m[i]++; } num /= i; break; } } if (cache == num) { if (m[num] == 0) { m[num] = 1; } else { m[num]++; } return; } else { prime_map(m, num); } }
[ "identifier.replace.add", "literal.replace.remove", "variable_access.subscript.index.change", "call.arguments.change", "identifier.replace.remove", "literal.replace.add", "expression.operation.binary.change", "expression.operation.binary.remove" ]
821,920
821,921
u030992242
cpp
p03007
#include <algorithm> #include <assert.h> #include <bitset> #include <ctype.h> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <time.h> #include <vector> #define mod 1000000007 #define ll long long int #define pb(x) push_back(x) #define MP(x, y) make_pair(x, y) using namespace std; ll power(ll a, ll b, ll m) { ll sol = power(a, b / 2, m); sol = (sol * sol) % m; if (b % 2 == 1) sol = (sol * a) % m; return (sol); } ll gcd(ll a, ll b) { if (b == 0) return a; else { return gcd(b, a % b); } } ll a[100005]; void solve() { int n; ll sum = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; sum = sum + abs(a[i]); } sort(a, a + n); if (a[0] < 0 && a[n - 1] < 0) { ll x = a[n - 1]; cout << sum + 2 * a[n - 1] << endl; for (int i = n - 2; i >= 0; i--) { cout << x << " " << a[i] << endl; x = x - a[i]; } return; } if (a[0] > 0 && a[n - 1] > 0) { ll x = a[0]; cout << sum - 2 * a[0] << endl; for (int i = 1; i < n - 1; i++) { cout << x << " " << a[i] << endl; x = x - a[i]; } cout << a[n - 1] << " " << x; return; } cout << sum << endl; int i = n - 2, x = a[0]; while (a[i] >= 0) { cout << x << " " << a[i] << endl; x = x - a[i]; i--; } cout << a[n - 1] << " " << x << endl; x = a[n - 1] - x; i = 1; while (a[i] < 0) { cout << x << " " << a[i] << endl; x = x - a[i]; i++; } } int main() { int t = 1; // cin >> t; while (t--) solve(); return (0); }
#include <algorithm> #include <assert.h> #include <bitset> #include <ctype.h> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <time.h> #include <vector> #define mod 1000000007 #define ll long long int #define pb(x) push_back(x) #define MP(x, y) make_pair(x, y) using namespace std; ll power(ll a, ll b, ll m) { ll sol = power(a, b / 2, m); sol = (sol * sol) % m; if (b % 2 == 1) sol = (sol * a) % m; return (sol); } ll gcd(ll a, ll b) { if (b == 0) return a; else { return gcd(b, a % b); } } ll a[100005]; void solve() { int n; ll sum = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; sum = sum + abs(a[i]); } sort(a, a + n); if (a[0] < 0 && a[n - 1] < 0) { ll x = a[n - 1]; cout << sum + 2 * a[n - 1] << endl; for (int i = n - 2; i >= 0; i--) { cout << x << " " << a[i] << endl; x = x - a[i]; } return; } if (a[0] >= 0 && a[n - 1] >= 0) { ll x = a[0]; cout << sum - 2 * a[0] << endl; for (int i = 1; i < n - 1; i++) { cout << x << " " << a[i] << endl; x = x - a[i]; } cout << a[n - 1] << " " << x; return; } cout << sum << endl; int i = n - 2, x = a[0]; while (a[i] >= 0) { cout << x << " " << a[i] << endl; x = x - a[i]; i--; } cout << a[n - 1] << " " << x << endl; x = a[n - 1] - x; i = 1; while (a[i] < 0) { cout << x << " " << a[i] << endl; x = x - a[i]; i++; } } int main() { int t = 1; // cin >> t; while (t--) solve(); return (0); }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
821,924
821,925
u773115096
cpp
p03007
#include <algorithm> #include <assert.h> #include <bitset> #include <ctype.h> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <time.h> #include <vector> #define mod 1000000007 #define ll long long int #define pb(x) push_back(x) #define MP(x, y) make_pair(x, y) using namespace std; ll power(ll a, ll b, ll m) { ll sol = power(a, b / 2, m); sol = (sol * sol) % m; if (b % 2 == 1) sol = (sol * a) % m; return (sol); } ll gcd(ll a, ll b) { if (b == 0) return a; else { return gcd(b, a % b); } } ll a[100005]; void solve() { int n; ll sum = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; sum = sum + abs(a[i]); } sort(a, a + n); if (a[0] < 0 && a[n - 1] < 0) { ll x = a[n - 1]; cout << sum + 2 * a[n - 1] << endl; for (int i = n - 2; i >= 0; i--) { cout << x << " " << a[i] << endl; x = x - a[i]; } return; } if (a[0] > 0 && a[n - 1] > 0) { ll x = a[0]; cout << sum - 2 * a[0] << endl; for (int i = 1; i < n - 1; i++) { cout << x << " " << a[i] << endl; x = x - a[i]; } cout << a[n - 1] << " " << x; return; } cout << sum << endl; int i = n - 2, x = a[0]; while (a[i] > 0) { cout << x << " " << a[i] << endl; x = x - a[i]; i--; } cout << a[n - 1] << " " << x << endl; x = a[n - 1] - x; i = 1; while (a[i] < 0) { cout << x << " " << a[i] << endl; x = x - a[i]; i++; } } int main() { int t = 1; // cin >> t; while (t--) solve(); return (0); }
#include <algorithm> #include <assert.h> #include <bitset> #include <ctype.h> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <time.h> #include <vector> #define mod 1000000007 #define ll long long int #define pb(x) push_back(x) #define MP(x, y) make_pair(x, y) using namespace std; ll power(ll a, ll b, ll m) { ll sol = power(a, b / 2, m); sol = (sol * sol) % m; if (b % 2 == 1) sol = (sol * a) % m; return (sol); } ll gcd(ll a, ll b) { if (b == 0) return a; else { return gcd(b, a % b); } } ll a[100005]; void solve() { int n; ll sum = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; sum = sum + abs(a[i]); } sort(a, a + n); if (a[0] < 0 && a[n - 1] < 0) { ll x = a[n - 1]; cout << sum + 2 * a[n - 1] << endl; for (int i = n - 2; i >= 0; i--) { cout << x << " " << a[i] << endl; x = x - a[i]; } return; } if (a[0] >= 0 && a[n - 1] >= 0) { ll x = a[0]; cout << sum - 2 * a[0] << endl; for (int i = 1; i < n - 1; i++) { cout << x << " " << a[i] << endl; x = x - a[i]; } cout << a[n - 1] << " " << x; return; } cout << sum << endl; int i = n - 2, x = a[0]; while (a[i] >= 0) { cout << x << " " << a[i] << endl; x = x - a[i]; i--; } cout << a[n - 1] << " " << x << endl; x = a[n - 1] - x; i = 1; while (a[i] < 0) { cout << x << " " << a[i] << endl; x = x - a[i]; i++; } } int main() { int t = 1; // cin >> t; while (t--) solve(); return (0); }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change", "control_flow.loop.condition.change" ]
821,926
821,925
u773115096
cpp
p03007
#include <algorithm> #include <assert.h> #include <bitset> #include <ctype.h> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <time.h> #include <vector> #define mod 1000000007 #define ll long long int #define pb(x) push_back(x) #define MP(x, y) make_pair(x, y) using namespace std; ll power(ll a, ll b, ll m) { ll sol = power(a, b / 2, m); sol = (sol * sol) % m; if (b % 2 == 1) sol = (sol * a) % m; return (sol); } ll gcd(ll a, ll b) { if (b == 0) return a; else { return gcd(b, a % b); } } ll a[100005]; void solve() { int n; ll sum = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; sum = sum + abs(a[i]); } sort(a, a + n); if (a[0] < 0 && a[n - 1] < 0) { int x = a[n - 1]; cout << sum + 2 * a[n - 1] << endl; for (int i = n - 2; i >= 0; i--) { cout << x << " " << a[i] << endl; x = x - a[i]; } return; } if (a[0] > 0 && a[n - 1] > 0) { int x = a[0]; cout << sum - 2 * a[0] << endl; for (int i = 1; i < n - 1; i++) { cout << x << " " << a[i] << endl; x = x - a[i]; } cout << a[n - 1] << " " << x; return; } cout << sum << endl; int i = n - 2, x = a[0]; while (a[i] >= 0) { cout << x << " " << a[i] << endl; x = x - a[i]; i--; } cout << a[n - 1] << " " << x << endl; x = a[n - 1] - x; i = 1; while (a[i] < 0) { cout << x << " " << a[i] << endl; x = x - a[i]; i++; } } int main() { int t = 1; // cin >> t; while (t--) solve(); return (0); }
#include <algorithm> #include <assert.h> #include <bitset> #include <ctype.h> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <time.h> #include <vector> #define mod 1000000007 #define ll long long int #define pb(x) push_back(x) #define MP(x, y) make_pair(x, y) using namespace std; ll power(ll a, ll b, ll m) { ll sol = power(a, b / 2, m); sol = (sol * sol) % m; if (b % 2 == 1) sol = (sol * a) % m; return (sol); } ll gcd(ll a, ll b) { if (b == 0) return a; else { return gcd(b, a % b); } } ll a[100005]; void solve() { int n; ll sum = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; sum = sum + abs(a[i]); } sort(a, a + n); if (a[0] < 0 && a[n - 1] < 0) { ll x = a[n - 1]; cout << sum + 2 * a[n - 1] << endl; for (int i = n - 2; i >= 0; i--) { cout << x << " " << a[i] << endl; x = x - a[i]; } return; } if (a[0] >= 0 && a[n - 1] >= 0) { ll x = a[0]; cout << sum - 2 * a[0] << endl; for (int i = 1; i < n - 1; i++) { cout << x << " " << a[i] << endl; x = x - a[i]; } cout << a[n - 1] << " " << x; return; } cout << sum << endl; int i = n - 2, x = a[0]; while (a[i] >= 0) { cout << x << " " << a[i] << endl; x = x - a[i]; i--; } cout << a[n - 1] << " " << x << endl; x = a[n - 1] - x; i = 1; while (a[i] < 0) { cout << x << " " << a[i] << endl; x = x - a[i]; i++; } } int main() { int t = 1; // cin >> t; while (t--) solve(); return (0); }
[ "variable_declaration.type.change", "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
821,927
821,925
u773115096
cpp
p03007
#include <algorithm> #include <iostream> using namespace std; int main() { const int MAX_N = 1e5 + 10; int N, A[MAX_N], ans = 0; cin >> N; for (int i = 0; i < N; ++i) { cin >> A[i]; ans += abs(A[i]); } sort(A, A + N); if (A[0] > 0) ans -= 2 * A[0]; if (A[N - 1] < 0) ans += 2 * A[N - 1]; cout << ans << endl; int p = A[N - 1]; int n = A[0]; for (int i = 1; i < N - 1; ++i) { if (A[i] < 0) { cout << p << " " << A[i] << endl; p -= A[i]; } if (A[i] > 0) { cout << n << " " << A[i] << endl; n -= A[i]; } } cout << p << " " << n << endl; return 0; }
#include <algorithm> #include <iostream> using namespace std; int main() { const int MAX_N = 1e5 + 10; int N, A[MAX_N], ans = 0; cin >> N; for (int i = 0; i < N; ++i) { cin >> A[i]; ans += abs(A[i]); } sort(A, A + N); if (A[0] > 0) ans -= 2 * A[0]; if (A[N - 1] < 0) ans += 2 * A[N - 1]; cout << ans << endl; int p = A[N - 1]; int n = A[0]; for (int i = 1; i < N - 1; ++i) { if (A[i] <= 0) { cout << p << " " << A[i] << endl; p -= A[i]; } if (A[i] > 0) { cout << n << " " << A[i] << endl; n -= A[i]; } } cout << p << " " << n << endl; return 0; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
821,937
821,938
u128142352
cpp
p03007
#include <bits/stdc++.h> using namespace std; int N; long long arr[100005]; vector<pair<long long, long long>> ans; int main() { cin.sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N; long long mini = INT_MAX, maxi = INT_MIN, idxmini = 0, idxmaxi = 0; for (int i = 1; i <= N; i++) { cin >> arr[i]; if (arr[i] < mini) { mini = arr[i]; idxmini = i; } if (arr[i] >= maxi) { maxi = arr[i]; idxmaxi = i; } } if (maxi == 0 && mini == 0) { for (int i = 1; i < N; i++) { ans.push_back({0, 0}); } } else if (maxi < 0) { for (int i = 1; i <= N; i++) { if (i != idxmaxi) { ans.push_back({maxi, arr[i]}); maxi -= arr[i]; } } } else if (mini > 0) { for (int i = 1; i <= N; i++) { if (i != idxmini && i != idxmaxi) { ans.push_back({mini, arr[i]}); mini -= arr[i]; } } ans.push_back({maxi, mini}); maxi -= mini; } else { for (int i = 1; i <= N; i++) { if (i != idxmaxi && arr[i] >= 0) { ans.push_back({mini, arr[i]}); mini -= arr[i]; } if (i != idxmini && arr[i] < 0) { ans.push_back({maxi, arr[i]}); maxi -= arr[i]; } } ans.push_back({maxi, mini}); maxi -= mini; } cout << maxi << "\n"; for (auto p : ans) { cout << p.first << " " << p.second << "\n"; } }
#include <bits/stdc++.h> using namespace std; int N; long long arr[100005]; vector<pair<long long, long long>> ans; int main() { cin.sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N; long long mini = INT_MAX, maxi = INT_MIN, idxmini = 0, idxmaxi = 0; for (int i = 1; i <= N; i++) { cin >> arr[i]; if (arr[i] < mini) { mini = arr[i]; idxmini = i; } if (arr[i] >= maxi) { maxi = arr[i]; idxmaxi = i; } } if (maxi == 0 && mini == 0) { for (int i = 1; i < N; i++) { ans.push_back({0, 0}); } } else if (maxi <= 0) { for (int i = 1; i <= N; i++) { if (i != idxmaxi) { ans.push_back({maxi, arr[i]}); maxi -= arr[i]; } } } else if (mini >= 0) { for (int i = 1; i <= N; i++) { if (i != idxmini && i != idxmaxi) { ans.push_back({mini, arr[i]}); mini -= arr[i]; } } ans.push_back({maxi, mini}); maxi -= mini; } else { for (int i = 1; i <= N; i++) { if (i != idxmaxi && arr[i] >= 0) { ans.push_back({mini, arr[i]}); mini -= arr[i]; } if (i != idxmini && arr[i] < 0) { ans.push_back({maxi, arr[i]}); maxi -= arr[i]; } } ans.push_back({maxi, mini}); maxi -= mini; } cout << maxi << "\n"; for (auto p : ans) { cout << p.first << " " << p.second << "\n"; } }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
821,943
821,944
u937063359
cpp
p03007
#include <algorithm> #include <iostream> #include <math.h> #include <string> #include <vector> using namespace std; int main() { int n; cin >> n; vector<long long> a, b; for (int i = 0; i < n; i++) { int t; cin >> t; a.push_back(t); b.push_back(t); } sort(a.begin(), a.end(), greater<long long>()); sort(b.begin(), b.end(), greater<long long>()); int w = n - 1; for (int i = 0; i < a.size(); i++) { if (a[i] <= 0) { w = i; break; } } for (int i = 1; i < b.size() - 1 && i < w; i++) { b[n - 1] = b[n - 1] - b[i]; } for (int i = w; i < b.size(); i++) { b[0] -= b[i]; } cout << b[0] << endl; for (int i = 1; i < a.size() - 1 && i < w; i++) { cout << a[n - 1] << " " << a[i] << endl; a[n - 1] = a[n - 1] - a[i]; } for (int i = w; i < a.size(); i++) { cout << a[0] << " " << a[i] << endl; a[0] -= a[i]; } }
#include <algorithm> #include <iostream> #include <math.h> #include <string> #include <vector> using namespace std; int main() { int n; cin >> n; vector<long long> a, b; for (int i = 0; i < n; i++) { int t; cin >> t; a.push_back(t); b.push_back(t); } sort(a.begin(), a.end(), greater<long long>()); sort(b.begin(), b.end(), greater<long long>()); int w = n - 1; for (int i = 1; i < a.size(); i++) { if (a[i] <= 0) { w = i; break; } } for (int i = 1; i < b.size() - 1 && i < w; i++) { b[n - 1] = b[n - 1] - b[i]; } for (int i = w; i < b.size(); i++) { b[0] -= b[i]; } cout << b[0] << endl; for (int i = 1; i < a.size() - 1 && i < w; i++) { cout << a[n - 1] << " " << a[i] << endl; a[n - 1] = a[n - 1] - a[i]; } for (int i = w; i < a.size(); i++) { cout << a[0] << " " << a[i] << endl; a[0] -= a[i]; } }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one" ]
821,950
821,951
u702906718
cpp
p03007
#include <bits/stdc++.h> using namespace std; #define ll long long ll nya(stack<ll> minus, stack<ll> plus, int mc, int pc) { if (mc == 0) { ll n1 = plus.top(); plus.pop(); ll n2 = plus.top(); plus.pop(); minus.push(n1 - n2); pc -= 2; mc++; } for (; 1 <= mc && 1 < pc; pc--) { ll n = minus.top() - plus.top(); minus.pop(); plus.pop(); minus.push(n); } ll po = plus.top(); for (; 0 < mc; mc--) { po -= minus.top(); minus.pop(); } return po; } ll mya(stack<ll> minus, stack<ll> plus, int mc, int pc) { if (mc == 0) { ll n1 = plus.top(); plus.pop(); ll n2 = plus.top(); plus.pop(); minus.push(n1 - n2); pc -= 2; mc++; cout << n1 << " " << n2 << endl; } for (; 1 <= mc && 1 < pc; pc--) { ll n1 = minus.top(); ll n2 = plus.top(); minus.pop(); plus.pop(); minus.push(n1 - n2); cout << n1 << " " << n2 << endl; } ll po = plus.top(); for (; 0 < mc; mc--) { cout << po << " " << minus.top() << endl; po -= minus.top(); minus.pop(); } return po; } int main() { int N; vector<ll> A; vector<ll> A_cp; cin >> N; A.resize(N); int minus_count = 0; int plus_count = 0; for (int i = 0; i < N; i++) { cin >> A[i]; if (0 < A[i]) { plus_count++; } if (A[i] <= 0) { minus_count++; } } sort(A.begin(), A.end()); if (N == 2) { cout << A[1] - A[0] << endl; cout << A[1] << " " << A[0] << endl; return 0; } copy(A.begin(), A.end(), back_inserter(A_cp)); stack<ll> minus; stack<ll> plus; int pre = 0; if (plus_count == 0) { ll x = A_cp[N - 1] - A_cp[0]; A_cp[N - 2] = x; pre = 1; } for (int i = pre; i < minus_count; i++) { minus.push(A_cp[i]); } for (int i = N - 1; minus_count <= i; i--) { plus.push(A_cp[i]); } cout << nya(minus, plus, minus_count - pre * 2, plus_count + pre) << endl; if (pre) { cout << A[N - 1] << " " << A[0] << endl; } mya(minus, plus, minus_count - pre * 2, plus_count + pre); return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long ll nya(stack<ll> minus, stack<ll> plus, int mc, int pc) { if (mc == 0) { ll n1 = plus.top(); plus.pop(); ll n2 = plus.top(); plus.pop(); minus.push(n1 - n2); pc -= 2; mc++; } for (; 1 <= mc && 1 < pc; pc--) { ll n = minus.top() - plus.top(); minus.pop(); plus.pop(); minus.push(n); } ll po = plus.top(); for (; 0 < mc; mc--) { po -= minus.top(); minus.pop(); } return po; } ll mya(stack<ll> minus, stack<ll> plus, int mc, int pc) { if (mc == 0) { ll n1 = plus.top(); plus.pop(); ll n2 = plus.top(); plus.pop(); minus.push(n1 - n2); pc -= 2; mc++; cout << n1 << " " << n2 << endl; } for (; 1 <= mc && 1 < pc; pc--) { ll n1 = minus.top(); ll n2 = plus.top(); minus.pop(); plus.pop(); minus.push(n1 - n2); cout << n1 << " " << n2 << endl; } ll po = plus.top(); for (; 0 < mc; mc--) { cout << po << " " << minus.top() << endl; po -= minus.top(); minus.pop(); } return po; } int main() { int N; vector<ll> A; vector<ll> A_cp; cin >> N; A.resize(N); int minus_count = 0; int plus_count = 0; for (int i = 0; i < N; i++) { cin >> A[i]; if (0 < A[i]) { plus_count++; } if (A[i] <= 0) { minus_count++; } } sort(A.begin(), A.end()); if (N == 2) { cout << A[1] - A[0] << endl; cout << A[1] << " " << A[0] << endl; return 0; } copy(A.begin(), A.end(), back_inserter(A_cp)); stack<ll> minus; stack<ll> plus; int pre = 0; if (plus_count == 0) { ll x = A_cp[N - 1] - A_cp[0]; A_cp[N - 1] = x; pre = 1; } for (int i = pre; i < minus_count - pre; i++) { minus.push(A_cp[i]); } for (int i = N - 1; minus_count - pre <= i; i--) { plus.push(A_cp[i]); } cout << nya(minus, plus, minus_count - pre * 2, plus_count + pre) << endl; if (pre) { cout << A[N - 1] << " " << A[0] << endl; } mya(minus, plus, minus_count - pre * 2, plus_count + pre); return 0; }
[ "literal.number.change", "assignment.variable.change", "variable_access.subscript.index.change", "expression.operation.binary.change", "control_flow.loop.for.condition.change" ]
821,969
821,970
u697421413
cpp
p03007
#include <algorithm> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <string> #include <tuple> #include <vector> using namespace std; #define REP(i, p, n) for (int i = p; i < n; ++i) #define rep(i, n) REP(i, 0, n) using ll = long long int; using pll = pair<ll, ll>; int main() { ll N; cin >> N; vector<ll> A(N); for (auto &a : A) { cin >> a; } sort(A.begin(), A.end()); { ll M = A[A.size() - 1] - A[0]; ll index = 1; while (index < N - 1 && A[index] <= 0) { M -= A[index]; ++index; } while (index < N - 1) { M += A[index]; ++index; } cout << M << endl; } { ll M = A[A.size() - 1]; ll index = 1; while (index < N - 1 && A[index] <= 0) { cout << M << " " << A[index]; M -= A[index]; ++index; } ll t = A[0]; while (index < N - 1) { cout << t << " " << A[index] << endl; t -= A[index]; ++index; } cout << M << " " << t << endl; M -= t; } return 0; }
#include <algorithm> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <string> #include <tuple> #include <vector> using namespace std; #define REP(i, p, n) for (int i = p; i < n; ++i) #define rep(i, n) REP(i, 0, n) using ll = long long int; using pll = pair<ll, ll>; int main() { ll N; cin >> N; vector<ll> A(N); for (auto &a : A) { cin >> a; } sort(A.begin(), A.end()); { ll M = A[A.size() - 1] - A[0]; ll index = 1; while (index < N - 1 && A[index] <= 0) { M -= A[index]; ++index; } while (index < N - 1) { M += A[index]; ++index; } cout << M << endl; } { ll M = A[A.size() - 1]; ll index = 1; while (index < N - 1 && A[index] <= 0) { cout << M << " " << A[index] << endl; M -= A[index]; ++index; } ll t = A[0]; while (index < N - 1) { cout << t << " " << A[index] << endl; t -= A[index]; ++index; } cout << M << " " << t << endl; M -= t; } return 0; }
[ "io.output.newline.add" ]
821,973
821,974
u039041830
cpp
p03007
#include <algorithm> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <limits.h> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> using namespace std; #define ll long long #define ull unsigned long long #define rep(i, N) for (ll i = 0; i < N; i++) #define loop(i, N, M) for (ll i = N; i < M; i++) #define MAX(v) *max_element(v.begin(), v.end()) #define MIN(v) *min_element(v.begin(), v.end()) #define SORTL2S(type, v) sort(v.begin(), v.end(), greater<type>()) #define SORTS2L(type, v) sort(v.begin(), v.end()) #define SORTMF(v, func) sort(v.begin(), v.end(), func) template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } ll N; vector<ll> vec; void solve() { cin >> N; vec.resize(N); bool po = false, ne = false; rep(i, N) { cin >> vec[i]; if (vec[i] >= 0) po = true; if (vec[i] < 0) ne = true; } SORTS2L(ll, vec); vector<pair<ll, ll>> ans; if (po == true && ne == false) { ll mm = vec[0]; rep(i, N - 2) { ans.emplace_back(make_pair(mm, vec[i + 1])); mm -= vec[i]; } ans.emplace_back(make_pair(vec[N - 1], mm)); mm = vec[N - 1] - mm; cout << mm << endl; rep(i, N - 1) { cout << ans[i].first << " " << ans[i].second << endl; } } if (po == false && ne == true) { ll mx = vec[N - 1]; rep(i, N - 2) { ans.emplace_back(make_pair(mx, vec[N - i - 2])); mx -= vec[N - i - 2]; } ans.emplace_back(make_pair(mx, vec[0])); mx = mx - vec[0]; cout << mx << endl; rep(i, N - 1) { cout << ans[i].first << " " << ans[i].second << endl; } } if (po == true && ne == true) { ll mx = vec[N - 1]; rep(i, N - 2) { if (vec[i + 1] > 0) break; ans.emplace_back(make_pair(mx, vec[i + 1])); mx -= vec[i + 1]; } ll mm = vec[0]; rep(i, N - 2) { if (vec[N - i - 2] <= 0) break; ans.emplace_back(make_pair(mm, vec[N - i - 2])); mm -= vec[N - i - 2]; } ans.emplace_back(make_pair(mx, mm)); mx = mx - mm; cout << mx << endl; rep(i, N - 1) { cout << ans[i].first << " " << ans[i].second << endl; } } } int main() { solve(); cout << endl; return 0; }
#include <algorithm> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <limits.h> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> using namespace std; #define ll long long #define ull unsigned long long #define rep(i, N) for (ll i = 0; i < N; i++) #define loop(i, N, M) for (ll i = N; i < M; i++) #define MAX(v) *max_element(v.begin(), v.end()) #define MIN(v) *min_element(v.begin(), v.end()) #define SORTL2S(type, v) sort(v.begin(), v.end(), greater<type>()) #define SORTS2L(type, v) sort(v.begin(), v.end()) #define SORTMF(v, func) sort(v.begin(), v.end(), func) template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } ll N; vector<ll> vec; void solve() { cin >> N; vec.resize(N); bool po = false, ne = false; rep(i, N) { cin >> vec[i]; if (vec[i] >= 0) po = true; if (vec[i] < 0) ne = true; } SORTS2L(ll, vec); vector<pair<ll, ll>> ans; if (po == true && ne == false) { ll mm = vec[0]; rep(i, N - 2) { ans.emplace_back(make_pair(mm, vec[i + 1])); mm -= vec[i + 1]; } ans.emplace_back(make_pair(vec[N - 1], mm)); mm = vec[N - 1] - mm; cout << mm << endl; rep(i, N - 1) { cout << ans[i].first << " " << ans[i].second << endl; } } if (po == false && ne == true) { ll mx = vec[N - 1]; rep(i, N - 2) { ans.emplace_back(make_pair(mx, vec[N - i - 2])); mx -= vec[N - i - 2]; } ans.emplace_back(make_pair(mx, vec[0])); mx = mx - vec[0]; cout << mx << endl; rep(i, N - 1) { cout << ans[i].first << " " << ans[i].second << endl; } } if (po == true && ne == true) { ll mx = vec[N - 1]; rep(i, N - 2) { if (vec[i + 1] > 0) break; ans.emplace_back(make_pair(mx, vec[i + 1])); mx -= vec[i + 1]; } ll mm = vec[0]; rep(i, N - 2) { if (vec[N - i - 2] <= 0) break; ans.emplace_back(make_pair(mm, vec[N - i - 2])); mm -= vec[N - i - 2]; } ans.emplace_back(make_pair(mx, mm)); mx = mx - mm; cout << mx << endl; rep(i, N - 1) { cout << ans[i].first << " " << ans[i].second << endl; } } } int main() { solve(); cout << endl; return 0; }
[ "assignment.change" ]
821,983
821,984
u426855695
cpp
p03007
#include <algorithm> #include <cmath> #include <cstring> #include <iostream> #include <map> #include <queue> #include <string> #include <vector> using namespace std; typedef long long ll; typedef pair<ll, ll> P; ll n, a; string str; int main() { cin >> n; priority_queue<ll> p, m; for (ll i = 1; i <= n; i++) { cin >> a; if (a >= 0) { p.push(-a); } else { m.push(a); } } if (p.size() == 0) { p.push(-m.top()); m.pop(); } if (m.size() == 0) { m.push(-p.top()); p.pop(); } vector<ll> ansp, ansm; while (!(p.size() == 1 && m.size() == 1)) { if (p.size() <= m.size()) { ansp.push_back(-p.top()); ansm.push_back(m.top()); a = -p.top() - m.top(); p.pop(); m.pop(); p.push(-a); } else { ansp.push_back(-p.top()); ansm.push_back(m.top()); a = -p.top() - m.top(); p.pop(); m.pop(); m.push(-a); } } ansp.push_back(-p.top()); ansm.push_back(m.top()); cout << -p.top() - m.top() << endl; for (ll i = 0; i < ansp.size(); i++) { cout << ansp[i] << " " << ansm[i] << endl; } return 0; }
#include <algorithm> #include <cmath> #include <cstring> #include <iostream> #include <map> #include <queue> #include <string> #include <vector> using namespace std; typedef long long ll; typedef pair<ll, ll> P; ll n, a; string str; int main() { cin >> n; priority_queue<ll> p, m; for (ll i = 1; i <= n; i++) { cin >> a; if (a >= 0) { p.push(-a); } else { m.push(a); } } if (p.size() == 0) { p.push(-m.top()); m.pop(); } if (m.size() == 0) { m.push(-p.top()); p.pop(); } vector<ll> ansp, ansm; while (!(p.size() == 1 && m.size() == 1)) { if (p.size() <= m.size()) { ansp.push_back(-p.top()); ansm.push_back(m.top()); a = -p.top() - m.top(); p.pop(); m.pop(); p.push(-a); } else { ansp.push_back(m.top()); ansm.push_back(-p.top()); a = -p.top() - m.top(); p.pop(); m.pop(); m.push(-a); } } ansp.push_back(-p.top()); ansm.push_back(m.top()); cout << -p.top() - m.top() << endl; for (ll i = 0; i < ansp.size(); i++) { cout << ansp[i] << " " << ansm[i] << endl; } return 0; }
[ "call.add", "call.remove" ]
821,985
821,986
u388697579
cpp
p03007
#include <algorithm> #include <iostream> #include <map> #include <math.h> #include <numeric> #include <queue> #include <regex> #include <set> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <vector> using namespace std; /*--- Macro ---*/ #define rep(i, n) for (int i = 0; i < (int)n; i++) #define rep1(i, n) for (int i = 1; i < (int)n; i++) #define mp make_pair #define pb push_back /*--- Type ---*/ typedef long long ll; typedef pair<int, int> pi; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vll; /*--- Constants ---*/ template <typename T> const T INF = numeric_limits<T>::max() / 10; const int MOD = (int)1e9 + 7; // 4-direction int dy4[] = {0, 1, -1, 0}; int dx4[] = {1, 0, 0, -1}; // 8-direction int dy8[] = {0, 1, 1, 1, 0, -1, -1, -1}; int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}; // Floating const double EPS = 1e-11; #define EQ0(x) (abs(x) < EPS) #define EQ(x, y) (abs(a - b) < EPS) int main() { vector<pair<int, int>> c; int n; vector<int> a; cin >> n; a.resize(n); rep(i, n) cin >> a[i]; sort(a.begin(), a.end()); vector<int> b; int _max = a[n - 1]; int _min = a[0]; int p = 1; while (p < n - 1 && a[p] < 0) { b.pb(a[p]); } for (int i = p; i < n - 1; i++) { c.pb(mp(_min, a[i])); _min -= a[i]; } b.pb(_min); rep(i, b.size()) { c.pb(mp(_max, b[i])); _max -= b[i]; } // cout << "---------------" << endl; // rep(i, b.size()) { // cout << b[i] << endl; // } // cout << "---------------" << endl; // cout << "-----------" << endl; // rep(i, c.size()) { // cout << c[i].first << ", " << c[i].second << endl; // } cout << _max << endl; rep(i, c.size()) { cout << c[i].first << " " << c[i].second << endl; } return 0; }
#include <algorithm> #include <iostream> #include <map> #include <math.h> #include <numeric> #include <queue> #include <regex> #include <set> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <vector> using namespace std; /*--- Macro ---*/ #define rep(i, n) for (int i = 0; i < (int)n; i++) #define rep1(i, n) for (int i = 1; i < (int)n; i++) #define mp make_pair #define pb push_back /*--- Type ---*/ typedef long long ll; typedef pair<int, int> pi; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vll; /*--- Constants ---*/ template <typename T> const T INF = numeric_limits<T>::max() / 10; const int MOD = (int)1e9 + 7; // 4-direction int dy4[] = {0, 1, -1, 0}; int dx4[] = {1, 0, 0, -1}; // 8-direction int dy8[] = {0, 1, 1, 1, 0, -1, -1, -1}; int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}; // Floating const double EPS = 1e-11; #define EQ0(x) (abs(x) < EPS) #define EQ(x, y) (abs(a - b) < EPS) int main() { vector<pair<int, int>> c; int n; vector<int> a; cin >> n; a.resize(n); rep(i, n) cin >> a[i]; sort(a.begin(), a.end()); vector<int> b; int _max = a[n - 1]; int _min = a[0]; int p = 1; while (p < n - 1 && a[p] < 0) { b.pb(a[p]); p++; } for (int i = p; i < n - 1; i++) { c.pb(mp(_min, a[i])); _min -= a[i]; } b.pb(_min); rep(i, b.size()) { c.pb(mp(_max, b[i])); _max -= b[i]; } // cout << "---------------" << endl; // rep(i, b.size()) { // cout << b[i] << endl; // } // cout << "---------------" << endl; // cout << "-----------" << endl; // rep(i, c.size()) { // cout << c[i].first << ", " << c[i].second << endl; // } cout << _max << endl; rep(i, c.size()) { cout << c[i].first << " " << c[i].second << endl; } return 0; }
[ "expression.unary.arithmetic.add" ]
821,989
821,990
u704630096
cpp
p03007
//#define DEB1 //output check function //#define DEB2 //same output, input from input.txt #include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <mutex> #include <queue> #include <set> #include <stack> #include <string> #include <thread> #include <vector> #define ZERO(a) memset(a, 0, sizeof(a)) #define MINUS(a) memset(a, 0xff, sizeof(a)) #define INF(a) memset(a, 0x3f, sizeof(a)) #define ALL(t) (t).begin(), (t).end() #define FILL(a, c) fill(a, a + sizeof(a) / sizeof(*a), c) #define FILL2D(A, c) fill(A[0], A[0] + sizeof(A) / sizeof(**A), c) #define FILL3D(A, c) fill(A[0][0], A[0][0] + sizeof(A) / sizeof(***A), c) #define REP(i, m) for (int i = 0; i < (m); ++i) #define REPN(i, m, in) for (int i = (in); i < (m); ++i) #define IN(a, x, b) (a <= x && x < b) #define PB push_back using namespace std; using LL = long long; using PAIR = pair<int, int>; using PAIRLL = pair<LL, LL>; using VI = vector<int>; using VVI = vector<VI>; 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; } #ifdef DEB1 #define DPRINT(x) cout << #x << "=" << (x) << endl; // print at debug mode #else #define DPRINT(x) ; #endif #ifdef DEB1 #define DCHECK(x) cout << "debug check" << #x << endl; #else #define DCHECK(x) ; #endif /* constant values */ // const int dx[] = {1,0,-1,0}; // const int dy[] = {0,1,0,-1}; // const int MX = 31001; // const ll INF= 1LL<<60 ;//INF = 1001001001001; //1e9 // Main program void solve() { vector<int> vec; queue<int> pos, neg, x, y; int N, a; cin >> N; REP(i, N) { cin >> a; vec.PB(a); // chmin(min,A[i]); // chmax(max,A[i]); } int minid = distance(vec.begin(), min_element(vec.begin(), vec.end())); int maxid = distance(vec.begin(), max_element(vec.begin(), vec.end())); if (minid == maxid) { ++maxid; } DPRINT(minid) DPRINT(maxid) REP(i, N) { int tmp = vec[i]; if (i != minid && i != maxid) { if (i >= 0) { pos.push(tmp); DCHECK('pos') } else { neg.push(tmp); DCHECK('neg') } } } int now = vec[minid]; while (!pos.empty()) { x.push(now); y.push(pos.front()); now = now - pos.front(); pos.pop(); DCHECK('pos pop') } int max = vec[maxid]; x.push(max); y.push(now); now = max - now; while (!neg.empty()) { x.push(now); y.push(neg.front()); now = now - neg.front(); neg.pop(); DCHECK('neg pop') } cout << now << endl; while (!x.empty()) { cout << x.front() << " " << y.front() << endl; x.pop(); y.pop(); } } // ---------------------------------------------- int main() { #ifdef DEB2 cout << "DEBUG MODE" << endl; ifstream in("input.txt"); // for debug cin.rdbuf(in.rdbuf()); // for debug #endif int T = 1; for (int i = 0; i < T; ++i) { solve(); } }
//#define DEB1 //output check function //#define DEB2 //same output, input from input.txt #include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <mutex> #include <queue> #include <set> #include <stack> #include <string> #include <thread> #include <vector> #define ZERO(a) memset(a, 0, sizeof(a)) #define MINUS(a) memset(a, 0xff, sizeof(a)) #define INF(a) memset(a, 0x3f, sizeof(a)) #define ALL(t) (t).begin(), (t).end() #define FILL(a, c) fill(a, a + sizeof(a) / sizeof(*a), c) #define FILL2D(A, c) fill(A[0], A[0] + sizeof(A) / sizeof(**A), c) #define FILL3D(A, c) fill(A[0][0], A[0][0] + sizeof(A) / sizeof(***A), c) #define REP(i, m) for (int i = 0; i < (m); ++i) #define REPN(i, m, in) for (int i = (in); i < (m); ++i) #define IN(a, x, b) (a <= x && x < b) #define PB push_back using namespace std; using LL = long long; using PAIR = pair<int, int>; using PAIRLL = pair<LL, LL>; using VI = vector<int>; using VVI = vector<VI>; 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; } #ifdef DEB1 #define DPRINT(x) cout << #x << "=" << (x) << endl; // print at debug mode #else #define DPRINT(x) ; #endif #ifdef DEB1 #define DCHECK(x) cout << "debug check" << #x << endl; #else #define DCHECK(x) ; #endif /* constant values */ // const int dx[] = {1,0,-1,0}; // const int dy[] = {0,1,0,-1}; // const int MX = 31001; // const ll INF= 1LL<<60 ;//INF = 1001001001001; //1e9 // Main program void solve() { vector<int> vec; queue<int> pos, neg, x, y; int N, a; cin >> N; REP(i, N) { cin >> a; vec.PB(a); // chmin(min,A[i]); // chmax(max,A[i]); } int minid = distance(vec.begin(), min_element(vec.begin(), vec.end())); int maxid = distance(vec.begin(), max_element(vec.begin(), vec.end())); if (minid == maxid) { ++maxid; } DPRINT(minid) DPRINT(maxid) REP(i, N) { int tmp = vec[i]; if (i != minid && i != maxid) { if (vec[i] >= 0) { pos.push(tmp); DCHECK('pos') } else { neg.push(tmp); DCHECK('neg') } } } int now = vec[minid]; while (!pos.empty()) { x.push(now); y.push(pos.front()); now = now - pos.front(); pos.pop(); DCHECK('pos pop') } int max = vec[maxid]; x.push(max); y.push(now); now = max - now; while (!neg.empty()) { x.push(now); y.push(neg.front()); now = now - neg.front(); neg.pop(); DCHECK('neg pop') } cout << now << endl; while (!x.empty()) { cout << x.front() << " " << y.front() << endl; x.pop(); y.pop(); } } // ---------------------------------------------- int main() { #ifdef DEB2 cout << "DEBUG MODE" << endl; ifstream in("input.txt"); // for debug cin.rdbuf(in.rdbuf()); // for debug #endif int T = 1; for (int i = 0; i < T; ++i) { solve(); } }
[ "control_flow.branch.if.condition.change" ]
821,993
821,994
u495072453
cpp
p03007
#include <bits/stdc++.h> using namespace std; #define _for(i, j, N) for (int i = (j); i < (N); i++) #define _rep(i, j, N) for (int i = (j); i <= (N); i++) #define ALL(x) x.begin(), x.end() #define pb push_back #define mk make_pair typedef long long LL; typedef pair<int, int> Interval; template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { _for(i, 0, v.size()) os << v[i] << " "; return os; } template <typename T> ostream &operator<<(ostream &os, const set<T> &v) { for (typename set<T>::iterator it = v.begin(); it != v.end(); it++) os << *it << " "; return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &v) { os << v.first << " " << v.second << endl; return os; } int N; const int maxn = 1e5 + 5; int A[maxn]; vector<LL> ans; LL ret; int main() { cin >> N; _for(i, 0, N) { cin >> A[i]; } sort(A, A + N, greater<int>()); if (A[0] >= 0 && A[N - 1] <= 0) { LL temp = A[0]; _for(i, 0, N - 1) { if (A[i] < 0) { ans.pb(temp); ans.pb(A[i]); temp = temp - A[i]; } } LL temp2 = A[N - 1]; for (int i = N - 2; i > 0; i--) { if (A[i] > 0) { ans.pb(temp2); ans.pb(A[i]); temp2 = temp2 - A[i]; } } ans.pb(temp); ans.pb(temp2); ret = temp - temp2; } else if (A[0] > 0 && A[N - 1] >= 0) { LL temp = A[N - 1]; for (int i = N - 2; i > 0; i--) { ans.pb(temp); ans.pb(A[i]); temp -= A[i]; } ans.pb(A[0]); ans.pb(temp); ret = A[0] - temp; } else if (A[0] <= 0 && A[N - 1] < 0) { LL temp = A[0]; _for(i, 1, N) { ans.pb(temp); ans.pb(A[i]); temp -= A[i]; } ret = temp; } printf("%lld\n", ret); for (int i = 0; i < ans.size(); i += 2) { printf("%lld %lld\n", ans[i], ans[i + 1]); } return 0; }
#include <bits/stdc++.h> using namespace std; #define _for(i, j, N) for (int i = (j); i < (N); i++) #define _rep(i, j, N) for (int i = (j); i <= (N); i++) #define ALL(x) x.begin(), x.end() #define pb push_back #define mk make_pair typedef long long LL; typedef pair<int, int> Interval; template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { _for(i, 0, v.size()) os << v[i] << " "; return os; } template <typename T> ostream &operator<<(ostream &os, const set<T> &v) { for (typename set<T>::iterator it = v.begin(); it != v.end(); it++) os << *it << " "; return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &v) { os << v.first << " " << v.second << endl; return os; } int N; const int maxn = 1e5 + 5; int A[maxn]; vector<LL> ans; LL ret; int main() { cin >> N; _for(i, 0, N) { cin >> A[i]; } sort(A, A + N, greater<int>()); if (A[0] >= 0 && A[N - 1] <= 0) { LL temp = A[0]; _for(i, 1, N - 1) { if (A[i] <= 0) { ans.pb(temp); ans.pb(A[i]); temp = temp - A[i]; } } LL temp2 = A[N - 1]; for (int i = N - 2; i > 0; i--) { if (A[i] > 0) { ans.pb(temp2); ans.pb(A[i]); temp2 = temp2 - A[i]; } } ans.pb(temp); ans.pb(temp2); ret = temp - temp2; } else if (A[0] > 0 && A[N - 1] >= 0) { LL temp = A[N - 1]; for (int i = N - 2; i > 0; i--) { ans.pb(temp); ans.pb(A[i]); temp -= A[i]; } ans.pb(A[0]); ans.pb(temp); ret = A[0] - temp; } else if (A[0] <= 0 && A[N - 1] < 0) { LL temp = A[0]; _for(i, 1, N) { ans.pb(temp); ans.pb(A[i]); temp -= A[i]; } ret = temp; } printf("%lld\n", ret); for (int i = 0; i < ans.size(); i += 2) { printf("%lld %lld\n", ans[i], ans[i + 1]); } return 0; }
[ "literal.number.change", "call.arguments.change", "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
821,999
822,000
u066651036
cpp
p03007
#include <bits/stdc++.h> #define x first #define y second using namespace std; typedef long long ll; const int N = 1e5 + 10; int n; ll a[N]; ll sum = 0; vector<pair<ll, ll>> v; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i]; sum += a[i]; } sort(a + 1, a + 1 + n); for (int i = 2; i < n; ++i) { if (a[i] > 0) { v.push_back({a[1], a[i]}); a[1] -= a[i]; } } v.push_back({a[n], a[1]}); a[n] -= a[1]; for (int i = 2; i < n; ++i) { if (a[i] < 0) { v.push_back({a[n], a[i]}); a[n] -= a[i]; } } cout << a[n] << endl; for (auto t : v) { cout << t.x << ' ' << t.y << endl; } return 0; }
#include <bits/stdc++.h> #define x first #define y second using namespace std; typedef long long ll; const int N = 1e5 + 10; int n; ll a[N]; ll sum = 0; vector<pair<ll, ll>> v; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i]; sum += a[i]; } sort(a + 1, a + 1 + n); for (int i = 2; i < n; ++i) { if (a[i] > 0) { v.push_back({a[1], a[i]}); a[1] -= a[i]; } } v.push_back({a[n], a[1]}); a[n] -= a[1]; for (int i = 2; i < n; ++i) { if (a[i] <= 0) { v.push_back({a[n], a[i]}); a[n] -= a[i]; } } cout << a[n] << endl; for (auto t : v) { cout << t.x << ' ' << t.y << endl; } return 0; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
822,003
822,004
u939019760
cpp
p03007
#pragma region Macros #include <bits/stdc++.h> using namespace std; // iteration helper #define FOR(i, l, r) for (int i = (l); i < (r); ++i) #define REP(i, n) FOR(i, 0, n) #define RFOR(i, l, r) for (int i = (r)-1; i >= (l); --i) #define RREP(i, n) RFOR(i, 0, n) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define EXIST(s, e) ((s).find(e) != (s).end()) #define PB push_back // MyVector template <typename T> class MyVector : private std::vector<T, std::allocator<T>> { public: using basetype = std::vector<T, std::allocator<T>>; using basetype::vector; // constractor using basetype::operator=; using basetype::begin; using basetype::capacity; using basetype::cbegin; using basetype::cend; using basetype::crbegin; using basetype::crend; using basetype::empty; using basetype::end; using basetype::max_size; using basetype::rbegin; using basetype::rend; using basetype::reserve; using basetype::resize; using basetype::shrink_to_fit; using basetype::size; // []のかわりに at をつかう typename MyVector<T>::reference operator[](typename basetype::size_type n) { basetype::at(n); } typename MyVector<T>::const_reference operator[](typename basetype::size_type n) const { basetype::at(n); }; using basetype::assign; using basetype::at; using basetype::back; using basetype::clear; using basetype::data; using basetype::emplace; using basetype::emplace_back; using basetype::erase; using basetype::front; using basetype::insert; using basetype::pop_back; using basetype::push_back; using basetype::swap; }; #ifdef _DEBUG #define vector MyVector #else #define vector std::vector #endif // typedefs #define ll long long #define vi vector<int> #define vi2 vector<vi> // input #define ci(x) \ int x; \ cin >> x #define cs(x) \ string x; \ cin >> x #define cd(x) \ double x; \ cin >> x #define cvi(x, n) \ vi x(n); \ REP(i, n) { cin >> x[i]; } // const input #define cci(x) \ const int x = []() { \ int t; \ cin >> t; \ return t; \ }() #define ccs(x) \ const string x = []() { \ string t; \ cin >> t; \ return t; \ }() #define ccd(x) \ const double x = []() { \ double t; \ cin >> t; \ return t; \ }() // output #define pr(x) cout << x << endl #define prvec(v) REP(i, v.size()) pr(v[i]) #define ppr(x) cout << x #define lf() cout << endl // debug methods // usage: debug(x,y); #define CHOOSE(a) CHOOSE2 a #define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x #define debug_1(x1) cout << #x1 << ": " << x1 << endl #define debug_2(x1, x2) \ cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl #define debug_3(x1, x2, x3) \ cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \ << x3 << endl #define debug_4(x1, x2, x3, x4) \ cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \ << x3 << ", " #x4 << ": " << x4 << endl #define debug_5(x1, x2, x3, x4, x5) \ cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \ << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl #ifdef _DEBUG #define debug(...) \ CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) \ (__VA_ARGS__) #else #define debug(...) #endif // const number const double PI = acos(-1.0); const double EPS = 1e-10; #define SP << " " << int powint(int a, int x) { int res = 1; REP(i, x) { res = res * a; } return res; } #pragma endregion #define int long long signed main() { #ifdef _DEBUG try { #endif // main program --------------------------------------------- cci(N); vi A(N); REP(i, N) { cin >> A[i]; } sort(ALL(A)); if (A[0] > 0) { int ans = 0; REP(i, N) { if (i == 0) ans -= A[i]; else ans += A[i]; } pr(ans); int mae = A[0]; for (int i = 1; i < N - 1; ++i) { cout << mae SP A[i] << endl; mae = mae - A[i]; } cout << A[N - 1] SP mae << endl; } else if (A[N - 1] < 0) { int ans = 0; REP(i, N) { if (i == N - 1) ans += A[i]; else ans -= A[i]; } pr(ans); int mae = A[N - 1]; for (int i = N - 2; i >= 0; --i) { cout << mae SP A[i] << endl; mae = mae - A[i]; } } else { int r = lower_bound(ALL(A), 1) - A.begin(); int ans = 0; REP(i, N) { if (i < r) ans -= A[i]; else ans += A[i]; } pr(ans); int mae = A[0]; for (int i = r; i < N - 1; ++i) { cout << mae SP A[i] << endl; mae = mae - A[i]; } cout << A[N - 1] SP mae << endl; mae = A[N - 1] - mae; for (int i = 1; i < r; ++i) { cout << mae SP A[i] << endl; mae = mae - A[i]; } } // end main program ----------------------------------------- #ifdef _DEBUG } catch (std::out_of_range &ex) { pr("out of range"); } #endif return 0; }
#pragma region Macros #include <bits/stdc++.h> using namespace std; // iteration helper #define FOR(i, l, r) for (int i = (l); i < (r); ++i) #define REP(i, n) FOR(i, 0, n) #define RFOR(i, l, r) for (int i = (r)-1; i >= (l); --i) #define RREP(i, n) RFOR(i, 0, n) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define EXIST(s, e) ((s).find(e) != (s).end()) #define PB push_back // MyVector template <typename T> class MyVector : private std::vector<T, std::allocator<T>> { public: using basetype = std::vector<T, std::allocator<T>>; using basetype::vector; // constractor using basetype::operator=; using basetype::begin; using basetype::capacity; using basetype::cbegin; using basetype::cend; using basetype::crbegin; using basetype::crend; using basetype::empty; using basetype::end; using basetype::max_size; using basetype::rbegin; using basetype::rend; using basetype::reserve; using basetype::resize; using basetype::shrink_to_fit; using basetype::size; // []のかわりに at をつかう typename MyVector<T>::reference operator[](typename basetype::size_type n) { basetype::at(n); } typename MyVector<T>::const_reference operator[](typename basetype::size_type n) const { basetype::at(n); }; using basetype::assign; using basetype::at; using basetype::back; using basetype::clear; using basetype::data; using basetype::emplace; using basetype::emplace_back; using basetype::erase; using basetype::front; using basetype::insert; using basetype::pop_back; using basetype::push_back; using basetype::swap; }; #ifdef _DEBUG #define vector MyVector #else #define vector std::vector #endif // typedefs #define ll long long #define vi vector<int> #define vi2 vector<vi> // input #define ci(x) \ int x; \ cin >> x #define cs(x) \ string x; \ cin >> x #define cd(x) \ double x; \ cin >> x #define cvi(x, n) \ vi x(n); \ REP(i, n) { cin >> x[i]; } // const input #define cci(x) \ const int x = []() { \ int t; \ cin >> t; \ return t; \ }() #define ccs(x) \ const string x = []() { \ string t; \ cin >> t; \ return t; \ }() #define ccd(x) \ const double x = []() { \ double t; \ cin >> t; \ return t; \ }() // output #define pr(x) cout << x << endl #define prvec(v) REP(i, v.size()) pr(v[i]) #define ppr(x) cout << x #define lf() cout << endl // debug methods // usage: debug(x,y); #define CHOOSE(a) CHOOSE2 a #define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x #define debug_1(x1) cout << #x1 << ": " << x1 << endl #define debug_2(x1, x2) \ cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl #define debug_3(x1, x2, x3) \ cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \ << x3 << endl #define debug_4(x1, x2, x3, x4) \ cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \ << x3 << ", " #x4 << ": " << x4 << endl #define debug_5(x1, x2, x3, x4, x5) \ cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \ << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl #ifdef _DEBUG #define debug(...) \ CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) \ (__VA_ARGS__) #else #define debug(...) #endif // const number const double PI = acos(-1.0); const double EPS = 1e-10; #define SP << " " << int powint(int a, int x) { int res = 1; REP(i, x) { res = res * a; } return res; } #pragma endregion #define int long long signed main() { #ifdef _DEBUG try { #endif // main program --------------------------------------------- cci(N); vi A(N); REP(i, N) { cin >> A[i]; } sort(ALL(A)); if (A[0] > 0) { int ans = 0; REP(i, N) { if (i == 0) ans -= A[i]; else ans += A[i]; } pr(ans); int mae = A[0]; for (int i = 1; i < N - 1; ++i) { cout << mae SP A[i] << endl; mae = mae - A[i]; } cout << A[N - 1] SP mae << endl; } else if (A[N - 1] <= 0) { int ans = 0; REP(i, N) { if (i == N - 1) ans += A[i]; else ans -= A[i]; } pr(ans); int mae = A[N - 1]; for (int i = N - 2; i >= 0; --i) { cout << mae SP A[i] << endl; mae = mae - A[i]; } } else { int r = lower_bound(ALL(A), 1) - A.begin(); int ans = 0; REP(i, N) { if (i < r) ans -= A[i]; else ans += A[i]; } pr(ans); int mae = A[0]; for (int i = r; i < N - 1; ++i) { cout << mae SP A[i] << endl; mae = mae - A[i]; } cout << A[N - 1] SP mae << endl; mae = A[N - 1] - mae; for (int i = 1; i < r; ++i) { cout << mae SP A[i] << endl; mae = mae - A[i]; } } // end main program ----------------------------------------- #ifdef _DEBUG } catch (std::out_of_range &ex) { pr("out of range"); } #endif return 0; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
822,007
822,008
u820612421
cpp
p03007
#include <algorithm> #include <iostream> #include <math.h> #include <numeric> #include <set> #include <vector> #define M 1000000007 #define int long long using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, i; cin >> n; multiset<int> a; for (i = 0; i < n; i++) { int p; cin >> p; a.insert(p); } int b[n - 1][2]; i = 0; auto it = a.begin(); auto it1 = it; for (;; i++) { if (a.size() == 2) { b[i][1] = *it; it++; b[i][0] = *it; break; } it1++; if (*it1 < 0) { it1 = a.end(); it--; b[i][0] = *it1; b[i][1] = *it; a.erase(it); a.erase(it1); } else { b[i][0] = *it; b[i][1] = *it1; a.erase(it); a.erase(it1); } a.insert(b[i][0] - b[i][1]); it = a.begin(); it1 = it; } cout << b[n - 2][0] - b[n - 2][1] << endl; for (i = 0; i < n - 1; i++) cout << b[i][0] << ' ' << b[i][1] << endl; }
#include <algorithm> #include <iostream> #include <math.h> #include <numeric> #include <set> #include <vector> #define M 1000000007 #define int long long using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, i; cin >> n; multiset<int> a; for (i = 0; i < n; i++) { int p; cin >> p; a.insert(p); } int b[n - 1][2]; i = 0; auto it = a.begin(); auto it1 = it; for (;; i++) { if (a.size() == 2) { b[i][1] = *it; it++; b[i][0] = *it; break; } it1++; if (*it1 < 0) { it1 = a.end(); it1--; b[i][0] = *it1; b[i][1] = *it; a.erase(it); a.erase(it1); } else { b[i][0] = *it; b[i][1] = *it1; a.erase(it); a.erase(it1); } a.insert(b[i][0] - b[i][1]); it = a.begin(); it1 = it; } cout << b[n - 2][0] - b[n - 2][1] << endl; for (i = 0; i < n - 1; i++) cout << b[i][0] << ' ' << b[i][1] << endl; }
[ "identifier.change" ]
822,022
822,023
u131230001
cpp
p03006
#include <bits/stdc++.h> typedef long long LL; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) using namespace std; int n; vector<LL> x, y; int check(LL dx, LL dy) { LL cnt = 0; REP(i, n) REP(j, n) if (x[i] - x[j] == dx && y[i] - y[j] == dy)++ cnt; } int main(void) { cin >> n; x.resize(n); y.resize(n); REP(i, n) cin >> x[i] >> y[i]; int answer = n; REP(i, n) REP(j, i) { answer = min(answer, n - check(x[i] - x[j], y[i] - y[j])); } cout << answer << endl; return 0; }
#include <bits/stdc++.h> typedef long long LL; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) using namespace std; int n; vector<LL> x, y; int check(LL dx, LL dy) { LL cnt = 0; REP(i, n) REP(j, n) if (x[i] - x[j] == dx && y[i] - y[j] == dy)++ cnt; return cnt; } int main(void) { cin >> n; x.resize(n); y.resize(n); REP(i, n) cin >> x[i] >> y[i]; int answer = n; REP(i, n) REP(j, i) { answer = min(answer, n - check(x[i] - x[j], y[i] - y[j])); } cout << answer << endl; return 0; }
[ "control_flow.return.add" ]
822,062
822,063
u633757735
cpp
p03006
#include <cmath> #include <iostream> #include <list> #include <map> #include <string> #include <utility> #include <vector> using namespace std; int main() { int n; vector<long long> x, y; cin >> n; x.resize(n); y.resize(n); for (int i = 0; i < n; i++) { cin >> x[i] >> y[i]; } map<string, int> count; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i == j) continue; string s = to_string(x[i] - x[j]) + "," + to_string(y[i] - y[j]); count[s]++; } } int c = 2; for (pair<string, int> m : count) { if (m.second > c) c = m.second; } if (c >= n) c = n - 1; cout << n - c; return 0; }
#include <cmath> #include <iostream> #include <list> #include <map> #include <string> #include <utility> #include <vector> using namespace std; int main() { int n; vector<long long> x, y; cin >> n; x.resize(n); y.resize(n); for (int i = 0; i < n; i++) { cin >> x[i] >> y[i]; } map<string, int> count; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i == j) continue; string s = to_string(x[i] - x[j]) + "," + to_string(y[i] - y[j]); count[s]++; } } int c = 0; for (pair<string, int> m : count) { if (m.second > c) c = m.second; } if (c >= n) c = n - 1; cout << n - c; return 0; }
[ "literal.number.change", "variable_declaration.value.change" ]
822,082
822,083
u536922989
cpp
p03008
#include <algorithm> #include <cmath> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <math.h> #include <queue> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string> #include <vector> using namespace std; typedef long long ll; int main() { ll N; cin >> N; ll a[3], b[3]; // g,s,b for (int i = 0; i < 3; i++) { cin >> a[i]; } for (int i = 0; i < 3; i++) { cin >> b[i]; } ll dp1[5001]; memset(dp1, 0, sizeof(dp1)); for (ll i = 1; i <= N; i++) { dp1[i] = dp1[i - 1] + 1; for (int j = 0; j < 3; j++) { if (i - a[j] >= 0) { dp1[i] = max(dp1[i], dp1[i - a[j]] + b[j]); } } } N = dp1[N]; ll dp2[N + 1]; memset(dp2, 0, sizeof(dp2)); for (ll i = 1; i <= N; i++) { dp2[i] = dp2[i - 1] + 1; for (int j = 0; j < 3; j++) { if (i - b[j] >= 0) { dp2[i] = max(dp2[i - 1] + 1, dp2[i - b[j]] + a[j]); } } } cout << dp2[N] << endl; return 0; }
#include <algorithm> #include <cmath> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <math.h> #include <queue> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string> #include <vector> using namespace std; typedef long long ll; int main() { ll N; cin >> N; ll a[3], b[3]; // g,s,b for (int i = 0; i < 3; i++) { cin >> a[i]; } for (int i = 0; i < 3; i++) { cin >> b[i]; } ll dp1[5001]; memset(dp1, 0, sizeof(dp1)); for (ll i = 1; i <= N; i++) { dp1[i] = dp1[i - 1] + 1; for (int j = 0; j < 3; j++) { if (i - a[j] >= 0) { dp1[i] = max(dp1[i], dp1[i - a[j]] + b[j]); } } } N = dp1[N]; ll dp2[N + 1]; memset(dp2, 0, sizeof(dp2)); for (ll i = 1; i <= N; i++) { dp2[i] = dp2[i - 1] + 1; for (int j = 0; j < 3; j++) { if (i - b[j] >= 0) { dp2[i] = max(dp2[i], dp2[i - b[j]] + a[j]); } } } cout << dp2[N] << endl; return 0; }
[ "expression.operation.binary.remove" ]
822,128
822,129
u227379863
cpp
p03008
#define y1 askjdkasldjlkasd #include <bits/stdc++.h> #undef y1 using namespace std; #define pb push_back #define mp make_pair #define fi(a, b) for (int i = a; i <= b; i++) #define fj(a, b) for (int j = a; j <= b; j++) #define fo(a, b) for (int o = a; o <= b; o++) #define fdi(a, b) for (int i = a; i >= b; i--) #define fdj(a, b) for (int j = a; j >= b; j--) #define fdo(a, b) for (int o = a; o >= b; o--) #define sz(x) (int)x.size() typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pii> vpii; typedef pair<ll, ll> pll; typedef vector<pll> vpll; typedef vector<ll> vll; #ifdef LOCAL #define err(...) fprintf(stderr, __VA_ARGS__) #else #define err(...) while (0) #endif double START_TIME; void exit() { #ifdef LOCAL cerr << "TIME: " << setprecision(5) << fixed << (clock() - START_TIME) / CLOCKS_PER_SEC << endl; #endif exit(0); } template <typename A, typename B> ostream &operator<<(ostream &os, pair<A, B> p) { os << "(" << p.first << ", " << p.second << ")"; return os; } template <typename T> ostream &operator<<(ostream &os, vector<T> v) { fi(0, sz(v) - 1) { os << v[i] << " "; } return os; } template <typename T> ostream &operator<<(ostream &os, set<T> t) { for (auto z : t) { os << z << " "; } return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, map<T1, T2> t) { cerr << endl; for (auto z : t) { os << "\t" << z.first << " -> " << z.second << endl; } return os; } #ifdef LOCAL #define dbg(x) \ { cerr << __LINE__ << "\t" << #x << ": " << x << endl; } #define dbg0(x, n) \ { \ cerr << __LINE__ << "\t" << #x << ": "; \ for (int ABC = 0; ABC < n; ABC++) \ cerr << x[ABC] << ' '; \ cerr << endl; \ } #else #define dbg(x) \ while (0) { \ } #define dbg0(x, n) \ while (0) { \ } #endif #ifdef LOCAL #define ass(x) \ if (!(x)) { \ cerr << __LINE__ << "\tassertion failed: " << #x << endl, abort(); \ } #else #define ass(x) assert(x) #endif /////////////////////////////////////////////////// int a[41]; int b[41]; int n; ll ans; vi l[2]; const int MAX = 25 * 1000 * 1000 + 41; const ll INF = 1e18 + 41; ll d[MAX]; void solve() { ans = n; fi(0, 2) { if (a[i] < b[i]) { l[0].pb(i); } else if (b[i] < a[i]) { l[1].pb(i); } } fi(0, 2) { if (a[i] > b[i]) swap(a[i], b[i]); } ans = n; fo(0, 1) { if (sz(l[o]) == 0) continue; fill_n(&d[0], MAX, -INF); d[ans] = 0; fdi(ans, 0) { for (int id : l[o]) { if (i >= a[id]) { d[i - a[id]] = max(d[i - a[id]], d[i] + b[id]); } } } fi(0, MAX - 1) ans = max(ans, d[i]); } printf("%lld\n", ans); } int main() { #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); START_TIME = (double)clock(); #endif scanf("%d", &n); fi(0, 2) scanf("%d", &a[i]); fi(0, 2) scanf("%d", &b[i]); solve(); exit(); return 0; }
#define y1 askjdkasldjlkasd #include <bits/stdc++.h> #undef y1 using namespace std; #define pb push_back #define mp make_pair #define fi(a, b) for (int i = a; i <= b; i++) #define fj(a, b) for (int j = a; j <= b; j++) #define fo(a, b) for (int o = a; o <= b; o++) #define fdi(a, b) for (int i = a; i >= b; i--) #define fdj(a, b) for (int j = a; j >= b; j--) #define fdo(a, b) for (int o = a; o >= b; o--) #define sz(x) (int)x.size() typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pii> vpii; typedef pair<ll, ll> pll; typedef vector<pll> vpll; typedef vector<ll> vll; #ifdef LOCAL #define err(...) fprintf(stderr, __VA_ARGS__) #else #define err(...) while (0) #endif double START_TIME; void exit() { #ifdef LOCAL cerr << "TIME: " << setprecision(5) << fixed << (clock() - START_TIME) / CLOCKS_PER_SEC << endl; #endif exit(0); } template <typename A, typename B> ostream &operator<<(ostream &os, pair<A, B> p) { os << "(" << p.first << ", " << p.second << ")"; return os; } template <typename T> ostream &operator<<(ostream &os, vector<T> v) { fi(0, sz(v) - 1) { os << v[i] << " "; } return os; } template <typename T> ostream &operator<<(ostream &os, set<T> t) { for (auto z : t) { os << z << " "; } return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, map<T1, T2> t) { cerr << endl; for (auto z : t) { os << "\t" << z.first << " -> " << z.second << endl; } return os; } #ifdef LOCAL #define dbg(x) \ { cerr << __LINE__ << "\t" << #x << ": " << x << endl; } #define dbg0(x, n) \ { \ cerr << __LINE__ << "\t" << #x << ": "; \ for (int ABC = 0; ABC < n; ABC++) \ cerr << x[ABC] << ' '; \ cerr << endl; \ } #else #define dbg(x) \ while (0) { \ } #define dbg0(x, n) \ while (0) { \ } #endif #ifdef LOCAL #define ass(x) \ if (!(x)) { \ cerr << __LINE__ << "\tassertion failed: " << #x << endl, abort(); \ } #else #define ass(x) assert(x) #endif /////////////////////////////////////////////////// int a[41]; int b[41]; int n; ll ans; vi l[2]; const int MAX = 25 * 1000 * 1000 + 41; const ll INF = 1e18 + 41; ll d[MAX]; void solve() { ans = n; fi(0, 2) { if (a[i] < b[i]) { l[0].pb(i); } else if (b[i] < a[i]) { l[1].pb(i); } } fi(0, 2) { if (a[i] > b[i]) swap(a[i], b[i]); } ans = n; fo(0, 1) { if (sz(l[o]) == 0) continue; fill_n(&d[0], MAX, -INF); d[ans] = 0; fdi(ans, 0) { for (int id : l[o]) { if (i >= a[id]) { d[i - a[id]] = max(d[i - a[id]], d[i] + b[id]); } } } fi(0, MAX - 1) ans = max(ans, d[i] + i); } printf("%lld\n", ans); } int main() { #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); START_TIME = (double)clock(); #endif scanf("%d", &n); fi(0, 2) scanf("%d", &a[i]); fi(0, 2) scanf("%d", &b[i]); solve(); exit(); return 0; }
[ "assignment.change" ]
822,134
822,135
u197964611
cpp
p03008
// #define _GLIBCXX_DEBUG // for STL debug (optional) #include <algorithm> #include <bitset> #include <cassert> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #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 <stack> #include <string> #include <utility> #include <vector> using namespace std; using ll = long long int; using int64 = long long int; template <typename T> void chmax(T &a, T b) { a = max(a, b); } template <typename T> void chmin(T &a, T b) { a = min(a, b); } template <typename T> void chadd(T &a, T b) { a = a + b; } int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; const ll INF = 1001001001001001LL; const ll MOD = 1000000007LL; int64 dp[5010 * 5010]; int main() { int64 N, x[3] = {}, y[3] = {}; cin >> N; cin >> x[0] >> x[1] >> x[2]; cin >> y[0] >> y[1] >> y[2]; { int64 v[4] = {}, p[4] = {}; for (int k = 0; k < 3; k++) { v[k] = x[k]; p[k] = y[k]; } v[3] = p[3] = 1; fill(dp, dp + N + 1, -1); dp[0] = 0; for (int i = 0; i < 3; i++) { for (int k = 0; k <= N; k++) { if (dp[k] < 0 or k + v[i] > N) continue; chmax(dp[k + v[i]], dp[k] + p[i]); } } } int64 M = *max_element(dp, dp + N + 1); // fprintf(stderr, "M = %lld\n", M); { int64 v[4] = {}, p[4] = {}; for (int k = 0; k < 3; k++) { v[k] = y[k]; p[k] = x[k]; } v[3] = p[3] = 1; fill(dp, dp + M + 1, -1); dp[0] = 0; for (int i = 0; i < 3; i++) { for (int k = 0; k <= M; k++) { if (dp[k] < 0 or k + v[i] > M) continue; chmax(dp[k + v[i]], dp[k] + p[i]); } } } int64 ans = *max_element(dp, dp + M + 1); cout << ans << endl; return 0; }
// #define _GLIBCXX_DEBUG // for STL debug (optional) #include <algorithm> #include <bitset> #include <cassert> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #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 <stack> #include <string> #include <utility> #include <vector> using namespace std; using ll = long long int; using int64 = long long int; template <typename T> void chmax(T &a, T b) { a = max(a, b); } template <typename T> void chmin(T &a, T b) { a = min(a, b); } template <typename T> void chadd(T &a, T b) { a = a + b; } int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; const ll INF = 1001001001001001LL; const ll MOD = 1000000007LL; int64 dp[5010 * 5010]; int main() { int64 N, x[3] = {}, y[3] = {}; cin >> N; cin >> x[0] >> x[1] >> x[2]; cin >> y[0] >> y[1] >> y[2]; { int64 v[4] = {}, p[4] = {}; for (int k = 0; k < 3; k++) { v[k] = x[k]; p[k] = y[k]; } v[3] = p[3] = 1; fill(dp, dp + N + 1, -1); dp[0] = 0; for (int i = 0; i < 4; i++) { for (int k = 0; k <= N; k++) { if (dp[k] < 0 or k + v[i] > N) continue; chmax(dp[k + v[i]], dp[k] + p[i]); } } } int64 M = *max_element(dp, dp + N + 1); // fprintf(stderr, "M = %lld\n", M); { int64 v[4] = {}, p[4] = {}; for (int k = 0; k < 3; k++) { v[k] = y[k]; p[k] = x[k]; } v[3] = p[3] = 1; fill(dp, dp + M + 1, -1); dp[0] = 0; for (int i = 0; i < 4; i++) { for (int k = 0; k <= M; k++) { if (dp[k] < 0 or k + v[i] > M) continue; chmax(dp[k + v[i]], dp[k] + p[i]); } } } int64 ans = *max_element(dp, dp + M + 1); cout << ans << endl; return 0; }
[ "literal.number.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
822,136
822,137
u119460590
cpp
p03008
#include <bits/stdc++.h> #define fi first #define se second #define mp make_pair #define mt make_tuple #define pb push_back #define INF (1 << 30) #define INFL (1LL << 60) #define MOD 1000000007 #define EPS ((ld)(1e-9)) #define sz(x) ((int)(x).size()) #define setz(x) memset(x, 0, sizeof(x)) #define all(x) (x).begin(), (x).end() #define rep(i, x) for (int i = 0, _##i = (x); i < _##i; i++) #define repp(i, s, e) for (int i = (s), _##i = (e); i < _##i; i++) #define repr(i, s, e) for (int i = (s)-1, _##i = (e); i >= _##i; i--) #define repi(i, x) for (auto &i : (x)) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pii; typedef pair<ld, ld> pdd; typedef pair<ll, ll> pll; template <typename T, typename V> ostream &operator<<(ostream &os, const pair<T, V> pai) { return os << '(' << pai.first << ' ' << pai.second << ')'; } template <typename T> ostream &operator<<(ostream &os, const vector<T> v) { cout << '['; rep(i, sz(v)) cout << v[i] << ","; cout << "]"; return os; } template <typename T> ostream &operator<<(ostream &os, const set<T> v) { cout << "{"; for (auto p : v) cout << p << ","; cout << "}"; return os; } template <typename T, typename V> ostream &operator<<(ostream &os, const map<T, V> v) { cout << "{"; for (auto p : v) cout << p << ","; cout << "}"; return os; } #ifndef __SOULTCH #define debug(...) 0 #define endl '\n' #else #define debug(...) cout << " [-] ", _dbg(#__VA_ARGS__, __VA_ARGS__) template <class TH> void _dbg(const char *sdbg, TH h) { cout << sdbg << '=' << h << endl; } template <class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) { while (*sdbg != ',') cout << *sdbg++; cout << '=' << (h) << ','; _dbg(sdbg + 1, a...); } #endif template <typename T> void get_max(T &a, T b) { a = max(a, b); } template <typename T> void get_min(T &a, T b) { a = min(a, b); } ll trade(ll in, pll t1, pll t2, pll t3) { vector<pll> cand; if (t1.fi < t1.se) cand.pb(t1); if (t2.fi < t2.se) cand.pb(t2); if (t3.fi < t3.se) cand.pb(t3); debug(cand); debug(in); if (sz(cand) == 0) return in; else if (sz(cand) == 1) { ll trades = in / cand[0].fi; return in + (cand[0].se - cand[0].fi) * trades; } else if (sz(cand) == 2) { ll mv = in; for (ll c1 = 0; c1 * cand[0].fi <= in; c1++) { ll remain = in - cand[0].fi * c1; ll c2 = remain / cand[1].fi; assert(c1 * cand[0].fi + c2 * cand[1].fi <= in); get_max(mv, in + c1 * (cand[0].se - cand[0].fi) + c2 * (cand[1].se - cand[1].fi)); } return mv; } else if (sz(cand) == 3) { ll mv = in; for (ll c1 = 0; c1 * cand[0].fi <= in; c1++) { for (ll c2 = 0; c1 * cand[0].fi + c2 * cand[1].se <= in; c2++) { ll remain = in - cand[0].fi * c1 - cand[1].fi * c2; ll c3 = remain / cand[2].fi; assert(c1 * cand[0].fi + c2 * cand[1].fi + c3 * cand[2].fi <= in); get_max(mv, in + c1 * (cand[0].se - cand[0].fi) + c2 * (cand[1].se - cand[1].fi) + c3 * (cand[2].se - cand[2].fi)); } } return mv; } assert(false); } ll N, Ga, Gb, Sa, Sb, Ba, Bb; int main(void) { iostream::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr); cin >> N >> Ga >> Sa >> Ba >> Gb >> Sb >> Bb; ll t = trade(N, {Ga, Gb}, {Sa, Sb}, {Ba, Bb}); t = trade(t, {Gb, Ga}, {Sb, Sa}, {Bb, Ba}); cout << t << endl; }
#include <bits/stdc++.h> #define fi first #define se second #define mp make_pair #define mt make_tuple #define pb push_back #define INF (1 << 30) #define INFL (1LL << 60) #define MOD 1000000007 #define EPS ((ld)(1e-9)) #define sz(x) ((int)(x).size()) #define setz(x) memset(x, 0, sizeof(x)) #define all(x) (x).begin(), (x).end() #define rep(i, x) for (int i = 0, _##i = (x); i < _##i; i++) #define repp(i, s, e) for (int i = (s), _##i = (e); i < _##i; i++) #define repr(i, s, e) for (int i = (s)-1, _##i = (e); i >= _##i; i--) #define repi(i, x) for (auto &i : (x)) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pii; typedef pair<ld, ld> pdd; typedef pair<ll, ll> pll; template <typename T, typename V> ostream &operator<<(ostream &os, const pair<T, V> pai) { return os << '(' << pai.first << ' ' << pai.second << ')'; } template <typename T> ostream &operator<<(ostream &os, const vector<T> v) { cout << '['; rep(i, sz(v)) cout << v[i] << ","; cout << "]"; return os; } template <typename T> ostream &operator<<(ostream &os, const set<T> v) { cout << "{"; for (auto p : v) cout << p << ","; cout << "}"; return os; } template <typename T, typename V> ostream &operator<<(ostream &os, const map<T, V> v) { cout << "{"; for (auto p : v) cout << p << ","; cout << "}"; return os; } #ifndef __SOULTCH #define debug(...) 0 #define endl '\n' #else #define debug(...) cout << " [-] ", _dbg(#__VA_ARGS__, __VA_ARGS__) template <class TH> void _dbg(const char *sdbg, TH h) { cout << sdbg << '=' << h << endl; } template <class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) { while (*sdbg != ',') cout << *sdbg++; cout << '=' << (h) << ','; _dbg(sdbg + 1, a...); } #endif template <typename T> void get_max(T &a, T b) { a = max(a, b); } template <typename T> void get_min(T &a, T b) { a = min(a, b); } ll trade(ll in, pll t1, pll t2, pll t3) { vector<pll> cand; if (t1.fi < t1.se) cand.pb(t1); if (t2.fi < t2.se) cand.pb(t2); if (t3.fi < t3.se) cand.pb(t3); debug(cand); debug(in); if (sz(cand) == 0) return in; else if (sz(cand) == 1) { ll trades = in / cand[0].fi; return in + (cand[0].se - cand[0].fi) * trades; } else if (sz(cand) == 2) { ll mv = in; for (ll c1 = 0; c1 * cand[0].fi <= in; c1++) { ll remain = in - cand[0].fi * c1; ll c2 = remain / cand[1].fi; assert(c1 * cand[0].fi + c2 * cand[1].fi <= in); get_max(mv, in + c1 * (cand[0].se - cand[0].fi) + c2 * (cand[1].se - cand[1].fi)); } return mv; } else if (sz(cand) == 3) { ll mv = in; for (ll c1 = 0; c1 * cand[0].fi <= in; c1++) { for (ll c2 = 0; c1 * cand[0].fi + c2 * cand[1].fi <= in; c2++) { ll remain = in - cand[0].fi * c1 - cand[1].fi * c2; ll c3 = remain / cand[2].fi; assert(c1 * cand[0].fi + c2 * cand[1].fi + c3 * cand[2].fi <= in); get_max(mv, in + c1 * (cand[0].se - cand[0].fi) + c2 * (cand[1].se - cand[1].fi) + c3 * (cand[2].se - cand[2].fi)); } } return mv; } assert(false); } ll N, Ga, Gb, Sa, Sb, Ba, Bb; int main(void) { iostream::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr); cin >> N >> Ga >> Sa >> Ba >> Gb >> Sb >> Bb; ll t = trade(N, {Ga, Gb}, {Sa, Sb}, {Ba, Bb}); t = trade(t, {Gb, Ga}, {Sb, Sa}, {Bb, Ba}); cout << t << endl; }
[ "control_flow.branch.if.condition.change" ]
822,138
822,139
u236019708
cpp
p03008
#include <bits/stdc++.h> using namespace std; using i64 = int64_t; #define rep(i, x, y) \ for (i64 i = i64(x), i##_max_for_repmacro = i64(y); \ i < i##_max_for_repmacro; ++i) #define debug(x) #x << "=" << (x) #ifdef DEBUG #define _GLIBCXX_DEBUG #define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl #else #define print(x) #endif const int inf = 1.01e9; const i64 inf64 = 4.01e18; const double eps = 1e-9; template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << "["; for (const auto &v : vec) { os << v << ","; } os << "]"; return os; } template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <typename T, size_t size> void fill(T (&ary)[size], const T &val) { fill_n((T *)ary, size, val); } void solve() { // const i64 mod = 1'000'000'007; i64 N, ga, sa, ba, gb, sb, bb; cin >> N; cin >> ga >> sa >> ba; cin >> gb >> sb >> bb; set<i64> st; rep(i, 0, N + 1) { rep(j, 0, N + 1) { i64 r = N - i * ga - j * sa; if (r < 0) break; i64 k = 0; if (-ba + bb > 0) { k = r / ba; r -= k * ba; } i64 x = r + i * max(ga, gb) + j * max(sa, sb) + k * bb; st.insert(x); } } i64 x = *st.rbegin(); i64 ans = 0; vector<i64> dp(x + 1); dp[x] = x; for (i64 i = x; i >= 0; --i) { chmax(ans, x); if (i - gb >= 0) chmax(dp[i - gb], dp[i] - gb + ga); if (i - sb >= 0) chmax(dp[i - sb], dp[i] - sb + sa); if (i - bb >= 0) chmax(dp[i - bb], dp[i] - bb + ba); } cout << ans << endl; } int main() { std::cin.tie(0); std::ios::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(16); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; using i64 = int64_t; #define rep(i, x, y) \ for (i64 i = i64(x), i##_max_for_repmacro = i64(y); \ i < i##_max_for_repmacro; ++i) #define debug(x) #x << "=" << (x) #ifdef DEBUG #define _GLIBCXX_DEBUG #define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl #else #define print(x) #endif const int inf = 1.01e9; const i64 inf64 = 4.01e18; const double eps = 1e-9; template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << "["; for (const auto &v : vec) { os << v << ","; } os << "]"; return os; } template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <typename T, size_t size> void fill(T (&ary)[size], const T &val) { fill_n((T *)ary, size, val); } void solve() { // const i64 mod = 1'000'000'007; i64 N, ga, sa, ba, gb, sb, bb; cin >> N; cin >> ga >> sa >> ba; cin >> gb >> sb >> bb; set<i64> st; rep(i, 0, N + 1) { rep(j, 0, N + 1) { i64 r = N - i * ga - j * sa; if (r < 0) break; i64 k = 0; if (-ba + bb > 0) { k = r / ba; r -= k * ba; } i64 x = r + i * max(ga, gb) + j * max(sa, sb) + k * bb; st.insert(x); } } i64 x = *st.rbegin(); i64 ans = 0; vector<i64> dp(x + 1); dp[x] = x; for (i64 i = x; i >= 0; --i) { chmax(ans, dp[i]); if (i - gb >= 0) chmax(dp[i - gb], dp[i] - gb + ga); if (i - sb >= 0) chmax(dp[i - sb], dp[i] - sb + sa); if (i - bb >= 0) chmax(dp[i - bb], dp[i] - bb + ba); } cout << ans << endl; } int main() { std::cin.tie(0); std::ios::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(16); solve(); return 0; }
[ "call.arguments.change" ]
822,152
822,153
u759266806
cpp
p03008
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> A(3), B(3); cin >> A[0] >> A[1] >> A[2]; cin >> B[0] >> B[1] >> B[2]; vector<long long> dp1(N + 1, 0); for (int i = 0; i < N; i++) { for (int p = 0; p < 3; p++) { if (A[p] >= B[p]) continue; if (i + A[p] <= N) { dp1[i + A[p]] = max(dp1[i + A[p]], dp1[i] - A[p] + B[p]); } } } long long maxget = 0; for (int i = 0; i <= N; i++) maxget = max(maxget, dp1[i]); long long now = N + maxget; vector<long long> dp2(now + 1, 0); for (long long i = 0; i < now; i++) { for (int p = 0; p < 3; p++) { if (B[p] >= A[p]) continue; if (i + B[p] <= N) { dp2[i + B[p]] = max(dp2[i + B[p]], dp2[i] - B[p] + A[p]); } } } maxget = 0; for (long long i = 0; i <= now; i++) maxget = max(maxget, dp2[i]); cout << now + maxget << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> A(3), B(3); cin >> A[0] >> A[1] >> A[2]; cin >> B[0] >> B[1] >> B[2]; vector<long long> dp1(N + 1, 0); for (int i = 0; i < N; i++) { for (int p = 0; p < 3; p++) { if (A[p] >= B[p]) continue; if (i + A[p] <= N) { dp1[i + A[p]] = max(dp1[i + A[p]], dp1[i] - A[p] + B[p]); } } } long long maxget = 0; for (int i = 0; i <= N; i++) maxget = max(maxget, dp1[i]); long long now = N + maxget; vector<long long> dp2(now + 1, 0); for (int i = 0; i < now; i++) { for (int p = 0; p < 3; p++) { if (B[p] >= A[p]) continue; if (i + B[p] <= now) { dp2[i + B[p]] = max(dp2[i + B[p]], dp2[i] - B[p] + A[p]); } } } maxget = 0; for (int i = 0; i <= now; i++) maxget = max(maxget, dp2[i]); cout << now + maxget << endl; }
[ "control_flow.loop.for.initializer.change", "variable_declaration.type.primitive.change", "variable_declaration.type.narrow.change", "identifier.change", "control_flow.branch.if.condition.change" ]
822,156
822,157
u544437817
cpp
p03008
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> A(3), B(3); cin >> A[0] >> A[1] >> A[2]; cin >> B[0] >> B[1] >> B[2]; vector<long long> dp1(N + 1, 0); for (int i = 0; i < N; i++) { for (int p = 0; p < 3; p++) { if (A[p] >= B[p]) continue; if (i + A[p] <= N) { dp1[i + A[p]] = max(dp1[i + A[p]], dp1[i] - A[p] + B[p]); } } } long long maxget = 0; for (int i = 0; i <= N; i++) maxget = max(maxget, dp1[i]); long long now = N + maxget; vector<long long> dp2(now + 1, 0); for (int i = 0; i < now; i++) { for (int p = 0; p < 3; p++) { if (B[p] >= A[p]) continue; if (i + B[p] <= N) { dp2[i + B[p]] = max(dp2[i + B[p]], dp2[i] - B[p] + A[p]); } } } maxget = 0; for (long long i = 0; i <= now; i++) maxget = max(maxget, dp2[i]); cout << now + maxget << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> A(3), B(3); cin >> A[0] >> A[1] >> A[2]; cin >> B[0] >> B[1] >> B[2]; vector<long long> dp1(N + 1, 0); for (int i = 0; i < N; i++) { for (int p = 0; p < 3; p++) { if (A[p] >= B[p]) continue; if (i + A[p] <= N) { dp1[i + A[p]] = max(dp1[i + A[p]], dp1[i] - A[p] + B[p]); } } } long long maxget = 0; for (int i = 0; i <= N; i++) maxget = max(maxget, dp1[i]); long long now = N + maxget; vector<long long> dp2(now + 1, 0); for (int i = 0; i < now; i++) { for (int p = 0; p < 3; p++) { if (B[p] >= A[p]) continue; if (i + B[p] <= now) { dp2[i + B[p]] = max(dp2[i + B[p]], dp2[i] - B[p] + A[p]); } } } maxget = 0; for (int i = 0; i <= now; i++) maxget = max(maxget, dp2[i]); cout << now + maxget << endl; }
[ "identifier.change", "control_flow.branch.if.condition.change", "control_flow.loop.for.initializer.change", "variable_declaration.type.primitive.change", "variable_declaration.type.narrow.change" ]
822,158
822,157
u544437817
cpp
p03008
#include "bits/stdc++.h" using ll = long long; using namespace std; #define int ll // 0 -> a-1 #define rep(i, a) for (int i = 0; (i) < (int)(a); (i)++) // a -> b-1 #define reps(i, a, b) for (int i = (int)(a); (i) < (int)(b); (i)++) // a-1 -> 0 #define rrep(i, a) for (int i = (int)a - 1; (i) >= 0; (i)--) // a-1 -> b #define rreps(i, a, b) for (int i = (int)(a)-1; (i) >= (int)(b); (i)--) #define MP(a, b) make_pair((a), (b)) #define PB(a) push_back((a)) #define all(v) (v).begin(), (v).end() // next_permutation(all(v)) #define PERM(v) next_permutation(all(v)) /*sort(all(v)); (v).erase(unique(all(v)), v.end())*/ #define UNIQUE(v) \ sort(all(v)); \ (v).erase(unique(all(v)), v.end()) #define CIN(type, x) \ type x; \ cin >> x #define YES(f) \ if ((f)) { \ cout << "YES" << endl; \ } else { \ cout << "NO" << endl; \ } #define Yes(f) \ if ((f)) { \ cout << "Yes" << endl; \ } else { \ cout << "No" << endl; \ } #define MINV(v) min_element(all(v)) #define MAXV(v) max_element(all(v)) #define MIN3(a, b, c) min(min(a, b), c) #define MIN4(a, b, c, d) min(MIN3(a, b, c), d) #define MIN5(a, b, c, d, e) min(MIN4(a, b, c, d), e) #define MIN6(a, b, c, d, e, f) min(MIN5(a, b, c, d, e), f) #define MAX3(a, b, c) max(max(a, b), c) #define MAX4(a, b, c, d) max(MAX3(a, b, c), d) #define MAX5(a, b, c, d, e) max(MAX4(a, b, c, d), e) #define MAX6(a, b, c, d, e, f) max(MAX5(a, b, c, d, e), f) // b is [a, c) #define RANGE(a, b, c) ((a) <= (b) && (b) < (c)) // c is [a, e) && d is [b, f) #define RANGE2D(a, b, c, d, e, f) (RANGE((a), (c), (e)) && RANGE((b), (d), (f))) #define chmin(a, b) a = min(a, (b)) #define chmin3(a, b, c) a = MIN3(a, (b), (c)) #define chmin4(a, b, c, d) a = MIN4(a, (b), (c), (d)) #define chmin5(a, b, c, d, e) a = MIN5(a, (b), (c), (d), (e)) #define chmin6(a, b, c, d, e, f) a = MIN6(a, (b), (c), (d), (e), (f)) #define chmax(a, b) a = max(a, (b)) #define chmax3(a, b, c) a = MAX3(a, (b), (c)) #define chmax4(a, b, c, d) a = MAX4(a, (b), (c), (d)) #define chmax5(a, b, c, d, e) a = MAX5(a, (b), (c), (d), (e)) #define chmax6(a, b, c, d, e, f) a = MAX6(a, (b), (c), (d), (e), (f)) #define fcout cout << fixed << setprecision(12) #define RS resize #define CINV(v, N) \ do { \ v.RS(N); \ rep(i, N) cin >> v[i]; \ } while (0); #define RCINV(v, N) \ do { \ v.RS(N); \ rrep(i, N) cin >> v[i]; \ } while (0); #define MOD 1000000007 template <class T> inline T GET() { T x; cin >> x; return x; } void init(); void solve(); signed main() { init(); solve(); } template <class T, char d = '\n'> struct Vector { vector<T> v; Vector(int sz) : v(sz) {} Vector(int sz, T t) : v(sz, t) {} Vector() : v(0) {} Vector(vector<T> t) : v(t) {} inline auto begin() { return v.begin(); } inline auto end() { return v.end(); } inline auto rbegin() { return v.rbegin(); } inline auto rend() { return v.rend(); } inline int size() { return v.size(); } inline auto resize(int sz) { v.resize(sz); } inline auto resize(int sz, T t) { v.resize(sz, t); } inline auto empty() { v.empty(); } inline auto reserve(int sz) { v.reserve(sz); } inline auto push_back(T t) { v.push_back(t); } inline auto pop_back() { v.pop_back(); } inline auto assign(int sz, const T &t) { v.assign(sz, t); } inline auto &front() { return v.front(); } inline auto &back() { return v.back(); } inline auto insert(const typename vector<T>::iterator p, const T &t) { v.insert(p, t); } inline auto insert(const typename vector<T>::iterator p, typename vector<T>::iterator f, typename vector<T>::iterator l) { v.insert(p, f, l); } inline auto erase(const typename vector<T>::iterator p) { v.erase(p); } inline auto erase(const typename vector<T>::iterator f, const typename vector<T>::iterator s) { v.erase(f, s); } inline auto emplace_back(T &t) { v.emplace_back(t); } inline auto swap(Vector<T> &f) { v.swap(f.v); } inline auto clear() { v.clear(); } inline auto &operator[](size_t pos) { return v[pos]; } inline auto operator<(const Vector &a) { return v < a.v; } inline auto operator>(const Vector &a) { return a < (*this); } inline auto operator>=(const Vector &a) { return !((*this) < a); } inline auto operator<=(const Vector &a) { return !(a < (*this)); } inline auto operator==(const Vector &a) { return !(a < (*this)) && !((*this) < a); } inline friend istream &operator>>(istream &lhs, Vector &rhs) { for (auto &x : rhs) lhs >> x; return lhs; } inline friend ostream &operator<<(ostream &lhs, Vector &rhs) { for (int i = 0; i + 1 < rhs.size(); i++) lhs << rhs[i] << d; if (rhs.size()) lhs << rhs.back(); return lhs; } inline auto make_accumulate_sum(T init) { Vector<T> res; res.push_back(init); for (auto x : v) { auto y = res.back(); res.push_back(y + x); } return res; } }; int calc2(int N, int v, int a1, int b1, int a2, int b2) { int v2 = N - v; int aa = v / a1; v -= aa * a1; int bb = v2 / b1; v2 -= bb * b1; return v + aa * a2 + v2 + bb * b2; } int calc(int N, vector<int> a, vector<int> b) { { int i = 0; while (i < (int)a.size()) { if (a[i] >= b[i]) { a.erase(next(a.begin(), i)); b.erase(next(b.begin(), i)); } else { i++; } } } if (a.size() >= 2) { int l = a.size(); vector<vector<int>> dp(l + 1, vector<int>(N + 1, 0)); rep(i, N + 1) { dp[0][i] = i; } reps(i, 1, l) { rep(j, N + 1) { dp[i][j] = dp[i - 1][j]; if (j >= a[i - 1]) { chmax(dp[i][j], dp[i][j - a[i - 1]] + b[i - 1]); } } } return dp[l][N]; } if (a.size() == 1) { return calc2(N, N, a[0], 1, b[0], 1); } return N; } void init() { int N; cin >> N; vector<int> a(3), b(3); rep(i, 3) cin >> a[i]; rep(i, 3) cin >> b[i]; N = calc(N, a, b); cout << calc(N, b, a) << endl; } void solve() {}
#include "bits/stdc++.h" using ll = long long; using namespace std; #define int ll // 0 -> a-1 #define rep(i, a) for (int i = 0; (i) < (int)(a); (i)++) // a -> b-1 #define reps(i, a, b) for (int i = (int)(a); (i) < (int)(b); (i)++) // a-1 -> 0 #define rrep(i, a) for (int i = (int)a - 1; (i) >= 0; (i)--) // a-1 -> b #define rreps(i, a, b) for (int i = (int)(a)-1; (i) >= (int)(b); (i)--) #define MP(a, b) make_pair((a), (b)) #define PB(a) push_back((a)) #define all(v) (v).begin(), (v).end() // next_permutation(all(v)) #define PERM(v) next_permutation(all(v)) /*sort(all(v)); (v).erase(unique(all(v)), v.end())*/ #define UNIQUE(v) \ sort(all(v)); \ (v).erase(unique(all(v)), v.end()) #define CIN(type, x) \ type x; \ cin >> x #define YES(f) \ if ((f)) { \ cout << "YES" << endl; \ } else { \ cout << "NO" << endl; \ } #define Yes(f) \ if ((f)) { \ cout << "Yes" << endl; \ } else { \ cout << "No" << endl; \ } #define MINV(v) min_element(all(v)) #define MAXV(v) max_element(all(v)) #define MIN3(a, b, c) min(min(a, b), c) #define MIN4(a, b, c, d) min(MIN3(a, b, c), d) #define MIN5(a, b, c, d, e) min(MIN4(a, b, c, d), e) #define MIN6(a, b, c, d, e, f) min(MIN5(a, b, c, d, e), f) #define MAX3(a, b, c) max(max(a, b), c) #define MAX4(a, b, c, d) max(MAX3(a, b, c), d) #define MAX5(a, b, c, d, e) max(MAX4(a, b, c, d), e) #define MAX6(a, b, c, d, e, f) max(MAX5(a, b, c, d, e), f) // b is [a, c) #define RANGE(a, b, c) ((a) <= (b) && (b) < (c)) // c is [a, e) && d is [b, f) #define RANGE2D(a, b, c, d, e, f) (RANGE((a), (c), (e)) && RANGE((b), (d), (f))) #define chmin(a, b) a = min(a, (b)) #define chmin3(a, b, c) a = MIN3(a, (b), (c)) #define chmin4(a, b, c, d) a = MIN4(a, (b), (c), (d)) #define chmin5(a, b, c, d, e) a = MIN5(a, (b), (c), (d), (e)) #define chmin6(a, b, c, d, e, f) a = MIN6(a, (b), (c), (d), (e), (f)) #define chmax(a, b) a = max(a, (b)) #define chmax3(a, b, c) a = MAX3(a, (b), (c)) #define chmax4(a, b, c, d) a = MAX4(a, (b), (c), (d)) #define chmax5(a, b, c, d, e) a = MAX5(a, (b), (c), (d), (e)) #define chmax6(a, b, c, d, e, f) a = MAX6(a, (b), (c), (d), (e), (f)) #define fcout cout << fixed << setprecision(12) #define RS resize #define CINV(v, N) \ do { \ v.RS(N); \ rep(i, N) cin >> v[i]; \ } while (0); #define RCINV(v, N) \ do { \ v.RS(N); \ rrep(i, N) cin >> v[i]; \ } while (0); #define MOD 1000000007 template <class T> inline T GET() { T x; cin >> x; return x; } void init(); void solve(); signed main() { init(); solve(); } template <class T, char d = '\n'> struct Vector { vector<T> v; Vector(int sz) : v(sz) {} Vector(int sz, T t) : v(sz, t) {} Vector() : v(0) {} Vector(vector<T> t) : v(t) {} inline auto begin() { return v.begin(); } inline auto end() { return v.end(); } inline auto rbegin() { return v.rbegin(); } inline auto rend() { return v.rend(); } inline int size() { return v.size(); } inline auto resize(int sz) { v.resize(sz); } inline auto resize(int sz, T t) { v.resize(sz, t); } inline auto empty() { v.empty(); } inline auto reserve(int sz) { v.reserve(sz); } inline auto push_back(T t) { v.push_back(t); } inline auto pop_back() { v.pop_back(); } inline auto assign(int sz, const T &t) { v.assign(sz, t); } inline auto &front() { return v.front(); } inline auto &back() { return v.back(); } inline auto insert(const typename vector<T>::iterator p, const T &t) { v.insert(p, t); } inline auto insert(const typename vector<T>::iterator p, typename vector<T>::iterator f, typename vector<T>::iterator l) { v.insert(p, f, l); } inline auto erase(const typename vector<T>::iterator p) { v.erase(p); } inline auto erase(const typename vector<T>::iterator f, const typename vector<T>::iterator s) { v.erase(f, s); } inline auto emplace_back(T &t) { v.emplace_back(t); } inline auto swap(Vector<T> &f) { v.swap(f.v); } inline auto clear() { v.clear(); } inline auto &operator[](size_t pos) { return v[pos]; } inline auto operator<(const Vector &a) { return v < a.v; } inline auto operator>(const Vector &a) { return a < (*this); } inline auto operator>=(const Vector &a) { return !((*this) < a); } inline auto operator<=(const Vector &a) { return !(a < (*this)); } inline auto operator==(const Vector &a) { return !(a < (*this)) && !((*this) < a); } inline friend istream &operator>>(istream &lhs, Vector &rhs) { for (auto &x : rhs) lhs >> x; return lhs; } inline friend ostream &operator<<(ostream &lhs, Vector &rhs) { for (int i = 0; i + 1 < rhs.size(); i++) lhs << rhs[i] << d; if (rhs.size()) lhs << rhs.back(); return lhs; } inline auto make_accumulate_sum(T init) { Vector<T> res; res.push_back(init); for (auto x : v) { auto y = res.back(); res.push_back(y + x); } return res; } }; int calc2(int N, int v, int a1, int b1, int a2, int b2) { int v2 = N - v; int aa = v / a1; v -= aa * a1; int bb = v2 / b1; v2 -= bb * b1; return v + aa * a2 + v2 + bb * b2; } int calc(int N, vector<int> a, vector<int> b) { { int i = 0; while (i < (int)a.size()) { if (a[i] >= b[i]) { a.erase(next(a.begin(), i)); b.erase(next(b.begin(), i)); } else { i++; } } } if (a.size() >= 2) { int l = a.size(); vector<vector<int>> dp(l + 1, vector<int>(N + 1, 0)); rep(i, N + 1) { dp[0][i] = i; } reps(i, 1, l + 1) { rep(j, N + 1) { dp[i][j] = dp[i - 1][j]; if (j >= a[i - 1]) { chmax(dp[i][j], dp[i][j - a[i - 1]] + b[i - 1]); } } } return dp[l][N]; } if (a.size() == 1) { return calc2(N, N, a[0], 1, b[0], 1); } return N; } void init() { int N; cin >> N; vector<int> a(3), b(3); rep(i, 3) cin >> a[i]; rep(i, 3) cin >> b[i]; N = calc(N, a, b); cout << calc(N, b, a) << endl; } void solve() {}
[ "expression.operation.binary.add" ]
822,159
822,160
u946322619
cpp
p03008
/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author alireza_kaviani */ #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; typedef long long ll; typedef long double ld; typedef pair<ll, ll> pll; typedef pair<double, double> pdd; typedef pair<ld, ld> pld; typedef pair<string, string> pss; #define all(x) (x).begin(), (x).end() #define Sort(x) sort(all((x))) #define X first #define Y second #define Mp make_pair #define sep ' ' #define endl '\n' #define debug(x) cerr << #x << " = " << x << endl #define SZ(x) ll(x.size()) #define fast_io \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define file_io \ freopen("in.txt", "r+", stdin); \ freopen("out.txt", "w+", stdout); #define set_random \ mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); inline ll input() { ll n; cin >> n; return n; } ll poww(ll a, ll b, ll md) { return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md)); } set_random; const ll MAXN = 2.5e7 + 10; const ll INF = 1e15; const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9; ll n, ans, ga[4], gb[4], dp[MAXN], dp2[MAXN]; int main() { fast_io; for (ll j = 0; j < MAXN; j++) { dp[j] = -INF; dp2[j] = -INF; } cin >> n >> ga[1] >> ga[2] >> ga[3] >> gb[1] >> gb[2] >> gb[3]; dp[n] = 0; for (ll i = 1; i < 4; i++) { for (ll j = MAXN - 1; j >= ga[i]; j--) { dp[j - ga[i]] = max(dp[j - ga[i]], dp[j] + gb[i]); } } n = 0; for (ll i = 0; i < MAXN; i++) n = max(n, i + dp[i]); dp2[n] = 0; for (ll i = 1; i < 4; i++) { for (ll j = MAXN - 1; j >= ga[i]; j--) { dp2[j - gb[i]] = max(dp2[j - gb[i]], dp2[j] + ga[i]); } } n = 0; for (ll i = 0; i < MAXN; i++) n = max(n, i + dp2[i]); cout << n << endl; return 0; } /* todo : 1- set constants 2- check TimeLimit and MemoryLimit 3- check special test cases 4- don't forget BS can help you that is good idea(use for loop for floats) 5- don't forget printf and scanf can help you in your code speed */
/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author alireza_kaviani */ #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; typedef long long ll; typedef long double ld; typedef pair<ll, ll> pll; typedef pair<double, double> pdd; typedef pair<ld, ld> pld; typedef pair<string, string> pss; #define all(x) (x).begin(), (x).end() #define Sort(x) sort(all((x))) #define X first #define Y second #define Mp make_pair #define sep ' ' #define endl '\n' #define debug(x) cerr << #x << " = " << x << endl #define SZ(x) ll(x.size()) #define fast_io \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define file_io \ freopen("in.txt", "r+", stdin); \ freopen("out.txt", "w+", stdout); #define set_random \ mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); inline ll input() { ll n; cin >> n; return n; } ll poww(ll a, ll b, ll md) { return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md)); } set_random; const ll MAXN = 2.5e7 + 10; const ll INF = 1e15; const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9; ll n, ans, ga[4], gb[4], dp[MAXN], dp2[MAXN]; int main() { fast_io; for (ll j = 0; j < MAXN; j++) { dp[j] = -INF; dp2[j] = -INF; } cin >> n >> ga[1] >> ga[2] >> ga[3] >> gb[1] >> gb[2] >> gb[3]; dp[n] = 0; for (ll i = 1; i < 4; i++) { for (ll j = MAXN - 1; j >= ga[i]; j--) { dp[j - ga[i]] = max(dp[j - ga[i]], dp[j] + gb[i]); } } n = 0; for (ll i = 0; i < MAXN; i++) n = max(n, i + dp[i]); dp2[n] = 0; for (ll i = 1; i < 4; i++) { for (ll j = MAXN - 1; j >= gb[i]; j--) { dp2[j - gb[i]] = max(dp2[j - gb[i]], dp2[j] + ga[i]); } } n = 0; for (ll i = 0; i < MAXN; i++) n = max(n, i + dp2[i]); cout << n << endl; return 0; } /* todo : 1- set constants 2- check TimeLimit and MemoryLimit 3- check special test cases 4- don't forget BS can help you that is good idea(use for loop for floats) 5- don't forget printf and scanf can help you in your code speed */
[ "identifier.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
822,170
822,171
u631674931
cpp
p03008
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll subproblem(int N, int gB, int sB, int bB, int gA, int sA, int bA) { vector<ll> dp(N + 1, 0); for (int i = 0; i <= N; i++) { dp[i] = i; } int gD = gB - gA; int sD = sB - sA; int bD = bB - bA; // cout << gD << " " << sD << " " << bD << endl; for (int i = 1; i <= N; i++) { if (N >= gA && gD >= 0) { dp[i] = max(dp[i], dp[i - gA] + gB); } if (N >= sA && sD >= 0) { dp[i] = max(dp[i], dp[i - sA] + sB); } if (N >= bA && bD >= 0) { dp[i] = max(dp[i], dp[i - bA] + bB); } } return dp[N]; } int main() { int N; cin >> N; int gA, sA, bA; cin >> gA >> sA >> bA; int gB, sB, bB; cin >> gB >> sB >> bB; ll halfN = subproblem(N, gB, sB, bB, gA, sA, bA); // cout << halfN << endl; ll ans = subproblem((int)halfN, gA, sA, bA, gB, sB, bB); cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll subproblem(int N, int gB, int sB, int bB, int gA, int sA, int bA) { vector<ll> dp(N + 1, 0); for (int i = 0; i <= N; i++) { dp[i] = i; } int gD = gB - gA; int sD = sB - sA; int bD = bB - bA; // cout << gD << " " << sD << " " << bD << endl; for (int i = 1; i <= N; i++) { if (i >= gA && gD >= 0) { dp[i] = max(dp[i], dp[i - gA] + gB); } if (i >= sA && sD >= 0) { dp[i] = max(dp[i], dp[i - sA] + sB); } if (i >= bA && bD >= 0) { dp[i] = max(dp[i], dp[i - bA] + bB); } } return dp[N]; } int main() { int N; cin >> N; int gA, sA, bA; cin >> gA >> sA >> bA; int gB, sB, bB; cin >> gB >> sB >> bB; ll halfN = subproblem(N, gB, sB, bB, gA, sA, bA); // cout << halfN << endl; ll ans = subproblem((int)halfN, gA, sA, bA, gB, sB, bB); cout << ans << endl; }
[ "identifier.change", "control_flow.branch.if.condition.change" ]
822,184
822,185
u695197008
cpp
p03008
#include <algorithm> #include <iostream> #include <map> #include <queue> #include <stack> #include <string> #include <utility> #include <vector> typedef long long ll; using namespace std; int main() { ll i, j, k, n, m, x; cin >> x; ll t[2][3]; for (i = 0; i < 2; i++) cin >> t[i][0] >> t[i][1] >> t[i][2]; ll dp[x + 1] = {}; ll mt = max(t[1][0], max(t[1][1], t[1][2])); for (i = 0; i < 3; i++) { for (j = t[0][i]; j < x + 1; j++) { if (t[1][0] > t[0][i]) dp[j] = max(dp[j], dp[j - t[0][i]] + t[1][i] - t[0][i]); } } // cout << "a" << endl; ll ret = 0; for (i = 0; i < x + 1; i++) ret = max(dp[i], ret); x += ret; mt = max(t[0][0], max(t[0][1], t[0][2])); ll dp2[x + 1] = {}; for (i = 0; i < 3; i++) { for (j = t[1][i]; j < x + 1; j++) { if (t[0][1] > t[1][i]) dp2[j] = max(dp2[j], dp2[j - t[1][i]] + t[0][i] - t[1][i]); } } ret = 0; for (i = 0; i < x + 1; i++) ret = max(dp2[i], ret); x += ret; cout << x << endl; return 0; }
#include <algorithm> #include <iostream> #include <map> #include <queue> #include <stack> #include <string> #include <utility> #include <vector> typedef long long ll; using namespace std; int main() { ll i, j, k, n, m, x; cin >> x; ll t[2][3]; for (i = 0; i < 2; i++) cin >> t[i][0] >> t[i][1] >> t[i][2]; ll dp[x + 1] = {}; ll mt = max(t[1][0], max(t[1][1], t[1][2])); for (i = 0; i < 3; i++) { for (j = t[0][i]; j < x + 1; j++) { if (t[1][i] > t[0][i]) dp[j] = max(dp[j], dp[j - t[0][i]] + t[1][i] - t[0][i]); } } // cout << "a" << endl; ll ret = 0; for (i = 0; i < x + 1; i++) ret = max(dp[i], ret); x += ret; mt = max(t[0][0], max(t[0][1], t[0][2])); ll dp2[x + 1] = {}; for (i = 0; i < 3; i++) { for (j = t[1][i]; j < x + 1; j++) { if (t[0][i] > t[1][i]) dp2[j] = max(dp2[j], dp2[j - t[1][i]] + t[0][i] - t[1][i]); } } ret = 0; for (i = 0; i < x + 1; i++) ret = max(dp2[i], ret); x += ret; cout << x << endl; return 0; }
[ "identifier.replace.add", "literal.replace.remove", "variable_access.subscript.index.change", "control_flow.branch.if.condition.change" ]
822,191
822,192
u595893956
cpp
p03008
#include "bits/stdc++.h" using namespace std; using ll = long long int; using pii = pair<int, int>; using pil = pair<int, ll>; using pll = pair<ll, ll>; int main() { int N; int ga, sa, ba; int gb, sb, bb; cin >> N; cin >> ga >> sa >> ba; cin >> gb >> sb >> bb; vector<int> dpab(N + 1); dpab[0] = 0; for (int n = 1; n <= N; n++) { dpab[n] = dpab[n - 1]; if (n >= ga) dpab[n] = max(dpab[n], gb + dpab[n - ga]); if (n >= sa) dpab[n] = max(dpab[n], sb + dpab[n - sa]); if (n >= ba) dpab[n] = max(dpab[n], bb + dpab[n - ba]); } int nN = dpab[N]; vector<ll> dpba(nN + 1); dpba[0] = 0; for (int n = 1; n <= nN; n++) { dpba[n] = dpba[n - 1]; if (n >= gb) dpba[n] = max(dpba[n], ga + dpba[n - gb]); if (n >= sb) dpba[n] = max(dpba[n], sa + dpba[n - sb]); if (n >= bb) dpba[n] = max(dpba[n], ba + dpba[n - bb]); } cout << dpba[nN] << endl; return 0; }
#include "bits/stdc++.h" using namespace std; using ll = long long int; using pii = pair<int, int>; using pil = pair<int, ll>; using pll = pair<ll, ll>; int main() { int N; int ga, sa, ba; int gb, sb, bb; cin >> N; cin >> ga >> sa >> ba; cin >> gb >> sb >> bb; vector<int> dpab(N + 1); dpab[0] = 0; for (int n = 1; n <= N; n++) { dpab[n] = 1 + dpab[n - 1]; if (n >= ga) dpab[n] = max(dpab[n], gb + dpab[n - ga]); if (n >= sa) dpab[n] = max(dpab[n], sb + dpab[n - sa]); if (n >= ba) dpab[n] = max(dpab[n], bb + dpab[n - ba]); } int nN = dpab[N]; vector<ll> dpba(nN + 1); dpba[0] = 0; for (int n = 1; n <= nN; n++) { dpba[n] = 1 + dpba[n - 1]; if (n >= gb) dpba[n] = max(dpba[n], ga + dpba[n - gb]); if (n >= sb) dpba[n] = max(dpba[n], sa + dpba[n - sb]); if (n >= bb) dpba[n] = max(dpba[n], ba + dpba[n - bb]); } cout << dpba[nN] << endl; return 0; }
[ "assignment.change" ]
822,204
822,205
u378945900
cpp
p03008
#include <bits/stdc++.h> #define fi first #define se second #define all(x) x.begin() #define pb push_back using namespace std; signed main() { #define int long long int n; cin >> n; vector<int> a(3), b(3); for (auto &i : a) cin >> i; for (auto &i : b) cin >> i; vector<int> dp(n + 1, 0); for (int j = 0; j <= n; ++j) { for (int z = 0; z < 3; ++z) if (j >= a[z]) { dp[j] = max(dp[j], dp[j - a[z]] + b[z]); } } int x = n; for (int i = 0; i <= n; ++i) { x = max(x, dp[i] + n - i); } vector<int> f(x + 1, 0); for (int j = 0; j <= n; ++j) { for (int z = 0; z < 3; ++z) if (j >= b[z]) { f[j] = max(f[j], f[j - b[z]] + a[z]); } } int ans = 0; for (int z = 0; z <= x; ++z) { ans = max(ans, f[z] + x - z); } cout << ans; return 0; }
#include <bits/stdc++.h> #define fi first #define se second #define all(x) x.begin() #define pb push_back using namespace std; signed main() { #define int long long int n; cin >> n; vector<int> a(3), b(3); for (auto &i : a) cin >> i; for (auto &i : b) cin >> i; vector<int> dp(n + 1, 0); for (int j = 0; j <= n; ++j) { for (int z = 0; z < 3; ++z) if (j >= a[z]) { dp[j] = max(dp[j], dp[j - a[z]] + b[z]); } } int x = n; for (int i = 0; i <= n; ++i) { x = max(x, dp[i] + n - i); } vector<int> f(x + 1, 0); for (int j = 0; j <= x; ++j) { for (int z = 0; z < 3; ++z) if (j >= b[z]) { f[j] = max(f[j], f[j - b[z]] + a[z]); } } int ans = 0; for (int z = 0; z <= x; ++z) { ans = max(ans, f[z] + x - z); } cout << ans; return 0; }
[ "identifier.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
822,221
822,220
u759779286
cpp