confusion in using iterator in vector
Разница между en1 и en2, 37 символ(ов) изменены
Using set implementation it is working.but using vector the code gives csompile errore mingw error which i cannot understand.can anyone know what to do in order to make it work in vectors↵
↵
~~~~~↵
#include <bits/stdc++.h>↵
using namespace std;↵
↵
#define ll long long↵
#define ar array↵
↵
const int mxN = 2e5;↵
int n;↵
ar<int, 3> a[mxN];↵
↵
int main() {↵
  cin >> n;↵
  for (int i = 0; i < n; ++i) {↵
    cin >> a[i][1] >> a[i][0] >> a[i][2];↵
  }↵
  sort(a, a + n);↵
  set<ar<ll, 2>> dp;↵
  dp.insert({0, 0});↵
  ll ldp = 0;↵
  for (int i = 0; i < n; ++i) {↵
    auto it = dp.lower_bound({a[i][1]});↵
    --it;↵
    ldp = max(ldp, (*it)[1] + a[i][2]);↵
    dp.insert({a[i][0], ldp});↵
  }↵
  cout << ldp;↵
}↵
↵
~~~~~↵
↵
↵
~~~~~↵
↵
#include <bits/stdc++.h>↵
using namespace std;↵
↵
#define ll long long↵
#define ar array↵
↵
const int mxN = 2e5;↵
int n;↵
ar<int, 3> a[mxN];↵
↵
int main() {↵
  cin >> n;↵
  for (int i = 0; i < n; ++i) {↵
    cin >> a[i][1] >> a[i][0] >> a[i][2];↵
  }↵
  sort(a, a + n);↵
  vector<ar<ll, 2>> dp;↵
  dp.push_back({0, 0});↵
  ll ldp = 0;↵
  for (int i = 0; i < n; ++i) {↵
    auto it = lower_bound(dp.begin(), dp.end(), a[i][1]) ;↵
    --it;↵
    ldp = max(ldp, (*it)[1] + a[i][2]);↵
    dp.push_back({a[i][0], ldp});↵
  }↵
  cout << ldp;↵
}↵
~~~~~↵
↵

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский electro177 2021-07-09 17:22:22 37
en1 Английский electro177 2021-07-09 17:15:57 1279 Initial revision (published)