#include<bits/stdc++.h> usingnamespace std; #define int long long intread() { int x = 0, f = 1; char ch = getchar(); while(ch < '0' || ch > '9') { if(ch == '-') f = -1; ch = getchar(); } while(ch >= '0' && ch <= '9') { x= x * 10 + ch - '0'; ch = getchar(); } return x * f; }
signedmain() { int n = read(), x = read(); vector<int> a(n); for(int i = 0; i < n; i++) a[i] = read(); int ans = 0; for(int i = 0; i < n; i++) { if(a[i] <= x) ans += a[i]; } cout << ans << endl; return0; }
#include<bits/stdc++.h> usingnamespace std; #define int long long intread() { int x = 0, f = 1; char ch = getchar(); while(ch < '0' || ch > '9') { if(ch == '-') f = -1; ch = getchar(); } while(ch >= '0' && ch <= '9') { x= x * 10 + ch - '0'; ch = getchar(); } return x * f; }
signedmain() { int n = read(); vector<int> d(n + 1); for(int i = 1; i <= n; i++) d[i] = read(); int ans = 0; for(int i = 1; i <= n; i++) { int x = i; int y = i; int j = x % 10; int k = j; bool f = 1; while(x) { if(x % 10 != j) { f = 0; break; } x /= 10; } if(f) { while(j <= d[i]) { ans++; j = j * 10 + k; } } } cout << ans << endl; return0; }
#include<bits/stdc++.h> usingnamespace std; #define int long long intread() { int x = 0, f = 1; char ch = getchar(); while(ch < '0' || ch > '9') { if(ch == '-') f = -1; ch = getchar(); } while(ch >= '0' && ch <= '9') { x= x * 10 + ch - '0'; ch = getchar(); } return x * f; }
constint N = 1010; structEdge { int u, v, w; } e[N];
int ans = 0x3f3f3f3f3f3f3f; int k, x, y; int n, m; int p[11]; intfind(int x) { if (p[x] != x) p[x] = find(p[x]); return p[x]; } voiddfs(int u, int s, int state) { if (s == m) { int t = 0, cnt; for(int i = 1; i <= 10; i++) p[i] = i; for (int i = 0; i < n; i ++ ) if (state >> i & 1) { int a = e[i + 1].u, b = e[i + 1].v, w = e[i + 1].w; a = find(a), b = find(b); if (a == b) { return; } p[a] = b; t += w; t %= k; }
ans = min(ans, t % k); return; } if (u == n) return;
for (int i = u; i < n; i ++ ) { dfs(i + 1, s + 1, state + (1 << i)); } }
signedmain() { x = read(), y = read(); k = read(); for(int i = 1; i <= y; i++) { int u = read(), v = read(), w = read(); e[i] = {u, v, w}; } n = y, m = x - 1; dfs(0, 0, 0); cout << ans; return0; }
boolunite(int i, int j, int x){ int root_i = find(i), root_j = find(j); if(root_i == root_j) return w[j]- w[i] == x; p[root_i] = root_j; w[root_i] = w[j]- w[i]-x; returntrue; }
signedmain(){ int n = read(), q = read(); for(int i = 0; i <= n; i++) p[i] = i, w[i] = 0; for(int i = 1; i <= q; i++) { int a = read(), b = read(), d = read(); if(unite(a, b, d)) cout << i << " "; } return0; }