#pragma warning(disable : 4996)
#include <iostream>
#include <vector>
#include <set>
#include<stdio.h>
#include<algorithm>
using namespace std;
void test0()
{
int N, x,ans=0;
vector<int> v1;
set<int>s;
set<int>::iterator iter;
cin >> N;
for (int i = 0; i < N; i++)
{
cin >> x;
iter = s.find(x);
if (iter!=s.end())ans++;
for (size_t j = 0; j<v1.size(); j++)
s.insert(x + v1[j]);
v1.push_back(x);
}
cout << ans;
cout << endl;
}
void test1()
{
double E=0, s = 1.0;
for (int i = 1; i < 21; i++)
{
s *= i;
E += 1.0 / s;
}
cout << E << "\n";
}
void test2()
{
int i, j;
for (i = 0; i < 4; i++)
{
for (j = 0; i==0?j!=1:j<i*3; j++)
cout << "*";
cout << endl;
}
}
void test3()
{
int a = 0;
cout << a++ << a++ << a++ << a++ << a++ << a++ << a++ << a++ << a++ << a++;
}
void test4()
{
//bool a=3 > 2 > 1;
//cout <<a;
}
typedef enum class MYENUM
{
Once =1,
Daily =2,
Weekly =3,
Monthly =4,
}Frequency;
istream& operator>>(istream& is, Frequency& frequency)
{
int k = 0;
cin >> k;
switch (k)
{
case 1:
frequency = Frequency::Once;
break;
case 2:
frequency = Frequency::Daily;
break;
case 3:
frequency = Frequency::Weekly;
break;
case 4:
frequency = Frequency::Monthly;
break;
default:
break;
}
return is;
}
ostream& operator<<(ostream& os,const Frequency frequency)
{
string s;
switch (frequency)
{
case Frequency::Once:
s = "Once"; break;
case Frequency::Daily:
s = "Daily"; break;
case Frequency::Weekly:
s = "Weekly"; break;
case Frequency::Monthly:
s = "Monthly"; break;
default:
break;
}
os << s <<" ";
return os;
}
class CO2Emission
{
private:
CO2Emission* next;
public:
CO2Emission() { next = NULL; }
~CO2Emission() { cout << "destructor CO2Emission: done";}
CO2Emission* get_next() { return this->next; }
void set_next(CO2Emission *c) { this->next = c; }
virtual float get_co2() {}
virtual void print() {}
};
class Transport :public CO2Emission
{
private:
float km;
Frequency frequency{};
public:
Transport() { cin >> this->km; cin >> this->frequency; }
Transport(float km, Frequency frequency= Frequency::Once) { this->km = km; this->frequency = frequency; }
~Transport() { cout << "destructor Transport: " << frequency << " " << km << " km done" << endl; }
};
void test5()
{
Frequency frequency{};
cin >> frequency;
//myEnum = MyEnum::Once;
cout << frequency;
}
void test6()
{
string 五行[] = { "金","木","水","火","土" };
for (int i = 0; i < 5; i++)
cout << 五行[i] << endl;
}
enum WX
{
阳木=1,
阴木=2,
阳火=3,
阴火=4,
阳土=5,
阴土=6,
阳金=7,
阴金=8,
阳水=9,
阴水=10
};
void test7()
{
int n, f, ans = 0, c[1001] = {0}, k = 0, d;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> f;
c[f]++;
}
while (k<n)
{
d = 0;//要承受多少只
ans++;//方案+1
for (int i = 0; i < 1001;)
{
if (c[i] != 0 && i >= d)
{
c[i]--;
k++;
d++;
}
else
i++;
}
}
cout << endl << ans;
}
void test8()
{
vector<int> nums = { -2,1,-3,4,-1,2,1,-5,4 };
int pre = 0, maxAns = nums[0];
for(const auto &x:nums)
{
pre = max(pre + x, x);
maxAns = max(maxAns, pre);
}
cout<<maxAns<<endl;
}
void test9()//动态规划爬楼梯
{
int n = 4;
if (n == 1)
{
cout << 1;
return;
}
int dp[10] = { 0 };
dp[1] = 1;
dp[2] = 2;
for (int i = 3; i <= n; i++)
dp[i] = dp[i - 1] + dp[i - 2];
cout << dp[n];
}
void test10()
{
int N, M, n[1001] = {0}, m[7] = { 0 }, k=0,x=0;
cin >> N;
cin >> M;
cin >> k;
for (int i = 0; i <N; i++)
{
for (int j = 0; j < M; j++)
{
cin >> m[j];
n[i] += m[j];
}
if (n[i] >= k) x++;
}
cout << x << endl;
}
int fun(int n)
{
int ans=0;
if (n <= 2)
return n;
if (n % 2 == 0)
ans = fun(n / 2) + fun(n - 1);
else if (n % 2 != 0)
ans = fun(n - 1);
return ans;
}
//
//#include<stdio.h>
//#include<stdlib.h>
//#include<math.h>
//
//#define Ti 0.0 // initial time
//#define Tf 50.0 // final time
//#define dT 0.001 // time step
//
//#define Y01 0.0 // initial condition 1
//#define Y02 1.0 // initial condition 2
//#define Y02 0.0 // initial condition 3
//
//#define sigma 10.0 // Lorenz equations parameters
//#define b 8.0/3.0
//#define r 28.0
//void lorenz1(double *xyz,double *fgh)
//{
// double x, y, z;
// double f, g, h;
// x = xyz[0];
// y = xyz[1];
// z = xyz[2];
//
// f = sigma * (y - x);
// g = r * x - y - x * z;
// h = x * y - b * z;
// fgh[0] = f;
// fgh[1] = g;
// fgh[2] = h;
//
//}
//
//void euler(double** p, void(*f)(double* xyz, double* fgh), int n)
//{
// double xyz[3] = {0,1,0}, fhg[3];
// for (int i = 0; i <= n; i++) {
// f(xyz,fhg);
// p[0][i] = fhg[0];
// p[1][i] = fhg[1];
// p[2][i] = fhg[2];
// xyz[0] +=fhg[0]*dt;
// xyz[1] +=fhg[1]*dt;
// xyz[2] +=fhg[2]*dt;
//
//
// }
//}
//void (*lorenz)(double* xyz,double* fgh);
//int main()
//{
// int i,N;
// double y1[3][100] = {0}, t[100];
// double** y=(double **)y1;
// lorenz = lorenz1;
// //…
// for (i = 0; i <= N; i++) {
// t[i] = Ti + dT * i; // define time
// }
// // solve Lorenz equations
// euler(y, lorenz, N); // y to store solutions
// // print to file
// for (i = 0; i <= N; i++) {
// fprintf(fw, "%f\t%f\t%f\t%f\n", t[i], y[0][i], y[1][i], y[2][i]);
// }
// …
// …
//}
#include <algorithm>
bool cmp(int a, int b) {//同一时间下回来的排前面
if (abs(a) == abs(b)) return a < b;
return abs(a) < abs(b);
}
void test11()
{
using namespace std;
int n, x, y, m=0;
int* a = new int[200005]{ 0 };
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> x >> y;
a[++m] = x; a[++m] = -(y + 1);//按规则处理出来
}
sort(a + 1, a + m + 1, cmp);
int sum = 0, ans = 0;
for (int i = 1; i <= m; i++) {
if (a[i] < 0) sum--;//回来人数-1
else {
sum++;//出去人数+1
if (sum > ans) ans = sum;//比最大值大就替换
}
}
cout << ans << endl;
delete a;
}
void test12()//线性动态规划
{
string txt = "ABCABCDEFEOT";
vector<int> a;
a.push_back(1);
int maxl=0;
for (int i = 1; i < txt.size(); i++)
{
if (txt[i] > txt[i - 1])
{
a.push_back(*(a.end() - 1)+1);
maxl = *(a.end() - 1) > maxl ? *(a.end() - 1) : maxl;
}
else
a.push_back(1);
}
cout << maxl << endl;
}
void test13()
{
int n = 0;
for (int i = 0; i < 5; i++)
printf("%d %d\n", n * 2, n++);
}
void test14()
{
int n, m,n1 = 0, m1 = 0,n2 = 0, m2 = 0;
cin >> n >> m;
vector<int> a,b;
while (n)
{
a.insert(a.begin(),n%10);
n /= 10;
}
while (m)
{
b.insert(b.begin(), m % 10);
m /= 10;
}
if (a.size() != b.size())
return;
for (int i = 0; i < a.size();i++)
{
if (a[i] < b[i])
{
m1 = m1*10+b[i];
n2++;
}
else if (a[i] == b[i])
{
n1 = n1 * 10 + a[i];
m1 = m1 * 10 + b[i];
}
else if (a[i] > b[i])
{
n1 = n1*10+a[i];
m2++;
}
}
if (n2 == 4)
cout << "BOOOM\n";
else
cout << n1 << endl;
if (m2 == 4)
cout << "BOOOM\n";
else
cout << m1 << endl;
}
void test15() {
int m, n, sum = 0;
cin >> m >> n;
for (int i = m; i <= n; i++)
if (i % 7 != 0 && i % 5 != 0)
sum += i;
cout << sum << endl;
}
void test16()
{
set<int>s;
int m, n,sum=0;
cin >> m >> n;
for (int i = 0; i < n; i++)
{
int k;
cin >> k;
s.insert(k);
}
for (int i = 0; i < m; i++)
{
sum += (*(--s.end())- *s.begin());
if(s.size())
s.erase(s.begin());
if (s.size())
s.erase(--s.end());
}
cout<<sum<<endl;
}
void test17()
{
vector<long> s;
long m, n,sum=0;
cin >> m;
for (int i = 0; i < m; i++)
{
cin >> n;
s.push_back(n);
}
sort(s.rbegin(), s.rend());
vector<long>::iterator it = s.begin();
for (size_t i = 1;it != s.end(); ++it,++i)
if(i%3!=0)sum += *it;
cout << sum << endl;
}
int main()
{
test17();
//test16();
//test15();
//test14();
//test13();
//test12();
//test11();
//fun(3);
//test9();
//test8();
//test0();
//test1();
//test2();
//test3();
//test4();
//test5();
//test6();
//test7();
}
|