結果
問題 |
No.647 明太子
|
ユーザー |
|
提出日時 | 2018-11-09 04:47:14 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 45 ms / 4,500 ms |
コード長 | 1,698 bytes |
コンパイル時間 | 623 ms |
コンパイル使用メモリ | 70,288 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-21 05:03:32 |
合計ジャッジ時間 | 1,620 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 20 |
ソースコード
#include<iostream> #include<vector> #include<algorithm> using namespace std; struct Person{ int price=0; int spice = 0; }; struct Mentaiko { int price = 0; int spice = 0; }; int main() { //整数nの入力 //データの入力 //整数mの入力 //データの入力 //大きさmの配列countを用意 //ループ開始 //ループ開始 //i番目の金額以内かつ、i番目の辛さ以上であればカウントする //0~mまで繰り返す //0~nまで繰り返す int n = 0, m = 0; vector<Person> array1; vector<Mentaiko> array2; cin >> n; for (int i = 0;i < n;i++) { Person buff; cin >> buff.price >> buff.spice; array1.push_back(buff); } cin >> m; for (int i = 0;i < m;i++) { Mentaiko buff; cin >> buff.price >> buff.spice; array2.push_back(buff); } vector<int> count(m, 0); for (int i = 0;i < n;i++) { for (int j = 0;j < m;j++) { if (array1[i].price >= array2[j].price && array1[i].spice <= array2[j].spice)count[j]++; } } vector<int>::iterator itr1= max_element(count.begin(), count.end());//最大値のイテレータ int maxvalue = *max_element(count.begin(), count.end());//最大値 if (maxvalue == 0) { cout << 0 << endl; return 0; } size_t maxIndex = distance(count.begin(), itr1);//最大値のインデックス vector<int> indexs; indexs.push_back(maxIndex); vector<int>::iterator itr2; while (true) { if (itr1 != count.end()-1 && *max_element(itr1+1, count.end()) == maxvalue) { itr2 = max_element(itr1+1, count.end()); maxIndex = distance(count.begin(), itr2); indexs.push_back(maxIndex); itr1 = itr2; } else break; } for (int i : indexs) { cout << i+1<<endl; } return 0; }