Submission #464670

# Submission time Handle Problem Language Result Execution time Memory
464670 2021-08-13T16:03:12 Z soba Cipele (COCI18_cipele) C++14
63 / 90
398 ms 201588 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 10000+1;

int n ,m , x;
int dp[5001][5001];
vector<int>v1 , v2;
int solve(int i , int rem)
{
    if(rem==0)
        return 0;
    if(i==n)
        return 1e9;
    int &ret=dp[i][rem];
    if(ret!=-1)
        return ret;
    ret=min( max(solve(i+1, rem-1), abs(v1[i]-v2[m-rem]) ) , solve(i+1 , rem) );
    return ret;
}
int main() {

    cin>>n>>m;
    for(int i = 0 ; i < n; i++)
    {
        cin>>x;
        if(n>=m)
            v1.push_back(x);
        else v2.push_back(x);
    }
    for(int i=0 ; i < m ;i++ )
    {
        cin >> x;
        if(n>=m)
        {
            v2.push_back(x);
        }
        else v1.push_back(x);
    }
    if(n<m)swap(n,m);
    int ans=0;
    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());
    if(n==m)
    {
        for(int i = 0;  i< n ;i++)
        {
            ans=max(ans , abs(v1[i]-v2[i]));
        }
        cout << ans;
        return 0;
    }
    memset(dp , -1 , sizeof dp);
    cout << solve(0 , m);
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 81 ms 1440 KB Output is correct
2 Correct 105 ms 1356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 104 ms 1448 KB Output is correct
2 Correct 104 ms 1336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 112 ms 98376 KB Output is correct
2 Correct 396 ms 98616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 98500 KB Output is correct
2 Correct 377 ms 98620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 357 ms 98584 KB Output is correct
2 Correct 381 ms 98648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 367 ms 98500 KB Output is correct
2 Correct 398 ms 98668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 387 ms 98684 KB Output is correct
2 Correct 389 ms 98704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 225 ms 201408 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 286 ms 201588 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 232 ms 201252 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -