Вітаю Вас, Гость

Задача A
#include<bits/stdc++.h>
using namespace std;
int dvoi,l,r,n,m,p,x1,k;
vector<int> a[200000];

void make(int x, int l, int r)
{
    if(l==r)return;
    make(x*2,l,(l+r)/2);
    make(x*2+1,(l+r)/2+1,r);
    merge (a[x*2].begin(), a[x*2].end(), a[x*2+1].begin(), a[x*2+1].end(),
                        back_inserter (a[x]));
}
void pos(int x, int l, int r, int ll, int rr)
{
    if(l>rr || r<ll) return;
    if(l>=ll && r<=rr)
    {
        int l1=0;
        int u=0;
        int r1=a[x].size();
        r1--;
        while(r1-l1>1)
        {
            u=(l1+r1)/2;
            if(a[x][u]>x1) r1=u; else l1=u;
        }
        k=min(k,min(abs(a[x][l1]-x1),abs(a[x][r1]-x1)));
        return;
    }
    int k1=(l+r)/2;
    pos(x*2,l,k1,ll,rr);
    pos(x*2+1,k1+1,r,ll,rr);
}
int main()
{
    freopen("cosmodrome.in","r",stdin);
    freopen("cosmodrome.out","w",stdout);
    ios_base::sync_with_stdio(0);
    cin>>n>>m;
    dvoi=1;
    while(dvoi<n)dvoi+=dvoi;
    for(int i=1;i<=n;i++)
    {
        cin>>p;
        a[i+dvoi-1].push_back(p);
    }
    make(1,1,dvoi);
    for(int i=1;i<=m;i++)
    {
        cin>>l>>r>>x1;
        k=2000000000;
        pos(1,1,dvoi,l,r);
        cout<<k<<endl;
    }
}

Задача B
/* GCC */

#include <stdio.h>

int main()
{
    freopen("game.in", "r", stdin);
    freopen("game.out", "w", stdout);

    int n;
    
    scanf("%d", &n);

    printf(n % 2 == 0 ? "1" : "7");
    for (int i = 0; i < n/2 - 1; i++)
        printf("1");

    printf(" ");

       int eights = 0;
    switch (n % 7)
    {   
        case 0:
            eights = n/7;
            break;
        case 1:
            printf("10");
            eights = (n - 8)/7;
            break;
        case 2:
            printf("1");
            eights = (n - 2)/7;
            break;
        case 3:
            if (n/7 == 0)
                printf("7");
            else if (n/7 == 1)
                printf("22");
            else
            {
                printf("200");
                eights = (n - 17)/7;
            }
            break;
        case 4:
            if (n/7 == 0)
                printf("4");
            else
            {
                printf("20");
                eights = (n - 11)/7;
            }
            break;
        case 5:
            printf("2");
            eights = (n - 5)/7;
            break;
        case 6:
            printf("6");
            eights = (n - 6)/7;
            break;
    }
    for (int i = 0; i < eights; i++)
        printf("8");

    printf("\n");

    return 0;
}

Задача C
Function Prost(x: LongInt):Boolean;
  Var flag: Boolean;
      i: LongInt;
  begin
    if Not(Odd(x)) and (x>2)
       then Flag:=False
       else begin
             Flag:=True;
             For i:=3 to Round(Sqrt(x)) do
              if x mod i=0 then begin Flag:=False; Break end;
            end;
    Prost:=Flag
  end;

 Function f(x:LongInt):LongInt;
   begin
     if x=1 then f:=MaxlongInt
            else if Prost(x) then f:=1
                             else if Not(Odd(x)) then f:=2
                                                 else If Prost(x-2) then f:=2
                                                                    else f:=3
   end;

Var a, b, c, d, k, n, Count, ff: LongInt;
Begin
  Assign(Input,'kingdom.in'); Reset(Input);
  Assign(Output,'kingdom.out'); Rewrite(Output);
  Read(a, b);
  Read(c,d);
  Count:=0;
  for k:=c to d do
   begin
    ff:=f(k);
    for N:=a to b do
     If N>=ff then Inc(count)
   end;
  WriteLn(Count);
end.

Задача D
#include <iostream>
#include <string>

using namespace std;

int t,n,la,lb,lc,zna,znb=1,kza,kzb,a[500],b[500],c[500];
string sa,sb;

void sum()
{ for(int i=1;i<=la;i++) c[i]=a[i]+b[i];
  for(int i=1;i<=la;i++) if (c[i]>5) {c[i]-=6;c[i+1]++;}
  lc=la; if (c[lc+1]) lc++;
}

void rizn()
{ for(int i=1;i<=la;i++) c[i]=a[i]-b[i];
  for(int i=1;i<=la;i++) if (c[i]<0) {c[i]+=6;c[i+1]--;}
  lc=la; for(int i=lc;i>kza+1;i--) if (c[i]==0) lc--; else break;
}

int main()
{ cin>>sa>>sb;
  if (sa[0]=='-') {zna=1; sa.erase(0,1);}
  if (sb[0]=='-') {znb=0; sb.erase(0,1);}
  if ((t=sa.find('.'))>0) {kza=sa.size()-t-1; sa.erase(t,1);}
  if ((t=sb.find('.'))>0) {kzb=sb.size()-t-1; sb.erase(t,1);}
  while (kza!=kzb) if (kza<kzb) {sa+='0'; kza++;} else {sb+='0'; kzb++;}
  if (sa.size()<sb.size()||(sa.size()==sb.size()&&sa<sb)) {swap(sa,sb);swap(zna,znb);}
  la=sa.size();lb=sb.size();
  for(int i=0;i<la;i++) a[la-i]=sa[i]-48;
  for(int i=0;i<lb;i++) b[lb-i]=sb[i]-48;
  if (zna==znb) sum(); else rizn();
  if (zna) cout<<'-';
  for(int i=lc;i>kza;i--) cout<<c[i];
  if (kza) cout<<'.';
  for(int i=kza;i>0;i--) cout<<c[i];
  cout<<endl;
}

Задача E
#include <iostream>

using namespace std;

int n,s1[101][101],s2[101][101],t1,t2,ts;

int main()
{ cin>>n; for(int i=1;i<=n;i++) cin>>s1[1][i];
  for(int l=2;l<=n;l++) for(int i=1;i+l-1<=n;i++)
  { t1=s2[l-1][i]+s1[1][i+l-1]; t2=s1[1][i]+s2[l-1][i+1]; ts=t2+s1[l-1][i+1];
        if (t1>t2) {s1[l][i]=t1; s2[l][i]=ts-t1;}
              else {s1[l][i]=t2; s2[l][i]=ts-t2;}
        for(int j=1;j<l;j++) if (s2[j][i]+s2[l-j][i+j]>s1[l][i])
         {s1[l][i]=s2[j][i]+s2[l-j][i+j]; s2[l][i]=s1[j][i]+s1[l-j][i+j];}
  }
  cout<<s1[n][1]<<" "<<s2[n][1]<<endl;
}