| Task: | Sprinklers |
| Sender: | Kemm1706 |
| Submission time: | 2025-03-03 13:56:41 +0200 |
| Language: | C++ (C++11) |
| Status: | COMPILE ERROR |
Compiler report
input/code.cpp: In function 'bool check(const vl&, const vl&, ll, vl&)':
input/code.cpp:17:20: error: no matching function for call to 'max(__gnu_cxx::__normal_iterator<const long long int*, std::vector<long long int> >::difference_type, ll&)'
17 | j = max(upper_bound(f.begin(), f.end(), s[i]) - f.begin(), j);
| ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/bits/char_traits.h:39,
from /usr/include/c++/11/ios:40,
from /usr/include/c++/11/istream:38,
from /usr/include/c++/11/sstream:38,
from /usr/include/c++/11/complex:45,
from /usr/include/c++/11/ccomplex:39,
from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
from input/code.cpp:1:
/usr/include/c++/11/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> const _Tp& std::max(const _Tp&, const _Tp&)'
254 |...Code
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector <ll> vl;
const ll nmax = 1e9 + 1;
bool check(const vl &s, const vl &f, ll val, vl &d)
{
ll i = 0, j = 0, n = s.size(), m = f.size();
while(i < n && j < m)
{
if(f[j] < s[i])
{
if(s[i] - val > f[j])
return false;
d[i] = -1;
j = max(upper_bound(f.begin(), f.end(), s[i]) - f.begin(), j);
i++;
}
else
{
d[i] = 1;
j = max(upper_bound(f.begin(), f.end(), s[i] + val) - f.begin(), j);
i++;
}
}
if(j < m)
return false;
for(; i < n; i++)
d[i] = 1;
return true;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
ll n, m, i, lo = 0, hi = nmax, mid;
cin >> n >> m;
vl s(n), f(m), d(n);
for(i = 0; i < n; i++)
cin >> s[i];
for(i = 0; i < m; i++)
cin >> f[i];
while(lo < hi)
{
mid = (lo + hi) / 2;
if(check(s, f, mid, d))
hi = mid;
else
lo = mid + 1;
//cerr << lo << " " << hi << "\n";
}
if(check(s, f, lo - 1, d))
{
cout << lo - 1 << "\n";
for(i = 0; i < n; i++)
if(d[i] == -1)
cout << "L";
else
cout << "R";
}
else
if(check(s, f, lo, d))
{
cout << lo << "\n";
for(i = 0; i < n; i++)
if(d[i] == -1)
cout << "L";
else
cout << "R";
}
else
if(check(s, f, lo + 1, d))
{
cout << lo + 1 << "\n";
for(i = 0; i < n; i++)
if(d[i] == -1)
cout << "L";
else
cout << "R";
}
else
cout << -1;
return 0;
}
