码迷,mamicode.com
首页 > 其他好文 > 详细

UVALive 6530 Football (水

时间:2014-10-30 13:31:37      阅读:228      评论:0      收藏:0      [点我收藏+]

标签:blog   http   io   ar   for   sp   on   2014   log   

题目链接:点击打开链

#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
vector<int> s;
int main() {
	int n, k;
	while (~scanf("%d%d", &n, &k)) {
		s.clear();
		int sum = 0, cnt = 0;
		for(int i = 0, x, y; i < n; i ++) {
			scanf("%d%d", &x, &y);
			if(x > y) sum += 3;
			else if(x == y) {
				cnt ++;
				sum ++;
			} else s.push_back(y-x);
		}
		
		if(k >= cnt) {
			sum += 2*cnt;
			k -= cnt;
		} else {
			sum += 2*k;
			k = 0;
		}
		sort(s.begin(), s.end());
		for(int i = 0; i < s.size() && k > 0; i ++) {
			if(k > s[i]) {
				sum += 3;
				k -= s[i]+1;
			} else if(k == s[i]) {
				sum += 1;
				k -= s[i];
			}
		}
		printf("%d\n", sum);
	}
		
	return 0;
}


UVALive 6530 Football (水

标签:blog   http   io   ar   for   sp   on   2014   log   

原文地址:http://blog.csdn.net/qq574857122/article/details/40618357

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!