Submission #1632289


Source Code Expand

Copy
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>
#include <utility>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<pair<int,int> > A;
  int a;
  for(int i = 0; i < N; ++i){
    cin >> a;
    A.push_back(make_pair(a,i));
  }
  sort(A.begin(),A.end());
  set<int> s;
  s.insert(-1);
  s.insert(N);
  long long int ans = 0LL;
  for(int i = 0; i < N; ++i){
    int id = A[i].second;
    s.insert(id);
    set<int>::iterator u = s.find(id), l = u;
    ++u;
    --l;
    ans += (long long int)(*u - id)*(id - (*l))*A[i].first;
    s.insert(id);
  }
  cout << ans << endl;
  return 0;
}

Submission Info

Submission Time
Task B - Minimum Sum
User TAB
Language C++14 (GCC 5.4.1)
Score 400
Code Size 653 Byte
Status
Exec Time 245 ms
Memory 11248 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 example0, example1, example2
All 400 / 400 corner0, corner1, corner2, corner3, example0, example1, example2, maxrand0, maxrand1, maxrand2, rand0, rand1, rand2
Case Name Status Exec Time Memory
corner0 177 ms 11120 KB
corner1 187 ms 11248 KB
corner2 1 ms 256 KB
corner3 148 ms 11120 KB
example0 1 ms 256 KB
example1 1 ms 256 KB
example2 1 ms 256 KB
maxrand0 245 ms 11248 KB
maxrand1 229 ms 11248 KB
maxrand2 213 ms 11248 KB
rand0 1 ms 256 KB
rand1 1 ms 256 KB
rand2 1 ms 256 KB