답안 #345168

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
345168 2021-01-07T05:44:03 Z Erzhan06 K개의 묶음 (IZhO14_blocks) C++17
0 / 100
1 ms 512 KB
#include <bits/stdc++.h>
using namespace std;
#define nl "\n"
#define bananas return 0;
#define ll long long
#define IOS ios_base :: sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
const int N=2e5+6;
const int INF=1e9+6;
int main() {
//freopen("divide.in", "r", stdin);
//freopen("divide.out", "w", stdout);
IOS
	int n,m;
	cin>>n>>m;
	int a[n+1];
	for (int i=1;i<=n;i++) {
		cin>>a[i];
	}
	sort(a+1,a+1+n);
	ll sum=0;
	if (m==1) {
		cout<<a[n];
		return 0;
	}
	if (n-1==m) {
		for (int i=1;i<=n;i++) {
			sum+=a[i];
		}
		cout<<sum;
		return 0;
	}
	if (m%2==1) {
		for (int i=1;i<=m/2+1;i++) {
			sum+=a[i];
		}
		int cnt=0;
		for (int i=n;i>=1;i--) {
			sum+=a[i];
			cnt++;
			if (cnt==m/2) break;
		}
	}else {
		for (int i=1;i<=m/2;i++) {
			sum+=a[i];
		}
		int cnt=0;
		for (int i=n;i>=1;i--) {
			sum+=a[i];
			cnt++;
			if (cnt==m/2) break;
		}
	}
	cout<<sum;
bananas
 
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Incorrect 1 ms 364 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Incorrect 1 ms 364 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Incorrect 1 ms 364 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Incorrect 1 ms 364 KB Output isn't correct
8 Halted 0 ms 0 KB -