Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef unsigned long long ull;
- int main(int argc, char const *argv[])
- {
- ull n;
- cin>>n;
- int line[n];
- for (int i = 0; i < n; ++i) cin>>line[i];
- ull flous(0);
- int i(0),j(n-1),day(1);
- while(i<j)
- {
- if (line[i]*day < line[j]*day)
- {
- flous += line[i]*day;
- day++; i++;
- }
- else if (line[i]*day > line[j]*day)
- {
- flous += line[j]*day;
- day++; j--;
- }
- else if (j - i > 2)
- {
- // first keep going until there's two distinct values
- // then do something like the following:
- if (line[i+1]*(day+1) < line[j-1]*(day+1))
- {
- flous += line[i]*day;
- day++; i++;
- }
- else if (line[i]*(day+1) < line[j]*(day+1))
- {
- flous += line[j]*day;
- day++; j--;
- }
- }
- else
- {
- flous += line[j]*day;
- day++; j--;
- }
- }
- flous += line[j] * day;
- cout<<flous<<'\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement