Submission #166424

# Submission time Handle Problem Language Result Execution time Memory
166424 2019-12-02T10:41:47 Z tincamatei Cipele (COCI18_cipele) C++14
90 / 90
98 ms 3156 KB
#include <bits/stdc++.h>

using namespace std;

vector<int> v1, v2;

bool check(int T) {
  int j = 0;
  for(int i = 0; i < v1.size(); ++i) {
    while(j < v2.size() && abs(v2[j] - v1[i]) > T)
      ++j;
    if(j == v2.size())
      return false;
    ++j;
  }
  return true;
}

int main() {
  int n, m, x;
  scanf("%d%d", &n, &m);
  for(int i = 0; i < n; ++i) {
    scanf("%d", &x);
    v1.push_back(x);
  }
  for(int i = 0; i < m; ++i) {
    scanf("%d", &x);
    v2.push_back(x);
  }

  if(v1.size() > v2.size())
    v1.swap(v2);

  sort(v1.begin(), v1.end());
  sort(v2.begin(), v2.end());

  int st = -1, dr = 1000000001;

  while(dr - st > 1) {
    int mid = (st + dr) / 2;
    if(check(mid))
      dr = mid;
    else
      st = mid;
  }

  printf("%d", dr);
  return 0;
}

Compilation message

cipele.cpp: In function 'bool check(int)':
cipele.cpp:9:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < v1.size(); ++i) {
                  ~~^~~~~~~~~~~
cipele.cpp:10:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while(j < v2.size() && abs(v2[j] - v1[i]) > T)
           ~~^~~~~~~~~~~
cipele.cpp:12:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(j == v2.size())
        ~~^~~~~~~~~~~~
cipele.cpp: In function 'int main()':
cipele.cpp:21:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &n, &m);
   ~~~~~^~~~~~~~~~~~~~~~
cipele.cpp:23:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &x);
     ~~~~~^~~~~~~~~~
cipele.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &x);
     ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 40 ms 1648 KB Output is correct
2 Correct 60 ms 3156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 61 ms 1648 KB Output is correct
2 Correct 60 ms 3072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 1408 KB Output is correct
2 Correct 36 ms 1908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 98 ms 1624 KB Output is correct
2 Correct 28 ms 2280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 1516 KB Output is correct
2 Correct 53 ms 2980 KB Output is correct