-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1661.cpp
More file actions
77 lines (72 loc) · 1011 Bytes
/
1661.cpp
File metadata and controls
77 lines (72 loc) · 1011 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
int n,i;
long long count=0;
scanf("%d",&n);
while(n){
int a[n];
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n-1;i++){
if(a[i]<0)
count=count+((-1)*a[i]);
else
count=count+a[i];
a[i+1]=a[i+1]+a[i];
}
printf("%lld\n",count);
scanf("%d",&n);
count=0;
}
return 0;
}
/* TIMELIMIT
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
int n,i,j;
long long cont=0;
scanf("%d",&n);
while(n){
int a[n];
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++){
if(a[i]<0){
j=i+1;
while(a[i]<0){
if(a[j]>0){
a[j]=a[j]-1;
a[i]=a[i]+1;
cont=cont+(j-i);
}else{
j++;
}
}
}else{
if(a[i]>0){
j=i+1;
while(a[i]>0){
if(a[j]<0){
a[j]=a[j]+1;
a[i]=a[i]-1;
cont=cont+(j-i);
}else{
j++;
}
}
}else{
continue;
}
}
}
printf("%lld\n",cont);
scanf("%d",&n);
cont=0;
}
return 0;
}
*/