結果
| 問題 | 
                            No.496 ワープクリスタル (給料日前編)
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2017-03-29 11:49:23 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 984 bytes | 
| コンパイル時間 | 628 ms | 
| コンパイル使用メモリ | 75,432 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-07-06 15:03:05 | 
| 合計ジャッジ時間 | 1,619 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 WA * 2 RE * 1 | 
| other | AC * 5 WA * 17 RE * 1 | 
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct crystal{
    int x;
    int y;
    int c;
    int safe;
};
bool comp(const crystal &a, const crystal &b){
    if(a.safe < b.safe) return true;
    return false;
}
int main(){
    int gx,gy,N,F;
    cin >> gx >> gy >> N >> F;
vector<crystal> cry;
int x,y,c,safe=0;
    for(int i = 0; i < N;i++){
        cin >> x >> y >> c;
        safe = (x+y)*F - c;
        if(safe > 0){
            cry.push_back({x,y,c,safe});
        }
    }
    sort(cry.begin(),cry.end(),comp);
    /*
    for(auto e : cry){
        cout << e.x << "," << e.y << "," << e.c << "," << e.safe << endl;
    }*/
    int tcost = 0,px=0,py=0;
    for(int i = 0; i < N; i++){
        if(px + cry[i].x <= gx && py + cry[i].y <= gy){
            px += cry[i].x;
            py += cry[i].y;
            tcost += cry[i].c;
        }
    }
    tcost += (gx-px)*F;
    tcost += (gy-py)*F;
    cout << tcost << endl;
    return 0;
}