Submission #345176

# Submission time Handle Problem Language Result Execution time Memory
345176 2021-01-07T05:59:48 Z Erzhan06 K blocks (IZhO14_blocks) C++17
0 / 100
1 ms 364 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;
		}
		if (n/2<m) {
			sum=0;
			for (int i=1;i<=m;i++) {
				sum+=a[i];
			}
		}
	}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;
		}
		if (n%2==1) {
			if (n/2+1<m) {
				sum=0;
				for (int i=1;i<=m;i++) sum+=a[i];
			}
		}else {
			if (n/2<m) {
				sum=0;
				for (int i=1;i<=m;i++) sum+=a[i];
			}
		}
	}
	cout<<sum;
bananas
 
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 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 -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 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 -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 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 -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 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 -