Code Monkey home page Code Monkey logo

-stone's Introduction

-Stone

Roman has no idea, why this problem is called Stone. He also has no idea on how to solve the following problem: given array of N integers A and a number K. During a turn the maximal value over all Ai is chosen, lets call it MAX. Then Ai =MAX - Ai is done for every 1 <= i <= N. Help Roman to find out how will the array look like after K turns.

Input The numbers N and K are given in the first line of an input. Then N integers are given in the second line which denote the array A. Output Output N numbers on a single line. It should be the array A after K turns. Constraints 1 <= N <= 105 0 <= K <= 109 Ai does not exceed 2 * 109 by its absolute value Logic Test Case 1

Input (stdin) 4 1

5 -1 7 0

Expected Output

2 8 0 7 Logic Test Case 2

Input (stdin) 5 1

5 -1 7 2 0

Expected Output

2 8 0 5 7

#include <stdio.h> typedef long long int LLI; #define inchar getchar_unlocked inline int inIntNeg() { int n=0, ch, neg=0; while ((ch = inchar()) < 32); if(ch=='-') neg=1; else n= (ch - '0'); while((ch = inchar()) >= '0') { n = (n << 3) + (n << 1) + (ch - '0'); } return neg?-n:n; }

#define MAX_N 100000 LLI a[MAX_N]; int n;

void iterate() { LLI ma; int i; ma=a[0]; for(i=1; i<n; ++i) if(a[i]>ma) { ma=a[i]; } for(i=0; i<n; ++i) a[i] = ma-a[i]; }

void print() { int i; printf("%lld",a[0]); for(i=1; i<n; ++i) printf(" %lld",a[i]); printf("\n"); }

int main() { int k,i;

n = inIntNeg();
k = inIntNeg();

for(i=0; i<n; ++i) a[i] = inIntNeg();

if( k > 0) {
	iterate();
	if((k&1)==0) iterate();
}
print();
return 0;

}

-stone's People

Contributors

hishore20 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.