feat: Add solutions for Codeforces problems 1993 A, B

This commit is contained in:
ShazidMahsrafi 2024-08-04 23:43:44 +06:00
parent 70c8441a83
commit 3a67a13275
3 changed files with 127 additions and 8 deletions

View File

@ -0,0 +1,49 @@
#include <bits/stdc++.h>
using namespace std;
#ifdef ONLINE_JUDGE
#define dbg(...)
#else
#include "Assets/debug.h"
#endif
#define int long long
#define ll long long
#define endl '\n'
#define ff first
#define ss second
#define ins insert
#define pb push_back
#define ppb pop_back
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define rep(i,a,b) for(int i=a; i<b; ++i)
#define rrep(i,a,b) for(int i=a; i>=b; --i)
#define yn(f) f? cout<<"YES\n":cout<<"NO\n"
#define FAST (ios_base::sync_with_stdio(false), cin.tie(nullptr));
ll pow(ll x,ll y,ll m=1e9+7) {ll ans=1;x%=m;while(y){if(y&1)ans=(ans*x)%m;x=(x*x)%m;y>>=1;}return ans;}
void solve()
{
int n;
string s;
cin>>n>>s;
vector<int>ct(4,0);
for(char c:s)
if(c!='?') ct[c-'A']++;
dbg(s.size(),ct);
int ans=0;
for(auto x:ct)
ans += min(x,n);
cout<<ans<<endl;
}
signed main()
{
FAST;
int TCS = 1;
cin >> TCS;
for (int TC = 1; TC <= TCS; ++TC)
{
// cout<<"Case "<<TC<<": ";
solve();
}
}

View File

@ -0,0 +1,68 @@
#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
#ifdef ONLINE_JUDGE
#define dbg(...)
#else
#include "Assets/debug.h"
#endif
#define int long long
#define ll long long
#define endl '\n'
#define ff first
#define ss second
#define ins insert
#define pb push_back
#define ppb pop_back
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define rep(i,a,b) for(int i=a; i<b; ++i)
#define rrep(i,a,b) for(int i=a; i>=b; --i)
#define yn(f) f? cout<<"YES\n":cout<<"NO\n"
#define FAST (ios_base::sync_with_stdio(false), cin.tie(nullptr));
ll pow(ll x,ll y,ll m=1e9+7) {ll ans=1;x%=m;while(y){if(y&1)ans=(ans*x)%m;x=(x*x)%m;y>>=1;}return ans;}
void solve()
{
int n;
cin>>n;
vector<int>v;
int mx=-1;
rep(i,0,n)
{
int x;
cin>>x;
if(x%2==0) v.pb(x);
else if(x>mx) mx=x;
}
if(v.empty() || mx==-1)
{
cout<<0<<endl;
return;
}
sort(all(v));
int ans=sz(v);
for(auto x:v)
{
dbg(mx,x,ans);
if(x<mx) mx+=x;
else
{
ans+=1;
break;
}
}
cout<<ans<<endl;
}
signed main()
{
FAST;
int TCS = 1;
cin >> TCS;
for (int TC = 1; TC <= TCS; ++TC)
{
// cout<<"Case "<<TC<<": ";
solve();
}
}

View File

@ -373,14 +373,16 @@ This repository contains my solutions of Codeforces problems. They are in C++ la
| 361 | 1992 A | Only Pluses | [Question](https://codeforces.com/problemset/problem/1992/A) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1992%20A%20-%20Only%20Pluses) | 361 | 1992 A | Only Pluses | [Question](https://codeforces.com/problemset/problem/1992/A) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1992%20A%20-%20Only%20Pluses)
| 362 | 1992 B | Angry Monk | [Question](https://codeforces.com/problemset/problem/1992/B) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1992%20B%20-%20Angry%20Monk) | 362 | 1992 B | Angry Monk | [Question](https://codeforces.com/problemset/problem/1992/B) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1992%20B%20-%20Angry%20Monk)
| 363 | 1992 C | Gorilla and Permutation | [Question](https://codeforces.com/problemset/problem/1992/C) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1992%20C%20-%20Gorilla%20and%20Permutation) | 363 | 1992 C | Gorilla and Permutation | [Question](https://codeforces.com/problemset/problem/1992/C) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1992%20C%20-%20Gorilla%20and%20Permutation)
| 364 | 1996 A | Legs | [Question](https://codeforces.com/problemset/problem/1996/A) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1996%20A%20-%20Legs) | 364 | 1993 A | Question Marks | [Question](https://codeforces.com/problemset/problem/1993/A) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1993%20A%20-%20Question%20Marks)
| 365 | 1996 B | Scale | [Question](https://codeforces.com/problemset/problem/1996/B) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1996%20B%20-%20Scale) | 365 | 1993 B | Parity and Sum | [Question](https://codeforces.com/problemset/problem/1993/B) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1993%20B%20-%20Parity%20and%20Sum)
| 366 | 1996 C | Sort | [Question](https://codeforces.com/problemset/problem/1996/C) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1996%20C%20-%20Sort) | 366 | 1996 A | Legs | [Question](https://codeforces.com/problemset/problem/1996/A) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1996%20A%20-%20Legs)
| 367 | 1996 D | Fun | [Question](https://codeforces.com/problemset/problem/1996/D) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1996%20D%20-%20Fun) | 367 | 1996 B | Scale | [Question](https://codeforces.com/problemset/problem/1996/B) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1996%20B%20-%20Scale)
| 368 | 1997 A | Strong Password | [Question](https://codeforces.com/problemset/problem/1997/A) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1997%20A%20-%20Strong%20Password) | 368 | 1996 C | Sort | [Question](https://codeforces.com/problemset/problem/1996/C) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1996%20C%20-%20Sort)
| 369 | 1997 B | Make Three Regions | [Question](https://codeforces.com/problemset/problem/1997/B) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1997%20B%20-%20Make%20Three%20Regions) | 369 | 1996 D | Fun | [Question](https://codeforces.com/problemset/problem/1996/D) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1996%20D%20-%20Fun)
| 370 | 1997 C | Even Positions | [Question](https://codeforces.com/problemset/problem/1997/C) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1997%20C%20-%20Even%20Positions) | 370 | 1997 A | Strong Password | [Question](https://codeforces.com/problemset/problem/1997/A) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1997%20A%20-%20Strong%20Password)
| 371 | 1997 D | Maximize the Root | [Question](https://codeforces.com/problemset/problem/1997/D) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1997%20D%20-%20Maximize%20the%20Root) | 371 | 1997 B | Make Three Regions | [Question](https://codeforces.com/problemset/problem/1997/B) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1997%20B%20-%20Make%20Three%20Regions)
| 372 | 1997 C | Even Positions | [Question](https://codeforces.com/problemset/problem/1997/C) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1997%20C%20-%20Even%20Positions)
| 373 | 1997 D | Maximize the Root | [Question](https://codeforces.com/problemset/problem/1997/D) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1997%20D%20-%20Maximize%20the%20Root)