Submission #198720

# Submission time Handle Problem Language Result Execution time Memory
198720 2020-01-27T13:24:29 Z stormy_weather Art Exhibition (JOI18_art) C++14
Compilation error
0 ms 0 KB
#include<iostream>
#include<vector>
using namespace std;

int main() {
  int n; cin >> n;

  vector <pair <int64_t, int>> values(n);
  for (int i = 0; i < n; i++) {
    cin >> values[i].first >> values[i].second;
  }

  sort(values.begin(), values.end());

  vector <int64_t> p_sum(n);
  for (int i = 0; i < n; i++) {
    p_sum[i] = i > 0 ? p_sum[i - 1] + values[i].second : values[i].second;
  }

  //we determine our functions
  vector <int64_t> first_part(n), second_part(n);
  for (int i = 0; i < n; i++) {
    first_part[i] = p_sum[i] - values[i].first;
    second_part[i] = i > 0 ? p_sum[i - 1] - values[i].first : -1 * values[i].first;
  }

  vector <int64_t> min_second_part(n);
  int64_t min = second_part[0];
  for (int i = 0; i < n; i++) {
    if (second_part[i] <= min)
      min = second_part[i];
    min_second_part[i] = min;
  }

  //we determine our max difference
  int64_t max_dif;
  for (int i = 0; i < n; i++) {
    int64_t cur_dif = first_part[i] - min_second_part[i];
    if (i == 0 || cur_dif > max_dif)
      max_dif = cur_dif;
  }

  cout << max_dif << "\n";

  return 0;
}

Compilation message

art.cpp: In function 'int main()':
art.cpp:13:3: error: 'sort' was not declared in this scope
   sort(values.begin(), values.end());
   ^~~~
art.cpp:13:3: note: suggested alternative: 'qsort'
   sort(values.begin(), values.end());
   ^~~~
   qsort