solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; const int dx[] = {-1, -1, -1, 0, 0, 0, 1, 1, 1}; const int dy[] = {-1, 0, 1, -1, 0, 1, -1, 0, 1}; void AIA() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } long long tin(string s) { long long re = 0; for (int i = 0; i < s.size(); i++) { re *= 10; re...
1
#include<bits/stdc++.h> using namespace std; int main() { long long l,r; scanf("%lld%lld",&l,&r); r=min(r,l+5000); long long ans=2018; for(long long i=l;i<=r;i++) for(long long j=i+1;j<=r;j++) { ans=min(ans,i*j%2019); } printf("%lld\n",ans); }
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6 + 10; const long long mod = 1e9 + 1e9 + 7; char s[MAXN]; int n; long long sum[MAXN]; long long quick_pow(long long a, long long b) { long long ret = 1; while (b) { if (b & 1) ret = ret * a % mod; a = a * a % mod; b >>= 1; } return re...
6
#include <bits/stdc++.h> using namespace std; const int MAX = 2005; int cnt[MAX][2]; int main() { int n; scanf("%d", &n); memset(cnt, 0, sizeof(cnt)); for (int i = 0; i < n; ++i) { int x, y; scanf("%d%d", &x, &y); cnt[y - x + 1000][0]++; cnt[x + y][1]++; } int ans = 0; for (int i = 0; i < ...
2
#include<bits/stdc++.h> using namespace std; typedef long long ll; int x,y,cnt[5],ans; int main() { for(int i=1;i<=3;i++) { scanf("%d%d",&x,&y); cnt[x]++,cnt[y]++; } for(int i=1;i<=4;i++) if(cnt[i]&1) ans++; puts(ans<=2?"YES":"NO"); return 0; }
0
#include <bits/stdc++.h> using namespace std; int n; long long a[1111], b[1111]; int main() { cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; for (int i = 1; i <= n; ++i) cin >> b[i]; long long ans = 0; for (int i = 1; i <= n; ++i) { long long cur1 = 0, cur2 = 0; for (int j = i; j <= n; ++j) { ...
1
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool upmin(T &x, T y) { return y < x ? x = y, 1 : 0; } template <typename T> inline bool upmax(T &x, T y) { return x < y ? x = y, 1 : 0; } const long double eps = 1e-11; const long double pi = acos(-1); const int oo = 1 << 30; const long lon...
3
#include <bits/stdc++.h> char s[2001]; long long dp[2001][2001]; long long sum[2001]; int main() { int n, k; int i, j, l; scanf("%d %d", &n, &k); scanf(" %s", s); for (i = 0; i <= n; i++) for (j = 0; j <= k; j++) dp[i][j] = 0; for (i = 0; i <= k; i++) sum[i] = 0; dp[0][0] = 1; sum[0]++; for (i = 1...
5
/*author - Kishor Kumar*/ #include<bits/stdc++.h> using namespace std; #define pow2(x) ((x)*(x)); #define max3(a,b,c) max(a,max(b,c)) #define min3(a,b,c) min(a,min(b,c)) #define ll long long #define ld long double #define eb emplace_back #define pb push_back #define mod 1000000007 #define mp make_pair #define ff first ...
3
#include <bits/stdc++.h> using namespace std; inline long long read() { char c = getchar(); long long f = 1, x = 0; while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = (x << 1) + (x << 3) + (c ^ '0'); c = getchar(); } return x * f; } long ...
1
#include<ctime> #include<cmath> #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<queue> #include<vector> #define p 1000000007 #define file(x)freopen(x".in","r",stdin);freopen(x".out","w",stdout) #define rt register int #define l putchar('\n') #define ll long long #define r read() using...
0
#pragma GCC optimize("trapv") #include<bits/stdc++.h> #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define pb push_back using namespace std; using ll = long long; //using arr = array; using pi = pair<int, int>; using vi = vector<ll>; using vvi = vector<vi>; using vpi = vector<pi>; using ld = l...
0
#include <bits/stdc++.h> using namespace std; int main() { int t; long long int n, x; cin >> n; long long int b[n]; map<long long int, long long int> mp; for (int i = 0; i < n; i++) { cin >> b[i]; } for (int i = 0; i < n; i++) { mp[(i - b[i])] += b[i]; } long long int maxv = 0; for (auto x...
1
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5; long long a[N]; long long tree[N << 2]; void build(int i, int l, int r) { if (l == r) return void(tree[i] = 2 * a[l]); int mid = (l + r) >> 1; build(i << 1, l, mid); build(i << 1 | 1, mid + 1, r); tree[i] = min(tree[i << 1], tree[i << 1 | 1]...
4
#include<iostream> using namespace std; int main(){ int n; cin>>n; if(n==10||n==100||n==1000||n==10000||n==100000){ cout<<10<<endl; } else cout<<-9*(n/100000)-9*(n/10000)-9*(n/1000)-9*(n/100)-9*(n/10)+n<<endl; return 0; }
0
#include<bits/stdc++.h> #define int long long using namespace std; int a[100010],n; signed main() { ios::sync_with_stdio(0); cin.tie(0);cout.tie(0); int ans=0; cin>>n; for(int i=1;i<=n;i++){ cin>>a[i]; if(a[i]&&a[i-1])a[i]--,ans++; ans+=(a[i]>>1); a[i]&=1; } cout<<ans<<endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int n, m; scanf("%d %d", &n, &m); int maxi = max(m + (n - 1) / 3 * m + ((n - 1) % 3 > 0 && m < 4 ? (m == 1 || m == 3 ? 1 : 2) : 0), n + (m - 1) / 3 * n + ((m - 1) % 3 > 0 && n < 4 ? (n == 1 || n == 3 ? 1 : 2) : ...
4
#include <bits/stdc++.h> long double f[100000 + 5]; long double C(int n, int m) { return f[n] - f[m] - f[n - m]; } template <typename Elem_1, typename Elem_2> Elem_1 mn(Elem_1 a, Elem_2 b) { return a < b ? a : b; } int main() { f[0] = 0; for (int i = 1; i <= 100000; i++) { f[i] = f[i - 1] + log(1.0 * i); } ...
4
#include <bits/stdc++.h> using namespace std; int32_t main() { long long t, n, i, j, k; cin >> t; string s; bool hi; while (t--) { cin >> s; n = s.size(); map<char, long long> m; for (i = 0; i < n; i++) m[s[i]]++; map<char, long long>::iterator it = m.begin(); hi = true; char ch = ...
1
#include <bits/stdc++.h> using namespace std; int amount; int numbers[200005]; long long cal(int exist, int without) { if (exist < without) return (long long)exist * (without - exist); else return (long long)(amount - exist + 1) * (exist - without); } void solve() { long long res = 0; for (int i = 1; i ...
5
#include <bits/stdc++.h> using namespace std; int main() { string st, st2 = "WUB"; cin >> st; vector<char> v; int l = st.size(); int j = 0; for (int i = 0; i < l; i++) { if (st[i] == 'W' && st[i + 1] == 'U' && st[i + 2] == 'B') { if (i > 0 && j == 0) { v.push_back('1'); i += 2; ...
1
#include <bits/stdc++.h> using namespace std; const long long maxn = 27; int main() { long long i, j, k, l, m, n, a, b; cin >> n; vector<pair<int, int>> pr; int y = 500000; int x = 0; pr.push_back({x, y}); pr.push_back({x + 1, y}); pr.push_back({x, y - 1}); pr.push_back({x + 1, y - 1}); x++, y--; ...
3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int t; cin >> t; while (t--) { long long int n; cin >> n; string s; cin >> s; vector<long long int> v; long long int j = 0, temp = 1; for (int i = 1; i < n; i++) { ...
4
#include <bits/stdc++.h> using namespace std; int main() { long long n, s; cin >> n >> s; vector<long long> nums(n); for (auto &x : nums) { cin >> x; } sort(nums.begin(), nums.end()); long long answ = 0; if (nums[n / 2] > s) { for (long long i = 0; i <= n / 2; i++) { if (nums[i] > s) { ...
2
#include <bits/stdc++.h> const int N = 100001; using namespace std; long long computeXor(long long x) { long long modFour = x % 4LL; switch (modFour) { case 0: return x; case 1: return 1LL; case 2: return x + 1LL; case 3: return 0LL; } } int main() { int n; long long xo...
3
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const int inf = 0x3f3f3f3f; template <typename T = int> inline const T read() { T x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { ...
5
#include <iostream> using namespace std; int main() { int n, m; while(cin >> n >> m ,n){ int ans = 0; for(int i=0;i<n;i++){ int a; cin >> a; ans += min(a, m/n); } cout << ans << endl; } return 0; }
0
#include<bits/stdc++.h> using namespace std; int main(){ int n,k;cin>>n>>k; string s; cin>>s; int res = 0; for(int i = 0; i < n-1; i++){ if(s[i] == s[i+1]) res++; } int ans = min(n-1,res+2*k); cout<<ans; }
0
#include <bits/stdc++.h> using namespace std; long long n, m, dx, dy; long long maxn = 0, maxx, maxy; long long w[2 * 1000000 + 5]; long long x, y, q; void e_gcd(long long a, long long b) { if (b == 0) { x = 1; y = 0; q = a; return; } e_gcd(b, a % b); long long temp = x; x = y % n; y = temp ...
5
#include <bits/stdc++.h> using namespace std; bool isPrime[1000005] = {false}; vector<long long> prm; vector<long long> SPF(1000005); void sieve() { isPrime[1] = isPrime[0] = 0; long long i; SPF[1] = SPF[0] = 1; for (i = 2; i < 1000005; ++i) isPrime[i] = 1, SPF[i] = i; for (i = 2; i * i < 1000005; ++i) { ...
1
#include <bits/stdc++.h> using namespace std; int main() { int x,a,b; cin>>x>>a>>b; if(abs(a-x)<abs(b-x)) cout<<"A"<<endl; else cout<<"B"<<endl; return 0; }
0
#include <bits/stdc++.h> int ri() { int n; scanf("%d", &n); return n; } int main() { int n = ri(); int res = 0; for (int i = 0; i < n; i++) { std::string s; std::cin >> s; if (s == "E869120") res++; } std::cout << res << std::endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int a[100010]; int n, l, x, y; bool have(int jump) { int lastidx = 0; for (int i = 1; i < n; i++) { while (a[i] - a[lastidx] > jump) lastidx++; if (a[i] - a[lastidx] == jump) { return true; } } return false; } int main() { scanf("%d%d%d%d", &n, &...
4
#include<bits/stdc++.h> using namespace std; using Int = long long; template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;} struct Node{ size_t cnt; Node *p,*l,*r; Node():cnt(0){p=l=r=nullptr;} Node(Node* p):cnt...
0
#include<bits/stdc++.h> using namespace std; long long int flagE,flagW,n,ans=10000000; char prevchar='W',s[300001]; int main() { long long int i,j; cin>>n; for(i=0;i<n;i++) { cin>>s[i]; if((prevchar=='E')&&(s[i]=='E')&&((flagW-flagE-1)<ans)) ans=(flagW-flagE-1); if(s[i]=='W') flagW++; else flagE++; ...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, *Z; string s; long long sum = 0, mx = 0, mn = 0, t, x = 0; cin >> n; Z = new int[n]; for (int i = 0; i < n; ++i) { cin >> Z[i]; sum += Z[i]; } cin >> s; for (int i = 0; i < n;...
2
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 100; struct node { int x, y; } f[2 * N]; int n, pos, vt[N], a[N], b[N], dd[N]; vector<pair<int, int> > vec; bool check(int x) { if (x == 0) return 0; while (x) { if (x % 10 != 7 && x % 10 != 4) return 0; x /= 10; } return 1; } int cnt =...
4
#include <bits/stdc++.h> using namespace std; bool vis[100010]; struct note { int v, next; } edge[100010 * 3]; int head[100010], kk; void add(int from, int to) { edge[kk].next = head[from]; edge[kk].v = to; head[from] = kk++; } int cnt; void dfs(int root) { if (vis[root]) return; cnt++; vis[root] = 1; f...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b; cin >> n >> a >> b; int ans = 0; for (int i = 1; i <= n; i++) { if (n - i <= b && i > a) ans++; } cout << ans; }
1
#include <bits/stdc++.h> using namespace std; const long long maxn = 1e5 + 5; void c_p_c() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } bool isPrime(long long n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (long long i = 5; i * i <= n;...
1
#include <bits/stdc++.h> using namespace std; long long n, k, a, b; struct bitch { long long b[200100]; bitch() { memset(b, 0, sizeof b); } void reset() { memset(b, 0, sizeof b); } void update(int at, int val) { for (int i = at; i < 200100; i += (i & (-i))) b[i] += val; } long long query(int at) { l...
4
#include <bits/stdc++.h> using namespace std; const int MAX = 405, MOD = 1e9 + 7; int n, k, a[MAX], b[MAX], t[MAX][MAX], dp[MAX][MAX]; int main() { scanf("%d%d", &n, &k); for(int i = 1; i <= n; i++) scanf("%d", &a[i]); for(int i = 1; i <= n; i++) scanf("%d", &b[i]); for(int p = 0; p <= 400; p++) { for(...
0
#include <bits/stdc++.h> using namespace std; long long qpow(long long b, long long e) { if (e == 0) return 1LL; if (e & 1LL) return qpow(b, e - 1LL) * b; return qpow(b * b, e >> 1LL); } int main() { long long n, x, y; cin >> n >> x >> y; long long a = max(n - x, n - y); long long b = max(x - 1, y - 1); ...
1
#include "bits/stdc++.h" using namespace std; const int MX = 1e5 + 5; const int INF = 2e9; int N, A[MX]; void solve() { cin >> N; for (int i = 0; i < N; i++) cin >> A[i]; sort(A, A + N); int bZ = 0, Z = 0, aZ = 0; for (int i = 0; i < N; i++) { if (A[i] == 0) Z++; if (A[i] > 0) aZ++; if (A[i] < 0) bZ++; ...
2
#include <bits/stdc++.h> using namespace std; bool visited[200000]; long long mem[200000]; int a[200000]; int n; long long run23(int x) { if (visited[x]) return mem[x]; visited[x] = true; long long dy = a[x]; int newx = x + a[x]; if (newx >= n) { mem[x] = dy; return dy; } dy += a[newx]; newx -= ...
2
#include <bits/stdc++.h> using namespace std; const int N = 2000 + 5; const int inf = 2e9 + 5; int n; int a[N]; int first[N]; bool tmp = false; void xuli() { int s = 0; for (int i = 1; i <= n; i++) { if (first[i] == 1) s += a[i]; else s -= a[i]; } if (s % 360 == 0) tmp = true; } void thu(int...
2
#include <bits/stdc++.h> #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; int main() { std::ios::sync_with_stdio(false); cin.tie(0); cin.exceptions(cin.failbit); int T; cin >> T; while...
1
#include <bits/stdc++.h> using namespace std; long long k, a[100005]; int n; bool check(long long x) { long long sum = 0; for (int i = 1; i <= n; i++) if (a[i] < x) sum += a[i]; else sum += x - 1; return sum <= k; } int main() { cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; lo...
2
#include<iostream> #include<algorithm> #include<vector> using namespace std; int main() { int q; cin >> q; vector<int> v; for(int i=0; i<q; i++) { int a; cin >> a; if(a==0) { int b; cin >> b; v.push_back(b); } else if(a==1) { int b; cin >...
0
#include <algorithm> #include <iostream> using namespace std; int main() { int n; cin >> n; int a[100005]; for(int i = 1; i <= n; i++) cin >> a[i]; a[n + 1] = 0; sort(a + 1, a + n + 1, greater<int>()); int f = 0, s = 0; for(int i = 1; i <= n; i++){ if(a[i] > a[i + 1]){ ...
0
#include<iostream> using namespace std; int n, p; int dp[101][76]; bool isp(int n){ for (int i = 2; i * i <= n; ++i)if (n % i == 0)return 0; return 1; } int main(){ cin >> n; dp[0][1] = 1; for (int i = 2; i <= n; ++i){ if (isp(i) == 0)continue; int cnt = 0; for (int j = 1;...
0
#include <bits/stdc++.h> using namespace std; int gi() { int res = 0, w = 1; char ch = getchar(); while (ch != '-' && !isdigit(ch)) ch = getchar(); if (ch == '-') w = -1, ch = getchar(); while (isdigit(ch)) res = res * 10 + ch - '0', ch = getchar(); return res * w; } const int INF = 1e9; const int MAX_...
0
#include <iostream> using namespace std; int main() { int N, K; string S; cin >> N >> S >> K; char c = S[K - 1]; for (auto &s : S) { s = (s == c ? s : '*'); } cout << S << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; template <typename T> T gcd(T a, T b) { if (a == 0) return b; return gcd(b % a, a); } template <typename T> T pow(T a, T b, long long m) { T ans = 1; while (b > 0) { if (b % 2 == 1) ans = (ans * a) % m; b /= 2; a = (a * a) % m; } return ans % m; } ve...
3
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long INFLL = 0x3f3f3f3f3f3f3f3fLL; const int mod = 1e9 + 7; const int MX = 2e5 + 5; struct Edge { int u, v, w, nxt; } E[MX * 5]; int head[MX], rear; void edge_add(int u, int v, int w = 0) { E[rear] = Edge{u, v, w, head[u]}; head[...
2
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int maxn=1e9+7; ll ksm(ll a,ll b) { ll ans=1; while(b) { if(b&1) ans=ans*a%maxn; a=a*a%maxn; b>>=1; } return ans; } ll kl(ll a,ll b) { ll ca=1,cb=1; if(a<b) { return 0; } else if(a==b) { return 1; } else { for(ll i=0;i<b;...
0
#include <bits/stdc++.h> using namespace std; string a; int b; int long long c = 1; int long long ans = 0; int main() { cin >> a; b = a.length() - 1; for (int x = 0; x <= b; x++) { int long long t = 1; if (a[x] == '1') { for (int y = 0; y < 2 * b - x; y++) { t *= 2; t %= 1000000007; ...
1
#include <bits/stdc++.h> using namespace std; int main() { int a, b, n, m, i; char s[110], c, d; scanf("%d%d", &n, &m); scanf("%s", s + 1); while (m) { scanf("%d%d", &a, &b); cin >> c >> d; for (i = a; i <= b; i++) { if (s[i] == c) s[i] = d; } m--; } for (i = 1; i <= n; i++) prin...
1
#include <bits/stdc++.h> using namespace std; vector<long long int> getPrimes(long long int n) { bool prime[n + 1]; vector<long long int> primes; for (long long int p = 2; p * p <= n; p++) if (!prime[p]) for (long long int i = p * p; i <= n; i += p) prime[i] = true; for (long long int p = 2; p <= n; p...
6
#include <bits/stdc++.h> using namespace std; struct DS { vector<int> p; vector<int> c; DS(int n) : p(n, 0), c(n, 1) { for (int i = 0; i < n; ++i) p[i] = i; } int SetOf(int x) { return (p[x] == x) ? x : p[x] = SetOf(p[x]); } bool Merge(int x, int y) { x = SetOf(x); y = SetOf(y); if (x == y) ...
5
#include<bits/stdc++.h> using namespace std; int main(){ int ans=0,a; for(int i=0;i<5;i++){ cin>>a; if(a<40){ a=40; } ans+=a; } cout<<ans/5<<endl; }
0
#include <bits/stdc++.h> using namespace std; const int N = 100002; int n, cnt[N]; vector<vector<int> > g(N); long long ans; void dfs(int i, int p) { cnt[i] = 1; long long sum = 0; for (int j : g[i]) if (j != p) { dfs(j, i); sum += 1ll * cnt[j] * cnt[i]; cnt[i] += cnt[j]; } ans -= sum ...
4
#include<bits/stdc++.h> using namespace std; #define LL long long #define MOD 998244353 LL N, M, K; LL qpow(LL base, LL pow) { return pow?((pow&1?base:1)*qpow(base*base%MOD, pow/2))%MOD:1; } LL qpow2(LL base, LL pow) { LL res = 1; while(pow) { if(pow&1) { res = res*base%MOD; ...
0
#include <bits/stdc++.h> using namespace std; const int dx[8] = {0, -1, 0, 1, -1, -1, 1, 1}, dy[8] = {1, 0, -1, 0, -1, 1, -1, 1}; struct node { int x, y; } a[1000005]; int n, p[1000005]; bool vis[1000005]; bool cmp(node x, node y) { if (x.y == y.y) return x.x < y.x; return x.y < y.y; } int main() { ci...
4
#include <bits/stdc++.h> using namespace std; int rui[2005][2005] = {}, n, m; char first[2005][2005]; int main() { srand((unsigned int)time(NULL)); scanf("%d %d", &n, &m); for (int i = 0; i < n; i++) scanf("%s", &first[i]); int lx = 2000000000, ly = 2000000000, rx = -2000000000, ry = -2000000000; for (int i =...
4
#include <bits/stdc++.h> #pragma GCC target("avx2") #pragma GCC optimization("O3") #pragma GCC optimization("unroll-loops") using namespace std; struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 2000; const int dr[] = {3, 2, 1, 0, -3, -2, -1, 0, 2, 1, 0, -3, -2, -1}; const int dc[] = {0, 1, 2, 3, 0, 1, 2, 3, -1, -2, -3, 0, -1, -2}; const int MAXN = 2000; const int INF = 0x3f3f3f3f; long long n, m; int cnt; int g[maxn][maxn]; map<pair<int, int>, int...
2
#include<iostream> #include<vector> #include<algorithm> using namespace std; bool check(int n,int wei,vector<int> book) { int tmp=wei; n--; for(int i=0;i<book.size();i++) { if(tmp<book[i]) { if(n>0) { n--; tmp=wei; if(tmp<book[i]) return false; } else return ...
0
#include <iostream> using namespace std; typedef long long ll; ll n,a,b,ans=-1,tot; int main(void){ cin>>n; for(int i=0;i<n;i++){ cin>>a>>b; ans+=b; tot+=(a*b); } ans+=(tot-1)/9; cout<<ans<<endl; }
0
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; string s; cin >> s; int i; for (i = 0; i < n; i++) { if (s[i] == 'A') { break; } } int cnt = 0; int mx = INT_MIN; for (i = i + 1; i < n; i++) { ...
1
#include <bits/stdc++.h> using namespace std; template <class num> inline void rd(num &x) { char c; while (isspace(c = getchar())) ; bool neg = false; if (!isdigit(c)) neg = (c == '-'), x = 0; else x = c - '0'; while (isdigit(c = getchar())) x = (x << 3) + (x << 1) + c - '0'; if (neg) x = -x; ...
6
#include <bits/stdc++.h> using namespace std; const int N = 200005; struct Query { int k, pos, id; } q[N]; vector<pair<int, int> > v; int n, m, a[N], res[N], bit[N]; bool cmp(pair<int, int> first, pair<int, int> second) { if (first.first == second.first) return first.second < second.second; return first.first > s...
2
#include <bits/stdc++.h> using namespace std; int jie[200010], tree[200010], num[200010]; int n; int lowbit(int x) { return x & (-x); } void update(int x, int date) { for (; x <= n; x += lowbit(x)) { tree[x] += date; } } int query(int x) { int sum = 0; for (; x > 0; x -= lowbit(x)) sum += tree[x]; return ...
2
#include <bits/stdc++.h> namespace MyMinMax { template <typename T> inline T mn(T x, T y) { return x < y ? x : y; } template <typename T> inline T mx(T x, T y) { return x > y ? x : y; } template <typename T> inline void chmin(T &x, T y) { (x > y) && (x = y); } template <typename T> inline void chmax(T &x, T y) { ...
4
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:268435456") using namespace std; template <class T> T sqr(T a) { return a * a; } int a[100010]; map<int, int> b; int n, k; int main() { cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); for (int i = 0; i < n; i++) { if (a[i] % ...
1
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 1; void testcase() { int n, m; cin >> n >> m; if (m % 2) { for (int i = 1; i <= n; i++) { int a1, a2, a3, a4; cin >> a1 >> a2 >> a3 >> a4; } cout << "NO" << endl; } else { int check = 0; for (int i = 1; i <= n; i++...
2
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void smin(T &a, U b) { if (a > b) a = b; } template <typename T, typename U> inline void smax(T &a, U b) { if (a < b) a = b; } template <class T> inline void gn(T &first) { char c, sg = 0; while (c = getchar(), (c > '9' || c ...
5
#include <bits/stdc++.h> using namespace std; void yes() { cout << "YES" << '\n'; } void no() { cout << "NO" << '\n'; } int gcd(unsigned long long a, unsigned long long b) { if (b == 0) return a; return gcd(b, a % b); } bool compare(pair<unsigned long long, int> &a, pair<unsigned long long, int> &b) { ...
1
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll inf = 1e9; const ll maxn = 610; int a[maxn*maxn], b[maxn*maxn]; double f[maxn], ans; vector <int> vec[maxn]; ll n, m; double DP(double p) { for(int i = 1; i <= n; ++i) { f[i] = 0; } f[n] = 0; for(int i = n - 1; i >= 1; --i){ ll len = v...
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 500 + 10; int T, n, m, b, mod, a[MAXN], dp[2][MAXN][MAXN]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); T = 1; while (T--) { cin >> n >> m >> b >> mod; for (int i = 1; i <= n; i++) { cin >> a[i]; } dp[0]...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int a[n]; vector<int> ind; for (int i = 0; i < n; i++) cin >> a[i]; int count = 0; while (k >= 0) { int m = 111; int i, ans; for (i = 0; i < n; i++) { if (a[i] < m) { m = a[i]; ans = i; ...
1
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; using vi = vector<int>; const ld EPS = 1E-9; struct pt { ld x, y; }; struct seg { pt p, q; int id; ld get_y(ld x) const { if (abs(p.x - q.x) < EPS) return p.y; ...
6
#include <bits/stdc++.h> using namespace std; int main() { int n, d; cin >> n >> d; vector<int> vec(n); for (int i = 0; i < n; i++) cin >> vec[i]; long long ans = 0; int l, h, m; for (int i = 0; i <= n - 3; i++) { if ((vec[i + 1] - vec[i]) < d) { l = i + 2; h = n - 1; while (l <= h) ...
1
#include <bits/stdc++.h> using namespace std; bool check(int mid, int *arr, int m, int n) { int total = 0; for (int i = 0; i < n; i++) { total += max(0, arr[i] - i / mid); if (total >= m) return true; } return false; } int main() { int n, m, ar; cin >> n >> m; vector<int> arr; for (int i = 0; i ...
4
#include <bits/stdc++.h> using namespace std; int n, a, s; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a; s += a; } for (int i = 1; i <= n; i++) { cin >> a; s -= a; } if (s < 0) { cout << "No" << endl; } else { cout << "Yes" << endl; } }
1
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, c = 1, i; cin >> n >> m; long long a[m]; for (i = 0; i < m; i++) cin >> a[i]; for (i = 0; i < m; i++) { if (a[i] <= a[i + 1]) { } else c++; } if (c > 1) cout << (n) * (c - 2) + (n - 1) + a[m - 1]; else cout ...
2
#include <bits/stdc++.h> using namespace std; class Timer { clock_t start; string name; public: Timer() { name = ""; start = clock(); } Timer(string s) { name = s; start = clock(); } ~Timer() { fprintf(stderr, "%s: %.3gs\n", name.c_str(), 1.0 * (clock() - start) / CLOCKS_...
3
#include <bits/stdc++.h> using namespace std; const long long MAXN = 1e5 + 10; struct fenwick { long long a[MAXN]; fenwick() { fill(a, a + MAXN, 0); } void update(long long id, long long val) { for (; id < MAXN; id += ((id) & -(id))) { a[id] += val; } } long long get_sum(long long id) { long...
5
#include <bits/stdc++.h> int main() { int a, b; scanf("%d %d", &a, &b); long long x, y, z; scanf("%lld %lld %lld", &x, &y, &z); long long tmpx = x * 2 + y, tmpz = 3 * z + y; if (b > tmpz) b = tmpz; if (a > tmpx) a = tmpx; if (tmpx - a + tmpz - b < 0) printf("0"); else printf("%lld", tmpx - a +...
1
#include <bits/stdc++.h> using namespace std; using ll = long long; template <typename... t> using V = vector<t...>; template <typename t> void print(ostream& os, const t& a) { os << a << '\n'; } template <typename t, typename... v> void print(ostream& os, const t& a, v&&... b) { os << a << ' '; print(os, b...); ...
4
/*{{{*/ #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<algorithm> #include<string> #include<iostream> #include<sstream> #include<set> #include<map> #include<queue> #include<bitset> #include<vector> #include<limits.h> #include<assert.h> #define SZ(X) ((int)(X).size()) #define ALL(X) (X).be...
0
#include <bits/stdc++.h> using namespace std; inline int read() { int res = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') res = res * 10 + ch - '0', ch = getchar(); return res * f; } inline void write(int x) { ...
2
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define rrep(i, n) for (int i = n - 1; i >= 0; i--) using namespace std; #define INF ((1<<30)-1) #define LINF (1LL<<60) #define EPS (1e-10) typedef long long ll; typedef pair<ll, ll> P; const int MOD = 1000000007; const int MOD2 = 998244353; ll a[5...
0
#include <bits/stdc++.h> using namespace std; ifstream fin; ofstream fout; FILE *outt, *inn; const int N = 100009, M = 70; int k, b[M], d[M], k2, y, yy; unsigned long long m, c[M][M], l, r, cur; void find() { for (int i = 0; i <= 64; i++) { for (int j = 0; j <= 64; j++) { if (i == 0) { c[i][j] = 1; ...
4
#include<bits/stdc++.h> int main(){long double a,b,x;std::cin>>a>>b>>x;std::cout<<std::fixed<<(b>2*x/(a*a)?atan(b/(2*x/(a*b)))*180/acos(-1):atan((b-x/(a*a))/(a/2))*180/acos(-1));}
0
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC target("sse4") using namespace std; int n, k, m; long long ans; vector<pair<int, pair<int, int> > > ed, edx; vector<pair<int, int> > e[((int)501 * 1000)]; int par[((int)19)][((int)501 * 1000)], dis[((int)501 * 1000)]; int pari[((int)501 * 1000)]; int root(...
6
#include <iostream> #include <vector> #include <algorithm> #include <string> #include <sstream> #include <cstring> #include <cstdio> #include <cstdlib> #include <cmath> #include <queue> #include <stack> #include <map> #include <set> #include <numeric> #include <cctype> #include <tuple> #ifdef _MSC_VER #include <agents...
0
#include <bits/stdc++.h> #define long long long int using namespace std; // @author: pashka vector<vector<int>> g, gr; vector<bool> z; vector<int> p; void dfs1(int x) { if (z[x]) return; z[x] = true; for (int y : g[x]) dfs1(y); p.push_back(x); } vector<int> c; int cc; void dfs2(int x) { if (z[x...
6
#include<bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)(n);i++) #define fs first #define sc second using namespace std; typedef pair<int,int> pii; typedef pair<pii,int> tri; int n,m; vector<tri> g[10100]; int dis[10100], cost[10100]; int main(){ while(scanf("%d%d",&n,&m), n){ rep(i,n)g[i].clear(); rep(...
0
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -1; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; return x * f; } const int MAXN = 1000010; const int INF = 2147483600; struct data { int...
4