1. 程式人生 > >UVALive 6530 Football (水

UVALive 6530 Football (水

scan item uvalive icp namespace pca pri sca ive

題目鏈接:點擊打開鏈

#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 (水