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 |
|---|---|---|---|---|---|---|---|
p03150 | // include
// ------------------------------------------------
#include <algorithm>
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
using namespace std;
// func
// ------------------------------------------------
int CalcSumOfDigit(int n); // 各桁の和を計算する。
long long getDigit(long long n); // 数字の桁数を取得する。
string upper(string str); // 英字を大文字に変換する。
string lower(string str); // 英字を小文字に変換する。
// define
// ------------------------------------------------
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define sz(a) int((a).size())
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define repe(i, n) for (int(i) = 0; (i) <= (n); (i)++)
#define vsort(v) sort((v).begin(), (v).end())
#define rvsort(v) sort(rall((v)))
#define vi vector<int>
#define GCD(a, b) __gcd((a), (b))
#define LCM(a, b) ((a) / GCD((a), (b)) * (b))
#define kiriage(a, b) ((a) + (b)-1) / (b)
const int INF = 1e9;
typedef long long ll;
typedef unsigned long long ull;
// code
// ------------------------------------------------
int main() {
string s, k("keyence");
cin >> s;
bool ans;
if (s == k) {
ans = true;
} else {
for (ll i = 0; i < sz(s); ++i) {
for (ll j = i; j < sz(s); ++j) {
string buf = s.substr(0, i) + s.substr(j + 1);
if (buf == k) {
ans = true;
break;
}
}
if (ans)
break;
}
}
if (ans)
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
// funcの実体
// ------------------------------------------------
ll getDigit(ll n) {
int i = 1;
while (1) {
n = n / 10;
if (n == 0)
break;
i++;
}
return i;
}
ll CalcSumOfDigit(ll n) {
ll s = 0;
while (n) {
s += n % 10;
n = n / 10;
}
return s;
}
string upper(string str) {
for (auto itr = str.begin(); itr != str.end(); itr++) {
if (97 <= *itr && *itr <= 122) {
*itr = *itr - 32;
}
}
return str;
}
string lower(string str) {
for (auto itr = str.begin(); itr != str.end(); itr++) {
if (65 <= *itr && *itr <= 90) {
*itr = *itr + 32;
}
}
return str;
}
| // include
// ------------------------------------------------
#include <algorithm>
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
using namespace std;
// func
// ------------------------------------------------
int CalcSumOfDigit(int n); // 各桁の和を計算する。
long long getDigit(long long n); // 数字の桁数を取得する。
string upper(string str); // 英字を大文字に変換する。
string lower(string str); // 英字を小文字に変換する。
// define
// ------------------------------------------------
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define sz(a) int((a).size())
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define repe(i, n) for (int(i) = 0; (i) <= (n); (i)++)
#define vsort(v) sort((v).begin(), (v).end())
#define rvsort(v) sort(rall((v)))
#define vi vector<int>
#define GCD(a, b) __gcd((a), (b))
#define LCM(a, b) ((a) / GCD((a), (b)) * (b))
#define kiriage(a, b) ((a) + (b)-1) / (b)
const int INF = 1e9;
typedef long long ll;
typedef unsigned long long ull;
// code
// ------------------------------------------------
int main() {
string s, k("keyence");
cin >> s;
bool ans = false;
if (s == k) {
ans = true;
} else {
for (ll i = 0; i < sz(s); ++i) {
for (ll j = i; j < sz(s); ++j) {
string buf = s.substr(0, i) + s.substr(j + 1);
if (buf == k) {
ans = true;
break;
}
}
if (ans)
break;
}
}
if (ans)
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
// funcの実体
// ------------------------------------------------
ll getDigit(ll n) {
int i = 1;
while (1) {
n = n / 10;
if (n == 0)
break;
i++;
}
return i;
}
ll CalcSumOfDigit(ll n) {
ll s = 0;
while (n) {
s += n % 10;
n = n / 10;
}
return s;
}
string upper(string str) {
for (auto itr = str.begin(); itr != str.end(); itr++) {
if (97 <= *itr && *itr <= 122) {
*itr = *itr - 32;
}
}
return str;
}
string lower(string str) {
for (auto itr = str.begin(); itr != str.end(); itr++) {
if (65 <= *itr && *itr <= 90) {
*itr = *itr + 32;
}
}
return str;
}
| [
"variable_declaration.value.change"
] | 948,081 | 948,082 | u610897920 | cpp |
p03150 | #include <bits/stdc++.h>
using namespace std;
signed main() {
string s, c = "keyence";
int a, b = 0;
cin >> s;
for (int i = 0; i < s.size(); i++) {
if (s[i] != c[i]) {
a = i;
break;
}
}
for (int i = s.size(); i >= 0; i--) {
b++;
if (s[i - 1] != c[c.size() - b]) {
b--;
break;
}
}
if (a + b == c.size() || a == c.size() || b == c.size() ||
a + 1 == c.size() && s.size() == c.size())
cout << "YES\n";
else
cout << "NO\n";
} | #include <bits/stdc++.h>
using namespace std;
signed main() {
string s, c = "keyence";
int a, b = 0;
cin >> s;
for (int i = 0; i < s.size(); i++) {
if (s[i] != c[i]) {
a = i;
break;
}
}
for (int i = s.size(); i >= 0; i--) {
b++;
if (s[i - 1] != c[c.size() - b]) {
b--;
break;
}
}
if (a + b >= c.size() || a == c.size() || b == c.size() ||
a + 1 == c.size() && s.size() == c.size())
cout << "YES\n";
else
cout << "NO\n";
} | [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 948,107 | 948,108 | u831161882 | cpp |
p03150 | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const long long INF = 1LL << 60;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
string s;
cin >> s;
bool a = false;
for (int i = 0; i < s.size(); i++) {
for (int j = 0; i + j < s.size(); j++) {
if (s.substr(0, i) + s.substr(i + j) == "keyence") {
a = true;
break;
}
}
}
if (a)
cout << "Yes" << endl;
else
cout << "No" << endl;
} | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const long long INF = 1LL << 60;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
string s;
cin >> s;
bool a = false;
for (int i = 0; i < s.size(); i++) {
for (int j = 0; i + j < s.size(); j++) {
if (s.substr(0, i) + s.substr(i + j) == "keyence") {
a = true;
break;
}
}
}
if (a)
cout << "YES" << endl;
else
cout << "NO" << endl;
} | [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 948,111 | 948,112 | u656568465 | cpp |
p03150 | #include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main() {
string s;
cin >> s;
string s1 = s;
int n = s.size();
for (int i = 0; i < n; i++) {
for (int j = 1; j <= n - i; j++) {
string key = s.erase(i, j);
if (key == "keyence") {
cout << "YES" << endl;
return 0;
}
s = s1;
}
}
cout << "NO" << endl;
return 0;
} | #include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main() {
string s;
cin >> s;
string s1 = s;
int n = s.size();
for (int i = 0; i < n; i++) {
for (int j = 0; j <= n - i; j++) {
string key = s.erase(i, j);
if (key == "keyence") {
cout << "YES" << endl;
return 0;
}
s = s1;
}
}
cout << "NO" << endl;
return 0;
} | [
"literal.number.change",
"variable_declaration.value.change",
"control_flow.loop.for.initializer.change",
"expression.off_by_one"
] | 948,119 | 948,120 | u003026289 | cpp |
p03150 | /*
* じょえチャンネル
* 高評価・チャンネル登録よろしくおねがいします!
* https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
*/
#include <bits/stdc++.h>
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
#define f(i, n) for (int i = 0; i < (n); i++)
#define inf (int)(3e18)
// here!!!
// define int long long !!!!!
#define int long long
// define int long long !!!!!
#define mod (int)((1e9) + 7)
#define intt long long
#define itn long long
#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i <= n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
// Library
//モッドパウ
inline int modpow(int x, int y, int m = mod) {
int res = 1;
while (y) {
if (y % 2) {
res *= x;
res %= m;
}
x = x * x % m;
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;
}
// saidai-kouyakusuu
inline int gcd(int x, int y) {
if (!y) {
return x;
}
return gcd(y, x % y);
}
// 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;
}
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; }
#define fin(i) scanf("%lld", &i)
#define fout(i) printf("%lld", i)
#define fendl printf("\n")
// Library-End
class modInt {
int value, modulo;
public:
modInt() : value(0), modulo(mod) { value = 0; }
template <typename T>
modInt(T value = 0, int modulo = mod) : value(value), modulo(modulo) {
if (value < 0) {
value = -value;
value %= modulo;
value = -value;
value += modulo;
}
this->value = value % modulo;
}
inline operator int() const { return value; }
inline modInt &operator+=(modInt x) {
value += x.value;
if (value >= modulo)
value -= modulo;
return *this;
}
inline modInt &operator++() {
if (value == modulo - 1)
value = 0;
else
value++;
return *this;
}
inline modInt &operator-() const { return modInt(0) -= *this; }
inline modInt &operator-=(modInt x) {
value -= x.value;
if (value < 0)
value += modulo;
return *this;
}
inline modInt &operator--() {
if (value == 0)
value = modulo - 1;
else
value--;
return *this;
}
inline modInt &operator*=(modInt x) {
value = value * x.value % modulo;
return *this;
}
inline modInt &operator/=(modInt x) { return operator*=(x.inv()); }
inline modInt inv() { return modpow(*this, modulo - 2); }
template <typename T> modInt operator+(T x) { return modInt(*this) += x; }
template <typename T> modInt &operator+=(T x) {
return operator+=(modInt(x, modulo));
}
template <typename T> modInt operator-(T x) { return modInt(*this) -= x; }
template <typename T> modInt &operator-=(T x) {
return operator-=(modInt(x, modulo));
}
template <typename T> modInt operator*(T x) { return modInt(*this) *= x; }
template <typename T> modInt &operator*=(T x) {
return operator*=(modInt(x, modulo));
}
template <typename T> modInt operator/(T x) { return modInt(*this) /= x; }
template <typename T> modInt &operator/=(T x) {
return operator/=(modInt(x, modulo));
}
};
istream &operator>>(istream &ist, modInt &x) {
int a;
ist >> a;
x = a;
return ist;
}
#define vecin(v) \
for (int i = 0; i < v.size(); i++) \
scanf("%lld", &v[i]);
#define vecout(v) \
{ \
for (int i = 0; i < v.size(); i++) \
printf("%lld\n", v[i]); \
}
#define endl "\n" // interactive の時に注意!!!
// 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; }
class Union_Find {
vector<int> par;
vector<int> rankmy;
vector<int> ookisa;
public:
Union_Find(int size) {
par = vector<int>(size);
rankmy = vector<int>(size);
ookisa = vector<int>(size);
for (int i = 0; i < size; i++) {
par[i] = i;
ookisa[i] = 1;
}
}
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;
ookisa[y] += ookisa[x];
ookisa[x] = 0;
} else {
par[y] = x;
ookisa[x] += ookisa[y];
ookisa[y] = 0;
if (rankmy[x] == rankmy[y]) {
rankmy[x]++;
}
}
}
int size(int i) {
i = find(i);
return ookisa[i];
}
bool same(int x, int y) { return find(x) == find(y); }
};
// Union-Find-End
int n, m, a[100004], ans, r, b, noko;
string s, t;
signed main() {
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
cin >> s;
t = "keyence";
rep(i, t.size()) {
if (t[i] != s[i]) {
noko = 7 - i;
}
}
for (int i = (int)s.size() - 1; i > (int)s.size() - 1 - noko; i--) {
if (s[i] != t[6 - ((int)s.size() - 1 - i)]) {
NO();
return 0;
}
}
YES();
}
| /*
* じょえチャンネル
* 高評価・チャンネル登録よろしくおねがいします!
* https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
*/
#include <bits/stdc++.h>
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
#define f(i, n) for (int i = 0; i < (n); i++)
#define inf (int)(3e18)
// here!!!
// define int long long !!!!!
#define int long long
// define int long long !!!!!
#define mod (int)((1e9) + 7)
#define intt long long
#define itn long long
#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i <= n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
// Library
//モッドパウ
inline int modpow(int x, int y, int m = mod) {
int res = 1;
while (y) {
if (y % 2) {
res *= x;
res %= m;
}
x = x * x % m;
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;
}
// saidai-kouyakusuu
inline int gcd(int x, int y) {
if (!y) {
return x;
}
return gcd(y, x % y);
}
// 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;
}
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; }
#define fin(i) scanf("%lld", &i)
#define fout(i) printf("%lld", i)
#define fendl printf("\n")
// Library-End
class modInt {
int value, modulo;
public:
modInt() : value(0), modulo(mod) { value = 0; }
template <typename T>
modInt(T value = 0, int modulo = mod) : value(value), modulo(modulo) {
if (value < 0) {
value = -value;
value %= modulo;
value = -value;
value += modulo;
}
this->value = value % modulo;
}
inline operator int() const { return value; }
inline modInt &operator+=(modInt x) {
value += x.value;
if (value >= modulo)
value -= modulo;
return *this;
}
inline modInt &operator++() {
if (value == modulo - 1)
value = 0;
else
value++;
return *this;
}
inline modInt &operator-() const { return modInt(0) -= *this; }
inline modInt &operator-=(modInt x) {
value -= x.value;
if (value < 0)
value += modulo;
return *this;
}
inline modInt &operator--() {
if (value == 0)
value = modulo - 1;
else
value--;
return *this;
}
inline modInt &operator*=(modInt x) {
value = value * x.value % modulo;
return *this;
}
inline modInt &operator/=(modInt x) { return operator*=(x.inv()); }
inline modInt inv() { return modpow(*this, modulo - 2); }
template <typename T> modInt operator+(T x) { return modInt(*this) += x; }
template <typename T> modInt &operator+=(T x) {
return operator+=(modInt(x, modulo));
}
template <typename T> modInt operator-(T x) { return modInt(*this) -= x; }
template <typename T> modInt &operator-=(T x) {
return operator-=(modInt(x, modulo));
}
template <typename T> modInt operator*(T x) { return modInt(*this) *= x; }
template <typename T> modInt &operator*=(T x) {
return operator*=(modInt(x, modulo));
}
template <typename T> modInt operator/(T x) { return modInt(*this) /= x; }
template <typename T> modInt &operator/=(T x) {
return operator/=(modInt(x, modulo));
}
};
istream &operator>>(istream &ist, modInt &x) {
int a;
ist >> a;
x = a;
return ist;
}
#define vecin(v) \
for (int i = 0; i < v.size(); i++) \
scanf("%lld", &v[i]);
#define vecout(v) \
{ \
for (int i = 0; i < v.size(); i++) \
printf("%lld\n", v[i]); \
}
#define endl "\n" // interactive の時に注意!!!
// 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; }
class Union_Find {
vector<int> par;
vector<int> rankmy;
vector<int> ookisa;
public:
Union_Find(int size) {
par = vector<int>(size);
rankmy = vector<int>(size);
ookisa = vector<int>(size);
for (int i = 0; i < size; i++) {
par[i] = i;
ookisa[i] = 1;
}
}
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;
ookisa[y] += ookisa[x];
ookisa[x] = 0;
} else {
par[y] = x;
ookisa[x] += ookisa[y];
ookisa[y] = 0;
if (rankmy[x] == rankmy[y]) {
rankmy[x]++;
}
}
}
int size(int i) {
i = find(i);
return ookisa[i];
}
bool same(int x, int y) { return find(x) == find(y); }
};
// Union-Find-End
int n, m, a[100004], ans, r, b, noko;
string s, t;
signed main() {
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
cin >> s;
t = "keyence";
rep(i, t.size()) {
if (t[i] != s[i]) {
noko = 7 - i;
break;
}
}
for (int i = (int)s.size() - 1; i > (int)s.size() - 1 - noko; i--) {
if (s[i] != t[6 - ((int)s.size() - 1 - i)]) {
NO();
return 0;
}
}
YES();
}
| [
"control_flow.break.add"
] | 948,121 | 948,122 | u943070796 | cpp |
p03150 | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
string com = "keyence";
string ans = "Yes";
if (s == com) {
cout << ans << endl;
return 0;
}
int a = s.size();
for (int i = 0; i < a; i++) {
for (int j = i; j < a; j++) {
string str = "";
for (int k = 0; k < a; k++) {
if (k >= i && k <= j) {
continue;
} else {
str.push_back(s[k]);
}
}
if (str == com) {
cout << ans << endl;
return 0;
}
}
}
cout << "No" << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
string com = "keyence";
string ans = "YES";
if (s == com) {
cout << ans << endl;
return 0;
}
int a = s.size();
for (int i = 0; i < a; i++) {
for (int j = i; j < a; j++) {
string str = "";
for (int k = 0; k < a; k++) {
if (k >= i && k <= j) {
continue;
} else {
str.push_back(s[k]);
}
}
if (str == com) {
cout << ans << endl;
return 0;
}
}
}
cout << "NO" << endl;
return 0;
} | [
"literal.string.change",
"literal.string.case.change",
"variable_declaration.value.change",
"io.output.change"
] | 948,133 | 948,134 | u955282280 | cpp |
p03150 | #include <bits/stdc++.h>
#define REP(i, x) for (int i = 0, i##_len = (x); i < i##_len; ++i)
#define rep(i, a, b) for (int i = (a), i##_len(b); i < i##_len; ++i)
#define All(x) begin(x), end(x)
#define rAll(x) rbegin(x), rend(x)
using namespace std;
using ll = long long;
int main() {
string s;
cin >> s;
REP(i, s.size()) rep(j, i, s.size() + 1) {
string t = s;
t.erase(t.begin() + i, t.end() + j);
if (t == "keyence") {
cout << "Yes" << endl;
return 0;
}
}
cout << "No" << endl;
}
| #include <bits/stdc++.h>
#define REP(i, x) for (int i = 0, i##_len = (x); i < i##_len; ++i)
#define rep(i, a, b) for (int i = (a), i##_len(b); i < i##_len; ++i)
#define All(x) begin(x), end(x)
#define rAll(x) rbegin(x), rend(x)
using namespace std;
using ll = long long;
int main() {
string s;
cin >> s;
REP(i, s.size()) rep(j, i, s.size() + 1) {
string t = s;
t.erase(t.begin() + i, t.begin() + j);
if (t == "keyence") {
cout << "YES" << endl;
return 0;
}
}
cout << "NO" << endl;
}
| [
"call.function.change",
"call.arguments.change",
"expression.operation.binary.change",
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 948,147 | 948,148 | u203033720 | cpp |
p03150 | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
string s;
int main() {
cin >> s;
int n = s.size();
string res = "No";
for (int left = 0; left <= n; left++) {
for (int right = left; right <= n; right++) {
string comp = s.substr(0, left) + s.substr(right);
// cerr << comp << endl;
if (comp == "keyence")
res = "Yes";
}
}
cout << res << endl;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
string s;
int main() {
cin >> s;
int n = s.size();
string res = "NO";
for (int left = 0; left <= n; left++) {
for (int right = left; right <= n; right++) {
string comp = s.substr(0, left) + s.substr(right);
// cerr << comp << endl;
if (comp == "keyence")
res = "YES";
}
}
cout << res << endl;
} | [
"literal.string.change",
"literal.string.case.change",
"variable_declaration.value.change",
"assignment.value.change"
] | 948,151 | 948,152 | u389007679 | cpp |
p03150 | #include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
int N = 0;
N = S.length();
if (N == 7) {
if (S == "keyece") {
cout << "YES" << endl;
return 0;
} else
cout << "NO" << endl;
return 0;
}
for (int i = 0; i < N - 7; i++) {
string P = S;
int C = N - 7;
if (P.erase(i, C) == "keyence") {
cout << "YES" << endl;
return 0;
}
}
cout << "NO" << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
int N = 0;
N = S.length();
if (N == 7) {
if (S == "keyence") {
cout << "YES" << endl;
return 0;
} else
cout << "NO" << endl;
return 0;
}
for (int i = 0; i < N; i++) {
string P = S;
int C = N - 7;
if (P.erase(i, C) == "keyence") {
cout << "YES" << endl;
return 0;
}
}
cout << "NO" << endl;
return 0;
}
| [
"literal.string.change",
"control_flow.branch.if.condition.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.remove"
] | 948,164 | 948,165 | u469315559 | cpp |
p03150 | #include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
int main() {
string s;
cin >> s;
// string key = "keyence";
int slen = s.size();
bool ans = false;
if (s == "keyence") {
cout << "YES" << endl;
return 0;
}
for (int i = 1; i <= slen; i++) {
for (int j = 0; j <= slen - i; j++) {
if (s.erase(j, i) == "keyence")
ans = true;
}
}
if (ans)
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
| #include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
int main() {
string s;
cin >> s;
// string key = "keyence";
int slen = s.size();
bool ans = false;
if (s == "keyence") {
cout << "YES" << endl;
return 0;
}
for (int i = 1; i <= slen; i++) {
for (int j = 0; j <= slen - i; j++) {
string t = s;
if (t.erase(j, i) == "keyence")
ans = true;
}
}
if (ans)
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
| [
"variable_declaration.add",
"identifier.change",
"control_flow.branch.if.condition.change"
] | 948,167 | 948,168 | u729285002 | cpp |
p03150 | #include <algorithm>
#include <iostream>
#include <queue>
using namespace std;
typedef long long ll;
ll inf = 100000000;
typedef pair<ll, ll> P;
int main() {
string s;
cin >> s;
for (int i = 0; i < s.size(); i++) {
for (int j = i + 1; j < s.size() - 1; j++) {
string a = s;
a.erase(i, j);
if (a == "keyence") {
cout << "YES" << endl;
return 0;
}
}
}
cout << "NO" << endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <queue>
using namespace std;
typedef long long ll;
ll inf = 100000000;
typedef pair<ll, ll> P;
int main() {
string s;
cin >> s;
for (int i = 0; i < s.size(); i++) {
for (int j = 0; j < s.size() - i; j++) {
string a = s;
a.erase(i, j);
if (a == "keyence") {
cout << "YES" << endl;
return 0;
}
}
}
cout << "NO" << endl;
return 0;
} | [
"variable_declaration.value.change",
"identifier.replace.remove",
"literal.replace.add",
"control_flow.loop.for.initializer.change",
"expression.operation.binary.change",
"expression.operation.binary.remove",
"identifier.replace.add",
"literal.replace.remove",
"control_flow.loop.for.condition.change... | 948,176 | 948,177 | u077051605 | cpp |
p03150 | #include <bits/stdc++.h>
using namespace std;
int main() {
string S, T = "keyence";
cin >> S;
int i;
for (i = 0; i < 8; i++) {
if (S.substr(0, i) == T.substr(0, i) &&
S.substr(S.size() + i - 7, 7 - i) == T.substr(i, 7 - i))
break;
}
if (i == 8)
cout << "No" << endl;
else
cout << "Yes" << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string S, T = "keyence";
cin >> S;
int i;
for (i = 0; i < 8; i++) {
if (S.substr(0, i) == T.substr(0, i) &&
S.substr(S.size() + i - 7, 7 - i) == T.substr(i, 7 - i))
break;
}
if (i == 8)
cout << "NO" << endl;
else
cout << "YES" << endl;
} | [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 948,178 | 948,179 | u820224016 | cpp |
p03150 | #include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
long long int INF = 1e18;
long long int mod = 1000000007;
double Pi = 3.1415926535897932384626;
vector<ll> G[500005];
vector<P> tree[500010];
priority_queue<ll> pql;
priority_queue<P> pqp;
// big priority queue
priority_queue<ll, vector<ll>, greater<ll>> pqls;
priority_queue<P, vector<P>, greater<P>> pqps;
// small priority queue
// top pop
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};
char dir[] = "RULD";
//↓,→,↑,←
#define p(x) cout << x << endl;
#define el cout << endl;
#define pe(x) cout << x << " ";
#define ps(x) cout << fixed << setprecision(25) << x << endl;
#define pu(x) cout << x;
#define re(i, n) \
for (i = 0; i < n; i++) \
;
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout << #x << " = " << x << endl
ll rui(ll number1, ll number2) {
if (number2 == 0) {
return 1;
} else {
ll number3 = rui(number1, number2 / 2);
number3 *= number3;
number3 %= mod;
if (number2 % 2 == 1) {
number3 *= number1;
number3 %= mod;
}
return number3;
}
}
ll gcd(ll number1, ll number2) {
if (number1 > number2) {
swap(number1, number2);
}
if (number1 == 0 || number1 == number2) {
return number2;
} else {
return gcd(number2 % number1, number1);
}
}
ll i, j, k, ii, jj, n, m, a, b, c, d, e, g, h, r, w, l;
ll num, ans;
ll x[500005], y[500005], z[500005];
bool dame, flag;
ll ok, ng;
string s, t;
int main() {
cin >> s;
n = s.size();
p(n);
t = "keyence";
for (i = 0; i <= 7; i++) {
a = 0;
// pe(i);
if (s.substr(0, i) == t.substr(0, i) || i == 0) {
a++;
}
if (s.substr(n - 7 + i, 7 - i) == t.substr(i, 7 - i) || i == 7) {
a++;
}
// p(a);
if (a == 2) {
p("YES");
return 0;
}
}
p("NO");
return 0;
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
long long int INF = 1e18;
long long int mod = 1000000007;
double Pi = 3.1415926535897932384626;
vector<ll> G[500005];
vector<P> tree[500010];
priority_queue<ll> pql;
priority_queue<P> pqp;
// big priority queue
priority_queue<ll, vector<ll>, greater<ll>> pqls;
priority_queue<P, vector<P>, greater<P>> pqps;
// small priority queue
// top pop
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};
char dir[] = "RULD";
//↓,→,↑,←
#define p(x) cout << x << endl;
#define el cout << endl;
#define pe(x) cout << x << " ";
#define ps(x) cout << fixed << setprecision(25) << x << endl;
#define pu(x) cout << x;
#define re(i, n) \
for (i = 0; i < n; i++) \
;
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout << #x << " = " << x << endl
ll rui(ll number1, ll number2) {
if (number2 == 0) {
return 1;
} else {
ll number3 = rui(number1, number2 / 2);
number3 *= number3;
number3 %= mod;
if (number2 % 2 == 1) {
number3 *= number1;
number3 %= mod;
}
return number3;
}
}
ll gcd(ll number1, ll number2) {
if (number1 > number2) {
swap(number1, number2);
}
if (number1 == 0 || number1 == number2) {
return number2;
} else {
return gcd(number2 % number1, number1);
}
}
ll i, j, k, ii, jj, n, m, a, b, c, d, e, g, h, r, w, l;
ll num, ans;
ll x[500005], y[500005], z[500005];
bool dame, flag;
ll ok, ng;
string s, t;
int main() {
cin >> s;
n = s.size(); // p(n);
t = "keyence";
for (i = 0; i <= 7; i++) {
a = 0;
// pe(i);
if (s.substr(0, i) == t.substr(0, i) || i == 0) {
a++;
}
if (s.substr(n - 7 + i, 7 - i) == t.substr(i, 7 - i) || i == 7) {
a++;
}
// p(a);
if (a == 2) {
p("YES");
return 0;
}
}
p("NO");
return 0;
} | [
"call.remove"
] | 948,184 | 948,185 | u399527088 | cpp |
p03150 | #include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
string S;
cin >> S;
string key = "keyence";
int leftsum = 0;
for (int i = 0; i < key.length(); i++) {
if (key[i] == S[i]) {
leftsum++;
} else {
break;
}
}
int rightsum = 0;
for (int i = 0; i < key.length(); i++) {
if (key[key.length() - 1 - i] == S[S.length() - 1 - i]) {
rightsum++;
} else {
break;
}
}
if (leftsum + rightsum == key.length()) {
cout << "YES\n";
} else {
cout << "NO\n";
}
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
string S;
cin >> S;
string key = "keyence";
int leftsum = 0;
for (int i = 0; i < key.length(); i++) {
if (key[i] == S[i]) {
leftsum++;
} else {
break;
}
}
int rightsum = 0;
for (int i = 0; i < key.length(); i++) {
if (key[key.length() - 1 - i] == S[S.length() - 1 - i]) {
rightsum++;
} else {
break;
}
}
if (leftsum + rightsum >= key.length()) {
cout << "YES\n";
} else {
cout << "NO\n";
}
} | [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 948,194 | 948,195 | u317806971 | cpp |
p03150 | #include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstddef>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
using ll = long long;
using ull = unsigned long long;
// vector
template <class T> using vec = std::vector<T>;
template <class T> using vvec = vec<vec<T>>;
constexpr std::size_t operator""_sz(ull n) { return std::size_t(n); }
int main() {
using namespace std;
string s;
cin >> s;
bool ans{};
for (int i = 0; i < s.size(); ++i)
for (int l = 0; l + i < s.size(); ++l) {
string sub;
sub += s.substr(0, i);
sub += s.substr(i + l + 1);
if (sub == "keyence") {
ans = true;
break;
}
}
if (ans)
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
} | #include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstddef>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
using ll = long long;
using ull = unsigned long long;
// vector
template <class T> using vec = std::vector<T>;
template <class T> using vvec = vec<vec<T>>;
constexpr std::size_t operator""_sz(ull n) { return std::size_t(n); }
int main() {
using namespace std;
string s;
cin >> s;
bool ans{};
for (int i = 0; i < s.size(); ++i)
for (int l = 0; l + i < s.size(); ++l) {
string sub;
sub += s.substr(0, i);
sub += s.substr(i + l);
if (sub == "keyence") {
ans = true;
break;
}
}
if (ans)
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
} | [
"expression.operation.binary.remove"
] | 948,204 | 948,205 | u207917850 | cpp |
p03150 | #include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define LL long long
string str;
string ans("keyence");
string Remove(int Begin, int len) {
return str.substr(0, Begin) + str.substr(Begin + len);
}
int main() {
#ifdef Dmaxiya
freopen("test.txt", "r", stdin);
#endif // Dmaxiya
ios::sync_with_stdio(false);
while (cin >> str) {
if (str == ans) {
cout << "YESS" << endl;
continue;
}
int len = str.length();
bool flag = false;
for (int i = 0; i < len; ++i) {
for (int j = 1; i + j - 1 < len; ++j) {
if (Remove(i, j) == ans) {
flag = true;
break;
}
}
}
if (flag) {
cout << "YES\n";
} else {
cout << "NO\n";
}
}
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define LL long long
string str;
string ans("keyence");
string Remove(int Begin, int len) {
return str.substr(0, Begin) + str.substr(Begin + len);
}
int main() {
#ifdef Dmaxiya
freopen("test.txt", "r", stdin);
#endif // Dmaxiya
ios::sync_with_stdio(false);
while (cin >> str) {
if (str == ans) {
cout << "YES" << endl;
continue;
}
int len = str.length();
bool flag = false;
for (int i = 0; i < len; ++i) {
for (int j = 1; i + j - 1 < len; ++j) {
if (Remove(i, j) == ans) {
flag = true;
break;
}
}
}
if (flag) {
cout << "YES\n";
} else {
cout << "NO\n";
}
}
return 0;
}
| [
"literal.string.change",
"io.output.change"
] | 948,224 | 948,225 | u493017253 | cpp |
p03150 | #include <bits/stdc++.h>
using namespace std;
//#define int long long
signed main() {
string s;
string q = "keyence";
cin >> s;
int i = 0;
int t = 0;
for (int j = 0; j < 7; j++) {
if (i == 0) {
if (q[j] != s[j])
i = 1;
if (q[j] != s[j - 7 + s.length()])
t = 1;
} else {
if (q[j] != s[j - 7 + s.length()])
t = 1;
}
}
if (t == 0)
cout << "YES";
else
cout << "NO";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
//#define int long long
signed main() {
string s;
string q = "keyence";
cin >> s;
int i = 0;
int t = 0;
for (int j = 0; j < 7; j++) {
if (i == 0) {
if (q[j] != s[j]) {
i = 1;
if (q[j] != s[j - 7 + s.length()])
t = 1;
}
} else {
if (q[j] != s[j - 7 + s.length()])
t = 1;
}
}
if (t == 0)
cout << "YES";
else
cout << "NO";
return 0;
} | [] | 948,228 | 948,229 | u651317892 | cpp |
p03150 |
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define M_PI 3.14159265358979323846
#ifdef LOCAL
#include <intrin.h>
#include <sys/timeb.h>
#include <sys/types.h>
#include <thread>
#else
#include <sys/time.h>
#endif
using namespace std;
// conversion
//------------------------------------------
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
// typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define EACH(i, c) \
for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define FILL(a, x) memset(a, x, sizeof(a))
// repetition
//------------------------------------------
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
char ans[] = "keyence";
int main() {
string str;
cin >> str;
int n = str.length();
REP(i, 8) {
if (str.substr(0, i) + str.substr(n - i - 1, 7 - i) == "keyence") {
cout << "YES" << endl;
return 0;
}
}
cout << "NO" << endl;
return 0;
} |
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define M_PI 3.14159265358979323846
#ifdef LOCAL
#include <intrin.h>
#include <sys/timeb.h>
#include <sys/types.h>
#include <thread>
#else
#include <sys/time.h>
#endif
using namespace std;
// conversion
//------------------------------------------
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
// typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define EACH(i, c) \
for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define FILL(a, x) memset(a, x, sizeof(a))
// repetition
//------------------------------------------
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
char ans[] = "keyence";
int main() {
string str;
cin >> str;
int n = str.length();
REP(i, 8) {
if (str.substr(0, i) + str.substr(n - (7 - i), 7 - i) == "keyence") {
cout << "YES" << endl;
return 0;
}
}
cout << "NO" << endl;
return 0;
} | [
"control_flow.branch.if.condition.change",
"identifier.replace.add",
"literal.replace.remove"
] | 948,230 | 948,231 | u614497125 | cpp |
p03150 | #include <bits/stdc++.h>
#define int long long
#define f(i, n) for (int i = 0; i < n; i++)
#define F first
#define S second
#define mod 1000000007
#define P pair<int, int>
using namespace std;
signed main() {
string s, t = "keyence";
cin >> s;
bool b = false;
int j = 0;
f(i, s.size()) {
if (s[i] != t[j]) {
if (b) {
puts("NO");
return 0;
} else
i += s.size() - t.size() - 1;
b = true;
}
j++;
}
puts("YES");
return 0;
}
| #include <bits/stdc++.h>
#define int long long
#define f(i, n) for (int i = 0; i < n; i++)
#define F first
#define S second
#define mod 1000000007
#define P pair<int, int>
using namespace std;
signed main() {
string s, t = "keyence";
cin >> s;
bool b = false;
int j = 0;
f(i, s.size()) {
if (s[i] != t[j]) {
if (b) {
puts("NO");
return 0;
} else
i += s.size() - t.size() - 1;
b = true;
j--;
}
j++;
}
puts("YES");
return 0;
}
| [
"expression.unary.arithmetic.add"
] | 948,239 | 948,240 | u259210975 | cpp |
p03150 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> p_int;
typedef pair<ll, ll> p_ll;
typedef tuple<ll, ll, ll> t3_ll;
int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
int prime[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41,
43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
const ll inf = 1e9 + 7;
int main() {
string s;
cin >> s;
bool ok = false;
for (int i = 0; i < 9; i++) {
string x = s;
x.erase(i, s.size() - 7);
if (x == "keyence") {
ok = true;
}
}
if (ok)
cout << "YES";
else
cout << "NO";
cout << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> p_int;
typedef pair<ll, ll> p_ll;
typedef tuple<ll, ll, ll> t3_ll;
int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
int prime[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41,
43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
const ll inf = 1e9 + 7;
int main() {
string s;
cin >> s;
bool ok = false;
for (int i = 0; i < 7; i++) {
string x = s;
x.erase(i, s.size() - 7);
if (x == "keyence") {
ok = true;
}
}
if (ok)
cout << "YES";
else
cout << "NO";
cout << endl;
} | [
"literal.number.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 948,249 | 948,250 | u764234894 | cpp |
p03150 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define pb push_back
#define mp make_pair
#define rep(i, n) for (int i = 0; i < (n); ++i)
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
string s;
cin >> s;
string t = "keyence";
rep(i, 8) {
if (s.substr(0, i) + s.substr(s.size() - 1 - i, 7 - i) == t) {
cout << "YES" << endl;
return 0;
}
}
cout << "NO" << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define pb push_back
#define mp make_pair
#define rep(i, n) for (int i = 0; i < (n); ++i)
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
string s;
cin >> s;
string t = "keyence";
rep(i, 8) {
if (s.substr(0, i) + s.substr(s.size() - (7 - i), 7 - i) == t) {
cout << "YES" << endl;
return 0;
}
}
cout << "NO" << endl;
} | [
"control_flow.branch.if.condition.change"
] | 948,251 | 948,252 | u480831358 | cpp |
p03150 | #include <bits/stdc++.h>
#define cinf(n, x, y, z) \
for (int i = 0; i < (n); i++) \
cin >> x[i] >> y[i] >> z[i];
typedef long long int ll;
using namespace std;
int main() {
string s;
cin >> s;
if (s == "keyence") {
cout << "YES" << endl;
return 0;
}
int n = s.size();
for (int i = 0; i < n; i++) {
for (int j = i; j < n; j++) {
string S = "";
for (int k = 0; k < n; k++) {
if (i <= k && k <= j)
continue;
else
S.push_back(s[k]);
}
if (s == "keyence") {
cout << "YES" << endl;
return 0;
}
}
}
cout << "NO" << endl;
return 0;
} | #include <bits/stdc++.h>
#define cinf(n, x, y, z) \
for (int i = 0; i < (n); i++) \
cin >> x[i] >> y[i] >> z[i];
typedef long long int ll;
using namespace std;
int main() {
string s;
cin >> s;
if (s == "keyence") {
cout << "YES" << endl;
return 0;
}
int n = s.size();
for (int i = 0; i < n; i++) {
for (int j = i; j < n; j++) {
string S = "";
for (int k = 0; k < n; k++) {
if (i <= k && k <= j)
continue;
else
S.push_back(s[k]);
}
if (S == "keyence") {
cout << "YES" << endl;
return 0;
}
}
}
cout << "NO" << endl;
return 0;
} | [
"identifier.change",
"control_flow.branch.if.condition.change"
] | 948,290 | 948,291 | u928536113 | cpp |
p03150 | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef long long int llint;
typedef pair<ll, ll> pa;
#define MM 1000000000
#define MOD MM + 7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define MAX_T 1001
#define Pair pair<int, int>
#define chmax(a, b) (a < b ? a = b : 0)
#define chmin(a, b) (a > b ? a = b : 0)
#define INF (1 << 29) // 536870912
const long double PI = acos(-1);
const ll DEP = 1e18;
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
int GCD(int x, int y) { return y ? GCD(y, x % y) : x; }
int main() {
string s;
cin >> s;
string ans = "NO";
if (s == "keyence")
ans == "YES";
else {
for (int i = 0; i < 7; i++) {
if (s.substr(0, i) + s.substr(s.size() + i - 7, 7 - i) == "keyence") {
ans = "YES";
break;
}
}
}
cout << ans << endl;
}
| #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef long long int llint;
typedef pair<ll, ll> pa;
#define MM 1000000000
#define MOD MM + 7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define MAX_T 1001
#define Pair pair<int, int>
#define chmax(a, b) (a < b ? a = b : 0)
#define chmin(a, b) (a > b ? a = b : 0)
#define INF (1 << 29) // 536870912
const long double PI = acos(-1);
const ll DEP = 1e18;
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
int GCD(int x, int y) { return y ? GCD(y, x % y) : x; }
int main() {
string s;
cin >> s;
string ans = "NO";
if (s == "keyence")
ans = "YES";
else {
for (int i = 0; i < 7; i++) {
if (s.substr(0, i) + s.substr(s.size() + i - 7, 7 - i) == "keyence") {
ans = "YES";
break;
}
}
}
cout << ans << endl;
}
| [
"expression.operation.compare.replace.remove",
"assignment.replace.add",
"misc.typo"
] | 948,294 | 948,295 | u342051078 | cpp |
p03150 | #include "bits/stdc++.h"
using namespace std;
#define Rep(i, n) for (int i = 0; i < n; i++)
#define For(i, n1, n2) for (int i = n1; i < n2; i++)
#define REP(i, n) for (ll i = 0; i < n; i++)
#define RREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, n1, n2) for (ll i = n1; i < n2; i++)
#define put(a) cout << a << "\n";
#define all(c) (c).begin(), (c).end()
#define SORT(a) sort((a).begin(), (a).end())
#define TDARRAY(int, a, n, m) vector<vector<int>> a(n, vector<int>(m, 0));
#define oorret 0
#define oor(x) \
[&]() { \
try { \
x; \
} catch (const out_of_range &oor) { \
return oorret; \
} \
return x; \
}()
typedef long long ll;
typedef pair<int, int> P;
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
string s;
string t = "keyence";
int main() {
cin >> s;
int n = s.size();
if (n < 7) {
put("No");
return 0;
}
int r = 0, l = 0;
REP(i, 7) {
if (s[i] == t[i]) {
l = i + 1;
} else {
// l = i;
break;
}
}
REP(i, 7) {
if (s[n - 1 - i] == t[6 - i]) {
r = i + 1;
} else {
// r = i;
break;
}
}
if (l + r >= 7) {
put("Yes");
} else {
put("No");
}
return 0;
}
| #include "bits/stdc++.h"
using namespace std;
#define Rep(i, n) for (int i = 0; i < n; i++)
#define For(i, n1, n2) for (int i = n1; i < n2; i++)
#define REP(i, n) for (ll i = 0; i < n; i++)
#define RREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, n1, n2) for (ll i = n1; i < n2; i++)
#define put(a) cout << a << "\n";
#define all(c) (c).begin(), (c).end()
#define SORT(a) sort((a).begin(), (a).end())
#define TDARRAY(int, a, n, m) vector<vector<int>> a(n, vector<int>(m, 0));
#define oorret 0
#define oor(x) \
[&]() { \
try { \
x; \
} catch (const out_of_range &oor) { \
return oorret; \
} \
return x; \
}()
typedef long long ll;
typedef pair<int, int> P;
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
string s;
string t = "keyence";
int main() {
cin >> s;
int n = s.size();
if (n < 7) {
put("No");
return 0;
}
int r = 0, l = 0;
REP(i, 7) {
if (s[i] == t[i]) {
l = i + 1;
} else {
// l = i;
break;
}
}
REP(i, 7) {
if (s[n - 1 - i] == t[6 - i]) {
r = i + 1;
} else {
// r = i;
break;
}
}
if (l + r >= 7) {
put("YES");
} else {
put("NO");
}
return 0;
}
| [
"literal.string.change",
"literal.string.case.change",
"call.arguments.change"
] | 948,300 | 948,301 | u030685402 | cpp |
p03150 | #include <iostream>
#include <string>
using namespace std;
int main(void) {
string s;
cin >> s;
int n = s.length();
bool flag = false;
for (int i = 0; i <= n; ++i) {
if (s.substr(0, i) + s.substr(n - (7 - i)) == string("keyence"))
flag = true;
}
cout << (flag ? "YES" : "NO") << endl;
return 0;
} | #include <iostream>
#include <string>
using namespace std;
int main(void) {
string s;
cin >> s;
int n = s.length();
bool flag = false;
for (int i = 0; i <= 7; ++i) {
if (s.substr(0, i) + s.substr(n - (7 - i)) == string("keyence"))
flag = true;
}
cout << (flag ? "YES" : "NO") << endl;
return 0;
} | [
"identifier.replace.remove",
"literal.replace.add",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 948,340 | 948,341 | u437973379 | cpp |
p03150 | #include <bits/stdc++.h>
using namespace std;
int main() {
regex re[8];
re[0] = "keyence.*";
re[1] = "keyenc.*e";
re[2] = "keyen.*ce";
re[3] = "keye.*nce";
re[4] = "key.*ence";
re[5] = "ke.*yence";
re[6] = "k.*eyence";
re[7] = ".*keyence";
string s;
cin >> s;
bool ret = false;
for (int i = 0; i < s.size(); i++) {
ret = ret || regex_match(s, re[i]);
}
cout << (ret ? "YES" : "NO") << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
regex re[8];
re[0] = "keyence.*";
re[1] = "keyenc.*e";
re[2] = "keyen.*ce";
re[3] = "keye.*nce";
re[4] = "key.*ence";
re[5] = "ke.*yence";
re[6] = "k.*eyence";
re[7] = ".*keyence";
string s;
cin >> s;
bool ret = false;
for (int i = 0; i < 8; i++) {
ret = ret || regex_match(s, re[i]);
}
cout << (ret ? "YES" : "NO") << endl;
return 0;
} | [
"identifier.replace.remove",
"literal.replace.add",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change",
"call.remove"
] | 948,350 | 948,351 | u174404613 | cpp |
p03150 | #include <bits/stdc++.h>
using namespace std;
string s, k = "keyence";
int main() {
cin >> s;
if (s == k) {
cout << "YES" << endl;
return 0;
}
int n = s.size();
for (int i = 0; i < n; i++) {
for (int j = i; j < n; j++) {
string t = "";
for (int k = 0; k < n; k++) {
if (k < i && k > j) {
t += s[k];
}
}
if (t == k) {
cout << "YES" << endl;
return 0;
}
}
}
cout << "NO" << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
string s, k = "keyence";
int main() {
cin >> s;
if (s == k) {
cout << "YES" << endl;
return 0;
}
int n = s.size();
for (int i = 0; i < n; i++) {
for (int j = i; j < n; j++) {
string t = "";
for (int k = 0; k < n; k++) {
if (k < i || k > j) {
t += s[k];
}
}
if (t == k) {
cout << "YES" << endl;
return 0;
}
}
}
cout << "NO" << endl;
return 0;
} | [
"misc.opposites",
"control_flow.branch.if.condition.change"
] | 948,354 | 948,355 | u386107860 | cpp |
p03150 |
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define INF 2147483647
#define MODE 1
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " ";
#define END cout << endl;
#else
#define DEB(X) \
{}
#define ARDEB(i, X) \
{}
#define END \
{}
#endif
typedef long long int ll;
int main() {
string s;
cin >> s;
string t = "keyence";
int d = s.size() - 7;
for (int i = 0; i < s.size() - d; i++) {
int k = 0;
string r = s.substr(0, i) + s.substr(i + d, s.size() - i - d);
DEB(r) END if (t == r) {
cout << "YES" << endl;
return 0;
}
}
cout << "NO" << endl;
} |
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define INF 2147483647
//#define MODE 1
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " ";
#define END cout << endl;
#else
#define DEB(X) \
{}
#define ARDEB(i, X) \
{}
#define END \
{}
#endif
typedef long long int ll;
int main() {
string s;
cin >> s;
string t = "keyence";
int d = s.size() - 7;
for (int i = 0; i < s.size() - d; i++) {
int k = 0;
string r = s.substr(0, i) + s.substr(i + d, s.size() - i - d);
DEB(r) END if (t == r) {
cout << "YES" << endl;
return 0;
}
}
cout << "NO" << endl;
} | [] | 948,359 | 948,360 | u901561754 | cpp |
p03150 | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
#define REP(i, n) for (long long i = 0; i < (n); i++)
#define FOR(i, m, n) for (long long i = (m); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
template <class T> using V = vector<T>;
template <class T, class U> using P = pair<T, U>;
const ll MOD = (ll)1e9 + 7;
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;
template <class T> void corner(bool flg, T hoge) {
if (flg) {
cout << hoge << endl;
exit(0);
}
}
template <class T, class U>
ostream &operator<<(ostream &o, const map<T, U> &obj) {
o << "{";
for (auto &x : obj)
o << " {" << x.first << " : " << x.second << "}"
<< ",";
o << " }";
return o;
}
template <class T> ostream &operator<<(ostream &o, const set<T> &obj) {
o << "{";
for (auto itr = obj.begin(); itr != obj.end(); ++itr)
o << (itr != obj.begin() ? ", " : "") << *itr;
o << "}";
return o;
}
template <class T> ostream &operator<<(ostream &o, const vector<T> &obj) {
o << "{";
for (int i = 0; i < (int)obj.size(); ++i)
o << (i > 0 ? ", " : "") << obj[i];
o << "}";
return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U> &obj) {
o << "{" << obj.first << ", " << obj.second << "}";
return o;
}
template <template <class tmp> class T, class U>
ostream &operator<<(ostream &o, const T<U> &obj) {
o << "{";
for (auto itr = obj.begin(); itr != obj.end(); ++itr)
o << (itr != obj.begin() ? ", " : "") << *itr;
o << "}";
return o;
}
void print(void) { cout << endl; }
template <class Head> void print(Head &&head) {
cout << head;
print();
}
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
cout << head << " ";
print(forward<Tail>(tail)...);
}
void YN(bool flg) { cout << ((flg) ? "YES" : "NO") << endl; }
void Yn(bool flg) { cout << ((flg) ? "Yes" : "No") << endl; }
void yn(bool flg) { cout << ((flg) ? "yes" : "no") << endl; }
int main() {
string S;
cin >> S;
int N = S.size(), flg = 0;
for (int i = 0; i <= N; ++i) {
for (int j = i + 1; j <= N; ++j) {
if (S.substr(0, i) + S.substr(j, N) == "keyence")
flg = 1;
}
}
YN(flg);
return 0;
} | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
#define REP(i, n) for (long long i = 0; i < (n); i++)
#define FOR(i, m, n) for (long long i = (m); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
template <class T> using V = vector<T>;
template <class T, class U> using P = pair<T, U>;
const ll MOD = (ll)1e9 + 7;
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;
template <class T> void corner(bool flg, T hoge) {
if (flg) {
cout << hoge << endl;
exit(0);
}
}
template <class T, class U>
ostream &operator<<(ostream &o, const map<T, U> &obj) {
o << "{";
for (auto &x : obj)
o << " {" << x.first << " : " << x.second << "}"
<< ",";
o << " }";
return o;
}
template <class T> ostream &operator<<(ostream &o, const set<T> &obj) {
o << "{";
for (auto itr = obj.begin(); itr != obj.end(); ++itr)
o << (itr != obj.begin() ? ", " : "") << *itr;
o << "}";
return o;
}
template <class T> ostream &operator<<(ostream &o, const vector<T> &obj) {
o << "{";
for (int i = 0; i < (int)obj.size(); ++i)
o << (i > 0 ? ", " : "") << obj[i];
o << "}";
return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U> &obj) {
o << "{" << obj.first << ", " << obj.second << "}";
return o;
}
template <template <class tmp> class T, class U>
ostream &operator<<(ostream &o, const T<U> &obj) {
o << "{";
for (auto itr = obj.begin(); itr != obj.end(); ++itr)
o << (itr != obj.begin() ? ", " : "") << *itr;
o << "}";
return o;
}
void print(void) { cout << endl; }
template <class Head> void print(Head &&head) {
cout << head;
print();
}
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
cout << head << " ";
print(forward<Tail>(tail)...);
}
void YN(bool flg) { cout << ((flg) ? "YES" : "NO") << endl; }
void Yn(bool flg) { cout << ((flg) ? "Yes" : "No") << endl; }
void yn(bool flg) { cout << ((flg) ? "yes" : "no") << endl; }
int main() {
string S;
cin >> S;
int N = S.size(), flg = 0;
for (int i = 0; i <= N; ++i) {
for (int j = i; j <= N; ++j) {
// cout << S.substr(0, i) + S.substr(j, N) << endl;
if (S.substr(0, i) + S.substr(j, N) == "keyence")
flg = 1;
}
}
YN(flg);
// cin >> N;
return 0;
} | [
"control_flow.loop.for.initializer.change",
"expression.operation.binary.remove"
] | 948,368 | 948,369 | u898651494 | cpp |
p03150 | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
#define REP(i, n) for (long long i = 0; i < (n); i++)
#define FOR(i, m, n) for (long long i = (m); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
template <class T> using V = vector<T>;
template <class T, class U> using P = pair<T, U>;
const ll MOD = (ll)1e9 + 7;
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;
template <class T> void corner(bool flg, T hoge) {
if (flg) {
cout << hoge << endl;
exit(0);
}
}
template <class T, class U>
ostream &operator<<(ostream &o, const map<T, U> &obj) {
o << "{";
for (auto &x : obj)
o << " {" << x.first << " : " << x.second << "}"
<< ",";
o << " }";
return o;
}
template <class T> ostream &operator<<(ostream &o, const set<T> &obj) {
o << "{";
for (auto itr = obj.begin(); itr != obj.end(); ++itr)
o << (itr != obj.begin() ? ", " : "") << *itr;
o << "}";
return o;
}
template <class T> ostream &operator<<(ostream &o, const vector<T> &obj) {
o << "{";
for (int i = 0; i < (int)obj.size(); ++i)
o << (i > 0 ? ", " : "") << obj[i];
o << "}";
return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U> &obj) {
o << "{" << obj.first << ", " << obj.second << "}";
return o;
}
template <template <class tmp> class T, class U>
ostream &operator<<(ostream &o, const T<U> &obj) {
o << "{";
for (auto itr = obj.begin(); itr != obj.end(); ++itr)
o << (itr != obj.begin() ? ", " : "") << *itr;
o << "}";
return o;
}
void print(void) { cout << endl; }
template <class Head> void print(Head &&head) {
cout << head;
print();
}
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
cout << head << " ";
print(forward<Tail>(tail)...);
}
void YN(bool flg) { cout << ((flg) ? "YES" : "NO") << endl; }
void Yn(bool flg) { cout << ((flg) ? "Yes" : "No") << endl; }
void yn(bool flg) { cout << ((flg) ? "yes" : "no") << endl; }
int main() {
string S;
cin >> S;
int N = S.size(), flg = 0;
for (int i = 0; i <= N; ++i) {
for (int j = i + 1; j < N; ++j) {
if (S.substr(0, i) + S.substr(j, N) == "keyence")
flg = 1;
}
}
YN(flg);
return 0;
} | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
#define REP(i, n) for (long long i = 0; i < (n); i++)
#define FOR(i, m, n) for (long long i = (m); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
template <class T> using V = vector<T>;
template <class T, class U> using P = pair<T, U>;
const ll MOD = (ll)1e9 + 7;
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;
template <class T> void corner(bool flg, T hoge) {
if (flg) {
cout << hoge << endl;
exit(0);
}
}
template <class T, class U>
ostream &operator<<(ostream &o, const map<T, U> &obj) {
o << "{";
for (auto &x : obj)
o << " {" << x.first << " : " << x.second << "}"
<< ",";
o << " }";
return o;
}
template <class T> ostream &operator<<(ostream &o, const set<T> &obj) {
o << "{";
for (auto itr = obj.begin(); itr != obj.end(); ++itr)
o << (itr != obj.begin() ? ", " : "") << *itr;
o << "}";
return o;
}
template <class T> ostream &operator<<(ostream &o, const vector<T> &obj) {
o << "{";
for (int i = 0; i < (int)obj.size(); ++i)
o << (i > 0 ? ", " : "") << obj[i];
o << "}";
return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U> &obj) {
o << "{" << obj.first << ", " << obj.second << "}";
return o;
}
template <template <class tmp> class T, class U>
ostream &operator<<(ostream &o, const T<U> &obj) {
o << "{";
for (auto itr = obj.begin(); itr != obj.end(); ++itr)
o << (itr != obj.begin() ? ", " : "") << *itr;
o << "}";
return o;
}
void print(void) { cout << endl; }
template <class Head> void print(Head &&head) {
cout << head;
print();
}
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
cout << head << " ";
print(forward<Tail>(tail)...);
}
void YN(bool flg) { cout << ((flg) ? "YES" : "NO") << endl; }
void Yn(bool flg) { cout << ((flg) ? "Yes" : "No") << endl; }
void yn(bool flg) { cout << ((flg) ? "yes" : "no") << endl; }
int main() {
string S;
cin >> S;
int N = S.size(), flg = 0;
for (int i = 0; i <= N; ++i) {
for (int j = i; j <= N; ++j) {
// cout << S.substr(0, i) + S.substr(j, N) << endl;
if (S.substr(0, i) + S.substr(j, N) == "keyence")
flg = 1;
}
}
YN(flg);
// cin >> N;
return 0;
} | [
"control_flow.loop.for.initializer.change",
"expression.operation.binary.remove",
"expression.operator.compare.change",
"control_flow.loop.for.condition.change",
"expression.off_by_one",
"expression.operation.binary.change"
] | 948,370 | 948,369 | u898651494 | cpp |
p03150 | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
#define REP(i, n) for (long long i = 0; i < (n); i++)
#define FOR(i, m, n) for (long long i = (m); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
template <class T> using V = vector<T>;
template <class T, class U> using P = pair<T, U>;
const ll MOD = (ll)1e9 + 7;
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;
template <class T> void corner(bool flg, T hoge) {
if (flg) {
cout << hoge << endl;
exit(0);
}
}
template <class T, class U>
ostream &operator<<(ostream &o, const map<T, U> &obj) {
o << "{";
for (auto &x : obj)
o << " {" << x.first << " : " << x.second << "}"
<< ",";
o << " }";
return o;
}
template <class T> ostream &operator<<(ostream &o, const set<T> &obj) {
o << "{";
for (auto itr = obj.begin(); itr != obj.end(); ++itr)
o << (itr != obj.begin() ? ", " : "") << *itr;
o << "}";
return o;
}
template <class T> ostream &operator<<(ostream &o, const vector<T> &obj) {
o << "{";
for (int i = 0; i < (int)obj.size(); ++i)
o << (i > 0 ? ", " : "") << obj[i];
o << "}";
return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U> &obj) {
o << "{" << obj.first << ", " << obj.second << "}";
return o;
}
template <template <class tmp> class T, class U>
ostream &operator<<(ostream &o, const T<U> &obj) {
o << "{";
for (auto itr = obj.begin(); itr != obj.end(); ++itr)
o << (itr != obj.begin() ? ", " : "") << *itr;
o << "}";
return o;
}
void print(void) { cout << endl; }
template <class Head> void print(Head &&head) {
cout << head;
print();
}
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
cout << head << " ";
print(forward<Tail>(tail)...);
}
void YN(bool flg) { cout << ((flg) ? "YES" : "NO") << endl; }
void Yn(bool flg) { cout << ((flg) ? "Yes" : "No") << endl; }
void yn(bool flg) { cout << ((flg) ? "yes" : "no") << endl; }
int main() {
string S;
cin >> S;
int N = S.size(), flg = 0;
for (int i = 0; i < N; ++i) {
for (int j = i + 1; j < N; ++j) {
if (S.substr(0, i) + S.substr(j, N) == "keyence")
flg = 1;
}
}
YN(flg);
return 0;
} | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
#define REP(i, n) for (long long i = 0; i < (n); i++)
#define FOR(i, m, n) for (long long i = (m); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
template <class T> using V = vector<T>;
template <class T, class U> using P = pair<T, U>;
const ll MOD = (ll)1e9 + 7;
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;
template <class T> void corner(bool flg, T hoge) {
if (flg) {
cout << hoge << endl;
exit(0);
}
}
template <class T, class U>
ostream &operator<<(ostream &o, const map<T, U> &obj) {
o << "{";
for (auto &x : obj)
o << " {" << x.first << " : " << x.second << "}"
<< ",";
o << " }";
return o;
}
template <class T> ostream &operator<<(ostream &o, const set<T> &obj) {
o << "{";
for (auto itr = obj.begin(); itr != obj.end(); ++itr)
o << (itr != obj.begin() ? ", " : "") << *itr;
o << "}";
return o;
}
template <class T> ostream &operator<<(ostream &o, const vector<T> &obj) {
o << "{";
for (int i = 0; i < (int)obj.size(); ++i)
o << (i > 0 ? ", " : "") << obj[i];
o << "}";
return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U> &obj) {
o << "{" << obj.first << ", " << obj.second << "}";
return o;
}
template <template <class tmp> class T, class U>
ostream &operator<<(ostream &o, const T<U> &obj) {
o << "{";
for (auto itr = obj.begin(); itr != obj.end(); ++itr)
o << (itr != obj.begin() ? ", " : "") << *itr;
o << "}";
return o;
}
void print(void) { cout << endl; }
template <class Head> void print(Head &&head) {
cout << head;
print();
}
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
cout << head << " ";
print(forward<Tail>(tail)...);
}
void YN(bool flg) { cout << ((flg) ? "YES" : "NO") << endl; }
void Yn(bool flg) { cout << ((flg) ? "Yes" : "No") << endl; }
void yn(bool flg) { cout << ((flg) ? "yes" : "no") << endl; }
int main() {
string S;
cin >> S;
int N = S.size(), flg = 0;
for (int i = 0; i <= N; ++i) {
for (int j = i; j <= N; ++j) {
// cout << S.substr(0, i) + S.substr(j, N) << endl;
if (S.substr(0, i) + S.substr(j, N) == "keyence")
flg = 1;
}
}
YN(flg);
// cin >> N;
return 0;
} | [
"expression.operator.compare.change",
"control_flow.loop.for.condition.change",
"expression.off_by_one",
"expression.operation.binary.change",
"control_flow.loop.for.initializer.change",
"expression.operation.binary.remove"
] | 948,371 | 948,369 | u898651494 | cpp |
p03150 | // include
//------------------------------------------
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
// typedef
//------------------------------------------
typedef long long LL;
typedef vector<int> VI;
typedef vector<bool> VB;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef vector<VI> VVI;
typedef vector<VB> VVB;
typedef vector<VS> VVS;
typedef vector<VLL> VVLL;
typedef vector<VVI> VVVI;
typedef vector<VVLL> VVVLL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<int, string> PIS;
typedef pair<string, int> PSI;
typedef pair<string, string> PSS;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef vector<VPII> VVPII;
typedef vector<VPLL> VVPLL;
typedef vector<VS> VVS;
//数値・文字列
//------------------------------------------
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
inline LL toLongLong(string s) {
LL v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
inline VC toVC(string s) {
VC data(s.begin(), s.end());
return data;
}
template <typename List>
void SPRIT(const std::string &s, const std::string &delim, List &result) {
result.clear();
string::size_type pos = 0;
while (pos != string::npos) {
string::size_type p = s.find(delim, pos);
if (p == string::npos) {
result.push_back(s.substr(pos));
break;
} else {
result.push_back(s.substr(pos, p - pos));
}
pos = p + delim.size();
}
}
string TRIM(const string &str, const char *trimCharacterList = " \t\v\r\n") {
string result;
string::size_type left = str.find_first_not_of(trimCharacterList);
if (left != string::npos) {
string::size_type right = str.find_last_not_of(trimCharacterList);
result = str.substr(left, right - left + 1);
}
return result;
}
string REPLACE_STRING(const string source, const string find,
const string alt) {
string result = source;
string::size_type pos = 0;
while (pos = result.find(find, pos), pos != string::npos) {
result.replace(pos, find.length(), alt);
pos += alt.length();
}
return result;
}
template <typename T> bool VECTOR_EXISTS(vector<T> vec, T data) {
auto itr = std::find(vec.begin(), vec.end(), data);
size_t index = distance(vec.begin(), itr);
if (index != vec.size())
return true;
else
return false;
}
template <typename T> vector<T> VECTOR_UNIQUE_ERASE(vector<T> vec) {
sort(vec.begin(), vec.end());
vec.erase(unique(vec.begin(), vec.end()), vec.end());
return vec;
}
template <typename T> void VECTOR_REMOVE_VALUE_ALL(vector<T> &vec, T data) {
vec.erase(remove(vec.begin(), vec.end(), data), vec.end());
}
template <typename T>
vector<T> VECTOR_REMOVE_VALUE_ALL_FAST(vector<T> vec, T data) {
vector<T> vec2;
for (auto &x : vec)
if (x != data)
vec2.push_back(x);
return vec2;
}
bool REG_MATCH(string const &text, regex const &re) {
bool result = regex_match(text, re);
return result;
}
bool REG_MATCH(string const &text, smatch &match, regex const &re) {
bool result = regex_match(text, match, re);
return result;
}
smatch REG_SEARCH(string const &text, regex const &re) {
smatch m;
regex_search(text, m, re);
return m;
}
vector<smatch> REG_ALL_SEARCH(string const &text, regex const &re) {
vector<smatch> matchs;
sregex_iterator iter(text.cbegin(), text.cend(), re);
sregex_iterator end;
for (; iter != end; iter++)
matchs.push_back(*iter);
return matchs;
}
string REG_REPLACE(string const &text, regex const &re, string const &replace) {
string result =
regex_replace(text, re, replace, regex_constants::format_first_only);
return result;
}
string REG_ALL_REPLACE(string const &text, regex const &re,
string const &replace) {
string result = regex_replace(text, re, replace);
return result;
}
template <typename T, typename U, typename V, typename W>
auto operator+(const std::pair<T, U> &l, const std::pair<V, W> &r)
-> std::pair<decltype(l.first + r.first), decltype(l.second + r.second)> {
return {l.first + r.first, l.second + r.second};
}
template <typename T, typename U, typename V, typename W>
auto operator-(const std::pair<T, U> &l, const std::pair<V, W> &r)
-> std::pair<decltype(l.first - r.first), decltype(l.second - r.second)> {
return {l.first - r.first, l.second - r.second};
}
#define UPPER(s) transform((s).begin(), (s).end(), (s).begin(), ::toupper)
#define LOWER(s) transform((s).begin(), (s).end(), (s).begin(), ::tolower)
//四捨五入 nLen=小数点第n位にする
//------------------------------------------
//切り上げ
double ceil_n(double dIn, int nLen) {
double dOut;
dOut = dIn * pow(10.0, nLen);
dOut = (double)(int)(dOut + 0.9);
return dOut * pow(10.0, -nLen);
}
//切り捨て
double floor_n(double dIn, int nLen) {
double dOut;
dOut = dIn * pow(10.0, nLen);
dOut = (double)(int)(dOut);
return dOut * pow(10.0, -nLen);
}
//四捨五入
double round_n(double dIn, int nLen) {
double dOut;
dOut = dIn * pow(10.0, nLen);
dOut = (double)(int)(dOut + 0.5);
return dOut * pow(10.0, -nLen);
}
// n桁目の数の取得
int take_a_n(LL num, int n) {
string str = toString(num);
return str[str.length() - n] - '0';
}
//進数
//------------------------------------------
//"1111011" → 123
int strbase_2to10(const std::string &s) {
int out = 0;
for (int i = 0, size = s.size(); i < size; ++i) {
out *= 2;
out += ((int)s[i] == 49) ? 1 : 0;
}
return out;
}
//"123" → 1111011
int strbase_10to2(const std::string &s) {
int binary = toInt(s);
int out = 0;
for (int i = 0; binary > 0; i++) {
out = out + (binary % 2) * pow(static_cast<int>(10), i);
binary = binary / 2;
}
return out;
}
//"ABC" 2748
int strbase_16to10(const std::string &s) {
int out = stoi(s, 0, 16);
return out;
}
// 1111011 → 123
int intbase_2to10(int in) {
string str = toString(in);
return strbase_2to10(str);
}
// 123 → 1111011
int intbase_10to2(int in) {
string str = toString(in);
return strbase_10to2(str);
}
int intbase_16to10(int in) {
string str = toString(in);
return strbase_16to10(str);
}
// 123→ "7B"
string intbase_10to16(unsigned int val, bool lower = true) {
if (!val)
return std::string("0");
std::string str;
const char hc = lower ? 'a' : 'A'; // 小文字 or 大文字表記
while (val != 0) {
int d = val & 15; // 16進数一桁を取得
if (d < 10)
str.insert(str.begin(), d + '0'); // 10未満の場合
else // 10以上の場合
str.insert(str.begin(), d - 10 + hc);
val >>= 4;
}
return str;
}
//整数を2進数表記したときの1の個数を返す
LL bitcount64(LL bits) {
bits = (bits & 0x5555555555555555) + (bits >> 1 & 0x5555555555555555);
bits = (bits & 0x3333333333333333) + (bits >> 2 & 0x3333333333333333);
bits = (bits & 0x0f0f0f0f0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f0f0f0f0f);
bits = (bits & 0x00ff00ff00ff00ff) + (bits >> 8 & 0x00ff00ff00ff00ff);
bits = (bits & 0x0000ffff0000ffff) + (bits >> 16 & 0x0000ffff0000ffff);
return (bits & 0x00000000ffffffff) + (bits >> 32 & 0x00000000ffffffff);
}
// comparison
//------------------------------------------
#define C_MAX(a, b) ((a) > (b) ? (a) : (b))
#define C_MIN(a, b) ((a) < (b) ? (a) : (b))
#define C_ABS(a, b) ((a) < (b) ? (b) - (a) : (a) - (b))
template <typename T1, typename T2> inline void S_MAX(T1 &a, T2 b) {
a = C_MAX(a, b);
};
template <typename T1, typename T2> inline void S_MIN(T1 &a, T2 b) {
a = C_MIN(a, b);
};
// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define EACH(i, arr) \
for (typeof((arr).begin()) i = (arr).begin(); i != (arr).end(); ++i)
#define EXIST(str, e) ((str).find(e) != (str).end())
#define COUNT(arr, v) count((arr).begin(), (arr).end(), v)
#define SEARCH(v, w) search((v).begin(), (v).end(), (w).begin(), (w).end())
#define B_SEARCH(arr, v) binary_search((arr).begin(), (arr).end(), v)
#define SORT(c) sort((c).begin(), (c).end())
#define RSORT(c) sort((c).rbegin(), (c).rend())
#define REVERSE(c) reverse((c).begin(), (c).end())
#define ROTATE_LEFT(arr, c) \
rotate((arr).begin(), (arr).begin() + (c), (arr).end())
#define ROTATE_RIGHT(arr, c) \
rotate((arr).rbegin(), (arr).rbegin() + (c), (arr).rend())
#define SUMI(arr) accumulate((arr).begin(), (arr).end(), 0)
#define SUMD(arr) accumulate((arr).begin(), (arr).end(), 0.)
#define SUMLL(arr) accumulate((arr).begin(), (arr).end(), 0LL)
#define SUMS(arr) accumulate((arr).begin(), (arr).end(), string())
#define UB(arr, n) upper_bound((arr).begin(), (arr).end(), n)
#define LB(arr, n) lower_bound((arr).begin(), (arr).end(), n)
#define OF_ALL(arr, func) all_of((arr).begin(), (arr).end(), (func))
#define OF_NONE(arr, func) none_of((arr).begin(), (arr).end(), (func))
#define OF_ANY(arr, func) any_of((arr).begin(), (arr).end(), (func))
#define PB push_back
#define MP make_pair
// input output
//------------------------------------------
#define GL(s) getline(cin, (s))
#define INIT() \
std::ios::sync_with_stdio(false); \
std::cin.tie(0);
#define OUT(d) std::cout << (d)
#define OUT_L(d) std::cout << (d) << endl
#define FOUT(n, data) std::cout << std::fixed << std::setprecision(n) << (data)
#define FOUT_L(n, data) \
std::cout << std::fixed << std::setprecision(n) << (data) << "\n"
#define EL() printf("\n")
#define SHOW_VECTOR(v) \
{ \
std::cerr << #v << "\t:"; \
for (const auto &xxx : v) { \
std::cerr << xxx << " "; \
} \
std::cerr << "\n"; \
}
#define SHOW_MAP(v) \
{ \
std::cerr << #v << endl; \
for (const auto &xxx : v) { \
std::cerr << xxx.first << " " << xxx.second << "\n"; \
} \
}
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define YES() printf("YES\n")
#define NO() printf("NO\n")
template <typename T1, typename T2>
istream &operator>>(istream &in, pair<T1, T2> &p) {
in >> p.first >> p.second;
return in;
}
template <typename T> istream &operator>>(istream &in, vector<T> &v) {
for (auto &x : v)
in >> x;
return in;
}
// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)
#define FORLL(i, a, b) for (LL i = LL(a); i < LL(b); ++i)
#define RFORLL(i, a, b) for (LL i = LL(b) - 1; i >= LL(a); --i)
#define REPLL(i, n) for (LL i = 0; i < LL(n); ++i)
#define RREPLL(i, n) for (LL i = LL(n) - 1; i >= 0; --i)
#define FOREACH(x, arr) for (auto &(x) : (arr))
#define FORITER(x, arr) for (auto(x) = (arr).begin(); (x) != (arr).end(); ++(x))
// constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
// math
//--------------------------------------------
// min <= aim <= max
template <typename T>
inline bool BETWEEN(const T aim, const T min, const T max) {
if (min <= aim && aim <= max) {
return true;
} else {
return false;
}
}
template <class T> inline T SQR(const T x) { return x * x; }
template <class T1, class T2> inline T1 POW(const T1 x, const T2 y) {
if (!y)
return 1;
else if ((y & 1) == 0) {
return SQR(POW(x, y >> 1));
} else
return POW(x, y ^ 1) * x;
}
template <typename T> constexpr T ABS(T x) { return x < 0 ? -x : x; }
// partial_permutation nPr 順列
// first・・最初の数
// middle・・r(取り出す数)
// last・・n(全体数)
template <class Iter>
bool next_partial_permutation(Iter first, Iter middle, Iter last) {
reverse(middle, last);
return next_permutation(first, last);
}
// combination nCr 組み合わせ
// first1・・最初の数
// last1==first2・・r(取り出す数)
// last2・・n(全体数)
template <class Iter>
bool next_combination(Iter first1, Iter last1, Iter first2, Iter last2) {
if ((first1 == last1) || (first2 == last2)) {
return false;
}
Iter m1 = last1;
Iter m2 = last2;
--m2;
while (--m1 != first1 && !(*m1 < *m2)) {
}
bool result = (m1 == first1) && !(*first1 < *m2);
if (!result) {
while (first2 != m2 && !(*m1 < *first2)) {
++first2;
}
first1 = m1;
std::iter_swap(first1, first2);
++first1;
++first2;
}
if ((first1 != last1) && (first2 != last2)) {
m1 = last1;
m2 = first2;
while ((m1 != first1) && (m2 != last2)) {
std::iter_swap(--m1, m2);
++m2;
}
std::reverse(first1, m1);
std::reverse(first1, last1);
std::reverse(m2, last2);
std::reverse(first2, last2);
}
return !result;
}
// numeric_law
//--------------------------------------------
template <typename T> constexpr bool ODD(T x) { return x % 2 != 0; }
template <typename T> constexpr bool EVEN(T x) { return x % 2 == 0; }
//最大公約数
template <class T> inline T GCD(const T x, const T y) {
if (x < 0)
return GCD(-x, y);
if (y < 0)
return GCD(x, -y);
return (!y) ? x : GCD(y, x % y);
}
//最小公倍数
template <class T> inline T LCM(const T x, const T y) {
if (x < 0)
return LCM(-x, y);
if (y < 0)
return LCM(x, -y);
return x * (y / GCD(x, y));
}
// ax + by = 1
// x,yが変数に格納される
template <class T> inline T EXTGCD(const T a, const T b, T &x, T &y) {
if (a < 0) {
T d = EXTGCD(-a, b, x, y);
x = -x;
return d;
}
if (b < 0) {
T d = EXTGCD(a, -b, x, y);
y = -y;
return d;
}
if (!b) {
x = 1;
y = 0;
return a;
} else {
T d = EXTGCD(b, a % b, x, y);
T t = x;
x = y;
y = t - (a / b) * y;
return d;
}
}
//素数
template <class T> inline bool ISPRIME(const T x) {
if (x <= 1)
return false;
for (T i = 2; SQR(i) <= x; i++)
if (x % i == 0)
return false;
return true;
}
//素数をtrueとして返す
template <class T> VB ERATOSTHENES(const T n) {
VB arr(n, true);
for (int i = 2; SQR(i) < n; i++) {
if (arr[i]) {
for (int j = 0; i * (j + 2) < n; j++) {
arr[i * (j + 2)] = false;
}
}
}
return arr;
}
// a <= x < b の素数を返す
template <typename T> VB ERATOSTHENES(const T a, const T b) {
VB small = ERATOSTHENES(b);
VB prime(b - a, true);
for (int i = 2; (T)(SQR(i)) < b; i++) {
if (small[i]) {
for (T j = max(2, (a + i - 1) / i) * i; j < b; j += i) {
prime[j - a] = false;
}
}
}
return prime;
}
// nの約数
template <typename T> vector<T> DIVISOR(T n) {
vector<T> v;
for (LL i = 1; i * i <= n; ++i) {
if (n % i == 0) {
v.push_back(i);
if (i != n / i) {
v.push_back(n / i);
}
}
}
sort(v.begin(), v.end());
return v;
}
// nまでのすべての約数
template <typename T> vector<vector<T>> DIVISOR_ALL(T n) {
vector<vector<T>> res(n + 1);
for (int i = 1; i <= n; i++) {
for (int j = i; j <= n; j += i) {
res[j].push_back(i);
}
}
return res;
}
//素因数分解
template <typename T> vector<pair<T, LL>> FACTORIZATION(T x) {
vector<pair<T, LL>> ans;
for (T i = 2; i * i <= x; i++) {
if (x % i == 0) {
LL count = 0;
while (x % i == 0) {
count++;
x /= i;
}
ans.push_back(MP(i, count));
}
}
if (x != 1)
ans.push_back(MP(x, 1));
return ans;
}
// N^P (mod M)
LL POW_MOD(LL N, LL P, LL M) {
if (P == 0)
return 1LL;
if (P % 2 == 0) {
LL ret = POW_MOD(N, P / 2, M);
return ret * ret % M;
}
return N * POW_MOD(N, P - 1, M) % M;
}
//組み合わせ個数
template <typename T> inline T NCR(T n, T r) {
T ans = 1;
REPLL(i, r) { ans = ans * (n - i) / (i + 1); }
return ans;
}
//組み合わせ個数 (mod M)
LL NCR_MOD(LL n, LL r, LL M) {
if (r > n - r)
return NCR_MOD(n, n - r, M);
LL numerator = 1LL; //分子
LL denominator = 1LL; //分母
for (LL i = 0; i < r; i++) {
numerator *= (n - i);
numerator %= M;
denominator *= (i + 1);
denominator %= M;
}
return numerator * POW_MOD(denominator, M - 2, M) % M;
}
// confirmation
//--------------------------------------------
// clear memory
#define CLR(arr, d) memset((arr), (d), sizeof(arr))
// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) \
cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << endl;
/*
*
*
* ~~~~Below My Answer~~~~
*
*
*/
int main() {
string S;
cin >> S;
bool good = false;
if (S == "keyence")
good = true;
for (int i = 1; i < S.size(); i++) {
for (int j = 0; j < S.size(); j++) {
string t = S;
t.erase(t.begin() + j, t.begin() + j + i);
if (t == "keyence")
good = true;
}
}
if (good)
YES();
else
NO();
return 0;
}
| // include
//------------------------------------------
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
// typedef
//------------------------------------------
typedef long long LL;
typedef vector<int> VI;
typedef vector<bool> VB;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef vector<VI> VVI;
typedef vector<VB> VVB;
typedef vector<VS> VVS;
typedef vector<VLL> VVLL;
typedef vector<VVI> VVVI;
typedef vector<VVLL> VVVLL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<int, string> PIS;
typedef pair<string, int> PSI;
typedef pair<string, string> PSS;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef vector<VPII> VVPII;
typedef vector<VPLL> VVPLL;
typedef vector<VS> VVS;
//数値・文字列
//------------------------------------------
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
inline LL toLongLong(string s) {
LL v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
inline VC toVC(string s) {
VC data(s.begin(), s.end());
return data;
}
template <typename List>
void SPRIT(const std::string &s, const std::string &delim, List &result) {
result.clear();
string::size_type pos = 0;
while (pos != string::npos) {
string::size_type p = s.find(delim, pos);
if (p == string::npos) {
result.push_back(s.substr(pos));
break;
} else {
result.push_back(s.substr(pos, p - pos));
}
pos = p + delim.size();
}
}
string TRIM(const string &str, const char *trimCharacterList = " \t\v\r\n") {
string result;
string::size_type left = str.find_first_not_of(trimCharacterList);
if (left != string::npos) {
string::size_type right = str.find_last_not_of(trimCharacterList);
result = str.substr(left, right - left + 1);
}
return result;
}
string REPLACE_STRING(const string source, const string find,
const string alt) {
string result = source;
string::size_type pos = 0;
while (pos = result.find(find, pos), pos != string::npos) {
result.replace(pos, find.length(), alt);
pos += alt.length();
}
return result;
}
template <typename T> bool VECTOR_EXISTS(vector<T> vec, T data) {
auto itr = std::find(vec.begin(), vec.end(), data);
size_t index = distance(vec.begin(), itr);
if (index != vec.size())
return true;
else
return false;
}
template <typename T> vector<T> VECTOR_UNIQUE_ERASE(vector<T> vec) {
sort(vec.begin(), vec.end());
vec.erase(unique(vec.begin(), vec.end()), vec.end());
return vec;
}
template <typename T> void VECTOR_REMOVE_VALUE_ALL(vector<T> &vec, T data) {
vec.erase(remove(vec.begin(), vec.end(), data), vec.end());
}
template <typename T>
vector<T> VECTOR_REMOVE_VALUE_ALL_FAST(vector<T> vec, T data) {
vector<T> vec2;
for (auto &x : vec)
if (x != data)
vec2.push_back(x);
return vec2;
}
bool REG_MATCH(string const &text, regex const &re) {
bool result = regex_match(text, re);
return result;
}
bool REG_MATCH(string const &text, smatch &match, regex const &re) {
bool result = regex_match(text, match, re);
return result;
}
smatch REG_SEARCH(string const &text, regex const &re) {
smatch m;
regex_search(text, m, re);
return m;
}
vector<smatch> REG_ALL_SEARCH(string const &text, regex const &re) {
vector<smatch> matchs;
sregex_iterator iter(text.cbegin(), text.cend(), re);
sregex_iterator end;
for (; iter != end; iter++)
matchs.push_back(*iter);
return matchs;
}
string REG_REPLACE(string const &text, regex const &re, string const &replace) {
string result =
regex_replace(text, re, replace, regex_constants::format_first_only);
return result;
}
string REG_ALL_REPLACE(string const &text, regex const &re,
string const &replace) {
string result = regex_replace(text, re, replace);
return result;
}
template <typename T, typename U, typename V, typename W>
auto operator+(const std::pair<T, U> &l, const std::pair<V, W> &r)
-> std::pair<decltype(l.first + r.first), decltype(l.second + r.second)> {
return {l.first + r.first, l.second + r.second};
}
template <typename T, typename U, typename V, typename W>
auto operator-(const std::pair<T, U> &l, const std::pair<V, W> &r)
-> std::pair<decltype(l.first - r.first), decltype(l.second - r.second)> {
return {l.first - r.first, l.second - r.second};
}
#define UPPER(s) transform((s).begin(), (s).end(), (s).begin(), ::toupper)
#define LOWER(s) transform((s).begin(), (s).end(), (s).begin(), ::tolower)
//四捨五入 nLen=小数点第n位にする
//------------------------------------------
//切り上げ
double ceil_n(double dIn, int nLen) {
double dOut;
dOut = dIn * pow(10.0, nLen);
dOut = (double)(int)(dOut + 0.9);
return dOut * pow(10.0, -nLen);
}
//切り捨て
double floor_n(double dIn, int nLen) {
double dOut;
dOut = dIn * pow(10.0, nLen);
dOut = (double)(int)(dOut);
return dOut * pow(10.0, -nLen);
}
//四捨五入
double round_n(double dIn, int nLen) {
double dOut;
dOut = dIn * pow(10.0, nLen);
dOut = (double)(int)(dOut + 0.5);
return dOut * pow(10.0, -nLen);
}
// n桁目の数の取得
int take_a_n(LL num, int n) {
string str = toString(num);
return str[str.length() - n] - '0';
}
//進数
//------------------------------------------
//"1111011" → 123
int strbase_2to10(const std::string &s) {
int out = 0;
for (int i = 0, size = s.size(); i < size; ++i) {
out *= 2;
out += ((int)s[i] == 49) ? 1 : 0;
}
return out;
}
//"123" → 1111011
int strbase_10to2(const std::string &s) {
int binary = toInt(s);
int out = 0;
for (int i = 0; binary > 0; i++) {
out = out + (binary % 2) * pow(static_cast<int>(10), i);
binary = binary / 2;
}
return out;
}
//"ABC" 2748
int strbase_16to10(const std::string &s) {
int out = stoi(s, 0, 16);
return out;
}
// 1111011 → 123
int intbase_2to10(int in) {
string str = toString(in);
return strbase_2to10(str);
}
// 123 → 1111011
int intbase_10to2(int in) {
string str = toString(in);
return strbase_10to2(str);
}
int intbase_16to10(int in) {
string str = toString(in);
return strbase_16to10(str);
}
// 123→ "7B"
string intbase_10to16(unsigned int val, bool lower = true) {
if (!val)
return std::string("0");
std::string str;
const char hc = lower ? 'a' : 'A'; // 小文字 or 大文字表記
while (val != 0) {
int d = val & 15; // 16進数一桁を取得
if (d < 10)
str.insert(str.begin(), d + '0'); // 10未満の場合
else // 10以上の場合
str.insert(str.begin(), d - 10 + hc);
val >>= 4;
}
return str;
}
//整数を2進数表記したときの1の個数を返す
LL bitcount64(LL bits) {
bits = (bits & 0x5555555555555555) + (bits >> 1 & 0x5555555555555555);
bits = (bits & 0x3333333333333333) + (bits >> 2 & 0x3333333333333333);
bits = (bits & 0x0f0f0f0f0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f0f0f0f0f);
bits = (bits & 0x00ff00ff00ff00ff) + (bits >> 8 & 0x00ff00ff00ff00ff);
bits = (bits & 0x0000ffff0000ffff) + (bits >> 16 & 0x0000ffff0000ffff);
return (bits & 0x00000000ffffffff) + (bits >> 32 & 0x00000000ffffffff);
}
// comparison
//------------------------------------------
#define C_MAX(a, b) ((a) > (b) ? (a) : (b))
#define C_MIN(a, b) ((a) < (b) ? (a) : (b))
#define C_ABS(a, b) ((a) < (b) ? (b) - (a) : (a) - (b))
template <typename T1, typename T2> inline void S_MAX(T1 &a, T2 b) {
a = C_MAX(a, b);
};
template <typename T1, typename T2> inline void S_MIN(T1 &a, T2 b) {
a = C_MIN(a, b);
};
// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define EACH(i, arr) \
for (typeof((arr).begin()) i = (arr).begin(); i != (arr).end(); ++i)
#define EXIST(str, e) ((str).find(e) != (str).end())
#define COUNT(arr, v) count((arr).begin(), (arr).end(), v)
#define SEARCH(v, w) search((v).begin(), (v).end(), (w).begin(), (w).end())
#define B_SEARCH(arr, v) binary_search((arr).begin(), (arr).end(), v)
#define SORT(c) sort((c).begin(), (c).end())
#define RSORT(c) sort((c).rbegin(), (c).rend())
#define REVERSE(c) reverse((c).begin(), (c).end())
#define ROTATE_LEFT(arr, c) \
rotate((arr).begin(), (arr).begin() + (c), (arr).end())
#define ROTATE_RIGHT(arr, c) \
rotate((arr).rbegin(), (arr).rbegin() + (c), (arr).rend())
#define SUMI(arr) accumulate((arr).begin(), (arr).end(), 0)
#define SUMD(arr) accumulate((arr).begin(), (arr).end(), 0.)
#define SUMLL(arr) accumulate((arr).begin(), (arr).end(), 0LL)
#define SUMS(arr) accumulate((arr).begin(), (arr).end(), string())
#define UB(arr, n) upper_bound((arr).begin(), (arr).end(), n)
#define LB(arr, n) lower_bound((arr).begin(), (arr).end(), n)
#define OF_ALL(arr, func) all_of((arr).begin(), (arr).end(), (func))
#define OF_NONE(arr, func) none_of((arr).begin(), (arr).end(), (func))
#define OF_ANY(arr, func) any_of((arr).begin(), (arr).end(), (func))
#define PB push_back
#define MP make_pair
// input output
//------------------------------------------
#define GL(s) getline(cin, (s))
#define INIT() \
std::ios::sync_with_stdio(false); \
std::cin.tie(0);
#define OUT(d) std::cout << (d)
#define OUT_L(d) std::cout << (d) << endl
#define FOUT(n, data) std::cout << std::fixed << std::setprecision(n) << (data)
#define FOUT_L(n, data) \
std::cout << std::fixed << std::setprecision(n) << (data) << "\n"
#define EL() printf("\n")
#define SHOW_VECTOR(v) \
{ \
std::cerr << #v << "\t:"; \
for (const auto &xxx : v) { \
std::cerr << xxx << " "; \
} \
std::cerr << "\n"; \
}
#define SHOW_MAP(v) \
{ \
std::cerr << #v << endl; \
for (const auto &xxx : v) { \
std::cerr << xxx.first << " " << xxx.second << "\n"; \
} \
}
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define YES() printf("YES\n")
#define NO() printf("NO\n")
template <typename T1, typename T2>
istream &operator>>(istream &in, pair<T1, T2> &p) {
in >> p.first >> p.second;
return in;
}
template <typename T> istream &operator>>(istream &in, vector<T> &v) {
for (auto &x : v)
in >> x;
return in;
}
// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)
#define FORLL(i, a, b) for (LL i = LL(a); i < LL(b); ++i)
#define RFORLL(i, a, b) for (LL i = LL(b) - 1; i >= LL(a); --i)
#define REPLL(i, n) for (LL i = 0; i < LL(n); ++i)
#define RREPLL(i, n) for (LL i = LL(n) - 1; i >= 0; --i)
#define FOREACH(x, arr) for (auto &(x) : (arr))
#define FORITER(x, arr) for (auto(x) = (arr).begin(); (x) != (arr).end(); ++(x))
// constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
// math
//--------------------------------------------
// min <= aim <= max
template <typename T>
inline bool BETWEEN(const T aim, const T min, const T max) {
if (min <= aim && aim <= max) {
return true;
} else {
return false;
}
}
template <class T> inline T SQR(const T x) { return x * x; }
template <class T1, class T2> inline T1 POW(const T1 x, const T2 y) {
if (!y)
return 1;
else if ((y & 1) == 0) {
return SQR(POW(x, y >> 1));
} else
return POW(x, y ^ 1) * x;
}
template <typename T> constexpr T ABS(T x) { return x < 0 ? -x : x; }
// partial_permutation nPr 順列
// first・・最初の数
// middle・・r(取り出す数)
// last・・n(全体数)
template <class Iter>
bool next_partial_permutation(Iter first, Iter middle, Iter last) {
reverse(middle, last);
return next_permutation(first, last);
}
// combination nCr 組み合わせ
// first1・・最初の数
// last1==first2・・r(取り出す数)
// last2・・n(全体数)
template <class Iter>
bool next_combination(Iter first1, Iter last1, Iter first2, Iter last2) {
if ((first1 == last1) || (first2 == last2)) {
return false;
}
Iter m1 = last1;
Iter m2 = last2;
--m2;
while (--m1 != first1 && !(*m1 < *m2)) {
}
bool result = (m1 == first1) && !(*first1 < *m2);
if (!result) {
while (first2 != m2 && !(*m1 < *first2)) {
++first2;
}
first1 = m1;
std::iter_swap(first1, first2);
++first1;
++first2;
}
if ((first1 != last1) && (first2 != last2)) {
m1 = last1;
m2 = first2;
while ((m1 != first1) && (m2 != last2)) {
std::iter_swap(--m1, m2);
++m2;
}
std::reverse(first1, m1);
std::reverse(first1, last1);
std::reverse(m2, last2);
std::reverse(first2, last2);
}
return !result;
}
// numeric_law
//--------------------------------------------
template <typename T> constexpr bool ODD(T x) { return x % 2 != 0; }
template <typename T> constexpr bool EVEN(T x) { return x % 2 == 0; }
//最大公約数
template <class T> inline T GCD(const T x, const T y) {
if (x < 0)
return GCD(-x, y);
if (y < 0)
return GCD(x, -y);
return (!y) ? x : GCD(y, x % y);
}
//最小公倍数
template <class T> inline T LCM(const T x, const T y) {
if (x < 0)
return LCM(-x, y);
if (y < 0)
return LCM(x, -y);
return x * (y / GCD(x, y));
}
// ax + by = 1
// x,yが変数に格納される
template <class T> inline T EXTGCD(const T a, const T b, T &x, T &y) {
if (a < 0) {
T d = EXTGCD(-a, b, x, y);
x = -x;
return d;
}
if (b < 0) {
T d = EXTGCD(a, -b, x, y);
y = -y;
return d;
}
if (!b) {
x = 1;
y = 0;
return a;
} else {
T d = EXTGCD(b, a % b, x, y);
T t = x;
x = y;
y = t - (a / b) * y;
return d;
}
}
//素数
template <class T> inline bool ISPRIME(const T x) {
if (x <= 1)
return false;
for (T i = 2; SQR(i) <= x; i++)
if (x % i == 0)
return false;
return true;
}
//素数をtrueとして返す
template <class T> VB ERATOSTHENES(const T n) {
VB arr(n, true);
for (int i = 2; SQR(i) < n; i++) {
if (arr[i]) {
for (int j = 0; i * (j + 2) < n; j++) {
arr[i * (j + 2)] = false;
}
}
}
return arr;
}
// a <= x < b の素数を返す
template <typename T> VB ERATOSTHENES(const T a, const T b) {
VB small = ERATOSTHENES(b);
VB prime(b - a, true);
for (int i = 2; (T)(SQR(i)) < b; i++) {
if (small[i]) {
for (T j = max(2, (a + i - 1) / i) * i; j < b; j += i) {
prime[j - a] = false;
}
}
}
return prime;
}
// nの約数
template <typename T> vector<T> DIVISOR(T n) {
vector<T> v;
for (LL i = 1; i * i <= n; ++i) {
if (n % i == 0) {
v.push_back(i);
if (i != n / i) {
v.push_back(n / i);
}
}
}
sort(v.begin(), v.end());
return v;
}
// nまでのすべての約数
template <typename T> vector<vector<T>> DIVISOR_ALL(T n) {
vector<vector<T>> res(n + 1);
for (int i = 1; i <= n; i++) {
for (int j = i; j <= n; j += i) {
res[j].push_back(i);
}
}
return res;
}
//素因数分解
template <typename T> vector<pair<T, LL>> FACTORIZATION(T x) {
vector<pair<T, LL>> ans;
for (T i = 2; i * i <= x; i++) {
if (x % i == 0) {
LL count = 0;
while (x % i == 0) {
count++;
x /= i;
}
ans.push_back(MP(i, count));
}
}
if (x != 1)
ans.push_back(MP(x, 1));
return ans;
}
// N^P (mod M)
LL POW_MOD(LL N, LL P, LL M) {
if (P == 0)
return 1LL;
if (P % 2 == 0) {
LL ret = POW_MOD(N, P / 2, M);
return ret * ret % M;
}
return N * POW_MOD(N, P - 1, M) % M;
}
//組み合わせ個数
template <typename T> inline T NCR(T n, T r) {
T ans = 1;
REPLL(i, r) { ans = ans * (n - i) / (i + 1); }
return ans;
}
//組み合わせ個数 (mod M)
LL NCR_MOD(LL n, LL r, LL M) {
if (r > n - r)
return NCR_MOD(n, n - r, M);
LL numerator = 1LL; //分子
LL denominator = 1LL; //分母
for (LL i = 0; i < r; i++) {
numerator *= (n - i);
numerator %= M;
denominator *= (i + 1);
denominator %= M;
}
return numerator * POW_MOD(denominator, M - 2, M) % M;
}
// confirmation
//--------------------------------------------
// clear memory
#define CLR(arr, d) memset((arr), (d), sizeof(arr))
// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) \
cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << endl;
/*
*
*
* ~~~~Below My Answer~~~~
*
*
*/
int main() {
string S;
cin >> S;
bool good = false;
if (S == "keyence")
good = true;
for (int i = 1; i < S.size(); i++) {
for (int j = 0; j < S.size() - i + 1; j++) {
string t = S;
t.erase(t.begin() + j, t.begin() + j + i);
if (t == "keyence")
good = true;
}
}
if (good)
YES();
else
NO();
return 0;
}
| [
"control_flow.loop.for.condition.change"
] | 948,374 | 948,375 | u259053514 | cpp |
p03150 | #include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;
int main() {
string s, t = "keyence";
cin >> s;
for (int i = 0; i < s.size(); i++) {
for (int j = i; j < s.size(); j++) {
string ss = "";
for (int k = 0; k < s.size(); k++) {
if (!(i <= k && k <= j))
ss += s[k];
}
if (ss == t) {
cout << "YES" << endl;
return 0;
}
}
}
cout << "NO" << endl;
} | #include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;
int main() {
string s, t = "keyence";
cin >> s;
for (int i = 0; i < s.size(); i++) {
for (int j = i; j <= s.size(); j++) {
string ss = "";
for (int k = 0; k < s.size(); k++) {
if (!(i <= k && k < j))
ss += s[k];
}
if (ss == t) {
cout << "YES" << endl;
return 0;
}
}
}
cout << "NO" << endl;
} | [
"expression.operator.compare.change",
"control_flow.loop.for.condition.change",
"expression.off_by_one",
"expression.operation.binary.change",
"control_flow.branch.if.condition.change"
] | 948,390 | 948,391 | u210718367 | cpp |
p03151 | #include <algorithm>
#include <iostream>
#include <map>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
int N;
cin >> N;
int A[N], B[N];
rep(i, N) cin >> A[i];
rep(i, N) cin >> B[i];
// 入力終了
// 現在の準備と必要な準備度の差分
int sub[N];
rep(i, N) sub[i] = A[i] - B[i];
sort(sub, sub + N);
int ans = 0;
// 足りない準備度の和 (マイナスだったら足せばOK)
int sum = 0;
rep(i, N) {
// 準備度が足りない
if (sub[i] < 0) {
sum += sub[i];
// 準備度が足りないなら変更しないといけない
ans++;
}
// 準備度が足りてるならそれ以降は見なくてOK
else
break;
}
// 正のほうが計算しやすい
sum = -sum;
// 余剰の準備度から分配していく
for (int i = N - 1; i >= 0; i--) {
// 分配し終わった
if (sum <= 0)
break;
// 途中でsub[i]<0になったら100%ムリ
if (sub[i] < 0) {
cout << -2 << endl;
return 0;
}
// 余剰分を引いていく
sum -= sub[i];
ans++;
}
// 解答
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <iostream>
#include <map>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
int N;
cin >> N;
int A[N], B[N];
rep(i, N) cin >> A[i];
rep(i, N) cin >> B[i];
// 入力終了
// 現在の準備と必要な準備度の差分
int sub[N];
rep(i, N) sub[i] = A[i] - B[i];
sort(sub, sub + N);
int ans = 0;
// 足りない準備度の和 (マイナスだったら足せばOK)
long long sum = 0;
rep(i, N) {
// 準備度が足りない
if (sub[i] < 0) {
sum += sub[i];
// 準備度が足りないなら変更しないといけない
ans++;
}
// 準備度が足りてるならそれ以降は見なくてOK
else
break;
}
// 正のほうが計算しやすい
sum = -sum;
// 余剰の準備度から分配していく
for (int i = N - 1; i >= 0; i--) {
// 分配し終わった
if (sum <= 0)
break;
// 途中でsub[i]<0になったら100%ムリ
if (sub[i] < 0) {
cout << -1 << endl;
return 0;
}
// 余剰分を引いていく
sum -= sub[i];
ans++;
}
// 解答
cout << ans << endl;
return 0;
}
| [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change",
"literal.number.change",
"io.output.change"
] | 948,394 | 948,393 | u537852947 | cpp |
p03151 | #include <bits/stdc++.h>
using namespace std;
// long long
using ll = long long;
// pair<int, int>
using PII = pair<int, int>;
//最大値、mod
const int MOD = 1000000007;
const int mod = 1000000007;
const int INF = 1000000000;
const long long LINF = 1e18;
const int MAX = 510000;
//出力系
#define print(x) cout << x << endl
#define prints(x) cout << fixed << setprecision(20) << x << endl
#define printc(x) cout << setw(2) << setfill('0') << x << endl;
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
//配列入力
vector<long long> vecin(ll n) {
vector<long long> res(n);
for (int i = 0; i < n; i++)
cin >> res[i];
return res;
}
// begin() end()
#define all(x) (x).begin(), (x).end()
// for
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rrep(i, a, b) for (int i = (a); i > (b); i--)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
//最大公約数
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
// 最小公倍数
unsigned lcm(unsigned a, unsigned b) { return a / gcd(a, b) * b; }
// a = max(a, b), a = min(a, b)
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
// num ^ pow(mod取る)
ll pow_mod(ll num, ll pow, ll mod) {
ll prod = 1;
num %= mod;
while (pow > 0) {
if (pow & 1)
prod = prod * num % mod;
num = num * num % mod;
pow >>= 1;
}
return prod;
}
// 二項係数(MODとる、1 ≦ k ≦ n ≦ 10^7 程度)
// COMinit()
// COM(x, y)
// とコンビで使う
// テーブルを作る前処理
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
//重みつきUnionFInd
template <class Abel> struct GUnionFind {
vector<int> par;
vector<int> rank;
vector<Abel> diff_weight;
GUnionFind(int n = 1, Abel SUM_UNITY = 0) { init(n, SUM_UNITY); }
void init(int n = 1, Abel SUM_UNITY = 0) {
par.resize(n);
rank.resize(n);
diff_weight.resize(n);
for (int i = 0; i < n; ++i)
par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
}
int root(int x) {
if (par[x] == x) {
return x;
} else {
int r = root(par[x]);
diff_weight[x] += diff_weight[par[x]];
return par[x] = r;
}
}
Abel weight(int x) {
root(x);
return diff_weight[x];
}
bool issame(int x, int y) { return root(x) == root(y); }
bool merge(int x, int y, Abel w) {
w += weight(x);
w -= weight(y);
x = root(x);
y = root(y);
if (x == y)
return false;
if (rank[x] < rank[y])
swap(x, y), w = -w;
if (rank[x] == rank[y])
++rank[x];
par[y] = x;
diff_weight[y] = w;
return true;
}
Abel diff(int x, int y) { return weight(y) - weight(x); }
};
// UnionFind
struct UnionFind {
vector<int> par;
vector<int> rank;
vector<ll> Size;
UnionFind(int n = 1) { init(n); }
void init(int n = 1) {
par.resize(n + 1);
rank.resize(n + 1);
Size.resize(n + 1);
for (int i = 0; i <= n; ++i)
par[i] = i, rank[i] = 0, Size[i] = 1;
}
int root(int x) {
if (par[x] == x) {
return x;
} else {
int r = root(par[x]);
return par[x] = r;
}
}
bool issame(int x, int y) { return root(x) == root(y); }
bool merge(int x, int y) {
x = root(x);
y = root(y);
if (x == y)
return false;
if (rank[x] < rank[y])
swap(x, y);
if (rank[x] == rank[y])
++rank[x];
par[y] = x;
Size[x] += Size[y];
return true;
}
ll size(int x) { return Size[root(x)]; }
};
// modint構造体
struct Mint {
int val;
Mint inv() const {
int tmp, a = val, b = mod, x = 1, y = 0;
while (b)
tmp = a / b, a -= tmp * b, swap(a, b), x -= tmp * y, swap(x, y);
return Mint(x);
}
public:
Mint() : val(0) {}
Mint(ll x) {
if ((val = x % mod) < 0)
val += mod;
}
Mint pow(ll t) {
Mint res = 1, b = *this;
while (t) {
if (t & 1)
res *= b;
b *= b;
t >>= 1;
}
return res;
}
Mint &operator+=(const Mint &x) {
if ((val += x.val) >= mod)
val -= mod;
return *this;
}
Mint &operator-=(const Mint &x) {
if ((val += mod - x.val) >= mod)
val -= mod;
return *this;
}
Mint &operator*=(const Mint &x) {
val = (ll)val * x.val % mod;
return *this;
}
Mint &operator/=(const Mint &x) { return *this *= x.inv(); }
bool operator==(const Mint &x) const { return val == x.val; }
bool operator!=(const Mint &x) const { return val != x.val; }
bool operator<(const Mint &x) const { return val < x.val; }
bool operator<=(const Mint &x) const { return val <= x.val; }
bool operator>(const Mint &x) const { return val > x.val; }
bool operator>=(const Mint &x) const { return val >= x.val; }
Mint operator+(const Mint &x) const { return Mint(*this) += x; }
Mint operator-(const Mint &x) const { return Mint(*this) -= x; }
Mint operator*(const Mint &x) const { return Mint(*this) *= x; }
Mint operator/(const Mint &x) const { return Mint(*this) /= x; }
};
struct factorial {
vector<Mint> Fact, Finv;
public:
// factorial fact(10000010);
// fact.nCr(a, b)
//「fact」の部分は自由に名前変更可能
factorial(int maxx) {
Fact.resize(maxx + 1), Finv.resize(maxx + 1);
Fact[0] = Mint(1);
rep(i, 0, maxx) Fact[i + 1] = Fact[i] * (i + 1);
Finv[maxx] = Mint(1) / Fact[maxx];
rrep(i, maxx, 0) Finv[i - 1] = Finv[i] * i;
}
Mint fact(int n, bool inv = 0) {
if (inv)
return Finv[n];
else
return Fact[n];
}
Mint nPr(int n, int r) {
if (n < 0 || n < r || r < 0)
return Mint(0);
else
return Fact[n] * Finv[n - r];
}
Mint nCr(int n, int r) {
if (n < 0 || n < r || r < 0)
return Mint(0);
else
return Fact[n] * Finv[r] * Finv[n - r];
}
};
// 1 * 2 * 3 .... * n (mod)
ll modfact(ll n) {
if (n <= 1)
return 1;
return (n * modfact(n - 1)) % MOD;
}
// kが角度だった場合:cos(k * (PI / 180));
// const double PI = acos(-1);のまま使うと円周率(M_PIもあるよ)
const double PI = acos(-1);
// 多次元 vector 生成 例: auto dp = make_vec<long long>(N+1, 5, 5, 5);
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
//素因数分解
vector<pair<long long, int>> factorize(long long n) {
vector<pair<long long, int>> res;
for (long long i = 2; i * i <= n; ++i) {
if (n % i)
continue;
res.emplace_back(i, 0);
while (n % i == 0) {
n /= i;
res.back().second++;
}
}
if (n != 1)
res.emplace_back(n, 1);
return res;
}
// 素数判定
bool primejudge(long long a) {
if (a <= 1)
return false;
for (long long i = 2; i * i <= a; i++) {
if (a % i == 0)
return false;
}
return true;
}
// 累積和
// vector<long long>sums(vector<int>n){
// vector<long long>res(n.size() + 1, 0);
// for(int i = 0; i < n.size(); i++) res[i + 1] = n[i] + res[i];
// return res;
// }
int dy[4] = {0, 1, 0, -1}, dx[4] = {1, 0, -1, 0};
vector<vector<int>> graph;
int main() {
int n;
cin >> n;
vector<ll> a(n);
vector<ll> b(n);
REP(i, n) cin >> a[i];
REP(i, n) cin >> b[i];
int sum = 0;
int ans = 0;
vector<ll> d;
REP(i, n) {
if (b[i] > a[i])
sum += b[i] - a[i], ans++;
else if (b[i] < a[i])
d.push_back(a[i] - b[i]);
}
sort(all(d));
reverse(all(d));
REP(i, d.size()) {
if (sum > 0)
ans++;
sum -= d[i];
}
sum <= 0 ? print(ans) : print(-1);
}
| #include <bits/stdc++.h>
using namespace std;
// long long
using ll = long long;
// pair<int, int>
using PII = pair<int, int>;
//最大値、mod
const int MOD = 1000000007;
const int mod = 1000000007;
const int INF = 1000000000;
const long long LINF = 1e18;
const int MAX = 510000;
//出力系
#define print(x) cout << x << endl
#define prints(x) cout << fixed << setprecision(20) << x << endl
#define printc(x) cout << setw(2) << setfill('0') << x << endl;
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
//配列入力
vector<long long> vecin(ll n) {
vector<long long> res(n);
for (int i = 0; i < n; i++)
cin >> res[i];
return res;
}
// begin() end()
#define all(x) (x).begin(), (x).end()
// for
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rrep(i, a, b) for (int i = (a); i > (b); i--)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
//最大公約数
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
// 最小公倍数
unsigned lcm(unsigned a, unsigned b) { return a / gcd(a, b) * b; }
// a = max(a, b), a = min(a, b)
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
// num ^ pow(mod取る)
ll pow_mod(ll num, ll pow, ll mod) {
ll prod = 1;
num %= mod;
while (pow > 0) {
if (pow & 1)
prod = prod * num % mod;
num = num * num % mod;
pow >>= 1;
}
return prod;
}
// 二項係数(MODとる、1 ≦ k ≦ n ≦ 10^7 程度)
// COMinit()
// COM(x, y)
// とコンビで使う
// テーブルを作る前処理
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
//重みつきUnionFInd
template <class Abel> struct GUnionFind {
vector<int> par;
vector<int> rank;
vector<Abel> diff_weight;
GUnionFind(int n = 1, Abel SUM_UNITY = 0) { init(n, SUM_UNITY); }
void init(int n = 1, Abel SUM_UNITY = 0) {
par.resize(n);
rank.resize(n);
diff_weight.resize(n);
for (int i = 0; i < n; ++i)
par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
}
int root(int x) {
if (par[x] == x) {
return x;
} else {
int r = root(par[x]);
diff_weight[x] += diff_weight[par[x]];
return par[x] = r;
}
}
Abel weight(int x) {
root(x);
return diff_weight[x];
}
bool issame(int x, int y) { return root(x) == root(y); }
bool merge(int x, int y, Abel w) {
w += weight(x);
w -= weight(y);
x = root(x);
y = root(y);
if (x == y)
return false;
if (rank[x] < rank[y])
swap(x, y), w = -w;
if (rank[x] == rank[y])
++rank[x];
par[y] = x;
diff_weight[y] = w;
return true;
}
Abel diff(int x, int y) { return weight(y) - weight(x); }
};
// UnionFind
struct UnionFind {
vector<int> par;
vector<int> rank;
vector<ll> Size;
UnionFind(int n = 1) { init(n); }
void init(int n = 1) {
par.resize(n + 1);
rank.resize(n + 1);
Size.resize(n + 1);
for (int i = 0; i <= n; ++i)
par[i] = i, rank[i] = 0, Size[i] = 1;
}
int root(int x) {
if (par[x] == x) {
return x;
} else {
int r = root(par[x]);
return par[x] = r;
}
}
bool issame(int x, int y) { return root(x) == root(y); }
bool merge(int x, int y) {
x = root(x);
y = root(y);
if (x == y)
return false;
if (rank[x] < rank[y])
swap(x, y);
if (rank[x] == rank[y])
++rank[x];
par[y] = x;
Size[x] += Size[y];
return true;
}
ll size(int x) { return Size[root(x)]; }
};
// modint構造体
struct Mint {
int val;
Mint inv() const {
int tmp, a = val, b = mod, x = 1, y = 0;
while (b)
tmp = a / b, a -= tmp * b, swap(a, b), x -= tmp * y, swap(x, y);
return Mint(x);
}
public:
Mint() : val(0) {}
Mint(ll x) {
if ((val = x % mod) < 0)
val += mod;
}
Mint pow(ll t) {
Mint res = 1, b = *this;
while (t) {
if (t & 1)
res *= b;
b *= b;
t >>= 1;
}
return res;
}
Mint &operator+=(const Mint &x) {
if ((val += x.val) >= mod)
val -= mod;
return *this;
}
Mint &operator-=(const Mint &x) {
if ((val += mod - x.val) >= mod)
val -= mod;
return *this;
}
Mint &operator*=(const Mint &x) {
val = (ll)val * x.val % mod;
return *this;
}
Mint &operator/=(const Mint &x) { return *this *= x.inv(); }
bool operator==(const Mint &x) const { return val == x.val; }
bool operator!=(const Mint &x) const { return val != x.val; }
bool operator<(const Mint &x) const { return val < x.val; }
bool operator<=(const Mint &x) const { return val <= x.val; }
bool operator>(const Mint &x) const { return val > x.val; }
bool operator>=(const Mint &x) const { return val >= x.val; }
Mint operator+(const Mint &x) const { return Mint(*this) += x; }
Mint operator-(const Mint &x) const { return Mint(*this) -= x; }
Mint operator*(const Mint &x) const { return Mint(*this) *= x; }
Mint operator/(const Mint &x) const { return Mint(*this) /= x; }
};
struct factorial {
vector<Mint> Fact, Finv;
public:
// factorial fact(10000010);
// fact.nCr(a, b)
//「fact」の部分は自由に名前変更可能
factorial(int maxx) {
Fact.resize(maxx + 1), Finv.resize(maxx + 1);
Fact[0] = Mint(1);
rep(i, 0, maxx) Fact[i + 1] = Fact[i] * (i + 1);
Finv[maxx] = Mint(1) / Fact[maxx];
rrep(i, maxx, 0) Finv[i - 1] = Finv[i] * i;
}
Mint fact(int n, bool inv = 0) {
if (inv)
return Finv[n];
else
return Fact[n];
}
Mint nPr(int n, int r) {
if (n < 0 || n < r || r < 0)
return Mint(0);
else
return Fact[n] * Finv[n - r];
}
Mint nCr(int n, int r) {
if (n < 0 || n < r || r < 0)
return Mint(0);
else
return Fact[n] * Finv[r] * Finv[n - r];
}
};
// 1 * 2 * 3 .... * n (mod)
ll modfact(ll n) {
if (n <= 1)
return 1;
return (n * modfact(n - 1)) % MOD;
}
// kが角度だった場合:cos(k * (PI / 180));
// const double PI = acos(-1);のまま使うと円周率(M_PIもあるよ)
const double PI = acos(-1);
// 多次元 vector 生成 例: auto dp = make_vec<long long>(N+1, 5, 5, 5);
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
//素因数分解
vector<pair<long long, int>> factorize(long long n) {
vector<pair<long long, int>> res;
for (long long i = 2; i * i <= n; ++i) {
if (n % i)
continue;
res.emplace_back(i, 0);
while (n % i == 0) {
n /= i;
res.back().second++;
}
}
if (n != 1)
res.emplace_back(n, 1);
return res;
}
// 素数判定
bool primejudge(long long a) {
if (a <= 1)
return false;
for (long long i = 2; i * i <= a; i++) {
if (a % i == 0)
return false;
}
return true;
}
// 累積和
// vector<long long>sums(vector<int>n){
// vector<long long>res(n.size() + 1, 0);
// for(int i = 0; i < n.size(); i++) res[i + 1] = n[i] + res[i];
// return res;
// }
int dy[4] = {0, 1, 0, -1}, dx[4] = {1, 0, -1, 0};
vector<vector<int>> graph;
int main() {
int n;
cin >> n;
vector<ll> a(n);
vector<ll> b(n);
REP(i, n) cin >> a[i];
REP(i, n) cin >> b[i];
ll sum = 0;
ll ans = 0;
vector<ll> d;
REP(i, n) {
if (b[i] > a[i])
sum += b[i] - a[i], ans++;
else if (b[i] < a[i])
d.push_back(a[i] - b[i]);
}
sort(all(d));
reverse(all(d));
REP(i, d.size()) {
if (sum > 0)
ans++;
sum -= d[i];
}
sum <= 0 ? print(ans) : print(-1);
}
| [
"variable_declaration.type.change"
] | 948,414 | 948,415 | u832995587 | cpp |
p03151 | #include <bits/stdc++.h>
using namespace std;
// long long
using ll = long long;
// pair<int, int>
using PII = pair<int, int>;
//最大値、mod
const int MOD = 1000000007;
const int mod = 1000000007;
const int INF = 1000000000;
const long long LINF = 1e18;
const int MAX = 510000;
//出力系
#define print(x) cout << x << endl
#define prints(x) cout << fixed << setprecision(20) << x << endl
#define printc(x) cout << setw(2) << setfill('0') << x << endl;
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
//配列入力
vector<long long> vecin(ll n) {
vector<long long> res(n);
for (int i = 0; i < n; i++)
cin >> res[i];
return res;
}
// begin() end()
#define all(x) (x).begin(), (x).end()
// for
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rrep(i, a, b) for (int i = (a); i > (b); i--)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
//最大公約数
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
// 最小公倍数
unsigned lcm(unsigned a, unsigned b) { return a / gcd(a, b) * b; }
// a = max(a, b), a = min(a, b)
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
// num ^ pow(mod取る)
ll pow_mod(ll num, ll pow, ll mod) {
ll prod = 1;
num %= mod;
while (pow > 0) {
if (pow & 1)
prod = prod * num % mod;
num = num * num % mod;
pow >>= 1;
}
return prod;
}
// 二項係数(MODとる、1 ≦ k ≦ n ≦ 10^7 程度)
// COMinit()
// COM(x, y)
// とコンビで使う
// テーブルを作る前処理
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
//重みつきUnionFInd
template <class Abel> struct GUnionFind {
vector<int> par;
vector<int> rank;
vector<Abel> diff_weight;
GUnionFind(int n = 1, Abel SUM_UNITY = 0) { init(n, SUM_UNITY); }
void init(int n = 1, Abel SUM_UNITY = 0) {
par.resize(n);
rank.resize(n);
diff_weight.resize(n);
for (int i = 0; i < n; ++i)
par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
}
int root(int x) {
if (par[x] == x) {
return x;
} else {
int r = root(par[x]);
diff_weight[x] += diff_weight[par[x]];
return par[x] = r;
}
}
Abel weight(int x) {
root(x);
return diff_weight[x];
}
bool issame(int x, int y) { return root(x) == root(y); }
bool merge(int x, int y, Abel w) {
w += weight(x);
w -= weight(y);
x = root(x);
y = root(y);
if (x == y)
return false;
if (rank[x] < rank[y])
swap(x, y), w = -w;
if (rank[x] == rank[y])
++rank[x];
par[y] = x;
diff_weight[y] = w;
return true;
}
Abel diff(int x, int y) { return weight(y) - weight(x); }
};
// UnionFind
struct UnionFind {
vector<int> par;
vector<int> rank;
vector<ll> Size;
UnionFind(int n = 1) { init(n); }
void init(int n = 1) {
par.resize(n + 1);
rank.resize(n + 1);
Size.resize(n + 1);
for (int i = 0; i <= n; ++i)
par[i] = i, rank[i] = 0, Size[i] = 1;
}
int root(int x) {
if (par[x] == x) {
return x;
} else {
int r = root(par[x]);
return par[x] = r;
}
}
bool issame(int x, int y) { return root(x) == root(y); }
bool merge(int x, int y) {
x = root(x);
y = root(y);
if (x == y)
return false;
if (rank[x] < rank[y])
swap(x, y);
if (rank[x] == rank[y])
++rank[x];
par[y] = x;
Size[x] += Size[y];
return true;
}
ll size(int x) { return Size[root(x)]; }
};
// modint構造体
struct Mint {
int val;
Mint inv() const {
int tmp, a = val, b = mod, x = 1, y = 0;
while (b)
tmp = a / b, a -= tmp * b, swap(a, b), x -= tmp * y, swap(x, y);
return Mint(x);
}
public:
Mint() : val(0) {}
Mint(ll x) {
if ((val = x % mod) < 0)
val += mod;
}
Mint pow(ll t) {
Mint res = 1, b = *this;
while (t) {
if (t & 1)
res *= b;
b *= b;
t >>= 1;
}
return res;
}
Mint &operator+=(const Mint &x) {
if ((val += x.val) >= mod)
val -= mod;
return *this;
}
Mint &operator-=(const Mint &x) {
if ((val += mod - x.val) >= mod)
val -= mod;
return *this;
}
Mint &operator*=(const Mint &x) {
val = (ll)val * x.val % mod;
return *this;
}
Mint &operator/=(const Mint &x) { return *this *= x.inv(); }
bool operator==(const Mint &x) const { return val == x.val; }
bool operator!=(const Mint &x) const { return val != x.val; }
bool operator<(const Mint &x) const { return val < x.val; }
bool operator<=(const Mint &x) const { return val <= x.val; }
bool operator>(const Mint &x) const { return val > x.val; }
bool operator>=(const Mint &x) const { return val >= x.val; }
Mint operator+(const Mint &x) const { return Mint(*this) += x; }
Mint operator-(const Mint &x) const { return Mint(*this) -= x; }
Mint operator*(const Mint &x) const { return Mint(*this) *= x; }
Mint operator/(const Mint &x) const { return Mint(*this) /= x; }
};
struct factorial {
vector<Mint> Fact, Finv;
public:
// factorial fact(10000010);
// fact.nCr(a, b)
//「fact」の部分は自由に名前変更可能
factorial(int maxx) {
Fact.resize(maxx + 1), Finv.resize(maxx + 1);
Fact[0] = Mint(1);
rep(i, 0, maxx) Fact[i + 1] = Fact[i] * (i + 1);
Finv[maxx] = Mint(1) / Fact[maxx];
rrep(i, maxx, 0) Finv[i - 1] = Finv[i] * i;
}
Mint fact(int n, bool inv = 0) {
if (inv)
return Finv[n];
else
return Fact[n];
}
Mint nPr(int n, int r) {
if (n < 0 || n < r || r < 0)
return Mint(0);
else
return Fact[n] * Finv[n - r];
}
Mint nCr(int n, int r) {
if (n < 0 || n < r || r < 0)
return Mint(0);
else
return Fact[n] * Finv[r] * Finv[n - r];
}
};
// 1 * 2 * 3 .... * n (mod)
ll modfact(ll n) {
if (n <= 1)
return 1;
return (n * modfact(n - 1)) % MOD;
}
// kが角度だった場合:cos(k * (PI / 180));
// const double PI = acos(-1);のまま使うと円周率(M_PIもあるよ)
const double PI = acos(-1);
// 多次元 vector 生成 例: auto dp = make_vec<long long>(N+1, 5, 5, 5);
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
//素因数分解
vector<pair<long long, int>> factorize(long long n) {
vector<pair<long long, int>> res;
for (long long i = 2; i * i <= n; ++i) {
if (n % i)
continue;
res.emplace_back(i, 0);
while (n % i == 0) {
n /= i;
res.back().second++;
}
}
if (n != 1)
res.emplace_back(n, 1);
return res;
}
// 素数判定
bool primejudge(long long a) {
if (a <= 1)
return false;
for (long long i = 2; i * i <= a; i++) {
if (a % i == 0)
return false;
}
return true;
}
// 累積和
// vector<long long>sums(vector<int>n){
// vector<long long>res(n.size() + 1, 0);
// for(int i = 0; i < n.size(); i++) res[i + 1] = n[i] + res[i];
// return res;
// }
int dy[4] = {0, 1, 0, -1}, dx[4] = {1, 0, -1, 0};
vector<vector<int>> graph;
int main() {
int n;
cin >> n;
vector<int> a(n);
vector<int> b(n);
REP(i, n) cin >> a[i];
REP(i, n) cin >> b[i];
int sum = 0;
int ans = 0;
vector<int> d;
REP(i, n) {
if (b[i] > a[i])
sum += b[i] - a[i], ans++;
else if (b[i] < a[i])
d.push_back(a[i] - b[i]);
}
sort(all(d));
reverse(all(d));
REP(i, d.size()) {
if (sum > 0)
ans++;
sum -= d[i];
}
sum <= 0 ? print(ans) : print(-1);
}
| #include <bits/stdc++.h>
using namespace std;
// long long
using ll = long long;
// pair<int, int>
using PII = pair<int, int>;
//最大値、mod
const int MOD = 1000000007;
const int mod = 1000000007;
const int INF = 1000000000;
const long long LINF = 1e18;
const int MAX = 510000;
//出力系
#define print(x) cout << x << endl
#define prints(x) cout << fixed << setprecision(20) << x << endl
#define printc(x) cout << setw(2) << setfill('0') << x << endl;
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
//配列入力
vector<long long> vecin(ll n) {
vector<long long> res(n);
for (int i = 0; i < n; i++)
cin >> res[i];
return res;
}
// begin() end()
#define all(x) (x).begin(), (x).end()
// for
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rrep(i, a, b) for (int i = (a); i > (b); i--)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
//最大公約数
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
// 最小公倍数
unsigned lcm(unsigned a, unsigned b) { return a / gcd(a, b) * b; }
// a = max(a, b), a = min(a, b)
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
// num ^ pow(mod取る)
ll pow_mod(ll num, ll pow, ll mod) {
ll prod = 1;
num %= mod;
while (pow > 0) {
if (pow & 1)
prod = prod * num % mod;
num = num * num % mod;
pow >>= 1;
}
return prod;
}
// 二項係数(MODとる、1 ≦ k ≦ n ≦ 10^7 程度)
// COMinit()
// COM(x, y)
// とコンビで使う
// テーブルを作る前処理
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
//重みつきUnionFInd
template <class Abel> struct GUnionFind {
vector<int> par;
vector<int> rank;
vector<Abel> diff_weight;
GUnionFind(int n = 1, Abel SUM_UNITY = 0) { init(n, SUM_UNITY); }
void init(int n = 1, Abel SUM_UNITY = 0) {
par.resize(n);
rank.resize(n);
diff_weight.resize(n);
for (int i = 0; i < n; ++i)
par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
}
int root(int x) {
if (par[x] == x) {
return x;
} else {
int r = root(par[x]);
diff_weight[x] += diff_weight[par[x]];
return par[x] = r;
}
}
Abel weight(int x) {
root(x);
return diff_weight[x];
}
bool issame(int x, int y) { return root(x) == root(y); }
bool merge(int x, int y, Abel w) {
w += weight(x);
w -= weight(y);
x = root(x);
y = root(y);
if (x == y)
return false;
if (rank[x] < rank[y])
swap(x, y), w = -w;
if (rank[x] == rank[y])
++rank[x];
par[y] = x;
diff_weight[y] = w;
return true;
}
Abel diff(int x, int y) { return weight(y) - weight(x); }
};
// UnionFind
struct UnionFind {
vector<int> par;
vector<int> rank;
vector<ll> Size;
UnionFind(int n = 1) { init(n); }
void init(int n = 1) {
par.resize(n + 1);
rank.resize(n + 1);
Size.resize(n + 1);
for (int i = 0; i <= n; ++i)
par[i] = i, rank[i] = 0, Size[i] = 1;
}
int root(int x) {
if (par[x] == x) {
return x;
} else {
int r = root(par[x]);
return par[x] = r;
}
}
bool issame(int x, int y) { return root(x) == root(y); }
bool merge(int x, int y) {
x = root(x);
y = root(y);
if (x == y)
return false;
if (rank[x] < rank[y])
swap(x, y);
if (rank[x] == rank[y])
++rank[x];
par[y] = x;
Size[x] += Size[y];
return true;
}
ll size(int x) { return Size[root(x)]; }
};
// modint構造体
struct Mint {
int val;
Mint inv() const {
int tmp, a = val, b = mod, x = 1, y = 0;
while (b)
tmp = a / b, a -= tmp * b, swap(a, b), x -= tmp * y, swap(x, y);
return Mint(x);
}
public:
Mint() : val(0) {}
Mint(ll x) {
if ((val = x % mod) < 0)
val += mod;
}
Mint pow(ll t) {
Mint res = 1, b = *this;
while (t) {
if (t & 1)
res *= b;
b *= b;
t >>= 1;
}
return res;
}
Mint &operator+=(const Mint &x) {
if ((val += x.val) >= mod)
val -= mod;
return *this;
}
Mint &operator-=(const Mint &x) {
if ((val += mod - x.val) >= mod)
val -= mod;
return *this;
}
Mint &operator*=(const Mint &x) {
val = (ll)val * x.val % mod;
return *this;
}
Mint &operator/=(const Mint &x) { return *this *= x.inv(); }
bool operator==(const Mint &x) const { return val == x.val; }
bool operator!=(const Mint &x) const { return val != x.val; }
bool operator<(const Mint &x) const { return val < x.val; }
bool operator<=(const Mint &x) const { return val <= x.val; }
bool operator>(const Mint &x) const { return val > x.val; }
bool operator>=(const Mint &x) const { return val >= x.val; }
Mint operator+(const Mint &x) const { return Mint(*this) += x; }
Mint operator-(const Mint &x) const { return Mint(*this) -= x; }
Mint operator*(const Mint &x) const { return Mint(*this) *= x; }
Mint operator/(const Mint &x) const { return Mint(*this) /= x; }
};
struct factorial {
vector<Mint> Fact, Finv;
public:
// factorial fact(10000010);
// fact.nCr(a, b)
//「fact」の部分は自由に名前変更可能
factorial(int maxx) {
Fact.resize(maxx + 1), Finv.resize(maxx + 1);
Fact[0] = Mint(1);
rep(i, 0, maxx) Fact[i + 1] = Fact[i] * (i + 1);
Finv[maxx] = Mint(1) / Fact[maxx];
rrep(i, maxx, 0) Finv[i - 1] = Finv[i] * i;
}
Mint fact(int n, bool inv = 0) {
if (inv)
return Finv[n];
else
return Fact[n];
}
Mint nPr(int n, int r) {
if (n < 0 || n < r || r < 0)
return Mint(0);
else
return Fact[n] * Finv[n - r];
}
Mint nCr(int n, int r) {
if (n < 0 || n < r || r < 0)
return Mint(0);
else
return Fact[n] * Finv[r] * Finv[n - r];
}
};
// 1 * 2 * 3 .... * n (mod)
ll modfact(ll n) {
if (n <= 1)
return 1;
return (n * modfact(n - 1)) % MOD;
}
// kが角度だった場合:cos(k * (PI / 180));
// const double PI = acos(-1);のまま使うと円周率(M_PIもあるよ)
const double PI = acos(-1);
// 多次元 vector 生成 例: auto dp = make_vec<long long>(N+1, 5, 5, 5);
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
//素因数分解
vector<pair<long long, int>> factorize(long long n) {
vector<pair<long long, int>> res;
for (long long i = 2; i * i <= n; ++i) {
if (n % i)
continue;
res.emplace_back(i, 0);
while (n % i == 0) {
n /= i;
res.back().second++;
}
}
if (n != 1)
res.emplace_back(n, 1);
return res;
}
// 素数判定
bool primejudge(long long a) {
if (a <= 1)
return false;
for (long long i = 2; i * i <= a; i++) {
if (a % i == 0)
return false;
}
return true;
}
// 累積和
// vector<long long>sums(vector<int>n){
// vector<long long>res(n.size() + 1, 0);
// for(int i = 0; i < n.size(); i++) res[i + 1] = n[i] + res[i];
// return res;
// }
int dy[4] = {0, 1, 0, -1}, dx[4] = {1, 0, -1, 0};
vector<vector<int>> graph;
int main() {
int n;
cin >> n;
vector<ll> a(n);
vector<ll> b(n);
REP(i, n) cin >> a[i];
REP(i, n) cin >> b[i];
ll sum = 0;
ll ans = 0;
vector<ll> d;
REP(i, n) {
if (b[i] > a[i])
sum += b[i] - a[i], ans++;
else if (b[i] < a[i])
d.push_back(a[i] - b[i]);
}
sort(all(d));
reverse(all(d));
REP(i, d.size()) {
if (sum > 0)
ans++;
sum -= d[i];
}
sum <= 0 ? print(ans) : print(-1);
}
| [
"variable_declaration.type.change"
] | 948,416 | 948,415 | u832995587 | cpp |
p03151 | #include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
int n;
cin >> n;
vector<ll> a(n), b(n), c;
ll suma = 0, sumb = 0;
rep(i, n) {
cin >> a[i];
suma += a[i];
}
ll cnt1 = 0, cnt2 = 0, s = 0;
rep(i, n) {
cin >> b[i];
if (a[i] < b[i]) {
cnt1++;
s += b[i] - a[i];
} else if (a[i] > b[i])
c.push_back(a[i] - b[i]);
sumb += b[i];
}
sort(all(c));
int i = n - 1;
while (s > 0) {
s -= c[i];
cnt2++;
i--;
}
if (suma < sumb)
cout << -1;
else
cout << cnt1 + cnt2;
} | #include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
int n;
cin >> n;
vector<ll> a(n), b(n), c;
ll suma = 0, sumb = 0;
rep(i, n) {
cin >> a[i];
suma += a[i];
}
ll cnt1 = 0, cnt2 = 0, s = 0;
rep(i, n) {
cin >> b[i];
if (a[i] < b[i]) {
cnt1++;
s += b[i] - a[i];
} else if (a[i] > b[i])
c.push_back(a[i] - b[i]);
sumb += b[i];
}
sort(all(c));
int i = c.size() - 1;
while (s > 0) {
s -= c[i];
cnt2++;
i--;
}
if (suma < sumb)
cout << -1;
else
cout << cnt1 + cnt2;
} | [
"expression.operation.binary.change",
"call.add"
] | 948,419 | 948,420 | u151236434 | cpp |
p03151 | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(ri, n) for (int ri = (int)(n - 1); ri >= 0; ri--)
#define rep2(i, x, n) for (int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri, x, n) for (int ri = (int)(n - 1); ri >= (int)(x); ri--)
#define repit(itr, x) for (auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr, x) for (auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(n);
rep(i, n) cin >> a.at(i);
vector<int> b(n);
rep(i, n) cin >> b.at(i);
vector<int> pl;
int ans = 0;
ll mi = 0;
rep(i, n) {
if (a.at(i) > b.at(i))
pl.push_back(a.at(i) - b.at(i));
else {
mi += b.at(i) - a.at(i);
if (b.at(i) - a.at(i) != 0)
ans++;
}
}
sort(ALL(a), greater<int>());
rep(i, pl.size()) {
if (mi <= 0)
break;
ans++;
mi -= pl.at(i);
}
if (mi <= 0)
cout << ans << endl;
else
cout << -1 << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(ri, n) for (int ri = (int)(n - 1); ri >= 0; ri--)
#define rep2(i, x, n) for (int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri, x, n) for (int ri = (int)(n - 1); ri >= (int)(x); ri--)
#define repit(itr, x) for (auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr, x) for (auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(n);
rep(i, n) cin >> a.at(i);
vector<int> b(n);
rep(i, n) cin >> b.at(i);
vector<int> pl;
int ans = 0;
ll mi = 0;
rep(i, n) {
if (a.at(i) > b.at(i))
pl.push_back(a.at(i) - b.at(i));
else {
mi += b.at(i) - a.at(i);
if (b.at(i) - a.at(i) != 0)
ans++;
}
}
sort(ALL(pl), greater<int>());
rep(i, pl.size()) {
if (mi <= 0)
break;
ans++;
mi -= pl.at(i);
}
if (mi <= 0)
cout << ans << endl;
else
cout << -1 << endl;
return 0;
} | [
"identifier.change",
"call.arguments.change"
] | 948,432 | 948,433 | u617826263 | cpp |
p03151 | // Exam and Wizard
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i, x, y) for (ll i = x; i < y; i++)
#define irep(i, a) for (auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n, a) \
ll n; \
cin >> n; \
vector<ll> a(n); \
rep(i, 0, n) cin >> a[i]
#define vecrep(n, a, type) \
vector<type> a(n); \
rep(i, 0, n) cin >> a[i]
#define lcm(a, b) (a / __gcd(a, b) * b)
#define range(a) (a).begin(), (a).end()
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<ll, string>;
using garph = vector<vector<ll>>;
const int inf = 2147483647; // 2*10^9
const ll INF = 9223372036854775807; // 9*10^18
signed main() {
int n;
cin >> n;
vecrep(n, a, int);
vecrep(n, b, int);
vector<int> ama;
rep(i, 0, n) {
if (a[i] > b[i])
ama.pb(a[i] - b[i]);
}
sort(range(ama), greater<int>());
int aac = accumulate(range(a), 0LL);
int bac = accumulate(range(b), 0LL);
if (aac < bac) {
cout << -1 << nnn;
return 0;
}
int ans = 0;
int tari = 0;
rep(i, 0, n) {
if (a[i] < b[i]) {
tari += b[i] - a[i];
ans++;
}
}
for (int i = 0; tari > 0; i++) {
tari -= ama[ans];
ans++;
}
cout << ans << nnn;
return 0;
} | // Exam and Wizard
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i, x, y) for (ll i = x; i < y; i++)
#define irep(i, a) for (auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n, a) \
ll n; \
cin >> n; \
vector<ll> a(n); \
rep(i, 0, n) cin >> a[i]
#define vecrep(n, a, type) \
vector<type> a(n); \
rep(i, 0, n) cin >> a[i]
#define lcm(a, b) (a / __gcd(a, b) * b)
#define range(a) (a).begin(), (a).end()
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<ll, string>;
using garph = vector<vector<ll>>;
const int inf = 2147483647; // 2*10^9
const ll INF = 9223372036854775807; // 9*10^18
signed main() {
int n;
cin >> n;
vecrep(n, a, int);
vecrep(n, b, int);
vector<int> ama;
rep(i, 0, n) {
if (a[i] > b[i])
ama.pb(a[i] - b[i]);
}
sort(range(ama), greater<int>());
int aac = accumulate(range(a), 0LL);
int bac = accumulate(range(b), 0LL);
if (aac < bac) {
cout << -1 << nnn;
return 0;
}
int ans = 0;
int tari = 0;
rep(i, 0, n) {
if (a[i] < b[i]) {
tari += b[i] - a[i];
ans++;
}
}
for (int i = 0; tari > 0; i++) {
tari -= ama[i];
ans++;
}
cout << ans << nnn;
return 0;
} | [
"assignment.value.change",
"identifier.change",
"variable_access.subscript.index.change"
] | 948,458 | 948,459 | u663842230 | cpp |
p03151 | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;
int main() {
int N, c = 0;
ll w = 0;
cin >> N;
vector<ll> A(N), B(N), d;
rep(i, N) cin >> A.at(i);
rep(i, N) {
cin >> B.at(i);
if (B.at(i) - A.at(i) > 0) {
w += B.at(i) - A.at(i);
++c;
}
if (A.at(i) - B.at(i) > 0)
d.push_back(A.at(i) - B.at(i));
}
sort(d.begin(), d.end(), greater<ll>());
if (w > 0)
rep(i, d.size()) {
w -= d.at(i);
++c;
if (w <= 0)
break;
}
cout << ((w <= 0) ? c : 0) << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;
int main() {
int N, c = 0;
ll w = 0;
cin >> N;
vector<ll> A(N), B(N), d;
rep(i, N) cin >> A.at(i);
rep(i, N) {
cin >> B.at(i);
if (B.at(i) - A.at(i) > 0) {
w += B.at(i) - A.at(i);
++c;
}
if (A.at(i) - B.at(i) > 0)
d.push_back(A.at(i) - B.at(i));
}
sort(d.begin(), d.end(), greater<ll>());
if (w > 0)
rep(i, d.size()) {
w -= d.at(i);
++c;
if (w <= 0)
break;
}
cout << ((w <= 0) ? c : -1) << endl;
} | [
"literal.number.change",
"io.output.change"
] | 948,460 | 948,461 | u211109468 | cpp |
p03151 | #include <bits/stdc++.h>
#define irep(i, n) for (int i = 0; i < (int)(n); i++)
#define irep2(i, a, n) for (int i = (int)(a); i <= (int)(n); i++)
#define lrep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define lrep2(i, a, n) \
for (long long i = (long long)(a); i <= (long long)(n); i++)
#define irrep(i, n) for (int i = (int)(n - 1); i > -1; i--)
#define irrep2(i, a, n) for (int i = (int)(n); i >= (int)(a); i--)
typedef long long ll;
typedef std::vector<int> v_int;
typedef std::vector<v_int> v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<v_ll> v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<v_string> v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<v_bool> v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;
const double PI = 3.14159265359;
const int INF = (int)1e9;
const ll LINF = 1e18;
const int IMOD = 1000000007;
const int dr[4] = {1, 0, -1, 0};
const int dc[4] = {0, 1, 0, -1};
using namespace std;
int main(void) {
int n;
cin >> n;
v_int a(n);
ll suma = 0, sumb = 0, diff = 0;
irep(i, n) {
cin >> a[i];
suma += a[i];
}
v_int q;
int ans = 0;
irep(i, n) {
int b;
cin >> b;
sumb += b;
if (b > a[i]) {
diff += b - a[i];
ans++;
} else {
if (b != a[i]) {
q.push_back(a[i] - b);
}
}
}
if (suma < sumb) {
cout << -1 << endl;
return 0;
}
sort(q.rbegin(), q.rend());
irep(i, q.size()) {
if (diff < 0) {
continue;
}
diff -= q[i];
ans++;
}
cout << ans << endl;
return 0;
}
/** atcoder **/
| #include <bits/stdc++.h>
#define irep(i, n) for (int i = 0; i < (int)(n); i++)
#define irep2(i, a, n) for (int i = (int)(a); i <= (int)(n); i++)
#define lrep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define lrep2(i, a, n) \
for (long long i = (long long)(a); i <= (long long)(n); i++)
#define irrep(i, n) for (int i = (int)(n - 1); i > -1; i--)
#define irrep2(i, a, n) for (int i = (int)(n); i >= (int)(a); i--)
typedef long long ll;
typedef std::vector<int> v_int;
typedef std::vector<v_int> v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<v_ll> v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<v_string> v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<v_bool> v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;
const double PI = 3.14159265359;
const int INF = (int)1e9;
const ll LINF = 1e18;
const int IMOD = 1000000007;
const int dr[4] = {1, 0, -1, 0};
const int dc[4] = {0, 1, 0, -1};
using namespace std;
int main(void) {
int n;
cin >> n;
v_int a(n);
ll suma = 0, sumb = 0, diff = 0;
irep(i, n) {
cin >> a[i];
suma += a[i];
}
v_int q;
int ans = 0;
irep(i, n) {
int b;
cin >> b;
sumb += b;
if (b > a[i]) {
diff += b - a[i];
ans++;
} else {
if (b != a[i]) {
q.push_back(a[i] - b);
}
}
}
if (suma < sumb) {
cout << -1 << endl;
return 0;
}
sort(q.rbegin(), q.rend());
irep(i, q.size()) {
if (diff <= 0) {
continue;
}
diff -= q[i];
ans++;
}
cout << ans << endl;
return 0;
}
/** atcoder **/
| [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 948,464 | 948,465 | u829260400 | cpp |
p03151 | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int, int>;
int main() {
ll N;
cin >> N;
vector<ll> A(N);
REP(i, N) { cin >> A[i]; }
vector<ll> B(N);
REP(i, N) cin >> B[i];
ll a = 0;
vector<ll> b;
ll c = 0;
ll cnt = 0;
REP(i, N) {
if (A.at(i) < B.at(i)) {
cnt++;
a += B.at(i) - A.at(i);
} else {
b.push_back(A.at(i) - B.at(i));
c += A.at(i) - B.at(i);
}
}
sort(ALL(b));
reverse(ALL(b));
// REP(i,b.size()){
// cout << b[i] << " ";
// }
// cout << endl;
// cout << a << " " << cnt << endl;
if (cnt == 0) {
cout << 0 << endl;
} else if (c < a) {
cout << -1 << endl;
} else {
REP(i, b.size()) {
if (b.at(i) < a) {
cnt++;
}
a -= b.at(0);
}
cout << cnt + 1 << 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, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int, int>;
int main() {
ll N;
cin >> N;
vector<ll> A(N);
REP(i, N) { cin >> A[i]; }
vector<ll> B(N);
REP(i, N) cin >> B[i];
ll a = 0;
vector<ll> b;
ll c = 0;
ll cnt = 0;
REP(i, N) {
if (A.at(i) < B.at(i)) {
cnt++;
a += B.at(i) - A.at(i);
} else {
b.push_back(A.at(i) - B.at(i));
c += A.at(i) - B.at(i);
}
}
sort(ALL(b));
reverse(ALL(b));
// REP(i,b.size()){
// cout << b[i] << " ";
// }
// cout << endl;
// cout << a << " " << cnt << endl;
if (cnt == 0) {
cout << 0 << endl;
} else if (c < a) {
cout << -1 << endl;
} else {
REP(i, b.size()) {
if (b.at(i) < a) {
cnt++;
}
a -= b.at(i);
}
cout << cnt + 1 << endl;
}
} | [
"assignment.value.change",
"identifier.replace.add",
"literal.replace.remove",
"call.arguments.change"
] | 948,500 | 948,501 | u135626132 | cpp |
p03151 | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int64_t> A(N);
for (int i = 0; i < N; i++)
cin >> A.at(i);
vector<int64_t> B(N);
for (int i = 0; i < N; i++)
cin >> B.at(i);
vector<int64_t> C(N);
for (int i = 0; i < N; i++) {
C.at(i) = A.at(i) - B.at(i);
}
vector<int64_t> P = {};
vector<int64_t> M = {};
for (int i = 0; i < N; i++) {
if (0 <= C.at(i))
P.push_back(C.at(i));
else
M.push_back(C.at(i));
}
sort(P.begin(), P.end());
reverse(P.begin(), P.end());
int64_t p = P.size();
int64_t m = M.size();
int64_t sum1 = 0;
int64_t sum2 = 0;
for (int i = 0; i < p; i++)
sum1 += P.at(i);
for (int i = 0; i < m; i++)
sum2 += M.at(i);
if (sum1 + sum2 < 0)
cout << -1 << endl;
else {
int ans = m;
int64_t sum3 = 0;
for (int i = 0; i < p; i++) {
if (-sum2 <= sum3) {
ans += i;
break;
}
sum3 += P.at(i);
}
cout << ans << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int64_t> A(N);
for (int i = 0; i < N; i++)
cin >> A.at(i);
vector<int64_t> B(N);
for (int i = 0; i < N; i++)
cin >> B.at(i);
vector<int64_t> C(N);
for (int i = 0; i < N; i++) {
C.at(i) = A.at(i) - B.at(i);
}
vector<int64_t> P = {};
vector<int64_t> M = {};
for (int i = 0; i < N; i++) {
if (0 <= C.at(i))
P.push_back(C.at(i));
else
M.push_back(C.at(i));
}
sort(P.begin(), P.end());
reverse(P.begin(), P.end());
int64_t p = P.size();
int64_t m = M.size();
int64_t sum1 = 0;
int64_t sum2 = 0;
for (int i = 0; i < p; i++)
sum1 += P.at(i);
for (int i = 0; i < m; i++)
sum2 += M.at(i);
if (sum1 + sum2 < 0)
cout << -1 << endl;
else {
int ans = m;
int64_t sum3 = 0;
for (int i = 0; i < p + 1; i++) {
if (-sum2 <= sum3) {
ans += i;
break;
}
sum3 += P.at(i);
}
cout << ans << endl;
}
return 0;
} | [
"control_flow.branch.if.condition.change",
"control_flow.loop.for.condition.change",
"misc.off_by_one"
] | 948,511 | 948,512 | u101018317 | cpp |
p03151 | #include <bits/stdc++.h>
#define rep(n) for (int i = 0; i < n; i++)
#define reps(i, s, n) for (int i = s; i < n; i++)
#define rep_bit(n) for (int bit = 0; bit < (1 << n); ++bit)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define ll long long
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
using namespace std;
typedef vector<vector<int>> Graph;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
int main() {
ll n;
cin >> n;
vl dif(n);
vl a(n), b(n);
rep(n) cin >> a.at(i);
rep(n) cin >> b.at(i);
rep(n) dif.at(i) = a.at(i) - b.at(i);
sort(all(dif));
ll sum = 0;
rep(n) sum += dif.at(i);
ll sum_mi = 0;
ll cnt = 0;
if (sum < 0)
cout << -1 << endl;
else {
ll time = 0;
while (dif.at(time) < 0) {
sum_mi += dif.at(time);
cnt++;
time++;
}
ll now = n - 1;
while (sum_mi < 0) {
sum_mi += dif.at(now);
now--;
cnt++;
}
}
cout << cnt << endl;
return 0;
}
| #include <bits/stdc++.h>
#define rep(n) for (int i = 0; i < n; i++)
#define reps(i, s, n) for (int i = s; i < n; i++)
#define rep_bit(n) for (int bit = 0; bit < (1 << n); ++bit)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define ll long long
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
using namespace std;
typedef vector<vector<int>> Graph;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
int main() {
ll n;
cin >> n;
vl dif(n);
vl a(n), b(n);
rep(n) cin >> a.at(i);
rep(n) cin >> b.at(i);
rep(n) dif.at(i) = a.at(i) - b.at(i);
sort(all(dif));
ll sum = 0;
rep(n) sum += dif.at(i);
ll sum_mi = 0;
ll cnt = 0;
if (sum < 0)
cout << -1 << endl;
else {
ll time = 0;
while (dif.at(time) < 0) {
sum_mi += dif.at(time);
cnt++;
time++;
}
ll now = n - 1;
while (sum_mi < 0) {
sum_mi += dif.at(now);
now--;
cnt++;
}
cout << cnt << endl;
}
return 0;
}
| [] | 948,513 | 948,514 | u314260680 | cpp |
p03151 | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod = 1e9 + 7;
int main() {
ll n;
cin >> n;
vector<int> a(n), b(n);
priority_queue<int> que;
ll m = 0, o = 0;
bool flag = true;
ll ans = 0;
ll sum = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
cin >> b[i];
}
for (int i = 0; i < n; i++) {
if (a[i] < b[i]) {
m += b[i] - a[i];
ans++;
} else if (a[i] > b[i]) {
o += a[i] - b[i];
que.push(b[i]);
}
}
if (o < m)
flag = false;
while (!que.empty() && m > sum) {
sum += que.top();
que.pop();
ans++;
}
if (flag)
cout << ans << endl;
else
cout << -1 << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod = 1e9 + 7;
int main() {
ll n;
cin >> n;
vector<int> a(n), b(n);
priority_queue<int> que;
ll m = 0, o = 0;
bool flag = true;
ll ans = 0;
ll sum = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
cin >> b[i];
}
for (int i = 0; i < n; i++) {
if (a[i] < b[i]) {
m += b[i] - a[i];
ans++;
} else if (a[i] > b[i]) {
o += a[i] - b[i];
que.push(a[i] - b[i]);
}
}
if (o < m)
flag = false;
while (!que.empty() && m > sum) {
sum += que.top();
que.pop();
ans++;
}
if (flag)
cout << ans << endl;
else
cout << -1 << endl;
} | [
"expression.operation.binary.add"
] | 948,521 | 948,522 | u191484928 | cpp |
p03151 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef vector<int> vint;
typedef vector<double> vdou;
typedef vector<ll> vll;
typedef vector<vint> vvint;
typedef vector<str> vstr;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
#define REP(i, n) for (ll(i) = 0; (i) < (ll)(n); i++)
#define FOR(i, a, b) for (ll(i) = a; (i) < (ll)b; i++)
#define ALL(v) (v).begin(), (v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const double PI = M_PI;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } //最小公倍数
//-------------------------------------------------
//
void yes() { cout << "Yes" << endl; }
void no() { cout << "No" << endl; }
//-------------------------------------------------
// メモ
/*
*/
//-------------------------------------------------
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n;
cin >> n;
vll a(n);
vll b(n);
vll dif(n);
ll suma = 0;
ll sumb = 0;
ll cnts = 0;
ll answ = 0;
REP(i, n) {
cin >> a[i];
suma += a[i];
}
REP(i, n) {
cin >> b[i];
sumb += b[i];
dif[i] = a[i] - b[i];
}
if (suma < sumb) {
cout << -1 << endl;
return 0;
}
sort(ALL(dif));
reverse(ALL(dif));
vll ruiseki(n, 0);
ruiseki[0] = dif[0];
if (dif[0] <= 0) {
cout << 0 << endl;
return 0;
}
REP(i, n - 1) { ruiseki[i + 1] = ruiseki[i] + dif[i + 1]; }
REP(i, n) {
if (a[i] < b[i]) {
cnts += b[i] - a[i];
answ++;
}
}
REP(i, n) {
if (ruiseki[i] < cnts) {
answ++;
} else {
break;
}
}
cout << answ + 1 << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef vector<int> vint;
typedef vector<double> vdou;
typedef vector<ll> vll;
typedef vector<vint> vvint;
typedef vector<str> vstr;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
#define REP(i, n) for (ll(i) = 0; (i) < (ll)(n); i++)
#define FOR(i, a, b) for (ll(i) = a; (i) < (ll)b; i++)
#define ALL(v) (v).begin(), (v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const double PI = M_PI;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } //最小公倍数
//-------------------------------------------------
//
void yes() { cout << "Yes" << endl; }
void no() { cout << "No" << endl; }
//-------------------------------------------------
// メモ
/*
*/
//-------------------------------------------------
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n;
cin >> n;
vll a(n);
vll b(n);
vll dif(n);
ll suma = 0;
ll sumb = 0;
ll cnts = 0;
ll answ = 0;
REP(i, n) {
cin >> a[i];
suma += a[i];
}
REP(i, n) {
cin >> b[i];
sumb += b[i];
dif[i] = a[i] - b[i];
}
if (suma < sumb) {
cout << -1 << endl;
return 0;
}
sort(ALL(dif));
reverse(ALL(dif));
vll ruiseki(n, 0);
ruiseki[0] = dif[0];
if (dif[n - 1] >= 0) {
cout << 0 << endl;
return 0;
}
REP(i, n - 1) { ruiseki[i + 1] = ruiseki[i] + dif[i + 1]; }
REP(i, n) {
if (a[i] < b[i]) {
cnts += b[i] - a[i];
answ++;
}
}
REP(i, n) {
if (ruiseki[i] < cnts) {
answ++;
} else {
break;
}
}
cout << answ + 1 << endl;
return 0;
}
| [
"identifier.replace.add",
"literal.replace.remove",
"variable_access.subscript.index.change",
"control_flow.branch.if.condition.change",
"misc.opposites",
"expression.operator.compare.change"
] | 948,534 | 948,535 | u852449189 | cpp |
p03151 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef vector<int> vint;
typedef vector<double> vdou;
typedef vector<ll> vll;
typedef vector<vint> vvint;
typedef vector<str> vstr;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
#define REP(i, n) for (ll(i) = 0; (i) < (ll)(n); i++)
#define FOR(i, a, b) for (ll(i) = a; (i) < (ll)b; i++)
#define ALL(v) (v).begin(), (v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const double PI = M_PI;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } //最小公倍数
//-------------------------------------------------
//
void yes() { cout << "Yes" << endl; }
void no() { cout << "No" << endl; }
//-------------------------------------------------
// メモ
/*
*/
//-------------------------------------------------
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n;
cin >> n;
vll a(n);
vll b(n);
vll dif(n);
ll suma = 0;
ll sumb = 0;
ll cnts = 0;
ll answ = 0;
REP(i, n) {
cin >> a[i];
suma += a[i];
}
REP(i, n) {
cin >> b[i];
sumb += b[i];
dif[i] = a[i] - b[i];
}
if (suma < sumb) {
cout << -1 << endl;
return 0;
}
sort(ALL(dif));
reverse(ALL(dif));
vll ruiseki(n, 0);
ruiseki[0] = dif[0];
if (dif[0] >= 0) {
cout << 0 << endl;
return 0;
}
REP(i, n - 1) { ruiseki[i + 1] = ruiseki[i] + dif[i + 1]; }
REP(i, n) {
if (a[i] < b[i]) {
cnts += b[i] - a[i];
answ++;
}
}
REP(i, n) {
if (ruiseki[i] < cnts) {
answ++;
} else {
break;
}
}
cout << answ + 1 << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef vector<int> vint;
typedef vector<double> vdou;
typedef vector<ll> vll;
typedef vector<vint> vvint;
typedef vector<str> vstr;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
#define REP(i, n) for (ll(i) = 0; (i) < (ll)(n); i++)
#define FOR(i, a, b) for (ll(i) = a; (i) < (ll)b; i++)
#define ALL(v) (v).begin(), (v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const double PI = M_PI;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } //最小公倍数
//-------------------------------------------------
//
void yes() { cout << "Yes" << endl; }
void no() { cout << "No" << endl; }
//-------------------------------------------------
// メモ
/*
*/
//-------------------------------------------------
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n;
cin >> n;
vll a(n);
vll b(n);
vll dif(n);
ll suma = 0;
ll sumb = 0;
ll cnts = 0;
ll answ = 0;
REP(i, n) {
cin >> a[i];
suma += a[i];
}
REP(i, n) {
cin >> b[i];
sumb += b[i];
dif[i] = a[i] - b[i];
}
if (suma < sumb) {
cout << -1 << endl;
return 0;
}
sort(ALL(dif));
reverse(ALL(dif));
vll ruiseki(n, 0);
ruiseki[0] = dif[0];
if (dif[n - 1] >= 0) {
cout << 0 << endl;
return 0;
}
REP(i, n - 1) { ruiseki[i + 1] = ruiseki[i] + dif[i + 1]; }
REP(i, n) {
if (a[i] < b[i]) {
cnts += b[i] - a[i];
answ++;
}
}
REP(i, n) {
if (ruiseki[i] < cnts) {
answ++;
} else {
break;
}
}
cout << answ + 1 << endl;
return 0;
}
| [
"identifier.replace.add",
"literal.replace.remove",
"variable_access.subscript.index.change",
"control_flow.branch.if.condition.change"
] | 948,536 | 948,535 | u852449189 | cpp |
p03151 | #include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
int n;
cin >> n;
vector<ll> a(n), b(n);
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
cin >> b[i];
vector<ll> ab(n);
for (int i = 0; i < n; i++) {
ab[i] = b[i] - a[i];
}
sort(a.begin(), a.end());
ll cnt = 0, tmp = 0;
for (int i = 0; i < n; i++) {
if (ab[i] > 0) {
tmp += ab[i];
cnt++;
}
}
for (int i = 0; i < n; i++) {
if (tmp > 0 && ab[i] < 0) {
tmp += ab[i];
cnt++;
}
}
if (tmp > 0)
cout << -1 << endl;
else
cout << cnt << endl;
} | #include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
int n;
cin >> n;
vector<ll> a(n), b(n);
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
cin >> b[i];
vector<ll> ab(n);
for (int i = 0; i < n; i++) {
ab[i] = b[i] - a[i];
}
sort(ab.begin(), ab.end());
ll cnt = 0, tmp = 0;
for (int i = 0; i < n; i++) {
if (ab[i] > 0) {
tmp += ab[i];
cnt++;
}
}
for (int i = 0; i < n; i++) {
if (tmp > 0 && ab[i] < 0) {
tmp += ab[i];
cnt++;
}
}
if (tmp > 0)
cout << -1 << endl;
else
cout << cnt << endl;
} | [
"identifier.change",
"call.arguments.change"
] | 948,555 | 948,556 | u089885969 | cpp |
p03151 | #include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define FORN(i, b, a) for (int i = (b); _a = (a); i >= _a; i--)
#define REP(i, n) for (int i = 0, _n = n; i < n; i++)
#define ll long long
#define pii pair<int, int>
#define re return
#define vi vector<int>
#define pb push_back
#define si set<int>
#define in insert
#define fl float
#define db double
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
using namespace std;
inline void read(int &x) {
short negative = 1;
x = 0;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-')
negative = -1;
c = getchar();
}
while (c >= '0' && c <= '9')
x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
x *= negative;
}
int main() {
vector<ll> v;
ll a[100100], b[100100];
int n;
cin >> n;
REP(i, n) cin >> a[i];
REP(i, n) cin >> b[i];
ll cnt1 = 0, cnt2 = 0;
ll sum = 0;
ll ans = 0;
REP(i, n) {
if (a[i] > b[i])
v.pb(a[i] - b[i]);
if (a[i] < b[i]) {
ans++;
sum += a[i] - b[i];
}
cnt1 += a[i];
cnt2 += b[i];
}
if (cnt1 < cnt2) {
cout << -1 << endl;
return 0;
}
sort(v.rbegin(), v.rend());
REP(i, v.size()) {
if (sum > 0) {
sum -= v[i];
ans++;
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define FORN(i, b, a) for (int i = (b); _a = (a); i >= _a; i--)
#define REP(i, n) for (int i = 0, _n = n; i < n; i++)
#define ll long long
#define pii pair<int, int>
#define re return
#define vi vector<int>
#define pb push_back
#define si set<int>
#define in insert
#define fl float
#define db double
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
using namespace std;
inline void read(int &x) {
short negative = 1;
x = 0;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-')
negative = -1;
c = getchar();
}
while (c >= '0' && c <= '9')
x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
x *= negative;
}
int main() {
vector<ll> v;
ll a[100100], b[100100];
int n;
cin >> n;
REP(i, n) cin >> a[i];
REP(i, n) cin >> b[i];
ll cnt1 = 0, cnt2 = 0;
ll sum = 0;
ll ans = 0;
REP(i, n) {
if (a[i] > b[i])
v.pb(a[i] - b[i]);
if (a[i] < b[i]) {
ans++;
sum += b[i] - a[i];
}
cnt1 += a[i];
cnt2 += b[i];
}
if (cnt1 < cnt2) {
cout << -1 << endl;
return 0;
}
sort(v.rbegin(), v.rend());
REP(i, v.size()) {
if (sum > 0) {
sum -= v[i];
ans++;
}
}
cout << ans << endl;
return 0;
}
| [
"assignment.value.change",
"identifier.change",
"expression.operation.binary.change"
] | 948,574 | 948,575 | u638661457 | cpp |
p03151 | #include <bits/stdc++.h>
using namespace std;
#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353
template <class T, class U> bool chmax(T &a, const U &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T, class U> bool chmin(T &a, const U &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
#define rep(i, n) for (int i = 0, _i = (n); i < _i; ++i)
#define rep1(i, a, b) for (int a_ = (a), b_ = (b), i = a_; i < b_; ++i)
#define repr(i, n) for (int _i = (n), i = _i; i > 0; --i)
#define db(x) cerr << #x << " = " << x << " ";
#define db2(x, y) \
cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ") ";
#define db3(x, y, z) \
cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y \
<< ", " << z << ") ";
#define ln cout << endl;
#define all(a) (a).begin(), (a).end()
#define dig(n) to_string(n).length()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppii;
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); }
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main() {
bool flag = false;
ll ans = 0, sum = 0;
int n;
cin >> n;
vector<int> a(n), b(n);
vector<int> a_b(n);
rep(i, n) cin >> a[i];
rep(i, n) cin >> b[i];
ll luck = 0;
rep(i, n) {
a_b[i] = a[i] - b[i];
if (a[i] - b[i] < 0) {
ans++;
luck += a[i] - b[i];
}
}
sort(all(a_b), greater<int>());
rep(i, n + 1) {
if (sum + luck >= 0) {
flag = true;
break;
}
if (a_b[i] < 0)
break;
if (i < n) {
sum += a[i - 1];
ans++;
}
}
// cout <<fixed<<setprecision(16)<< << endl;
if (flag)
cout << ans << endl;
else
puts("-1");
// if(flag)cout << "Yes" <<endl;
// else cout << "No" <<endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353
template <class T, class U> bool chmax(T &a, const U &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T, class U> bool chmin(T &a, const U &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
#define rep(i, n) for (int i = 0, _i = (n); i < _i; ++i)
#define rep1(i, a, b) for (int a_ = (a), b_ = (b), i = a_; i < b_; ++i)
#define repr(i, n) for (int _i = (n), i = _i; i > 0; --i)
#define db(x) cerr << #x << " = " << x << " ";
#define db2(x, y) \
cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ") ";
#define db3(x, y, z) \
cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y \
<< ", " << z << ") ";
#define ln cout << endl;
#define all(a) (a).begin(), (a).end()
#define dig(n) to_string(n).length()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppii;
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); }
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main() {
bool flag = false;
ll ans = 0, sum = 0;
int n;
cin >> n;
vector<int> a(n), b(n);
vector<int> a_b(n);
rep(i, n) cin >> a[i];
rep(i, n) cin >> b[i];
ll luck = 0;
rep(i, n) {
a_b[i] = a[i] - b[i];
if (a[i] - b[i] < 0) {
ans++;
luck += a[i] - b[i];
}
}
sort(all(a_b), greater<int>());
rep(i, n + 1) {
// db2(sum,luck);ln;
if (sum + luck >= 0) {
flag = true;
break;
}
if (a_b[i] < 0)
break;
if (i < n) {
sum += a_b[i];
ans++;
}
}
// cout <<fixed<<setprecision(16)<< << endl;
if (flag)
cout << ans << endl;
else
puts("-1");
// if(flag)cout << "Yes" <<endl;
// else cout << "No" <<endl;
return 0;
}
| [
"assignment.value.change",
"identifier.change",
"expression.operation.binary.remove"
] | 948,595 | 948,594 | u355424600 | cpp |
p03151 | #include <bits/stdc++.h>
#define inp(X) cin >> X
#define out(X) cout << X << endl
#define out16(X) cout << setprecision(16) << X << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, f, n) for (int i = f; i < n; i++)
#define MAX(A) *max_element(A.begin(), A.end())
#define MIN(A) *min_element(A.begin(), A.end())
#define SORT(A) sort(A.begin(), A.end())
#define REV(A) reverse(A.begin(), A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vd = std::vector<double>;
using vvd = std::vector<std::vector<double>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using namespace std;
#define MOD 1000000007
#define INF 1000000001
#define LL_INF 1001001001001001001
int main(void) {
int n;
cin >> n;
vll a(n), b(n);
rep(i, n) cin >> a[i];
rep(i, n) cin >> b[i];
vll sub(n);
rep(i, n) sub[i] = b[i] - a[i];
SORT(sub);
ll lack = 0;
int ans = 0;
rep(i, n) {
if (sub[i] > 0) {
lack += sub[i];
ans++;
}
}
if (lack <= 0)
ans = -1;
else {
rep(i, n) {
if (sub[i] >= 0) {
ans = -1;
break;
} else {
lack += sub[i];
ans++;
if (lack <= 0)
break;
}
}
}
out(ans);
}
| #include <bits/stdc++.h>
#define inp(X) cin >> X
#define out(X) cout << X << endl
#define out16(X) cout << setprecision(16) << X << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, f, n) for (int i = f; i < n; i++)
#define MAX(A) *max_element(A.begin(), A.end())
#define MIN(A) *min_element(A.begin(), A.end())
#define SORT(A) sort(A.begin(), A.end())
#define REV(A) reverse(A.begin(), A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vd = std::vector<double>;
using vvd = std::vector<std::vector<double>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using namespace std;
#define MOD 1000000007
#define INF 1000000001
#define LL_INF 1001001001001001001
int main(void) {
int n;
cin >> n;
vll a(n), b(n);
rep(i, n) cin >> a[i];
rep(i, n) cin >> b[i];
vll sub(n);
rep(i, n) sub[i] = b[i] - a[i];
SORT(sub);
ll lack = 0;
int ans = 0;
rep(i, n) {
if (sub[i] > 0) {
lack += sub[i];
ans++;
}
}
if (lack <= 0)
ans = 0;
else {
rep(i, n) {
if (sub[i] >= 0) {
ans = -1;
break;
} else {
lack += sub[i];
ans++;
if (lack <= 0)
break;
}
}
}
out(ans);
}
| [
"literal.number.change",
"assignment.value.change"
] | 948,605 | 948,606 | u086672186 | cpp |
p03151 | #include <bits/stdc++.h>
#define inp(X) cin >> X
#define out(X) cout << X << endl
#define out16(X) cout << setprecision(16) << X << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, f, n) for (int i = f; i < n; i++)
#define MAX(A) *max_element(A.begin(), A.end())
#define MIN(A) *min_element(A.begin(), A.end())
#define SORT(A) sort(A.begin(), A.end())
#define REV(A) reverse(A.begin(), A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vd = std::vector<double>;
using vvd = std::vector<std::vector<double>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using namespace std;
#define MOD 1000000007
#define INF 1000000001
#define LL_INF 1001001001001001001
int main(void) {
int n;
cin >> n;
vi a(n), b(n);
rep(i, n) cin >> a[i];
rep(i, n) cin >> b[i];
vi sub(n);
rep(i, n) sub[i] = b[i] - a[i];
SORT(sub);
ll lack = 0;
int ans = 0;
rep(i, n) {
if (sub[i] > 0) {
lack += sub[i];
ans++;
}
}
if (lack <= 0)
ans = -1;
else {
rep(i, n) {
if (sub[i] >= 0) {
ans = -1;
break;
} else {
lack += sub[i];
ans++;
if (lack <= 0)
break;
}
}
}
out(ans);
}
| #include <bits/stdc++.h>
#define inp(X) cin >> X
#define out(X) cout << X << endl
#define out16(X) cout << setprecision(16) << X << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, f, n) for (int i = f; i < n; i++)
#define MAX(A) *max_element(A.begin(), A.end())
#define MIN(A) *min_element(A.begin(), A.end())
#define SORT(A) sort(A.begin(), A.end())
#define REV(A) reverse(A.begin(), A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vd = std::vector<double>;
using vvd = std::vector<std::vector<double>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using namespace std;
#define MOD 1000000007
#define INF 1000000001
#define LL_INF 1001001001001001001
int main(void) {
int n;
cin >> n;
vll a(n), b(n);
rep(i, n) cin >> a[i];
rep(i, n) cin >> b[i];
vll sub(n);
rep(i, n) sub[i] = b[i] - a[i];
SORT(sub);
ll lack = 0;
int ans = 0;
rep(i, n) {
if (sub[i] > 0) {
lack += sub[i];
ans++;
}
}
if (lack <= 0)
ans = 0;
else {
rep(i, n) {
if (sub[i] >= 0) {
ans = -1;
break;
} else {
lack += sub[i];
ans++;
if (lack <= 0)
break;
}
}
}
out(ans);
}
| [
"variable_declaration.type.change",
"literal.number.change",
"assignment.value.change"
] | 948,607 | 948,606 | u086672186 | cpp |
p03151 | #include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
using ld = long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout << "YES" << endl
#define cNO cout << "NO" << endl
#define cYes cout << "Yes" << endl
#define cNo cout << "No" << endl
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Rep(i, a, b) for (ll i = (a); i < (b); ++i)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define rRep(i, a, b) for (int i = a; i >= b; i--)
#define crep(i) for (char i = 'a'; i <= 'z'; ++i)
#define psortsecond(A, N) \
sort(A, A + N, \
[](const pii &a, const pii &b) { return a.second < b.second; });
#define ALL(x) (x).begin(), (x).end()
#define debug(v) \
cout << #v << ":"; \
for (auto x : v) { \
cout << x << ' '; \
} \
cout << endl;
#define endl '\n'
int ctoi(const char c) {
if ('0' <= c && c <= '9')
return (c - '0');
return -1;
}
ll gcd(ll a, ll b) { return (b == 0 ? a : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
constexpr ll MOD = 1000000007;
constexpr ll INF = 1000000011;
constexpr ll MOD2 = 998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS = 10e-8;
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> istream &operator>>(istream &is, vector<T> &v) {
for (auto &&x : v)
is >> x;
return is;
}
template <typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p) {
is >> p.first;
is >> p.second;
return is;
}
template <typename T, typename U>
ostream &operator>>(ostream &os, const pair<T, U> &p) {
os << p.first << ' ' << p.second;
return os;
}
template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
for (auto i = begin(v); i != end(v); ++i) {
if (i != begin(v))
os << ' ';
os << *i;
}
return os;
}
int main() {
ll N, A[100007], B[100007], ans = 0, min, sum = 0;
vector<ll> plu;
cin >> N;
rep(i, N) {
cin >> A[i];
sum += A[i];
}
rep(i, N) {
cin >> B[i];
sum -= B[i];
}
if (sum < 0) {
cout << -1 << endl;
return 0;
}
sum = 0;
rep(i, N) {
if (A[i] < B[i]) {
ans++;
sum += B[i] - A[i];
} else {
plu.pb(A[i] - B[i]);
}
}
if (plu.size() >= 1) {
sort(ALL(plu));
reverse(ALL(plu));
}
ll k = 0;
while (sum > 0) {
sum -= plu[k];
ans++;
}
cout << ans << endl;
} | #include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
using ld = long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout << "YES" << endl
#define cNO cout << "NO" << endl
#define cYes cout << "Yes" << endl
#define cNo cout << "No" << endl
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Rep(i, a, b) for (ll i = (a); i < (b); ++i)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define rRep(i, a, b) for (int i = a; i >= b; i--)
#define crep(i) for (char i = 'a'; i <= 'z'; ++i)
#define psortsecond(A, N) \
sort(A, A + N, \
[](const pii &a, const pii &b) { return a.second < b.second; });
#define ALL(x) (x).begin(), (x).end()
#define debug(v) \
cout << #v << ":"; \
for (auto x : v) { \
cout << x << ' '; \
} \
cout << endl;
#define endl '\n'
int ctoi(const char c) {
if ('0' <= c && c <= '9')
return (c - '0');
return -1;
}
ll gcd(ll a, ll b) { return (b == 0 ? a : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
constexpr ll MOD = 1000000007;
constexpr ll INF = 1000000011;
constexpr ll MOD2 = 998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS = 10e-8;
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> istream &operator>>(istream &is, vector<T> &v) {
for (auto &&x : v)
is >> x;
return is;
}
template <typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p) {
is >> p.first;
is >> p.second;
return is;
}
template <typename T, typename U>
ostream &operator>>(ostream &os, const pair<T, U> &p) {
os << p.first << ' ' << p.second;
return os;
}
template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
for (auto i = begin(v); i != end(v); ++i) {
if (i != begin(v))
os << ' ';
os << *i;
}
return os;
}
int main() {
ll N, A[100007], B[100007], ans = 0, min, sum = 0;
vector<ll> plu;
cin >> N;
rep(i, N) {
cin >> A[i];
sum += A[i];
}
rep(i, N) {
cin >> B[i];
sum -= B[i];
}
if (sum < 0) {
cout << -1 << endl;
return 0;
}
sum = 0;
rep(i, N) {
if (A[i] < B[i]) {
ans++;
sum += B[i] - A[i];
} else {
plu.pb(A[i] - B[i]);
}
}
if (plu.size() >= 1) {
sort(ALL(plu));
reverse(ALL(plu));
}
ll k = 0;
while (sum > 0) {
sum -= plu[k];
ans++;
k++;
}
cout << ans << endl;
} | [
"expression.unary.arithmetic.add"
] | 948,624 | 948,625 | u008229752 | cpp |
p03151 | #include <algorithm>
#include <bitset>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long n, i, j, k, s, ans;
cin >> n;
vector<long long> a(n), b(n), c;
for (i = 0; i < n; i++)
cin >> a[i];
for (i = 0; i < n; i++)
cin >> b[i];
s = 0;
ans = 0;
for (i = 0; i < n; i++) {
if (a[i] > b[i])
c.push_back(a[i] - b[i]);
else
s += b[i] - a[i], ans++;
}
sort(c.rbegin(), c.rend());
for (auto p : c) {
if (s <= 0)
break;
s -= p;
ans++;
}
if (s > 0)
cout << "-1\n";
else
cout << ans << "\n";
return 0;
}
| #include <algorithm>
#include <bitset>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long n, i, j, k, s, ans;
cin >> n;
vector<long long> a(n), b(n), c;
for (i = 0; i < n; i++)
cin >> a[i];
for (i = 0; i < n; i++)
cin >> b[i];
s = 0;
ans = 0;
for (i = 0; i < n; i++) {
if (a[i] >= b[i])
c.push_back(a[i] - b[i]);
else
s += b[i] - a[i], ans++;
}
sort(c.rbegin(), c.rend());
for (auto p : c) {
if (s <= 0)
break;
s -= p;
ans++;
}
if (s > 0)
cout << "-1\n";
else
cout << ans << "\n";
return 0;
}
| [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 948,628 | 948,629 | u696290869 | cpp |
p03151 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;
const int INF = pow(2, 30) - 1;
int main() {
int N;
cin >> N;
ll A[N];
rep(i, N) cin >> A[i];
ll B[N];
rep(i, N) cin >> B[i];
vector<ll> plus;
ll diff = 0, result = 0;
rep(i, N) {
if (A[i] < B[i]) {
diff += B[i] - A[i];
result++;
}
if (A[i] > B[i])
plus.push_back(A[i] - B[i]);
}
sort(plus.begin(), plus.end(),
[](const ll &x, const ll &y) { return x > y; });
rep(i, plus.size()) {
diff -= plus[i];
if (diff <= 0) {
result += i + 1;
break;
}
}
if (diff > 0)
result = -1;
cout << result << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;
const int INF = pow(2, 30) - 1;
int main() {
int N;
cin >> N;
ll A[N];
rep(i, N) cin >> A[i];
ll B[N];
rep(i, N) cin >> B[i];
vector<ll> plus;
ll diff = 0, result = 0;
rep(i, N) {
if (A[i] < B[i]) {
diff += B[i] - A[i];
result++;
}
if (A[i] > B[i])
plus.push_back(A[i] - B[i]);
}
sort(plus.begin(), plus.end(),
[](const ll &x, const ll &y) { return x > y; });
if (diff > 0)
rep(i, plus.size()) {
diff -= plus[i];
if (diff <= 0) {
result += i + 1;
break;
}
}
if (diff > 0)
result = -1;
cout << result << endl;
return 0;
} | [
"control_flow.branch.if.add"
] | 948,634 | 948,635 | u680707192 | cpp |
p03151 | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int main(void) {
ll n, i, a[100010], b[100010], k = 0, s = 0;
vector<ll> u;
cin >> n;
for (i = 0; i < n; i++)
cin >> a[i];
for (i = 0; i < n; i++)
cin >> b[i];
for (i = 0; i < n; i++) {
if (a[i] > b[i])
u.push_back(a[i] - b[i]);
else if (a[i] < b[i]) {
s += b[i] - a[i];
k++;
}
}
sort(u.begin(), u.end(), greater<int>());
for (i = 0; i < u.size(); i++) {
if (s <= 0)
break;
s -= u[i];
}
if (i == u.size())
cout << -1 << endl;
else
cout << k + i << endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int main(void) {
ll n, i, a[100010], b[100010], k = 0, s = 0;
vector<ll> u;
cin >> n;
for (i = 0; i < n; i++)
cin >> a[i];
for (i = 0; i < n; i++)
cin >> b[i];
for (i = 0; i < n; i++) {
if (a[i] > b[i])
u.push_back(a[i] - b[i]);
else if (a[i] < b[i]) {
s += b[i] - a[i];
k++;
}
}
sort(u.begin(), u.end(), greater<int>());
for (i = 0; i < u.size(); i++) {
if (s <= 0)
break;
s -= u[i];
}
if (i == u.size() && s > 0)
cout << -1 << endl;
else
cout << k + i << endl;
return 0;
} | [
"control_flow.branch.if.condition.change"
] | 948,642 | 948,643 | u088895504 | cpp |
p03151 | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i, n) for (int i = 0; i < n; i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 // 10^12-1
#define dev 998244353 // tenka1
#define P pair<int, int>
#define F first
#define S second
int n, les = 0, ans = 0;
int a[200000], b[200000];
priority_queue<int> que;
signed main() {
cin >> n;
rep(i, n) cin >> a[i];
rep(i, n) {
cin >> b[i];
if (a[i] < b[i]) {
les += b[i] - a[i];
a[i] = b[i];
ans++;
} else if (a[i] > b[i]) {
que.push(a[i] - b[i]);
}
}
while (!que.empty() && les > 0) {
int n = que.top();
que.pop();
ans++;
les -= n;
if (que.empty()) {
cout << -1 << endl;
return 0;
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i, n) for (int i = 0; i < n; i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 // 10^12-1
#define dev 998244353 // tenka1
#define P pair<int, int>
#define F first
#define S second
int n, les = 0, ans = 0;
int a[200000], b[200000];
priority_queue<int> que;
signed main() {
cin >> n;
rep(i, n) cin >> a[i];
rep(i, n) {
cin >> b[i];
if (a[i] < b[i]) {
les += b[i] - a[i];
a[i] = b[i];
ans++;
} else if (a[i] > b[i]) {
que.push(a[i] - b[i]);
}
}
while (!que.empty() && les > 0) {
int n = que.top();
que.pop();
ans++;
les -= n;
if (que.empty() && les > 0) {
cout << -1 << endl;
return 0;
}
}
cout << ans << endl;
return 0;
}
| [
"control_flow.branch.if.condition.change"
] | 948,650 | 948,651 | u988961969 | cpp |
p03151 | // In The Name Of Allah
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int inf = 1e18;
const int maxx = 1e5 + 19;
int n, a[maxx], b[maxx], c[maxx];
int ans = 0, cnt = 0;
int32_t main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
cin >> b[i];
for (int i = 0; i < n; i++)
c[i] = a[i] - b[i];
sort(c, c + n);
for (int i = 0; i < n; i++)
if (c[i] <= 0)
ans += c[i], cnt++;
sort(c, c + n, greater<int>());
for (int i = 0; i < n; i++) {
if (ans < 0 && c[i] > 0)
ans += c[i], cnt++;
else
break;
}
if (ans < 0)
return cout << -1, 0;
cout << cnt;
return 0;
}
| // In The Name Of Allah
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int inf = 1e18;
const int maxx = 1e5 + 19;
int n, a[maxx], b[maxx], c[maxx];
int ans = 0, cnt = 0;
int32_t main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
cin >> b[i];
for (int i = 0; i < n; i++)
c[i] = a[i] - b[i];
sort(c, c + n);
for (int i = 0; i < n; i++)
if (c[i] < 0)
ans += c[i], cnt++;
sort(c, c + n, greater<int>());
for (int i = 0; i < n; i++) {
if (ans < 0 && c[i] > 0)
ans += c[i], cnt++;
else
break;
}
if (ans < 0)
return cout << -1, 0;
cout << cnt;
return 0;
}
| [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 948,656 | 948,657 | u479179837 | cpp |
p03151 | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
long long n, ans, res;
long long a[MAXN], b[MAXN], c[MAXN];
long long sa, sb;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
sa += a[i];
}
for (int i = 0; i < n; i++) {
cin >> b[i];
sb += b[i];
if (a[i] < b[i]) {
res = b[i] - a[i];
ans++;
}
c[i] = a[i] - b[i];
}
sort(c, c + n);
if (sa < sb)
return cout << -1 << '\n', 0;
for (int i = n - 1; i >= 0; i--) {
if (res > 0) {
ans++;
res -= c[i];
} else
break;
}
cout << ans << '\n';
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
long long n, ans, res;
long long a[MAXN], b[MAXN], c[MAXN];
long long sa, sb;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
sa += a[i];
}
for (int i = 0; i < n; i++) {
cin >> b[i];
sb += b[i];
if (a[i] < b[i]) {
res += (b[i] - a[i]);
ans++;
}
c[i] = (a[i] - b[i]);
}
sort(c, c + n);
if (sa < sb)
return cout << -1 << '\n', 0;
for (int i = n - 1; i >= 0; i--) {
if (res > 0) {
ans++;
res -= c[i];
} else
break;
}
cout << ans << '\n';
return 0;
}
| [
"assignment.value.change"
] | 948,658 | 948,659 | u699904147 | cpp |
p03151 | #include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using ll = long long;
int MOD = 1e9 + 7;
using namespace std;
ll GCD(ll x, ll y) {
if (y == 0) {
return x;
} else {
return GCD(y, x % y);
}
}
ll LCM(ll x, ll y) { return x / GCD(x, y) * y; }
struct UnionFind {
vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2
UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
for (int i = 0; i < N; i++)
par[i] = i;
}
int root(int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根}
if (par[x] == x)
return x;
return par[x] = root(par[x]);
}
void unite(int x, int y) { // xとyの木を併合
int rx = root(x); // xの根をrx
int ry = root(y); // yの根をry
if (rx == ry)
return; // xとyの根が同じ(=同じ木にある)時はそのまま
par[rx] =
ry; // xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける
}
bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
int rx = root(x);
int ry = root(y);
return rx == ry;
}
};
//使い方 インスタンス化(頂点数) uniteつなぐ(双方向注意) same判定
int main() {
int n;
cin >> n;
vector<ll> p;
vector<ll> o;
vector<ll> vec(n);
vector<ll> vec1(n);
for (int i = 0; i < n; i++) {
cin >> vec[i];
}
for (int i = 0; i < n; i++) {
cin >> vec1[i];
}
ll p_sum = 0;
ll num = 0;
for (int i = 0; i < n; i++) {
if (vec[i] > vec1[i]) {
o.push_back(vec[i] - vec1[i]);
}
if (vec[i] < vec1[i]) {
p_sum += (vec1[i] - vec[i]);
num++;
}
}
sort(o.begin(), o.begin(), greater<ll>());
if (p_sum == 0) {
cout << 0 << endl;
return 0;
}
for (int i = 0; i < o.size(); i++) {
num++;
p_sum -= o[i];
if (p_sum <= 0) {
break;
}
}
if (p_sum > 0) {
cout << -1 << endl;
return 0;
}
cout << num << endl;
}
| #include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using ll = long long;
int MOD = 1e9 + 7;
using namespace std;
ll GCD(ll x, ll y) {
if (y == 0) {
return x;
} else {
return GCD(y, x % y);
}
}
ll LCM(ll x, ll y) { return x / GCD(x, y) * y; }
struct UnionFind {
vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2
UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
for (int i = 0; i < N; i++)
par[i] = i;
}
int root(int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根}
if (par[x] == x)
return x;
return par[x] = root(par[x]);
}
void unite(int x, int y) { // xとyの木を併合
int rx = root(x); // xの根をrx
int ry = root(y); // yの根をry
if (rx == ry)
return; // xとyの根が同じ(=同じ木にある)時はそのまま
par[rx] =
ry; // xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける
}
bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
int rx = root(x);
int ry = root(y);
return rx == ry;
}
};
//使い方 インスタンス化(頂点数) uniteつなぐ(双方向注意) same判定
int main() {
int n;
cin >> n;
vector<ll> p;
vector<ll> o;
vector<ll> vec(n);
vector<ll> vec1(n);
for (int i = 0; i < n; i++) {
cin >> vec[i];
}
for (int i = 0; i < n; i++) {
cin >> vec1[i];
}
ll p_sum = 0;
ll num = 0;
for (int i = 0; i < n; i++) {
if (vec[i] > vec1[i]) {
o.push_back(vec[i] - vec1[i]);
}
if (vec[i] < vec1[i]) {
p_sum += (vec1[i] - vec[i]);
num++;
}
}
sort(o.begin(), o.end(), greater<ll>());
if (p_sum == 0) {
cout << 0 << endl;
return 0;
}
for (int i = 0; i < o.size(); i++) {
num++;
p_sum -= o[i];
if (p_sum <= 0) {
break;
}
}
if (p_sum > 0) {
cout << -1 << endl;
return 0;
}
cout << num << endl;
}
| [
"call.function.change",
"call.arguments.change"
] | 948,662 | 948,663 | u759162415 | cpp |
p03143 | #include <bits/stdc++.h>
using namespace std;
class unionfind {
int last;
int *parent, *time;
std::vector<std::pair<int, size_t>> *size;
const size_t length;
public:
unionfind(size_t n, int *w) : last(0), length(n) {
parent = new int[n];
time = new int[n];
size = new std::vector<std::pair<int, size_t>>[n];
for (size_t i = 0; i < n; ++i) {
parent[i] = w[i];
time[i] = INT32_MAX;
size[i].emplace_back(0, w[i]);
}
}
size_t root(size_t v, int t) {
if (time[v] > t)
return v;
else
return root(parent[v], t);
}
bool is_same(size_t u, size_t v, int t = -1) {
if (t < 0)
t = last;
return root(u, t) == root(v, t);
}
int merge(size_t u, size_t v) {
int t = ++last;
u = root(u, t);
v = root(v, t);
if (u == v)
return t;
if (parent[u] < parent[v])
std::swap(u, v);
parent[u] += parent[v];
size[u].emplace_back(t, parent[u]);
parent[v] = u;
time[v] = t;
return t;
}
size_t count(size_t v, int t = -1) {
if (t < 0)
t = last;
v = root(v, t);
return std::prev(std::lower_bound(size[v].begin(), size[v].end(),
std::pair<int, size_t>{t, ~0}))
->second;
}
};
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n, m;
static int vw[100000];
static vector<pair<int, int>> edges[100000];
static pair<int, pair<int, int>> ew[100000];
static bool ok[100000];
cin >> n >> m;
for (int i = 0; i < n; ++i)
cin >> vw[i];
for (int i = 0; i < m; ++i) {
int a, b, y;
cin >> a >> b >> y;
--a;
--b;
edges[a].emplace_back(b, y);
edges[b].emplace_back(a, y);
ew[i] = {y, {a, b}};
}
sort(ew, ew + m);
unionfind uf(n, vw);
for (int i = 0; i < m; ++i) {
uf.merge(ew[i].second.first, ew[i].second.second);
}
int ans = 0;
for (int t = m; t > 0; --t) {
int u, v, w;
w = ew[t - 1].first;
tie(u, v) = ew[t - 1].second;
if (ok[u])
continue;
if (uf.count(u, t + 1) < w)
++ans;
else {
queue<int> q;
q.emplace(u);
q.emplace(v);
ok[u] = ok[v] = true;
while (!q.empty()) {
int f = q.front();
q.pop();
for (auto e : edges[f]) {
if (e.second > w)
continue;
if (ok[e.first])
continue;
ok[e.first] = true;
q.emplace(e.first);
}
}
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
class unionfind {
int last;
int *parent, *time;
std::vector<std::pair<int, size_t>> *size;
const size_t length;
public:
unionfind(size_t n, int *w) : last(0), length(n) {
parent = new int[n];
time = new int[n];
size = new std::vector<std::pair<int, size_t>>[n];
for (size_t i = 0; i < n; ++i) {
parent[i] = w[i];
time[i] = INT32_MAX;
size[i].emplace_back(0, w[i]);
}
}
size_t root(size_t v, int t) {
if (time[v] > t)
return v;
else
return root(parent[v], t);
}
bool is_same(size_t u, size_t v, int t = -1) {
if (t < 0)
t = last;
return root(u, t) == root(v, t);
}
int merge(size_t u, size_t v) {
int t = ++last;
u = root(u, t);
v = root(v, t);
if (u == v)
return t;
if (parent[u] < parent[v])
std::swap(u, v);
parent[u] += parent[v];
size[u].emplace_back(t, parent[u]);
parent[v] = u;
time[v] = t;
return t;
}
size_t count(size_t v, int t = -1) {
if (t < 0)
t = last;
v = root(v, t);
return std::prev(std::lower_bound(size[v].begin(), size[v].end(),
std::pair<int, size_t>{t, ~0}))
->second;
}
};
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n, m;
static int vw[100000];
static vector<pair<int, int>> edges[100000];
static pair<int, pair<int, int>> ew[100000];
static bool ok[100000];
cin >> n >> m;
for (int i = 0; i < n; ++i)
cin >> vw[i];
for (int i = 0; i < m; ++i) {
int a, b, y;
cin >> a >> b >> y;
--a;
--b;
edges[a].emplace_back(b, y);
edges[b].emplace_back(a, y);
ew[i] = {y, {a, b}};
}
sort(ew, ew + m);
unionfind uf(n, vw);
for (int i = 0; i < m; ++i) {
uf.merge(ew[i].second.first, ew[i].second.second);
}
int ans = 0;
for (int t = m; t > 0; --t) {
int u, v, w;
w = ew[t - 1].first;
tie(u, v) = ew[t - 1].second;
if (ok[u])
continue;
if (uf.count(u, t) < w)
++ans;
else {
queue<int> q;
q.emplace(u);
q.emplace(v);
ok[u] = ok[v] = true;
while (!q.empty()) {
int f = q.front();
q.pop();
for (auto e : edges[f]) {
if (e.second > w)
continue;
if (ok[e.first])
continue;
ok[e.first] = true;
q.emplace(e.first);
}
}
}
}
cout << ans << endl;
return 0;
} | [
"control_flow.loop.for.condition.change",
"expression.operation.binary.remove"
] | 948,686 | 948,687 | u726604439 | cpp |
p03143 | #include <bits/stdc++.h>
using namespace std;
class unionfind {
int last;
int *parent, *time;
std::vector<std::pair<int, size_t>> *size;
const size_t length;
public:
unionfind(size_t n, int *w) : last(0), length(n) {
parent = new int[n];
time = new int[n];
size = new std::vector<std::pair<int, size_t>>[n];
for (size_t i = 0; i < n; ++i) {
parent[i] = w[i];
time[i] = INT32_MAX;
size[i].emplace_back(0, w[i]);
}
}
size_t root(size_t v, int t) {
if (time[v] > t)
return v;
else
return root(parent[v], t);
}
bool is_same(size_t u, size_t v, int t = -1) {
if (t < 0)
t = last;
return root(u, t) == root(v, t);
}
int merge(size_t u, size_t v) {
int t = ++last;
u = root(u, t);
v = root(v, t);
if (u == v)
return t;
if (parent[u] < parent[v])
std::swap(u, v);
parent[u] += parent[v];
size[u].emplace_back(t, parent[u]);
parent[v] = u;
time[v] = t;
return t;
}
size_t count(size_t v, int t = -1) {
if (t < 0)
t = last;
v = root(v, t);
return std::prev(std::lower_bound(size[v].begin(), size[v].end(),
std::pair<int, size_t>{t, length + 1}))
->second;
}
};
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n, m;
static int vw[100000];
static vector<pair<int, int>> edges[100000];
static pair<int, pair<int, int>> ew[100000];
static bool ok[100000];
cin >> n >> m;
for (int i = 0; i < n; ++i)
cin >> vw[i];
for (int i = 0; i < m; ++i) {
int a, b, y;
cin >> a >> b >> y;
--a;
--b;
edges[a].emplace_back(b, y);
edges[b].emplace_back(a, y);
ew[i] = {y, {a, b}};
}
sort(ew, ew + m);
unionfind uf(n, vw);
for (int i = 0; i < m; ++i) {
uf.merge(ew[i].second.first, ew[i].second.second);
}
int ans = 0;
for (int t = m; t > 0; --t) {
int u, v, w;
w = ew[t - 1].first;
tie(u, v) = ew[t - 1].second;
if (ok[u])
continue;
if (uf.count(u, t + 1) < w)
++ans;
else {
queue<int> q;
q.emplace(u);
q.emplace(v);
ok[u] = ok[v] = true;
while (!q.empty()) {
int f = q.front();
q.pop();
for (auto e : edges[f]) {
if (e.second > w)
continue;
if (ok[e.first])
continue;
ok[e.first] = true;
q.emplace(e.first);
}
}
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
class unionfind {
int last;
int *parent, *time;
std::vector<std::pair<int, size_t>> *size;
const size_t length;
public:
unionfind(size_t n, int *w) : last(0), length(n) {
parent = new int[n];
time = new int[n];
size = new std::vector<std::pair<int, size_t>>[n];
for (size_t i = 0; i < n; ++i) {
parent[i] = w[i];
time[i] = INT32_MAX;
size[i].emplace_back(0, w[i]);
}
}
size_t root(size_t v, int t) {
if (time[v] > t)
return v;
else
return root(parent[v], t);
}
bool is_same(size_t u, size_t v, int t = -1) {
if (t < 0)
t = last;
return root(u, t) == root(v, t);
}
int merge(size_t u, size_t v) {
int t = ++last;
u = root(u, t);
v = root(v, t);
if (u == v)
return t;
if (parent[u] < parent[v])
std::swap(u, v);
parent[u] += parent[v];
size[u].emplace_back(t, parent[u]);
parent[v] = u;
time[v] = t;
return t;
}
size_t count(size_t v, int t = -1) {
if (t < 0)
t = last;
v = root(v, t);
return std::prev(std::lower_bound(size[v].begin(), size[v].end(),
std::pair<int, size_t>{t, ~0}))
->second;
}
};
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n, m;
static int vw[100000];
static vector<pair<int, int>> edges[100000];
static pair<int, pair<int, int>> ew[100000];
static bool ok[100000];
cin >> n >> m;
for (int i = 0; i < n; ++i)
cin >> vw[i];
for (int i = 0; i < m; ++i) {
int a, b, y;
cin >> a >> b >> y;
--a;
--b;
edges[a].emplace_back(b, y);
edges[b].emplace_back(a, y);
ew[i] = {y, {a, b}};
}
sort(ew, ew + m);
unionfind uf(n, vw);
for (int i = 0; i < m; ++i) {
uf.merge(ew[i].second.first, ew[i].second.second);
}
int ans = 0;
for (int t = m; t > 0; --t) {
int u, v, w;
w = ew[t - 1].first;
tie(u, v) = ew[t - 1].second;
if (ok[u])
continue;
if (uf.count(u, t) < w)
++ans;
else {
queue<int> q;
q.emplace(u);
q.emplace(v);
ok[u] = ok[v] = true;
while (!q.empty()) {
int f = q.front();
q.pop();
for (auto e : edges[f]) {
if (e.second > w)
continue;
if (ok[e.first])
continue;
ok[e.first] = true;
q.emplace(e.first);
}
}
}
}
cout << ans << endl;
return 0;
} | [
"call.arguments.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.remove"
] | 948,688 | 948,687 | u726604439 | cpp |
p03143 | ///////////////////////////////////////////////////////////////////////////////
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <typeinfo>
#include <unistd.h>
#include <unordered_map>
#include <vector>
using namespace std;
///////////////////////////////////////////////////////////////////////////////
#define DEBUG 0
#define pb push_back
#define V vector
#define M unordered_map
#define rep(i, n) for (ll i = 0LL; i < n; ++i)
#define srep(i, s, n) for (ll i = s; i < n; ++i)
#define rrep(i, n) for (ll i = n - 1LL; i >= 0LL; --i)
#define ALL(a) (a).begin(), (a).end()
#define CIN(x) \
do { \
assert(!cin.eof()); \
cin >> x; \
assert(!cin.fail()); \
} while (0);
#if DEBUG
#define debug_print(...) _debug_print(__VA_ARGS__)
#define debug_printf(...) printf(__VA_ARGS__)
#else // DEBUG
#define debug_print(...)
#define debug_printf(...)
#endif // DEBUG
typedef long long ll;
typedef unsigned long long ull;
typedef tuple<ll, ll> t2;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;
template <typename T>
using priority_queue_incr = priority_queue<T, V<T>, greater<T>>;
template <typename S, typename T> T get_m(M<S, T> &m, S k, S default_value) {
if (m.find(k) == m.end())
return m[k] = default_value;
return m[k];
}
struct UnionFind {
ull *parent, *count, *rank;
UnionFind(ull n) {
parent = new ull[n + 1];
count = new ull[n + 1];
rank = new ull[n + 1];
for (ull i = 0ULL; i < n + 1; ++i) {
parent[i] = i;
count[i] = 1;
rank[i] = 0;
}
}
~UnionFind() {
delete rank;
delete count;
delete parent;
}
ull root(ull i) {
if (parent[i] == i)
return i;
parent[i] = root(parent[i]);
return parent[i];
}
void unite(ull i, ull j) {
ull rooti = root(i);
ull rootj = root(j);
if (rooti == rootj)
return;
if (rank[rootj] < rank[rooti]) {
parent[i] = parent[j] = parent[rootj] = rooti;
count[rooti] += count[rootj];
} else {
parent[i] = parent[j] = parent[rooti] = rootj;
count[rootj] += count[rooti];
if (rank[rootj] == rank[rooti])
rank[rootj]++;
}
}
bool same(ull i, ull j) { return root(i) == root(j); }
};
struct UnionFindM {
M<ull, ull> parent, count, rank;
ull root(ull i) {
ull parent_i = get_m(parent, i, i);
if (parent_i == i)
return i;
return parent[i] = root(parent_i);
}
void unite(ull i, ull j) {
ull rooti = root(i);
ull rootj = root(j);
if (rooti == rootj)
return;
if (get_m(rank, rootj, 0ULL) < get_m(rank, rooti, 0ULL)) {
parent[i] = parent[j] = parent[rootj] = rooti;
count[rooti] = get_m(count, rooti, 1ULL) + get_m(count, rootj, 1ULL);
} else {
parent[i] = parent[j] = parent[rooti] = rootj;
count[rootj] = get_m(count, rootj, 1ULL) + get_m(count, rooti, 1ULL);
if (get_m(rank, rootj, 0ULL) == get_m(rank, rooti, 0ULL))
rank[rootj]++;
}
}
bool same(ull i, ull j) { return root(i) == root(j); }
};
struct BIT {
ll *tree;
ll size;
BIT(ll n, ll init) {
tree = new ll[n + 1];
size = n;
memset(tree, 0, sizeof(ll) * (n + 1));
this->init(init);
}
void init(ll init) {
rep(i0, size) {
ll idx = i0 + 1LL;
while (idx <= size) {
tree[idx] += init;
idx += (idx & (-idx));
}
}
}
// idx is 1 origin
void add(ll idx, ll x) {
assert(idx > 0LL);
while (idx <= size) {
tree[idx] += x;
idx += (idx & (-idx));
}
}
// idx is 1 origin
ll sum(ll idx) {
assert(idx > 0LL);
ll ret = 0LL;
while (idx > 0LL) {
ret += tree[idx];
idx -= (idx & (-idx));
}
return ret;
}
};
struct MaxFlow {
V<ll> links[1005];
ll capacities[1005][1005];
ll nodes;
MaxFlow(ll nodes) {
// i == 0 --> S
// i == nodes+1 --> T
rep(i, nodes + 2LL) links[i].clear();
memset(capacities, 0, sizeof(capacities));
this->nodes = nodes;
}
void add_path(ll a, ll b, ll capacity) {
links[a].pb(b);
links[b].pb(a);
capacities[a][b] = capacity;
capacities[b][a] = 0LL;
}
ll solve(void) {
deque<V<ll>> q;
ll ret = 0LL;
for (;; q.clear()) {
V<ll> start;
start.pb(0);
q.push_front(start);
bool checked[nodes + 2];
memset(checked, 0, sizeof(checked));
V<ll> found;
for (; !(q.empty());) {
V<ll> path = q.front();
q.pop_front();
ll last = path[path.size() - 1];
if (checked[last])
continue;
if (last == nodes + 1) {
found = path;
break;
}
checked[last] = true;
for (auto next : (links[last])) {
if (capacities[last][next] == 0)
continue;
V<ll> newpath(path);
newpath.pb(next);
q.push_front(newpath);
}
}
if (found.size() == 0) {
break;
} else {
ll flowcount = capacities[found[0]][found[1]];
rep(i, found.size() - 1) {
ll src = found[i];
ll dst = found[i + 1];
flowcount = min(flowcount, capacities[src][dst]);
}
rep(i, found.size() - 1) {
ll src = found[i];
ll dst = found[i + 1];
capacities[src][dst] -= flowcount;
capacities[dst][src] += flowcount;
}
ret += flowcount;
}
}
return ret;
}
};
template <typename T> struct SegmentTree {
T *nodes;
t2 *ranges; // [start, end)
ll nodecount;
ll itemcount;
T unit;
T (*op)(T, T);
SegmentTree(ll itemcount, T unit, T op(T, T)) {
ll orig_itemcount = itemcount;
this->itemcount = 1LL;
while (this->itemcount < orig_itemcount)
this->itemcount *= 2LL;
nodecount = this->itemcount * 2 - 1;
nodes = new T[nodecount];
ranges = new t2[nodecount];
this->unit = unit;
this->op = op;
ll start = 0LL;
ll end = this->itemcount;
ll len = this->itemcount;
rep(i, nodecount) {
nodes[i] = unit;
ranges[i] = t2(start, end);
if (end >= this->itemcount) {
len /= 2LL;
start = 0LL;
end = len;
} else {
start = end;
end = start + len;
}
}
}
void update(ll k, T v) {
ll idx = k + itemcount - 1LL;
nodes[idx] = v;
idx = (idx - 1LL) / 2LL;
for (; idx >= 0; idx = (idx - 1LL) / 2LL) {
nodes[idx] = op(nodes[idx * 2LL + 1LL], nodes[idx * 2LL + 2LL]);
if (!idx)
break;
}
}
T query(ll start, ll end) const { return _query(start, end, 0LL); }
T _query(ll start, ll end, ll idx) const {
ll rstart = get<0>(ranges[idx]);
ll rend = get<1>(ranges[idx]);
if (start <= rstart && rend <= end) {
return nodes[idx];
}
if (rend <= start || end <= rstart) {
return unit;
}
T left = _query(start, end, idx * 2LL + 1LL);
T right = _query(start, end, idx * 2LL + 2LL);
return op(left, right);
}
};
void llin(ll &a) { CIN(a); }
void llinl1(auto &v, ll count) {
for (ll i = 0LL; i < count; ++i) {
ll a;
CIN(a);
v.push_back(a);
}
}
void llinl2(auto &v, ll count) {
for (ll i = 0LL; i < count; ++i) {
ll a, b;
CIN(a >> b);
v.push_back(t2(a, b));
}
}
void llinl3(auto &v, ll count) {
for (ll i = 0LL; i < count; ++i) {
ll a, b, c;
CIN(a >> b >> c);
v.push_back(t3(a, b, c));
}
}
void llinl4(auto &v, ll count) {
for (ll i = 0LL; i < count; ++i) {
ll a, b, c, d;
CIN(a >> b >> c >> d);
v.push_back(t4(a, b, c, d));
}
}
void llina(auto &v, ll count) { llinl1(v, count); }
template <typename T> T min(const V<T> v) {
T ret = v[0];
for (auto i : v)
ret = min(ret, i);
return ret;
}
template <typename T> T max(const V<T> v) {
T ret = v[0];
for (auto i : v)
ret = max(ret, i);
return ret;
}
ll absll(ll x) {
if (x < 0)
return -x;
return x;
}
ll mod_mlt(ll x, ll y, ll mod) {
ll ret = 0LL;
x %= mod;
while (y) {
if (y & 1LL) {
ret += x;
ret %= mod;
}
y >>= 1;
x <<= 1;
x %= mod;
}
return ret;
}
// O(log(exp))
ll mod_pow(ll base, ll exp, ll mod) {
ll ret = 1LL;
for (; exp;) {
if (exp & 1LL) {
ret *= base;
ret %= mod;
}
base = (base * base) % mod;
exp >>= 1;
}
return ret;
}
// O(log(mod))
ll mod_inv(ll x, ll mod) {
// available only when mod is prime
return mod_pow(x, mod - 2LL, mod);
}
ll gcm(ll x, ll y) {
while (y != 0) {
ll z = x % y;
x = y;
y = z;
}
return x;
}
template <typename T> void sort(V<T> &v) { sort(v.begin(), v.end()); }
template <typename T> void sort_reverse(V<T> &v) {
sort(v.begin(), v.end(), greater<T>());
}
void get_divisors(V<ll> &retlist, ll x) {
for (ll i = 1LL; i < sqrt(x) + 3LL; ++i) {
if (x % i == 0LL) {
retlist.push_back(i);
retlist.push_back(x / i);
}
}
}
void get_factors(V<ll> &retlist, ll x) {
for (ll i = 2LL; i < (ll)(sqrt(x)) + 3LL; ++i) {
while (x % i == 0LL) {
retlist.pb(i);
x /= i;
}
}
retlist.pb(x);
}
bool is_prime(ll x) {
V<ll> factors, factors2;
get_factors(factors, x);
for (auto factor : factors) {
if (factor > 1)
factors2.pb(factor);
}
return factors2.size() == 1 && x == factors2[0];
}
template <typename T>
void intersection(const set<T> &a, const set<T> &b, set<T> &result) {
set_intersection(ALL(a), ALL(b), inserter(result, result.end()));
}
ull combination(ll x, ll y) {
if (y > x / 2LL)
y = x - y;
ull ret = 1LL;
for (ll i = 0LL; i < y; ++i) {
ret *= x--;
ret /= (i + 1LL);
}
return ret;
}
ull mod_combination(ll x, ll y, ll mod) {
if (y > x / 2LL)
y = x - y;
ll ret = 1;
for (ll i = 0LL; i < y; ++i) {
ret = (ret * x--) % mod;
ret = (ret * mod_inv(i + 1LL, mod)) % mod;
}
return ret;
}
void make_linklist(const V<t2> &srclist, V<ll> dstlist[]) {
for (auto src : srclist) {
ll a = get<0>(src);
ll b = get<1>(src);
dstlist[a].pb(b);
dstlist[b].pb(a);
}
}
void make_parental_relation(const V<ll> linklist[], ll root, ll n, ll parent[],
V<ll> children[], ll level[]) {
queue<ll> q;
bool checked[n + 1];
memset(checked, 0, sizeof(checked));
q.push(root);
checked[root] = true;
parent[root] = root;
level[root] = 0LL;
for (; !(q.empty());) {
ll now = q.front();
q.pop();
for (auto next : linklist[now]) {
if (checked[next])
continue;
q.push(next);
checked[next] = true;
parent[next] = now;
children[now].pb(next);
level[next] = level[now] + 1LL;
}
}
}
void make_subtree_sizes(const ll child_count[], const ll parents[],
ll subtree_sizes[], ll n) {
ll remain_count[n + 1LL];
memcpy(remain_count, child_count, sizeof(remain_count));
queue<ll> q;
srep(node, 1LL, n + 1LL) {
subtree_sizes[node] = 1LL;
if (remain_count[node] > 0)
continue;
q.push(node);
}
while (!q.empty()) {
ll node = q.front();
q.pop();
ll parent = parents[node];
if (node == parent)
continue;
remain_count[parent]--;
subtree_sizes[parent] += subtree_sizes[node];
if (remain_count[parent] == 0LL)
q.push(parent);
}
}
void get_centroids(const V<ll> children[], const ll subtree_sizes[], ll root,
ll n, V<ll> ¢roids) {
queue<ll> q;
q.push(root);
while (!q.empty()) {
ll now = q.front();
q.pop();
bool is_centroid = true;
for (auto child : children[now]) {
q.push(child);
if (subtree_sizes[child] > n / 2LL)
is_centroid = false;
}
if (n - subtree_sizes[now] > n / 2LL)
is_centroid = false;
if (is_centroid)
centroids.pb(now);
}
assert(centroids.size() == 1LL || centroids.size() == 2LL);
}
#define POW_ANCESTOR_MAXSIZE 20
// preprocess for get_common_ancestor()
void make_pow_ancestor(const ll parent[], ll n,
ll (*pow_ancestor)[POW_ANCESTOR_MAXSIZE]) {
rep(i, n) pow_ancestor[i + 1][0] = parent[i + 1];
for (int pow2 = 1; pow(2, pow2) <= n; ++pow2) {
rep(i0, n) {
int i = i0 + 1;
ll prev = pow_ancestor[i][pow2 - 1];
pow_ancestor[i][pow2] = pow_ancestor[prev][pow2 - 1];
}
}
}
ll get_common_ancestor(ll n, ll x, ll y,
const ll (*pow_ancestor)[POW_ANCESTOR_MAXSIZE],
const ll level[]) {
if (level[x] < level[y]) {
ll diff = level[y] - level[x];
for (; diff;) {
ll bit = diff & -diff;
y = pow_ancestor[y][(int)log2(bit)];
diff -= bit;
}
} else {
ll diff = level[x] - level[y];
for (; diff;) {
ll bit = diff & -diff;
x = pow_ancestor[x][(int)log2(bit)];
diff -= bit;
}
}
if (x == y)
return x;
rrep(i, (int)log2(n) + 1) {
if (pow_ancestor[x][i] != pow_ancestor[y][i]) {
x = pow_ancestor[x][i];
y = pow_ancestor[y][i];
}
}
return pow_ancestor[x][0];
}
void kmp_init(const string &pattern, ll kmp_next[]) {
kmp_next[0] = -1LL;
ll plen = pattern.size();
ll prefix_end = -1;
rep(suffix_end, pattern.size()) {
while (prefix_end >= 0 && pattern[suffix_end] != pattern[prefix_end]) {
prefix_end = kmp_next[prefix_end];
}
kmp_next[suffix_end + 1] = ++prefix_end;
}
kmp_next[0] = 0LL;
}
// founds ... list of text's idx of match position. start position idx.
void kmp_search(const string &text, const string &pattern, const ll kmp_next[],
V<ll> &founds) {
ll text_size = text.size();
ll pattern_size = pattern.size();
ll text_start = 0LL;
ll pattern_idx = 0LL;
assert(pattern_size <= text_size);
for (;;) {
if (text_start + pattern_idx >= text_size)
break;
if (pattern_idx >= pattern_size)
break;
if (text[text_start + pattern_idx] == pattern[pattern_idx]) {
pattern_idx++;
if (pattern_idx == pattern_size) {
founds.pb(text_start);
pattern_idx = kmp_next[pattern_idx];
text_start += (pattern_size - pattern_idx);
}
}
else {
text_start += (pattern_idx - kmp_next[pattern_idx]);
pattern_idx = kmp_next[pattern_idx];
if (pattern_idx == 0LL && text[text_start] != pattern[0]) {
text_start++;
}
}
}
}
void _debug_print(auto x) { cout << x << endl; }
void _debug_print(const t2 &x) {
ll x1 = get<0>(x);
ll x2 = get<1>(x);
cout << "-- " << x1 << " -- " << x2 << endl;
}
void _debug_print(const t3 &x) {
ll x1 = get<0>(x);
ll x2 = get<1>(x);
ll x3 = get<2>(x);
cout << "-- " << x1 << " -- " << x2 << " -- " << x3 << endl;
}
void _debug_print(const t4 &x) {
ll x1 = get<0>(x);
ll x2 = get<1>(x);
ll x3 = get<2>(x);
ll x4 = get<3>(x);
cout << "-- " << x1 << " -- " << x2 << " -- " << x3 << " -- " << x4 << endl;
}
template <typename T> void _debug_print(T xarray[], ll n) {
rep(i, n) _debug_print(xarray[i]);
}
template <typename T> void _debug_print(const V<T> &xlist) {
for (auto x : xlist) {
cout << "-- ";
_debug_print(x);
}
}
template <typename T> void _debug_print(const set<T> &xset) {
for (auto x : xset) {
cout << "-- ";
_debug_print(x);
}
}
template <typename S, typename T> void _debug_print(const M<S, T> &xlist) {
for (auto x : xlist) {
S k = x.first;
T v = x.second;
cout << "====" << endl;
cout << "K=";
_debug_print(k);
cout << "V=";
_debug_print(v);
}
}
int _main();
int main() {
cout << setprecision(12);
return _main();
}
///////////////////////////////////////////////////////////////////////////////
void make_llist(V<t3> linklist[], const V<t4> &cost_edges) {
for (auto cost_edge : cost_edges) {
ll ecost = get<0>(cost_edge);
ll v1 = get<1>(cost_edge);
ll v2 = get<2>(cost_edge);
ll eidx = get<3>(cost_edge);
linklist[v1].pb(t3(v2, eidx, ecost));
linklist[v2].pb(t3(v1, eidx, ecost));
}
}
void find_cand(UnionFind &uf, ll vsums[100005], bool e_iscand[100005], ll ecost,
ll v1, ll v2, ll eidx) {
ll root1 = uf.root(v1);
ll root2 = uf.root(v2);
ll root = root1;
if (root1 != root2) {
ll newsum = vsums[root1] + vsums[root2];
uf.unite(root1, root2);
root = uf.root(root1);
vsums[root] = newsum;
}
if (ecost < vsums[root])
e_iscand[eidx] = true;
}
void update_e_pass(bool e_pass[100005], const V<t3> linklist[100005], ll ecost,
ll v1, ll v2, ll eidx) {
queue<ll> q;
static bool checked[100005];
memset(checked, 0, sizeof(checked));
q.push(v1);
q.push(v2);
checked[v1] = checked[v2] = true;
e_pass[eidx] = true;
while (!q.empty()) {
ll v = q.front();
q.pop();
// linklist[] ... (t3(v, eidx, ecost), ... );
for (auto link : linklist[v]) {
ll nv = get<0>(link);
ll neidx = get<1>(link);
ll necost = get<2>(link);
if (ecost < necost)
continue;
e_pass[neidx] = true;
if (checked[nv])
continue;
checked[nv] = true;
q.push(nv);
}
}
}
int _main() {
ll n;
llin(n);
ll m;
llin(m);
V<ll> xlist;
llina(xlist, n);
V<t3> abylist;
llinl3(abylist, m);
V<t4> cost_edges;
rep(i, m) {
ll a = get<0>(abylist[i]) - 1LL;
ll b = get<1>(abylist[i]) - 1LL;
ll y = get<2>(abylist[i]);
cost_edges.pb(t4(y, a, b, i));
}
sort(cost_edges);
UnionFind uf(n);
static ll vsums[100005];
rep(i, n + 1) vsums[i] = xlist[i];
static bool e_iscand[100005];
memset(e_iscand, 0, sizeof(e_iscand));
static V<t3> linklist[100005];
make_llist(linklist, cost_edges);
for (auto cost_edge : cost_edges) {
ll ecost = get<0>(cost_edge);
ll v1 = get<1>(cost_edge);
ll v2 = get<2>(cost_edge);
ll eidx = get<3>(cost_edge);
find_cand(uf, vsums, e_iscand, ecost, v1, v2, eidx);
}
debug_printf("---- e_iscand\n");
debug_print(e_iscand, m + 1);
reverse(ALL(cost_edges));
static bool e_pass[100005];
memset(e_pass, 0, sizeof(e_pass));
for (auto cost_edge : cost_edges) {
ll ecost = get<0>(cost_edge);
ll v1 = get<1>(cost_edge);
ll v2 = get<2>(cost_edge);
ll eidx = get<3>(cost_edge);
if (e_pass[eidx] || !e_iscand[eidx])
continue;
update_e_pass(e_pass, linklist, ecost, v1, v2, eidx);
}
ll passcount = 0LL;
rep(i, m) {
if (e_pass[i])
passcount++;
}
debug_printf("--- ans\n");
cout << m - passcount << endl;
return 0;
}
///////////////////////////////////////////////////////////////////////////////
| ///////////////////////////////////////////////////////////////////////////////
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <typeinfo>
#include <unistd.h>
#include <unordered_map>
#include <vector>
using namespace std;
///////////////////////////////////////////////////////////////////////////////
#define DEBUG 0
#define pb push_back
#define V vector
#define M unordered_map
#define rep(i, n) for (ll i = 0LL; i < n; ++i)
#define srep(i, s, n) for (ll i = s; i < n; ++i)
#define rrep(i, n) for (ll i = n - 1LL; i >= 0LL; --i)
#define ALL(a) (a).begin(), (a).end()
#define CIN(x) \
do { \
assert(!cin.eof()); \
cin >> x; \
assert(!cin.fail()); \
} while (0);
#if DEBUG
#define debug_print(...) _debug_print(__VA_ARGS__)
#define debug_printf(...) printf(__VA_ARGS__)
#else // DEBUG
#define debug_print(...)
#define debug_printf(...)
#endif // DEBUG
typedef long long ll;
typedef unsigned long long ull;
typedef tuple<ll, ll> t2;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;
template <typename T>
using priority_queue_incr = priority_queue<T, V<T>, greater<T>>;
template <typename S, typename T> T get_m(M<S, T> &m, S k, S default_value) {
if (m.find(k) == m.end())
return m[k] = default_value;
return m[k];
}
struct UnionFind {
ull *parent, *count, *rank;
UnionFind(ull n) {
parent = new ull[n + 1];
count = new ull[n + 1];
rank = new ull[n + 1];
for (ull i = 0ULL; i < n + 1; ++i) {
parent[i] = i;
count[i] = 1;
rank[i] = 0;
}
}
~UnionFind() {
delete rank;
delete count;
delete parent;
}
ull root(ull i) {
if (parent[i] == i)
return i;
parent[i] = root(parent[i]);
return parent[i];
}
void unite(ull i, ull j) {
ull rooti = root(i);
ull rootj = root(j);
if (rooti == rootj)
return;
if (rank[rootj] < rank[rooti]) {
parent[i] = parent[j] = parent[rootj] = rooti;
count[rooti] += count[rootj];
} else {
parent[i] = parent[j] = parent[rooti] = rootj;
count[rootj] += count[rooti];
if (rank[rootj] == rank[rooti])
rank[rootj]++;
}
}
bool same(ull i, ull j) { return root(i) == root(j); }
};
struct UnionFindM {
M<ull, ull> parent, count, rank;
ull root(ull i) {
ull parent_i = get_m(parent, i, i);
if (parent_i == i)
return i;
return parent[i] = root(parent_i);
}
void unite(ull i, ull j) {
ull rooti = root(i);
ull rootj = root(j);
if (rooti == rootj)
return;
if (get_m(rank, rootj, 0ULL) < get_m(rank, rooti, 0ULL)) {
parent[i] = parent[j] = parent[rootj] = rooti;
count[rooti] = get_m(count, rooti, 1ULL) + get_m(count, rootj, 1ULL);
} else {
parent[i] = parent[j] = parent[rooti] = rootj;
count[rootj] = get_m(count, rootj, 1ULL) + get_m(count, rooti, 1ULL);
if (get_m(rank, rootj, 0ULL) == get_m(rank, rooti, 0ULL))
rank[rootj]++;
}
}
bool same(ull i, ull j) { return root(i) == root(j); }
};
struct BIT {
ll *tree;
ll size;
BIT(ll n, ll init) {
tree = new ll[n + 1];
size = n;
memset(tree, 0, sizeof(ll) * (n + 1));
this->init(init);
}
void init(ll init) {
rep(i0, size) {
ll idx = i0 + 1LL;
while (idx <= size) {
tree[idx] += init;
idx += (idx & (-idx));
}
}
}
// idx is 1 origin
void add(ll idx, ll x) {
assert(idx > 0LL);
while (idx <= size) {
tree[idx] += x;
idx += (idx & (-idx));
}
}
// idx is 1 origin
ll sum(ll idx) {
assert(idx > 0LL);
ll ret = 0LL;
while (idx > 0LL) {
ret += tree[idx];
idx -= (idx & (-idx));
}
return ret;
}
};
struct MaxFlow {
V<ll> links[1005];
ll capacities[1005][1005];
ll nodes;
MaxFlow(ll nodes) {
// i == 0 --> S
// i == nodes+1 --> T
rep(i, nodes + 2LL) links[i].clear();
memset(capacities, 0, sizeof(capacities));
this->nodes = nodes;
}
void add_path(ll a, ll b, ll capacity) {
links[a].pb(b);
links[b].pb(a);
capacities[a][b] = capacity;
capacities[b][a] = 0LL;
}
ll solve(void) {
deque<V<ll>> q;
ll ret = 0LL;
for (;; q.clear()) {
V<ll> start;
start.pb(0);
q.push_front(start);
bool checked[nodes + 2];
memset(checked, 0, sizeof(checked));
V<ll> found;
for (; !(q.empty());) {
V<ll> path = q.front();
q.pop_front();
ll last = path[path.size() - 1];
if (checked[last])
continue;
if (last == nodes + 1) {
found = path;
break;
}
checked[last] = true;
for (auto next : (links[last])) {
if (capacities[last][next] == 0)
continue;
V<ll> newpath(path);
newpath.pb(next);
q.push_front(newpath);
}
}
if (found.size() == 0) {
break;
} else {
ll flowcount = capacities[found[0]][found[1]];
rep(i, found.size() - 1) {
ll src = found[i];
ll dst = found[i + 1];
flowcount = min(flowcount, capacities[src][dst]);
}
rep(i, found.size() - 1) {
ll src = found[i];
ll dst = found[i + 1];
capacities[src][dst] -= flowcount;
capacities[dst][src] += flowcount;
}
ret += flowcount;
}
}
return ret;
}
};
template <typename T> struct SegmentTree {
T *nodes;
t2 *ranges; // [start, end)
ll nodecount;
ll itemcount;
T unit;
T (*op)(T, T);
SegmentTree(ll itemcount, T unit, T op(T, T)) {
ll orig_itemcount = itemcount;
this->itemcount = 1LL;
while (this->itemcount < orig_itemcount)
this->itemcount *= 2LL;
nodecount = this->itemcount * 2 - 1;
nodes = new T[nodecount];
ranges = new t2[nodecount];
this->unit = unit;
this->op = op;
ll start = 0LL;
ll end = this->itemcount;
ll len = this->itemcount;
rep(i, nodecount) {
nodes[i] = unit;
ranges[i] = t2(start, end);
if (end >= this->itemcount) {
len /= 2LL;
start = 0LL;
end = len;
} else {
start = end;
end = start + len;
}
}
}
void update(ll k, T v) {
ll idx = k + itemcount - 1LL;
nodes[idx] = v;
idx = (idx - 1LL) / 2LL;
for (; idx >= 0; idx = (idx - 1LL) / 2LL) {
nodes[idx] = op(nodes[idx * 2LL + 1LL], nodes[idx * 2LL + 2LL]);
if (!idx)
break;
}
}
T query(ll start, ll end) const { return _query(start, end, 0LL); }
T _query(ll start, ll end, ll idx) const {
ll rstart = get<0>(ranges[idx]);
ll rend = get<1>(ranges[idx]);
if (start <= rstart && rend <= end) {
return nodes[idx];
}
if (rend <= start || end <= rstart) {
return unit;
}
T left = _query(start, end, idx * 2LL + 1LL);
T right = _query(start, end, idx * 2LL + 2LL);
return op(left, right);
}
};
void llin(ll &a) { CIN(a); }
void llinl1(auto &v, ll count) {
for (ll i = 0LL; i < count; ++i) {
ll a;
CIN(a);
v.push_back(a);
}
}
void llinl2(auto &v, ll count) {
for (ll i = 0LL; i < count; ++i) {
ll a, b;
CIN(a >> b);
v.push_back(t2(a, b));
}
}
void llinl3(auto &v, ll count) {
for (ll i = 0LL; i < count; ++i) {
ll a, b, c;
CIN(a >> b >> c);
v.push_back(t3(a, b, c));
}
}
void llinl4(auto &v, ll count) {
for (ll i = 0LL; i < count; ++i) {
ll a, b, c, d;
CIN(a >> b >> c >> d);
v.push_back(t4(a, b, c, d));
}
}
void llina(auto &v, ll count) { llinl1(v, count); }
template <typename T> T min(const V<T> v) {
T ret = v[0];
for (auto i : v)
ret = min(ret, i);
return ret;
}
template <typename T> T max(const V<T> v) {
T ret = v[0];
for (auto i : v)
ret = max(ret, i);
return ret;
}
ll absll(ll x) {
if (x < 0)
return -x;
return x;
}
ll mod_mlt(ll x, ll y, ll mod) {
ll ret = 0LL;
x %= mod;
while (y) {
if (y & 1LL) {
ret += x;
ret %= mod;
}
y >>= 1;
x <<= 1;
x %= mod;
}
return ret;
}
// O(log(exp))
ll mod_pow(ll base, ll exp, ll mod) {
ll ret = 1LL;
for (; exp;) {
if (exp & 1LL) {
ret *= base;
ret %= mod;
}
base = (base * base) % mod;
exp >>= 1;
}
return ret;
}
// O(log(mod))
ll mod_inv(ll x, ll mod) {
// available only when mod is prime
return mod_pow(x, mod - 2LL, mod);
}
ll gcm(ll x, ll y) {
while (y != 0) {
ll z = x % y;
x = y;
y = z;
}
return x;
}
template <typename T> void sort(V<T> &v) { sort(v.begin(), v.end()); }
template <typename T> void sort_reverse(V<T> &v) {
sort(v.begin(), v.end(), greater<T>());
}
void get_divisors(V<ll> &retlist, ll x) {
for (ll i = 1LL; i < sqrt(x) + 3LL; ++i) {
if (x % i == 0LL) {
retlist.push_back(i);
retlist.push_back(x / i);
}
}
}
void get_factors(V<ll> &retlist, ll x) {
for (ll i = 2LL; i < (ll)(sqrt(x)) + 3LL; ++i) {
while (x % i == 0LL) {
retlist.pb(i);
x /= i;
}
}
retlist.pb(x);
}
bool is_prime(ll x) {
V<ll> factors, factors2;
get_factors(factors, x);
for (auto factor : factors) {
if (factor > 1)
factors2.pb(factor);
}
return factors2.size() == 1 && x == factors2[0];
}
template <typename T>
void intersection(const set<T> &a, const set<T> &b, set<T> &result) {
set_intersection(ALL(a), ALL(b), inserter(result, result.end()));
}
ull combination(ll x, ll y) {
if (y > x / 2LL)
y = x - y;
ull ret = 1LL;
for (ll i = 0LL; i < y; ++i) {
ret *= x--;
ret /= (i + 1LL);
}
return ret;
}
ull mod_combination(ll x, ll y, ll mod) {
if (y > x / 2LL)
y = x - y;
ll ret = 1;
for (ll i = 0LL; i < y; ++i) {
ret = (ret * x--) % mod;
ret = (ret * mod_inv(i + 1LL, mod)) % mod;
}
return ret;
}
void make_linklist(const V<t2> &srclist, V<ll> dstlist[]) {
for (auto src : srclist) {
ll a = get<0>(src);
ll b = get<1>(src);
dstlist[a].pb(b);
dstlist[b].pb(a);
}
}
void make_parental_relation(const V<ll> linklist[], ll root, ll n, ll parent[],
V<ll> children[], ll level[]) {
queue<ll> q;
bool checked[n + 1];
memset(checked, 0, sizeof(checked));
q.push(root);
checked[root] = true;
parent[root] = root;
level[root] = 0LL;
for (; !(q.empty());) {
ll now = q.front();
q.pop();
for (auto next : linklist[now]) {
if (checked[next])
continue;
q.push(next);
checked[next] = true;
parent[next] = now;
children[now].pb(next);
level[next] = level[now] + 1LL;
}
}
}
void make_subtree_sizes(const ll child_count[], const ll parents[],
ll subtree_sizes[], ll n) {
ll remain_count[n + 1LL];
memcpy(remain_count, child_count, sizeof(remain_count));
queue<ll> q;
srep(node, 1LL, n + 1LL) {
subtree_sizes[node] = 1LL;
if (remain_count[node] > 0)
continue;
q.push(node);
}
while (!q.empty()) {
ll node = q.front();
q.pop();
ll parent = parents[node];
if (node == parent)
continue;
remain_count[parent]--;
subtree_sizes[parent] += subtree_sizes[node];
if (remain_count[parent] == 0LL)
q.push(parent);
}
}
void get_centroids(const V<ll> children[], const ll subtree_sizes[], ll root,
ll n, V<ll> ¢roids) {
queue<ll> q;
q.push(root);
while (!q.empty()) {
ll now = q.front();
q.pop();
bool is_centroid = true;
for (auto child : children[now]) {
q.push(child);
if (subtree_sizes[child] > n / 2LL)
is_centroid = false;
}
if (n - subtree_sizes[now] > n / 2LL)
is_centroid = false;
if (is_centroid)
centroids.pb(now);
}
assert(centroids.size() == 1LL || centroids.size() == 2LL);
}
#define POW_ANCESTOR_MAXSIZE 20
// preprocess for get_common_ancestor()
void make_pow_ancestor(const ll parent[], ll n,
ll (*pow_ancestor)[POW_ANCESTOR_MAXSIZE]) {
rep(i, n) pow_ancestor[i + 1][0] = parent[i + 1];
for (int pow2 = 1; pow(2, pow2) <= n; ++pow2) {
rep(i0, n) {
int i = i0 + 1;
ll prev = pow_ancestor[i][pow2 - 1];
pow_ancestor[i][pow2] = pow_ancestor[prev][pow2 - 1];
}
}
}
ll get_common_ancestor(ll n, ll x, ll y,
const ll (*pow_ancestor)[POW_ANCESTOR_MAXSIZE],
const ll level[]) {
if (level[x] < level[y]) {
ll diff = level[y] - level[x];
for (; diff;) {
ll bit = diff & -diff;
y = pow_ancestor[y][(int)log2(bit)];
diff -= bit;
}
} else {
ll diff = level[x] - level[y];
for (; diff;) {
ll bit = diff & -diff;
x = pow_ancestor[x][(int)log2(bit)];
diff -= bit;
}
}
if (x == y)
return x;
rrep(i, (int)log2(n) + 1) {
if (pow_ancestor[x][i] != pow_ancestor[y][i]) {
x = pow_ancestor[x][i];
y = pow_ancestor[y][i];
}
}
return pow_ancestor[x][0];
}
void kmp_init(const string &pattern, ll kmp_next[]) {
kmp_next[0] = -1LL;
ll plen = pattern.size();
ll prefix_end = -1;
rep(suffix_end, pattern.size()) {
while (prefix_end >= 0 && pattern[suffix_end] != pattern[prefix_end]) {
prefix_end = kmp_next[prefix_end];
}
kmp_next[suffix_end + 1] = ++prefix_end;
}
kmp_next[0] = 0LL;
}
// founds ... list of text's idx of match position. start position idx.
void kmp_search(const string &text, const string &pattern, const ll kmp_next[],
V<ll> &founds) {
ll text_size = text.size();
ll pattern_size = pattern.size();
ll text_start = 0LL;
ll pattern_idx = 0LL;
assert(pattern_size <= text_size);
for (;;) {
if (text_start + pattern_idx >= text_size)
break;
if (pattern_idx >= pattern_size)
break;
if (text[text_start + pattern_idx] == pattern[pattern_idx]) {
pattern_idx++;
if (pattern_idx == pattern_size) {
founds.pb(text_start);
pattern_idx = kmp_next[pattern_idx];
text_start += (pattern_size - pattern_idx);
}
}
else {
text_start += (pattern_idx - kmp_next[pattern_idx]);
pattern_idx = kmp_next[pattern_idx];
if (pattern_idx == 0LL && text[text_start] != pattern[0]) {
text_start++;
}
}
}
}
void _debug_print(auto x) { cout << x << endl; }
void _debug_print(const t2 &x) {
ll x1 = get<0>(x);
ll x2 = get<1>(x);
cout << "-- " << x1 << " -- " << x2 << endl;
}
void _debug_print(const t3 &x) {
ll x1 = get<0>(x);
ll x2 = get<1>(x);
ll x3 = get<2>(x);
cout << "-- " << x1 << " -- " << x2 << " -- " << x3 << endl;
}
void _debug_print(const t4 &x) {
ll x1 = get<0>(x);
ll x2 = get<1>(x);
ll x3 = get<2>(x);
ll x4 = get<3>(x);
cout << "-- " << x1 << " -- " << x2 << " -- " << x3 << " -- " << x4 << endl;
}
template <typename T> void _debug_print(T xarray[], ll n) {
rep(i, n) _debug_print(xarray[i]);
}
template <typename T> void _debug_print(const V<T> &xlist) {
for (auto x : xlist) {
cout << "-- ";
_debug_print(x);
}
}
template <typename T> void _debug_print(const set<T> &xset) {
for (auto x : xset) {
cout << "-- ";
_debug_print(x);
}
}
template <typename S, typename T> void _debug_print(const M<S, T> &xlist) {
for (auto x : xlist) {
S k = x.first;
T v = x.second;
cout << "====" << endl;
cout << "K=";
_debug_print(k);
cout << "V=";
_debug_print(v);
}
}
int _main();
int main() {
cout << setprecision(12);
return _main();
}
///////////////////////////////////////////////////////////////////////////////
void make_llist(V<t3> linklist[], const V<t4> &cost_edges) {
for (auto cost_edge : cost_edges) {
ll ecost = get<0>(cost_edge);
ll v1 = get<1>(cost_edge);
ll v2 = get<2>(cost_edge);
ll eidx = get<3>(cost_edge);
linklist[v1].pb(t3(v2, eidx, ecost));
linklist[v2].pb(t3(v1, eidx, ecost));
}
}
void find_cand(UnionFind &uf, ll vsums[100005], bool e_iscand[100005], ll ecost,
ll v1, ll v2, ll eidx) {
ll root1 = uf.root(v1);
ll root2 = uf.root(v2);
ll root = root1;
if (root1 != root2) {
ll newsum = vsums[root1] + vsums[root2];
uf.unite(root1, root2);
root = uf.root(root1);
vsums[root] = newsum;
}
if (ecost <= vsums[root])
e_iscand[eidx] = true;
}
void update_e_pass(bool e_pass[100005], const V<t3> linklist[100005], ll ecost,
ll v1, ll v2, ll eidx) {
queue<ll> q;
static bool checked[100005];
memset(checked, 0, sizeof(checked));
q.push(v1);
q.push(v2);
checked[v1] = checked[v2] = true;
e_pass[eidx] = true;
while (!q.empty()) {
ll v = q.front();
q.pop();
// linklist[] ... (t3(v, eidx, ecost), ... );
for (auto link : linklist[v]) {
ll nv = get<0>(link);
ll neidx = get<1>(link);
ll necost = get<2>(link);
if (ecost < necost)
continue;
e_pass[neidx] = true;
if (checked[nv])
continue;
checked[nv] = true;
q.push(nv);
}
}
}
int _main() {
ll n;
llin(n);
ll m;
llin(m);
V<ll> xlist;
llina(xlist, n);
V<t3> abylist;
llinl3(abylist, m);
V<t4> cost_edges;
rep(i, m) {
ll a = get<0>(abylist[i]) - 1LL;
ll b = get<1>(abylist[i]) - 1LL;
ll y = get<2>(abylist[i]);
cost_edges.pb(t4(y, a, b, i));
}
sort(cost_edges);
UnionFind uf(n);
static ll vsums[100005];
rep(i, n + 1) vsums[i] = xlist[i];
static bool e_iscand[100005];
memset(e_iscand, 0, sizeof(e_iscand));
static V<t3> linklist[100005];
make_llist(linklist, cost_edges);
for (auto cost_edge : cost_edges) {
ll ecost = get<0>(cost_edge);
ll v1 = get<1>(cost_edge);
ll v2 = get<2>(cost_edge);
ll eidx = get<3>(cost_edge);
find_cand(uf, vsums, e_iscand, ecost, v1, v2, eidx);
}
debug_printf("---- e_iscand\n");
debug_print(e_iscand, m + 1);
reverse(ALL(cost_edges));
static bool e_pass[100005];
memset(e_pass, 0, sizeof(e_pass));
for (auto cost_edge : cost_edges) {
ll ecost = get<0>(cost_edge);
ll v1 = get<1>(cost_edge);
ll v2 = get<2>(cost_edge);
ll eidx = get<3>(cost_edge);
if (e_pass[eidx] || !e_iscand[eidx])
continue;
update_e_pass(e_pass, linklist, ecost, v1, v2, eidx);
}
ll passcount = 0LL;
rep(i, m) {
if (e_pass[i])
passcount++;
}
debug_printf("--- ans\n");
cout << m - passcount << endl;
return 0;
}
///////////////////////////////////////////////////////////////////////////////
| [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 948,693 | 948,694 | u167931717 | cpp |
p03143 | #include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;
struct edge {
int u, v, w;
bool operator<(const edge &o) const { return w < o.w; }
} e[N];
int n, m, a[N], f[N];
ll sum[N], p[N];
int getf(int x) { return f[x] == x ? x : f[x] = getf(f[x]); }
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]);
for (int i = 1; i <= n; i++)
f[i] = i, sum[i] = a[i];
for (int i = 1; i <= m; i++)
scanf("%d%d%d", &e[i].u, &e[i].v, &e[i].w);
sort(e + 1, e + 1 + m);
for (int i = 1; i <= m; i++) {
int fu = getf(e[i].u), fv = getf(e[i].v);
if (fu == fv) {
f[fu] = fv;
sum[fv] += sum[fu];
p[fv] += p[fu];
}
p[fv]++;
if (e[i].w <= sum[fv])
p[fv] = 0;
}
int ans = 0;
for (int i = 1; i <= n; i++)
if (getf(i) == i)
ans += p[i];
printf("%d\n", ans);
}
| #include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;
struct edge {
int u, v, w;
bool operator<(const edge &o) const { return w < o.w; }
} e[N];
int n, m, a[N], f[N];
ll sum[N], p[N];
int getf(int x) { return f[x] == x ? x : f[x] = getf(f[x]); }
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]);
for (int i = 1; i <= n; i++)
f[i] = i, sum[i] = a[i];
for (int i = 1; i <= m; i++)
scanf("%d%d%d", &e[i].u, &e[i].v, &e[i].w);
sort(e + 1, e + 1 + m);
for (int i = 1; i <= m; i++) {
int fu = getf(e[i].u), fv = getf(e[i].v);
if (fu != fv) {
f[fu] = fv;
sum[fv] += sum[fu];
p[fv] += p[fu];
}
p[fv]++;
if (e[i].w <= sum[fv])
p[fv] = 0;
}
int ans = 0;
for (int i = 1; i <= n; i++)
if (getf(i) == i)
ans += p[i];
printf("%d\n", ans);
}
| [
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 948,710 | 948,711 | u676323984 | cpp |
p03143 | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
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, M, w[100005], fa[100005], cnt[100005], ans;
ll sum[100005];
struct edge {
int u, v, w;
} ed[100005];
inline bool operator<(const edge &ed1, const edge &ed2) {
return ed1.w < ed2.w;
}
int getf(const int &u) { return fa[u] == u ? u : fa[u] = getf(fa[u]); }
int main() {
getint(N), getint(M);
for (register int i = 1; i <= N; i++)
getint(w[i]);
for (register int i = 1; i <= M; i++)
getint(ed[i].u), getint(ed[i].v), getint(ed[i].w);
sort(ed + 1, ed + M + 1);
for (register int i = 1; i <= N; i++)
fa[i] = i, cnt[i] = 0, sum[i] = w[i];
for (register int i = 1; i <= M; i++) {
const int fu = getf(ed[i].u), fv = getf(ed[i].v);
if (fu == fv)
cnt[fu]++;
else
cnt[fu] += cnt[fv] + 1, sum[fu] += sum[fv], fa[fv] = fu;
if (sum[fu] > ed[i].w)
ans += cnt[fu], cnt[fu] = 0;
}
return printf("%d\n", M - ans), 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
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, M, w[100005], fa[100005], cnt[100005], ans;
ll sum[100005];
struct edge {
int u, v, w;
} ed[100005];
inline bool operator<(const edge &ed1, const edge &ed2) {
return ed1.w < ed2.w;
}
int getf(const int &u) { return fa[u] == u ? u : fa[u] = getf(fa[u]); }
int main() {
getint(N), getint(M);
for (register int i = 1; i <= N; i++)
getint(w[i]);
for (register int i = 1; i <= M; i++)
getint(ed[i].u), getint(ed[i].v), getint(ed[i].w);
sort(ed + 1, ed + M + 1);
for (register int i = 1; i <= N; i++)
fa[i] = i, cnt[i] = 0, sum[i] = w[i];
for (register int i = 1; i <= M; i++) {
const int fu = getf(ed[i].u), fv = getf(ed[i].v);
if (fu == fv)
cnt[fu]++;
else
cnt[fu] += cnt[fv] + 1, sum[fu] += sum[fv], fa[fv] = fu;
if (sum[fu] >= ed[i].w)
ans += cnt[fu], cnt[fu] = 0;
}
return printf("%d\n", M - ans), 0;
} | [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 948,720 | 948,721 | u244167505 | cpp |
p03143 | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using T = tuple<int, int, int>;
const int MX = 100005;
int n, m, p[MX], d[MX], a, b, c;
long long w[MX];
T tp[MX];
int find(int x) { return (p[x] < 0 ? x : p[x] = find(p[x])); }
void uni(int x, int y, int z) {
x = find(x);
y = find(y);
if (x != y) {
if (p[x] > p[y])
swap(x, y);
p[x] += p[y];
w[x] += w[y];
d[x] += d[y];
p[y] = x;
}
if (z < w[x])
d[x] = 0;
else
d[x]++;
}
int main() {
scanf("%d%d", &n, &m);
rep(i, n) {
scanf("%lld", w + i);
p[i] = -1;
}
rep(i, m) {
scanf("%d%d%d", &a, &b, &c);
tp[i] = T(c, a - 1, b - 1);
}
sort(tp, tp + m);
rep(i, m) {
tie(c, a, b) = tp[i];
uni(a, b, c);
}
printf("%d\n", d[find(a)]);
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using T = tuple<int, int, int>;
const int MX = 100005;
int n, m, p[MX], d[MX], a, b, c;
long long w[MX];
T tp[MX];
int find(int x) { return (p[x] < 0 ? x : p[x] = find(p[x])); }
void uni(int x, int y, int z) {
x = find(x);
y = find(y);
if (x != y) {
if (p[x] > p[y])
swap(x, y);
p[x] += p[y];
w[x] += w[y];
d[x] += d[y];
p[y] = x;
}
if (z <= w[x])
d[x] = 0;
else
d[x]++;
}
int main() {
scanf("%d%d", &n, &m);
rep(i, n) {
scanf("%lld", w + i);
p[i] = -1;
}
rep(i, m) {
scanf("%d%d%d", &a, &b, &c);
tp[i] = T(c, a - 1, b - 1);
}
sort(tp, tp + m);
rep(i, m) {
tie(c, a, b) = tp[i];
uni(a, b, c);
}
printf("%d\n", d[find(a)]);
} | [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 948,726 | 948,727 | u309985845 | cpp |
p03143 | #include <bits/stdc++.h>
#define N 100010
using namespace std;
int n, m, first[N], nxt[N << 1], tot = 0;
int fa[N], sum[N], x, y, z, ans = 0;
long long w[N];
long long Read() {
long long 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 f * x;
}
struct Edge {
int u, v;
long long w;
} edge[N << 1];
bool cmp(const Edge a, const Edge b) {
if (a.w < b.w)
return true;
else
return false;
}
void Add(int u, int v, int w) {
tot++;
nxt[tot] = first[u];
first[u] = tot;
edge[tot] = (Edge){u, v, w};
return;
}
int Get(int x) {
if (x == fa[x])
return x;
else
return fa[x] = Get(fa[x]);
}
void Join(int x, int y) {
fa[x] = y;
w[y] += w[x];
sum[y] += sum[x];
return;
}
int main() {
memset(first, -1, sizeof(first));
n = Read(), m = Read();
for (int i = 1; i <= n; i++)
w[i] = Read();
for (int i = 1; i <= m; i++) {
x = Read(), y = Read(), z = Read();
Add(x, y, z);
}
for (int i = 1; i <= n; i++)
fa[i] = i;
sort(edge + 1, edge + tot + 1, cmp);
for (int i = 1; i <= tot; i++) {
int u = edge[i].u, v = edge[i].v;
int f1 = Get(u), f2 = Get(v);
if (f1 != f2)
Join(f1, f2);
sum[f2]++;
if (w[f2] >= edge[i].w)
ans += sum[f2], sum[f2] = 0;
}
printf("%d\b", m - ans);
return 0;
} | #include <bits/stdc++.h>
#define N 100010
using namespace std;
int n, m, first[N], nxt[N << 1], tot = 0;
int fa[N], sum[N], x, y, z, ans = 0;
long long w[N];
long long Read() {
long long 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 f * x;
}
struct Edge {
int u, v;
long long w;
} edge[N << 1];
bool cmp(const Edge a, const Edge b) {
if (a.w < b.w)
return true;
else
return false;
}
void Add(int u, int v, int w) {
tot++;
nxt[tot] = first[u];
first[u] = tot;
edge[tot] = (Edge){u, v, w};
return;
}
int Get(int x) {
if (x == fa[x])
return x;
else
return fa[x] = Get(fa[x]);
}
void Join(int x, int y) {
fa[x] = y;
w[y] += w[x];
sum[y] += sum[x];
return;
}
int main() {
memset(first, -1, sizeof(first));
n = Read(), m = Read();
for (int i = 1; i <= n; i++)
w[i] = Read();
for (int i = 1; i <= m; i++) {
x = Read(), y = Read(), z = Read();
Add(x, y, z);
}
for (int i = 1; i <= n; i++)
fa[i] = i;
sort(edge + 1, edge + tot + 1, cmp);
for (int i = 1; i <= tot; i++) {
int u = edge[i].u, v = edge[i].v;
int f1 = Get(u), f2 = Get(v);
if (f1 != f2)
Join(f1, f2);
sum[f2]++;
if (w[f2] >= edge[i].w)
ans += sum[f2], sum[f2] = 0;
}
printf("%d\n", m - ans);
return 0;
} | [
"literal.string.change",
"call.arguments.change",
"io.output.change",
"io.output.newline.add"
] | 948,742 | 948,743 | u746894388 | cpp |
p03143 | #include <bits/stdc++.h>
using namespace std;
#define int long long // aaaaaaaaaaaaaaaaaa
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define SIZE(buff) (sizeof(buff) / sizeof(buff[0]))
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<pair<int, int>> VPII;
const ll mod = 1000000007;
ll powmod(ll a, ll b) {
ll res = 1;
a %= mod;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1)
res = res * a % mod;
a = a * a % mod;
}
return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
void chmin(int64_t &a, int64_t b) { a = min(a, b); }
template <class T> ostream &operator<<(ostream &o, const vector<T> &v) {
o << "{";
for (int i = 0; i < (int)v.size(); i++)
o << (i > 0 ? ", " : "") << v[i];
o << "}";
return o;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
os << "(" << pair_var.first << ", " << pair_var.second << ")";
return os;
}
// head
int q, m, n, k, res, tmp, tmp2, tmp3, h, w;
int a[100001] = {};
// int b[100010] = {};
deque<PII> que;
string s;
map<int, VPII> kukan;
vector<pair<int, PII>> g;
int dp[200000];
int flag;
int ok[100010] = {};
VPII g2[200000];
class UnionFind {
private:
int n;
vector<int> uni;
public:
UnionFind(int _n) {
n = _n;
uni.clear();
uni.resize(n, -1);
rep(i, 0, n) { uni[i] = -a[i]; }
}
int root(int x) {
if (uni[x] < 0)
return x;
return uni[x] = root(uni[x]);
}
bool same(int x, int y) { return root(x) == root(y); }
void unite(int x, int y) {
x = root(x);
y = root(y);
if (x == y)
return;
if (uni[x] > uni[y])
swap(x, y);
uni[x] += uni[y];
uni[y] = x;
}
int getSize(int x) { return -uni[root(x)]; }
void print() {
for (auto x : uni)
cout << x << " ";
cout << endl;
}
};
void dfs(int x, int c) {
rep(j, 0, g2[x].size()) {
PII i = g2[x][j];
if (i.se <= c) {
g2[x][j].se = 1LL << 60;
res += 1;
dfs(i.fi, c);
}
}
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n >> m;
rep(i, 0, n) { cin >> a[i]; }
rep(i, 0, m) {
cin >> tmp >> tmp2 >> tmp3;
g.pb({tmp3, {tmp2 - 1, tmp - 1}});
g2[tmp2 - 1].push_back({tmp - 1, tmp3});
g2[tmp - 1].push_back({tmp2 - 1, tmp3});
}
UnionFind UF(n);
sort(all(g));
VI v;
rep(i, 0, n) {
pair<int, PII> hen = g[i];
UF.unite(hen.se.fi, hen.se.se);
if (UF.getSize(hen.se.fi) >= hen.fi) {
v.pb(i);
}
}
res = 0;
reverse(all(v));
for (int k : v) {
pair<int, PII> hen = g[k];
dfs(hen.se.se, hen.fi);
}
cout << m - res / 2 << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long // aaaaaaaaaaaaaaaaaa
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define SIZE(buff) (sizeof(buff) / sizeof(buff[0]))
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<pair<int, int>> VPII;
const ll mod = 1000000007;
ll powmod(ll a, ll b) {
ll res = 1;
a %= mod;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1)
res = res * a % mod;
a = a * a % mod;
}
return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
void chmin(int64_t &a, int64_t b) { a = min(a, b); }
template <class T> ostream &operator<<(ostream &o, const vector<T> &v) {
o << "{";
for (int i = 0; i < (int)v.size(); i++)
o << (i > 0 ? ", " : "") << v[i];
o << "}";
return o;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
os << "(" << pair_var.first << ", " << pair_var.second << ")";
return os;
}
// head
int q, m, n, k, res, tmp, tmp2, tmp3, h, w;
int a[100001] = {};
// int b[100010] = {};
deque<PII> que;
string s;
map<int, VPII> kukan;
vector<pair<int, PII>> g;
int dp[200000];
int flag;
int ok[100010] = {};
VPII g2[200000];
class UnionFind {
private:
int n;
vector<int> uni;
public:
UnionFind(int _n) {
n = _n;
uni.clear();
uni.resize(n, -1);
rep(i, 0, n) { uni[i] = -a[i]; }
}
int root(int x) {
if (uni[x] < 0)
return x;
return uni[x] = root(uni[x]);
}
bool same(int x, int y) { return root(x) == root(y); }
void unite(int x, int y) {
x = root(x);
y = root(y);
if (x == y)
return;
if (uni[x] > uni[y])
swap(x, y);
uni[x] += uni[y];
uni[y] = x;
}
int getSize(int x) { return -uni[root(x)]; }
void print() {
for (auto x : uni)
cout << x << " ";
cout << endl;
}
};
void dfs(int x, int c) {
rep(j, 0, g2[x].size()) {
PII i = g2[x][j];
if (i.se <= c) {
g2[x][j].se = 1LL << 60;
res += 1;
dfs(i.fi, c);
}
}
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n >> m;
rep(i, 0, n) { cin >> a[i]; }
rep(i, 0, m) {
cin >> tmp >> tmp2 >> tmp3;
g.pb({tmp3, {tmp2 - 1, tmp - 1}});
g2[tmp2 - 1].push_back({tmp - 1, tmp3});
g2[tmp - 1].push_back({tmp2 - 1, tmp3});
}
UnionFind UF(n);
sort(all(g));
VI v;
rep(i, 0, m) {
pair<int, PII> hen = g[i];
UF.unite(hen.se.fi, hen.se.se);
if (UF.getSize(hen.se.fi) >= hen.fi) {
v.pb(i);
}
}
res = 0;
reverse(all(v));
for (int k : v) {
pair<int, PII> hen = g[k];
dfs(hen.se.se, hen.fi);
}
cout << m - res / 2 << endl;
} | [
"identifier.change",
"call.arguments.change"
] | 948,766 | 948,767 | u884982181 | cpp |
p03143 | #include <bits/stdc++.h>
using namespace std;
int n, m;
long long x[100010], weight[100010];
int ans[100010], cand[100010];
class Edge {
public:
long long cost;
int from, to, num;
Edge(long long c, int f, int t, int n) {
cost = c;
from = f;
to = t;
num = n;
}
};
typedef vector<Edge> Edges;
Edges all;
typedef vector<Edges> Graph;
void readGraph(Graph &g, int E, bool D,
bool C) { // E:NumofEdges, D:Directed, C:Costed
for (int i = 0; i < E; ++i) {
Edge e(0, 0, 0, i);
if (!C)
cin >> e.from >> e.to;
else
cin >> e.from >> e.to >> e.cost;
g[e.from].push_back(e);
all.push_back(e);
if (!D) {
swap(e.from, e.to);
g[e.from].push_back(e);
}
}
}
bool operator<(const Edge &e, const Edge &f) {
return e.cost != f.cost ? e.cost < f.cost
: e.from != f.from ? e.from < f.from
: e.to < f.to;
}
class UnionFind {
public:
vector<int> Parent;
vector<int> Rank;
UnionFind(int n) {
++n;
Parent.resize(n, 0);
Rank.resize(n, 0);
for (int i = 0; i < n; ++i)
Parent[i] = i;
}
int find(int x) {
if (Parent[x] == x)
return x;
return Parent[x] = find(Parent[x]);
}
void unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y)
return;
if (Rank[x] < Rank[y]) {
Parent[x] = y;
weight[y] += weight[x];
weight[x] = 0;
} else {
Parent[y] = x;
weight[x] += weight[y];
weight[y] = 0;
if (Rank[x] == Rank[y])
++Rank[x];
}
}
bool same(int x, int y) { return find(x) == find(y); }
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n >> m;
for (int i = 0; i < n; ++i) {
cin >> x[i + 1];
weight[i + 1] = x[i + 1];
}
Graph g(n + 1);
readGraph(g, m, false, true);
sort(all.begin(), all.end());
// for(int i=0; i<m; ++i) cout << all[i].from << " " << all[i].to << "\n";
UnionFind uf(n);
for (int i = 0; i < m; ++i) {
int a = all[i].from;
int b = all[i].to;
a = uf.find(a);
b = uf.find(b);
// cout << i << " " << a << " " << b << " " << weight[a] << " " <<
//weight[b] << " " << all[i].cost << "\n";
if ((a == b && x[a] >= all[i].cost) ||
(a != b && weight[a] + weight[b] >= all[i].cost))
cand[all[i].num] = 1;
uf.unite(a, b);
}
// for(int i=0; i<m; ++i) cout << i << " " << cand[i] << "\n";
for (int i = m - 1; i >= 0; --i) {
if (ans[all[i].num] == 1 || cand[all[i].num] == 0)
continue;
ans[all[i].num] = 1;
queue<int> q;
q.push(all[i].from);
q.push(all[i].to);
while (!q.empty()) {
int p = q.front();
q.pop();
for (int j = 0; j < g[p].size(); ++j) {
if (ans[g[p][j].num] == 0 && g[p][j].cost <= all[i].cost) {
ans[g[p][j].num] = 1;
// cout << all[i].from << " " << all[i].to << " "
//<< g[p][j].from << " " << g[p][j].to << "\n";
q.push(g[p][j].to);
}
}
}
}
// for(int i=0; i<m; ++i) cout << i << " " << ans[i] << "\n";
int tmp = 0;
for (int i = 0; i < m; ++i)
tmp += ans[i];
cout << m - tmp << "\n";
} | #include <bits/stdc++.h>
using namespace std;
int n, m;
long long x[100010], weight[100010];
int ans[100010], cand[100010];
class Edge {
public:
long long cost;
int from, to, num;
Edge(long long c, int f, int t, int n) {
cost = c;
from = f;
to = t;
num = n;
}
};
typedef vector<Edge> Edges;
Edges all;
typedef vector<Edges> Graph;
void readGraph(Graph &g, int E, bool D,
bool C) { // E:NumofEdges, D:Directed, C:Costed
for (int i = 0; i < E; ++i) {
Edge e(0, 0, 0, i);
if (!C)
cin >> e.from >> e.to;
else
cin >> e.from >> e.to >> e.cost;
g[e.from].push_back(e);
all.push_back(e);
if (!D) {
swap(e.from, e.to);
g[e.from].push_back(e);
}
}
}
bool operator<(const Edge &e, const Edge &f) {
return e.cost != f.cost ? e.cost < f.cost
: e.from != f.from ? e.from < f.from
: e.to < f.to;
}
class UnionFind {
public:
vector<int> Parent;
vector<int> Rank;
UnionFind(int n) {
++n;
Parent.resize(n, 0);
Rank.resize(n, 0);
for (int i = 0; i < n; ++i)
Parent[i] = i;
}
int find(int x) {
if (Parent[x] == x)
return x;
return Parent[x] = find(Parent[x]);
}
void unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y)
return;
if (Rank[x] < Rank[y]) {
Parent[x] = y;
weight[y] += weight[x];
weight[x] = 0;
} else {
Parent[y] = x;
weight[x] += weight[y];
weight[y] = 0;
if (Rank[x] == Rank[y])
++Rank[x];
}
}
bool same(int x, int y) { return find(x) == find(y); }
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n >> m;
for (int i = 0; i < n; ++i) {
cin >> x[i + 1];
weight[i + 1] = x[i + 1];
}
Graph g(n + 1);
readGraph(g, m, false, true);
sort(all.begin(), all.end());
// for(int i=0; i<m; ++i) cout << all[i].from << " " << all[i].to << "\n";
UnionFind uf(n);
for (int i = 0; i < m; ++i) {
int a = all[i].from;
int b = all[i].to;
a = uf.find(a);
b = uf.find(b);
// cout << i << " " << a << " " << b << " " << weight[a] << " " <<
//weight[b] << " " << all[i].cost << "\n";
if ((a == b && weight[a] >= all[i].cost) ||
(a != b && weight[a] + weight[b] >= all[i].cost))
cand[all[i].num] = 1;
uf.unite(a, b);
}
// for(int i=0; i<m; ++i) cout << i << " " << cand[i] << "\n";
for (int i = m - 1; i >= 0; --i) {
if (ans[all[i].num] == 1 || cand[all[i].num] == 0)
continue;
ans[all[i].num] = 1;
queue<int> q;
q.push(all[i].from);
q.push(all[i].to);
while (!q.empty()) {
int p = q.front();
q.pop();
for (int j = 0; j < g[p].size(); ++j) {
if (ans[g[p][j].num] == 0 && g[p][j].cost <= all[i].cost) {
ans[g[p][j].num] = 1;
// cout << all[i].from << " " << all[i].to << " "
//<< g[p][j].from << " " << g[p][j].to << "\n";
q.push(g[p][j].to);
}
}
}
}
// for(int i=0; i<m; ++i) cout << i << " " << ans[i] << "\n";
int tmp = 0;
for (int i = 0; i < m; ++i)
tmp += ans[i];
cout << m - tmp << "\n";
} | [
"identifier.change",
"control_flow.branch.if.condition.change"
] | 948,768 | 948,769 | u207036582 | cpp |
p03143 | #include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
const int N = 100005;
const int M = 100005;
vector<pair<int, int>> edges;
int a[N];
int parents[N];
long long weight[N];
bool included[M];
bool used[M];
bool visited[N];
int u[M], v[M], w[M];
vector<pair<int, int>> adj[N];
int find(int a) {
if (parents[a] == a)
return a;
int pa = find(parents[a]);
parents[a] = pa;
return pa;
}
void join(int a, int b) {
int pa = find(a);
int pb = find(b);
parents[pb] = pa;
weight[pa] += weight[pb];
}
void dfs(int i, int wi) {
visited[i] = true;
for (auto &p : adj[i]) {
if (visited[p.first])
continue;
if (w[p.second] <= wi) {
used[p.second] = true;
dfs(p.first, wi);
}
}
}
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> weight[i];
parents[i] = i;
}
for (int i = 0; i < m; i++) {
int ui, vi, wi;
cin >> ui >> vi >> wi;
ui--;
vi--;
edges.push_back({wi, i});
w[i] = wi;
u[i] = ui;
v[i] = vi;
adj[ui].push_back({vi, i});
adj[vi].push_back({ui, i});
}
sort(edges.begin(), edges.end());
memset(included, false, sizeof(included));
for (int i = 0; i < m; i++) {
int idx = edges[i].second;
int wi = edges[i].first;
int pu = find(u[idx]);
int pv = find(v[idx]);
if (pu != pv) {
join(pu, pv);
}
if (weight[find(pu)] >= wi) {
included[idx] = true;
}
}
memset(used, false, sizeof(used));
memset(visited, false, sizeof(visited));
for (int i = m - 1; i >= 0; i--) {
int idx = edges[i].second;
int wi = edges[i].first;
if (used[idx])
continue;
if (included[idx]) {
dfs(u[idx], wi);
}
}
int ans = m;
for (int i = 0; i < m; i++) {
if (used[i])
ans--;
}
cout << ans;
}
| #include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
const int N = 100005;
const int M = 100005;
vector<pair<int, int>> edges;
int a[N];
int parents[N];
long long weight[N];
bool included[M];
bool used[M];
bool visited[N];
int u[M], v[M], w[M];
vector<pair<int, int>> adj[N];
int find(int a) {
if (parents[a] == a)
return a;
int pa = find(parents[a]);
parents[a] = pa;
return pa;
}
void join(int a, int b) {
int pa = find(a);
int pb = find(b);
parents[pb] = pa;
weight[pa] += weight[pb];
}
void dfs(int i, int wi) {
visited[i] = true;
for (auto &p : adj[i]) {
if (used[p.second])
continue;
if (w[p.second] <= wi) {
used[p.second] = true;
dfs(p.first, wi);
}
}
}
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> weight[i];
parents[i] = i;
}
for (int i = 0; i < m; i++) {
int ui, vi, wi;
cin >> ui >> vi >> wi;
ui--;
vi--;
edges.push_back({wi, i});
w[i] = wi;
u[i] = ui;
v[i] = vi;
adj[ui].push_back({vi, i});
adj[vi].push_back({ui, i});
}
sort(edges.begin(), edges.end());
memset(included, false, sizeof(included));
for (int i = 0; i < m; i++) {
int idx = edges[i].second;
int wi = edges[i].first;
int pu = find(u[idx]);
int pv = find(v[idx]);
if (pu != pv) {
join(pu, pv);
}
if (weight[find(pu)] >= wi) {
included[idx] = true;
}
}
memset(used, false, sizeof(used));
memset(visited, false, sizeof(visited));
for (int i = m - 1; i >= 0; i--) {
int idx = edges[i].second;
int wi = edges[i].first;
if (used[idx])
continue;
if (included[idx]) {
dfs(u[idx], wi);
}
}
int ans = m;
for (int i = 0; i < m; i++) {
if (used[i])
ans--;
}
cout << ans;
}
| [
"identifier.change",
"control_flow.branch.if.condition.change",
"variable_access.subscript.index.change"
] | 948,776 | 948,777 | u530984919 | cpp |
p03151 | #include <bits/stdc++.h>
#define FAST \
cin.tie(0); \
cout.tie(0); \
ios_base::sync_with_stdio(false);
#define pb push_back
#define int long long
#define fr(i, a, b) for (int i = a; i < b; i++)
#define mod 1000000007
#define FILEIO \
freopen("C:/Users/Aman/Desktop/kachda/input.txt", "r", stdin); \
freopen("C:/Users/Aman/Desktop/kachda/output.txt", "w", stdout);
using namespace std;
signed main() {
// FILEIO
FAST int n;
cin >> n;
int a[n + 1], b[n + 1];
int d[n + 1];
int s1 = 0, s2 = 0;
fr(i, 1, n + 1) {
cin >> a[i];
s1 += a[i];
}
fr(i, 1, n + 1) {
cin >> b[i];
d[i] = a[i] - b[i];
s2 += b[i];
}
if (s1 < s2)
return cout << -1, 0;
if (n == 1) {
cout << 0;
return 0;
}
sort(d + 1, d + n + 1);
int l = 1, r = n;
int ans = 0;
bool ok[n] = {0};
while (l < r) {
if (d[l] < 0) {
int temp = min(-d[l], d[r]);
d[l] += temp;
d[r] -= temp;
ok[r] = 1;
ok[l] = 1;
if (d[l] == 0) {
l++;
}
if (d[r] == 0) {
r--;
}
} else
break;
}
fr(i, 1, n + 1) { ans += ok[i]; }
cout << ans;
} | #include <bits/stdc++.h>
#define FAST \
cin.tie(0); \
cout.tie(0); \
ios_base::sync_with_stdio(false);
#define pb push_back
#define int long long
#define fr(i, a, b) for (int i = a; i < b; i++)
#define mod 1000000007
#define FILEIO \
freopen("C:/Users/Aman/Desktop/kachda/input.txt", "r", stdin); \
freopen("C:/Users/Aman/Desktop/kachda/output.txt", "w", stdout);
using namespace std;
signed main() {
// FILEIO
FAST int n;
cin >> n;
int a[n + 1], b[n + 1];
int d[n + 1];
int s1 = 0, s2 = 0;
fr(i, 1, n + 1) {
cin >> a[i];
s1 += a[i];
}
fr(i, 1, n + 1) {
cin >> b[i];
d[i] = a[i] - b[i];
s2 += b[i];
}
if (s1 < s2)
return cout << -1, 0;
if (n == 1) {
cout << 0;
return 0;
}
sort(d + 1, d + n + 1);
int l = 1, r = n;
int ans = 0;
bool ok[n + 1] = {0};
while (l < r) {
if (d[l] < 0) {
int temp = min(-d[l], d[r]);
d[l] += temp;
d[r] -= temp;
ok[r] = 1;
ok[l] = 1;
if (d[l] == 0)
l++;
if (d[r] == 0)
r--;
} else
break;
}
fr(i, 1, n + 1) { ans += ok[i]; }
cout << ans;
} | [
"variable_declaration.array_dimensions.change",
"assignment.change"
] | 948,795 | 948,796 | u955177919 | cpp |
p03151 | #include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstddef>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
using ll = long long;
using ull = unsigned long long;
// vector
template <class T> using vec = std::vector<T>;
template <class T> using vvec = vec<vec<T>>;
constexpr std::size_t operator""_sz(ull n) { return std::size_t(n); }
int main() {
using namespace std;
int n;
cin >> n;
vec<ll> A(n);
vec<ll> B(n);
for (auto &e : A)
cin >> e;
for (auto &e : B)
cin >> e;
if (accumulate(A.cbegin(), A.cend(), 0ll) <
accumulate(B.cbegin(), B.cend(), 0ll)) {
cout << -1 << endl;
return 0;
}
ll minus{};
ll minusCount{};
vec<ll> diffs;
for (int i = 0; i < n; ++i) {
auto d = A[i] - B[i];
if (d > 0) {
diffs.push_back(d);
} else {
minus += d;
++minusCount;
}
}
sort(diffs.begin(), diffs.end(), std::greater<ll>());
int index{};
while (minus < 0) {
minus += diffs[index];
++index;
}
cout << index + minusCount << endl;
return 0;
} | #include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstddef>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
using ll = long long;
using ull = unsigned long long;
// vector
template <class T> using vec = std::vector<T>;
template <class T> using vvec = vec<vec<T>>;
constexpr std::size_t operator""_sz(ull n) { return std::size_t(n); }
int main() {
using namespace std;
int n;
cin >> n;
vec<ll> A(n);
vec<ll> B(n);
for (auto &e : A)
cin >> e;
for (auto &e : B)
cin >> e;
if (accumulate(A.cbegin(), A.cend(), 0ll) <
accumulate(B.cbegin(), B.cend(), 0ll)) {
cout << -1 << endl;
return 0;
}
ll minus{};
ll minusCount{};
vec<ll> diffs;
for (int i = 0; i < n; ++i) {
auto d = A[i] - B[i];
if (d > 0) {
diffs.push_back(d);
} else if (d < 0) {
minus += d;
++minusCount;
}
}
sort(diffs.begin(), diffs.end(), std::greater<ll>());
int index{};
while (minus < 0) {
minus += diffs[index];
++index;
}
cout << index + minusCount << endl;
return 0;
} | [
"control_flow.branch.if.add"
] | 948,807 | 948,808 | u207917850 | cpp |
p03151 | #include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int read() {
int 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;
}
long long a[200005], b[200005];
long long c[200005];
int cnt;
int main() {
int n = read();
long long sum = 0, tmp = 0;
int res = 0;
for (int i = 1; i <= n; ++i) {
a[i] = read();
sum += a[i];
}
for (int i = 1; i <= n; ++i) {
b[i] = read();
sum -= b[i];
if (b[i] > a[i]) {
tmp += b[i] - a[i];
res++;
} else
c[++cnt] = a[i] - b[i];
}
if (sum < 0) {
puts("-1");
return 0;
}
sort(c + 1, c + 1 + cnt);
for (int i = cnt; i >= 1; --i) {
if (tmp <= 0)
break;
res++;
tmp -= c[cnt];
}
printf("%d\n", res);
return 0;
} | #include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int read() {
int 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;
}
long long a[200005], b[200005];
long long c[200005];
int cnt;
int main() {
int n = read();
long long sum = 0, tmp = 0;
int res = 0;
for (int i = 1; i <= n; ++i) {
a[i] = read();
sum += a[i];
}
for (int i = 1; i <= n; ++i) {
b[i] = read();
sum -= b[i];
if (b[i] > a[i]) {
tmp += b[i] - a[i];
res++;
} else
c[++cnt] = a[i] - b[i];
}
if (sum < 0) {
puts("-1");
return 0;
}
sort(c + 1, c + 1 + cnt);
for (int i = cnt; i >= 1; --i) {
if (tmp <= 0)
break;
res++;
tmp -= c[i];
}
printf("%d\n", res);
return 0;
} | [
"assignment.value.change",
"identifier.change",
"variable_access.subscript.index.change"
] | 948,817 | 948,818 | u547532427 | cpp |
p03151 | #include <algorithm>
#include <iostream>
#include <vector>
#define ll long long
using namespace std;
int n;
ll a[100010], b[100010];
bool vis[100010] = {0};
vector<ll> v1, v2;
ll r1, r2;
int res;
int main() {
r1 = r2 = 0;
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i], r1 += a[i];
for (int i = 0; i < n; i++) {
cin >> b[i], r2 += b[i];
if (a[i] < b[i])
v1.push_back(b[i] - a[i]);
else if (a[i] > b[i])
v2.push_back(a[i] - b[i]);
}
if (r1 < r2) {
cout << "-1";
return 0;
}
sort(v1.begin(), v1.end());
sort(v2.begin(), v2.end());
res = v1.size();
int t = v2.size();
for (int i = 0; i < v1.size(); i++) {
for (int j = v2.size() - 1; j >= 0; j--) {
vis[j] = 1;
if (v2[j] < v1[i]) {
v1[i] -= v2[i];
v2.pop_back();
} else if (v2[j] == v1[i]) {
v2.pop_back();
v1[i] = 0;
break;
} else {
v2[j] -= v1[i];
v1[i] = 0;
break;
}
}
}
res += count(vis, vis + t, 1);
cout << res;
return 0;
} | #include <algorithm>
#include <iostream>
#include <vector>
#define ll long long
using namespace std;
int n;
ll a[100010], b[100010];
bool vis[100010] = {0};
vector<ll> v1, v2;
ll r1, r2;
int res;
int main() {
r1 = r2 = 0;
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i], r1 += a[i];
for (int i = 0; i < n; i++) {
cin >> b[i], r2 += b[i];
if (a[i] < b[i])
v1.push_back(b[i] - a[i]);
else if (a[i] > b[i])
v2.push_back(a[i] - b[i]);
}
if (r1 < r2) {
cout << "-1";
return 0;
}
sort(v1.begin(), v1.end());
sort(v2.begin(), v2.end());
res = v1.size();
int t = v2.size();
for (int i = 0; i < v1.size(); i++) {
for (int j = v2.size() - 1; j >= 0; j--) {
vis[j] = 1;
if (v2[j] < v1[i]) {
v1[i] -= v2[j];
v2.pop_back();
} else if (v2[j] == v1[i]) {
v2.pop_back();
v1[i] = 0;
break;
} else {
v2[j] -= v1[i];
v1[i] = 0;
break;
}
}
}
res += count(vis, vis + t, 1);
cout << res;
return 0;
} | [
"assignment.value.change",
"identifier.change",
"variable_access.subscript.index.change"
] | 948,819 | 948,820 | u152424169 | cpp |
p03151 | #include <algorithm>
#include <iostream>
#include <vector>
#define ll long long
using namespace std;
int n;
ll a[100010], b[100010];
bool vis[100010] = {0};
vector<ll> v1, v2;
ll r1, r2;
int res;
int main() {
r1 = r2 = 0;
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i], r1 += a[i];
for (int i = 0; i < n; i++) {
cin >> b[i], r2 += b[i];
if (a[i] < b[i])
v1.push_back(b[i] - a[i]);
else if (a[i] > b[i])
v2.push_back(a[i] - b[i]);
}
if (r1 < r2) {
cout << "-1";
return 0;
}
sort(v1.begin(), v1.end());
sort(v2.begin(), v2.end());
res = v1.size();
int t = v2.size();
for (int i = 0; i < v1.size(); i++) {
for (int j = v2.size() - 1; j >= 0; j--) {
vis[j] = 1;
if (v2[i] < v1[i]) {
v1[i] -= v2[i];
v2.pop_back();
} else if (v2[i] == v1[i]) {
v2.pop_back();
v1[i] = 0;
break;
} else {
v2[i] -= v1[i];
v1[i] = 0;
break;
}
}
}
res += count(vis, vis + t, 1);
cout << res;
return 0;
} | #include <algorithm>
#include <iostream>
#include <vector>
#define ll long long
using namespace std;
int n;
ll a[100010], b[100010];
bool vis[100010] = {0};
vector<ll> v1, v2;
ll r1, r2;
int res;
int main() {
r1 = r2 = 0;
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i], r1 += a[i];
for (int i = 0; i < n; i++) {
cin >> b[i], r2 += b[i];
if (a[i] < b[i])
v1.push_back(b[i] - a[i]);
else if (a[i] > b[i])
v2.push_back(a[i] - b[i]);
}
if (r1 < r2) {
cout << "-1";
return 0;
}
sort(v1.begin(), v1.end());
sort(v2.begin(), v2.end());
res = v1.size();
int t = v2.size();
for (int i = 0; i < v1.size(); i++) {
for (int j = v2.size() - 1; j >= 0; j--) {
vis[j] = 1;
if (v2[j] < v1[i]) {
v1[i] -= v2[j];
v2.pop_back();
} else if (v2[j] == v1[i]) {
v2.pop_back();
v1[i] = 0;
break;
} else {
v2[j] -= v1[i];
v1[i] = 0;
break;
}
}
}
res += count(vis, vis + t, 1);
cout << res;
return 0;
} | [
"identifier.change",
"variable_access.subscript.index.change",
"control_flow.branch.if.condition.change",
"assignment.value.change",
"assignment.variable.change"
] | 948,821 | 948,820 | u152424169 | cpp |
p03151 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const int INF = 1 << 30, MOD = 1000000007;
const ll LINF = 1ll << 60;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) _repi(i, 0, n)
#define _repi(i, a, b) for (int i = a, i##_l = (b); i < i##_l; ++i)
#define REP(...) _overload3(__VA_ARGS__, _repi, _rep, )(__VA_ARGS__)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define REPARR(i, v) for (int i = 0; i < v.size(); ++i)
#define all(v) (v).begin(), (v).end()
#define uniq(v) \
sort(all(v)); \
v.erase(unique(all(v)), v.end())
#define bit(n) (1ll << (n))
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define yes(n) cout << ((n) ? "yes" : "no") << endl
#define poss(n) cout << ((n) ? "" : "im") << "possible" << endl
#define Poss(n) cout << ((n) ? "P" : "Imp") << "ossible" << endl
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) {
for (T i : v)
o << i << ' ';
return o;
}
template <typename T> istream &operator>>(istream &i, vector<T> &v) {
for (T &j : v)
i >> j;
return i;
}
template <typename T> ostream &operator<<(ostream &o, const set<T> &v) {
for (T i : v)
o << i << ' ';
return o;
}
template <typename T, typename U>
ostream &operator<<(ostream &o, const pair<T, U> &v) {
o << v.first << ' ' << v.second;
return o;
}
int main() {
int n;
cin >> n;
vl a(n), b(n);
vl overs;
ll lesses = 0;
cin >> a >> b;
ll ans = 0;
REP(i, n) {
if (a[i] > b[i]) {
overs.push_back(a[i] - b[i]);
} else if (a[i] < b[i]) {
ans++;
lesses += b[i] - a[i];
}
}
cerr << ans << endl;
sort(all(a), greater<ll>());
for (ll ov : overs) {
if (lesses <= 0)
break;
lesses -= ov;
ans++;
}
if (lesses > 0)
ans = -1;
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const int INF = 1 << 30, MOD = 1000000007;
const ll LINF = 1ll << 60;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) _repi(i, 0, n)
#define _repi(i, a, b) for (int i = a, i##_l = (b); i < i##_l; ++i)
#define REP(...) _overload3(__VA_ARGS__, _repi, _rep, )(__VA_ARGS__)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define REPARR(i, v) for (int i = 0; i < v.size(); ++i)
#define all(v) (v).begin(), (v).end()
#define uniq(v) \
sort(all(v)); \
v.erase(unique(all(v)), v.end())
#define bit(n) (1ll << (n))
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define yes(n) cout << ((n) ? "yes" : "no") << endl
#define poss(n) cout << ((n) ? "" : "im") << "possible" << endl
#define Poss(n) cout << ((n) ? "P" : "Imp") << "ossible" << endl
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) {
for (T i : v)
o << i << ' ';
return o;
}
template <typename T> istream &operator>>(istream &i, vector<T> &v) {
for (T &j : v)
i >> j;
return i;
}
template <typename T> ostream &operator<<(ostream &o, const set<T> &v) {
for (T i : v)
o << i << ' ';
return o;
}
template <typename T, typename U>
ostream &operator<<(ostream &o, const pair<T, U> &v) {
o << v.first << ' ' << v.second;
return o;
}
int main() {
int n;
cin >> n;
vl a(n), b(n);
vl overs;
ll lesses = 0;
cin >> a >> b;
ll ans = 0;
REP(i, n) {
if (a[i] > b[i]) {
overs.push_back(a[i] - b[i]);
} else if (a[i] < b[i]) {
ans++;
lesses += b[i] - a[i];
}
}
cerr << ans << endl;
sort(all(overs), greater<ll>());
for (ll ov : overs) {
if (lesses <= 0)
break;
lesses -= ov;
ans++;
}
if (lesses > 0)
ans = -1;
cout << ans << endl;
return 0;
}
| [
"identifier.change",
"call.arguments.change"
] | 948,843 | 948,844 | u502709453 | cpp |
p03151 | #include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string.h>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1, 0, 0, 1, -1, -1, 1, 1};
int diry[8] = {0, 1, -1, 0, -1, 1, -1, 1};
ll MOD = 1000000007;
const ll MAX_N = 100000;
ll n;
ll a[MAX_N], b[MAX_N];
int main() {
cin >> n;
REP(i, n) cin >> a[i];
REP(i, n) cin >> b[i];
ll sa = 0, sb = 0;
REP(i, n) {
sa += a[i];
sb += b[i];
}
if (sa < sb) {
cout << -1 << endl;
return 0;
}
ll d[n];
REP(i, n) d[i] = a[i] - b[i];
sort(d, d + n);
ll ans = 0;
ll i = 0;
ll s = 0;
while (d[i] < 0) {
s += d[i];
i++;
ans++;
}
i = n - 1;
while (s < 0) {
s += d[i];
ans++;
}
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string.h>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1, 0, 0, 1, -1, -1, 1, 1};
int diry[8] = {0, 1, -1, 0, -1, 1, -1, 1};
ll MOD = 1000000007;
const ll MAX_N = 100000;
ll n;
ll a[MAX_N], b[MAX_N];
int main() {
cin >> n;
REP(i, n) cin >> a[i];
REP(i, n) cin >> b[i];
ll sa = 0, sb = 0;
REP(i, n) {
sa += a[i];
sb += b[i];
}
if (sa < sb) {
cout << -1 << endl;
return 0;
}
ll d[n];
REP(i, n) d[i] = a[i] - b[i];
sort(d, d + n);
ll ans = 0;
ll i = 0;
ll s = 0;
while (d[i] < 0) {
s += d[i];
i++;
ans++;
}
i = n - 1;
while (s < 0) {
s += d[i];
i--;
ans++;
}
cout << ans << endl;
return 0;
}
| [
"expression.unary.arithmetic.add"
] | 948,851 | 948,852 | u505831576 | cpp |
p03151 | #include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
#define int long long int
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using namespace std;
typedef pair<int, int> P;
const int INF = 1e15;
const int MOD = 1e9 + 7;
bool compare(P a, P b) { return a.first - a.second < b.first - b.first; }
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> a(n), b(n);
rep(i, n) cin >> a[i];
rep(i, n) cin >> b[i];
vector<P> x(n);
rep(i, n) x[i] = {a[i], b[i]};
sort(ALL(x), compare);
int sum = 0;
int s = -1;
rep(i, n) {
if (x[i].first >= x[i].second) {
break;
}
sum += x[i].second - x[i].first;
s = i;
}
int t = -1;
for (int i = n - 1; i >= 0; i--) {
if (x[i].first <= x[i].second) {
break;
}
if (sum <= 0) {
break;
}
sum -= x[i].first - x[i].second;
t = i;
}
if (sum > 0) {
cout << -1 << endl;
return 0;
}
if (s == -1 || t == -1) {
cout << 0 << endl;
} else {
cout << s + 1 + n - t << endl;
}
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
#define int long long int
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using namespace std;
typedef pair<int, int> P;
const int INF = 1e15;
const int MOD = 1e9 + 7;
bool compare(P a, P b) { return a.first - a.second < b.first - b.second; }
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> a(n), b(n);
rep(i, n) cin >> a[i];
rep(i, n) cin >> b[i];
vector<P> x(n);
rep(i, n) x[i] = {a[i], b[i]};
sort(ALL(x), compare);
int sum = 0;
int s = -1;
rep(i, n) {
if (x[i].first >= x[i].second) {
break;
}
sum += x[i].second - x[i].first;
s = i;
}
int t = -1;
for (int i = n - 1; i >= 0; i--) {
if (x[i].first <= x[i].second) {
break;
}
if (sum <= 0) {
break;
}
sum -= x[i].first - x[i].second;
t = i;
}
if (sum > 0) {
cout << -1 << endl;
return 0;
}
if (s == -1 || t == -1) {
cout << 0 << endl;
} else {
cout << s + 1 + n - t << endl;
}
return 0;
}
| [
"function.return_value.change",
"expression.operation.binary.change"
] | 948,853 | 948,854 | u558092537 | cpp |
p03151 | #include <bits/stdc++.h>
#include <cstdio>
using namespace std;
using ll = long long;
#define int long long
#define rep(i, a) for (int i = 0; (i) < (int)(a); (i)++)
#define reps(i, a, b) for (int i = (int)(a); (i) < (int)(b); (i)++)
#define rrep(i, a) for (int i = (int)a - 1; (i) >= 0; (i)--)
#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()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) \
sort(all(v)); \
(v).erase(unique(all(v)), v.end())
#define CIN(type, x) \
type x; \
cin >> x
#define TRUE__ "Yes"
#define FALSE__ "No"
#define PRINT(f) \
if ((f)) { \
cout << (TRUE__) << endl; \
} else { \
cout << FALSE__ << endl; \
}
#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);
template <typename T> inline T GET() {
T val;
cin >> val;
return val;
}
void init();
void solve();
signed main() {
init();
solve();
}
int N;
vector<int> v;
int need;
int res;
void init() {
cin >> N;
CINV(v, N);
rep(i, N) {
int t;
cin >> t;
v[i] -= t;
}
sort(all(v), greater<int>());
rep(i, N) {
if (v[i] < 0) {
need += -v[i];
res++;
}
}
}
void solve() {
rep(i, N) {
if (need < 0)
break;
need -= v[i];
res++;
}
if (need < 0) {
cout << res << endl;
} else {
cout << -1 << endl;
}
}
| #include <bits/stdc++.h>
#include <cstdio>
using namespace std;
using ll = long long;
#define int long long
#define rep(i, a) for (int i = 0; (i) < (int)(a); (i)++)
#define reps(i, a, b) for (int i = (int)(a); (i) < (int)(b); (i)++)
#define rrep(i, a) for (int i = (int)a - 1; (i) >= 0; (i)--)
#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()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) \
sort(all(v)); \
(v).erase(unique(all(v)), v.end())
#define CIN(type, x) \
type x; \
cin >> x
#define TRUE__ "Yes"
#define FALSE__ "No"
#define PRINT(f) \
if ((f)) { \
cout << (TRUE__) << endl; \
} else { \
cout << FALSE__ << endl; \
}
#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);
template <typename T> inline T GET() {
T val;
cin >> val;
return val;
}
void init();
void solve();
signed main() {
init();
solve();
}
int N;
vector<int> v;
int need;
int res;
void init() {
cin >> N;
CINV(v, N);
rep(i, N) {
int t;
cin >> t;
v[i] -= t;
}
sort(all(v), greater<int>());
rep(i, N) {
if (v[i] < 0) {
need += -v[i];
res++;
}
}
}
void solve() {
rep(i, N) {
if (need <= 0)
break;
need -= v[i];
res++;
}
if (need <= 0) {
cout << res << endl;
} else {
cout << -1 << endl;
}
}
| [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 948,857 | 948,856 | u946322619 | cpp |
p03151 | #include <bits/stdc++.h>
using namespace std;
int main() {
long long N;
scanf("%lld", &N);
vector<long long> A(N), B(N);
long long sa, sb;
for (auto &i : A) {
scanf("%lld", &i);
sa += i;
}
for (auto &i : B) {
scanf("%lld", &i);
sb += i;
}
if (sa < sb)
return 0 & puts("-1");
vector<long long> lg({0});
long long S(0), a(0);
for (int i = 0; i < N; ++i) {
if (A[i] < B[i]) {
S += B[i] - A[i];
++a;
} else {
lg.push_back(A[i] - B[i]);
}
}
sort(lg.rbegin(), lg.rend() - 1);
partial_sum(lg.begin(), lg.end(), lg.begin());
printf("%lld", a + (lower_bound(lg.begin(), lg.end(), S) - lg.begin()));
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
long long N;
scanf("%lld", &N);
vector<long long> A(N), B(N);
long long sa(0), sb(0);
for (auto &i : A) {
scanf("%lld", &i);
sa += i;
}
for (auto &i : B) {
scanf("%lld", &i);
sb += i;
}
if (sa < sb)
return 0 & puts("-1");
vector<long long> lg({0});
long long S(0), a(0);
for (int i = 0; i < N; ++i) {
if (A[i] < B[i]) {
S += B[i] - A[i];
++a;
} else {
lg.push_back(A[i] - B[i]);
}
}
sort(lg.rbegin(), lg.rend() - 1);
partial_sum(lg.begin(), lg.end(), lg.begin());
printf("%lld", a + (lower_bound(lg.begin(), lg.end(), S) - lg.begin()));
return 0;
} | [
"call.arguments.add"
] | 948,860 | 948,861 | u462437857 | cpp |
p03151 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MM 1000000000
#define MOD MM + 7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define Pair pair<int, int>
#define chmax(a, b) (a < b ? a = b : 0)
#define chmin(a, b) (a > b ? a = b : 0)
ll INF = 1e18;
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
int main() {
ll N;
cin >> N;
ll A[N], B[N];
ll sum = 0;
ll num = 0;
ll minus_sum = 0;
vector<ll> S_plus(0);
for (ll i = 0; i < N; i++)
cin >> A[i];
for (ll i = 0; i < N; i++)
cin >> B[i];
for (ll i = 0; i < N; i++) {
sum += (A[i] - B[i]);
if (B[i] > A[i]) {
minus_sum += (B[i] - A[i]);
num++;
} else
S_plus.push_back(B[i] - A[i]);
}
if (sum < 0) {
cout << -1 << endl;
return 0;
}
sort(S_plus.begin(), S_plus.end());
reverse(S_plus.begin(), S_plus.end());
for (ll i = 0; i < S_plus.size(); i++) {
if (minus_sum > 0) {
minus_sum -= S_plus[i];
num++;
} else
break;
}
cout << num << endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MM 1000000000
#define MOD MM + 7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define Pair pair<int, int>
#define chmax(a, b) (a < b ? a = b : 0)
#define chmin(a, b) (a > b ? a = b : 0)
ll INF = 1e18;
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
int main() {
ll N;
cin >> N;
ll A[N], B[N];
ll sum = 0;
ll num = 0;
ll minus_sum = 0;
vector<ll> S_plus(0);
for (ll i = 0; i < N; i++)
cin >> A[i];
for (ll i = 0; i < N; i++)
cin >> B[i];
for (ll i = 0; i < N; i++) {
sum += (A[i] - B[i]);
if (B[i] > A[i]) {
minus_sum += (B[i] - A[i]);
num++;
} else
S_plus.push_back(A[i] - B[i]);
}
if (sum < 0) {
cout << -1 << endl;
return 0;
}
sort(S_plus.begin(), S_plus.end());
reverse(S_plus.begin(), S_plus.end());
for (ll i = 0; i < S_plus.size(); i++) {
if (minus_sum > 0) {
minus_sum -= S_plus[i];
num++;
} else
break;
}
cout << num << endl;
}
| [
"identifier.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 948,878 | 948,879 | u342051078 | cpp |
p03151 | #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), b(n);
ll asum = 0, bsum = 0;
REP(i, n) {
cin >> a[i];
asum += a[i];
}
REP(i, n) {
cin >> b[i];
bsum += b[i];
}
if (asum < bsum) {
cout << -1 << endl;
;
return 0;
}
priority_queue<ll> p;
ll msum = 0;
ll ans = 0;
REP(i, n) {
if (a[i] > b[i]) {
p.push(a[i] - b[i]);
} else if (a[i] < b[i]) {
msum += b[i] - a[i];
ans++;
}
}
while (msum > 0) {
ll tmp = p.top();
msum -= tmp;
ans++;
}
cout << ans << endl;
} | #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), b(n);
ll asum = 0, bsum = 0;
REP(i, n) {
cin >> a[i];
asum += a[i];
}
REP(i, n) {
cin >> b[i];
bsum += b[i];
}
if (asum < bsum) {
cout << -1 << endl;
;
return 0;
}
priority_queue<ll> p;
ll msum = 0;
ll ans = 0;
REP(i, n) {
if (a[i] > b[i]) {
p.push(a[i] - b[i]);
} else if (a[i] < b[i]) {
msum += b[i] - a[i];
ans++;
}
}
while (msum > 0) {
ll tmp = p.top();
p.pop();
msum -= tmp;
ans++;
}
cout << ans << endl;
} | [
"call.add"
] | 948,905 | 948,906 | u013628553 | cpp |
p03151 | #include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(), v.end()
#define rep(i, a, b) for (i = (ll)a; i < (ll)b; i++)
#define revrep(i, a, b) for (i = (ll)a; i >= (ll)b; i--)
#define ii pair<ll, ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ii>
ll modexp(ll a, ll b) {
ll res = 1;
while (b > 0) {
if (b & 1)
res = (res * a) % mod;
a = (a * a) % mod;
b /= 2;
}
return res;
}
#define rs resize
typedef tree<ll, null_type, less<ll>, rb_tree_tag,
tree_order_statistics_node_update>
OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cout.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
#else
#define trace(...)
#endif
const ll N = 100003;
ll i, n, b, l, r;
ll a[N];
bool pos = 1;
vi x;
set<ll> ans;
int main() {
std::ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
rep(i, 0, n) cin >> a[i];
rep(i, 0, n) {
cin >> b;
x.pb({a[i] - b, i});
}
sort(all(x));
l = 0;
r = n - 1;
while (l < r) {
if (x[l].f >= 0)
break;
if (x[r].f <= 0) {
pos = 0;
break;
}
ans.insert(x[l].se);
ans.insert(x[r].se);
if (x[l].f + x[r].f == 0) {
l += 1;
r -= 1;
} else {
if (x[l].f + x[r].f > 0) {
x[r].f += x[l].f;
l += 1;
} else {
x[l].f += x[r].f;
r -= 1;
}
}
}
if (!pos)
cout << -1;
else
cout << ans.size();
return 0;
} | #include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(), v.end()
#define rep(i, a, b) for (i = (ll)a; i < (ll)b; i++)
#define revrep(i, a, b) for (i = (ll)a; i >= (ll)b; i--)
#define ii pair<ll, ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ii>
ll modexp(ll a, ll b) {
ll res = 1;
while (b > 0) {
if (b & 1)
res = (res * a) % mod;
a = (a * a) % mod;
b /= 2;
}
return res;
}
#define rs resize
typedef tree<ll, null_type, less<ll>, rb_tree_tag,
tree_order_statistics_node_update>
OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cout.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
#else
#define trace(...)
#endif
const ll N = 100003;
ll i, n, b, l, r;
ll a[N];
bool pos = 1;
vi x;
set<ll> ans;
int main() {
std::ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
rep(i, 0, n) cin >> a[i];
rep(i, 0, n) {
cin >> b;
x.pb({a[i] - b, i});
}
sort(all(x));
l = 0;
r = n - 1;
while (l <= r) {
if (x[l].f >= 0)
break;
if (x[r].f <= 0) {
pos = 0;
break;
}
ans.insert(x[l].se);
ans.insert(x[r].se);
if (x[l].f + x[r].f == 0) {
l += 1;
r -= 1;
} else {
if (x[l].f + x[r].f > 0) {
x[r].f += x[l].f;
l += 1;
} else {
x[l].f += x[r].f;
r -= 1;
}
}
}
if (!pos)
cout << -1;
else
cout << ans.size();
return 0;
} | [
"expression.operator.compare.change",
"control_flow.loop.condition.change"
] | 948,907 | 948,908 | u794573819 | cpp |
p03151 | #include <bits/stdc++.h>
using namespace std;
int main() {
long n;
cin >> n;
vector<long> a(n);
vector<long> b(n);
for (long i = 0; i < n; i++) {
cin >> a.at(i);
}
for (long i = 0; i < n; i++) {
cin >> b.at(i);
}
vector<long> d(n);
for (long i = 0; i < n; i++) {
d.at(i) = a.at(i) - b.at(i);
}
sort(d.begin(), d.end());
long long sum = 0;
for (long i = 0; i < n; i++) {
sum += d.at(i);
}
if (sum < 0) {
cout << -1 << endl;
}
else {
long j = 0; // j:A<Bとなる個数
long l = 0;
while (d.at(l) < 0) {
j++;
l++;
}
if (j == 0) {
cout << 0 << endl;
}
long long dif = 0;
for (long i = 0; i < j; i++) {
dif += d.at(i);
}
long k = 0; // k:分配に必要な個数
long long x = 0;
for (long i = 0; i < n - j; i++) {
k++;
x += d.at(n - 1 - i);
if (x + dif >= 0) {
cout << j + k << endl;
break;
}
}
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
long n;
cin >> n;
vector<long> a(n);
vector<long> b(n);
for (long i = 0; i < n; i++) {
cin >> a.at(i);
}
for (long i = 0; i < n; i++) {
cin >> b.at(i);
}
vector<long> d(n);
for (long i = 0; i < n; i++) {
d.at(i) = a.at(i) - b.at(i);
}
sort(d.begin(), d.end());
long long sum = 0;
for (long i = 0; i < n; i++) {
sum += d.at(i);
}
if (sum < 0) {
cout << -1 << endl;
}
else {
long j = 0; // j:A<Bとなる個数
long l = 0;
while (d.at(l) < 0) {
j++;
l++;
}
if (j == 0) {
cout << 0 << endl;
} else {
long long dif = 0;
for (long i = 0; i < j; i++) {
dif += d.at(i);
}
long k = 0; // k:分配に必要な個数
long long x = 0;
for (long i = 0; i < n - j; i++) {
k++;
x += d.at(n - 1 - i);
if (x + dif >= 0) {
cout << j + k << endl;
break;
}
}
}
}
return 0;
} | [
"control_flow.branch.else.add"
] | 948,919 | 948,920 | u578035814 | cpp |
p03151 | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for (ll(i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define Decimal fixed << setpresicion(20)
typedef long long ll;
typedef pair<ll, ll> P;
int main() {
ll N;
cin >> N;
vector<ll> A(N), B(N);
vector<ll> v;
ll asum = 0;
REP(i, N) {
cin >> A[i];
asum += A[i];
}
ll ans = 0, hituyo = 0;
ll bsum = 0;
REP(i, N) {
cin >> B[i];
bsum += B[i];
if (A[i] - B[i] < 0) {
ans++;
hituyo += B[i] - A[i];
}
v.PB(A[i] - B[i]);
}
if (asum < bsum) {
cout << -1 << endl;
return 0;
}
cout << ans << ' ' << hituyo << endl;
sort(ALL(v), greater<ll>());
ll sum = 0, cnt = -1;
for (ll i = 0; i < v.size(); i++) {
if (sum >= hituyo) {
cnt = i;
break;
}
sum += v[i];
}
ans += cnt;
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for (ll(i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define Decimal fixed << setpresicion(20)
typedef long long ll;
typedef pair<ll, ll> P;
int main() {
ll N;
cin >> N;
vector<ll> A(N), B(N);
vector<ll> v;
ll asum = 0;
REP(i, N) {
cin >> A[i];
asum += A[i];
}
ll ans = 0, hituyo = 0;
ll bsum = 0;
REP(i, N) {
cin >> B[i];
bsum += B[i];
if (A[i] - B[i] < 0) {
ans++;
hituyo += B[i] - A[i];
}
v.PB(A[i] - B[i]);
}
if (asum < bsum) {
cout << -1 << endl;
return 0;
}
cerr << ans << ' ' << hituyo << endl;
sort(ALL(v), greater<ll>());
ll sum = 0, cnt = -1;
for (ll i = 0; i < v.size(); i++) {
if (sum >= hituyo) {
cnt = i;
break;
}
sum += v[i];
}
ans += cnt;
cout << ans << endl;
return 0;
} | [
"identifier.change",
"expression.operation.binary.change"
] | 948,925 | 948,926 | u973997867 | cpp |
p03151 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ll n, i, j, asum = 0, bsum = 0, ans = 0, s = 0;
cin >> n;
vector<ll> a(n), b(n), plus, minus;
for (i = 0; i < n; ++i) {
cin >> a[i];
asum += a[i];
}
for (i = 0; i < n; ++i) {
cin >> b[i];
bsum += b[i];
}
for (i = 0; i < n; ++i) {
if (a[i] < b[i]) {
minus.push_back(b[i] - a[i]);
s += b[i] - a[i];
++ans;
} else {
plus.push_back(a[i] - b[i]);
}
}
if (asum - bsum < 0) {
ans = -1;
} else if (minus.size() == 0) {
ans = 0;
} else {
sort(minus.rbegin(), minus.rend());
for (i = 0; i < plus.size(); ++i) {
s -= plus[i];
++ans;
if (s <= 0) {
break;
}
}
}
cout << ans << "\n";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ll n, i, j, asum = 0, bsum = 0, ans = 0, s = 0;
cin >> n;
vector<ll> a(n), b(n), plus, minus;
for (i = 0; i < n; ++i) {
cin >> a[i];
asum += a[i];
}
for (i = 0; i < n; ++i) {
cin >> b[i];
bsum += b[i];
}
for (i = 0; i < n; ++i) {
if (a[i] < b[i]) {
minus.push_back(b[i] - a[i]);
s += b[i] - a[i];
++ans;
} else {
plus.push_back(a[i] - b[i]);
}
}
if (asum - bsum < 0) {
ans = -1;
} else if (minus.size() == 0) {
ans = 0;
} else {
sort(plus.rbegin(), plus.rend());
for (i = 0; i < plus.size(); ++i) {
s -= plus[i];
++ans;
if (s <= 0) {
break;
}
}
}
cout << ans << "\n";
return 0;
} | [
"identifier.change",
"call.arguments.change"
] | 948,927 | 948,928 | u319242216 | cpp |
p03151 | //#include <bits/stdc++.h>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <time.h>
#include <unordered_map>
#include <vector>
using namespace std;
#define sz(a) int((a).size())
#define ll long long
#define pb push_back
#define ld long double
#define mp make_pair
#define vi vector<ll>
#define all(c) (c).begin(), (c).end()
#define allr(c) (c).rbegin(), (c).rend()
#define For(i, n) for (ll i = 0; i < n; i++)
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define input(a, n) \
for (long long i = 0; i < n; i++) \
cin >> a[i]
#define output(a, n) \
for (long long i = 0; i < n; i++) \
cout << a[i] << " "
#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max(max3(a, b, c), d)
#define min3(a, b, c) min(min(a, b), c)
#define min4(a, b, c, d) min(min3(a, b, c), d)
#define she_taught_me_to_code \
cin.tie(0); \
cout.tie(0); \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define ep 1e-10
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
return (a.second < b.second);
}
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
ll pow2(ll n) {
ll x = 1;
for (ll i = 1; i <= n; i++) {
x *= 2;
}
return x;
}
#define N 1000000
vector<ll> adj[N];
vector<ll> v(N);
vector<bool> visited(N, 0);
void DFSUtil(ll u) {
visited[u] = true;
for (ll i = 0; i < adj[u].size(); i++) {
if (visited[adj[u][i]] == false) {
DFSUtil(adj[u][i]);
}
}
}
void DFS(ll n) {
for (ll u = 0; u < n; u++) {
if (visited[u] == false) {
DFSUtil(u);
}
}
}
void aE(ll u, ll v) { adj[u].push_back(v); }
int main() {
she_taught_me_to_code
ll n;
cin >> n;
vector<pair<ll, ll>> v(n);
for (ll i = 0; i < n; i++) {
cin >> v[i].first;
}
for (ll i = 0; i < n; i++) {
cin >> v[i].second;
}
ll sum = 0, ans = 0;
for (ll i = 0; i < n; i++) {
if (v[i].second > v[i].first) {
sum += (v[i].second - v[i].first);
ans++;
}
}
vector<ll> k;
for (ll i = 0; i < n; i++) {
if (v[i].first > v[i].second) {
k.pb(v[i].first - v[i].second);
}
}
sort(allr(k));
for (ll i = 0; i < k.size(); i++) {
if (sum <= 0) {
cout << ans;
return 0;
}
sum -= k[i];
ans++;
}
if (sum == 0) {
cout << ans;
} else {
cout << -1;
}
}
| //#include <bits/stdc++.h>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <time.h>
#include <unordered_map>
#include <vector>
using namespace std;
#define sz(a) int((a).size())
#define ll long long
#define pb push_back
#define ld long double
#define mp make_pair
#define vi vector<ll>
#define all(c) (c).begin(), (c).end()
#define allr(c) (c).rbegin(), (c).rend()
#define For(i, n) for (ll i = 0; i < n; i++)
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define input(a, n) \
for (long long i = 0; i < n; i++) \
cin >> a[i]
#define output(a, n) \
for (long long i = 0; i < n; i++) \
cout << a[i] << " "
#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max(max3(a, b, c), d)
#define min3(a, b, c) min(min(a, b), c)
#define min4(a, b, c, d) min(min3(a, b, c), d)
#define she_taught_me_to_code \
cin.tie(0); \
cout.tie(0); \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define ep 1e-10
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
return (a.second < b.second);
}
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
ll pow2(ll n) {
ll x = 1;
for (ll i = 1; i <= n; i++) {
x *= 2;
}
return x;
}
#define N 1000000
vector<ll> adj[N];
vector<ll> v(N);
vector<bool> visited(N, 0);
void DFSUtil(ll u) {
visited[u] = true;
for (ll i = 0; i < adj[u].size(); i++) {
if (visited[adj[u][i]] == false) {
DFSUtil(adj[u][i]);
}
}
}
void DFS(ll n) {
for (ll u = 0; u < n; u++) {
if (visited[u] == false) {
DFSUtil(u);
}
}
}
void aE(ll u, ll v) { adj[u].push_back(v); }
int main() {
she_taught_me_to_code
ll n;
cin >> n;
vector<pair<ll, ll>> v(n);
for (ll i = 0; i < n; i++) {
cin >> v[i].first;
}
for (ll i = 0; i < n; i++) {
cin >> v[i].second;
}
ll sum = 0, ans = 0;
for (ll i = 0; i < n; i++) {
if (v[i].second > v[i].first) {
sum += (v[i].second - v[i].first);
ans++;
}
}
vector<ll> k;
for (ll i = 0; i < n; i++) {
if (v[i].first > v[i].second) {
k.pb(v[i].first - v[i].second);
}
}
sort(allr(k));
for (ll i = 0; i < k.size(); i++) {
if (sum <= 0) {
cout << ans;
return 0;
}
sum -= k[i];
ans++;
}
if (sum <= 0) {
cout << ans;
} else {
cout << -1;
}
}
| [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 948,931 | 948,932 | u640641692 | cpp |
p03151 | //#include <bits/stdc++.h>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <time.h>
#include <unordered_map>
#include <vector>
using namespace std;
#define sz(a) int((a).size())
#define ll long long
#define pb push_back
#define ld long double
#define mp make_pair
#define vi vector<ll>
#define all(c) (c).begin(), (c).end()
#define allr(c) (c).rbegin(), (c).rend()
#define For(i, n) for (ll i = 0; i < n; i++)
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define input(a, n) \
for (long long i = 0; i < n; i++) \
cin >> a[i]
#define output(a, n) \
for (long long i = 0; i < n; i++) \
cout << a[i] << " "
#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max(max3(a, b, c), d)
#define min3(a, b, c) min(min(a, b), c)
#define min4(a, b, c, d) min(min3(a, b, c), d)
#define she_taught_me_to_code \
cin.tie(0); \
cout.tie(0); \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define ep 1e-10
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
return (a.second < b.second);
}
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
ll pow2(ll n) {
ll x = 1;
for (ll i = 1; i <= n; i++) {
x *= 2;
}
return x;
}
#define N 1000000
vector<ll> adj[N];
vector<ll> v(N);
vector<bool> visited(N, 0);
void DFSUtil(ll u) {
visited[u] = true;
for (ll i = 0; i < adj[u].size(); i++) {
if (visited[adj[u][i]] == false) {
DFSUtil(adj[u][i]);
}
}
}
void DFS(ll n) {
for (ll u = 0; u < n; u++) {
if (visited[u] == false) {
DFSUtil(u);
}
}
}
void aE(ll u, ll v) { adj[u].push_back(v); }
int main() {
she_taught_me_to_code
ll n;
cin >> n;
vector<pair<ll, ll>> v(n);
for (ll i = 0; i < n; i++) {
cin >> v[i].first;
}
for (ll i = 0; i < n; i++) {
cin >> v[i].second;
}
ll sum = 0, ans = 0;
for (ll i = 0; i < n; i++) {
if (v[i].second > v[i].first) {
sum += (v[i].second - v[i].first);
ans++;
}
}
vector<ll> k;
for (ll i = 0; i < n; i++) {
if (v[i].first > v[i].second) {
k.pb(v[i].first - v[i].second);
}
}
sort(allr(k));
for (ll i = 0; i < k.size(); i++) {
if (sum <= 0) {
cout << ans;
return 0;
}
sum -= k[i];
ans++;
}
if (sum >= 0) {
cout << ans;
} else {
cout << -1;
}
}
| //#include <bits/stdc++.h>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <time.h>
#include <unordered_map>
#include <vector>
using namespace std;
#define sz(a) int((a).size())
#define ll long long
#define pb push_back
#define ld long double
#define mp make_pair
#define vi vector<ll>
#define all(c) (c).begin(), (c).end()
#define allr(c) (c).rbegin(), (c).rend()
#define For(i, n) for (ll i = 0; i < n; i++)
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define input(a, n) \
for (long long i = 0; i < n; i++) \
cin >> a[i]
#define output(a, n) \
for (long long i = 0; i < n; i++) \
cout << a[i] << " "
#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max(max3(a, b, c), d)
#define min3(a, b, c) min(min(a, b), c)
#define min4(a, b, c, d) min(min3(a, b, c), d)
#define she_taught_me_to_code \
cin.tie(0); \
cout.tie(0); \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define ep 1e-10
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
return (a.second < b.second);
}
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
ll pow2(ll n) {
ll x = 1;
for (ll i = 1; i <= n; i++) {
x *= 2;
}
return x;
}
#define N 1000000
vector<ll> adj[N];
vector<ll> v(N);
vector<bool> visited(N, 0);
void DFSUtil(ll u) {
visited[u] = true;
for (ll i = 0; i < adj[u].size(); i++) {
if (visited[adj[u][i]] == false) {
DFSUtil(adj[u][i]);
}
}
}
void DFS(ll n) {
for (ll u = 0; u < n; u++) {
if (visited[u] == false) {
DFSUtil(u);
}
}
}
void aE(ll u, ll v) { adj[u].push_back(v); }
int main() {
she_taught_me_to_code
ll n;
cin >> n;
vector<pair<ll, ll>> v(n);
for (ll i = 0; i < n; i++) {
cin >> v[i].first;
}
for (ll i = 0; i < n; i++) {
cin >> v[i].second;
}
ll sum = 0, ans = 0;
for (ll i = 0; i < n; i++) {
if (v[i].second > v[i].first) {
sum += (v[i].second - v[i].first);
ans++;
}
}
vector<ll> k;
for (ll i = 0; i < n; i++) {
if (v[i].first > v[i].second) {
k.pb(v[i].first - v[i].second);
}
}
sort(allr(k));
for (ll i = 0; i < k.size(); i++) {
if (sum <= 0) {
cout << ans;
return 0;
}
sum -= k[i];
ans++;
}
if (sum <= 0) {
cout << ans;
} else {
cout << -1;
}
}
| [
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 948,933 | 948,932 | u640641692 | cpp |
p03151 | #include <bits/stdc++.h>
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) REP(i, 0, (n))
//#define int long long
typedef long long ll;
using namespace std;
const int LIM = 100000;
int n, a[LIM], b[LIM], ans, num;
int main() {
cin >> n;
rep(i, n) cin >> a[i];
rep(i, n) cin >> b[i];
vector<int> deff(n);
rep(i, n) { deff[i] = a[i] - b[i]; }
sort(deff.begin(), deff.end());
int idx = deff.size() - 1;
while (deff.size()) {
if (deff[0] >= 0)
break;
if (abs(deff[0]) > num) {
if (idx <= 0 || deff[idx] <= 0) {
cout << -1 << endl;
return 0;
} else {
num += deff[idx--];
deff.pop_back();
ans++;
}
} else {
num -= abs(deff[0]);
ans++;
deff.erase(deff.begin());
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) REP(i, 0, (n))
//#define int long long
typedef long long ll;
using namespace std;
const int LIM = 100000;
int n, a[LIM], b[LIM], ans, num;
int main() {
cin >> n;
rep(i, n) cin >> a[i];
rep(i, n) cin >> b[i];
vector<int> deff(n);
rep(i, n) deff[i] = a[i] - b[i];
sort(deff.begin(), deff.end());
int idx = deff.size() - 1;
while (deff.size()) {
if (deff[0] >= 0)
break;
if (abs(deff[0]) > num) {
if (idx <= 0 || deff[idx] <= 0) {
cout << -1 << endl;
return 0;
} else {
num += deff[idx--];
deff.pop_back();
ans++;
}
} else {
num -= abs(deff[0]);
ans++;
deff.erase(deff.begin());
idx--;
}
}
cout << ans << endl;
return 0;
} | [
"expression.unary.arithmetic.add"
] | 948,946 | 948,947 | u658655325 | cpp |
p03151 | #include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef long LL;
typedef pair<LL, LL> P;
const LL mod = 1e9 + 7;
const LL LINF = 1LL << 62;
const int INF = 1000000000;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int main() {
int N;
cin >> N;
vector<LL> a(N), b(N), x;
for (int i = 0; i < N; i++) {
cin >> a[i];
}
for (int i = 0; i < N; i++) {
cin >> b[i];
x.pb(a[i] - b[i]);
}
sort(ALL(x));
int t = 0, k = 0, cnt = 0;
;
for (int i = 0; i < N; i++) {
if (x[i] < 0) {
t -= x[i];
cnt++;
} else
k += x[i];
}
if (t > k) {
puts("-1");
return 0;
}
for (int i = N - 1; i >= 0; i--) {
if (t <= 0) {
cout << N - 1 - i + cnt << endl;
return 0;
}
t -= x[i];
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef long LL;
typedef pair<LL, LL> P;
const LL mod = 1e9 + 7;
const LL LINF = 1LL << 62;
const int INF = 1000000000;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int main() {
int N;
cin >> N;
vector<LL> a(N), b(N), x;
for (int i = 0; i < N; i++) {
cin >> a[i];
}
for (int i = 0; i < N; i++) {
cin >> b[i];
x.pb(a[i] - b[i]);
}
sort(ALL(x));
LL t = 0, k = 0, cnt = 0;
;
for (int i = 0; i < N; i++) {
if (x[i] < 0) {
t -= x[i];
cnt++;
} else
k += x[i];
}
if (t > k) {
puts("-1");
return 0;
}
for (int i = N - 1; i >= 0; i--) {
if (t <= 0) {
cout << N - 1 - i + cnt << endl;
return 0;
}
t -= x[i];
}
return 0;
}
| [
"variable_declaration.type.change"
] | 948,950 | 948,951 | u640323045 | cpp |
p03151 | #include <bits/stdc++.h>
#include <time.h>
#define ll long long int
#define F first
#define S second
#define pb push_back
#define sd(x) scanf("%d", &x)
#define sd2(x, y) scanf("%d%d", &x, &y);
#define sdl(x) scanf("%lld", &x)
#define sd2l(x, y) scanf("%lld%lld", &x, &y);
#define sz(x) (int)(x.size())
#define nax 100010
#define inf 1001000100
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define MOD 1000000007
#define mp make_pair
#define pc pair<char, int>
#define pi pair<int, int>
#define pii pair<pi, pi>
using namespace std;
int arr[nax];
int brr[nax];
vector<ll> v;
int main(int argc, char const *argv[]) {
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
int n;
sd(n);
for (int i = 1; i <= n; i++)
sd(arr[i]);
ll sum = 0;
int lo, hi;
lo = hi = 0;
ll def = 0;
int c_def = 0;
for (int i = 1; i <= n; i++) {
sd(brr[i]);
sum += arr[i] - brr[i];
if (brr[i] > arr[i]) {
def += brr[i] - arr[i];
c_def++;
} else
v.pb(arr[i] - brr[i]);
}
if (sum < 0) {
puts("-1");
return 0;
}
int siz = sz(v);
sort(v.begin(), v.end());
ll psum = 0;
int change = 0;
for (int i = siz - 1; siz >= 0; siz--) {
if (psum >= def)
break;
psum += v[i];
change++;
}
printf("%d\n", change + c_def);
return 0;
} | #include <bits/stdc++.h>
#include <time.h>
#define ll long long int
#define F first
#define S second
#define pb push_back
#define sd(x) scanf("%d", &x)
#define sd2(x, y) scanf("%d%d", &x, &y);
#define sdl(x) scanf("%lld", &x)
#define sd2l(x, y) scanf("%lld%lld", &x, &y);
#define sz(x) (int)(x.size())
#define nax 100010
#define inf 1001000100
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define MOD 1000000007
#define mp make_pair
#define pc pair<char, int>
#define pi pair<int, int>
#define pii pair<pi, pi>
using namespace std;
int arr[nax];
int brr[nax];
vector<ll> v;
int main(int argc, char const *argv[]) {
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
int n;
sd(n);
for (int i = 1; i <= n; i++)
sd(arr[i]);
ll sum = 0;
int lo, hi;
lo = hi = 0;
ll def = 0;
int c_def = 0;
for (int i = 1; i <= n; i++) {
sd(brr[i]);
sum += arr[i] - brr[i];
if (brr[i] > arr[i]) {
def += brr[i] - arr[i];
c_def++;
} else
v.pb(arr[i] - brr[i]);
}
if (sum < 0) {
puts("-1");
return 0;
}
int siz = sz(v);
sort(v.begin(), v.end());
ll psum = 0;
int change = 0;
for (int i = siz - 1; siz >= 0; i--) {
if (psum >= def)
break;
psum += v[i];
change++;
}
printf("%d\n", change + c_def);
return 0;
} | [
"identifier.change"
] | 948,959 | 948,960 | u717615117 | cpp |
p03151 | #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define FOR(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define PRINT(str) printf(#str "\n")
#define yOUT PRINT(Yes)
#define nOUT PRINT(No)
#define YOUT PRINT(YES)
#define NOUT PRINT(NO)
#define pb(a) push_back(a)
#define all(x) (x).begin(), (x).end()
int main() {
int n;
cin >> n;
vector<long long> a(n);
vector<long long> b(n);
long long suma = 0, sumb = 0;
REP(i, n) {
cin >> a[i];
suma += a[i];
}
REP(i, n) {
cin >> b[i];
sumb += b[i];
}
if (suma < sumb) {
cout << -1 << endl;
return 0;
}
vector<long long> dif(n);
REP(i, n) { dif[i] = a[i] - b[i]; }
sort(all(dif));
int ans = 0;
long long sum1 = 0, sum2 = 0;
for (int i = 0; dif[i] < 0; i++) {
sum1 += dif[i];
ans++;
}
for (int i = n - 1; sum1 + sum2 < 0; i--) {
sum2 += dif[n - 1];
ans++;
}
cout << ans << endl;
}
| #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define FOR(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define PRINT(str) printf(#str "\n")
#define yOUT PRINT(Yes)
#define nOUT PRINT(No)
#define YOUT PRINT(YES)
#define NOUT PRINT(NO)
#define pb(a) push_back(a)
#define all(x) (x).begin(), (x).end()
int main() {
int n;
cin >> n;
vector<long long> a(n);
vector<long long> b(n);
long long suma = 0, sumb = 0;
REP(i, n) {
cin >> a[i];
suma += a[i];
}
REP(i, n) {
cin >> b[i];
sumb += b[i];
}
if (suma < sumb) {
cout << -1 << endl;
return 0;
}
vector<long long> dif(n);
REP(i, n) { dif[i] = a[i] - b[i]; }
sort(all(dif));
int ans = 0;
long long sum1 = 0, sum2 = 0;
for (int i = 0; dif[i] < 0; i++) {
sum1 += dif[i];
ans++;
}
for (int i = n - 1; sum1 + sum2 < 0; i--) {
sum2 += dif[i];
ans++;
}
cout << ans << endl;
}
| [
"assignment.value.change",
"variable_access.subscript.index.change",
"expression.operation.binary.change",
"expression.operation.binary.remove"
] | 948,966 | 948,967 | u833064541 | cpp |
p03151 |
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
int main() {
int n, sum, ans;
sum = 0;
int sumsum = 0;
ans = 0;
priority_queue<int> v;
cin >> n;
int ab[100005][2] = {0};
for (int i = 1; i <= n; i++) {
cin >> ab[i][0];
}
for (int i = 1; i <= n; i++) {
cin >> ab[i][1];
if (ab[i][0] > ab[i][1]) {
v.push(ab[i][0] - ab[i][1]);
sumsum += (ab[i][0] - ab[i][1]);
}
if (ab[i][0] < ab[i][1]) {
sum += (ab[i][0] - ab[i][1]);
ans++;
// cout << 1744 << endl;
}
}
if (sum + sumsum < 0)
cout << -1 << endl;
else {
while (sum < 0) {
sum += v.top();
v.pop();
ans++;
// cout << 57 << endl;
}
cout << ans << endl;
}
} | #include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
int main() {
long long int n, sum, ans;
sum = 0;
long long int sumsum = 0;
ans = 0;
priority_queue<int> v;
cin >> n;
int ab[100005][2] = {0};
for (int i = 1; i <= n; i++) {
cin >> ab[i][0];
}
for (int i = 1; i <= n; i++) {
cin >> ab[i][1];
if (ab[i][0] > ab[i][1]) {
v.push(ab[i][0] - ab[i][1]);
sumsum += (ab[i][0] - ab[i][1]);
}
if (ab[i][0] < ab[i][1]) {
sum += (ab[i][0] - ab[i][1]);
ans++;
// cout << 1744 << endl;
}
}
if (sum + sumsum < 0)
cout << -1 << endl;
else {
while (sum < 0) {
sum += v.top();
v.pop();
ans++;
// cout << 57 << endl;
}
cout << ans << endl;
}
}
| [
"variable_declaration.type.widen.change"
] | 948,970 | 948,971 | u791146764 | cpp |
p03151 | #include <algorithm>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <deque>
#include <iomanip>
#include <math.h>
#include <numeric>
//#include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(n), b(n), c(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
unsigned long long int countf = 0;
int f = 0;
deque<unsigned long long int> plus;
for (int i = 0; i < n; i++) {
cin >> b[i];
int t = a[i] - b[i];
if (t < 0) {
countf -= t;
f++;
} else if (t > 0) {
plus.push_back(t);
}
}
// cout << countf << endl;
sort(plus.begin(), plus.end());
reverse(plus.begin(), plus.end());
int flag = 0;
if (countf == 0) {
cout << 0 << endl;
flag++;
} else {
while (plus.size() != 0) {
countf -= plus.front();
f++;
plus.pop_front();
if (countf <= 0) {
cout << f << endl;
flag++;
break;
}
}
}
if (flag == 0) {
cout << -1 << endl;
}
} | #include <algorithm>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <deque>
#include <iomanip>
#include <math.h>
#include <numeric>
//#include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(n), b(n), c(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
long long int countf = 0;
int f = 0;
deque<unsigned long long int> plus;
for (int i = 0; i < n; i++) {
cin >> b[i];
int t = a[i] - b[i];
if (t < 0) {
countf -= t;
f++;
} else if (t > 0) {
plus.push_back(t);
}
}
// cout << countf << endl;
sort(plus.begin(), plus.end());
reverse(plus.begin(), plus.end());
int flag = 0;
if (countf == 0) {
cout << 0 << endl;
flag++;
} else {
while (plus.size() != 0) {
countf -= plus.front();
f++;
plus.pop_front();
if (countf <= 0) {
cout << f << endl;
flag++;
break;
}
}
}
if (flag == 0) {
cout << -1 << endl;
}
} | [
"variable_declaration.type.narrow.change"
] | 948,974 | 948,975 | u775013393 | cpp |
p03151 | #include <algorithm>
#include <iostream>
using namespace std;
int main(void) {
int n;
cin >> n;
int a[n];
int b[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
cin >> b[i];
}
int diff[n];
for (int i = 0; i < n; i++) {
diff[i] = a[i] - b[i];
}
sort(diff, diff + n);
int less = 0;
int cnt = 0;
for (int i = 0; i < n; i++) {
if (diff[i] < 0) {
less += diff[i];
cnt++;
} else
break;
}
for (int i = n - 1; i >= 0; i++) {
if (less >= 0)
break;
if (less < 0 && diff[i] <= 0) {
cnt = -1;
break;
}
less += diff[i];
cnt++;
}
cout << cnt << endl;
return 0;
} | #include <algorithm>
#include <iostream>
using namespace std;
int main(void) {
int n;
cin >> n;
int a[n];
int b[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
cin >> b[i];
}
int diff[n];
for (int i = 0; i < n; i++) {
diff[i] = a[i] - b[i];
}
sort(diff, diff + n);
long less = 0;
int cnt = 0;
for (int i = 0; i < n; i++) {
if (diff[i] < 0) {
less += diff[i];
cnt++;
} else
break;
}
for (int i = n - 1; i >= 0; i--) {
if (less >= 0)
break;
if (less < 0 && diff[i] <= 0) {
cnt = -1;
break;
}
less += diff[i];
cnt++;
}
cout << cnt << endl;
return 0;
}
| [
"variable_declaration.type.primitive.change"
] | 948,983 | 948,982 | u809889010 | cpp |
p03151 | // VIVEK UPADHYAY
// MANIT, BHOPAL(M.P)
/**********************************************************************************************/
/**********************************************************************************************/
// $$ JAB-TAK TODEGA NHI,
// TAB -TAK CHODEGA NHI :D
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unistd.h>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
#define F first
#define S second
#define mk(x, y) make_pair(x, y)
#define pb(x) push_back(x)
#define LINE cout << "\n";
#define ok cout << "ok\n";
#define dbg(x) cout << #x << " = " << (x) << "\n";
#define fill(A, VAL) memset(A, VAL, sizeof(A))
#define sz(a) ((int)a.size())
typedef long long ll;
const int MAXN = 2 * 1e5 + 10;
const int MAX = 1e7 + 1;
double pi = 3.1415926535897932384626433832795;
const ll inf = 1e18;
ll mod = 998244353;
ll powr(ll a, ll b) {
if (b == 0)
return 1LL;
ll x = powr(a, b / 2);
x = (x * x) % mod;
if (b % 2)
return ((a % mod) * x) % mod;
return x;
}
ll gcd(ll a, ll b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
int main() {
int N;
cin >> N;
ll a[N], b[N];
for (int i = 0; i < N; i++)
cin >> a[i];
for (int i = 0; i < N; i++)
cin >> b[i];
vector<ll> d2;
vector<pair<ll, int>> d1;
for (int i = 0; i < N; i++) {
if (a[i] > b[i])
d1.pb(mk(a[i] - b[i], i));
else if (a[i] < b[i])
d2.pb(b[i] - a[i]);
}
sort(d1.begin(), d1.end()); // available
reverse(d1.begin(), d1.end());
sort(d2.begin(), d2.end()); // required
int cnt = 0;
int i = 0, j = 0;
while (i < d1.size() && j < sz(d2)) {
if (d2[j] <= d1[i].F) {
d1[i].F -= d2[j];
d2[j] = 0;
d1[i].S = 0;
j++;
} else {
d2[j] -= d1[i].F;
d1[i].S = 0;
i++;
}
}
for (int i = 0; i < d2.size(); i++)
if (d2[i]) {
cout << "-1\n";
return 0;
}
cnt += sz(d2);
for (int i = 0; i < d1.size(); i++)
if (d1[i].S == 0)
cnt++;
cout << cnt << endl;
}
// zkeyzenceszkeyence
| // VIVEK UPADHYAY
// MANIT, BHOPAL(M.P)
/**********************************************************************************************/
/**********************************************************************************************/
// $$ JAB-TAK TODEGA NHI,
// TAB -TAK CHODEGA NHI :D
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unistd.h>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
#define F first
#define S second
#define mk(x, y) make_pair(x, y)
#define pb(x) push_back(x)
#define LINE cout << "\n";
#define ok cout << "ok\n";
#define dbg(x) cout << #x << " = " << (x) << "\n";
#define fill(A, VAL) memset(A, VAL, sizeof(A))
#define sz(a) ((int)a.size())
typedef long long ll;
const int MAXN = 2 * 1e5 + 10;
const int MAX = 1e7 + 1;
double pi = 3.1415926535897932384626433832795;
const ll inf = 1e18;
ll mod = 998244353;
ll powr(ll a, ll b) {
if (b == 0)
return 1LL;
ll x = powr(a, b / 2);
x = (x * x) % mod;
if (b % 2)
return ((a % mod) * x) % mod;
return x;
}
ll gcd(ll a, ll b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
int main() {
int N;
cin >> N;
ll a[N], b[N];
for (int i = 0; i < N; i++)
cin >> a[i];
for (int i = 0; i < N; i++)
cin >> b[i];
vector<ll> d2;
vector<pair<ll, int>> d1;
for (int i = 0; i < N; i++) {
if (a[i] > b[i])
d1.pb(mk(a[i] - b[i], 1));
else if (a[i] < b[i])
d2.pb(b[i] - a[i]);
}
sort(d1.begin(), d1.end()); // available
reverse(d1.begin(), d1.end());
sort(d2.begin(), d2.end()); // required
int cnt = 0;
int i = 0, j = 0;
while (i < d1.size() && j < sz(d2)) {
if (d2[j] <= d1[i].F) {
d1[i].F -= d2[j];
d2[j] = 0;
d1[i].S = 0;
j++;
} else {
d2[j] -= d1[i].F;
d1[i].S = 0;
i++;
}
}
for (int i = 0; i < d2.size(); i++)
if (d2[i]) {
cout << "-1\n";
return 0;
}
cnt += sz(d2);
for (int i = 0; i < d1.size(); i++)
if (d1[i].S == 0)
cnt++;
cout << cnt << endl;
}
// zkeyzenceszkeyence
| [
"identifier.replace.remove",
"literal.replace.add",
"call.arguments.change"
] | 948,996 | 948,997 | u753615145 | cpp |
p03151 | #include <bits/stdc++.h>
typedef long long ll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define rep(i, m, n) for (int i = (m); i < (n); i++)
#define P pair<ll, ll>
#define pb push_back
#define mk make_pair
using namespace std;
#define Vec(a) vector<int> a
#define F first
#define S second
const int INF = 1 << 20;
const int MOD = 1e9 + 7;
int main() {
int n;
cin >> n;
ll a[n], b[n];
ll asum = 0, bsum = 0;
REP(i, n) {
cin >> a[i];
asum += a[i];
}
REP(i, n) {
cin >> b[i];
bsum += b[i];
}
if (bsum > asum) {
cout << -1 << endl;
return 0;
}
P d[n];
ll res = 0, f = 0, fsum = 0;
REP(i, n) {
P p = mk(a[i] - b[i], a[i]);
if (a[i] - b[i] < 0) {
f++;
fsum += (a[i] - b[i]) * (-1);
}
d[i] = p;
}
sort(d, d + n);
/*
REP(i,n)
cout << d[i].first << " " << d[i].second << endl;
*/
int x = n - 1;
while (fsum > 0) {
fsum -= d[x].first;
res++;
}
res += f;
cout << res << endl;
return 0;
}
| #include <bits/stdc++.h>
typedef long long ll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define rep(i, m, n) for (int i = (m); i < (n); i++)
#define P pair<ll, ll>
#define pb push_back
#define mk make_pair
using namespace std;
#define Vec(a) vector<int> a
#define F first
#define S second
const int INF = 1 << 20;
const int MOD = 1e9 + 7;
int main() {
ll n;
cin >> n;
ll a[n], b[n];
ll asum = 0, bsum = 0;
REP(i, n) {
cin >> a[i];
asum += a[i];
}
REP(i, n) {
cin >> b[i];
bsum += b[i];
}
if (bsum > asum) {
cout << -1 << endl;
return 0;
}
P d[n];
ll res = 0, f = 0, fsum = 0;
REP(i, n) {
P p = mk(a[i] - b[i], a[i]);
if (a[i] - b[i] < 0) {
f++;
fsum += (a[i] - b[i]) * (-1);
}
d[i] = p;
}
sort(d, d + n);
/*
REP(i,n)
cout << d[i].first << " " << d[i].second << endl;
*/
int x = n - 1;
while (fsum > 0) {
fsum -= d[x].first;
res++;
x--;
}
res += f;
cout << res << endl;
return 0;
}
| [
"variable_declaration.type.change",
"expression.unary.arithmetic.add"
] | 948,999 | 949,000 | u416560151 | cpp |
p03151 | #include <algorithm>
#include <cassert>
#include <cstdlib>
#include <iostream>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
//整形Shift + alt + f 2回
// int x[101],y[101],h[101];
// int koya[100001][];
/*
//ユークリッドの互除法
unsigned gcd(unsigned a, unsigned b) {
if(a < b) gcd(b, a);
unsigned r;
while ((r=a%b)) {
a = b;
b = r;
}
return b;
}
*/
/*
//桁数取得
unsigned GetDigit(unsigned num)
{
unsigned digit = 0;
while (num != 0)
{
num /= 10;
digit++;
}
return digit;
}
*/
/*
//素数の真偽
vector<bool> IsPrime;
//素数のリスト
vector<int> PrimeList;
//素数の出現回数
map<int, int> CountPrime;
void sieve(int max)
{
IsPrime.resize(max + 1, true); // IsPrimeに必要な要素数を確保
IsPrime[0] = false;
IsPrime[1] = false;
for (int i = 2; i * i <= max; i++) // 0からsqrt(max)まで調べる
if (IsPrime[i]) // iが素数ならば
for (int j = 2; i * j <= max; j++) // (max以下の)iの倍数は
IsPrime[i * j] = false; // 素数ではない
}
void mkPrimeList()
{
for (int i = 2; i <= IsPrime.size() - 1; i++)
{
if (IsPrime[i])
{
PrimeList.push_back(i);
}
}
}
void factor(int n)
{
for (auto e : PrimeList)
{
int ct = 0;
int tmp = n;
while (tmp % e == 0)
{
tmp = tmp / e;
ct++;
}
CountPrime.insert(make_pair(e, ct));
}
}
*/
/*
// index が条件を満たすかどうか
bool isOK(int index)
{
long double tmp = pow((double)index, n);
//i^n が pを超えるか
if (p < tmp)
return true;
else
return false;
}
//二分探索
int binary_search()
{
int left = 1;
int right = p;
while (right - left > 1)
{
long long int mid = left + (right - left) / 2;
if (isOK(mid))
right = mid;
else
left = mid;
}
//left は条件を満たさない最大の値、right は条件を満たす最小の値になっている
return right;
}
*/
long long int n, sum = 0, ct = 0;
vector<long long int> a, b, d;
long long int fusoku = 0;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
int tmp;
cin >> tmp;
a.push_back(tmp);
}
for (int i = 0; i < n; i++) {
int tmp;
cin >> tmp;
b.push_back(tmp);
d.push_back(a[i] - b[i]);
if (d[i] < 0) {
fusoku -= d[i];
ct++;
}
sum += d[i];
}
if (sum < 0) {
cout << sum;
cout << -1;
return 0;
}
if (fusoku == 0) {
cout << 0;
return 0;
}
sort(d.begin(), d.end(), greater<long long int>());
int i = 0;
while (fusoku > 0) {
fusoku -= d[i];
i++;
}
cout << i + ct;
return 0;
}
| #include <algorithm>
#include <cassert>
#include <cstdlib>
#include <iostream>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
//整形Shift + alt + f 2回
// int x[101],y[101],h[101];
// int koya[100001][];
/*
//ユークリッドの互除法
unsigned gcd(unsigned a, unsigned b) {
if(a < b) gcd(b, a);
unsigned r;
while ((r=a%b)) {
a = b;
b = r;
}
return b;
}
*/
/*
//桁数取得
unsigned GetDigit(unsigned num)
{
unsigned digit = 0;
while (num != 0)
{
num /= 10;
digit++;
}
return digit;
}
*/
/*
//素数の真偽
vector<bool> IsPrime;
//素数のリスト
vector<int> PrimeList;
//素数の出現回数
map<int, int> CountPrime;
void sieve(int max)
{
IsPrime.resize(max + 1, true); // IsPrimeに必要な要素数を確保
IsPrime[0] = false;
IsPrime[1] = false;
for (int i = 2; i * i <= max; i++) // 0からsqrt(max)まで調べる
if (IsPrime[i]) // iが素数ならば
for (int j = 2; i * j <= max; j++) // (max以下の)iの倍数は
IsPrime[i * j] = false; // 素数ではない
}
void mkPrimeList()
{
for (int i = 2; i <= IsPrime.size() - 1; i++)
{
if (IsPrime[i])
{
PrimeList.push_back(i);
}
}
}
void factor(int n)
{
for (auto e : PrimeList)
{
int ct = 0;
int tmp = n;
while (tmp % e == 0)
{
tmp = tmp / e;
ct++;
}
CountPrime.insert(make_pair(e, ct));
}
}
*/
/*
// index が条件を満たすかどうか
bool isOK(int index)
{
long double tmp = pow((double)index, n);
//i^n が pを超えるか
if (p < tmp)
return true;
else
return false;
}
//二分探索
int binary_search()
{
int left = 1;
int right = p;
while (right - left > 1)
{
long long int mid = left + (right - left) / 2;
if (isOK(mid))
right = mid;
else
left = mid;
}
//left は条件を満たさない最大の値、right は条件を満たす最小の値になっている
return right;
}
*/
long long int n, sum = 0, ct = 0;
vector<long long int> a, b, d;
long long int fusoku = 0;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
int tmp;
cin >> tmp;
a.push_back(tmp);
}
for (int i = 0; i < n; i++) {
int tmp;
cin >> tmp;
b.push_back(tmp);
d.push_back(a[i] - b[i]);
if (d[i] < 0) {
fusoku -= d[i];
ct++;
}
sum += d[i];
}
if (sum < 0) {
// cout << sum;
cout << -1;
return 0;
}
if (fusoku == 0) {
cout << 0;
return 0;
}
sort(d.begin(), d.end(), greater<long long int>());
int i = 0;
while (fusoku > 0) {
fusoku -= d[i];
i++;
}
cout << i + ct;
return 0;
}
| [] | 949,001 | 949,002 | u814440174 | cpp |
p03151 | #include <bits/stdc++.h>
#include <iterator>
#include <set>
using namespace std;
#define ft first
#define sd second
#define pb push_back
#define all(x) x.begin(), x.end()
#define ll long long int
#define vi vector<int>
#define vii vector<pair<int, int>>
#define pii pair<int, int>
#define plii pair<pair<ll, int>, int>
#define piii pair<pii, int>
#define viii vector<pair<pii, int>>
#define vl vector<ll>
#define vll vector<pair<ll, ll>>
#define pll pair<ll, ll>
#define pli pair<ll, int>
#define mp make_pair
#define ms(x, v) memset(x, v, sizeof x)
#define pr_vec(v) \
for (int i = 0; i < v.size(); i++) \
cout << v[i] << " ";
#define f_in(st) freopen(st, "r", stdin)
#define f_out(st) freopen(st, "w", stdout)
#define fr(i, a, b) for (i = a; i <= b; i++)
#define fb(i, a, b) for (i = a; i >= b; i--)
#define ASST(x, l, r) assert(x <= r && x >= l)
const int p = 31, po = 1, N = 2e5 + 1, M = (ll)1e9 + 1;
const int mod = 998244353;
// struct node{
// ll prefixsum,suffixsum,bettersum,totalsum;
// void create(ll val){
// prefixsum=suffixsum=bettersum=val;
// }
// void Merge(node& a,node &b){
// prefixsum=max(a.prefixsum,a.totalsum+b.prefixsum);
// suffixsum=max(b.suffixsum,a.suffixsum+b.sum);
// totalsum=a.totalsum+b.totalsum;
// }
// }
// ll dp[2][100];
vl compute(string s) {
vl has(s.length());
ll i;
for (i = 0; i < s.length(); i++) {
if (i == 0) {
has[i] = ((s[i] - 'a' + 1)) % mod;
} else
has[i] = (has[i - 1] * p + (s[i] - 'a' + 1)) % mod;
}
return has;
}
// ll g[N][N],keep[N*N];
vl g[N], a(N), gc(N), dist(N, 1), vis(N, 0);
// ll solve(ll l,ll r){
// if(l==r)
// return l;
// ll n1=solve(l,(l+r)/2);
// ll n2=solve((l+r)/2 +1,r);
// if(g[n1][n2]>0){
// keep[g[n1][n2]]=true;
// return n1;
// }
// else{
// keep[g[n2][n1]]=true;
// return n2;
// }
// }
ll ma = 0;
void dfs(ll x) {
vis[x] = 1;
// cout << x << " ";
for (auto &it : g[x]) {
if (vis[it])
continue;
dfs(it);
if (__gcd(a[x], gc[it]) != 1) {
if (dist[x] < 1 + dist[it]) {
dist[x] = 1 + dist[it];
gc[x] = __gcd(a[x], gc[it]);
}
}
}
// if(a[x]!=1)
ma = max(ma, dist[x]);
// return ma;
}
int main() {
ios_base::sync_with_stdio(0);
ll i, n;
cin >> n;
vl a(n), b(n);
ll ma = 0, mb = 0;
for (i = 0; i < n; i++) {
cin >> a[i];
ma += a[i];
}
for (i = 0; i < n; i++) {
cin >> b[i];
mb += b[i];
}
if (ma < mb) {
cout << -1;
return 0;
}
vl dif[n];
for (i = 0; i < n; i++) {
dif[i] = {a[i] - b[i], i};
}
sort(dif, dif + n);
ll j = 0, c = 0, k = 0;
for (i = n - 1; i >= 0; i--) {
// c++;
k = 0;
if (j >= i)
break;
while (dif[i][0] > 0 && dif[j][0] < 0) {
k = 1;
c++;
if (dif[i][0] < abs(dif[j][0])) {
dif[j][0] += dif[i][0];
dif[i][0] = 0;
break;
} else
dif[i][0] += dif[j][0];
j++;
// else
// break;
}
if (k)
c++;
}
cout << c << endl;
return 0;
} | #include <bits/stdc++.h>
#include <iterator>
#include <set>
using namespace std;
#define ft first
#define sd second
#define pb push_back
#define all(x) x.begin(), x.end()
#define ll long long int
#define vi vector<int>
#define vii vector<pair<int, int>>
#define pii pair<int, int>
#define plii pair<pair<ll, int>, int>
#define piii pair<pii, int>
#define viii vector<pair<pii, int>>
#define vl vector<ll>
#define vll vector<pair<ll, ll>>
#define pll pair<ll, ll>
#define pli pair<ll, int>
#define mp make_pair
#define ms(x, v) memset(x, v, sizeof x)
#define pr_vec(v) \
for (int i = 0; i < v.size(); i++) \
cout << v[i] << " ";
#define f_in(st) freopen(st, "r", stdin)
#define f_out(st) freopen(st, "w", stdout)
#define fr(i, a, b) for (i = a; i <= b; i++)
#define fb(i, a, b) for (i = a; i >= b; i--)
#define ASST(x, l, r) assert(x <= r && x >= l)
const int p = 31, po = 1, N = 2e5 + 1, M = (ll)1e9 + 1;
const int mod = 998244353;
// struct node{
// ll prefixsum,suffixsum,bettersum,totalsum;
// void create(ll val){
// prefixsum=suffixsum=bettersum=val;
// }
// void Merge(node& a,node &b){
// prefixsum=max(a.prefixsum,a.totalsum+b.prefixsum);
// suffixsum=max(b.suffixsum,a.suffixsum+b.sum);
// totalsum=a.totalsum+b.totalsum;
// }
// }
// ll dp[2][100];
vl compute(string s) {
vl has(s.length());
ll i;
for (i = 0; i < s.length(); i++) {
if (i == 0) {
has[i] = ((s[i] - 'a' + 1)) % mod;
} else
has[i] = (has[i - 1] * p + (s[i] - 'a' + 1)) % mod;
}
return has;
}
// ll g[N][N],keep[N*N];
vl g[N], a(N), gc(N), dist(N, 1), vis(N, 0);
// ll solve(ll l,ll r){
// if(l==r)
// return l;
// ll n1=solve(l,(l+r)/2);
// ll n2=solve((l+r)/2 +1,r);
// if(g[n1][n2]>0){
// keep[g[n1][n2]]=true;
// return n1;
// }
// else{
// keep[g[n2][n1]]=true;
// return n2;
// }
// }
ll ma = 0;
void dfs(ll x) {
vis[x] = 1;
// cout << x << " ";
for (auto &it : g[x]) {
if (vis[it])
continue;
dfs(it);
if (__gcd(a[x], gc[it]) != 1) {
if (dist[x] < 1 + dist[it]) {
dist[x] = 1 + dist[it];
gc[x] = __gcd(a[x], gc[it]);
}
}
}
// if(a[x]!=1)
ma = max(ma, dist[x]);
// return ma;
}
int main() {
ios_base::sync_with_stdio(0);
ll i, n;
cin >> n;
vl a(n), b(n);
ll ma = 0, mb = 0;
for (i = 0; i < n; i++) {
cin >> a[i];
ma += a[i];
}
for (i = 0; i < n; i++) {
cin >> b[i];
mb += b[i];
}
if (ma < mb) {
cout << -1;
return 0;
}
vl dif[n];
for (i = 0; i < n; i++) {
dif[i] = {a[i] - b[i], i};
}
sort(dif, dif + n);
ll j = 0, c = 0, k = 0;
for (i = n - 1; i >= 0; i--) {
// c++;
k = 0;
if (j >= i)
break;
while (dif[i][0] > 0 && dif[j][0] < 0) {
k = 1;
c++;
if (dif[i][0] < abs(dif[j][0])) {
dif[j][0] += dif[i][0];
dif[i][0] = 0;
c--;
break;
} else
dif[i][0] += dif[j][0];
j++;
// else
// break;
}
if (k)
c++;
}
cout << c << endl;
return 0;
} | [
"expression.unary.arithmetic.add"
] | 949,007 | 949,008 | u888735570 | cpp |
p03151 | #include <bits/stdc++.h>
#define $$ long long int
#define pb push_back
#define db pop_back
#define q2(n) (n % 2) == 0
#define loop(i, m, p) for ($$ i = m; i < p; ++i)
#define loopn(i, m, p) for ($$ i = p - 1; i >= m; --i)
using namespace std;
int main() {
$$ n;
cin >> n;
$$ a[n], b[n], sum = 0, ind = 0, av = 0;
loop(i, 0, n) cin >> a[i];
loop(i, 0, n) cin >> b[i];
vector<$$> v;
loop(i, 0, n) {
if (a[i] > b[i]) {
v.pb(a[i] - b[i]);
av += (a[i] - b[i]);
} else if (a[i] < b[i]) {
sum += (b[i] - a[i]);
ind++;
}
}
// cout<<ind<<"*";
if ((av >= sum) && (ind > 0)) {
sort(v.begin(), v.end());
$$ cn = 0, m = v.size() - 1;
while ((cn < sum) || (m >= 0)) {
cn += v[m];
m--;
ind++;
}
cout << ind << "\n";
} else if (sum == 0)
cout << "0\n";
else
cout << "-1\n";
return 0;
}
| #include <bits/stdc++.h>
#define $$ long long int
#define pb push_back
#define db pop_back
#define q2(n) (n % 2) == 0
#define loop(i, m, p) for ($$ i = m; i < p; ++i)
#define loopn(i, m, p) for ($$ i = p - 1; i >= m; --i)
using namespace std;
int main() {
$$ n;
cin >> n;
$$ a[n], b[n], sum = 0, ind = 0, av = 0;
loop(i, 0, n) cin >> a[i];
loop(i, 0, n) cin >> b[i];
vector<$$> v;
loop(i, 0, n) {
if (a[i] > b[i]) {
v.pb(a[i] - b[i]);
av += (a[i] - b[i]);
// cout<<"$"<<i<<"/"<<(a[i]-b[i])<<endl;
} else if (a[i] < b[i]) {
sum += (b[i] - a[i]);
// cout<<"*"<<i<<"/"<<(b[i]-a[i])<<endl;
ind++;
}
}
// cout<<ind<<"hh"<<av<<"tt"<<sum<<endl;
// $$ lap=0;
// loopn(i,0,v.size())
// {
// lap+=v[i];
// cout<<"&&"<<lap<<endl;
// }
if ((av >= sum) && (ind > 0)) {
sort(v.begin(), v.end());
$$ cn = 0, m = v.size() - 1;
while ((cn < sum) && (m >= 0)) {
cn += v[m];
m--;
ind++;
}
cout << ind << "\n";
} else if (sum == 0)
cout << "0\n";
else
cout << "-1\n";
return 0;
}
| [
"misc.opposites",
"control_flow.loop.condition.change"
] | 949,015 | 949,016 | u276573825 | cpp |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.