Submission #2317856


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

bool cmp(PLL &a, PLL &b){
	return (a.sc*b.fs == b.sc*a.fs ? a.sc > b.sc : a.sc*b.fs > b.sc*a.fs);
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int32 N;
	cin >> N;
	int64 res = 0;
	int64 T = 0;
	vector<PLL> v;
	REP(i, N){
		int64 A, B;
		cin >> A >> B;
		if(A < B){
			T += B-A;
			res += A;
		}else{
			v.push_back(PLL(A-B+1, A));
		}
	}
	sort(all(v));
	REP(i, v.size()){
		if(v[i].fs <= T){
			T -= v[i].fs;
			res += v[i].sc;
		}
	}
	cout << res+T << endl;
}

Submission Info

Submission Time
Task E - Tozan and Gezan
User maze1230
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1165 Byte
Status
Exec Time 7 ms
Memory 892 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 s1.txt, s2.txt, s3.txt
All 0 / 700 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt 6 ms 640 KB
02.txt 6 ms 640 KB
03.txt 6 ms 640 KB
04.txt 6 ms 640 KB
05.txt 6 ms 640 KB
06.txt 6 ms 640 KB
07.txt 6 ms 640 KB
08.txt 6 ms 640 KB
09.txt 7 ms 892 KB
10.txt 7 ms 892 KB
11.txt 7 ms 892 KB
12.txt 7 ms 892 KB
13.txt 6 ms 892 KB
14.txt 6 ms 892 KB
15.txt 6 ms 892 KB
16.txt 6 ms 892 KB
17.txt 6 ms 892 KB
18.txt 6 ms 892 KB
19.txt 6 ms 640 KB
20.txt 6 ms 640 KB
21.txt 6 ms 640 KB
22.txt 6 ms 640 KB
23.txt 6 ms 640 KB
24.txt 6 ms 640 KB
25.txt 6 ms 640 KB
26.txt 6 ms 640 KB
27.txt 6 ms 640 KB
28.txt 6 ms 640 KB
29.txt 6 ms 640 KB
30.txt 6 ms 640 KB
31.txt 1 ms 256 KB
32.txt 1 ms 256 KB
s1.txt 1 ms 256 KB
s2.txt 1 ms 256 KB
s3.txt 1 ms 256 KB