# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
27123 |
2017-07-09T10:57:39 Z |
아인타(#1126) |
포도주 시음 (FXCUP2_wine) |
C++ |
|
89 ms |
2292 KB |
/*#include<cstdio>
#include<algorithm>
using namespace std;
int w[12], v[11], head, tail, CC, pp;
int chk[1030][1030][2][2];
struct point{
int a, b, ck, r1, r2, ck2;
}Q[2010000], TQ[2010000];
void Ins(int m1, int m2, int t1, int t2, int ck, int r1, int r2, int ck2){
if(ck2 && t2)return;
if(m1&(1<<t1))return;
if(!ck2 && (m2&(1<<t2)))return;
if(pp == 1000000000 && ck == 1)return;
m1 |= (1<<t1);
m2 |= (1<<t2);
if(ck2 == 0 && t2 == 0){
ck2 = 1;
if(!chk[m1][m2][ck][ck2]){
r1 += pp * t1;
r2 += pp * t2;
TQ[++CC] = {m1,m2,ck,r1,r2,ck2};
chk[m1][m2][ck][ck2] = 1;
r1 -= pp * t1;
r2 -= pp * t2;
}
ck2 = 0;
}
if(chk[m1][m2][ck][ck2])return;
r1 += pp * t1;
r2 += pp * t2;
chk[m1][m2][ck][ck2] = 1;
TQ[++CC] = {m1,m2,ck,r1,r2,ck2};
}
bool Repeat(int a){
int t = a;
int v[10] = {0};
while(t>10){
if(v[t%10])return true;
v[t%10] = true;
t/=10;
}
return false;
}
bool Pos(int n, int ccc){
if(ccc){
while(1){}
}
int m = 0, tn = n;
while(n){
w[++m] = n%10;
n/=10;
}
n = tn;
head = tail = 0;
Q[++tail] = {0,0,0,0,0,0};
pp = 1;
int i, j, k;
for(i=1;i<=m;i++){
CC = 0;
for(j=1;j<=tail;j++){
if(i==m && w[i] == 1 && Q[j].ck == 1){
if(!ccc)printf( "2 %d %d\n",Q[i].r1, Q[i].r2);
else printf("3 %d %d %d\n",ccc,Q[i].r1,Q[i].r2);
return true;
}
int a = w[i] - Q[j].ck, m1 = Q[j].a, m2 = Q[j].b;
for(k=0;k<10;k++){
if(a >= k){
Ins(m1, m2, k, a-k, 0, Q[j].r1, Q[j].r2, Q[j].ck2);
}
if(a < k){
Ins(m1, m2, k, 10+a-k, 1, Q[j].r1, Q[j].r2, Q[j].ck2);
}
}
}
pp*=10;
for(j=1;j<=CC;j++){
chk[TQ[j].a][TQ[j].b][TQ[j].ck][TQ[j].ck2] = 0;
Q[j] = TQ[j];
}
tail = CC;
}
for(i=1;i<=tail;i++){
if(Q[i].ck == 0){
if(Q[i].r1 + Q[i].r2 != n){
while(1){}
}
if(Repeat(Q[i].r1) || Repeat(Q[i].r2)){
fprintf(stderr,"%d %d %d\n",Q[i].r1, Q[i].r2, n);
while(1){}
}
if(!ccc)printf( "2 %d %d\n",Q[i].r1, Q[i].r2);
else printf("3 %d %d %d\n",ccc,Q[i].r1,Q[i].r2);
return true;
}
}
return false;
}
int main(){
int i, j, k;
int TC, n;
freopen("/Users/joseunghyeon/Downloads/d2.in","r", stdin);
freopen("/Users/joseunghyeon/Desktop/code/160929/0409/0409/output.txt","w",stdout);
scanf("%d",&TC);
while(TC--){
fprintf(stderr, "%d\n",TC);
scanf("%d",&n);
int tn = n;
for(i=0;i<10;i++)v[i]=0;
int ck = 0, m = 0;
head = 0, tail = 0;
while(n){
if(v[n%10])ck = 1;
v[n%10] = 1;
w[++m] = n%10;
n/=10;
}
n = tn;
if(!ck){
printf("%d %d\n",1, n);
continue;
}
for(i=0;;i+=19){
if(i && Repeat(i))continue;
if(Pos(n-i, i))break;
}
}
}*/
#include<cstdio>
#include<algorithm>
using namespace std;
int n, K, w[301000];
long long res;
int main(){
int i;
scanf("%d%d",&n,&K);
for(i=1;i<=n;i++)scanf("%d",&w[i]);
sort(w+1,w+n+1);
for(i=n;i>n-(K+1)/2;i--)res += w[i];
for(i=1;i<=(K-1)/2;i++)res -= w[i];
printf("%lld\n",res);
}
Compilation message
wine.cpp: In function 'int main()':
wine.cpp:136:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&n,&K);
^
wine.cpp:137:39: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(i=1;i<=n;i++)scanf("%d",&w[i]);
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2292 KB |
Output is correct |
2 |
Correct |
0 ms |
2292 KB |
Output is correct |
3 |
Correct |
0 ms |
2292 KB |
Output is correct |
4 |
Correct |
0 ms |
2292 KB |
Output is correct |
5 |
Correct |
0 ms |
2292 KB |
Output is correct |
6 |
Correct |
0 ms |
2292 KB |
Output is correct |
7 |
Correct |
0 ms |
2292 KB |
Output is correct |
8 |
Correct |
0 ms |
2292 KB |
Output is correct |
9 |
Correct |
0 ms |
2292 KB |
Output is correct |
10 |
Correct |
0 ms |
2292 KB |
Output is correct |
11 |
Correct |
0 ms |
2292 KB |
Output is correct |
12 |
Correct |
0 ms |
2292 KB |
Output is correct |
13 |
Correct |
0 ms |
2292 KB |
Output is correct |
14 |
Correct |
0 ms |
2292 KB |
Output is correct |
15 |
Correct |
0 ms |
2292 KB |
Output is correct |
16 |
Correct |
0 ms |
2292 KB |
Output is correct |
17 |
Correct |
3 ms |
2292 KB |
Output is correct |
18 |
Correct |
3 ms |
2292 KB |
Output is correct |
19 |
Correct |
6 ms |
2292 KB |
Output is correct |
20 |
Correct |
9 ms |
2292 KB |
Output is correct |
21 |
Correct |
16 ms |
2292 KB |
Output is correct |
22 |
Correct |
19 ms |
2292 KB |
Output is correct |
23 |
Correct |
29 ms |
2292 KB |
Output is correct |
24 |
Correct |
26 ms |
2292 KB |
Output is correct |
25 |
Correct |
83 ms |
2292 KB |
Output is correct |
26 |
Correct |
73 ms |
2292 KB |
Output is correct |
27 |
Correct |
83 ms |
2292 KB |
Output is correct |
28 |
Correct |
49 ms |
2292 KB |
Output is correct |
29 |
Correct |
89 ms |
2292 KB |
Output is correct |
30 |
Correct |
86 ms |
2292 KB |
Output is correct |
31 |
Correct |
86 ms |
2292 KB |
Output is correct |
32 |
Correct |
89 ms |
2292 KB |
Output is correct |
33 |
Correct |
0 ms |
2292 KB |
Output is correct |
34 |
Correct |
13 ms |
2292 KB |
Output is correct |