#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n;
int a[1e5+10];
bool srt(pair<int,int> a, pair<int,int> b) {
return a.first < b.first;
}
void init(int size, vector<int> h) {
n = size;
for(int i = 0; i < n; i++) a[i] = h[i];
}
int max_towers(int l, int r, int d) {
int res = 0, f, s;
bool ok;
vector<bool> used(n, false);
vector<pair<int,int>> b(r-l+1);
for(int i = l; i <= r; i++) b[i] = {a[i], i};
sort(b.begin(), b.end(), srt);
for(int i = 0; i < b.size(); i++) {
f = b[i].second, s = b[i].second;
ok = true;
//find closest left and right a[i] >= a[b[i].second]+d
for(; f >= l; f--) {
if(used[f]) {
ok = false;
break;
}
if(a[f] >= a[b[i].second]+d) break;
if(f == l) {
f = b[i].second;
break;
}
}
for(; s <= r; s++) {
if(used[s]) {
ok = false;
break;
}
if(a[s] >= a[b[i].second]+d) break;
if(s == r) {
s = b[i].second;
break;
}
}
if(ok) {
used[b[i].second] = true;
res++;
}
}
return res;
}
Compilation message
towers.cpp:8:10: error: conversion from 'double' to 'long unsigned int' in a converted constant expression
8 | int a[1e5+10];
| ~~~^~~
towers.cpp:8:10: error: could not convert '(1.0e+5 + (double)10)' from 'double' to 'long unsigned int'
towers.cpp:8:10: error: size of array 'a' has non-integral type 'double'
towers.cpp: In function 'int max_towers(int, int, int)':
towers.cpp:23:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | for(int i = 0; i < b.size(); i++) {
| ~~^~~~~~~~~~