洛谷P3406

P3406 海底高铁

这题就写我在写题遇到的两个坑
一、是从\(P_1\)出发,不是从点1出发。。。
二、times、a、b、c数组没开long long导致WA

点击查看代码
#include<bits/stdc++.h>
using namespace std;

const int N = 1e5 + 10;
long long diff[N], go[N];
long long times[N];
long long a[N], b[N], c[N];

int main() {
    int n, m; cin >> n >> m;
    cin >> go[1];
    for(int i = 2; i <= m; i++) {
        cin >> go[i];
        int st = min(go[i - 1], go[i]);
        int ed = max(go[i - 1], go[i]);
        diff[st]++;
        diff[ed]--;
    }
    long long ans = 0;
    times[0] = 0;
    for(int i = 1; i < n; i++) {
        times[i] = times[i - 1] + diff[i];
        cin >> a[i] >> b[i] >> c[i];
        ans += min(times[i] * a[i], times[i] * b[i] + c[i]);
    }
    cout << ans << '\n';
    return 0;
}
posted @ 2025-05-18 19:53  Chuan81  阅读(11)  评论(0)    收藏  举报