結果

問題 No.1046 Fruits Rush
ユーザー manaitamanaita
提出日時 2020-05-08 21:31:11
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,275 bytes
コンパイル時間 1,097 ms
コンパイル使用メモリ 104,752 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-03 23:56:09
合計ジャッジ時間 1,512 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <iostream>
#include <iterator>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <numeric>
#include <iomanip>
#include <limits>
#include <set>
#include <map>
#include <type_traits>
#include <cstdint>
#include <queue>
#define _USE_MATH_DEFINES
#include <math.h>
typedef long long ll;
using namespace std;
//
void factoring(ll n, map<ll, ll>& mp) {
for (ll i = 2; i * i <= n; i++) {
while (n % i == 0) {
mp[i]++;
n /= i;
}
}
if (n != 1) mp[n]++;
}
//
template<class T, class U = std::make_unsigned_t<T>>
U SafeAbs( T x ) {
return x < 0 ? -static_cast<uintmax_t>(x) : x;
}
//
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
//xn
ll mod_pow(ll x, ll n, ll mod) {
ll res = 1;
while (n > 0) {
if (n & 1) res = res * x % mod;
x = x * x % mod;
n >>= 1;
}
return res;
}
//x
ll mod_inv(ll x, ll mod) {//O(log(mod))
return mod_pow(x, mod - 2, mod);
}
//nCr
ll ncr(ll n, ll r, ll mod){
ll res=1;
ll num=1,den=1;
for(ll i=n;i>=n-r+1;i--){
(den*=i)%=mod;
}
for(ll i=1;i<=r;i++){
(num*=i)%=mod;
}
res=den*mod_inv(num,mod);
return res%mod;
}
//
bool isOk(ll index, ll key,vector<ll> &a){
if(a[index]>key){
return true;
}
return false;
}
ll bin_search(ll key, vector<ll> &a){
ll l=-1;
ll r=a.size();
while(abs(r-l)>1){
ll mid = (l+r)/2;
if(isOk(mid, key, a)){
r=mid;
}
else{
l=mid;
}
}
return r;
}
/*
//
void dfs(vector<vector<ll>> &gra,vector<bool> &seen, ll v){
seen[v]=true;
for(auto next : gra[v]){
if(seen[next]){
continue;
}
dfs(gra,seen,next);
}
}
*/
const ll MOD=1000000007;
void solve(){
ll n,k;
cin>>n>>k;
vector<ll> a(n,0);
for(ll i=0;i<n;i++){
cin>>a[i];
a[i]=-a[i];
}
sort(a.begin(),a.end());
ll sum=0;
if(a[0]<0){
for(ll i=0;i<k;i++){
if(a[i]<0){
sum+=(-a[i]);
}
}
}else{
sum=(-a[0]);
}
cout<<sum<<endl;
}
int main(){
solve();
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0