Submission #469721

# Submission time Handle Problem Language Result Execution time Memory
469721 2021-09-01T16:27:25 Z Karabasan Cipele (COCI18_cipele) C++17
90 / 90
57 ms 2472 KB
#include <bits/stdc++.h>

using namespace std;
int n,m;
int sol[100005];
int sag[100005];
int mx;
int check(int x)
{
    int k=0;
    for(int i=0;i<m;i++)
    {
        if(abs(sol[k]-sag[i])<=x)
        {
            k++;
            continue;
        }
        while(abs(sol[k]-sag[i])>x)
            {
                k++;
                if(k>=n)
                    return 0;
            }
        if(abs(sol[k]-sag[i])<=x)
        {
            k++;
            continue;
        }

    }
    return 1;


}
int check1(int x)
{
    int k=0;
    for(int i=0;i<n;i++)
    {
        if(abs(sol[i]-sag[k])<=x)
        {
            k++;
            continue;
        }
        while(abs(sol[i]-sag[k])>x)
            {
                k++;
                if(k>=m)
                    return 0;
            }
        if(abs(sol[i]-sag[k])<=x)
        {
            k++;
            continue;
        }

    }
    return 1;


}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++)
        scanf("%d",&sol[i]);
    for(int i=0;i<m;i++)
        scanf("%d",&sag[i]);
    sort(sol,sol+n);
    sort(sag,sag+m);
    if(n==m)
    {
        for(int i=0;i<n;i++)
        {
            mx=max(mx,abs(sol[i]-sag[i]));
        }
        printf("%d",mx);
        return 0;
    }
    if(n>m)
    {
        int bas=0;
        int son=1000000000;
        while(bas<son)
        {
            int orta=(bas+son)/2;
            if(check(orta)==1)
                son=orta;
            else bas=orta+1;
        }
        printf("%d",bas);
    }
    else
    {
        int bas=0;
        int son=1000000000;
        while(bas<son)
        {
            int orta=(bas+son)/2;
            if(check1(orta)==1)
                son=orta;
            else bas=orta+1;
        }
        printf("%d",bas);



    }
    return 0;
}

Compilation message

cipele.cpp: In function 'int main()':
cipele.cpp:64:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |     scanf("%d%d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~
cipele.cpp:66:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |         scanf("%d",&sol[i]);
      |         ~~~~~^~~~~~~~~~~~~~
cipele.cpp:68:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |         scanf("%d",&sag[i]);
      |         ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 28 ms 972 KB Output is correct
2 Correct 48 ms 948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 1104 KB Output is correct
2 Correct 52 ms 1020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 3 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 3 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 3 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 4 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 332 KB Output is correct
2 Correct 3 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 836 KB Output is correct
2 Correct 29 ms 1724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 1004 KB Output is correct
2 Correct 23 ms 1996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 864 KB Output is correct
2 Correct 41 ms 2472 KB Output is correct