Submission #823314

#TimeUsernameProblemLanguageResultExecution timeMemory
823314Dremix10Meetings (IOI18_meetings)C++17
4 / 100
5541 ms1484 KiB
#include "meetings.h" #include <bits/stdc++.h> using namespace std; #define F first #define S second #define all(x) (x).begin(),(x).end() typedef long long ll; typedef pair<int,int> pi; typedef pair<ll,ll> pl; const int N = 3e5+5; const ll INF = 1e18+5; const int MOD = 1e9+7; vector<long long> minimum_costs(vector<int> arr, vector<int> L, vector<int> R) { int n = arr.size(); int q = L.size(); int i,j,k; vector<ll> ans(q); for(k=0;k<q;k++){ int x = L[k]; int y = R[k]; ll res = INF; for(i=x;i<=y;i++){ // good i is always local minima if(i-1 >= x && arr[i-1] < arr[i] || i+1 <= y && arr[i+1] < arr[i])continue; ll curr = 0; int maxi = 0; for(j=i;j<=y;j++){ maxi = max(maxi,arr[j]); curr += maxi; } maxi = arr[i]; for(j=i-1;j>=x;j--){ maxi = max(maxi,arr[j]); curr += maxi; } res = min(res,curr); } ans[k] = res; } return ans; }

Compilation message (stderr)

meetings.cpp: In function 'std::vector<long long int> minimum_costs(std::vector<int>, std::vector<int>, std::vector<int>)':
meetings.cpp:28:25: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   28 |             if(i-1 >= x && arr[i-1] < arr[i] || i+1 <= y && arr[i+1] < arr[i])continue;
meetings.cpp:16:9: warning: unused variable 'n' [-Wunused-variable]
   16 |     int n = arr.size();
      |         ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...