Submission #1035221

#TimeUsernameProblemLanguageResultExecution timeMemory
1035221NeroZein모임들 (IOI18_meetings)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;

vector<int> h, ql, qr;

vector<long long> minimum_costs(vector<int> H, vector<int> L, vector<int> R) {
  h = H; ql = L, qr = R;
  int n = (int) H.size();
  int q = (int) L.size();
  vector<long long> ret(q);
  for (int qind = 0; qind < q; ++qind) {
    vector<int> change(n); 
    int l = ql[qind], r = qr[qind];
    for (int i = l; i < r; ++i) {
      if (h[i] < h[i + 1]) {//there's a suffix that will get affected (increase)
        int mx = 0;
        for (int j = i; j >= l; --j) {
          if (h[j] >= h[i + 1]) {
            break; 
          }
          mx = max(mx, h[j]); 
          change[i] += (h[i + 1] - mx);
        }
      } else if (h[i] > h[i + 1]) {
        int mx = 0;
        for (int j = i + 1; j <= r; ++j) {
          if (h[j] >= h[i]) {
            break; 
          }
          mx = max(mx, h[j]);
          change[i] -= (h[i] - mx); //there's a prefix of him that will decrease
        }
      }
    }
    long long init_cost = 0; 
    for (int i = l, mx = 0; i <= r; ++i) {
      mx = max(mx, h[i]);
      init_cost += mx; 
    }
    long long mn = init_cost;
    for (int i = l; i < r; ++i) {
      init_cost += change[i];
      mn = min(mn, init_cost); 
    }
    ret[qind] = mn; 
  }
  return ret; 
}

int main() {
  int n, q;
  cin >> n >> q;
  vector<int> ih(n);
  for (int i = 0; i < n; ++i) {
    cin >> ih[i];
  }
  vector<int> il(q), ir(q);
  for (int i = 0; i < q; ++i) {
    cin >> il[i] >> ir[i];
  }
  vector<long long> ans = minimum_costs(ih, il, ir); 
  for (int i = 0; i < q; ++i) {
    cout << ans[i] << '\n';
  }
}

Compilation message (stderr)

/usr/bin/ld: /tmp/ccxcP8Sd.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cc6GPSxc.o:meetings.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status