A. Arcane
Hint
You can use for loop
just for some test and see that every number n
has n+1 of 0 and n of 1 and n-1 of 2 and so on
.
Solution
Solution
int main(){
int t;
cin >> t;
while(t--)
{ ll x; cin >> x;
cout << (x+1) * (x+2) / 2 << "\n";
}
return 0 ;
}
Another solution
int main()
{
int t;
cin >> t;
while(t--)
{
long long n;
cin >> n;
long long ans = ((n - 1) * (n - 2) / 2) + n * 3;
cout << ans << endl;
}
return 0;
}
B. Max Window
Hint
It is 2 pointers problem and it is a popular technique called sliding window.
Solution
Solution
int main(){
ll n, d; cin >> n >> d;
vector < ll > nums(n);
for(auto & i : nums) cin >> i;
ll sum = 0;
ll ans = 0;
ll l = 0, r = 0;
ll ll1 = 0, rr = 0;
while(r < n)
{
r = max(r, l);
while(r < n && sum + nums[r] <= d)
{
sum += nums[r];
r++;
}
if(ans < r-l)
{
ans = r - l;
ll1 = l;
rr = r;
}
if(sum >= nums[l])
sum -= nums[l];
l++;
}
cout << ans << "\n";
for(ll i = ll1; i < rr; i++)
{
cout << nums[i] << " ";
}
if(ans != 0)
cout << "\n"; return 0;
}
C. Gold
Solution
Solution
#include <iostream>
ll n;
bool isgood(ll m){
return m * (m+1)/2 <= n;
}
ll bs(){
ll l = 0, r = n, best = -1;
while(l <= r){
ll m = l + (r-l)/2;
if(isgood(m)) best = m, l = m + 1;
else r = m-1;
}
return best;
}
int main()
{
lil_codi_vert();
int t; cin >> t;
while(t--){
cin >> n;
cout << bs() << "\n";
}
return 0;
}
D. NARUTO
Solution
Solution
bool isGood(ll x, vector<ll> &nums, ll n, ll t) {
ll numOfProd = 0;
for (auto& I : nums) numOfProd += x / I;
return numOfProd >= t;
}
ll BS(vector<ll> &nums, ll n, ll t) {
ll l = 1, r = 1;
while (!isGood(r, nums, n, t)) r <<= 1;
ll best = r;
while (l <= r) {
ll mid = l + (r - l) / 2;
(isGood(mid, nums, n, t) ? r = mid - 1, best = mid : l = mid + 1);
}
return best;
}
int main() {
ll n, t;
cin >> n >> t;
vector<ll> nums(n);
for (auto& I : nums) cin >> I;
cout << BS(nums, n, t) << endl;
return 0;
}
E.Gift for you
Solution
Solution
int main(){
ll n, q, x;
cin >> n;
ll arr[n]{}, prefix[n + 1]{};
for (int i = 0; i < n; i++) {
cin >> arr[i];
prefix[i + 1] = prefix[i] + arr[i];
}
cin >> q;
while (q--) {
cin >> x;
cout << lower_bound(prefix, prefix + n + 1, x) - prefix << endl;
}
return 0;
}
F. Circle
Solution
Solution
int main() {
int n;
cin >> n;
int arr[n];
for (auto& I : arr) cin >> I;
deque<int> dq;
sort(arr, arr + n, [](int a, int b) {
return a > b;
});
for (int i = 0; i < n; i++) {
(i % 2 ? dq.push_back(arr[i]) : dq.push_front(arr[i]));
}
for (auto& I : dq) {
cout << I << " ";
}
cout << endl;
return 0;
}
G. String
Solution
Solution
int main() {
ll t; cin >> t;
while(t--){
ll n, k; cin >> n >> k;
string s, t; cin >> s >> t;
map<char,int> m1,m2;
for(auto&i: s) m1[i]++;
for(auto&i: t) m2[i]++;
for(char i = 'a'; i <= 'z'; i++){
while(m1[i] > m2[i] && m1[i] >= k){
m1[i+1] += k, m1[i] -= k;
}
}
if(m1 == m2) cout << "Yes\n";
else cout << "No\n";
}
return 0;
}