結果

提出番号 933
提出者 littlegirl112
言語 C++
提出日時 2017-08-01 15:53:15
問題名 (28)いつだって一位の男、olphe君
結果 CE
点数 0%

テストケース

テストケース 結果 得点 実行時間 メモリ使用量
1 CE 0% 0ms 0KB
2 CE 0% 0ms 0KB
3 CE 0% 0ms 0KB
4 CE 0% 0ms 0KB
5 CE 0% 0ms 0KB
6 CE 0% 0ms 0KB
7 CE 0% 0ms 0KB
8 CE 0% 0ms 0KB
9 CE 0% 0ms 0KB
10 CE 0% 0ms 0KB
11 CE 0% 0ms 0KB
12 CE 0% 0ms 0KB
13 CE 0% 0ms 0KB
14 CE 0% 0ms 0KB
15 CE 0% 0ms 0KB
16 CE 0% 0ms 0KB
17 CE 0% 0ms 0KB
18 CE 0% 0ms 0KB
19 CE 0% 0ms 0KB
20 CE 0% 0ms 0KB

ソースコード

#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
using namespace std;
int n, p[1000], s, yan;
int b = 50000000000;
int c = 0;
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}
	cin >> s;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (p[i] > p[j]) {
				yan = p[i];
				p[i] = p[j];
				p[j] = yan;
			}
		}
	}

	if (s == 0) {
		cout << p[0] << endl;
		return 0;
	}
	for (int i = n - 1; i >= 0;i=i-1) {
		if (p[i] >= s) {
			b = p[i];
		}
		else {
			c += p[i];
			if (c >= s) {
				if (b >= c&&c >= s) {
					cout << c << endl;
					return 0;
				}
				else {
					if (b >= c&&c <= s) {
						cout << b << endl;
						return 0;
					}
					else {
						if (c >= b&&b >= s) {
							cout << b << endl;
							return 0;
						}
						else {
							cout << c << endl;
							return 0;
						}

					}
				}