Problem p02868 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

#define p_ary(ary, a, b)                                                       \
  do {                                                                         \
    cout << "[";                                                               \
    for (int count = (a); count < (b); ++count)                                \
      cout << ary[count] << ((b)-1 == count ? "" : ", ");                      \
    cout << "]\n";                                                             \
  } while (0)
#define p_map(map, it)                                                         \
  do {                                                                         \
    cout << "{";                                                               \
    for (auto(it) = map.begin();; ++(it)) {                                    \
      if ((it) == map.end()) {                                                 \
        cout << "}\n";                                                         \
        break;                                                                 \
      } else                                                                   \
        cout << "" << (it)->first << "=>" << (it)->second << ", ";             \
    }                                                                          \
  } while (0)

int MAX_N = 100010;
ll INF = 1LL << 60;
vector<vector<P>> edges(MAX_N);
vector<ll> dist(MAX_N, INF);

void dijkstra(int s) {
  priority_queue<P, vector<P>, greater<P>> que;
  dist[s] = 0;
  que.push(P(0, s));

  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (dist[v] < p.first)
      continue;
    for (int i = 0; i < edges[v].size(); ++i) {
      P e = edges[v][i];
      if (dist[e.first] > dist[v] + e.second) {
        dist[e.first] = dist[v] + e.second;
        que.push(P(dist[e.first], e.first));
      }
    }
  }
}

int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int l, r, c;
    cin >> l >> r >> c;
    edges[l - 1].push_back(P(r - 1, c));
  }
  for (int i = 1; i < n; ++i)
    edges[i].push_back(P(i - 1, 0));
  dijkstra(0);
  cout << (dist[n - 1] < INF ? dist[n - 1] : -1) << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define p_ary(ary, a, b)                                                       \
  do {                                                                         \
    cout << "[";                                                               \
    for (int count = (a); count < (b); ++count)                                \
      cout << ary[count] << ((b)-1 == count ? "" : ", ");                      \
    cout << "]\n";                                                             \
  } while (0)
#define p_map(map, it)                                                         \
  do {                                                                         \
    cout << "{";                                                               \
    for (auto(it) = map.begin();; ++(it)) {                                    \
      if ((it) == map.end()) {                                                 \
        cout << "}\n";                                                         \
        break;                                                                 \
      } else                                                                   \
        cout << "" << (it)->first << "=>" << (it)->second << ", ";             \
    }                                                                          \
  } while (0)

int MAX_N = 100010;
ll INF = 1LL << 60;
vector<vector<P>> edges(MAX_N);
vector<ll> dist(MAX_N, INF);

void dijkstra(int s) {
  priority_queue<P, vector<P>, greater<P>> que;
  dist[s] = 0;
  que.push(P(0, s));

  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (dist[v] < p.first)
      continue;
    for (int i = 0; i < edges[v].size(); ++i) {
      P e = edges[v][i];
      if (dist[e.first] > dist[v] + e.second) {
        dist[e.first] = dist[v] + e.second;
        que.push(P(dist[e.first], e.first));
      }
    }
  }
}

int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int l, r, c;
    cin >> l >> r >> c;
    edges[l - 1].push_back(P(r - 1, c));
  }
  for (int i = 1; i < n; ++i)
    edges[i].push_back(P(i - 1, 0));
  dijkstra(0);
  cout << (dist[n - 1] < INF ? dist[n - 1] : -1) << endl;
  return 0;
}