結果

問題 No.633 バスの運賃
ユーザー donkorin_donkorin_
提出日時 2018-09-25 17:01:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,607 bytes
コンパイル時間 2,148 ms
コンパイル使用メモリ 166,184 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 07:51:17
合計ジャッジ時間 2,272 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 WA -
testcase_08 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
#define vii vector<int>
#define vll vector<long long>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n;
    vii a(n-1), b(n), c(n);
    rep(i, 0, n-1) cin >> a[i];
    rep(i, 0, n) {
        cin >> b[i] >> c[i];
    }
    int ans = 0;
    rep(i, 0, n) {
        if (b[i] > 0) {
            rep(j, 0, n) {
                if (c[j] > 0) {
                    int x = 0;
                    rep(k, j, i)
                        x += a[k];
                    if (c[j] - b[i] >= 0) {
                        ans += b[i] * x;
                        c[j] -= b[i];
                        break;
                    }
                    else {
                        ans += c[j] * x;
                        c[j] = 0;
                        continue;
                    }
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}
0