Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions 1343A_Candies.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;

for(int i=2; i<10e9; i++)
{
int p = pow(2,i) - 1;
if(n%p==0)
{
cout<<n/p<<endl;
break;
}
}
}
}
48 changes: 48 additions & 0 deletions 1353B_Two_Arrays_and_Swaps.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include<bits/stdc++.h>
using namespace std;

int main()
{
int t;
cin>>t;

while(t--)
{
int n,m;
cin>>n;
cin>>m;

int a[n];
int b[n];
for(int i = 0; i<n; i++)
{
cin>>a[i];
}
for(int i = 0; i<n; i++)
{
cin>>b[i];
}

sort(a,a+n);
sort(b,b+n);

int i = 0;
int j = n-1;
while(b[j] > a[i] and m>0)
{
swap(b[j],a[i]);
j--;
i++;
m--;
}

int ans = 0;
for(int k = 0; k<n; k++)
{
ans += a[k];
}

cout<<ans<<endl;
}
return 0;
}
47 changes: 47 additions & 0 deletions 1520A_Do_Not_Be_Distracted.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include<bits/stdc++.h>
using namespace std;

int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;

string s;
cin>>s;
bool ans = true;

unordered_map<char,int>m;
for(int i = 0; i<n; i++)
{
if(m.find(s[i]) == m.end())
{
m[s[i]] = i;
}
else
{
if(m[s[i]] < i-1)
{
ans = false;
break;
}
else
{
m[s[i]] = i;
}
}
}
if(ans == true)
{
cout<<"YES"<<endl;
}
else
{
cout<<"NO"<<endl;
}
}
return 0;
}
33 changes: 33 additions & 0 deletions 1669B_Triple.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include<bits/stdc++.h>
using namespace std;

int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
unordered_map<int,int>m;
for(int i = 0; i<n; i++)
{
int x;
cin>>x;
m[x]++;
}

int ans = -1;
for(auto x : m)
{
if(x.second>2)
{
ans = x.first;
break;
}
}
cout<<ans<<endl;

}
return 0;
}
36 changes: 36 additions & 0 deletions 1671C_Dolce_Vita.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <iostream>
#include <algorithm>
using namespace std;

int main(void)
{
int tests, n, x;
cin >> tests;
for (int test = 0; test < tests; test++)
{
cin >> n >> x;
int *arr = new int[n];
for (int i = 0; i < n; i++)
cin >> arr[i];
sort(arr, arr + n);
int bags = 0;
long long totalCost = 0;
for (int i = 0; i < n; i++)
{
if (totalCost + arr[i] > x)
break;
totalCost += arr[i];
bags++;
}
long long ans = 0, lastDays = 0;
for (int i = bags; i > 0; i--)
{
long long days = ((x - totalCost) / i) + 1;
ans += (days - lastDays) * i;
lastDays = days;
totalCost -= arr[i - 1];
}
cout << ans << endl;
}
return 0;
}
20 changes: 20 additions & 0 deletions 1760A_Medium_Number.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include<bits/stdc++.h>
using namespace std;

int main(){

int t;
cin>>t;

while(t--)
{
int arr[3];
for(int i = 0; i<3; i++)
{
cin>>arr[i];
}
sort(arr,arr+3);
cout<<arr[1]<<endl;
}
return 0;
}
21 changes: 21 additions & 0 deletions 208A_Dubstep.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <iostream>
using namespace std;

int main() {
string s;
int flag=1;
cin>>s;
for(int i=0;i<s.size();i++){
if(s[i]=='W'&& s[i+1]=='U' && s[i+2]=='B'){
i+=2;
if(!flag){
cout<<" ";
}
continue;
}else {
flag=0;
cout<<s[i];
}
}
return 0;
}
45 changes: 45 additions & 0 deletions 230A_Dragons.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

#include<bits/stdc++.h>
using namespace std;

int main(){

int s,n;
cin>>s>>n;
bool win = true;

int d,p;


vector<pair<int,int>>m;
for(int i = 0; i<n; i++)
{
cin>>d>>p;
m.push_back({d,p});
}

sort(m.begin(),m.end());

for(auto x : m)
{
if(s > x.first)
{
s += x.second;
}
else
{
win = false;
break;
}
}

if(win)
{
cout<<"YES"<<endl;
}
else
{
cout<<"NO"<<endl;
}
return 0;
}
31 changes: 31 additions & 0 deletions 268A_Games.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <iostream>
#include <vector>

using namespace std;

int main()
{
int n;
cin >> n;

int number = 0;
vector<int>h(n);
vector<int>a(n);
for (int i = 0; i < n; ++i)
{
cin >> h[i] >> a[i];
for (int j = 0; j < i; ++j)
{
if (h[i] == a[j])
{
number += 1;
}
if (a[i] == h[j])
{
number += 1;
}
}
}
cout << number << endl;
return 0;
}
25 changes: 25 additions & 0 deletions 337A_Puzzles.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
int n, m, f[1000];
cin >> n >> m;
for (int i = 0; i < m; ++i)
{
cin >> f[i];
}
sort(f, f + m);
int least = f[n-1] - f[0];
for (int i = 1; i <= m - n; ++i)
{
if (f[i+n-1] - f[i] < least)
{
least = f[i+n-1] - f[i];
}
}
cout << least << endl;
return 0;
}
32 changes: 32 additions & 0 deletions 339B_Xenia_and_Ringroad.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include<iostream>
using namespace std;

int main(){

int n;
int m;
cin>>n>>m;

long long int arr[m];
for(int i = 0; i<m;i++)
{
cin>>arr[i];
}

long long int ans = arr[0]-1;

for(int i = 1; i<m; i++)
{
if(arr[i] >= arr[i-1])
{
ans += arr[i]-arr[i-1];
}
else
{
ans += n - arr[i-1];
ans += arr[i];
}
}
cout<<ans<<endl;
return 0;
}
Loading