This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define fo(a, b, c) for (int a = b; a < c; a++)
#define ll long long
#define print(x) cout << x << "\n";
# define vint vector<int>
# define vll vector<long long>
ll recur(int l, int r, vint h)
{ // r is non-inclsuive
if (r - l <=1)
{
return h[l];
}
int maxH = -1;
fo(i, l, r)
{
maxH = max(maxH, h[i]);
}
vector<pair<pair<int, int>, ll>> aves;
// stores the left and right, and then the sum of the middle
int leftH = l;
fo(i, l, r)
{
if (h[i] == maxH)
{
ll tmp = recur(leftH, i, h);
aves.push_back({{leftH, i}, tmp});
leftH = i + 1;
}
}
if (leftH != r)
{
ll tmp = recur(leftH, r, h);
aves.push_back({{leftH, r}, tmp});
}
// int index=-1;
ll smallest = maxH * (r-l) + 1;
fo(i,0,aves.size()){
ll maxtmp = 0ll + aves[i].second + maxH * ((r - aves[i].first.second) + (aves[i].first.first-l));
if(maxtmp < smallest){
smallest=maxtmp;
// index=i;
}
}
// ll numMax = (r - aves[index].first.second) + (aves[index].first.first-l);
return smallest;
}
//looking for smallest ave
// h - heights
// l, r - left and right bounds of each meeting
// ll minCosts[750000];
vll minCosts;
vll minimum_costs(vint h, vint l, vint r)
{
int numMeetings = l.size();
minCosts.reserve(numMeetings);
fo(i, 0, numMeetings)
{
minCosts.push_back(recur(l[i], r[i] + 1, h));
}
return minCosts;
}
// int main()
// {
// ios::sync_with_stdio(0);
// cin.tie(0);
// vint h = {2, 5, 1, 6, 8, 1, 4};
// vint l = {0};
// vint r = {6};
// vll tmp = minimum_costs(h, l, r);
// fo(i,0,tmp.size()){
// print(tmp[i]);
// }
// }
Compilation message (stderr)
meetings.cpp: In function 'long long int recur(int, int, std::vector<int>)':
meetings.cpp:4:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
4 | #define fo(a, b, c) for (int a = b; a < c; a++)
......
52 | fo(i,0,aves.size()){
| ~~~~~~~~~~~~~~~
meetings.cpp:52:5: note: in expansion of macro 'fo'
52 | fo(i,0,aves.size()){
| ^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |