-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
91dac12
commit c5b7281
Showing
2 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# 048 - I will not drop out (★3) | ||
|
||
## 解答 | ||
|
||
```cpp | ||
#include <iostream> | ||
#include <vector> | ||
#include <algorithm> // std::sort() | ||
#include <functional> // std::greater<> | ||
#include <numeric> // std::reduce() | ||
|
||
int main() | ||
{ | ||
// N 問, K 分間 | ||
int N, K; | ||
std::cin >> N >> K; | ||
|
||
std::vector<int> scores; | ||
|
||
for (int i = 0; i < N; ++i) | ||
{ | ||
// 満点 A 点, 部分点 B 点 | ||
int A, B; | ||
std::cin >> A >> B; | ||
|
||
// 1 分で得られるスコア | ||
const int s1 = B; | ||
scores.push_back(s1); | ||
|
||
// もう 1 分で得られるスコア | ||
const int s2 = (A - B); | ||
scores.push_back(s2); | ||
} | ||
|
||
// 大きい順にソート | ||
std::sort(scores.begin(), scores.end(), std::greater<>{}); | ||
|
||
// 先頭 K 要素の合計を求める (long long 型で求める) | ||
const long long a = std::reduce(scores.begin(), scores.begin() + K, 0LL); | ||
|
||
// 解答を出力 | ||
std::cout << a << '\n'; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters