EDITORIAL SIZLARGA YORDAM BERISH MAQSADIDA QO'YILDI SHUNDAY EKAN MISOLLARNI ISHLANISHINI KO'CHIRMASDAN QANDAY ISHLANGANINI KO'RIB YOKI IDEASINI TUSHUNIB O'ZINGIZ QAYTA ISHLASHGA HARAKAT QILIB KO'RING. TUSHUNGANIGIZ UCHUN RAXMAT!!!
A masalaning ishlanishi.
a = int(input())
b = int(input())
d = abs(a - b)
print((d + 1) // 2)
B masala uchun editorial Foiz topish formulasidan foydalanamiz !!!
a=str(input())
kiharf=0
kaharf=0
son=0
belgi=0
bel=["*","+","-","=","@","#","$","%","^","&","(",")"]
a=a.replace(" ","")
for i in a:
if ord(i)>=48 and ord(i)<=57:
son+=1
elif ord(i)>=97 and ord(i)<=122:
kiharf+=1
elif ord(i)>=65 and ord(i)<=90:
kaharf+=1
if i in bel:
belgi+=1
ans1=(100*kaharf)//len(a)
ans2=(100*kiharf)//len(a)
ans3=(100*son)//len(a)
ans4=(100*belgi)//len(a)
print(f"katta harflar: {ans1} %")
print(f"kichik harflar: {ans2} %" )
print(f"sonlar: {ans3} %")
print(f"belgilar: {ans4} %")
C masalaning ishlanishi.
C masalada biz prefix sum dan foydalanamiz birinchi bizga A massiv berilgan bo'lsin biz undan bitta urinish bilan bitta yoki ikkita elementini o'chira olsak biz birinchi A massivni so'rt qilib olishimizga to'g'ri keladi. keyin K marta undagi eng katta yoki eng kichik elementni o'chirib maksimum yig'indi hosil qilamiz bunda vizga prefix yig'indi yordam beradi. Prefix yig'indini bilmaydiganlar uchun https://t.me/robocontestuzwithme kanaliga kirib jo'rishingiz mumkun
# include <bits/stdc++.h>
using namespace std;
void solution(){
int n, k;
cin >> n >> k;
vector<int> a(n);
for(int i=0; i<n; i++) cin >> a[i];
sort(a.begin(), a.end());
vector<int> sum(n, 0);
sum[0] = a[0];
for (int i = 1; i < n; i++) {
sum[i] = sum[i - 1] + a[i];
}
int l, r;
int ans = 0;
for (int i = 0; i <= k; i++) {
l = 2 * i;
r = n - k + i - 1;
ans = max(ans, sum[r] - sum[l] + a[l]);
}
cout << ans << endl;
}
int main(){
int q = 1;
while(q--) solution();
}
D masala Ishlash uchun sal qiyinroq Ammo Breath-first-search bilan ishlasa bo'ladi
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int sx,sy,ex,ey;
cin>>sx>>sy>>ex>>ey;
vector<vector<int>> dist(n,vector<int>(n,0));
sx--;
sy--;
ex--;
ey--;
queue<vector<int>> q;
q.push({sx,sy});
int dx[8]={1,-1,2,2,-2,-2,-1,1};
int dy[8]={2,2,1,-1,1,-1,-2,-2};
vector<int> minn;
while(!q.empty()){
auto node = q.front();
q.pop();
int nx,ny;
for(int i=0;i<8;i++){
nx=node[0]+dx[i];
ny=node[1]+dy[i];
if(nx>=0 && ny>=0 && nx<n && nx>=0 && ny>=0 && ny<n && dist[nx][ny]==0){
dist[nx][ny]=dist[node[0]][node[1]]+1;
q.push({nx,ny});
}
if(nx==ex && ny==ey) {
minn.push_back(dist[nx][ny]);
break;
}
}
}
int mi=10e6;
for(int i=0;i<minn.size();i++){
if (minn[i]<mi) mi=minn[i];
}
cout<<mi;
}
E ham (Breath-first-search ) bilan ishlanadi
#include <bits/stdc++.h>
using namespace std;
#define inf 10e6
int main(){
int n=8;
char x1,x2;
int y1,y2,sx,sy,ex,ey;
cin>>x1;
sx=int(x1)-97;
cin>>y1;
sy=y1-1;
cin>>x2;
ex=int(x2)-97;
cin>>y2;
ey=y2-1;
vector<vector<vector<int>>> dist(2,vector<vector<int>>(8,vector<int>(8,inf)));
queue<vector<int>> q;
q.push({sx,sy});
dist[0][sx][sy]=0;
dist[1][ex][ey]=0;
int dx[8]={1,-1,2,2,-2,-2,-1,1};
int dy[8]={2,2,1,-1,1,-1,-2,-2};
while(!q.empty()){
auto node = q.front();
q.pop();
int nx,ny;
for(int i=0;i<8;i++){
nx=node[0]+dx[i];
ny=node[1]+dy[i];
if(nx>=0 && ny>=0 && nx<n && ny<n){
if(dist[0][node[0]][node[1]]+1<dist[0][nx][ny]){
dist[0][nx][ny]=dist[0][node[0]][node[1]]+1;
q.push({nx,ny});
}
}
}
}
queue<vector<int>> q1;
q1.push({ex,ey});
while(!q1.empty()){
auto node = q1.front();
q1.pop();
int nx,ny;
for(int i=0;i<8;i++){
nx=node[0]+dx[i];
ny=node[1]+dy[i];
if(nx>=0 && ny>=0 && nx<n && ny<n){
if(dist[1][node[0]][node[1]]+1<dist[1][nx][ny]){
dist[1][nx][ny]=dist[1][node[0]][node[1]]+1;
q1.push({nx,ny});
}
}
}
}
int minn=inf;
for(int i=0;i<8;i++){
for(int j=0;j<8;j++){
// cout<<dist[0][i][j]<<" ";
if(dist[0][i][j]==dist[1][i][j]){
if(dist[0][i][j]<minn) minn=dist[0][i][j];
}
}
}
if(minn!=inf) cout<<minn;
else cout<<-1;
}
F masalaning ishlanishi
#include <bits/stdc++.h>
using namespace std;
#define inf 10e6
int main(){
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
cout.tie(nullptr);
int n,m;
cin>>n>>m;
int sx,sy,ex,ey;
vector<vector<int>> graf(n,vector<int>(m));
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
char s;
cin>>s;
if(int(s)==68){
ex=i;
ey=j;
graf[i][j]=0;
}
if(int(s)==83){
sx=i;
sy=j;
graf[i][j]=0;
}
if(int(s)==42){
graf[i][j]=1;
}
if(int(s)==46){
graf[i][j]=0;
}
}
}
vector<vector<int>> dist(n,vector<int>(m,inf));
queue<vector<int>> q;
q.push({sx,sy});
dist[sx][sy]=0;
int dx[]={-1,1,0,0};
int dy[]={0,0,1,-1};
while(!q.empty()){
auto node=q.front();
q.pop();
for(int i=0;i<4;i++){
int nx,ny;
nx=node[0]+dx[i];
ny=node[1]+dy[i];
if(nx>=0 && nx<n && ny>=0 && ny<m){
if(graf[nx][ny]==1) continue;
if(graf[nx][ny]==0 and dist[nx][ny]==inf){
dist[nx][ny]=dist[node[0]][node[1]]+1;
q.push({nx,ny});
}
if(nx==ex && ny==ey) break;
}
}
}
if(dist[ex][ey]!=inf) cout<<"yes";
else cout<<"no";
}
shunga o'xshagan masalalarni topish yoki yechish niyatida bo'lsangiz https://t.me/robocontestuzwithme kanaliga azo bo'ling