Demo entry 3548917

5710

   

Submitted by anonymous on Jan 20, 2016 at 09:55
Language: C++. Code size: 1.3 kB.

#include <stdio.h>
#include <iostream>
#include <fstream>
#include <cstring>
#include <string>
#include <math.h>
int getUsage(int fee) {
	int usage = 0;
	if (fee > 4979900) {
		usage = 1000000 + (fee- 4979900) / 7;
	}
	else if (fee > 29900) {
		usage = 10000 + (fee- 29900) / 5;
	}
	else if (fee > 200) {
		usage = 100 + (fee - 200) / 3;
	}
	else {
		usage = fee / 2;
	}
	return usage;
}
int getFee(int usage) {
	int fee = 0;
	if (usage > 1000000) {
		fee = 4979900 + (usage - 1000000) * 7;
	}
	else if (usage > 10000) {
		fee = 29900 + (usage - 10000) * 5;
	}
	else if (usage > 100) {
		fee = 200 + (usage - 100) * 3;
	}
	else {
		fee = usage * 2;
	}
	return fee;
}
int findAns(int fee, int diff) {
	int usage = getUsage(fee) , temp = 0, tempUsage = usage / 2;
	while (temp <= tempUsage) {
		int mid = (temp + tempUsage) / 2;
		int tempFee = getFee(usage - mid) - getFee(mid);
		if (tempFee == diff) {
			temp = mid;
			break;
		}
		else if (tempFee > diff) {
			temp = mid + 1;
		}
		else {
			tempUsage = mid - 1;
		}
	}
	return getFee(temp);
}
int main() {
	while (1) {
		int fee = 0, diff = 0, total = 0;

		std::cin >> fee >> diff;
		if ((fee == 0) && (diff == 0)) {
			return 0;
		}
		std::cout << findAns(fee,diff) << std::endl;
		
	}
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).