Developing Skills

题目传送门:点击打开链接

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;

//int a[100010];

struct node{
	int p1, p2;
}a[100010];

bool cmp(node a, node b) {
	return a.p2 > b.p2;
}

bool cmp1(node a, node b) {
	return a.p1 > b.p1;
}


int main() {
	int n, k;
	cin >> n>> k;
	for (int i = 0; i<n; i++) {
		cin >> a[i].p1;
		a[i].p2 = a[i].p1 %10;
	}
	
	sort(a, a+n, cmp);
	int flag = 0;
	int res = 0;
	
	for (int i = 0; i<n; i++) {
		
		if (a[i].p2)
			flag = 10-a[i].p2;
	//	cout << flag<< endl;
		if (k >= flag) {
			res += (a[i].p1 + flag) /10;
			a[i].p1 = a[i].p1 + flag;
			k -= flag;
			flag = 0;
		//	cout << flag<< endl;
		}
		else
			res += a[i].p1 / 10;
	}
	
	//cout << res<< endl;
	
	//cout << k<< endl;
	if (k >= 10) {
		//res = 0;
		sort(a, a+n, cmp1);
		for (int i = 0; i<n; i++) {
			if (a[i].p1 < 100) {
				int f = 100 - a[i].p1;
				//cout << f<< endl<< k<< endl;;
				if (f < k) {
				
					res += f/10;
					k -= f;
				}
				else {
					res += k/10;
					k = 0;
				}
			}
		}
		
	}
	
	
	cout << res << endl;
	return 0;
	
}


你可能感兴趣的:(codeforces)