#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <deque>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll,ll> Pll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i, n) for(int i=0;i<n;i++)
#define repp(i, n) for(int i=1;i<=n;i++)
#define all(x) x.begin(), x.end()
#define geti1(X) scanf("%d",&X)
#define geti2(X,Y) scanf("%d%d",&X,&Y)
#define geti3(X,Y,Z) scanf("%d%d%d",&X,&Y,&Z)
#define geti4(X,Y,Z,W) scanf("%d%d%d%d",&X,&Y,&Z,&W)
#define GET_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define geti(...) GET_MACRO(__VA_ARGS__, geti4, geti3, geti2, geti1) (__VA_ARGS__)
#define INF 987654321
#define IINF 987654321987654321
#define MAXV 200500
#define MOD 1234567
int N,M,K,T;
int main(){
geti(N,K);
vector<ll> v;
repp(i,N){
ll x; scanf("%lld",&x); v.pb(x);
}
sort(all(v));
int l = 0, r = v.size()-2;
ll ans = v[v.size()-1];
K--;
while(K>1){
ans += v[r] - v[l];
r--; l++;
K -= 2;
}
cout << ans;
}
Compilation message
wine.cpp: In function 'int main()':
wine.cpp:48:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
geti(N,K);
^
wine.cpp:51:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
ll x; scanf("%lld",&x); v.pb(x);
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2020 KB |
Output is correct |
2 |
Correct |
0 ms |
2020 KB |
Output is correct |
3 |
Correct |
0 ms |
2020 KB |
Output is correct |
4 |
Correct |
0 ms |
2020 KB |
Output is correct |
5 |
Correct |
0 ms |
2020 KB |
Output is correct |
6 |
Correct |
0 ms |
2020 KB |
Output is correct |
7 |
Correct |
0 ms |
2020 KB |
Output is correct |
8 |
Correct |
0 ms |
2020 KB |
Output is correct |
9 |
Correct |
0 ms |
2020 KB |
Output is correct |
10 |
Correct |
0 ms |
2020 KB |
Output is correct |
11 |
Correct |
0 ms |
2020 KB |
Output is correct |
12 |
Correct |
0 ms |
2020 KB |
Output is correct |
13 |
Correct |
0 ms |
2160 KB |
Output is correct |
14 |
Correct |
0 ms |
2160 KB |
Output is correct |
15 |
Correct |
0 ms |
2160 KB |
Output is correct |
16 |
Correct |
0 ms |
2160 KB |
Output is correct |
17 |
Correct |
3 ms |
2488 KB |
Output is correct |
18 |
Correct |
6 ms |
2488 KB |
Output is correct |
19 |
Correct |
6 ms |
2488 KB |
Output is correct |
20 |
Correct |
6 ms |
2488 KB |
Output is correct |
21 |
Correct |
13 ms |
3640 KB |
Output is correct |
22 |
Correct |
26 ms |
3640 KB |
Output is correct |
23 |
Correct |
29 ms |
3640 KB |
Output is correct |
24 |
Correct |
23 ms |
3640 KB |
Output is correct |
25 |
Correct |
79 ms |
8248 KB |
Output is correct |
26 |
Correct |
103 ms |
8248 KB |
Output is correct |
27 |
Correct |
83 ms |
8248 KB |
Output is correct |
28 |
Correct |
63 ms |
8248 KB |
Output is correct |
29 |
Correct |
89 ms |
8248 KB |
Output is correct |
30 |
Correct |
93 ms |
8248 KB |
Output is correct |
31 |
Correct |
113 ms |
8248 KB |
Output is correct |
32 |
Correct |
79 ms |
8248 KB |
Output is correct |
33 |
Correct |
0 ms |
2020 KB |
Output is correct |
34 |
Correct |
16 ms |
3640 KB |
Output is correct |