結果

問題 No.1046 Fruits Rush
ユーザー nanophoto12nanophoto12
提出日時 2020-05-08 21:39:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,436 bytes
コンパイル時間 2,123 ms
コンパイル使用メモリ 203,016 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-17 02:11:07
合計ジャッジ時間 2,894 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

#include <bits/stdc++.h>
using namespace std;

const ll mod = 1e9 + 7;

const ll INF = 1e15;

template<typename T> class SegmentTree {
private:
	typedef function<T(T, T)> F;
	int n;
	T d0;
	vector<T> vertex;
	F f;
	F g;
public:

	SegmentTree(int sourceN, F f, F g, T d = 0) :d0(d), f(f), g(g) {
		init(sourceN);
	}
	void init(int sourceN) {
		n = 1;
		while (n < sourceN) n *= 2;
		vertex.assign(2 * n - 1, d0);
	}
	void update(int i, T x) {
		int k = i + n - 1;
		vertex[k] = g(vertex[k], x);
		while (k > 0) {
			k = (k - 1) / 2;
			vertex[k] = f(vertex[2 * k + 1], vertex[2 * k + 2]);
		}
		return;
	}
	T query(int l, int r) {
		T vl = d0, vr = d0;
		l += n - 1;
		r += n - 1;
		for (; l <= r; l /= 2, r = r / 2 - 1) {
			if (l % 2 == 0) vl = f(vl, vertex[l]);
			if (r & 1) vr = f(vr, vertex[r]);
		}
		return f(vl, vr);
	}
};


int main() {
	ll n, k;
	cin >> n >> k;
	vector<ll> as(n);
	rep(i, n)cin >> as[i];
	sort(as.begin(), as.end(), std::greater<ll>());
	ll sum = 0;
	for (int i = 0; i < k; i++) {
		if (as[i] > 0) {
			sum += as[i];
		}
	}
	cout << sum << endl;
	return 0;
}
0