QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#732333#8768. Arrested Developmentjiujiu#WA 0ms3564kbC++201.5kb2024-11-10 14:03:192024-11-10 14:03:19

Judging History

你现在查看的是最新测评结果

  • [2024-11-10 14:03:19]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3564kb
  • [2024-11-10 14:03:19]
  • 提交

answer

#include <bits/stdc++.h>
using ld = long double;
using i64 = long long;

#define NO std::cout << "No\n"
#define YES std::cout << "Yes\n"
#define all(x) x.begin(), x.end()

// std::default_random_engine Rand;
// std::uniform_int_distribution<int> r1(1, 10);
// constexpr int d[4][2] = {-1, 0, 0, 1, 1, 0, 0, -1};

void db(){
	int n;
	std::cin >> n;
	std::vector<std::pair<int,int>> v(n);
	for(auto &[a, b] : v){
		std::cin >> a >> b;
	}
	i64 ans = 1e18;
	for(int i = 0; i <= (1ll << n); i++){
		i64 a = 0, b = 0;
		for(int j = 0; j < n; j++){
			if((i >> j) & 1){
				a += v[j].first;
			} else {
				b += v[j].second;
			}
		}
		// std::cout << a << " " << b << '\n';
		ans = std::min(ans, std::max(a, b));
	}
	std::cout << ans << "\n";
}

void solve() {
	int n;
	std::cin >> n;
	std::vector<std::pair<int,int>> v(n);
	int ans = 1e9, sa = 0, sb = 0;
	for(auto &[a, b] : v){
		std::cin >> a >> b;
		sa+= a;
	}
	for(int i = 0; i < n; i++){
		auto [a, b] = v[i];
		sa -= a;
		sb += b;
		if(std::max(sa, sb) <= ans){
			ans = std::max(sa, sb);
		} else {
			sa += a;
			sb -=b;
		}
	}
	std::cout << ans << "\n";
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout.tie(0);
    // Rand.seed(time(0));

    int _ = 1;

    // std::cin >> _;
    // scanf("%ld",&_);
    // std::cout<<std::fixed<<std::setprecision(2);

    while (_--) {
        solve();
        // db();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3512kb

input:

4
100 1
1 90
1 20
1 20

output:

3

result:

ok single line: '3'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3564kb

input:

2
314 1
592 6

output:

7

result:

ok single line: '7'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3512kb

input:

1
1 1

output:

1

result:

ok single line: '1'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3512kb

input:

1
100000 1

output:

1

result:

ok single line: '1'

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 3496kb

input:

1
1 100000

output:

100000

result:

wrong answer 1st lines differ - expected: '1', found: '100000'