Submission #23254298
Source Code Expand
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
struct Edge {
int to;
long long w;
Edge(int to, long long w) : to(to), w(w) {}
};
using Graph = vector<vector<int> >;
// using Graph = vector<vector<Edge> >;
template<class T> void chmax(T& a, T b) {
if(a < b) a = b;
}
template<class T> void chmin(T& a, T b) {
if(a > b) a = b;
}
struct UnionFind {
vector<long long> par, siz;
UnionFind(long long n) : par(n, -1), siz(n, 1){}
long long root(long long x) {
if(par[x] == -1) return x;
else return par[x] = root(par[x]);
}
bool issame(long long x, long long y) {
return root(x) == root(y);
}
bool unite(long long x, long long y) {
x = root(x); y = root(y);
if(x == y) return false;
if(siz[x] < siz[y]) swap(x, y);
par[y] = x;
siz[x] += siz[y];
return true;
}
long long size(long long x) {
return siz[root(x)];
}
};
int main() {
int N, M;
cin >> N;
vector<int> T(N);
rep(i, N) cin >> T[i];
sort(T.begin(), T.end());
if(N == 1) cout << T[0] << endl;
if(N == 2) cout << max(T[0], T[1]) << endl;
if(N > 2) {
int ob1 = T[N-1], ob2 = 0;
for(int i=N-2;i>=0;i--) {
int t = T[i];
if(ob1 <= ob2) ob1 += t;
else ob2 += t;
}
cout << max(ob1, ob2) << endl;
}
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - Cooking |
| User | Tommy3 |
| Language | C++ (GCC 9.2.1) |
| Score | 0 |
| Code Size | 1529 Byte |
| Status | WA |
| Exec Time | 8 ms |
| Memory | 3640 KiB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:61:10: warning: unused variable ‘M’ [-Wunused-variable]
61 | int N, M;
| ^
Judge Result
| Set Name | Sample | All | ||||||
|---|---|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 0 / 400 | ||||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | sample_01.txt, sample_02.txt, sample_03.txt |
| All | hand_01.txt, max_01.txt, max_02.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, sample_01.txt, sample_02.txt, sample_03.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| hand_01.txt | AC | 7 ms | 3600 KiB |
| max_01.txt | AC | 2 ms | 3552 KiB |
| max_02.txt | AC | 5 ms | 3468 KiB |
| random_01.txt | WA | 2 ms | 3604 KiB |
| random_02.txt | WA | 1 ms | 3532 KiB |
| random_03.txt | WA | 2 ms | 3492 KiB |
| random_04.txt | WA | 2 ms | 3640 KiB |
| random_05.txt | WA | 2 ms | 3572 KiB |
| random_06.txt | WA | 8 ms | 3600 KiB |
| random_07.txt | WA | 2 ms | 3604 KiB |
| random_08.txt | AC | 3 ms | 3404 KiB |
| random_09.txt | WA | 2 ms | 3540 KiB |
| random_10.txt | WA | 2 ms | 3580 KiB |
| random_11.txt | WA | 3 ms | 3580 KiB |
| random_12.txt | WA | 2 ms | 3468 KiB |
| random_13.txt | AC | 2 ms | 3524 KiB |
| random_14.txt | WA | 3 ms | 3596 KiB |
| random_15.txt | WA | 4 ms | 3524 KiB |
| random_16.txt | WA | 2 ms | 3416 KiB |
| sample_01.txt | AC | 2 ms | 3456 KiB |
| sample_02.txt | AC | 2 ms | 3456 KiB |
| sample_03.txt | AC | 3 ms | 3600 KiB |