Submission #469719

# Submission time Handle Problem Language Result Execution time Memory
469719 2021-09-01T16:26:38 Z Karabasan Cipele (COCI18_cipele) C++17
45 / 90
4 ms 460 KB
#include <bits/stdc++.h>

using namespace std;
int n,m;
int sol[5005];
int sag[5005];
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 Runtime error 2 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 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 3 ms 204 KB Output is correct
2 Correct 3 ms 432 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 4 ms 332 KB Output is correct
2 Correct 3 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 460 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -