mirror of
https://github.com/tiennm99/codeforces.git
synced 2026-10-14 06:17:38 +00:00
[Init] Solved solutions
This commit is contained in:
1 parent
51f667ac81
commit
20542601dd
131 files changed
+4148
No files matched your search
+38
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
|
||||
namespace problem_381A
|
||||
{
|
||||
class problem_381A
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
int n = int.Parse(Console.ReadLine());
|
||||
int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
|
||||
int[] b = new int[n];
|
||||
int l = 0, r = n - 1, s1 = 0, s2 = 0;
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
if (a[l] >= a[r])
|
||||
{
|
||||
b[i] = a[l++];
|
||||
}
|
||||
else
|
||||
{
|
||||
b[i] = a[r--];
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
if (i % 2 == 0)
|
||||
{
|
||||
s1 += b[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
s2 += b[i];
|
||||
}
|
||||
}
|
||||
Console.Write("{0} {1}", s1, s2);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user