#include<bits/stdc++.h> #define int long long usingnamespace std; using ll = longlong; using arr2 = array<int, 2>; using arr3 = array<int, 3>; constint N = (int)2e5 + 9; constint M = (int)1e5 + 9; constint mod = (int)1e9 + 7;
voidsolve(){ int n, s, x; cin >> n >> s >> x; vector<int> a(n + 5); int sum = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; sum += a[i]; } if (sum > s) { cout << "No\n"; return ; } int num = s - sum; if (num % x == 0) { cout << "Yes\n"; } else cout << "No\n"; }
#include<bits/stdc++.h> #define int long long usingnamespace std; using ll = longlong; using arr2 = array<int, 2>; using arr3 = array<int, 3>; constint N = (int)2e5 + 9; constint M = (int)1e5 + 9; constint mod = (int)1e9 + 7;
voidsolve(){ int n; cin >> n; vector<int> a(n + 5); for (int i = 1; i <= n; i++) { cin >> a[i]; } int b = n; int p1 = 0, p2 = 0; for (int i = 1; i <= n; i++) { if (a[i] != b) { p1 = i; break; } b--; } if (b == 0) { for (int i = 1; i <= n; i++) { cout << a[i] << " "; } cout << "\n"; return ; } for (int i = 1; i <= n; i++) { if (a[i] == b) { p2 = i; break; } } for (int i = 1; i < p1; i++) { cout << a[i] << " "; } for (int i = p2; i >= p1; i--) { cout << a[i] << " "; } for (int i = p2 + 1; i <= n; i++) { cout << a[i] << " "; } cout << "\n"; }
#include<bits/stdc++.h> #define int long long usingnamespace std; using ll = longlong; using arr2 = array<int, 2>; using arr3 = array<int, 3>; constint N = (int)2e5 + 9; constint M = (int)1e5 + 9; constint mod = (int)1e9 + 7;
voidsolve(){ int n, q; cin >> n >> q; vector<int> a(n + 5), b(n + 5), pre(n + 5); for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = 1; i <= n; i++) { cin >> b[i]; } for (int i = 1; i <= n; i++) { a[i] = max(a[i], b[i]); } for (int i = n - 1; i >= 1; i--) { a[i] = max(a[i], a[i + 1]); } for (int i = 1; i <= n; i++) { pre[i] = pre[i - 1] + a[i]; } while (q--) { int l, r; cin >> l >> r; cout << pre[r] - pre[l - 1] << " "; } cout << "\n";
#include<bits/stdc++.h> #define int long long usingnamespace std; using ll = longlong; using arr2 = array<int, 2>; using arr3 = array<int, 3>; constint N = (int)2e5 + 9; constint M = (int)1e5 + 9; constint mod = (int)1e9 + 7;
voidsolve(){ int n; cin >> n; vector<int> a(n + 5), b(n + 5), pre(n + 5); for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = 1; i <= n; i++) { cin >> b[i]; } for (int i = 1; i <= n; i++) { pre[i] = pre[i - 1] + b[i]; } sort(a.begin() + 1, a.begin() + 1 + n); int ans = 0; for (int i = 1; i <= n; i++) { int x = a[i]; int num = n - i + 1; int cnt = upper_bound(pre.begin() + 1, pre.begin() + 1 + n, num) - pre.begin(); cnt--; ans = max(ans, x * cnt); } cout << ans << "\n"; }
#include<bits/stdc++.h> usingnamespace std; #define int long long using arr2 = array<int, 2>; using arr3 = array<int, 3>; constint N = 1e5 + 9; constint mod = 1e9 + 7;
voidsolve(){ int n; cin >> n; set<int>s; for (int i = 1; i <= n; i++) { int x; cin >> x; s.insert(x); } vector<int>dp(n + 5, 1e12); for (int x : s) { dp[x] = 1; for (int i = 2; i * x <= n; i++) { dp[x * i] = min(dp[x * i], dp[x] + dp[i]); } } for (int i = 1; i <= n; i++) { if (dp[i] == 1e12) cout << -1 << ' '; else cout << dp[i] << ' '; } cout << '\n';
}
signedmain(){ ios::sync_with_stdio(0); cin.tie(0); int _ = 1; cin >> _; while (_--) { solve(); } return0; }
// #include<bits/stdc++.h> // #define int long long // using namespace std; // using ll = long long; // using arr2 = array<int, 2>; // using arr3 = array<int, 3>; // const int N = (int)2e5 + 9; // const int M = (int)1e5 + 9; // const int mod = (int)1e9 + 7;